MCPcopy
hub / github.com/rohitg00/agentmemory / mockSdk

Function mockSdk

test/diagnostic-followup-rate.test.ts:36–69  ·  view source on GitHub ↗
(kv: ReturnType<typeof mockKV>)

Source from the content-addressed store, hash-verified

34}
35
36function mockSdk(kv: ReturnType<typeof mockKV>) {
37 const functions = new Map<string, Function>();
38 const sdk = {
39 registerFunction: (
40 idOrOpts: string | { id: string },
41 handler: Function,
42 ) => {
43 const id = typeof idOrOpts === "string" ? idOrOpts : idOrOpts.id;
44 functions.set(id, handler);
45 },
46 registerTrigger: () => {},
47 trigger: async (
48 idOrInput: string | { function_id: string; payload?: unknown },
49 data?: unknown,
50 ) => {
51 const id = typeof idOrInput === "string" ? idOrInput : idOrInput.function_id;
52 const payload =
53 typeof idOrInput === "string" ? data : (idOrInput as any).payload;
54 const fn = functions.get(id);
55 if (!fn) {
56 if (id === "mem::lesson-recall") return { success: true, lessons: [] };
57 throw new Error(`No function: ${id}`);
58 }
59 const result = await fn(payload);
60 // smart-search now runs followup detection off the critical
61 // response path; drain it before returning so test assertions
62 // see consistent state.
63 if (id === "mem::smart-search") await flushPendingFollowups();
64 return result;
65 },
66 } as any;
67 void kv;
68 return sdk;
69}
70
71function makeHit(obsId: string, sessionId = "ses_1"): HybridSearchResult {
72 return {

Calls 3

flushPendingFollowupsFunction · 0.85
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected