2026-01-10 23:31:25 +00:00
|
|
|
import type { SessionEntry } from "../config/sessions.js";
|
|
|
|
|
import { normalizeProviderId } from "./model-selection.js";
|
|
|
|
|
|
|
|
|
|
export function getCliSessionId(
|
|
|
|
|
entry: SessionEntry | undefined,
|
|
|
|
|
provider: string,
|
|
|
|
|
): string | undefined {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (!entry) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
2026-01-10 23:31:25 +00:00
|
|
|
const normalized = normalizeProviderId(provider);
|
|
|
|
|
const fromMap = entry.cliSessionIds?.[normalized];
|
2026-01-31 16:19:20 +09:00
|
|
|
if (fromMap?.trim()) {
|
|
|
|
|
return fromMap.trim();
|
|
|
|
|
}
|
2026-01-10 23:31:25 +00:00
|
|
|
if (normalized === "claude-cli") {
|
|
|
|
|
const legacy = entry.claudeCliSessionId?.trim();
|
2026-01-31 16:19:20 +09:00
|
|
|
if (legacy) {
|
|
|
|
|
return legacy;
|
|
|
|
|
}
|
2026-01-10 23:31:25 +00:00
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 14:31:43 +00:00
|
|
|
export function setCliSessionId(entry: SessionEntry, provider: string, sessionId: string): void {
|
2026-01-10 23:31:25 +00:00
|
|
|
const normalized = normalizeProviderId(provider);
|
|
|
|
|
const trimmed = sessionId.trim();
|
2026-01-31 16:19:20 +09:00
|
|
|
if (!trimmed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-10 23:31:25 +00:00
|
|
|
const existing = entry.cliSessionIds ?? {};
|
|
|
|
|
entry.cliSessionIds = { ...existing };
|
|
|
|
|
entry.cliSessionIds[normalized] = trimmed;
|
|
|
|
|
if (normalized === "claude-cli") {
|
|
|
|
|
entry.claudeCliSessionId = trimmed;
|
|
|
|
|
}
|
|
|
|
|
}
|