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

Function captureBetaRequestBody

packages/kosong/test/anthropic.test.ts:150–184  ·  view source on GitHub ↗

* Capture the request body sent to the Anthropic beta Messages API by mocking * the client (non-stream mode). Also asserts the standard Messages API was * not called.

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

Source from the content-addressed store, hash-verified

148 * not called.
149 */
150async function captureBetaRequestBody(
151 provider: AnthropicChatProvider,
152 systemPrompt: string,
153 tools: Tool[],
154 history: Message[],
155): Promise<Record<string, unknown>> {
156 let capturedParams: Record<string, unknown> | undefined;
157 let capturedOptions: Record<string, unknown> | undefined;
158
159 (provider as any)._client.beta.messages.create = vi
160 .fn()
161 .mockImplementation((params: unknown, options?: unknown) => {
162 capturedParams = params as Record<string, unknown>;
163 capturedOptions = options as Record<string, unknown> | undefined;
164 return Promise.resolve(makeAnthropicResponse());
165 });
166 const standardCreate = vi.fn();
167 (provider as any)._client.messages.create = standardCreate;
168
169 const stream = await provider.generate(systemPrompt, tools, history);
170 for await (const part of stream) {
171 void part;
172 }
173
174 if (capturedParams === undefined) {
175 throw new Error('Expected provider.generate() to call beta.messages.create');
176 }
177 expect(standardCreate).not.toHaveBeenCalled();
178
179 const result = { ...capturedParams };
180 if (capturedOptions !== undefined && capturedOptions['headers'] !== undefined) {
181 result['_extra_headers'] = capturedOptions['headers'];
182 }
183 return result;
184}
185
186describe('betaApi', () => {
187 const history: Message[] = [

Callers 1

anthropic.test.tsFile · 0.85

Calls 3

makeAnthropicResponseFunction · 0.70
resolveMethod · 0.65
generateMethod · 0.65

Tested by

no test coverage detected