* Cache validators for tool output schemas. * Called after listTools() to pre-compile validators for better performance.
(tools: Tool[])
| 804 | * Called after listTools() to pre-compile validators for better performance. |
| 805 | */ |
| 806 | private cacheToolMetadata(tools: Tool[]): void { |
| 807 | this._cachedToolOutputValidators.clear(); |
| 808 | this._cachedKnownTaskTools.clear(); |
| 809 | this._cachedRequiredTaskTools.clear(); |
| 810 | |
| 811 | for (const tool of tools) { |
| 812 | // If the tool has an outputSchema, create and cache the validator |
| 813 | if (tool.outputSchema) { |
| 814 | const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema as JsonSchemaType); |
| 815 | this._cachedToolOutputValidators.set(tool.name, toolValidator); |
| 816 | } |
| 817 | |
| 818 | // If the tool supports task-based execution, cache that information |
| 819 | const taskSupport = tool.execution?.taskSupport; |
| 820 | if (taskSupport === 'required' || taskSupport === 'optional') { |
| 821 | this._cachedKnownTaskTools.add(tool.name); |
| 822 | } |
| 823 | if (taskSupport === 'required') { |
| 824 | this._cachedRequiredTaskTools.add(tool.name); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Get cached validator for a tool |
no test coverage detected