* Calculate total deferred tool description size in characters. * Includes name, description text, and input schema to match what's actually sent to the API.
( tools: Tools, getToolPermissionContext: () => Promise<ToolPermissionContext>, agents: AgentDefinition[], )
| 338 | * Includes name, description text, and input schema to match what's actually sent to the API. |
| 339 | */ |
| 340 | async function calculateDeferredToolDescriptionChars( |
| 341 | tools: Tools, |
| 342 | getToolPermissionContext: () => Promise<ToolPermissionContext>, |
| 343 | agents: AgentDefinition[], |
| 344 | ): Promise<number> { |
| 345 | const deferredTools = tools.filter(t => isDeferredTool(t)) |
| 346 | if (deferredTools.length === 0) return 0 |
| 347 | |
| 348 | const sizes = await Promise.all( |
| 349 | deferredTools.map(async tool => { |
| 350 | const description = await tool.prompt({ |
| 351 | getToolPermissionContext, |
| 352 | tools, |
| 353 | agents, |
| 354 | }) |
| 355 | const inputSchema = tool.inputJSONSchema |
| 356 | ? jsonStringify(tool.inputJSONSchema) |
| 357 | : tool.inputSchema |
| 358 | ? jsonStringify(zodToJsonSchema(tool.inputSchema)) |
| 359 | : '' |
| 360 | return tool.name.length + description.length + inputSchema.length |
| 361 | }), |
| 362 | ) |
| 363 | |
| 364 | return sizes.reduce((total, size) => total + size, 0) |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Check if tool search (MCP tool deferral with tool_reference) is enabled for a specific request. |
no test coverage detected