fix(gateway): canonicalize main session aliases
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
import { registerAgentRunContext } from "../../infra/agent-events.js";
|
||||
import { resolveOutboundTarget } from "../../infra/outbound/targets.js";
|
||||
import { DEFAULT_CHAT_PROVIDER } from "../../providers/registry.js";
|
||||
import { normalizeMainKey } from "../../routing/session-key.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { resolveSendPolicy } from "../../sessions/send-policy.js";
|
||||
import {
|
||||
@@ -29,7 +28,7 @@ import {
|
||||
validateAgentParams,
|
||||
validateAgentWaitParams,
|
||||
} from "../protocol/index.js";
|
||||
import { loadSessionEntry } from "../session-utils.js";
|
||||
import { loadSessionEntry, resolveSessionStoreKey } from "../session-utils.js";
|
||||
import { formatForLog } from "../ws-log.js";
|
||||
import { waitForAgentJob } from "./agent-job.js";
|
||||
import type { GatewayRequestHandlers } from "./types.js";
|
||||
@@ -190,24 +189,21 @@ export const agentHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
resolvedSessionId = sessionId;
|
||||
const agentId = resolveAgentIdFromSessionKey(requestedSessionKey);
|
||||
const mainSessionKey = resolveAgentMainSessionKey({
|
||||
const canonicalSessionKey = resolveSessionStoreKey({
|
||||
cfg,
|
||||
agentId,
|
||||
sessionKey: requestedSessionKey,
|
||||
});
|
||||
const rawMainKey = normalizeMainKey(cfg.session?.mainKey);
|
||||
// Normalize short main key alias to canonical form before store write
|
||||
const storeKey =
|
||||
requestedSessionKey === rawMainKey ? mainSessionKey : requestedSessionKey;
|
||||
const agentId = resolveAgentIdFromSessionKey(canonicalSessionKey);
|
||||
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
|
||||
if (store) {
|
||||
store[storeKey] = nextEntry;
|
||||
store[canonicalSessionKey] = nextEntry;
|
||||
if (storePath) {
|
||||
await saveSessionStore(storePath, store);
|
||||
}
|
||||
}
|
||||
if (
|
||||
requestedSessionKey === mainSessionKey ||
|
||||
requestedSessionKey === rawMainKey
|
||||
canonicalSessionKey === mainSessionKey ||
|
||||
canonicalSessionKey === "global"
|
||||
) {
|
||||
context.addChatRun(idem, {
|
||||
sessionKey: requestedSessionKey,
|
||||
|
||||
@@ -3,15 +3,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { resolveThinkingDefault } from "../../agents/model-selection.js";
|
||||
import { resolveAgentTimeoutMs } from "../../agents/timeout.js";
|
||||
import { agentCommand } from "../../commands/agent.js";
|
||||
import {
|
||||
mergeSessionEntry,
|
||||
resolveAgentMainSessionKey,
|
||||
saveSessionStore,
|
||||
} from "../../config/sessions.js";
|
||||
import {
|
||||
normalizeMainKey,
|
||||
resolveAgentIdFromSessionKey,
|
||||
} from "../../routing/session-key.js";
|
||||
import { mergeSessionEntry, saveSessionStore } from "../../config/sessions.js";
|
||||
import { registerAgentRunContext } from "../../infra/agent-events.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { resolveSendPolicy } from "../../sessions/send-policy.js";
|
||||
@@ -40,6 +32,7 @@ import {
|
||||
loadSessionEntry,
|
||||
readSessionMessages,
|
||||
resolveSessionModelRef,
|
||||
resolveSessionStoreKey,
|
||||
} from "../session-utils.js";
|
||||
import { formatForLog } from "../ws-log.js";
|
||||
import type { GatewayRequestHandlers } from "./types.js";
|
||||
@@ -314,12 +307,10 @@ export const chatHandlers: GatewayRequestHandlers = {
|
||||
clientRunId,
|
||||
});
|
||||
|
||||
// Normalize short main key alias to canonical form before store write
|
||||
const agentId = resolveAgentIdFromSessionKey(p.sessionKey);
|
||||
const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
|
||||
const rawMainKey = normalizeMainKey(cfg.session?.mainKey);
|
||||
const storeKey =
|
||||
p.sessionKey === rawMainKey ? mainSessionKey : p.sessionKey;
|
||||
const storeKey = resolveSessionStoreKey({
|
||||
cfg,
|
||||
sessionKey: p.sessionKey,
|
||||
});
|
||||
if (store) {
|
||||
store[storeKey] = sessionEntry;
|
||||
if (storePath) {
|
||||
|
||||
Reference in New Issue
Block a user