refactor: canonicalize gateway session store keys

This commit is contained in:
Peter Steinberger
2026-01-17 07:41:06 +00:00
parent d5fdda8e28
commit c92265a51b
13 changed files with 449 additions and 650 deletions

View File

@@ -16,6 +16,25 @@ export type ParsedAgentSessionKey = {
rest: string;
};
export function toAgentRequestSessionKey(storeKey: string | undefined | null): string | undefined {
const raw = (storeKey ?? "").trim();
if (!raw) return undefined;
return parseAgentSessionKey(raw)?.rest ?? raw;
}
export function toAgentStoreSessionKey(params: {
agentId: string;
requestKey: string | undefined | null;
mainKey?: string | undefined;
}): string {
const raw = (params.requestKey ?? "").trim();
if (!raw || raw === DEFAULT_MAIN_KEY) {
return buildAgentMainSessionKey({ agentId: params.agentId, mainKey: params.mainKey });
}
if (raw.startsWith("agent:")) return raw;
return `agent:${normalizeAgentId(params.agentId)}:${raw}`;
}
export function resolveAgentIdFromSessionKey(sessionKey: string | undefined | null): string {
const parsed = parseAgentSessionKey(sessionKey);
return normalizeAgentId(parsed?.agentId ?? DEFAULT_AGENT_ID);