diff --git a/src/agents/agent-command.live-model-switch.test.ts b/src/agents/agent-command.live-model-switch.test.ts index b1aaea68860..45b8b20fcbc 100644 --- a/src/agents/agent-command.live-model-switch.test.ts +++ b/src/agents/agent-command.live-model-switch.test.ts @@ -48,7 +48,7 @@ vi.mock("./command/run-context.js", () => ({ }), })); -vi.mock("./command/session-store.js", () => ({ +vi.mock("./command/session-store.runtime.js", () => ({ updateSessionStoreAfterAgentRun: (...args: unknown[]) => state.updateSessionStoreAfterAgentRunMock(...args), })); diff --git a/src/agents/agent-command.ts b/src/agents/agent-command.ts index 48dfd5bb226..29fa37e94ad 100644 --- a/src/agents/agent-command.ts +++ b/src/agents/agent-command.ts @@ -51,7 +51,6 @@ import { prependInternalEventContext, } from "./command/attempt-execution.shared.js"; import { resolveAgentRunContext } from "./command/run-context.js"; -import { updateSessionStoreAfterAgentRun } from "./command/session-store.js"; import { resolveSession } from "./command/session.js"; import type { AgentCommandIngressOpts, AgentCommandOpts } from "./command/types.js"; import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js"; @@ -79,10 +78,12 @@ import { ensureAgentWorkspace } from "./workspace.js"; const log = createSubsystemLogger("agents/agent-command"); type AttemptExecutionRuntime = typeof import("./command/attempt-execution.runtime.js"); type DeliveryRuntime = typeof import("./command/delivery.runtime.js"); +type SessionStoreRuntime = typeof import("./command/session-store.runtime.js"); type TranscriptResolveRuntime = typeof import("../config/sessions/transcript-resolve.runtime.js"); let attemptExecutionRuntimePromise: Promise | undefined; let deliveryRuntimePromise: Promise | undefined; +let sessionStoreRuntimePromise: Promise | undefined; let transcriptResolveRuntimePromise: Promise | undefined; function loadAttemptExecutionRuntime(): Promise { @@ -95,6 +96,11 @@ function loadDeliveryRuntime(): Promise { return deliveryRuntimePromise; } +function loadSessionStoreRuntime(): Promise { + sessionStoreRuntimePromise ??= import("./command/session-store.runtime.js"); + return sessionStoreRuntimePromise; +} + function loadTranscriptResolveRuntime(): Promise { transcriptResolveRuntimePromise ??= import("../config/sessions/transcript-resolve.runtime.js"); return transcriptResolveRuntimePromise; @@ -1022,6 +1028,7 @@ async function agentCommandInternal( // Update token+model fields in the session store. if (sessionStore && sessionKey) { + const { updateSessionStoreAfterAgentRun } = await loadSessionStoreRuntime(); await updateSessionStoreAfterAgentRun({ cfg, contextTokensOverride: agentCfg?.contextTokens, diff --git a/src/agents/command/session-store.runtime.ts b/src/agents/command/session-store.runtime.ts new file mode 100644 index 00000000000..c60601cba5b --- /dev/null +++ b/src/agents/command/session-store.runtime.ts @@ -0,0 +1 @@ +export { updateSessionStoreAfterAgentRun } from "./session-store.js"; diff --git a/src/commands/agent.runtime-config.test.ts b/src/commands/agent.runtime-config.test.ts index 5cb67b4686b..e7162a92106 100644 --- a/src/commands/agent.runtime-config.test.ts +++ b/src/commands/agent.runtime-config.test.ts @@ -15,7 +15,7 @@ import { withSharedAgentCommandTempHome, } from "./agent-runtime-config.test-support.js"; -vi.mock("../agents/command/session-store.js", () => { +vi.mock("../agents/command/session-store.runtime.js", () => { return { updateSessionStoreAfterAgentRun: vi.fn(async () => undefined), }; diff --git a/src/commands/agent.test.ts b/src/commands/agent.test.ts index 31b84767200..169ff25ef9f 100644 --- a/src/commands/agent.test.ts +++ b/src/commands/agent.test.ts @@ -7,7 +7,7 @@ import "../cron/isolated-agent.mocks.js"; import { __testing as acpManagerTesting } from "../acp/control-plane/manager.js"; import { resolveAgentDir, resolveSessionAgentId } from "../agents/agent-scope.js"; import * as authProfilesModule from "../agents/auth-profiles.js"; -import * as sessionStoreModule from "../agents/command/session-store.js"; +import * as sessionStoreModule from "../agents/command/session-store.runtime.js"; import { resolveSession } from "../agents/command/session.js"; import { loadModelCatalog } from "../agents/model-catalog.js"; import * as modelSelectionModule from "../agents/model-selection.js"; @@ -51,7 +51,7 @@ vi.mock("../agents/auth-profiles/store.js", () => { }; }); -vi.mock("../agents/command/session-store.js", () => { +vi.mock("../agents/command/session-store.runtime.js", () => { return { updateSessionStoreAfterAgentRun: vi.fn(async () => undefined), };