MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / makeScriptedSession

Function makeScriptedSession

packages/acp-adapter/test/error-mapping.test.ts:68–94  ·  view source on GitHub ↗

* Build a fake `Session` whose `prompt()` either rejects with a * caller-supplied error OR fans out a pre-recorded event sequence * through any subscribed listener — covering the two distinct error * paths that AcpSession.prompt routes through * `mapPromptError` / `authRequiredFromPayloa

(
  sessionId: string,
  opts: { script?: readonly Event[]; rejectWith?: Error },
)

Source from the content-addressed store, hash-verified

66 * `mapPromptError` / `authRequiredFromPayload`.
67 */
68function makeScriptedSession(
69 sessionId: string,
70 opts: { script?: readonly Event[]; rejectWith?: Error },
71): ScriptedSession {
72 const listeners = new Set<(event: Event) => void>();
73 let unsubCount = 0;
74 const session = {
75 id: sessionId,
76 prompt: async (_input: unknown) => {
77 if (opts.rejectWith) throw opts.rejectWith;
78 if (opts.script) {
79 for (const ev of opts.script) {
80 for (const fn of listeners) fn(ev);
81 }
82 }
83 },
84 cancel: async () => undefined,
85 onEvent: (fn: (event: Event) => void) => {
86 listeners.add(fn);
87 return () => {
88 unsubCount += 1;
89 listeners.delete(fn);
90 };
91 },
92 } as unknown as Session;
93 return { session, unsubscribeCount: () => unsubCount };
94}
95
96const textBlock = (text: string): ContentBlock => ({ type: 'text', text });
97

Callers 1

Calls 2

addMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected