|
| 1 | +import type { AnthropicAiClient, AnthropicAiResponse } from '@sentry/core'; |
| 2 | + |
| 3 | +export class MockAnthropic implements AnthropicAiClient { |
| 4 | + public messages: { |
| 5 | + create: (...args: unknown[]) => Promise<AnthropicAiResponse>; |
| 6 | + countTokens: (...args: unknown[]) => Promise<AnthropicAiResponse>; |
| 7 | + }; |
| 8 | + public models: { |
| 9 | + list: (...args: unknown[]) => Promise<AnthropicAiResponse>; |
| 10 | + get: (...args: unknown[]) => Promise<AnthropicAiResponse>; |
| 11 | + }; |
| 12 | + public completions: { |
| 13 | + create: (...args: unknown[]) => Promise<AnthropicAiResponse>; |
| 14 | + }; |
| 15 | + public apiKey: string; |
| 16 | + |
| 17 | + public constructor(config: { apiKey: string }) { |
| 18 | + this.apiKey = config.apiKey; |
| 19 | + |
| 20 | + // Main focus: messages.create functionality |
| 21 | + this.messages = { |
| 22 | + create: async (...args: unknown[]) => { |
| 23 | + const params = args[0] as { model: string; stream?: boolean }; |
| 24 | + // Simulate processing time |
| 25 | + await new Promise(resolve => setTimeout(resolve, 10)); |
| 26 | + |
| 27 | + if (params.model === 'error-model') { |
| 28 | + const error = new Error('Model not found'); |
| 29 | + (error as unknown as { status: number }).status = 404; |
| 30 | + (error as unknown as { headers: Record<string, string> }).headers = { 'x-request-id': 'mock-request-123' }; |
| 31 | + throw error; |
| 32 | + } |
| 33 | + |
| 34 | + return { |
| 35 | + id: 'msg_mock123', |
| 36 | + type: 'message', |
| 37 | + role: 'assistant', |
| 38 | + model: params.model, |
| 39 | + content: [ |
| 40 | + { |
| 41 | + type: 'text', |
| 42 | + text: 'Hello from Anthropic mock!', |
| 43 | + }, |
| 44 | + ], |
| 45 | + stop_reason: 'end_turn', |
| 46 | + stop_sequence: null, |
| 47 | + usage: { |
| 48 | + input_tokens: 10, |
| 49 | + output_tokens: 15, |
| 50 | + cache_creation_input_tokens: 0, |
| 51 | + cache_read_input_tokens: 0, |
| 52 | + }, |
| 53 | + }; |
| 54 | + }, |
| 55 | + countTokens: async (..._args: unknown[]) => ({ id: 'mock', type: 'model', model: 'mock', input_tokens: 0 }), |
| 56 | + }; |
| 57 | + |
| 58 | + // Minimal implementations for required interface compliance |
| 59 | + this.models = { |
| 60 | + list: async (..._args: unknown[]) => ({ id: 'mock', type: 'model', model: 'mock' }), |
| 61 | + get: async (..._args: unknown[]) => ({ id: 'mock', type: 'model', model: 'mock' }), |
| 62 | + }; |
| 63 | + |
| 64 | + this.completions = { |
| 65 | + create: async (..._args: unknown[]) => ({ id: 'mock', type: 'completion', model: 'mock' }), |
| 66 | + }; |
| 67 | + } |
| 68 | +} |
0 commit comments