eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.22 kB
JavaScript
const WORKFLOW_CONTEXT_SYMBOL=Symbol.for(`WORKFLOW_CONTEXT`),WORKFLOW_CREATE_HOOK=Symbol.for(`WORKFLOW_CREATE_HOOK`),WORKFLOW_GET_STREAM_ID=Symbol.for(`WORKFLOW_GET_STREAM_ID`),WORKFLOW_USE_STEP=Symbol.for(`WORKFLOW_USE_STEP`),STREAM_NAME_SYMBOL=Symbol.for(`WORKFLOW_STREAM_NAME`),workflowGlobal=globalThis;var RetryableError=class extends Error{},FatalError=class extends Error{};function createHook(e){let n=workflowGlobal[WORKFLOW_CREATE_HOOK];if(n===void 0)throw Error("`createHook()` can only be called inside a workflow function");return n(e)}function getWorkflowMetadata(){let t=workflowGlobal[WORKFLOW_CONTEXT_SYMBOL];if(t===void 0)throw Error("`getWorkflowMetadata()` can only be called inside a workflow or step function");return t}function getWritable(e={}){let t=workflowGlobal[WORKFLOW_GET_STREAM_ID];if(t===void 0)throw Error("`getWritable()` can only be called inside a workflow function");let r=t(e.namespace);return Object.create(globalThis.WritableStream.prototype,{[STREAM_NAME_SYMBOL]:{value:r,writable:!1}})}function createWebhook(e){let t=createHook(e),n=getWorkflowMetadata();return t.url=`${typeof n.url==`string`?n.url:``}/.well-known/workflow/v1/webhook/${encodeURIComponent(t.token)}`,t}function defineHook(){return{create:createHook,resume(){throw Error("`defineHook().resume()` can only be called from external contexts.")}}}function sleep(){throw Error("`sleep()` is not available in eve workflow body bundles")}function resumeHook(){throw Error("`resumeHook()` can only be called from outside a workflow function")}function getStepMetadata(){throw Error("`getStepMetadata()` can only be called inside a step function")}async function experimental_setAttributes(e,t={}){let n=Object.entries(e);if(n.length===0)return;let i=workflowGlobal[WORKFLOW_USE_STEP];if(i===void 0)throw Error("`experimental_setAttributes()` can only be called inside a workflow runtime context");let a=n.map(([e,t])=>({key:e,value:t===void 0?null:t})),o=t.allowReservedAttributes===!0?{allowReservedAttributes:!0}:{};await i(`__builtin_set_attributes`)(a,o)}export{FatalError,RetryableError,createHook,createWebhook,defineHook,experimental_setAttributes,getStepMetadata,getWorkflowMetadata,getWritable,resumeHook,sleep};