( config: CodeModeToolConfig, )
| 82 | * ``` |
| 83 | */ |
| 84 | export function createCodeModeTool( |
| 85 | config: CodeModeToolConfig, |
| 86 | ): ServerTool< |
| 87 | typeof executeTypescriptInputSchema, |
| 88 | typeof executeTypescriptOutputSchema, |
| 89 | 'execute_typescript' |
| 90 | > { |
| 91 | const { |
| 92 | driver, |
| 93 | tools, |
| 94 | timeout = 30000, |
| 95 | memoryLimit = 128, |
| 96 | getSkillBindings, |
| 97 | onSecretParameter, |
| 98 | transpile = stripTypeScript, |
| 99 | } = config |
| 100 | |
| 101 | // Validate tools |
| 102 | if (tools.length === 0) { |
| 103 | throw new Error('At least one tool must be provided to createCodeModeTool') |
| 104 | } |
| 105 | |
| 106 | // Transform tools to bindings with external_ prefix (static bindings) |
| 107 | const staticBindings = toolsToBindings(tools, 'external_') |
| 108 | |
| 109 | // Shared across static + dynamic (skill) binding scans so a given |
| 110 | // (toolName, paramPath) pair surfaces at most once per code-mode instance. |
| 111 | const secretDedupCache = new Set<string>() |
| 112 | |
| 113 | warnIfBindingsExposeSecrets(Object.values(staticBindings), { |
| 114 | handler: onSecretParameter, |
| 115 | dedupCache: secretDedupCache, |
| 116 | }) |
| 117 | |
| 118 | // Create the tool definition |
| 119 | const definition = toolDefinition({ |
| 120 | name: 'execute_typescript' as const, |
| 121 | description: buildToolDescription(tools), |
| 122 | inputSchema: executeTypescriptInputSchema, |
| 123 | outputSchema: executeTypescriptOutputSchema, |
| 124 | }) |
| 125 | |
| 126 | // Return server tool with execute function that accepts context |
| 127 | return definition.server( |
| 128 | async ( |
| 129 | input, |
| 130 | toolContext?: ToolExecutionContext, |
| 131 | ): Promise<CodeModeToolResult> => { |
| 132 | const { typescriptCode } = input |
| 133 | |
| 134 | // Get emitCustomEvent from context or use no-op |
| 135 | const emitCustomEvent = toolContext?.emitCustomEvent || (() => {}) |
| 136 | |
| 137 | if (!typescriptCode || typeof typescriptCode !== 'string') { |
| 138 | return { |
| 139 | success: false, |
| 140 | error: { |
| 141 | message: 'typescriptCode must be a non-empty string', |
no test coverage detected