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

Function captureRequestBody

packages/kosong/test/openai-responses.test.ts:43–69  ·  view source on GitHub ↗

Capture the request body sent to the Responses API by mocking the client.

(
  provider: OpenAIResponsesChatProvider,
  systemPrompt: string,
  tools: Tool[],
  history: Message[],
)

Source from the content-addressed store, hash-verified

41
42/** Capture the request body sent to the Responses API by mocking the client. */
43async function captureRequestBody(
44 provider: OpenAIResponsesChatProvider,
45 systemPrompt: string,
46 tools: Tool[],
47 history: Message[],
48): Promise<Record<string, unknown>> {
49 let capturedBody: Record<string, unknown> | undefined;
50
51 (provider as any)._stream = false;
52
53 ((provider as any)._client.responses as unknown as Record<string, unknown>)['create'] = vi
54 .fn()
55 .mockImplementation((params: unknown) => {
56 capturedBody = params as Record<string, unknown>;
57 return Promise.resolve(makeResponsesAPIResponse());
58 });
59
60 const stream = await provider.generate(systemPrompt, tools, history);
61 for await (const part of stream) {
62 void part;
63 }
64
65 if (capturedBody === undefined) {
66 throw new Error('Expected provider.generate() to call responses.create');
67 }
68 return capturedBody;
69}
70
71const ADD_TOOL: Tool = {
72 name: 'add',

Callers 1

Calls 3

makeResponsesAPIResponseFunction · 0.85
resolveMethod · 0.65
generateMethod · 0.65

Tested by

no test coverage detected