{"_id":"@alexma03/utcp-code-mode","_rev":"4-5cd5bdaf03023107c26544ea2aa3ca3b","name":"@alexma03/utcp-code-mode","dist-tags":{"latest":"1.2.14"},"versions":{"1.2.11":{"name":"@alexma03/utcp-code-mode","version":"1.2.11","keywords":["utcp","code","typescript","execution","tool calling","chain","isolated-vm","sandbox"],"author":{"name":"Alexma03"},"license":"MPL-2.0","_id":"@alexma03/utcp-code-mode@1.2.11","maintainers":[{"name":"alexma03","email":"alex03marcos@gmail.com"}],"homepage":"https://github.com/Alexma03/alexma03-utcp#readme","bugs":{"url":"https://github.com/Alexma03/alexma03-utcp/issues"},"dist":{"shasum":"81503da3381e9d0a3c78ab461024f6a6cd79c70e","tarball":"https://registry.npmjs.org/@alexma03/utcp-code-mode/-/utcp-code-mode-1.2.11.tgz","fileCount":8,"integrity":"sha512-b1ofCBKVPkAb2qk3fpIHBWoUUC+cPYsPwAb2wUlJzBfGLRHAq5UsGQeIzfLV/0ClT2G/7x9/UFvqV6vf/4/9Vg==","signatures":[{"sig":"MEYCIQCK/Y4CDlJCcsfll8pA8lUQra4R0elnmvVS/bqD4F3RnQIhALtTZsuV0exdQHIXcohuNzUM89Q5l9QfyXMZ+JSeEuBB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":122044},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=24.14.0 <25"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"97f8055784030184a8917378a6de581d7ae7f22d","scripts":{"test":"jest","build":"tsup","prepublishOnly":"npm run build"},"_npmUser":{"name":"alexma03","email":"alex03marcos@gmail.com"},"repository":{"url":"git+https://github.com/Alexma03/alexma03-utcp.git","type":"git","directory":"packages/code-mode"},"_npmVersion":"11.9.0","description":"Code execution mode for UTCP - enables executing TypeScript code chains with tool access using isolated-vm for security","directories":{},"_nodeVersion":"24.14.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.7.0","tsup":"8.5.0","ts-jest":"29.1.2","typescript":"5.0.4","@types/jest":"29.5.12","@types/node":"20.0.0","isolated-vm":"6.1.2","@alexma03/utcp-sdk":"workspace:*","@alexma03/utcp-direct-call":"workspace:*"},"peerDependencies":{"isolated-vm":"6.1.2","@alexma03/utcp-sdk":"workspace:*"},"peerDependenciesMeta":{"isolated-vm":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/utcp-code-mode_1.2.11_1773650889142_0.022983119457546275","host":"s3://npm-registry-packages-npm-production"}},"1.2.12":{"name":"@alexma03/utcp-code-mode","version":"1.2.12","keywords":["utcp","code","typescript","execution","tool calling","chain","isolated-vm","sandbox"],"author":{"name":"Alexma03"},"license":"MPL-2.0","_id":"@alexma03/utcp-code-mode@1.2.12","maintainers":[{"name":"alexma03","email":"alex03marcos@gmail.com"}],"homepage":"https://github.com/Alexma03/alexma03-utcp#readme","bugs":{"url":"https://github.com/Alexma03/alexma03-utcp/issues"},"dist":{"shasum":"6fe9ef454e734d5235dbeb0ff30de48f1d743d63","tarball":"https://registry.npmjs.org/@alexma03/utcp-code-mode/-/utcp-code-mode-1.2.12.tgz","fileCount":8,"integrity":"sha512-OVB5DShZKmXrntN43Dq1q/OJOJoPIXmN61zuCyidvXOu+ceiRRfCEuAy8lJBiIecCnpQ2c9cEInd/vvrnxTf8g==","signatures":[{"sig":"MEUCICTZjx9yQiM0cuL/rdlnMD+hdKUxAB/8NhBnHBHbNt3BAiEA+12FE1WAkPWVI9tBUHl6Umk4ugmbWD1GRn6UomuewYg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":122029},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=24.14.0 <25"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"e836da75819768e8584255bfb61e7bdee947b035","scripts":{"test":"jest","build":"tsup","prepublishOnly":"npm run build"},"_npmUser":{"name":"alexma03","email":"alex03marcos@gmail.com"},"repository":{"url":"git+https://github.com/Alexma03/alexma03-utcp.git","type":"git","directory":"packages/code-mode"},"_npmVersion":"11.9.0","description":"Code execution mode for UTCP - enables executing TypeScript code chains with tool access using isolated-vm for security","directories":{},"_nodeVersion":"24.14.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.7.0","tsup":"8.5.0","ts-jest":"29.1.2","typescript":"5.0.4","@types/jest":"29.5.12","@types/node":"20.0.0","isolated-vm":"6.1.2","@alexma03/utcp-sdk":"^1.1.0","@alexma03/utcp-direct-call":"^1.1.2"},"peerDependencies":{"isolated-vm":"6.1.2","@alexma03/utcp-sdk":"^1.1.0"},"peerDependenciesMeta":{"isolated-vm":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/utcp-code-mode_1.2.12_1773652223011_0.1289672270964548","host":"s3://npm-registry-packages-npm-production"}},"1.2.13":{"name":"@alexma03/utcp-code-mode","version":"1.2.13","keywords":["utcp","code","typescript","execution","tool calling","chain","isolated-vm","sandbox"],"author":{"name":"Alexma03"},"license":"MPL-2.0","_id":"@alexma03/utcp-code-mode@1.2.13","maintainers":[{"name":"alexma03","email":"alex03marcos@gmail.com"}],"homepage":"https://github.com/Alexma03/alexma03-utcp#readme","bugs":{"url":"https://github.com/Alexma03/alexma03-utcp/issues"},"dist":{"shasum":"a66b0659f7d26057207c0dba5b5b2ded14d5aa10","tarball":"https://registry.npmjs.org/@alexma03/utcp-code-mode/-/utcp-code-mode-1.2.13.tgz","fileCount":8,"integrity":"sha512-syP7FWykioGTblQ/M29rMWgWOBak2VkVKnvVyhMQz9T6VMyN04x789e7Hl6LEJ/b2M/122EihkOcu1hvlHjwdw==","signatures":[{"sig":"MEUCIH8IeSJaswaSomgHy6LuR+pt3hmU7C/M14pjyC/AXE0BAiEAkVU+ESLdclECxMDzDPwSfAYVBJXInH78WaZnLaapfpI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":123831},"main":"dist/index.cjs","type":"module","_from":"file:alexma03-utcp-code-mode-1.2.13.tgz","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=24.14.0 <25"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","default":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"test":"jest","build":"tsup"},"_npmUser":{"name":"alexma03","email":"alex03marcos@gmail.com"},"_resolved":"/private/var/folders/mw/dp007xzd5sz9vkhkjfz0fdh40000gn/T/3a8e9b30bf21a802decfc8546fab0da2/alexma03-utcp-code-mode-1.2.13.tgz","_integrity":"sha512-syP7FWykioGTblQ/M29rMWgWOBak2VkVKnvVyhMQz9T6VMyN04x789e7Hl6LEJ/b2M/122EihkOcu1hvlHjwdw==","repository":{"url":"git+https://github.com/Alexma03/alexma03-utcp.git","type":"git","directory":"packages/code-mode"},"_npmVersion":"11.9.0","description":"Code execution mode for UTCP - enables executing TypeScript code chains with tool access using isolated-vm for security","directories":{},"_nodeVersion":"24.14.0","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.7.0","tsup":"8.5.0","ts-jest":"29.1.2","typescript":"5.0.4","@types/jest":"29.5.12","@types/node":"20.0.0","isolated-vm":"6.1.2","@alexma03/utcp-sdk":"^1.1.1","@alexma03/utcp-direct-call":"^1.1.2"},"peerDependencies":{"isolated-vm":"6.1.2","@alexma03/utcp-sdk":"^1.1.1"},"peerDependenciesMeta":{"isolated-vm":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/utcp-code-mode_1.2.13_1773735238342_0.5389549737694455","host":"s3://npm-registry-packages-npm-production"}},"1.2.14":{"name":"@alexma03/utcp-code-mode","version":"1.2.14","description":"Code execution mode for UTCP - enables executing TypeScript code chains with tool access using isolated-vm for security","type":"module","main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","license":"MPL-2.0","author":{"name":"Alexma03"},"repository":{"type":"git","url":"git+https://github.com/Alexma03/alexma03-utcp.git","directory":"packages/code-mode"},"keywords":["utcp","code","typescript","execution","tool calling","chain","isolated-vm","sandbox"],"publishConfig":{"access":"public"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"}},"dependencies":{},"peerDependencies":{"@alexma03/utcp-sdk":"^1.1.1","isolated-vm":"6.1.2"},"peerDependenciesMeta":{"isolated-vm":{"optional":false}},"devDependencies":{"@types/jest":"29.5.12","@types/node":"20.0.0","@alexma03/utcp-sdk":"^1.1.1","@alexma03/utcp-direct-call":"^1.1.2","isolated-vm":"6.1.2","jest":"29.7.0","ts-jest":"29.1.2","tsup":"8.5.0","typescript":"5.0.4"},"engines":{"node":">=24.14.0 <25"},"scripts":{"build":"tsup","test":"jest"},"_id":"@alexma03/utcp-code-mode@1.2.14","bugs":{"url":"https://github.com/Alexma03/alexma03-utcp/issues"},"homepage":"https://github.com/Alexma03/alexma03-utcp#readme","_integrity":"sha512-QPH6JyYnpFz6bOqhb+21NtsETKST+fAaSQhakNxF52fWRWb0KsXSqajBCY+Gv/pwXN/+paIUiXUzckRvQ+FVQA==","_resolved":"/private/var/folders/mw/dp007xzd5sz9vkhkjfz0fdh40000gn/T/d6d9a97277431c89187000ad96b2c6b6/alexma03-utcp-code-mode-1.2.14.tgz","_from":"file:alexma03-utcp-code-mode-1.2.14.tgz","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-QPH6JyYnpFz6bOqhb+21NtsETKST+fAaSQhakNxF52fWRWb0KsXSqajBCY+Gv/pwXN/+paIUiXUzckRvQ+FVQA==","shasum":"08eb22b08fdb1b4880987e4cce6caeefa586bb91","tarball":"https://registry.npmjs.org/@alexma03/utcp-code-mode/-/utcp-code-mode-1.2.14.tgz","fileCount":8,"unpackedSize":129055,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICNvkIon/I1UbzDSHYt0fKz/qBbsJJCKX8/3eYkUvU0TAiEAllozYgY2ljRcJGGgkBLjB9S+rrvDEgl8UUztC/qZMwo="}]},"_npmUser":{"name":"alexma03","email":"alex03marcos@gmail.com"},"directories":{},"maintainers":[{"name":"alexma03","email":"alex03marcos@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/utcp-code-mode_1.2.14_1774116789174_0.8061520423080195"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-16T08:48:09.026Z","modified":"2026-03-21T18:13:09.512Z","1.2.11":"2026-03-16T08:48:09.307Z","1.2.12":"2026-03-16T09:10:23.165Z","1.2.13":"2026-03-17T08:13:58.483Z","1.2.14":"2026-03-21T18:13:09.389Z"},"bugs":{"url":"https://github.com/Alexma03/alexma03-utcp/issues"},"author":{"name":"Alexma03"},"license":"MPL-2.0","homepage":"https://github.com/Alexma03/alexma03-utcp#readme","keywords":["utcp","code","typescript","execution","tool calling","chain","isolated-vm","sandbox"],"repository":{"type":"git","url":"git+https://github.com/Alexma03/alexma03-utcp.git","directory":"packages/code-mode"},"description":"Code execution mode for UTCP - enables executing TypeScript code chains with tool access using isolated-vm for security","maintainers":[{"name":"alexma03","email":"alex03marcos@gmail.com"}],"readme":"# @alexma03/utcp-code-mode\n\nExecute TypeScript code with direct access to UTCP tools using isolated-vm for secure sandboxed execution.\n\n## Installation\n\n```bash\nnpm install @alexma03/utcp-code-mode @alexma03/utcp-sdk @alexma03/utcp-direct-call isolated-vm\n```\n\n## Quick Start\n\n```typescript\nimport { CodeModeUtcpClient } from '@alexma03/utcp-code-mode';\nimport { addFunctionToUtcpDirectCall } from '@alexma03/utcp-direct-call';\n\n// Register a function that returns a UTCP manual\naddFunctionToUtcpDirectCall('getWeatherManual', async () => ({\n  utcp_version: '0.2.0',\n  tools: [{\n    name: 'get_current',\n    description: 'Get current weather for a city',\n    inputs: {\n      type: 'object',\n      properties: { city: { type: 'string' } },\n      required: ['city']\n    },\n    tool_call_template: {\n      call_template_type: 'direct-call',\n      callable_name: 'getWeather'\n    }\n  }]\n}));\n\n// Register the actual tool implementation\naddFunctionToUtcpDirectCall('getWeather', async (city: string) => ({\n  city,\n  temperature: 22,\n  condition: 'sunny'\n}));\n\n// Create client and register manual\nconst client = await CodeModeUtcpClient.create();\nawait client.registerManual({\n  name: 'weather',\n  call_template_type: 'direct-call',\n  callable_name: 'getWeatherManual'\n});\n\n// Execute code with tool access\nconst { result, logs } = await client.callToolChain(`\n  const data = weather.get_current({ city: 'London' });\n  console.log('Weather:', data);\n  return data;\n`);\n\nconsole.log(result);\n// { city: 'London', temperature: 22, condition: 'sunny' }\n```\n\n## API\n\n### `CodeModeUtcpClient.create(root_dir?, config?)`\n\nCreates a new client instance.\n\n```typescript\nconst client = await CodeModeUtcpClient.create(\n  process.cwd(),  // optional: root directory\n  null            // optional: UtcpClientConfig\n);\n```\n\n### `client.callToolChain(code, timeout?, memoryLimit?)`\n\nExecutes TypeScript code with tool access.\n\n```typescript\nconst result = await client.callToolChain(\n  code,\n  30000,\n  128\n);\n```\n\n**Returns:**\n```typescript\n{\n  result: any;      // return value from code\n  logs: string[];   // captured console.log/error/warn output\n}\n```\n\nIf execution fails, `callToolChain` throws `CodeModeExecutionError` and includes captured `logs`.\n\n### `client.getAllToolsTypeScriptInterfaces()`\n\nReturns TypeScript interface definitions for all registered tools.\n\n```typescript\nconst interfaces = await client.getAllToolsTypeScriptInterfaces();\nconsole.log(interfaces);\n// \"interface Weather_get_current_Input { city: string; } ...\"\n```\n\n### `CodeModeUtcpClient.AGENT_PROMPT_TEMPLATE`\n\nStatic prompt template for AI agents explaining how to use code-mode.\n\n```typescript\nconst systemPrompt = CodeModeUtcpClient.AGENT_PROMPT_TEMPLATE;\n```\n\n## Tool Access Patterns\n\nTools are accessed using their namespace:\n\n```typescript\n// Namespaced tools (from manuals)\nmanual_name.tool_name({ param: value })\n\n// Examples\nweather.get_current({ city: 'Tokyo' })\nprocurement.search_parts({ mpn: 'ABC123' })\n```\n\n## Runtime Context\n\nInside `callToolChain`, you have access to:\n\n| Variable | Description |\n|----------|-------------|\n| `__interfaces` | String with all TypeScript interface definitions |\n| `__getToolInterface(name)` | Get interface for specific tool |\n| `__availableTools` | Array of available tool access patterns |\n| `console.log/error/warn` | Captured and returned in `logs` |\n| Standard JS globals | `JSON`, `Math`, `Date`, `Array`, etc. |\n\n## Example: Chaining Tools\n\n```typescript\nconst result = await client.callToolChain(`\n  // Get parts from supplier\n  const parts = procurement.search_parts({ mpn: 'LM358' });\n  \n  // Get pricing for each part\n  const pricing = parts.map(part => \n    procurement.get_pricing({ part_id: part.id })\n  );\n  \n  // Return combined result\n  return { parts, pricing };\n`);\n```\n\n## Using File Templates\n\nFor loading tools from UTCP manual files:\n\n```typescript\nimport { CodeModeUtcpClient } from '@alexma03/utcp-code-mode';\nimport '@alexma03/utcp-file';\n\nconst client = await CodeModeUtcpClient.create();\n\n// Register from a UTCP manual file\nawait client.registerManual({\n  name: 'myapi',\n  call_template_type: 'file',\n  file_path: './my-api-manual.utcp.json'\n});\n\n// Use tools defined in the manual\nconst result = await client.callToolChain(`\n  return myapi.some_tool({ param: 'value' });\n`);\n```\n\n## Security\n\nCode execution uses [isolated-vm](https://github.com/laverdet/isolated-vm) for sandboxing:\n\n- Isolated V8 context (no access to Node.js APIs)\n- Memory limits enforced\n- Execution timeouts\n- No file system or network access from sandbox\n\n## License\n\nMPL-2.0\n","readmeFilename":"README.md"}