@zibby/agent-workflow 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -1,34 +1,34 @@
1
- var _t=Object.defineProperty;var R=(r,t,e)=>()=>{if(e)throw e[0];try{return r&&(t=r(r=0)),t}catch(n){throw e=[n],n}};var wt=(r,t)=>{for(var e in t)_t(r,e,{get:t[e],enumerable:!0})};var z,St,M,x,f,P=R(()=>{z=()=>{},St={debug:z,info:z,warn:(...r)=>console.warn("[workflow]",...r),error:(...r)=>console.error("[workflow]",...r)},M=Symbol.for("@zibby/agent-workflow.logger");globalThis[M]||(globalThis[M]={impl:St});x=globalThis[M],f={debug:(...r)=>x.impl.debug?.(...r),info:(...r)=>x.impl.info?.(...r),warn:(...r)=>x.impl.warn?.(...r),error:(...r)=>x.impl.error?.(...r)}});var st=R(()=>{});function at(r){return xt.get(r)||null}var G,U,xt,zt,ut=R(()=>{G=Symbol.for("@zibby/agent-workflow.skills"),U=Symbol.for("@zibby/agent-workflow.skills.sources");globalThis[G]||(globalThis[G]=new Map);globalThis[U]||(globalThis[U]=new Map);xt=globalThis[G],zt=globalThis[U]});var pt={};wt(pt,{getAgentStrategy:()=>dt,invokeAgent:()=>Wt,listStrategies:()=>Pt,registerStrategy:()=>Mt,resolveInvocationExtras:()=>lt,resolveInvocationModel:()=>ct});function Mt(r){if(!r||typeof r.getName!="function"||typeof r.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=$.findIndex(e=>e.getName()===r.getName());t>=0?$[t]=r:$.push(r)}function Pt(){return $.map(r=>r.getName())}function ct({config:r={},options:t={},strategyName:e,envModel:n,nodeConfigModel:o}={}){let i=r.models||{},a=typeof o=="string"&&o.trim()?o.trim():null,m=t.nodeName&&i[t.nodeName]||null,l=i.default||null,S=r.agent?.[e]?.model||null,E=(typeof n=="string"?n.trim():"")||null;return a||m||l||S||t.model||E||null}function lt({options:r={},stateView:t={},context:e={}}={}){return{workspace:t.workspace||r.workspace,schema:r.schema||e.schema,images:r.images||e.images||[],skills:r.skills||e.skills||[],extraMcpServers:r.extraMcpServers||t.extraMcpServers||e.extraMcpServers||[],plugins:r.plugins||e.plugins||[]}}function dt(r={}){let{state:t={},preferredAgent:e=null}=r,n=e||t.agentType||process.env.AGENT_TYPE;if(!n){let i=$.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${i}`)}f.debug(`[workflow] agent selection: requested=${n}`);let o=$.find(i=>i.getName()===n);if(!o){let i=$.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${n}'. Available: ${i}`)}if(!o.canHandle(r))throw new Error(`Agent '${n}' is not available in this environment. Check credentials/environment.`);return f.debug(`[workflow] using agent: ${o.getName()}`),o}async function Wt(r,t={},e={}){let n=t.state&&typeof t.state.getAll=="function"?t.state.getAll():t.state||{},o={...t,state:n},i=dt(o),a=n.config||e.config||{},m=n._currentNodeConfig||{},l=typeof m.agent=="string"?m.agent.trim():"",S=!l||l===i.name?m.model:null,E=ct({config:a,options:e,strategyName:i.name,envModel:process.env.MODEL,nodeConfigModel:S}),I={...e,model:E,...lt({options:e,stateView:n,context:t}),config:a},N=r,c=I.skills||[];if(c.length>0&&!e.skipPromptFragments){let w=e.connectedIntegrations;if(!w){let p=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof p=="string"&&p.trim()!==""){w={};for(let u of p.split(",").map(b=>b.trim()).filter(Boolean))w[u]=!0}}let T=p=>{let u=p&&p.requiresIntegration;return!u||!w?!0:(Array.isArray(u)?u:[u]).some(O=>w[O]===!0)},s=i.name==="assistant",_=p=>p?.inProcessOnly!==!0||s,h=c.map(p=>{let u=at(p);if(!T(u)||!_(u))return null;let b=u?.promptFragment;return typeof b=="function"?b():b}).filter(Boolean);h.length>0&&(N+=`
1
+ var Et=Object.defineProperty;var x=(r,t,e)=>()=>{if(e)throw e[0];try{return r&&(t=r(r=0)),t}catch(n){throw e=[n],n}};var Nt=(r,t)=>{for(var e in t)Et(r,e,{get:t[e],enumerable:!0})};var Y,Tt,W,P,d,C=x(()=>{Y=()=>{},Tt={debug:Y,info:Y,warn:(...r)=>console.warn("[workflow]",...r),error:(...r)=>console.error("[workflow]",...r)},W=Symbol.for("@zibby/agent-workflow.logger");globalThis[W]||(globalThis[W]={impl:Tt});P=globalThis[W],d={debug:(...r)=>P.impl.debug?.(...r),info:(...r)=>P.impl.info?.(...r),warn:(...r)=>P.impl.warn?.(...r),error:(...r)=>P.impl.error?.(...r)}});var ut=x(()=>{});function ct(r){return Ct.get(r)||null}var H,K,Ct,Zt,dt=x(()=>{H=Symbol.for("@zibby/agent-workflow.skills"),K=Symbol.for("@zibby/agent-workflow.skills.sources");globalThis[H]||(globalThis[H]=new Map);globalThis[K]||(globalThis[K]=new Map);Ct=globalThis[H],Zt=globalThis[K]});var gt={};Nt(gt,{EFFORT_LEVELS:()=>z,getAgentStrategy:()=>ht,invokeAgent:()=>Dt,listStrategies:()=>Ft,registerStrategy:()=>Lt,resolveInvocationEffort:()=>ft,resolveInvocationExtras:()=>mt,resolveInvocationModel:()=>pt});function Lt(r){if(!r||typeof r.getName!="function"||typeof r.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=$.findIndex(e=>e.getName()===r.getName());t>=0?$[t]=r:$.push(r)}function Ft(){return $.map(r=>r.getName())}function pt({config:r={},options:t={},strategyName:e,envModel:n,nodeConfigModel:o}={}){let i=r.models||{},s=typeof o=="string"&&o.trim()?o.trim():null,p=t.nodeName&&i[t.nodeName]||null,u=i.default||null,b=r.agent?.[e]?.model||null,N=(typeof n=="string"?n.trim():"")||null;return s||p||u||b||t.model||N||null}function ft({options:r={},envEffort:t,nodeConfigEffort:e}={}){let n=[e,r.effort,t].map(o=>typeof o=="string"?o.trim().toLowerCase():"").find(Boolean);return n?z.indexOf(n)===-1?(d.warn(`[workflow] ignoring unknown effort "${n}" \u2014 expected one of ${z.join(", ")}`),null):n:null}function mt({options:r={},stateView:t={},context:e={}}={}){return{workspace:t.workspace||r.workspace,schema:r.schema||e.schema,images:r.images||e.images||[],skills:r.skills||e.skills||[],extraMcpServers:r.extraMcpServers||t.extraMcpServers||e.extraMcpServers||[],plugins:r.plugins||e.plugins||[]}}function ht(r={}){let{state:t={},preferredAgent:e=null}=r,n=e||t.agentType||process.env.AGENT_TYPE;if(!n){let i=$.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${i}`)}d.debug(`[workflow] agent selection: requested=${n}`);let o=$.find(i=>i.getName()===n);if(!o){let i=$.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${n}'. Available: ${i}`)}if(!o.canHandle(r))throw new Error(`Agent '${n}' is not available in this environment. Check credentials/environment.`);return d.debug(`[workflow] using agent: ${o.getName()}`),o}async function Dt(r,t={},e={}){let n=t.state&&typeof t.state.getAll=="function"?t.state.getAll():t.state||{},o={...t,state:n},i=ht(o),s=n.config||e.config||{},p=n._currentNodeConfig||{},u=typeof p.agent=="string"?p.agent.trim():"",b=!u||u===i.name?p.model:null,N=pt({config:s,options:e,strategyName:i.name,envModel:process.env.MODEL,nodeConfigModel:b}),O=!u||u===i.name?p.effort:null,A=ft({options:e,envEffort:process.env.EFFORT,nodeConfigEffort:O}),c={...e,model:N,...A?{effort:A}:{},...mt({options:e,stateView:n,context:t}),config:s},f=r,g=c.skills||[];if(g.length>0&&!e.skipPromptFragments){let l=e.connectedIntegrations;if(!l){let _=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof _=="string"&&_.trim()!==""){l={};for(let S of _.split(",").map(T=>T.trim()).filter(Boolean))l[S]=!0}}let y=_=>{let S=_&&_.requiresIntegration;return!S||!l?!0:(Array.isArray(S)?S:[S]).some(v=>l[v]===!0)},a=i.name==="assistant",w=_=>_?.inProcessOnly!==!0||a,m=g.map(_=>{let S=ct(_);if(!y(S)||!w(S))return null;let T=S?.promptFragment;return typeof T=="function"?T():T}).filter(Boolean);m.length>0&&(f+=`
2
2
 
3
- ${h.join(`
3
+ ${m.join(`
4
4
 
5
- `)}`)}let d=n._currentNodeConfig?.stores;if(Array.isArray(d)&&d.length>0&&typeof d[0]=="object"){let w=d.length<=8,T=d.map(s=>{let _=s?.id??s?.storeId??"",h=(s?.name??"").toString().trim()||_,p=s?.type?` \xB7 ${s.type}`:"",u=(s?.description||"").toString().replace(/\s+/g," ").trim(),b=`- ${h} \xB7 ${u||"(no description)"}${p} (id: ${_})`;if(w&&s?.schema&&typeof s.schema=="object"){let O=s.schema.properties&&typeof s.schema.properties=="object"?Object.keys(s.schema.properties):Object.keys(s.schema);O.length&&(b+=`
6
- fields: ${O.join(", ")}`)}return b});N+=`
5
+ `)}`)}let E=n._currentNodeConfig?.stores;if(Array.isArray(E)&&E.length>0&&typeof E[0]=="object"){let l=E.length<=8,y=E.map(a=>{let w=a?.id??a?.storeId??"",m=(a?.name??"").toString().trim()||w,_=a?.type?` \xB7 ${a.type}`:"",S=(a?.description||"").toString().replace(/\s+/g," ").trim(),T=`- ${m} \xB7 ${S||"(no description)"}${_} (id: ${w})`;if(l&&a?.schema&&typeof a.schema=="object"){let v=a.schema.properties&&typeof a.schema.properties=="object"?Object.keys(a.schema.properties):Object.keys(a.schema);v.length&&(T+=`
6
+ fields: ${v.join(", ")}`)}return T});f+=`
7
7
 
8
8
  AVAILABLE STORES (pick a store by its description and pass its NAME to the store tool):
9
- ${T.join(`
10
- `)}`}let y=n._currentNodeConfig?.extraPromptInstructions?.trim();return y&&(N+=`
9
+ ${y.join(`
10
+ `)}`}let I=n._currentNodeConfig?.extraPromptInstructions?.trim();return I&&(f+=`
11
11
 
12
12
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
13
13
  PRIORITY OVERRIDE \u2014 THE FOLLOWING INSTRUCTIONS TAKE PRECEDENCE OVER ALL PREVIOUS CONTENT
14
14
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
15
15
 
16
- ${y}
17
- `),f.debug(`[workflow] prompt length: ${N.length} chars`),i.invoke(N,I)}var H,$,ft=R(()=>{st();P();ut();H=Symbol.for("@zibby/agent-workflow.strategies");globalThis[H]||(globalThis[H]=[]);$=globalThis[H]});import k from"handlebars";var v=class{constructor(t){this.schema=t}parse(t){let e=t.match(/```json\s*([\s\S]*?)\s*```/);if(e)return this.validate(JSON.parse(e[1]));let n=[t.match(/\{[\s\S]*?\}/),t.match(/\{[\s\S]*\}/)].filter(Boolean).map(o=>o[0]);for(let o of n)try{return this.validate(JSON.parse(o))}catch(i){if(!(i instanceof SyntaxError))throw i}return this.validate({result:t.trim()})}validate(t){let e=[];for(let[n,o]of Object.entries(this.schema)){if(o.required&&!(n in t)&&e.push(`Missing required field: ${n}`),n in t&&o.type){let i=typeof t[n];i!==o.type&&e.push(`Field '${n}' expected ${o.type}, got ${i}`)}if(o.validate&&n in t){let i=o.validate(t[n]);i&&e.push(`Field '${n}': ${i}`)}}if(e.length>0)throw new Error(`Output validation failed:
16
+ ${I}
17
+ `),d.debug(`[workflow] prompt length: ${f.length} chars`),i.invoke(f,c)}var J,$,z,yt=x(()=>{ut();C();dt();J=Symbol.for("@zibby/agent-workflow.strategies");globalThis[J]||(globalThis[J]=[]);$=globalThis[J];z=["low","medium","high","xhigh","max"]});import k from"handlebars";var M=class{constructor(t){this.schema=t}parse(t){let e=t.match(/```json\s*([\s\S]*?)\s*```/);if(e)return this.validate(JSON.parse(e[1]));let n=[t.match(/\{[\s\S]*?\}/),t.match(/\{[\s\S]*\}/)].filter(Boolean).map(o=>o[0]);for(let o of n)try{return this.validate(JSON.parse(o))}catch(i){if(!(i instanceof SyntaxError))throw i}return this.validate({result:t.trim()})}validate(t){let e=[];for(let[n,o]of Object.entries(this.schema)){if(o.required&&!(n in t)&&e.push(`Missing required field: ${n}`),n in t&&o.type){let i=typeof t[n];i!==o.type&&e.push(`Field '${n}' expected ${o.type}, got ${i}`)}if(o.validate&&n in t){let i=o.validate(t[n]);i&&e.push(`Field '${n}': ${i}`)}}if(e.length>0)throw new Error(`Output validation failed:
18
18
  ${e.join(`
19
- `)}`);return t}};P();import{writeFileSync as K,readFileSync as mt,existsSync as ht,mkdirSync as Ct}from"node:fs";import{join as J,dirname as Lt}from"node:path";import g from"chalk";var bt="__WORKFLOW_GRAPH_LOG__",A=g.gray("\u2502"),Et=g.gray("\u250C"),q=g.gray("\u2514"),W=g.green("\u25C6"),Y=g.hex("#c084fc")("\u25C6"),V=g.hex("#2dd4bf")("\u25C6"),C=g.red("\u25C6"),Z=`${A} `,X=2;function Q(r){return r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function tt(r,t){return(e,n,o)=>{if(typeof e!="string")return r(e,n,o);let i=process.stdout.columns||120,a="";for(let m=0;m<e.length;m++){let l=e[m];t.lineStart&&(a+=Z,t.col=X,t.lineStart=!1),l===`
20
- `?(a+=l,t.lineStart=!0,t.col=0,t.inEsc=!1):l==="\x1B"?(t.inEsc=!0,a+=l):t.inEsc?(a+=l,(l>="A"&&l<="Z"||l>="a"&&l<="z")&&(t.inEsc=!1)):(t.col++,a+=l,t.col>=i&&(a+=`
21
- ${Z}`,t.col=X))}return r(a,n,o)}}var L=class{constructor(){this._currentNode=null,this._origStdoutWrite=null,this._origStderrWrite=null,this._emitWorkflowGraphMarkers=String(process.env.ZIBBY_EMIT_GRAPH_MARKERS||"").trim()==="1"||String(process.env.ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS||"").trim()==="1"}get isInsideNode(){return this._currentNode!==null}_startIntercepting(){this._origStdoutWrite=process.stdout.write.bind(process.stdout),this._origStderrWrite=process.stderr.write.bind(process.stderr);let t={lineStart:!0,col:0,inEsc:!1},e={lineStart:!0,col:0,inEsc:!1};this._outState=t,this._errState=e,process.stdout.write=tt(this._origStdoutWrite,t),process.stderr.write=tt(this._origStderrWrite,e)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
19
+ `)}`);return t}};C();import{writeFileSync as q,readFileSync as _t,existsSync as wt,mkdirSync as jt}from"node:fs";import{join as V,dirname as Bt}from"node:path";import h from"chalk";var $t="__WORKFLOW_GRAPH_LOG__",R=h.gray("\u2502"),kt=h.gray("\u250C"),Z=h.gray("\u2514"),L=h.green("\u25C6"),X=h.hex("#c084fc")("\u25C6"),Q=h.hex("#2dd4bf")("\u25C6"),F=h.red("\u25C6"),tt=`${R} `,et=2;function rt(r){return r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function nt(r,t){return(e,n,o)=>{if(typeof e!="string")return r(e,n,o);let i=process.stdout.columns||120,s="";for(let p=0;p<e.length;p++){let u=e[p];t.lineStart&&(s+=tt,t.col=et,t.lineStart=!1),u===`
20
+ `?(s+=u,t.lineStart=!0,t.col=0,t.inEsc=!1):u==="\x1B"?(t.inEsc=!0,s+=u):t.inEsc?(s+=u,(u>="A"&&u<="Z"||u>="a"&&u<="z")&&(t.inEsc=!1)):(t.col++,s+=u,t.col>=i&&(s+=`
21
+ ${tt}`,t.col=et))}return r(s,n,o)}}var D=class{constructor(){this._currentNode=null,this._origStdoutWrite=null,this._origStderrWrite=null,this._emitWorkflowGraphMarkers=String(process.env.ZIBBY_EMIT_GRAPH_MARKERS||"").trim()==="1"||String(process.env.ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS||"").trim()==="1"}get isInsideNode(){return this._currentNode!==null}_startIntercepting(){this._origStdoutWrite=process.stdout.write.bind(process.stdout),this._origStderrWrite=process.stderr.write.bind(process.stderr);let t={lineStart:!0,col:0,inEsc:!1},e={lineStart:!0,col:0,inEsc:!1};this._outState=t,this._errState=e,process.stdout.write=nt(this._origStdoutWrite,t),process.stderr.write=nt(this._origStderrWrite,e)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
22
22
  `),process.stdout.write=this._origStdoutWrite),this._origStderrWrite&&(this._errState&&!this._errState.lineStart&&this._origStderrWrite(`
23
23
  `),process.stderr.write=this._origStderrWrite),this._origStdoutWrite=null,this._origStderrWrite=null}_rawWrite(t){(this._origStdoutWrite||process.stdout.write.bind(process.stdout))(`${t}
24
- `)}_emitGraphLogMarker(t){if(!this._emitWorkflowGraphMarkers)return;let e=`${bt}${JSON.stringify(t)}
24
+ `)}_emitGraphLogMarker(t){if(!this._emitWorkflowGraphMarkers)return;let e=`${$t}${JSON.stringify(t)}
25
25
  `;this._origStdoutWrite?this._origStdoutWrite(e):process.stdout.write(e)}_writeDot(t,e){this._origStdoutWrite?(this._outState&&!this._outState.lineStart&&(this._origStdoutWrite(`
26
26
  `),this._outState.lineStart=!0,this._outState.col=0),this._origStdoutWrite(`${t} ${e}
27
27
  `)):process.stdout.write.bind(process.stdout)(`${t} ${e}
28
- `)}step(t){this._origStdoutWrite?this._writeDot(W,t):process.stdout.write.bind(process.stdout)(`${A} ${W} ${t}
29
- `)}stepInfo(t){this.step(t)}stepTool(t){this._origStdoutWrite?this._writeDot(Y,t):process.stdout.write.bind(process.stdout)(`${A} ${Y} ${t}
30
- `)}stepMemory(t){let e=g.hex("#2dd4bf")(t);this._origStdoutWrite?this._writeDot(V,e):process.stdout.write.bind(process.stdout)(`${A} ${V} ${e}
31
- `)}stepFail(t){this._origStdoutWrite?this._writeDot(C,g.red(t)):process.stdout.write.bind(process.stdout)(`${A} ${C} ${g.red(t)}
32
- `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${Et} ${t}`),this._startIntercepting()}nodeComplete(t,e={}){this._stopIntercepting();let{duration:n,details:o}=e;if(o)for(let a of o)this._rawWrite(`${W} ${a}`);let i=n?g.dim(` ${Q(n)}`):"";this._rawWrite(`${q} ${g.green("done")}${i}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,e,n={}){this._stopIntercepting();let{duration:o}=n,i=o?g.dim(` ${Q(o)}`):"";this._rawWrite(`${C} ${g.red(e)}`),this._rawWrite(`${q} ${g.red("failed")}${i}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,e){this._rawWrite(g.dim(` ${t} \u2192 ${e}`)),this._rawWrite("")}graphComplete(){}},et=new L;var F=".session-info.json";var Ut=Object.freeze(["codebase-memory","code-scan","artifact"]);var Nt=Object.freeze({authentication_failed:"deterministic",oauth_org_not_allowed:"deterministic",billing_error:"deterministic",invalid_request:"deterministic",max_output_tokens:"deterministic",rate_limit:"transient",server_error:"transient",unknown:"inconclusive"}),Tt=Object.freeze([/stream idle timeout/i,/partial response received/i,/no chunks received/i,/stream ended without receiving any events/i,/stream completed without receiving/i,/socket hang up/i,/premature close/i,/\b(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENETUNREACH|ENETRESET|EHOSTUNREACH)\b/,/\bfetch failed\b/i,/\bnetwork (?:error|timeout)\b/i,/request timed out/i,/\brequest timeout\b/i,/\boverloaded(?:_error)?\b/i,/\brate[_ ]limit(?:_error|ed)?\b/i,/\b(?:HTTP|http_status|status(?:\s*code)?)[:= ]\s*(?:429|5\d\d)\b/i,/\b(?:429|500|502|503|504|529)\s+(?:too many requests|internal server error|bad gateway|service unavailable|gateway time-?out|overloaded)\b/i]),$t=Object.freeze([/\bAbortError\b/,/\bAPIUserAbortError\b/,/\boperation was aborted\b/i,/\bcanceled by parent abort\b/i,/\bstopped by operator\b/i]),ot=/provider error \[([a-z_]+)(?:\s+http\s+(\d{3}))?\]/i;function j(r){if(r==null)return"";if(typeof r=="string")return r;if(typeof r!="object")return String(r);let t=r;return[t.message,t.name,t.code,t.providerErrorText,t.cause?.message??(typeof t.cause=="string"?t.cause:void 0),t.cause?.code].filter(n=>typeof n=="string"||typeof n=="number").join(" | ")}function kt(r){if(r&&typeof r=="object"){let e=r.providerErrorKind;if(typeof e=="string"&&e.trim())return e.trim()}let t=ot.exec(j(r));return t?t[1].toLowerCase():null}function It(r){if(r&&typeof r=="object"){let n=Number(r.providerErrorStatus);if(Number.isInteger(n)&&n>=100&&n<=599)return n}let t=ot.exec(j(r)),e=t&&t[2]?Number(t[2]):NaN;return Number.isInteger(e)?e:null}function At(r){let t=j(r);if(!t)return"deterministic";for(let o of $t)if(o.test(t))return"deterministic";let e=kt(r);if(e){let o=Nt[e];if(o==="transient"||o==="deterministic")return o}let n=It(r);if(n===429||n>=500&&n<=599)return"transient";for(let o of Tt)if(o.test(t))return"transient";return"deterministic"}var rt=2,Ot=5;function Rt(r=process.env){let t=r?.AGENT_TRANSIENT_RETRIES;if(t==null||String(t).trim()==="")return rt;let e=Number(t);return!Number.isFinite(e)||e<0?rt:Math.min(Ot,Math.floor(e))}var D=5e3,it=3e4;function vt(r=process.env){let t=r?.AGENT_TRANSIENT_BACKOFF_MS;if(t==null||String(t).trim()==="")return D;let e=Number(t);return!Number.isFinite(e)||e<0?D:Math.min(it,Math.floor(e))}function nt(r,t=Math.random,e=D){if(!(e>0))return 0;let n=Math.max(1,Math.floor(Number(r)||1)),o=Math.min(it,e*2**(n-1)),i=1+(t()-.5)*.4;return Math.max(1,Math.round(o*i))}function B(r,{env:t=process.env,rand:e=Math.random}={}){let n=Math.max(0,Math.floor(Number(r)||0)),o=Rt(t),i=vt(t),a=0,m=0;return{get attemptsMade(){return 1+a+m},get transientUsed(){return m},get transientMax(){return o},next(l){let S=At(l);return a<n?(a+=1,{retry:!0,paidBy:"declared",delayMs:S==="transient"?nt(a,e,i):0,failureClass:S,index:a,of:n}):S==="transient"&&m<o?(m+=1,{retry:!0,paidBy:"transient",delayMs:nt(m,e,i),failureClass:S,index:m,of:o}):{retry:!1,delayMs:0,failureClass:S}}}}async function gt(r,t,e,n){if(!t.retry)return!1;if(n())return f.info(`[workflow] node '${r}': run aborted \u2014 not retrying`),!1;let o=e?.message??String(e??"");return t.paidBy==="transient"?f.warn(`[workflow] node '${r}': TRANSIENT provider failure \u2014 ${o}. Retrying in ${Math.round(t.delayMs/1e3)}s (transient retry ${t.index}/${t.of}; the workspace is untouched, so files this node already wrote survive into the retry).`):f.info(`[workflow] node '${r}' failed (${t.failureClass}), retrying (${t.index}/${t.of})\u2026`),t.delayMs>0&&(await new Promise(i=>setTimeout(i,t.delayMs)),n())?(f.info(`[workflow] node '${r}': run aborted during backoff \u2014 not retrying`),!1):!0}k.helpers.inc||k.registerHelper("inc",r=>Number(r)+1);k.helpers.json||k.registerHelper("json",r=>JSON.stringify(r,null,2));k.helpers.eq||k.registerHelper("eq",(r,t)=>r===t);var yt=class{constructor(t){if(this.config=t,this.name=t.name,this.prompt=t.prompt,this.outputSchema=t.outputSchema,!this.outputSchema&&!t._isCustomCode&&!t._isRouter)throw new Error(`Node '${this.name}' must define outputSchema (Zod schema). This defines the contract for what the node returns to state.`);this.isZodSchema=this.outputSchema&&typeof this.outputSchema._def<"u",this.parser=t.outputSchema&&!this.isZodSchema?new v(t.outputSchema):null,this.retries=t.retries||0,this.onComplete=t.onComplete,this.customExecute=t.execute}async execute(t,e){if(this.config._isRouter)return f.debug(`[workflow] node '${this.name}': router passthrough (routing happens on its conditional edges)`),{success:!0,output:{},raw:null};let n=()=>e&&typeof e.getAll=="function"?e.getAll():t,o=c=>e&&typeof e.get=="function"?e.get(c):t?.[c],i=()=>o("_signal")?.aborted===!0;if(typeof this.customExecute=="function"){f.debug(`[workflow] node '${this.name}': custom execute (skipping LLM)`);let c=B(this.retries),d=null,y=null;for(;;){try{let s=await this.customExecute(t);if(typeof s=="object"&&s!==null&&s.success===!1)y=null,d={success:!1,error:s.error||`node '${this.name}' returned { success: false } with no \`error\` field. On a custom-code node \`success\` is RESERVED: the engine reads it as "this node failed" and stops the graph. If it was meant as a DOMAIN fact (no diff to commit, a PR deliberately skipped), give that fact its own field name and return the outcome \u2014 or set \`error\` to say what actually failed.`,raw:s.raw||null};else return this.isZodSchema?(f.debug(`[workflow] node '${this.name}': validating output schema`),{success:!0,output:this.outputSchema.parse(s),raw:null}):{success:!0,output:s,raw:null}}catch(s){f.error(`[workflow] node '${this.name}' failed: ${s.message}`),s.name==="ZodError"&&f.error(`Schema errors: ${JSON.stringify(s.issues||s.errors,null,2)}`),y=s,d={success:!1,error:s.message,raw:null}}let w=y??d?.error,T=c.next(w);if(!await gt(this.name,T,w,i))break}return d&&(d.attempts=c.attemptsMade),d}let a;typeof this.prompt=="function"?a=this.prompt(n()):typeof this.prompt=="string"&&this.prompt.includes("{{")?(this._compiledPrompt||(this._compiledPrompt=k.compile(this.prompt,{noEscape:!0})),a=this._compiledPrompt(n())):a=this.prompt;let m=o("_skillHints");m&&(a=`${m}
28
+ `)}step(t){this._origStdoutWrite?this._writeDot(L,t):process.stdout.write.bind(process.stdout)(`${R} ${L} ${t}
29
+ `)}stepInfo(t){this.step(t)}stepTool(t){this._origStdoutWrite?this._writeDot(X,t):process.stdout.write.bind(process.stdout)(`${R} ${X} ${t}
30
+ `)}stepMemory(t){let e=h.hex("#2dd4bf")(t);this._origStdoutWrite?this._writeDot(Q,e):process.stdout.write.bind(process.stdout)(`${R} ${Q} ${e}
31
+ `)}stepFail(t){this._origStdoutWrite?this._writeDot(F,h.red(t)):process.stdout.write.bind(process.stdout)(`${R} ${F} ${h.red(t)}
32
+ `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${kt} ${t}`),this._startIntercepting()}nodeComplete(t,e={}){this._stopIntercepting();let{duration:n,details:o}=e;if(o)for(let s of o)this._rawWrite(`${L} ${s}`);let i=n?h.dim(` ${rt(n)}`):"";this._rawWrite(`${Z} ${h.green("done")}${i}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,e,n={}){this._stopIntercepting();let{duration:o}=n,i=o?h.dim(` ${rt(o)}`):"";this._rawWrite(`${F} ${h.red(e)}`),this._rawWrite(`${Z} ${h.red("failed")}${i}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,e){this._rawWrite(h.dim(` ${t} \u2192 ${e}`)),this._rawWrite("")}graphComplete(){}},ot=new D;var j=".session-info.json";var zt=Object.freeze(["codebase-memory","code-scan","artifact"]);var It=Object.freeze({authentication_failed:"deterministic",oauth_org_not_allowed:"deterministic",billing_error:"deterministic",invalid_request:"deterministic",max_output_tokens:"deterministic",rate_limit:"transient",server_error:"transient",unknown:"inconclusive"}),Ot=Object.freeze([/stream idle timeout/i,/partial response received/i,/no chunks received/i,/stream ended without receiving any events/i,/stream completed without receiving/i,/socket hang up/i,/premature close/i,/\b(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENETUNREACH|ENETRESET|EHOSTUNREACH)\b/,/\bfetch failed\b/i,/\bnetwork (?:error|timeout)\b/i,/request timed out/i,/\brequest timeout\b/i,/\boverloaded(?:_error)?\b/i,/\brate[_ ]limit(?:_error|ed)?\b/i,/\b(?:HTTP|http_status|status(?:\s*code)?)[:= ]\s*(?:429|5\d\d)\b/i,/\b(?:429|500|502|503|504|529)\s+(?:too many requests|internal server error|bad gateway|service unavailable|gateway time-?out|overloaded)\b/i]),At=Object.freeze([/\bAbortError\b/,/\bAPIUserAbortError\b/,/\boperation was aborted\b/i,/\bcanceled by parent abort\b/i,/\bstopped by operator\b/i]),at=/provider error \[([a-z_]+)(?:\s+http\s+(\d{3}))?\]/i;function G(r){if(r==null)return"";if(typeof r=="string")return r;if(typeof r!="object")return String(r);let t=r;return[t.message,t.name,t.code,t.providerErrorText,t.cause?.message??(typeof t.cause=="string"?t.cause:void 0),t.cause?.code].filter(n=>typeof n=="string"||typeof n=="number").join(" | ")}function Rt(r){if(r&&typeof r=="object"){let e=r.providerErrorKind;if(typeof e=="string"&&e.trim())return e.trim()}let t=at.exec(G(r));return t?t[1].toLowerCase():null}function vt(r){if(r&&typeof r=="object"){let n=Number(r.providerErrorStatus);if(Number.isInteger(n)&&n>=100&&n<=599)return n}let t=at.exec(G(r)),e=t&&t[2]?Number(t[2]):NaN;return Number.isInteger(e)?e:null}function xt(r){let t=G(r);if(!t)return"deterministic";for(let o of At)if(o.test(t))return"deterministic";let e=Rt(r);if(e){let o=It[e];if(o==="transient"||o==="deterministic")return o}let n=vt(r);if(n===429||n>=500&&n<=599)return"transient";for(let o of Ot)if(o.test(t))return"transient";return"deterministic"}var it=2,Mt=5;function Pt(r=process.env){let t=r?.AGENT_TRANSIENT_RETRIES;if(t==null||String(t).trim()==="")return it;let e=Number(t);return!Number.isFinite(e)||e<0?it:Math.min(Mt,Math.floor(e))}var B=5e3,lt=3e4;function Wt(r=process.env){let t=r?.AGENT_TRANSIENT_BACKOFF_MS;if(t==null||String(t).trim()==="")return B;let e=Number(t);return!Number.isFinite(e)||e<0?B:Math.min(lt,Math.floor(e))}function st(r,t=Math.random,e=B){if(!(e>0))return 0;let n=Math.max(1,Math.floor(Number(r)||1)),o=Math.min(lt,e*2**(n-1)),i=1+(t()-.5)*.4;return Math.max(1,Math.round(o*i))}function U(r,{env:t=process.env,rand:e=Math.random}={}){let n=Math.max(0,Math.floor(Number(r)||0)),o=Pt(t),i=Wt(t),s=0,p=0;return{get attemptsMade(){return 1+s+p},get transientUsed(){return p},get transientMax(){return o},next(u){let b=xt(u);return s<n?(s+=1,{retry:!0,paidBy:"declared",delayMs:b==="transient"?st(s,e,i):0,failureClass:b,index:s,of:n}):b==="transient"&&p<o?(p+=1,{retry:!0,paidBy:"transient",delayMs:st(p,e,i),failureClass:b,index:p,of:o}):{retry:!1,delayMs:0,failureClass:b}}}}async function St(r,t,e,n){if(!t.retry)return!1;if(n())return d.info(`[workflow] node '${r}': run aborted \u2014 not retrying`),!1;let o=e?.message??String(e??"");return t.paidBy==="transient"?d.warn(`[workflow] node '${r}': TRANSIENT provider failure \u2014 ${o}. Retrying in ${Math.round(t.delayMs/1e3)}s (transient retry ${t.index}/${t.of}; the workspace is untouched, so files this node already wrote survive into the retry).`):d.info(`[workflow] node '${r}' failed (${t.failureClass}), retrying (${t.index}/${t.of})\u2026`),t.delayMs>0&&(await new Promise(i=>setTimeout(i,t.delayMs)),n())?(d.info(`[workflow] node '${r}': run aborted during backoff \u2014 not retrying`),!1):!0}k.helpers.inc||k.registerHelper("inc",r=>Number(r)+1);k.helpers.json||k.registerHelper("json",r=>JSON.stringify(r,null,2));k.helpers.eq||k.registerHelper("eq",(r,t)=>r===t);var bt=class{constructor(t){if(this.config=t,this.name=t.name,this.prompt=t.prompt,this.outputSchema=t.outputSchema,!this.outputSchema&&!t._isCustomCode&&!t._isRouter)throw new Error(`Node '${this.name}' must define outputSchema (Zod schema). This defines the contract for what the node returns to state.`);this.isZodSchema=this.outputSchema&&typeof this.outputSchema._def<"u",this.parser=t.outputSchema&&!this.isZodSchema?new M(t.outputSchema):null,this.retries=t.retries||0,this.onComplete=t.onComplete,this.customExecute=t.execute}async execute(t,e){if(this.config._isRouter)return d.debug(`[workflow] node '${this.name}': router passthrough (routing happens on its conditional edges)`),{success:!0,output:{},raw:null};let n=()=>e&&typeof e.getAll=="function"?e.getAll():t,o=c=>e&&typeof e.get=="function"?e.get(c):t?.[c],i=()=>o("_signal")?.aborted===!0;if(typeof this.customExecute=="function"){d.debug(`[workflow] node '${this.name}': custom execute (skipping LLM)`);let c=U(this.retries),f=null,g=null;for(;;){try{let l=await this.customExecute(t);if(typeof l=="object"&&l!==null&&l.success===!1)g=null,f={success:!1,error:l.error||`node '${this.name}' returned { success: false } with no \`error\` field. On a custom-code node \`success\` is RESERVED: the engine reads it as "this node failed" and stops the graph. If it was meant as a DOMAIN fact (no diff to commit, a PR deliberately skipped), give that fact its own field name and return the outcome \u2014 or set \`error\` to say what actually failed.`,raw:l.raw||null};else return this.isZodSchema?(d.debug(`[workflow] node '${this.name}': validating output schema`),{success:!0,output:this.outputSchema.parse(l),raw:null}):{success:!0,output:l,raw:null}}catch(l){d.error(`[workflow] node '${this.name}' failed: ${l.message}`),l.name==="ZodError"&&d.error(`Schema errors: ${JSON.stringify(l.issues||l.errors,null,2)}`),g=l,f={success:!1,error:l.message,raw:null}}let E=g??f?.error,I=c.next(E);if(!await St(this.name,I,E,i))break}return f&&(f.attempts=c.attemptsMade),f}let s;typeof this.prompt=="function"?s=this.prompt(n()):typeof this.prompt=="string"&&this.prompt.includes("{{")?(this._compiledPrompt||(this._compiledPrompt=k.compile(this.prompt,{noEscape:!0})),s=this._compiledPrompt(n())):s=this.prompt;let p=o("_skillHints");p&&(s=`${p}
33
33
 
34
- ${a}`);let l=n(),S=l.cwd||process.cwd(),E=l.sessionPath;try{if(E){let c=J(E,F);if(ht(c)){let y=JSON.parse(mt(c,"utf-8"));y.currentNode=this.name,K(c,JSON.stringify(y,null,2),"utf-8")}let d=J(E,"..",F);if(ht(d))try{let y=JSON.parse(mt(d,"utf-8"));y.currentNode=this.name,K(d,JSON.stringify(y,null,2),"utf-8")}catch{}}}catch(c){f.debug(`[workflow] could not update session info: ${c.message}`)}let I=B(this.retries),N=null;for(;;)try{f.debug(`[workflow] node '${this.name}' attempt ${I.attemptsMade-1}`);let c=n().config||{},d=c.agents||{},y=this.config.agent??d[this.name]??null,w={state:n()};y&&(w.preferredAgent=y);let T={workspace:S,schema:this.isZodSchema?this.outputSchema:null,skills:this.config.skills||[],disallowedTools:this.config.disallowedTools||[],plugins:this.config.plugins||[],sessionPath:E,config:c,nodeName:this.name,timeout:this.config?.timeout||3e5},s=t?._coreInvokeAgent;s||(s=(await Promise.resolve().then(()=>(ft(),pt))).invokeAgent);let _=await s(a,w,T),h,p;if(typeof _=="string"?(h=_,p=null):_.structured?(h=_.raw||JSON.stringify(_.structured,null,2),p=_.structured):(h=_.raw||JSON.stringify(_,null,2),p=_.extracted||null),E)try{let u=J(E,this.name,"raw_stream_output.txt");Ct(Lt(u),{recursive:!0}),K(u,typeof h=="string"?h:JSON.stringify(h),"utf-8")}catch(u){f.debug(`[workflow] could not save raw output: ${u.message}`)}if(this.isZodSchema&&p){f.debug(`[workflow] node '${this.name}': output validated: ${JSON.stringify(p,null,2)}`);let u=p;if(typeof this.onComplete=="function")try{u=await this.onComplete(n(),p)}catch(b){f.warn(`[workflow] onComplete hook failed: ${b.message}`)}return{success:!0,output:u,raw:h}}if(typeof this.onComplete=="function")try{return{success:!0,output:await this.onComplete(n(),{raw:h}),raw:h}}catch(u){throw new Error(`onComplete failed: ${u.message}`,{cause:u})}if(this.parser){let u=this.parser.parse(h);return f.debug(`[workflow] node '${this.name}': parsed output: ${JSON.stringify(u,null,2)}`),et.step("Output parsed"),{success:!0,output:u,raw:h}}return{success:!0,output:h,raw:h}}catch(c){N=c;let d=I.next(c);if(!await gt(this.name,d,c,i))break}return{success:!1,error:N.message,raw:null,attempts:I.attemptsMade}}};export{yt as Node};
34
+ ${s}`);let u=n(),b=u.cwd||process.cwd(),N=u.sessionPath;try{if(N){let c=V(N,j);if(wt(c)){let g=JSON.parse(_t(c,"utf-8"));g.currentNode=this.name,q(c,JSON.stringify(g,null,2),"utf-8")}let f=V(N,"..",j);if(wt(f))try{let g=JSON.parse(_t(f,"utf-8"));g.currentNode=this.name,q(f,JSON.stringify(g,null,2),"utf-8")}catch{}}}catch(c){d.debug(`[workflow] could not update session info: ${c.message}`)}let O=U(this.retries),A=null;for(;;)try{d.debug(`[workflow] node '${this.name}' attempt ${O.attemptsMade-1}`);let c=n().config||{},f=c.agents||{},g=this.config.agent??f[this.name]??null,E={state:n()};g&&(E.preferredAgent=g);let I={workspace:b,schema:this.isZodSchema?this.outputSchema:null,skills:this.config.skills||[],disallowedTools:this.config.disallowedTools||[],plugins:this.config.plugins||[],sessionPath:N,config:c,nodeName:this.name,timeout:this.config?.timeout||3e5},l=t?._coreInvokeAgent;l||(l=(await Promise.resolve().then(()=>(yt(),gt))).invokeAgent);let y=await l(s,E,I),a,w;if(typeof y=="string"?(a=y,w=null):y.structured?(a=y.raw||JSON.stringify(y.structured,null,2),w=y.structured):(a=y.raw||JSON.stringify(y,null,2),w=y.extracted||null),N)try{let m=V(N,this.name,"raw_stream_output.txt");jt(Bt(m),{recursive:!0}),q(m,typeof a=="string"?a:JSON.stringify(a),"utf-8")}catch(m){d.debug(`[workflow] could not save raw output: ${m.message}`)}if(this.isZodSchema&&w){d.debug(`[workflow] node '${this.name}': output validated: ${JSON.stringify(w,null,2)}`);let m=w;if(typeof this.onComplete=="function")try{m=await this.onComplete(n(),w)}catch(_){d.warn(`[workflow] onComplete hook failed: ${_.message}`)}return{success:!0,output:m,raw:a}}if(typeof this.onComplete=="function")try{return{success:!0,output:await this.onComplete(n(),{raw:a}),raw:a}}catch(m){throw new Error(`onComplete failed: ${m.message}`,{cause:m})}if(this.parser){let m=this.parser.parse(a);return d.debug(`[workflow] node '${this.name}': parsed output: ${JSON.stringify(m,null,2)}`),ot.step("Output parsed"),{success:!0,output:m,raw:a}}return{success:!0,output:a,raw:a}}catch(c){A=c;let f=O.next(c);if(!await St(this.name,f,c,i))break}return{success:!1,error:A.message,raw:null,attempts:O.attemptsMade}}};export{bt as Node};
@@ -68,6 +68,22 @@ export declare function resolveInvocationModel({ config, options, strategyName,
68
68
  * chain (resolveInvocationModel, above), same cure: derive, don't duplicate.
69
69
  * A field added here now reaches BOTH paths by construction.
70
70
  */
71
+ /**
72
+ * REASONING EFFORT for this invocation. Same shape of chain as the model, and
73
+ * for the same reason: the operator's per-node pin is the most specific thing
74
+ * anyone said, and every executor that re-derives this on its own is one more
75
+ * place to drift from it.
76
+ * nodeConfigEffort (nodeConfigOverrides[node].effort — the dashboard's pick)
77
+ * > options.effort (a node passing its own, e.g. a cheap triage pass)
78
+ * > EFFORT env (the run-level default the executor stamps)
79
+ * Returns null when nobody said anything, which means "the vendor's own
80
+ * default" — never a value invented here.
81
+ * VALIDATED, not passed through: the levels are a closed set the CLIs accept
82
+ * (`claude --effort low|medium|high|xhigh|max`), and an unknown string reaching
83
+ * a vendor is an opaque runtime error rather than a visible bad pick.
84
+ */
85
+ export declare const EFFORT_LEVELS: string[];
86
+ export declare function resolveInvocationEffort({ options, envEffort, nodeConfigEffort }?: any): string;
71
87
  export declare function resolveInvocationExtras({ options, stateView, context }?: any): {
72
88
  workspace: any;
73
89
  schema: any;
@@ -1,17 +1,17 @@
1
- var R=()=>{},P={debug:R,info:R,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},N=Symbol.for("@zibby/agent-workflow.logger");globalThis[N]||(globalThis[N]={impl:P});var k=globalThis[N];var S={debug:(...e)=>k.impl.debug?.(...e),info:(...e)=>k.impl.info?.(...e),warn:(...e)=>k.impl.warn?.(...e),error:(...e)=>k.impl.error?.(...e)};var A=Symbol.for("@zibby/agent-workflow.skills"),I=Symbol.for("@zibby/agent-workflow.skills.sources");globalThis[A]||(globalThis[A]=new Map);globalThis[I]||(globalThis[I]=new Map);var j=globalThis[A],z=globalThis[I];function M(e){return j.get(e)||null}var O=Symbol.for("@zibby/agent-workflow.strategies");globalThis[O]||(globalThis[O]=[]);var p=globalThis[O];function V(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=p.findIndex(n=>n.getName()===e.getName());t>=0?p[t]=e:p.push(e)}function B(){return p.map(e=>e.getName())}function C({config:e={},options:t={},strategyName:n,envModel:r,nodeConfigModel:l}={}){let i=e.models||{},g=typeof l=="string"&&l.trim()?l.trim():null,m=t.nodeName&&i[t.nodeName]||null,y=i.default||null,E=e.agent?.[n]?.model||null,T=(typeof r=="string"?r.trim():"")||null;return g||m||y||E||t.model||T||null}function L({options:e={},stateView:t={},context:n={}}={}){return{workspace:t.workspace||e.workspace,schema:e.schema||n.schema,images:e.images||n.images||[],skills:e.skills||n.skills||[],extraMcpServers:e.extraMcpServers||t.extraMcpServers||n.extraMcpServers||[],plugins:e.plugins||n.plugins||[]}}function Y(e={}){let{state:t={},preferredAgent:n=null}=e,r=n||t.agentType||process.env.AGENT_TYPE;if(!r){let i=p.map(g=>g.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${i}`)}S.debug(`[workflow] agent selection: requested=${r}`);let l=p.find(i=>i.getName()===r);if(!l){let i=p.map(g=>g.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${i}`)}if(!l.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return S.debug(`[workflow] using agent: ${l.getName()}`),l}async function W(e,t={},n={}){let r=t.state&&typeof t.state.getAll=="function"?t.state.getAll():t.state||{},l={...t,state:r},i=Y(l),g=r.config||n.config||{},m=r._currentNodeConfig||{},y=typeof m.agent=="string"?m.agent.trim():"",E=!y||y===i.name?m.model:null,T=C({config:g,options:n,strategyName:i.name,envModel:process.env.MODEL,nodeConfigModel:E}),$={...n,model:T,...L({options:n,stateView:r,context:t}),config:g},u=e,x=$.skills||[];if(x.length>0&&!n.skipPromptFragments){let f=n.connectedIntegrations;if(!f){let s=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof s=="string"&&s.trim()!==""){f={};for(let a of s.split(",").map(c=>c.trim()).filter(Boolean))f[a]=!0}}let v=s=>{let a=s&&s.requiresIntegration;return!a||!f?!0:(Array.isArray(a)?a:[a]).some(w=>f[w]===!0)},o=i.name==="assistant",h=s=>s?.inProcessOnly!==!0||o,b=x.map(s=>{let a=M(s);if(!v(a)||!h(a))return null;let c=a?.promptFragment;return typeof c=="function"?c():c}).filter(Boolean);b.length>0&&(u+=`
1
+ var M=()=>{},j={debug:M,info:M,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},N=Symbol.for("@zibby/agent-workflow.logger");globalThis[N]||(globalThis[N]={impl:j});var k=globalThis[N];var h={debug:(...e)=>k.impl.debug?.(...e),info:(...e)=>k.impl.info?.(...e),warn:(...e)=>k.impl.warn?.(...e),error:(...e)=>k.impl.error?.(...e)};var A=Symbol.for("@zibby/agent-workflow.skills"),x=Symbol.for("@zibby/agent-workflow.skills.sources");globalThis[A]||(globalThis[A]=new Map);globalThis[x]||(globalThis[x]=new Map);var Y=globalThis[A],q=globalThis[x];function L(e){return Y.get(e)||null}var O=Symbol.for("@zibby/agent-workflow.strategies");globalThis[O]||(globalThis[O]=[]);var p=globalThis[O];function Q(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=p.findIndex(n=>n.getName()===e.getName());t>=0?p[t]=e:p.push(e)}function X(){return p.map(e=>e.getName())}function F({config:e={},options:t={},strategyName:n,envModel:r,nodeConfigModel:s}={}){let o=e.models||{},f=typeof s=="string"&&s.trim()?s.trim():null,m=t.nodeName&&o[t.nodeName]||null,u=o.default||null,S=e.agent?.[n]?.model||null,T=(typeof r=="string"?r.trim():"")||null;return f||m||u||S||t.model||T||null}var P=["low","medium","high","xhigh","max"];function G({options:e={},envEffort:t,nodeConfigEffort:n}={}){let r=[n,e.effort,t].map(s=>typeof s=="string"?s.trim().toLowerCase():"").find(Boolean);return r?P.indexOf(r)===-1?(h.warn(`[workflow] ignoring unknown effort "${r}" \u2014 expected one of ${P.join(", ")}`),null):r:null}function K({options:e={},stateView:t={},context:n={}}={}){return{workspace:t.workspace||e.workspace,schema:e.schema||n.schema,images:e.images||n.images||[],skills:e.skills||n.skills||[],extraMcpServers:e.extraMcpServers||t.extraMcpServers||n.extraMcpServers||[],plugins:e.plugins||n.plugins||[]}}function z(e={}){let{state:t={},preferredAgent:n=null}=e,r=n||t.agentType||process.env.AGENT_TYPE;if(!r){let o=p.map(f=>f.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${o}`)}h.debug(`[workflow] agent selection: requested=${r}`);let s=p.find(o=>o.getName()===r);if(!s){let o=p.map(f=>f.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${o}`)}if(!s.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return h.debug(`[workflow] using agent: ${s.getName()}`),s}async function Z(e,t={},n={}){let r=t.state&&typeof t.state.getAll=="function"?t.state.getAll():t.state||{},s={...t,state:r},o=z(s),f=r.config||n.config||{},m=r._currentNodeConfig||{},u=typeof m.agent=="string"?m.agent.trim():"",S=!u||u===o.name?m.model:null,T=F({config:f,options:n,strategyName:o.name,envModel:process.env.MODEL,nodeConfigModel:S}),C=!u||u===o.name?m.effort:null,I=G({options:n,envEffort:process.env.EFFORT,nodeConfigEffort:C}),$={...n,model:T,...I?{effort:I}:{},...K({options:n,stateView:r,context:t}),config:f},d=e,_=$.skills||[];if(_.length>0&&!n.skipPromptFragments){let g=n.connectedIntegrations;if(!g){let a=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof a=="string"&&a.trim()!==""){g={};for(let l of a.split(",").map(c=>c.trim()).filter(Boolean))g[l]=!0}}let v=a=>{let l=a&&a.requiresIntegration;return!l||!g?!0:(Array.isArray(l)?l:[l]).some(E=>g[E]===!0)},i=o.name==="assistant",w=a=>a?.inProcessOnly!==!0||i,b=_.map(a=>{let l=L(a);if(!v(l)||!w(l))return null;let c=l?.promptFragment;return typeof c=="function"?c():c}).filter(Boolean);b.length>0&&(d+=`
2
2
 
3
3
  ${b.join(`
4
4
 
5
- `)}`)}let d=r._currentNodeConfig?.stores;if(Array.isArray(d)&&d.length>0&&typeof d[0]=="object"){let f=d.length<=8,v=d.map(o=>{let h=o?.id??o?.storeId??"",b=(o?.name??"").toString().trim()||h,s=o?.type?` \xB7 ${o.type}`:"",a=(o?.description||"").toString().replace(/\s+/g," ").trim(),c=`- ${b} \xB7 ${a||"(no description)"}${s} (id: ${h})`;if(f&&o?.schema&&typeof o.schema=="object"){let w=o.schema.properties&&typeof o.schema.properties=="object"?Object.keys(o.schema.properties):Object.keys(o.schema);w.length&&(c+=`
6
- fields: ${w.join(", ")}`)}return c});u+=`
5
+ `)}`)}let y=r._currentNodeConfig?.stores;if(Array.isArray(y)&&y.length>0&&typeof y[0]=="object"){let g=y.length<=8,v=y.map(i=>{let w=i?.id??i?.storeId??"",b=(i?.name??"").toString().trim()||w,a=i?.type?` \xB7 ${i.type}`:"",l=(i?.description||"").toString().replace(/\s+/g," ").trim(),c=`- ${b} \xB7 ${l||"(no description)"}${a} (id: ${w})`;if(g&&i?.schema&&typeof i.schema=="object"){let E=i.schema.properties&&typeof i.schema.properties=="object"?Object.keys(i.schema.properties):Object.keys(i.schema);E.length&&(c+=`
6
+ fields: ${E.join(", ")}`)}return c});d+=`
7
7
 
8
8
  AVAILABLE STORES (pick a store by its description and pass its NAME to the store tool):
9
9
  ${v.join(`
10
- `)}`}let _=r._currentNodeConfig?.extraPromptInstructions?.trim();return _&&(u+=`
10
+ `)}`}let R=r._currentNodeConfig?.extraPromptInstructions?.trim();return R&&(d+=`
11
11
 
12
12
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
13
13
  PRIORITY OVERRIDE \u2014 THE FOLLOWING INSTRUCTIONS TAKE PRECEDENCE OVER ALL PREVIOUS CONTENT
14
14
  \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
15
15
 
16
- ${_}
17
- `),S.debug(`[workflow] prompt length: ${u.length} chars`),i.invoke(u,$)}export{Y as getAgentStrategy,W as invokeAgent,B as listStrategies,V as registerStrategy,L as resolveInvocationExtras,C as resolveInvocationModel};
16
+ ${R}
17
+ `),h.debug(`[workflow] prompt length: ${d.length} chars`),o.invoke(d,$)}export{P as EFFORT_LEVELS,z as getAgentStrategy,Z as invokeAgent,X as listStrategies,Q as registerStrategy,G as resolveInvocationEffort,K as resolveInvocationExtras,F as resolveInvocationModel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/agent-workflow",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "Graph-based AI agent workflow orchestration. Bring your own agent strategies.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",