| 380 | } |
| 381 | |
| 382 | function isOpenAIChatCompletion(value: unknown): boolean { |
| 383 | if (!value || typeof value !== 'object') return false; |
| 384 | const choices = (value as { choices?: unknown }).choices; |
| 385 | return ( |
| 386 | Array.isArray(choices) && |
| 387 | choices.some((choice) => { |
| 388 | if (!choice || typeof choice !== 'object') return false; |
| 389 | const message = (choice as { message?: unknown }).message; |
| 390 | if (!message || typeof message !== 'object') return false; |
| 391 | const completion = message as { |
| 392 | content?: unknown; |
| 393 | reasoning?: unknown; |
| 394 | reasoning_content?: unknown; |
| 395 | tool_calls?: unknown; |
| 396 | }; |
| 397 | return ( |
| 398 | typeof completion.content === 'string' || |
| 399 | typeof completion.reasoning === 'string' || |
| 400 | typeof completion.reasoning_content === 'string' || |
| 401 | (Array.isArray(completion.tool_calls) && completion.tool_calls.length > 0) |
| 402 | ); |
| 403 | }) |
| 404 | ); |
| 405 | } |
| 406 | |
| 407 | async function probeGoogle( |
| 408 | baseUrl: string, |