import{mcpToolHandlers as s}from"../../../../../client/mcp-tool-handlers-entry.js";import{EXECUTE_TOOL_NAME as c,CODE_MODE_TOOL_NAMES as u}from"../tool-schemas.js";import{sanitizeToolName as f}from"../codemode/build-tool-type-declarations.js";import{runInSandbox as l}from"../codemode/sandbox.js";import{executeMcpTool as m,isMcpToolAvailable as p}from"../../workers/execute-mcp-tool.js";const y=async(t,r,n)=>{const o=await E(r,n),{result:i,error:e}=await l(t.code,o);return{content:[{type:"text",text:JSON.stringify({result:i,error:e})}],isError:e!==void 0}};async function E(t,r){const n={};for(const o of Object.keys(s))u.has(o)||await d(o,t)&&(n[f(o)]=async i=>{const e=await m({toolName:o,args:i,context:t,extra:r}),a=O(e);if(e.isError)throw new Error(a);return T(a)});return n}async function d(t,r){try{return await p({toolName:t,context:r})}catch{return!1}}function O(t){return t.content.filter(r=>r.type==="text").map(r=>r.text).join("")}function T(t){try{return JSON.parse(t)}catch{return t}}var _={[c]:y};export{_ as default};
