Capture the request body sent to the Responses API by mocking the client.
( provider: OpenAIResponsesChatProvider, systemPrompt: string, tools: Tool[], history: Message[], )
| 41 | |
| 42 | /** Capture the request body sent to the Responses API by mocking the client. */ |
| 43 | async 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 | |
| 71 | const ADD_TOOL: Tool = { |
| 72 | name: 'add', |
no test coverage detected