(config: CodeModeToolConfig)
| 26 | * ``` |
| 27 | */ |
| 28 | export function createCodeModeSystemPrompt(config: CodeModeToolConfig): string { |
| 29 | const { tools } = config |
| 30 | const include = config.lazyToolsConfig?.includeDescription ?? 'none' |
| 31 | |
| 32 | const eagerTools = tools.filter((t) => !t.lazy) |
| 33 | const lazyTools = tools.filter((t) => t.lazy) |
| 34 | |
| 35 | // Only eager tools get full type stubs + doc lines. |
| 36 | const bindings = toolsToBindings(eagerTools, 'external_') |
| 37 | const typeStubs = generateTypeStubs(bindings) |
| 38 | |
| 39 | const functionDocs = Object.entries(bindings) |
| 40 | .map(([name, binding]) => `- \`${name}(input)\`: ${binding.description}`) |
| 41 | .join('\n') |
| 42 | |
| 43 | const discoverableSection = |
| 44 | lazyTools.length > 0 |
| 45 | ? ` |
| 46 | |
| 47 | ### Discoverable APIs |
| 48 | |
| 49 | These additional functions are available but not yet documented. Before calling \`external_<name>\` for any of them inside \`execute_typescript\`, call the \`discover_tools\` tool with their names to get full TypeScript signatures: |
| 50 | |
| 51 | ${lazyTools |
| 52 | .map( |
| 53 | (t) => |
| 54 | `- ${renderLazyCatalogEntry(`external_${t.name}`, t.description, include)}`, |
| 55 | ) |
| 56 | .join('\n')}` |
| 57 | : '' |
| 58 | |
| 59 | return `## Code Execution Tool |
| 60 | |
| 61 | You have access to \`execute_typescript\` which runs TypeScript code in a sandboxed environment. |
| 62 | |
| 63 | ### When to Use |
| 64 | |
| 65 | Use \`execute_typescript\` when you need to: |
| 66 | - Process data with loops, conditionals, or complex logic |
| 67 | - Make multiple API calls in parallel (Promise.all) |
| 68 | - Transform, filter, or aggregate data |
| 69 | - Perform calculations or data analysis |
| 70 | |
| 71 | For simple operations, prefer calling tools directly. |
| 72 | |
| 73 | ### Available External APIs |
| 74 | |
| 75 | Inside your TypeScript code, you can call these async functions: |
| 76 | |
| 77 | ${functionDocs} |
| 78 | |
| 79 | ### Type Definitions |
| 80 | |
| 81 | \`\`\`typescript |
| 82 | ${typeStubs} |
| 83 | \`\`\`${discoverableSection} |
| 84 | |
| 85 | ### Example |
no test coverage detected