( lazyTools: Array<CodeModeTool>, lazyToolsConfig?: LazyToolsConfig, )
| 53 | * description appears in this tool's own catalog (mirroring the system prompt). |
| 54 | */ |
| 55 | export function createDiscoveryTool( |
| 56 | lazyTools: Array<CodeModeTool>, |
| 57 | lazyToolsConfig?: LazyToolsConfig, |
| 58 | ): ServerTool< |
| 59 | typeof discoverInputSchema, |
| 60 | typeof discoverOutputSchema, |
| 61 | 'discover_tools' |
| 62 | > { |
| 63 | const lazyMap = new Map(lazyTools.map((t) => [t.name, t])) |
| 64 | const include = lazyToolsConfig?.includeDescription ?? 'none' |
| 65 | const catalog = lazyTools |
| 66 | .map((t) => |
| 67 | renderLazyCatalogEntry( |
| 68 | `${EXTERNAL_PREFIX}${t.name}`, |
| 69 | t.description, |
| 70 | include, |
| 71 | ), |
| 72 | ) |
| 73 | .join(', ') |
| 74 | |
| 75 | return toolDefinition({ |
| 76 | name: 'discover_tools' as const, |
| 77 | description: |
| 78 | `Discover full TypeScript signatures for additional sandbox APIs before ` + |
| 79 | `using them inside execute_typescript. Discoverable tools: [${catalog}]. ` + |
| 80 | `Pass the names exactly as shown (the external_ prefix is optional).`, |
| 81 | inputSchema: discoverInputSchema, |
| 82 | outputSchema: discoverOutputSchema, |
| 83 | }).server(async ({ toolNames }) => { |
| 84 | const tools: Array<{ |
| 85 | name: string |
| 86 | description: string |
| 87 | typeStub: string |
| 88 | }> = [] |
| 89 | const errors: Array<string> = [] |
| 90 | |
| 91 | for (const name of toolNames) { |
| 92 | const tool = lazyMap.get(stripExternalPrefix(name)) |
| 93 | if (!tool) { |
| 94 | errors.push(`Unknown tool: '${name}'. Discoverable tools: [${catalog}]`) |
| 95 | continue |
| 96 | } |
| 97 | const binding = toolToBinding(tool, EXTERNAL_PREFIX) |
| 98 | const typeStub = generateTypeStubs({ [binding.name]: binding }) |
| 99 | tools.push({ |
| 100 | name: binding.name, |
| 101 | description: tool.description, |
| 102 | typeStub, |
| 103 | }) |
| 104 | } |
| 105 | |
| 106 | return errors.length > 0 ? { tools, errors } : { tools } |
| 107 | }) |
| 108 | } |
no test coverage detected