* Converts an array of tools to be compatible with OpenAI's strict mode. * Filters for function tools, applies schema conversion to their parameters, * and ensures all tools have consistent strict: true values.
(tools: any[] | undefined)
| 28 | * and ensures all tools have consistent strict: true values. |
| 29 | */ |
| 30 | protected convertToolsForOpenAI(tools: any[] | undefined): any[] | undefined { |
| 31 | if (!tools) { |
| 32 | return undefined |
| 33 | } |
| 34 | |
| 35 | return tools.map((tool) => { |
| 36 | if (tool.type !== "function") { |
| 37 | return tool |
| 38 | } |
| 39 | |
| 40 | // MCP tools use the 'mcp--' prefix - disable strict mode for them |
| 41 | // to preserve optional parameters from the MCP server schema |
| 42 | const isMcp = isMcpTool(tool.function.name) |
| 43 | |
| 44 | return { |
| 45 | ...tool, |
| 46 | function: { |
| 47 | ...tool.function, |
| 48 | strict: !isMcp, |
| 49 | parameters: isMcp |
| 50 | ? tool.function.parameters |
| 51 | : this.convertToolSchemaForOpenAI(tool.function.parameters), |
| 52 | }, |
| 53 | } |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Converts tool schemas to be compatible with OpenAI's strict mode by: |
nothing calls this directly
no test coverage detected