UNPKG

eve

Version:

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

6 lines 3.29 kB
import{ct as e,st as t,tt as n}from"./dist-DjECvUyK.js";import{Cn as r,Sn as i,Tn as a,wn as o}from"./logger-DFNCa8Nl.js";import{i as s}from"./dist-xTushGCp.js";function c(e,t){let n=Error.captureStackTrace;n?.(e,t)}const l=Symbol.for(`nodejs.util.inspect.custom`);function u(e){return`code`in e?`\`${e.code}\``:`dim`in e?e.dim:e.text}function d(e){return`code`in e?i(e.code):`dim`in e?r(e.dim):e.text}function f(e){return e.type===`docs`?`docs: ${e.url}`:e.segments.map(u).join(``)}function p(e){return e.type===`docs`?o(e.url):e.segments.map(d).join(``)}function m(e){let t=[e.title.map(u).join(``)];return e.details.forEach((n,r)=>{let i=r===e.details.length-1,a=i?`╰▶ `:`├▶ `,o=i?` `:`│ `;f(n).split(` `).forEach((e,n)=>{t.push(`${n===0?a:o}${e}`)})}),t.join(` `)}function h(e){let t=e.title.map(d).join(``);return a(t,e.details.map(p))}var g=class extends Error{fatal=!0;#e;constructor(e){super(m(e)),this.#e=e}[l](){let e=h(this.#e),t=this.message.split(` `).length,n=(this.stack??``).split(` `).slice(t).join(` `);return n?`${this.name}: ${e}\n${n}`:`${this.name}: ${e}`}toString(){return`${this.name}: ${h(this.#e)}`}},_=class extends g{name=`NotInWorkflowContextError`;constructor(e,t){super({title:[{code:e},{text:` can only be called inside a workflow function`}],details:[{type:`docs`,url:t}]})}},v=class extends g{name=`NotInStepContextError`;constructor(e,t){super({title:[{code:e},{text:` can only be called inside a step function`}],details:[{type:`docs`,url:t}]})}},y=class extends g{name=`NotInWorkflowOrStepContextError`;constructor(e,t){super({title:[{code:e},{text:` can only be called inside a workflow or step function`}],details:[{type:`docs`,url:t}]})}};const b=Symbol.for(`WORKFLOW_CONTEXT`);function x(){let e=globalThis[b];if(!e){let e=new y(`getWorkflowMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-workflow-metadata`);throw c(e,x),e}return e}var S=class extends g{name=`UnavailableInWorkflowContextError`;constructor(e,t){let n=globalThis[b]?.workflowName,r=(()=>{if(!n)return null;let e=n.match(/^(workflow\/|step\/)(.*)$/);return e?[{dim:e[1]},{text:e[2]}]:[{text:n}]})(),i=r?{type:`plain`,segments:[{text:`this call was made from the `},...r,{text:` workflow context.`}]}:{type:`plain`,segments:[{text:`this call was made from a workflow context.`}]};super({title:[{code:e},{text:` cannot be called from a workflow context.`}],details:[{type:`plain`,segments:[{text:`calling this in a workflow context can cause determinism issues.`}]},i,{type:`docs`,url:t}]})}};function C(e,t,n){let r=new _(e,t);throw c(r,n),r}function w(e,t,n){let r=new v(e,t);throw c(r,n),r}function T(e,t,n){let r=new y(e,t);throw c(r,n),r}function E(e,t,n){let r=new S(e,t);throw c(r,n),r}function D(r,i={},a){if(typeof r!=`object`||!r||Array.isArray(r))throw new s(`setAttributes requires a plain object, got ${r===null?`null`:Array.isArray(r)?`array`:typeof r}`);let o=Object.entries(r).map(([e,t])=>({key:e,value:t===void 0?null:t}));if(o.length===0)return o;let c=i.allowReservedAttributes===!0;try{t(o,{allowReservedAttributes:c}),a&&e({changes:o,writer:a,...c?{allowReservedAttributes:!0}:{}})}catch(e){throw e instanceof n?new s(e.message):e}return o}export{T as a,x as c,y as d,C as i,v as l,S as n,E as o,w as r,b as s,D as t,_ as u};