mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
Major Features: - Gateway tunnel system with Discord/Feishu/Telegram support - Agent request tool policy management - Aster session recovery mechanism - Channel log viewer UI with filtering Improvements: - Refactor MCP database migration and config hot-reload - Optimize request tool policy service - Add comprehensive tests for new features Fixes: - Fix test compilation errors (Config gateway field, type inference) - Fix doctest import paths - Fix flaky antigravity token validation test - Fix CI build issues Dependencies: - Update pnpm-lock.yaml and Cargo.lock Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
export interface RecoverableAsterSession {
|
|
id: string;
|
|
createdAt?: number;
|
|
updatedAt?: number;
|
|
}
|
|
|
|
export interface ResolveRestorableSessionIdOptions {
|
|
candidateSessionId?: string | null;
|
|
sessions: RecoverableAsterSession[];
|
|
}
|
|
|
|
function toEpochSecond(value?: number): number {
|
|
if (!Number.isFinite(value)) {
|
|
return 0;
|
|
}
|
|
return Number(value);
|
|
}
|
|
|
|
export function sortSessionsByRecency(
|
|
sessions: RecoverableAsterSession[],
|
|
): RecoverableAsterSession[] {
|
|
return [...sessions].sort((a, b) => {
|
|
const bRank = toEpochSecond(b.updatedAt) || toEpochSecond(b.createdAt);
|
|
const aRank = toEpochSecond(a.updatedAt) || toEpochSecond(a.createdAt);
|
|
return bRank - aRank;
|
|
});
|
|
}
|
|
|
|
export function resolveRestorableSessionId({
|
|
candidateSessionId,
|
|
sessions,
|
|
}: ResolveRestorableSessionIdOptions): string | null {
|
|
const normalizedCandidate = candidateSessionId?.trim();
|
|
if (normalizedCandidate) {
|
|
const matched = sessions.some((session) => session.id === normalizedCandidate);
|
|
if (matched) {
|
|
return normalizedCandidate;
|
|
}
|
|
}
|
|
|
|
const [fallback] = sortSessionsByRecency(sessions);
|
|
return fallback?.id ?? null;
|
|
}
|
|
|
|
export function isAsterSessionNotFoundError(error: unknown): boolean {
|
|
const message =
|
|
typeof error === "string"
|
|
? error
|
|
: error instanceof Error
|
|
? error.message
|
|
: String(error ?? "");
|
|
const normalized = message.toLowerCase();
|
|
|
|
return (
|
|
message.includes("会话不存在") ||
|
|
normalized.includes("session not found") ||
|
|
normalized.includes("no such session")
|
|
);
|
|
}
|