(tools: unknown)
| 682 | } |
| 683 | |
| 684 | function convertTools(tools: unknown): Array<Record<string, unknown>> | undefined { |
| 685 | if (!Array.isArray(tools) || tools.length === 0) { |
| 686 | return undefined |
| 687 | } |
| 688 | |
| 689 | return tools.map(tool => { |
| 690 | if ( |
| 691 | !tool || |
| 692 | typeof tool !== 'object' || |
| 693 | !('name' in tool) || |
| 694 | typeof tool.name !== 'string' |
| 695 | ) { |
| 696 | throw new Error('Unsupported tool shape for OpenAI compat client') |
| 697 | } |
| 698 | |
| 699 | return { |
| 700 | type: 'function', |
| 701 | function: { |
| 702 | name: tool.name, |
| 703 | ...(typeof tool.description === 'string' |
| 704 | ? { description: tool.description } |
| 705 | : {}), |
| 706 | parameters: |
| 707 | 'input_schema' in tool && tool.input_schema |
| 708 | ? tool.input_schema |
| 709 | : { type: 'object', properties: {} }, |
| 710 | }, |
| 711 | } |
| 712 | }) |
| 713 | } |
| 714 | |
| 715 | function convertToolChoice( |
| 716 | toolChoice: unknown, |
no outgoing calls
no test coverage detected