@zibby/agent-workflow 0.1.4 → 0.3.0

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.
@@ -1,20 +1,20 @@
1
- var R=Object.defineProperty;var w=(e,t)=>()=>(e&&(t=e(e=0)),t);var O=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})};var E=w(()=>{});var S,C,h,k,b=w(()=>{S=()=>{},C={debug:S,info:S,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},h={impl:C},k={debug:(...e)=>h.impl.debug?.(...e),info:(...e)=>h.impl.info?.(...e),warn:(...e)=>h.impl.warn?.(...e),error:(...e)=>h.impl.error?.(...e)}});function v(e){return P.get(e)||null}var P,T=w(()=>{P=new Map});var _={};O(_,{getAgentStrategy:()=>A,invokeAgent:()=>L,listStrategies:()=>j,registerStrategy:()=>M});function M(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=c.findIndex(n=>n.getName()===e.getName());t>=0?c[t]=e:c.push(e)}function j(){return c.map(e=>e.getName())}function A(e={}){let{state:t={},preferredAgent:n=null}=e,r=n||t.agentType||process.env.AGENT_TYPE;if(!r){let o=c.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${o}`)}k.debug(`[workflow] agent selection: requested=${r}`);let i=c.find(o=>o.getName()===r);if(!i){let o=c.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${o}`)}if(!i.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return k.debug(`[workflow] using agent: ${i.getName()}`),i}async function L(e,t={},n={}){let r=A(t),i=t.state?.config||n.config||{},o=i.models||{},s=n.nodeName&&o[n.nodeName]||null,l=o.default||null,p=i.agent?.[r.name]?.model||null,a=s||l||p||n.model||null,m={...n,model:a,workspace:t.state?.workspace||n.workspace,schema:n.schema||t.schema,images:n.images||t.images||[],skills:n.skills||t.skills||[],config:i},u=e,g=m.skills||[];if(g.length>0&&!n.skipPromptFragments){let x=g.map($=>{let y=v($)?.promptFragment;return typeof y=="function"?y():y}).filter(Boolean);x.length>0&&(u+=`
1
+ var C=Object.defineProperty;var w=(e,t)=>()=>(e&&(t=e(e=0)),t);var P=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})};var T=w(()=>{});var x,Y,h,k,v=w(()=>{x=()=>{},Y={debug:x,info:x,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},h={impl:Y},k={debug:(...e)=>h.impl.debug?.(...e),info:(...e)=>h.impl.info?.(...e),warn:(...e)=>h.impl.warn?.(...e),error:(...e)=>h.impl.error?.(...e)}});function _(e){return G.get(e)||null}var y,G,A=w(()=>{y=Symbol.for("@zibby/agent-workflow.skills");globalThis[y]||(globalThis[y]=new Map);G=globalThis[y]});var R={};P(R,{getAgentStrategy:()=>I,invokeAgent:()=>z,listStrategies:()=>j,registerStrategy:()=>M});function M(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=c.findIndex(n=>n.getName()===e.getName());t>=0?c[t]=e:c.push(e)}function j(){return c.map(e=>e.getName())}function I(e={}){let{state:t={},preferredAgent:n=null}=e,r=n||t.agentType||process.env.AGENT_TYPE;if(!r){let o=c.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${o}`)}k.debug(`[workflow] agent selection: requested=${r}`);let i=c.find(o=>o.getName()===r);if(!i){let o=c.map(s=>s.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${o}`)}if(!i.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return k.debug(`[workflow] using agent: ${i.getName()}`),i}async function z(e,t={},n={}){let r=I(t),i=t.state?.config||n.config||{},o=i.models||{},s=n.nodeName&&o[n.nodeName]||null,l=o.default||null,m=i.agent?.[r.name]?.model||null,a=s||l||m||n.model||null,p={...n,model:a,workspace:t.state?.workspace||n.workspace,schema:n.schema||t.schema,images:n.images||t.images||[],skills:n.skills||t.skills||[],config:i},g=e,u=p.skills||[];if(u.length>0&&!n.skipPromptFragments){let S=u.map(O=>{let b=_(O)?.promptFragment;return typeof b=="function"?b():b}).filter(Boolean);S.length>0&&(g+=`
2
2
 
3
- ${x.join(`
3
+ ${S.join(`
4
4
 
5
- `)}`)}let d=t.state?._currentNodeConfig?.extraPromptInstructions?.trim();return d&&(u+=`
5
+ `)}`)}let d=t.state?._currentNodeConfig?.extraPromptInstructions?.trim();return d&&(g+=`
6
6
 
7
7
  \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
8
8
  PRIORITY OVERRIDE \u2014 THE FOLLOWING INSTRUCTIONS TAKE PRECEDENCE OVER ALL PREVIOUS CONTENT
9
9
  \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
10
10
 
11
11
  ${d}
12
- `),k.debug(`[workflow] prompt length: ${u.length} chars`),r.invoke(u,m)}var N,c,I=w(()=>{E();b();T();N=Symbol.for("@zibby/agent-workflow.strategies");globalThis[N]||(globalThis[N]=[]);c=globalThis[N]});var f=new Map;function Y(e,t){f.set(e,t)}function B(e){return f.get(e)}function J(e){return f.has(e)}function W(){return Array.from(f.keys())}function Q(e){let t=f.get(e);return t?t.factory&&typeof t.create=="function"?t.create.toString():typeof t.execute=="function"?t.execute.toString():typeof t=="function"?t.toString():null:null}Y("ai_agent",{name:"ai_agent",factory:!0,create:(e,t={})=>({name:e,_isCustomCode:!0,execute:async n=>{let r=n?._coreInvokeAgent;r||(r=(await Promise.resolve().then(()=>(I(),_))).invokeAgent);let i=t.extraPromptInstructions||"Execute the task based on the current state.",o=G(i,n),s=await r(o,{cwd:n.workspace||process.cwd(),model:n.model,tools:t.resolvedTools||null});return{success:!0,output:{raw:s,nodeId:e},raw:typeof s=="string"?s:s.raw}}})});function G(e,t){let n=/@([\w.]+)/g,r=new Set,i;for(;(i=n.exec(e))!==null;)r.add(i[1]);if(r.size===0)return e;let o=[],s=new Set;for(let l of r){let p=l.split(".")[0];if(s.has(p))continue;let a=l.split(".").reduce((g,d)=>g?.[d],t);if(a===void 0)continue;let m=typeof a=="string"?a:a?.raw??JSON.stringify(a,null,2),u=l.replace(/_/g," ").replace(/\b\w/g,g=>g.toUpperCase());o.push(`## ${u}
13
- ${m}`),l.includes(".")||s.add(p)}return o.length===0?e:`${e}
12
+ `),k.debug(`[workflow] prompt length: ${g.length} chars`),r.invoke(g,p)}var E,c,$=w(()=>{T();v();A();E=Symbol.for("@zibby/agent-workflow.strategies");globalThis[E]||(globalThis[E]=[]);c=globalThis[E]});var N=Symbol.for("@zibby/agent-workflow.nodes");globalThis[N]||(globalThis[N]=new Map);var f=globalThis[N];function L(e,t){f.set(e,t)}function W(e){return f.get(e)}function Q(e){return f.has(e)}function X(){return Array.from(f.keys())}function Z(e){let t=f.get(e);return t?t.factory&&typeof t.create=="function"?t.create.toString():typeof t.execute=="function"?t.execute.toString():typeof t=="function"?t.toString():null:null}L("ai_agent",{name:"ai_agent",factory:!0,create:(e,t={})=>({name:e,_isCustomCode:!0,execute:async n=>{let r=n?._coreInvokeAgent;r||(r=(await Promise.resolve().then(()=>($(),R))).invokeAgent);let i=t.extraPromptInstructions||"Execute the task based on the current state.",o=H(i,n),s=await r(o,{cwd:n.workspace||process.cwd(),model:n.model,tools:t.resolvedTools||null});return{success:!0,output:{raw:s,nodeId:e},raw:typeof s=="string"?s:s.raw}}})});function H(e,t){let n=/@([\w.]+)/g,r=new Set,i;for(;(i=n.exec(e))!==null;)r.add(i[1]);if(r.size===0)return e;let o=[],s=new Set;for(let l of r){let m=l.split(".")[0];if(s.has(m))continue;let a=l.split(".").reduce((u,d)=>u?.[d],t);if(a===void 0)continue;let p=typeof a=="string"?a:a?.raw??JSON.stringify(a,null,2),g=l.replace(/_/g," ").replace(/\b\w/g,u=>u.toUpperCase());o.push(`## ${g}
13
+ ${p}`),l.includes(".")||s.add(m)}return o.length===0?e:`${e}
14
14
 
15
15
  ---
16
16
  # Referenced Context
17
17
 
18
18
  ${o.join(`
19
19
 
20
- `)}`}export{B as getNodeImpl,Q as getNodeTemplate,J as hasNode,W as listNodeTypes,Y as registerNode};
20
+ `)}`}export{W as getNodeImpl,Z as getNodeTemplate,Q as hasNode,X as listNodeTypes,L as registerNode};
package/dist/node.js CHANGED
@@ -1,6 +1,6 @@
1
- var ot=Object.defineProperty;var k=(r,t)=>()=>(r&&(t=r(r=0)),t);var st=(r,t)=>{for(var e in t)ot(r,e,{get:t[e],enumerable:!0})};var M,it,N,c,x=k(()=>{M=()=>{},it={debug:M,info:M,warn:(...r)=>console.warn("[workflow]",...r),error:(...r)=>console.error("[workflow]",...r)},N={impl:it},c={debug:(...r)=>N.impl.debug?.(...r),info:(...r)=>N.impl.info?.(...r),warn:(...r)=>N.impl.warn?.(...r),error:(...r)=>N.impl.error?.(...r)}});var Y=k(()=>{});function Z(r){return ut.get(r)||null}var ut,V=k(()=>{ut=new Map});var q={};st(q,{getAgentStrategy:()=>z,invokeAgent:()=>pt,listStrategies:()=>lt,registerStrategy:()=>ct});function ct(r){if(!r||typeof r.getName!="function"||typeof r.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=S.findIndex(e=>e.getName()===r.getName());t>=0?S[t]=r:S.push(r)}function lt(){return S.map(r=>r.getName())}function z(r={}){let{state:t={},preferredAgent:e=null}=r,o=e||t.agentType||process.env.AGENT_TYPE;if(!o){let n=S.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${n}`)}c.debug(`[workflow] agent selection: requested=${o}`);let i=S.find(n=>n.getName()===o);if(!i){let n=S.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${o}'. Available: ${n}`)}if(!i.canHandle(r))throw new Error(`Agent '${o}' is not available in this environment. Check credentials/environment.`);return c.debug(`[workflow] using agent: ${i.getName()}`),i}async function pt(r,t={},e={}){let o=z(t),i=t.state?.config||e.config||{},n=i.models||{},a=e.nodeName&&n[e.nodeName]||null,g=n.default||null,p=i.agent?.[o.name]?.model||null,w=a||g||p||e.model||null,$={...e,model:w,workspace:t.state?.workspace||e.workspace,schema:e.schema||t.schema,images:e.images||t.images||[],skills:e.skills||t.skills||[],config:i},s=r,h=$.skills||[];if(h.length>0&&!e.skipPromptFragments){let y=h.map(I=>{let E=Z(I)?.promptFragment;return typeof E=="function"?E():E}).filter(Boolean);y.length>0&&(s+=`
1
+ var st=Object.defineProperty;var I=(r,t)=>()=>(r&&(t=r(r=0)),t);var it=(r,t)=>{for(var e in t)st(r,e,{get:t[e],enumerable:!0})};var D,nt,N,u,R=I(()=>{D=()=>{},nt={debug:D,info:D,warn:(...r)=>console.warn("[workflow]",...r),error:(...r)=>console.error("[workflow]",...r)},N={impl:nt},u={debug:(...r)=>N.impl.debug?.(...r),info:(...r)=>N.impl.info?.(...r),warn:(...r)=>N.impl.warn?.(...r),error:(...r)=>N.impl.error?.(...r)}});var Z=I(()=>{});function V(r){return ut.get(r)||null}var v,ut,z=I(()=>{v=Symbol.for("@zibby/agent-workflow.skills");globalThis[v]||(globalThis[v]=new Map);ut=globalThis[v]});var X={};it(X,{getAgentStrategy:()=>q,invokeAgent:()=>dt,listStrategies:()=>pt,registerStrategy:()=>ct});function ct(r){if(!r||typeof r.getName!="function"||typeof r.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let t=S.findIndex(e=>e.getName()===r.getName());t>=0?S[t]=r:S.push(r)}function pt(){return S.map(r=>r.getName())}function q(r={}){let{state:t={},preferredAgent:e=null}=r,o=e||t.agentType||process.env.AGENT_TYPE;if(!o){let n=S.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${n}`)}u.debug(`[workflow] agent selection: requested=${o}`);let i=S.find(n=>n.getName()===o);if(!i){let n=S.map(a=>a.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${o}'. Available: ${n}`)}if(!i.canHandle(r))throw new Error(`Agent '${o}' is not available in this environment. Check credentials/environment.`);return u.debug(`[workflow] using agent: ${i.getName()}`),i}async function dt(r,t={},e={}){let o=q(t),i=t.state?.config||e.config||{},n=i.models||{},a=e.nodeName&&n[e.nodeName]||null,g=n.default||null,p=i.agent?.[o.name]?.model||null,w=a||g||p||e.model||null,y={...e,model:w,workspace:t.state?.workspace||e.workspace,schema:e.schema||t.schema,images:e.images||t.images||[],skills:e.skills||t.skills||[],config:i},s=r,h=y.skills||[];if(h.length>0&&!e.skipPromptFragments){let E=h.map(b=>{let $=V(b)?.promptFragment;return typeof $=="function"?$():$}).filter(Boolean);E.length>0&&(s+=`
2
2
 
3
- ${y.join(`
3
+ ${E.join(`
4
4
 
5
5
  `)}`)}let f=t.state?._currentNodeConfig?.extraPromptInstructions?.trim();return f&&(s+=`
6
6
 
@@ -9,21 +9,21 @@ PRIORITY OVERRIDE \u2014 THE FOLLOWING INSTRUCTIONS TAKE PRECEDENCE OVER ALL PRE
9
9
  \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
10
10
 
11
11
  ${f}
12
- `),c.debug(`[workflow] prompt length: ${s.length} chars`),o.invoke(s,$)}var v,S,X=k(()=>{Y();x();V();v=Symbol.for("@zibby/agent-workflow.strategies");globalThis[v]||(globalThis[v]=[]);S=globalThis[v]});var b=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 o=t.match(/\{[\s\S]*\}/);return o?this.validate(JSON.parse(o[0])):this.validate({result:t.trim()})}validate(t){let e=[];for(let[o,i]of Object.entries(this.schema)){if(i.required&&!(o in t)&&e.push(`Missing required field: ${o}`),o in t&&i.type){let n=typeof t[o];n!==i.type&&e.push(`Field '${o}' expected ${i.type}, got ${n}`)}if(i.validate&&o in t){let n=i.validate(t[o]);n&&e.push(`Field '${o}': ${n}`)}}if(e.length>0)throw new Error(`Output validation failed:
12
+ `),u.debug(`[workflow] prompt length: ${s.length} chars`),o.invoke(s,y)}var P,S,Q=I(()=>{Z();R();z();P=Symbol.for("@zibby/agent-workflow.strategies");globalThis[P]||(globalThis[P]=[]);S=globalThis[P]});var k=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 o=[t.match(/\{[\s\S]*?\}/),t.match(/\{[\s\S]*\}/)].filter(Boolean).map(i=>i[0]);for(let i of o)try{return this.validate(JSON.parse(i))}catch(n){if(!(n instanceof SyntaxError))throw n}return this.validate({result:t.trim()})}validate(t){let e=[];for(let[o,i]of Object.entries(this.schema)){if(i.required&&!(o in t)&&e.push(`Missing required field: ${o}`),o in t&&i.type){let n=typeof t[o];n!==i.type&&e.push(`Field '${o}' expected ${i.type}, got ${n}`)}if(i.validate&&o in t){let n=i.validate(t[o]);n&&e.push(`Field '${o}': ${n}`)}}if(e.length>0)throw new Error(`Output validation failed:
13
13
  ${e.join(`
14
- `)}`);return t}};x();import{writeFileSync as C,readFileSync as Q,existsSync as tt,mkdirSync as dt}from"node:fs";import{join as P,dirname as ht}from"node:path";import u from"chalk";var nt="__WORKFLOW_GRAPH_LOG__",O=u.gray("\u2502"),at=u.gray("\u250C"),D=u.gray("\u2514"),R=u.green("\u25C6"),U=u.hex("#c084fc")("\u25C6"),G=u.hex("#2dd4bf")("\u25C6"),A=u.red("\u25C6"),j=`${O} `,J=2;function H(r){return r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function B(r,t){return(e,o,i)=>{if(typeof e!="string")return r(e,o,i);let n=process.stdout.columns||120,a="";for(let g=0;g<e.length;g++){let p=e[g];t.lineStart&&(a+=j,t.col=J,t.lineStart=!1),p===`
14
+ `)}`);return t}};R();import{writeFileSync as C,readFileSync as tt,existsSync as et,mkdirSync as ht}from"node:fs";import{join as F,dirname as ft}from"node:path";import l from"chalk";var at="__WORKFLOW_GRAPH_LOG__",O=l.gray("\u2502"),lt=l.gray("\u250C"),G=l.gray("\u2514"),x=l.green("\u25C6"),U=l.hex("#c084fc")("\u25C6"),j=l.hex("#2dd4bf")("\u25C6"),T=l.red("\u25C6"),J=`${O} `,H=2;function K(r){return r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`}function B(r,t){return(e,o,i)=>{if(typeof e!="string")return r(e,o,i);let n=process.stdout.columns||120,a="";for(let g=0;g<e.length;g++){let p=e[g];t.lineStart&&(a+=J,t.col=H,t.lineStart=!1),p===`
15
15
  `?(a+=p,t.lineStart=!0,t.col=0,t.inEsc=!1):p==="\x1B"?(t.inEsc=!0,a+=p):t.inEsc?(a+=p,(p>="A"&&p<="Z"||p>="a"&&p<="z")&&(t.inEsc=!1)):(t.col++,a+=p,t.col>=n&&(a+=`
16
- ${j}`,t.col=J))}return r(a,o,i)}}var T=class{constructor(){this._currentNode=null,this._origStdoutWrite=null,this._origStderrWrite=null;let t=String(process.env.ZIBBY_RUN_SOURCE||"").trim().toLowerCase(),e=String(process.env.ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS||"").trim()==="1";this._emitWorkflowGraphMarkers=e||t==="studio"}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=B(this._origStdoutWrite,t),process.stderr.write=B(this._origStderrWrite,e)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
16
+ ${J}`,t.col=H))}return r(a,o,i)}}var A=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=B(this._origStdoutWrite,t),process.stderr.write=B(this._origStderrWrite,e)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
17
17
  `),process.stdout.write=this._origStdoutWrite),this._origStderrWrite&&(this._errState&&!this._errState.lineStart&&this._origStderrWrite(`
18
18
  `),process.stderr.write=this._origStderrWrite),this._origStdoutWrite=null,this._origStderrWrite=null}_rawWrite(t){(this._origStdoutWrite||process.stdout.write.bind(process.stdout))(`${t}
19
- `)}_emitGraphLogMarker(t){if(!this._emitWorkflowGraphMarkers)return;let e=`${nt}${JSON.stringify(t)}
19
+ `)}_emitGraphLogMarker(t){if(!this._emitWorkflowGraphMarkers)return;let e=`${at}${JSON.stringify(t)}
20
20
  `;this._origStdoutWrite?this._origStdoutWrite(e):process.stdout.write(e)}_writeDot(t,e){this._origStdoutWrite?(this._outState&&!this._outState.lineStart&&(this._origStdoutWrite(`
21
21
  `),this._outState.lineStart=!0,this._outState.col=0),this._origStdoutWrite(`${t} ${e}
22
22
  `)):process.stdout.write.bind(process.stdout)(`${t} ${e}
23
- `)}step(t){this._origStdoutWrite?this._writeDot(R,t):process.stdout.write.bind(process.stdout)(`${O} ${R} ${t}
23
+ `)}step(t){this._origStdoutWrite?this._writeDot(x,t):process.stdout.write.bind(process.stdout)(`${O} ${x} ${t}
24
24
  `)}stepInfo(t){this.step(t)}stepTool(t){this._origStdoutWrite?this._writeDot(U,t):process.stdout.write.bind(process.stdout)(`${O} ${U} ${t}
25
- `)}stepMemory(t){let e=u.hex("#2dd4bf")(t);this._origStdoutWrite?this._writeDot(G,e):process.stdout.write.bind(process.stdout)(`${O} ${G} ${e}
26
- `)}stepFail(t){this._origStdoutWrite?this._writeDot(A,u.red(t)):process.stdout.write.bind(process.stdout)(`${O} ${A} ${u.red(t)}
27
- `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${at} ${t}`),this._startIntercepting()}nodeComplete(t,e={}){this._stopIntercepting();let{duration:o,details:i}=e;if(i)for(let a of i)this._rawWrite(`${R} ${a}`);let n=o?u.dim(` ${H(o)}`):"";this._rawWrite(`${D} ${u.green("done")}${n}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,e,o={}){this._stopIntercepting();let{duration:i}=o,n=i?u.dim(` ${H(i)}`):"";this._rawWrite(`${A} ${u.red(e)}`),this._rawWrite(`${D} ${u.red("failed")}${n}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,e){this._rawWrite(u.dim(` ${t} \u2192 ${e}`)),this._rawWrite("")}graphComplete(){this._rawWrite(u.green.bold("\u2713 Workflow completed"))}},K=new T;var L=".session-info.json";var F=class{constructor(t){if(this.config=t,this.name=t.name,this.prompt=t.prompt,this.outputSchema=t.outputSchema,!this.outputSchema&&!t._isCustomCode)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 b(t.outputSchema):null,this.retries=t.retries||0,this.onComplete=t.onComplete,this.customExecute=t.execute}async execute(t,e){let o=()=>e&&typeof e.getAll=="function"?e.getAll():t,i=s=>e&&typeof e.get=="function"?e.get(s):t?.[s];if(typeof this.customExecute=="function"){c.debug(`[workflow] node '${this.name}': custom execute (skipping LLM)`);try{let s=await this.customExecute(t);return typeof s=="object"&&s!==null&&s.success===!1?{success:!1,error:s.error||"Node execution failed",raw:s.raw||null}:this.isZodSchema?(c.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){return c.error(`[workflow] node '${this.name}' failed: ${s.message}`),s.name==="ZodError"&&c.error(`Schema errors: ${JSON.stringify(s.errors,null,2)}`),{success:!1,error:s.message,raw:null}}}let n=typeof this.prompt=="function"?this.prompt(o()):this.prompt,a=i("_skillHints");a&&(n=`${a}
25
+ `)}stepMemory(t){let e=l.hex("#2dd4bf")(t);this._origStdoutWrite?this._writeDot(j,e):process.stdout.write.bind(process.stdout)(`${O} ${j} ${e}
26
+ `)}stepFail(t){this._origStdoutWrite?this._writeDot(T,l.red(t)):process.stdout.write.bind(process.stdout)(`${O} ${T} ${l.red(t)}
27
+ `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${lt} ${t}`),this._startIntercepting()}nodeComplete(t,e={}){this._stopIntercepting();let{duration:o,details:i}=e;if(i)for(let a of i)this._rawWrite(`${x} ${a}`);let n=o?l.dim(` ${K(o)}`):"";this._rawWrite(`${G} ${l.green("done")}${n}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,e,o={}){this._stopIntercepting();let{duration:i}=o,n=i?l.dim(` ${K(i)}`):"";this._rawWrite(`${T} ${l.red(e)}`),this._rawWrite(`${G} ${l.red("failed")}${n}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,e){this._rawWrite(l.dim(` ${t} \u2192 ${e}`)),this._rawWrite("")}graphComplete(){this._rawWrite(l.green.bold("\u2713 Workflow completed"))}},Y=new A;var L=".session-info.json";var M=class{constructor(t){if(this.config=t,this.name=t.name,this.prompt=t.prompt,this.outputSchema=t.outputSchema,!this.outputSchema&&!t._isCustomCode)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 k(t.outputSchema):null,this.retries=t.retries||0,this.onComplete=t.onComplete,this.customExecute=t.execute}async execute(t,e){let o=()=>e&&typeof e.getAll=="function"?e.getAll():t,i=s=>e&&typeof e.get=="function"?e.get(s):t?.[s];if(typeof this.customExecute=="function"){u.debug(`[workflow] node '${this.name}': custom execute (skipping LLM)`);try{let s=await this.customExecute(t);return typeof s=="object"&&s!==null&&s.success===!1?{success:!1,error:s.error||"Node execution failed",raw:s.raw||null}:this.isZodSchema?(u.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){return u.error(`[workflow] node '${this.name}' failed: ${s.message}`),s.name==="ZodError"&&u.error(`Schema errors: ${JSON.stringify(s.issues||s.errors,null,2)}`),{success:!1,error:s.message,raw:null}}}let n=typeof this.prompt=="function"?this.prompt(o()):this.prompt,a=i("_skillHints");a&&(n=`${a}
28
28
 
29
- ${n}`);let g=o(),p=g.cwd||process.cwd(),w=g.sessionPath;try{if(w){let s=P(w,L);if(tt(s)){let f=JSON.parse(Q(s,"utf-8"));f.currentNode=this.name,C(s,JSON.stringify(f,null,2),"utf-8")}let h=P(w,"..",L);if(tt(h))try{let f=JSON.parse(Q(h,"utf-8"));f.currentNode=this.name,C(h,JSON.stringify(f,null,2),"utf-8")}catch{}}}catch(s){c.debug(`[workflow] could not update session info: ${s.message}`)}let $=null;for(let s=0;s<=this.retries;s++)try{c.debug(`[workflow] node '${this.name}' attempt ${s}`);let h=o().config||{},f=h.agents||{},y=this.config.agent??f[this.name]??null,I={state:o()};y&&(I.preferredAgent=y);let E={workspace:p,schema:this.isZodSchema?this.outputSchema:null,skills:this.config.skills||[],sessionPath:w,config:h,nodeName:this.name,timeout:this.config?.timeout||3e5},W=t?._coreInvokeAgent;W||(W=(await Promise.resolve().then(()=>(X(),q))).invokeAgent);let m=await W(n,I,E),d,_;if(typeof m=="string"?(d=m,_=null):m.structured?(d=m.raw||JSON.stringify(m.structured,null,2),_=m.structured):(d=m.raw||JSON.stringify(m,null,2),_=m.extracted||null),w)try{let l=P(w,this.name,"raw_stream_output.txt");dt(ht(l),{recursive:!0}),C(l,typeof d=="string"?d:JSON.stringify(d),"utf-8")}catch(l){c.debug(`[workflow] could not save raw output: ${l.message}`)}if(this.isZodSchema&&_){c.info(`[workflow] node '${this.name}': output validated: ${JSON.stringify(_,null,2)}`);let l=_;if(typeof this.onComplete=="function")try{l=await this.onComplete(o(),_)}catch(rt){c.warn(`[workflow] onComplete hook failed: ${rt.message}`)}return{success:!0,output:l,raw:d}}if(typeof this.onComplete=="function")try{return{success:!0,output:await this.onComplete(o(),{raw:d}),raw:d}}catch(l){throw new Error(`onComplete failed: ${l.message}`,{cause:l})}if(this.parser){let l=this.parser.parse(d);return c.info(`[workflow] node '${this.name}': parsed output: ${JSON.stringify(l,null,2)}`),K.step("Output parsed"),{success:!0,output:l,raw:d}}return{success:!0,output:d,raw:d}}catch(h){$=h,s<this.retries&&c.info(`[workflow] node '${this.name}' failed, retrying (${s+1}/${this.retries})\u2026`)}return{success:!1,error:$.message,raw:null}}},et=class extends F{constructor(t){super({...t,_isCustomCode:!0}),this.condition=t.condition}async execute(t,e){let o=e&&typeof e.getAll=="function"?e.getAll():t;return{success:!0,output:{nextNode:this.condition(o)},raw:null}}};export{et as ConditionalNode,F as Node};
29
+ ${n}`);let g=o(),p=g.cwd||process.cwd(),w=g.sessionPath;try{if(w){let s=F(w,L);if(et(s)){let f=JSON.parse(tt(s,"utf-8"));f.currentNode=this.name,C(s,JSON.stringify(f,null,2),"utf-8")}let h=F(w,"..",L);if(et(h))try{let f=JSON.parse(tt(h,"utf-8"));f.currentNode=this.name,C(h,JSON.stringify(f,null,2),"utf-8")}catch{}}}catch(s){u.debug(`[workflow] could not update session info: ${s.message}`)}let y=null;for(let s=0;s<=this.retries;s++)try{u.debug(`[workflow] node '${this.name}' attempt ${s}`);let h=o().config||{},f=h.agents||{},E=this.config.agent??f[this.name]??null,b={state:o()};E&&(b.preferredAgent=E);let $={workspace:p,schema:this.isZodSchema?this.outputSchema:null,skills:this.config.skills||[],sessionPath:w,config:h,nodeName:this.name,timeout:this.config?.timeout||3e5},W=t?._coreInvokeAgent;W||(W=(await Promise.resolve().then(()=>(Q(),X))).invokeAgent);let m=await W(n,b,$),d,_;if(typeof m=="string"?(d=m,_=null):m.structured?(d=m.raw||JSON.stringify(m.structured,null,2),_=m.structured):(d=m.raw||JSON.stringify(m,null,2),_=m.extracted||null),w)try{let c=F(w,this.name,"raw_stream_output.txt");ht(ft(c),{recursive:!0}),C(c,typeof d=="string"?d:JSON.stringify(d),"utf-8")}catch(c){u.debug(`[workflow] could not save raw output: ${c.message}`)}if(this.isZodSchema&&_){u.info(`[workflow] node '${this.name}': output validated: ${JSON.stringify(_,null,2)}`);let c=_;if(typeof this.onComplete=="function")try{c=await this.onComplete(o(),_)}catch(ot){u.warn(`[workflow] onComplete hook failed: ${ot.message}`)}return{success:!0,output:c,raw:d}}if(typeof this.onComplete=="function")try{return{success:!0,output:await this.onComplete(o(),{raw:d}),raw:d}}catch(c){throw new Error(`onComplete failed: ${c.message}`,{cause:c})}if(this.parser){let c=this.parser.parse(d);return u.info(`[workflow] node '${this.name}': parsed output: ${JSON.stringify(c,null,2)}`),Y.step("Output parsed"),{success:!0,output:c,raw:d}}return{success:!0,output:d,raw:d}}catch(h){y=h,s<this.retries&&u.info(`[workflow] node '${this.name}' failed, retrying (${s+1}/${this.retries})\u2026`)}return{success:!1,error:y.message,raw:null}}},rt=class extends M{constructor(t){super({...t,_isCustomCode:!0}),this.condition=t.condition}async execute(t,e){let o=e&&typeof e.getAll=="function"?e.getAll():t;return{success:!0,output:{nextNode:this.condition(o)},raw:null}}};export{rt as ConditionalNode,M as Node};
@@ -1,3 +1,3 @@
1
- var o=class{constructor(e){this.schema=e}parse(e){let i=e.match(/```json\s*([\s\S]*?)\s*```/);if(i)return this.validate(JSON.parse(i[1]));let r=e.match(/\{[\s\S]*\}/);return r?this.validate(JSON.parse(r[0])):this.validate({result:e.trim()})}validate(e){let i=[];for(let[r,n]of Object.entries(this.schema)){if(n.required&&!(r in e)&&i.push(`Missing required field: ${r}`),r in e&&n.type){let s=typeof e[r];s!==n.type&&i.push(`Field '${r}' expected ${n.type}, got ${s}`)}if(n.validate&&r in e){let s=n.validate(e[r]);s&&i.push(`Field '${r}': ${s}`)}}if(i.length>0)throw new Error(`Output validation failed:
2
- ${i.join(`
3
- `)}`);return e}},a={string:(t=!0)=>({type:"string",required:t}),number:(t=!0)=>({type:"number",required:t}),boolean:(t=!0)=>({type:"boolean",required:t}),array:(t=!0)=>({type:"object",required:t,validate:e=>Array.isArray(e)?null:"must be an array"}),enum:(t,e=!0)=>({type:"string",required:e,validate:i=>t.includes(i)?null:`must be one of: ${t.join(", ")}`})};export{o as OutputParser,a as SchemaTypes};
1
+ var a=class{constructor(e){this.schema=e}parse(e){let r=e.match(/```json\s*([\s\S]*?)\s*```/);if(r)return this.validate(JSON.parse(r[1]));let i=[e.match(/\{[\s\S]*?\}/),e.match(/\{[\s\S]*\}/)].filter(Boolean).map(n=>n[0]);for(let n of i)try{return this.validate(JSON.parse(n))}catch(s){if(!(s instanceof SyntaxError))throw s}return this.validate({result:e.trim()})}validate(e){let r=[];for(let[i,n]of Object.entries(this.schema)){if(n.required&&!(i in e)&&r.push(`Missing required field: ${i}`),i in e&&n.type){let s=typeof e[i];s!==n.type&&r.push(`Field '${i}' expected ${n.type}, got ${s}`)}if(n.validate&&i in e){let s=n.validate(e[i]);s&&r.push(`Field '${i}': ${s}`)}}if(r.length>0)throw new Error(`Output validation failed:
2
+ ${r.join(`
3
+ `)}`);return e}},o={string:(t=!0)=>({type:"string",required:t}),number:(t=!0)=>({type:"number",required:t}),boolean:(t=!0)=>({type:"boolean",required:t}),array:(t=!0)=>({type:"object",required:t,validate:e=>Array.isArray(e)?null:"must be an array"}),enum:(t,e=!0)=>({type:"string",required:e,validate:r=>t.includes(r)?null:`must be one of: ${t.join(", ")}`})};export{a as OutputParser,o as SchemaTypes};
@@ -1 +1 @@
1
- var e=new Map;function r(t){if(!t||typeof t.id!="string")throw new Error("Skill definition must include a string id");e.set(t.id,Object.freeze({...t}))}function n(t){return e.get(t)||null}function i(t){return e.has(t)}function o(){return new Map(e)}function l(){return Array.from(e.keys())}function u(){e.clear()}export{u as clearSkills,o as getAllSkills,n as getSkill,i as hasSkill,l as listSkillIds,r as registerSkill};
1
+ var e=Symbol.for("@zibby/agent-workflow.skills");globalThis[e]||(globalThis[e]=new Map);var r=globalThis[e];function i(t){if(!t||typeof t.id!="string")throw new Error("Skill definition must include a string id");r.set(t.id,Object.freeze({...t}))}function n(t){return r.get(t)||null}function l(t){return r.has(t)}function o(){return new Map(r)}function s(){return Array.from(r.keys())}function f(){r.clear()}export{f as clearSkills,o as getAllSkills,n as getSkill,l as hasSkill,s as listSkillIds,i as registerSkill};
@@ -1,12 +1,12 @@
1
- var h=()=>{},y={debug:h,info:h,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},g={impl:y};var c={debug:(...e)=>g.impl.debug?.(...e),info:(...e)=>g.impl.info?.(...e),warn:(...e)=>g.impl.warn?.(...e),error:(...e)=>g.impl.error?.(...e)};var T=new Map;function k(e){return T.get(e)||null}var f=Symbol.for("@zibby/agent-workflow.strategies");globalThis[f]||(globalThis[f]=[]);var s=globalThis[f];function P(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let n=s.findIndex(t=>t.getName()===e.getName());n>=0?s[n]=e:s.push(e)}function C(){return s.map(e=>e.getName())}function v(e={}){let{state:n={},preferredAgent:t=null}=e,r=t||n.agentType||process.env.AGENT_TYPE;if(!r){let i=s.map(l=>l.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${i}`)}c.debug(`[workflow] agent selection: requested=${r}`);let o=s.find(i=>i.getName()===r);if(!o){let i=s.map(l=>l.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${i}`)}if(!o.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return c.debug(`[workflow] using agent: ${o.getName()}`),o}async function L(e,n={},t={}){let r=v(n),o=n.state?.config||t.config||{},i=o.models||{},l=t.nodeName&&i[t.nodeName]||null,E=i.default||null,N=o.agent?.[r.name]?.model||null,b=l||E||N||t.model||null,u={...t,model:b,workspace:n.state?.workspace||t.workspace,schema:t.schema||n.schema,images:t.images||n.images||[],skills:t.skills||n.skills||[],config:o},a=e,p=u.skills||[];if(p.length>0&&!t.skipPromptFragments){let w=p.map(S=>{let m=k(S)?.promptFragment;return typeof m=="function"?m():m}).filter(Boolean);w.length>0&&(a+=`
1
+ var k=()=>{},y={debug:k,info:k,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},g={impl:y};var c={debug:(...e)=>g.impl.debug?.(...e),info:(...e)=>g.impl.info?.(...e),warn:(...e)=>g.impl.warn?.(...e),error:(...e)=>g.impl.error?.(...e)};var f=Symbol.for("@zibby/agent-workflow.skills");globalThis[f]||(globalThis[f]=new Map);var v=globalThis[f];function b(e){return v.get(e)||null}var u=Symbol.for("@zibby/agent-workflow.strategies");globalThis[u]||(globalThis[u]=[]);var s=globalThis[u];function C(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let n=s.findIndex(t=>t.getName()===e.getName());n>=0?s[n]=e:s.push(e)}function Y(){return s.map(e=>e.getName())}function A(e={}){let{state:n={},preferredAgent:t=null}=e,r=t||n.agentType||process.env.AGENT_TYPE;if(!r){let i=s.map(l=>l.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${i}`)}c.debug(`[workflow] agent selection: requested=${r}`);let o=s.find(i=>i.getName()===r);if(!o){let i=s.map(l=>l.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${i}`)}if(!o.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return c.debug(`[workflow] using agent: ${o.getName()}`),o}async function G(e,n={},t={}){let r=A(n),o=n.state?.config||t.config||{},i=o.models||{},l=t.nodeName&&i[t.nodeName]||null,E=i.default||null,N=o.agent?.[r.name]?.model||null,T=l||E||N||t.model||null,p={...t,model:T,workspace:n.state?.workspace||t.workspace,schema:t.schema||n.schema,images:t.images||n.images||[],skills:t.skills||n.skills||[],config:o},a=e,d=p.skills||[];if(d.length>0&&!t.skipPromptFragments){let h=d.map(S=>{let m=b(S)?.promptFragment;return typeof m=="function"?m():m}).filter(Boolean);h.length>0&&(a+=`
2
2
 
3
- ${w.join(`
3
+ ${h.join(`
4
4
 
5
- `)}`)}let d=n.state?._currentNodeConfig?.extraPromptInstructions?.trim();return d&&(a+=`
5
+ `)}`)}let w=n.state?._currentNodeConfig?.extraPromptInstructions?.trim();return w&&(a+=`
6
6
 
7
7
  \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
8
8
  PRIORITY OVERRIDE \u2014 THE FOLLOWING INSTRUCTIONS TAKE PRECEDENCE OVER ALL PREVIOUS CONTENT
9
9
  \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
10
10
 
11
- ${d}
12
- `),c.debug(`[workflow] prompt length: ${a.length} chars`),r.invoke(a,u)}export{v as getAgentStrategy,L as invokeAgent,C as listStrategies,P as registerStrategy};
11
+ ${w}
12
+ `),c.debug(`[workflow] prompt length: ${a.length} chars`),r.invoke(a,p)}export{A as getAgentStrategy,G as invokeAgent,Y as listStrategies,C as registerStrategy};
package/dist/timeline.js CHANGED
@@ -1,14 +1,14 @@
1
- import e from"chalk";var I="__WORKFLOW_GRAPH_LOG__",c=e.gray("\u2502"),E=e.gray("\u250C"),p=e.gray("\u2514"),h=e.green("\u25C6"),S=e.hex("#c084fc")("\u25C6"),W=e.hex("#2dd4bf")("\u25C6"),l=e.red("\u25C6"),w=`${c} `,f=2;function g(d){return d<1e3?`${d}ms`:`${(d/1e3).toFixed(1)}s`}function $(d,t){return(r,o,n)=>{if(typeof r!="string")return d(r,o,n);let _=process.stdout.columns||120,s="";for(let u=0;u<r.length;u++){let i=r[u];t.lineStart&&(s+=w,t.col=f,t.lineStart=!1),i===`
1
+ import e from"chalk";var I="__WORKFLOW_GRAPH_LOG__",c=e.gray("\u2502"),E=e.gray("\u250C"),a=e.gray("\u2514"),u=e.green("\u25C6"),S=e.hex("#c084fc")("\u25C6"),W=e.hex("#2dd4bf")("\u25C6"),l=e.red("\u25C6"),w=`${c} `,f=2;function g(d){return d<1e3?`${d}ms`:`${(d/1e3).toFixed(1)}s`}function $(d,t){return(r,o,n)=>{if(typeof r!="string")return d(r,o,n);let _=process.stdout.columns||120,s="";for(let h=0;h<r.length;h++){let i=r[h];t.lineStart&&(s+=w,t.col=f,t.lineStart=!1),i===`
2
2
  `?(s+=i,t.lineStart=!0,t.col=0,t.inEsc=!1):i==="\x1B"?(t.inEsc=!0,s+=i):t.inEsc?(s+=i,(i>="A"&&i<="Z"||i>="a"&&i<="z")&&(t.inEsc=!1)):(t.col++,s+=i,t.col>=_&&(s+=`
3
- ${w}`,t.col=f))}return d(s,o,n)}}var a=class{constructor(){this._currentNode=null,this._origStdoutWrite=null,this._origStderrWrite=null;let t=String(process.env.ZIBBY_RUN_SOURCE||"").trim().toLowerCase(),r=String(process.env.ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS||"").trim()==="1";this._emitWorkflowGraphMarkers=r||t==="studio"}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},r={lineStart:!0,col:0,inEsc:!1};this._outState=t,this._errState=r,process.stdout.write=$(this._origStdoutWrite,t),process.stderr.write=$(this._origStderrWrite,r)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
3
+ ${w}`,t.col=f))}return d(s,o,n)}}var p=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},r={lineStart:!0,col:0,inEsc:!1};this._outState=t,this._errState=r,process.stdout.write=$(this._origStdoutWrite,t),process.stderr.write=$(this._origStderrWrite,r)}_stopIntercepting(){this._origStdoutWrite&&(this._outState&&!this._outState.lineStart&&this._origStdoutWrite(`
4
4
  `),process.stdout.write=this._origStdoutWrite),this._origStderrWrite&&(this._errState&&!this._errState.lineStart&&this._origStderrWrite(`
5
5
  `),process.stderr.write=this._origStderrWrite),this._origStdoutWrite=null,this._origStderrWrite=null}_rawWrite(t){(this._origStdoutWrite||process.stdout.write.bind(process.stdout))(`${t}
6
6
  `)}_emitGraphLogMarker(t){if(!this._emitWorkflowGraphMarkers)return;let r=`${I}${JSON.stringify(t)}
7
7
  `;this._origStdoutWrite?this._origStdoutWrite(r):process.stdout.write(r)}_writeDot(t,r){this._origStdoutWrite?(this._outState&&!this._outState.lineStart&&(this._origStdoutWrite(`
8
8
  `),this._outState.lineStart=!0,this._outState.col=0),this._origStdoutWrite(`${t} ${r}
9
9
  `)):process.stdout.write.bind(process.stdout)(`${t} ${r}
10
- `)}step(t){this._origStdoutWrite?this._writeDot(h,t):process.stdout.write.bind(process.stdout)(`${c} ${h} ${t}
10
+ `)}step(t){this._origStdoutWrite?this._writeDot(u,t):process.stdout.write.bind(process.stdout)(`${c} ${u} ${t}
11
11
  `)}stepInfo(t){this.step(t)}stepTool(t){this._origStdoutWrite?this._writeDot(S,t):process.stdout.write.bind(process.stdout)(`${c} ${S} ${t}
12
12
  `)}stepMemory(t){let r=e.hex("#2dd4bf")(t);this._origStdoutWrite?this._writeDot(W,r):process.stdout.write.bind(process.stdout)(`${c} ${W} ${r}
13
13
  `)}stepFail(t){this._origStdoutWrite?this._writeDot(l,e.red(t)):process.stdout.write.bind(process.stdout)(`${c} ${l} ${e.red(t)}
14
- `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${E} ${t}`),this._startIntercepting()}nodeComplete(t,r={}){this._stopIntercepting();let{duration:o,details:n}=r;if(n)for(let s of n)this._rawWrite(`${h} ${s}`);let _=o?e.dim(` ${g(o)}`):"";this._rawWrite(`${p} ${e.green("done")}${_}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,r,o={}){this._stopIntercepting();let{duration:n}=o,_=n?e.dim(` ${g(n)}`):"";this._rawWrite(`${l} ${e.red(r)}`),this._rawWrite(`${p} ${e.red("failed")}${_}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,r){this._rawWrite(e.dim(` ${t} \u2192 ${r}`)),this._rawWrite("")}graphComplete(){this._rawWrite(e.green.bold("\u2713 Workflow completed"))}},O=new a;var P=O;export{a as Timeline,I as WORKFLOW_GRAPH_LOG_MARKER_PREFIX,P as default,O as timeline};
14
+ `)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${E} ${t}`),this._startIntercepting()}nodeComplete(t,r={}){this._stopIntercepting();let{duration:o,details:n}=r;if(n)for(let s of n)this._rawWrite(`${u} ${s}`);let _=o?e.dim(` ${g(o)}`):"";this._rawWrite(`${a} ${e.green("done")}${_}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}nodeFailed(t,r,o={}){this._stopIntercepting();let{duration:n}=o,_=n?e.dim(` ${g(n)}`):"";this._rawWrite(`${l} ${e.red(r)}`),this._rawWrite(`${a} ${e.red("failed")}${_}`),this._emitGraphLogMarker({phase:"node_end",node:t}),this._rawWrite("")}route(t,r){this._rawWrite(e.dim(` ${t} \u2192 ${r}`)),this._rawWrite("")}graphComplete(){this._rawWrite(e.green.bold("\u2713 Workflow completed"))}},O=new p;var P=O;export{p as Timeline,I as WORKFLOW_GRAPH_LOG_MARKER_PREFIX,P as default,O as timeline};
@@ -1 +1 @@
1
- var m=new Map;function u(e){return m.get(e)||null}var p=()=>{},d={debug:p,info:p,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},l={impl:d};var a={debug:(...e)=>l.impl.debug?.(...e),info:(...e)=>l.impl.info?.(...e),warn:(...e)=>l.impl.warn?.(...e),error:(...e)=>l.impl.error?.(...e)};var w={};function h(e,t){if(Array.isArray(t))return g(t);let n=w[e];return!n||n.length===0?null:g(n)}function g(e){if(!Array.isArray(e)||e.length===0)return null;let t=[],n={},s=[];for(let i of e){let r=u(i);if(!r){a.warn(`[workflow] unknown skill "${i}" \u2014 skipping`);continue}s.push(i);for(let o of r.tools||[])t.push({name:o.name,description:o.description,input_schema:o.input_schema||{type:"object",properties:{}}});if(!n[r.serverName])if(typeof r.resolve=="function"){let o=r.resolve();o&&(n[r.serverName]={...o,toolPrefix:i})}else{let o={};for(let c of r.envKeys||[]){let f=process.env[c];f&&(o[c]=f)}n[r.serverName]={command:r.command,args:[...r.args||[]],env:o,toolPrefix:i}}}return s.length===0?null:{toolIds:s,claudeTools:t,mcpServers:n}}export{w as NODE_DEFAULT_TOOLS,g as getResolvedToolDefinitions,h as resolveNodeTools};
1
+ var f=Symbol.for("@zibby/agent-workflow.skills");globalThis[f]||(globalThis[f]=new Map);var d=globalThis[f];function u(o){return d.get(o)||null}var p=()=>{},w={debug:p,info:p,warn:(...o)=>console.warn("[workflow]",...o),error:(...o)=>console.error("[workflow]",...o)},l={impl:w};var g={debug:(...o)=>l.impl.debug?.(...o),info:(...o)=>l.impl.info?.(...o),warn:(...o)=>l.impl.warn?.(...o),error:(...o)=>l.impl.error?.(...o)};var k={};function S(o,t){if(Array.isArray(t))return m(t);let n=k[o];return!n||n.length===0?null:m(n)}function m(o){if(!Array.isArray(o)||o.length===0)return null;let t=[],n={},s=[];for(let i of o){let e=u(i);if(!e){g.warn(`[workflow] unknown skill "${i}" \u2014 skipping`);continue}s.push(i);for(let r of e.tools||[])t.push({name:r.name,description:r.description,input_schema:r.input_schema||{type:"object",properties:{}}});if(!n[e.serverName])if(typeof e.resolve=="function"){let r=e.resolve();r&&(n[e.serverName]={...r,toolPrefix:i})}else{let r={};for(let c of e.envKeys||[]){let a=process.env[c];a&&(r[c]=a)}n[e.serverName]={command:e.command,args:[...e.args||[]],env:r,toolPrefix:i}}}return s.length===0?null:{toolIds:s,claudeTools:t,mcpServers:n}}export{k as NODE_DEFAULT_TOOLS,m as getResolvedToolDefinitions,S as resolveNodeTools};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/agent-workflow",
3
- "version": "0.1.4",
3
+ "version": "0.3.0",
4
4
  "description": "Graph-based AI agent workflow orchestration. Bring your own agent strategies.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",