MCPcopy Index your code
hub / github.com/coder/mux / createSession

Function createSession

src/node/services/agentSession.memoryContext.test.ts:24–73  ·  view source on GitHub ↗

* Behavior under test: the memory session context (index snapshot + * hot-memories block) is computed once per model in a session segment and * recomputed at compaction boundaries — never per repeated model turn — so the * injected bytes stay prompt-cache-stable.

(args: {
  historyService: HistoryService;
  sessionDir: string;
  buildMemorySessionContext: AIService["buildMemorySessionContext"];
})

Source from the content-addressed store, hash-verified

22 */
23
24function createSession(args: {
25 historyService: HistoryService;
26 sessionDir: string;
27 buildMemorySessionContext: AIService["buildMemorySessionContext"];
28}): AgentSession {
29 const aiEmitter = new EventEmitter();
30 const aiService: AIService = {
31 on(eventName: string | symbol, listener: (...args: unknown[]) => void) {
32 aiEmitter.on(String(eventName), listener);
33 return this;
34 },
35 off(eventName: string | symbol, listener: (...args: unknown[]) => void) {
36 aiEmitter.off(String(eventName), listener);
37 return this;
38 },
39 getWorkspaceMetadata: mock(() =>
40 Promise.resolve({ success: false as const, error: "metadata unavailable" })
41 ),
42 stopStream: mock(() => Promise.resolve({ success: true as const, data: undefined })),
43 buildMemorySessionContext: args.buildMemorySessionContext,
44 } as unknown as AIService;
45
46 const initStateManager: InitStateManager = {
47 on() {
48 return this;
49 },
50 off() {
51 return this;
52 },
53 } as unknown as InitStateManager;
54
55 const backgroundProcessManager: BackgroundProcessManager = {
56 setMessageQueued: mock(() => undefined),
57 cleanup: mock(() => Promise.resolve()),
58 } as unknown as BackgroundProcessManager;
59
60 const config: Config = {
61 srcDir: "/tmp",
62 getSessionDir: mock(() => args.sessionDir),
63 } as unknown as Config;
64
65 return new AgentSession({
66 workspaceId: "workspace-hot-memories-test",
67 config,
68 historyService: args.historyService,
69 aiService,
70 initStateManager,
71 backgroundProcessManager,
72 });
73}
74
75interface PrivateSessionAccess {
76 resolveMemoryContext: (

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected