eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.79 kB
JavaScript
const WORKFLOW_SANDBOX_MODULE_KEY=Symbol.for(`eve.workflowSandbox.module`),WORKFLOW_SANDBOX_MODULE_SPECIFIER=[`#compiled`,`@ai-sdk`,`code-mode`,`index.js`].join(`/`);let workflowSandboxModulePromise;function installWorkflowSandboxModule(e){globalThis[WORKFLOW_SANDBOX_MODULE_KEY]=e}async function createWorkflowSandboxTool(e){let{createCodeModeTool:t}=await loadWorkflowSandboxModule();return t(e.hostTools,createWorkflowSandboxOptions(e.bridgeRequestLimit,e.continuationSecurity))}async function continueWorkflowSandboxInterrupt(e){let{continueCodeModeInterrupt:t}=await loadWorkflowSandboxModule();return t({interrupt:e.interrupt,options:createWorkflowSandboxOptions(e.bridgeRequestLimit,e.continuationSecurity),resolution:e.resolution,tools:e.tools})}async function unwrapWorkflowSandboxResult(e,t){let{unwrapCodeModeResult:n}=await loadWorkflowSandboxModule();return n(e,t)}function createParkingHostTool(e){return{description:e.description,inputSchema:e.inputSchema,outputSchema:e.outputSchema??void 0,execute:async(t,n)=>{let r=await loadWorkflowSandboxModule(),i=readWorkflowProgramResolution(n);if(i?.status===`failed`)throw new r.CodeModeToolError(i.error);return i?.status===`completed`?i.output:r.requestCodeModeInterrupt(e.interrupt(t))}}}function readWorkflowProgramResolution(e){if(typeof e!=`object`||!e)return;let t=e.codeModeInterrupt;if(typeof t!=`object`||!t)return;let n=t.resolution;if(typeof n!=`object`||!n)return;let r=n.status;return r===`completed`||r===`failed`?n:void 0}function getWorkflowSandboxPendingInterrupts(e){let t=e.continuation,n=new Set(t.resolutions.map(e=>e.runInterruptionId));return t.pendingInterruptions.flatMap(e=>n.has(e.runInterruptionId)?[]:[{continuation:t,input:e.input,interruptId:e.interruptId,outerToolCallId:t.outerToolCallId,payload:e.payload,toolCallId:e.toolCallId,toolName:e.toolName,type:`code-mode-interrupt`}])}function createWorkflowSandboxOptions(e,t){return{continuationSecurity:t,executionPolicy:{maxBridgeRequests:e,maxInFlightBridgeRequests:e}}}async function loadWorkflowSandboxModule(){let e=globalThis[WORKFLOW_SANDBOX_MODULE_KEY];return e===void 0?(workflowSandboxModulePromise??=importWorkflowSandboxModule(WORKFLOW_SANDBOX_MODULE_SPECIFIER),await workflowSandboxModulePromise):e}async function importWorkflowSandboxModule(e){let t=await import(e);return{CodeModeToolError:t.CodeModeToolError,continueCodeModeInterrupt:t.experimental_continueCodeModeInterrupt,createCodeModeTool:t.experimental_createCodeModeTool,requestCodeModeInterrupt:t.experimental_requestCodeModeInterrupt,unwrapCodeModeResult:t.experimental_unwrapCodeModeResult}}export{continueWorkflowSandboxInterrupt,createParkingHostTool,createWorkflowSandboxTool,getWorkflowSandboxPendingInterrupts,installWorkflowSandboxModule,unwrapWorkflowSandboxResult};