UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.71 kB
const WORKFLOW_TOOL_NAME=`Workflow`,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 requestWorkflowSandboxInterrupt(e){let{requestCodeModeInterrupt:t}=await loadWorkflowSandboxModule();return t(e)}async function getWorkflowSandboxInterrupt(e,t){let{getCodeModeInterrupt:n}=await loadWorkflowSandboxModule();return n(e,t)}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 readWorkflowSandboxResolution(e){if(typeof e!=`object`||!e)return;let t=e.codeModeInterrupt;if(typeof t==`object`&&t)return t.resolution}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{continueCodeModeInterrupt:t.experimental_continueCodeModeInterrupt,createCodeModeTool:t.experimental_createCodeModeTool,getCodeModeInterrupt:t.experimental_getCodeModeInterrupt,requestCodeModeInterrupt:t.experimental_requestCodeModeInterrupt,unwrapCodeModeResult:t.experimental_unwrapCodeModeResult}}export{WORKFLOW_TOOL_NAME,continueWorkflowSandboxInterrupt,createWorkflowSandboxTool,getWorkflowSandboxInterrupt,getWorkflowSandboxPendingInterrupts,installWorkflowSandboxModule,readWorkflowSandboxResolution,requestWorkflowSandboxInterrupt,unwrapWorkflowSandboxResult};