@zibby/agent-workflow 2.0.3 → 2.0.5

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,34 +1,34 @@
1
- var W=Object.defineProperty;var x=(e,n,t)=>()=>{if(t)throw t[0];try{return e&&(n=e(e=0)),n}catch(r){throw t=[r],r}};var H=(e,n)=>{for(var t in n)W(e,t,{get:n[t],enumerable:!0})};function O(e){return J.get(e)||null}var A,I,J,de,j=x(()=>{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);J=globalThis[A],de=globalThis[I]});var M,q,_,b,C=x(()=>{M=()=>{},q={debug:M,info:M,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},_={impl:q},b={debug:(...e)=>_.impl.debug?.(...e),info:(...e)=>_.impl.info?.(...e),warn:(...e)=>_.impl.warn?.(...e),error:(...e)=>_.impl.error?.(...e)}});var D=x(()=>{});var F={};H(F,{getAgentStrategy:()=>B,invokeAgent:()=>X,listStrategies:()=>Q,registerStrategy:()=>Z,resolveInvocationExtras:()=>z,resolveInvocationModel:()=>G});function Z(e){if(!e||typeof e.getName!="function"||typeof e.invoke!="function")throw new Error("strategy must implement getName() and invoke() (AgentStrategy shape)");let n=k.findIndex(t=>t.getName()===e.getName());n>=0?k[n]=e:k.push(e)}function Q(){return k.map(e=>e.getName())}function G({config:e={},options:n={},strategyName:t,envModel:r,nodeConfigModel:i}={}){let s=e.models||{},o=typeof i=="string"&&i.trim()?i.trim():null,c=n.nodeName&&s[n.nodeName]||null,a=s.default||null,l=e.agent?.[t]?.model||null,h=(typeof r=="string"?r.trim():"")||null;return o||c||a||l||n.model||h||null}function z({options:e={},stateView:n={},context:t={}}={}){return{workspace:n.workspace||e.workspace,schema:e.schema||t.schema,images:e.images||t.images||[],skills:e.skills||t.skills||[],extraMcpServers:e.extraMcpServers||n.extraMcpServers||t.extraMcpServers||[],plugins:e.plugins||t.plugins||[]}}function B(e={}){let{state:n={},preferredAgent:t=null}=e,r=t||n.agentType||process.env.AGENT_TYPE;if(!r){let s=k.map(o=>o.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${s}`)}b.debug(`[workflow] agent selection: requested=${r}`);let i=k.find(s=>s.getName()===r);if(!i){let s=k.map(o=>o.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${s}`)}if(!i.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return b.debug(`[workflow] using agent: ${i.getName()}`),i}async function X(e,n={},t={}){let r=n.state&&typeof n.state.getAll=="function"?n.state.getAll():n.state||{},i={...n,state:r},s=B(i),o=r.config||t.config||{},c=r._currentNodeConfig||{},a=typeof c.agent=="string"?c.agent.trim():"",l=!a||a===s.name?c.model:null,h=G({config:o,options:t,strategyName:s.name,envModel:process.env.MODEL,nodeConfigModel:l}),T={...t,model:h,...z({options:t,stateView:r,context:n}),config:o},m=e,S=T.skills||[];if(S.length>0&&!t.skipPromptFragments){let u=t.connectedIntegrations;if(!u){let p=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof p=="string"&&p.trim()!==""){u={};for(let g of p.split(",").map(w=>w.trim()).filter(Boolean))u[g]=!0}}let y=p=>{let g=p&&p.requiresIntegration;return!g||!u?!0:(Array.isArray(g)?g:[g]).some(E=>u[E]===!0)},f=s.name==="assistant",v=p=>p?.inProcessOnly!==!0||f,$=S.map(p=>{let g=O(p);if(!y(g)||!v(g))return null;let w=g?.promptFragment;return typeof w=="function"?w():w}).filter(Boolean);$.length>0&&(m+=`
1
+ var H=Object.defineProperty;var x=(e,n,o)=>()=>{if(o)throw o[0];try{return e&&(n=e(e=0)),n}catch(r){throw o=[r],r}};var J=(e,n)=>{for(var o in n)H(e,o,{get:n[o],enumerable:!0})};function O(e){return q.get(e)||null}var A,I,q,pe,j=x(()=>{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);q=globalThis[A],pe=globalThis[I]});var L,Z,C,_,N,R=x(()=>{L=()=>{},Z={debug:L,info:L,warn:(...e)=>console.warn("[workflow]",...e),error:(...e)=>console.error("[workflow]",...e)},C=Symbol.for("@zibby/agent-workflow.logger");globalThis[C]||(globalThis[C]={impl:Z});_=globalThis[C],N={debug:(...e)=>_.impl.debug?.(...e),info:(...e)=>_.impl.info?.(...e),warn:(...e)=>_.impl.warn?.(...e),error:(...e)=>_.impl.error?.(...e)}});var z=x(()=>{});var Y={};J(Y,{getAgentStrategy:()=>F,invokeAgent:()=>ee,listStrategies:()=>X,registerStrategy:()=>Q,resolveInvocationExtras:()=>B,resolveInvocationModel:()=>G});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 n=k.findIndex(o=>o.getName()===e.getName());n>=0?k[n]=e:k.push(e)}function X(){return k.map(e=>e.getName())}function G({config:e={},options:n={},strategyName:o,envModel:r,nodeConfigModel:i}={}){let s=e.models||{},t=typeof i=="string"&&i.trim()?i.trim():null,c=n.nodeName&&s[n.nodeName]||null,a=s.default||null,l=e.agent?.[o]?.model||null,h=(typeof r=="string"?r.trim():"")||null;return t||c||a||l||n.model||h||null}function B({options:e={},stateView:n={},context:o={}}={}){return{workspace:n.workspace||e.workspace,schema:e.schema||o.schema,images:e.images||o.images||[],skills:e.skills||o.skills||[],extraMcpServers:e.extraMcpServers||n.extraMcpServers||o.extraMcpServers||[],plugins:e.plugins||o.plugins||[]}}function F(e={}){let{state:n={},preferredAgent:o=null}=e,r=o||n.agentType||process.env.AGENT_TYPE;if(!r){let s=k.map(t=>t.getName()).join(", ")||"none registered";throw new Error(`No agent specified. Set agentType in state or AGENT_TYPE env var. Available: ${s}`)}N.debug(`[workflow] agent selection: requested=${r}`);let i=k.find(s=>s.getName()===r);if(!i){let s=k.map(t=>t.getName()).join(", ")||"none registered";throw new Error(`Unknown agent '${r}'. Available: ${s}`)}if(!i.canHandle(e))throw new Error(`Agent '${r}' is not available in this environment. Check credentials/environment.`);return N.debug(`[workflow] using agent: ${i.getName()}`),i}async function ee(e,n={},o={}){let r=n.state&&typeof n.state.getAll=="function"?n.state.getAll():n.state||{},i={...n,state:r},s=F(i),t=r.config||o.config||{},c=r._currentNodeConfig||{},a=typeof c.agent=="string"?c.agent.trim():"",l=!a||a===s.name?c.model:null,h=G({config:t,options:o,strategyName:s.name,envModel:process.env.MODEL,nodeConfigModel:l}),T={...o,model:h,...B({options:o,stateView:r,context:n}),config:t},m=e,b=T.skills||[];if(b.length>0&&!o.skipPromptFragments){let f=o.connectedIntegrations;if(!f){let p=process.env.WORKFLOW_CONNECTED_INTEGRATIONS;if(typeof p=="string"&&p.trim()!==""){f={};for(let g of p.split(",").map(w=>w.trim()).filter(Boolean))f[g]=!0}}let y=p=>{let g=p&&p.requiresIntegration;return!g||!f?!0:(Array.isArray(g)?g:[g]).some(E=>f[E]===!0)},u=s.name==="assistant",v=p=>p?.inProcessOnly!==!0||u,$=b.map(p=>{let g=O(p);if(!y(g)||!v(g))return null;let w=g?.promptFragment;return typeof w=="function"?w():w}).filter(Boolean);$.length>0&&(m+=`
2
2
 
3
3
  ${$.join(`
4
4
 
5
- `)}`)}let d=r._currentNodeConfig?.stores;if(Array.isArray(d)&&d.length>0&&typeof d[0]=="object"){let u=d.length<=8,y=d.map(f=>{let v=f?.id??f?.storeId??"",$=(f?.name??"").toString().trim()||v,p=f?.type?` \xB7 ${f.type}`:"",g=(f?.description||"").toString().replace(/\s+/g," ").trim(),w=`- ${$} \xB7 ${g||"(no description)"}${p} (id: ${v})`;if(u&&f?.schema&&typeof f.schema=="object"){let E=f.schema.properties&&typeof f.schema.properties=="object"?Object.keys(f.schema.properties):Object.keys(f.schema);E.length&&(w+=`
5
+ `)}`)}let d=r._currentNodeConfig?.stores;if(Array.isArray(d)&&d.length>0&&typeof d[0]=="object"){let f=d.length<=8,y=d.map(u=>{let v=u?.id??u?.storeId??"",$=(u?.name??"").toString().trim()||v,p=u?.type?` \xB7 ${u.type}`:"",g=(u?.description||"").toString().replace(/\s+/g," ").trim(),w=`- ${$} \xB7 ${g||"(no description)"}${p} (id: ${v})`;if(f&&u?.schema&&typeof u.schema=="object"){let E=u.schema.properties&&typeof u.schema.properties=="object"?Object.keys(u.schema.properties):Object.keys(u.schema);E.length&&(w+=`
6
6
  fields: ${E.join(", ")}`)}return w});m+=`
7
7
 
8
8
  AVAILABLE STORES (pick a store by its description and pass its NAME to the store tool):
9
9
  ${y.join(`
10
- `)}`}let N=r._currentNodeConfig?.extraPromptInstructions?.trim();return N&&(m+=`
10
+ `)}`}let S=r._currentNodeConfig?.extraPromptInstructions?.trim();return S&&(m+=`
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
- ${N}
17
- `),b.debug(`[workflow] prompt length: ${m.length} chars`),s.invoke(m,T)}var R,k,Y=x(()=>{D();C();j();R=Symbol.for("@zibby/agent-workflow.strategies");globalThis[R]||(globalThis[R]=[]);k=globalThis[R]});j();C();var L={};var P=Symbol.for("@zibby/agent-workflow.nodes");globalThis[P]||(globalThis[P]=new Map);var U=globalThis[P];function ee(e,n){U.set(e,n)}function V(e){let n=U.get(e);return n?n.factory&&typeof n.create=="function"?n.create.toString():typeof n.execute=="function"?n.execute.toString():typeof n=="function"?n.toString():null:null}ee("ai_agent",{name:"ai_agent",factory:!0,create:(e,n={})=>({name:e,_isCustomCode:!0,execute:async t=>{let r=t?._coreInvokeAgent;r||(r=(await Promise.resolve().then(()=>(Y(),F))).invokeAgent);let i=n.extraPromptInstructions||"Execute the task based on the current state.",s=ne(i,t),o=await r(s,{cwd:t.workspace||process.cwd(),model:t.model,tools:n.resolvedTools||null});return{success:!0,output:{raw:o,nodeId:e},raw:typeof o=="string"?o:o.raw}}})});function ne(e,n){let t=/@([\w.]+)/g,r=new Set,i;for(;(i=t.exec(e))!==null;)r.add(i[1]);if(r.size===0)return e;let s=[],o=new Set;for(let c of r){let a=c.split(".")[0];if(o.has(a))continue;let l=c.split(".").reduce((m,S)=>m?.[S],n);if(l===void 0)continue;let h=typeof l=="string"?l:l?.raw??JSON.stringify(l,null,2),T=c.replace(/_/g," ").replace(/\b\w/g,m=>m.toUpperCase());s.push(`## ${T}
18
- ${h}`),c.includes(".")||o.add(a)}return s.length===0?e:`${e}
16
+ ${S}
17
+ `),N.debug(`[workflow] prompt length: ${m.length} chars`),s.invoke(m,T)}var P,k,U=x(()=>{z();R();j();P=Symbol.for("@zibby/agent-workflow.strategies");globalThis[P]||(globalThis[P]=[]);k=globalThis[P]});j();R();var D={};var M=Symbol.for("@zibby/agent-workflow.nodes");globalThis[M]||(globalThis[M]=new Map);var V=globalThis[M];function ne(e,n){V.set(e,n)}function K(e){let n=V.get(e);return n?n.factory&&typeof n.create=="function"?n.create.toString():typeof n.execute=="function"?n.execute.toString():typeof n=="function"?n.toString():null:null}ne("ai_agent",{name:"ai_agent",factory:!0,create:(e,n={})=>({name:e,_isCustomCode:!0,execute:async o=>{let r=o?._coreInvokeAgent;r||(r=(await Promise.resolve().then(()=>(U(),Y))).invokeAgent);let i=n.extraPromptInstructions||"Execute the task based on the current state.",s=oe(i,o),t=await r(s,{cwd:o.workspace||process.cwd(),model:o.model,tools:n.resolvedTools||null});return{success:!0,output:{raw:t,nodeId:e},raw:typeof t=="string"?t:t.raw}}})});function oe(e,n){let o=/@([\w.]+)/g,r=new Set,i;for(;(i=o.exec(e))!==null;)r.add(i[1]);if(r.size===0)return e;let s=[],t=new Set;for(let c of r){let a=c.split(".")[0];if(t.has(a))continue;let l=c.split(".").reduce((m,b)=>m?.[b],n);if(l===void 0)continue;let h=typeof l=="string"?l:l?.raw??JSON.stringify(l,null,2),T=c.replace(/_/g," ").replace(/\b\w/g,m=>m.toUpperCase());s.push(`## ${T}
18
+ ${h}`),c.includes(".")||t.add(a)}return s.length===0?e:`${e}
19
19
 
20
20
  ---
21
21
  # Referenced Context
22
22
 
23
23
  ${s.join(`
24
24
 
25
- `)}`}function Ee(e,n={}){let{nodes:t,edges:r,nodeConfigs:i={}}=e,s=new Set,o=[],c=new Map;for(let u of t){let y=u.data?.nodeType||u.type;c.set(u.id,y),y==="decision"?s.add(u.id):o.push({id:u.id,nodeType:y,label:u.data?.label||u.id})}let a=o.some(u=>{let y=i[u.id]||{};return!y.customCode&&!y.executeCode}),{toolsPerNode:l,toolIdsByVar:h}=ce(o,i),{simpleEdges:T,conditionalEdges:m}=le(r,s),S=ue(o,r,s),d=[],N=n.workflowType||"workflow";return d.push(te(n)),d.push(oe(N,{usesRegisteredNodes:a})),d.push(re(h)),d.push(se(N)),d.push(ie(o,i)),d.push(ae(o,S,T,m,l,N)),d.filter(Boolean).join(`
26
- `)}function xe(e){let n={};for(let[t,r]of Object.entries(e)){let{tools:i,...s}=r;Object.keys(s).length>0&&(n[t]=s)}return n}function te(e){let n=e.workflowType||"workflow";return["// Generated workflow",`// ${e.projectId?`Project: ${e.projectId} | `:""}Type: ${n} | Version: ${e.version??0}`,`// Downloaded: ${new Date().toISOString()}`,""].join(`
27
- `)}function oe(e,{usesRegisteredNodes:n=!0}={}){let t=["import { WorkflowGraph, invokeAgent, getResolvedToolDefinitions } from '@zibby/agent-workflow';"];return n&&t.push("// import './register-nodes.js'; // register custom node types here"),t.push("import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';","import { join, dirname } from 'node:path';","import { fileURLToPath } from 'node:url';",""),t.join(`
28
- `)}function re(e){if(e.size===0)return"";let n=["// \u2500\u2500 Tool Bindings \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];for(let[t,r]of e)n.push(`const ${t} = getResolvedToolDefinitions(${JSON.stringify(r)}); // ${r.join(", ")}`);return n.push(""),n.join(`
29
- `)}function se(e){return["// \u2500\u2500 Node Configs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500","const __filename = fileURLToPath(import.meta.url);","const __dirname = dirname(__filename);",`const configPath = join(__dirname, 'workflow-${e}.config.json');`,"const nodeConfigs = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};",""].join(`
30
- `)}function ie(e,n){let t=["// \u2500\u2500 Node Implementations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",""];for(let r of e){let i=K(r.id),s=n[r.id]?.customCode;if(s)t.push(`// @custom \u2014 modified from default "${r.nodeType}" template`),t.push(`const ${i}_execute = ${s};`);else{let o=V(r.nodeType);o?(t.push(`// Default "${r.nodeType}" implementation`),t.push(`const ${i}_execute = ${o};`)):(t.push(`// No template for "${r.nodeType}" \u2014 passthrough`),t.push(`const ${i}_execute = async (state) => ({ success: true, output: {}, raw: null });`))}t.push("")}return t.join(`
31
- `)}function ae(e,n,t,r,i,s){let o=["// \u2500\u2500 Graph Builder \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];o.push("export function buildGraph(options = {}) {"),o.push(" const graph = new WorkflowGraph(options);",""),o.push(" // Nodes");for(let a of e){let l=K(a.id);o.push(` graph.addNode('${a.id}', { name: '${a.id}', execute: ${l}_execute });`),o.push(` graph.setNodeType('${a.id}', '${a.nodeType}');`)}o.push("",` graph.setEntryPoint('${n}');`,""),(t.length>0||r.length>0)&&o.push(" // Edges");for(let a of t)o.push(` graph.addEdge('${a.source}', '${a.target}');`);for(let a of r){let l=a.code.split(`
25
+ `)}`}function xe(e,n={}){let{nodes:o,edges:r,nodeConfigs:i={}}=e,s=new Set,t=[],c=new Map;for(let f of o){let y=f.data?.nodeType||f.type;c.set(f.id,y),y==="decision"?s.add(f.id):t.push({id:f.id,nodeType:y,label:f.data?.label||f.id})}let a=t.some(f=>{let y=i[f.id]||{};return!y.customCode&&!y.executeCode}),{toolsPerNode:l,toolIdsByVar:h}=le(t,i),{simpleEdges:T,conditionalEdges:m}=fe(r,s),b=ue(t,r,s),d=[],S=n.workflowType||"workflow";return d.push(te(n)),d.push(re(S,{usesRegisteredNodes:a})),d.push(se(h)),d.push(ie(S)),d.push(ae(t,i)),d.push(ce(t,b,T,m,l,S)),d.filter(Boolean).join(`
26
+ `)}function _e(e){let n={};for(let[o,r]of Object.entries(e)){let{tools:i,...s}=r;Object.keys(s).length>0&&(n[o]=s)}return n}function te(e){let n=e.workflowType||"workflow";return["// Generated workflow",`// ${e.projectId?`Project: ${e.projectId} | `:""}Type: ${n} | Version: ${e.version??0}`,`// Downloaded: ${new Date().toISOString()}`,""].join(`
27
+ `)}function re(e,{usesRegisteredNodes:n=!0}={}){let o=["import { WorkflowGraph, invokeAgent, getResolvedToolDefinitions } from '@zibby/agent-workflow';"];return n&&o.push("// import './register-nodes.js'; // register custom node types here"),o.push("import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';","import { join, dirname } from 'node:path';","import { fileURLToPath } from 'node:url';",""),o.join(`
28
+ `)}function se(e){if(e.size===0)return"";let n=["// \u2500\u2500 Tool Bindings \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];for(let[o,r]of e)n.push(`const ${o} = getResolvedToolDefinitions(${JSON.stringify(r)}); // ${r.join(", ")}`);return n.push(""),n.join(`
29
+ `)}function ie(e){return["// \u2500\u2500 Node Configs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500","const __filename = fileURLToPath(import.meta.url);","const __dirname = dirname(__filename);",`const configPath = join(__dirname, 'workflow-${e}.config.json');`,"const nodeConfigs = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};",""].join(`
30
+ `)}function ae(e,n){let o=["// \u2500\u2500 Node Implementations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",""];for(let r of e){let i=W(r.id),s=n[r.id]?.customCode;if(s)o.push(`// @custom \u2014 modified from default "${r.nodeType}" template`),o.push(`const ${i}_execute = ${s};`);else{let t=K(r.nodeType);t?(o.push(`// Default "${r.nodeType}" implementation`),o.push(`const ${i}_execute = ${t};`)):(o.push(`// No template for "${r.nodeType}" \u2014 passthrough`),o.push(`const ${i}_execute = async (state) => ({ success: true, output: {}, raw: null });`))}o.push("")}return o.join(`
31
+ `)}function ce(e,n,o,r,i,s){let t=["// \u2500\u2500 Graph Builder \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];t.push("export function buildGraph(options = {}) {"),t.push(" const graph = new WorkflowGraph(options);",""),t.push(" // Nodes");for(let a of e){let l=W(a.id);t.push(` graph.addNode('${a.id}', { name: '${a.id}', execute: ${l}_execute });`),t.push(` graph.setNodeType('${a.id}', '${a.nodeType}');`)}t.push("",` graph.setEntryPoint('${n}');`,""),(o.length>0||r.length>0)&&t.push(" // Edges");for(let a of o)t.push(` graph.addEdge('${a.source}', '${a.target}');`);for(let a of r){let l=a.code.split(`
32
32
  `).map((h,T)=>T===0?h:` ${h}`).join(`
33
- `);o.push(` graph.addConditionalEdges('${a.source}', ${l});`)}let c=[];for(let a of e){let l=i.get(a.id);l&&c.push(` '${a.id}': ${l},`)}return c.length>0&&o.push(""," graph.resolvedToolsMap = {",...c," };"),o.push(""," return graph;","}",""),o.push("export { nodeConfigs };",""),o.join(`
34
- `)}function ce(e,n){let t=new Map,r=new Map;for(let i of e){let s=n[i.id]?.tools,o;if(Array.isArray(s)&&s.length>0)o=[...s].sort();else{let c=L[i.nodeType];c?.length>0&&(o=[...c].sort())}if(o){let c=`${o.map(a=>a.replace(/[^a-zA-Z0-9]/g,"")).join("And")}Tools`;t.set(i.id,c),r.has(c)||r.set(c,o)}}return{toolsPerNode:t,toolIdsByVar:r}}function le(e,n){let t=[],r=[],i=new Map,s=new Set;for(let o of e)i.has(o.source)||i.set(o.source,[]),i.get(o.source).push(o);for(let o of e)if(!n.has(o.source))if(n.has(o.target)){if(s.has(o.target))continue;s.add(o.target);let a=(i.get(o.target)||[]).find(l=>l.data?.conditionalCode||l.conditionalCode);a&&r.push({source:o.source,code:a.data?.conditionalCode||a.conditionalCode})}else t.push({source:o.source,target:o.target});return{simpleEdges:t,conditionalEdges:r}}function ue(e,n,t){let r=new Set;for(let s of n)t.has(s.target)||r.add(s.target);let i=e.find(s=>!r.has(s.id));return i?i.id:e[0]?.id}function K(e){return e.replace(/[^a-zA-Z0-9]/g,"_")}export{xe as generateNodeConfigsJson,Ee as generateWorkflowCode};
33
+ `);t.push(` graph.addConditionalEdges('${a.source}', ${l});`)}let c=[];for(let a of e){let l=i.get(a.id);l&&c.push(` '${a.id}': ${l},`)}return c.length>0&&t.push(""," graph.resolvedToolsMap = {",...c," };"),t.push(""," return graph;","}",""),t.push("export { nodeConfigs };",""),t.join(`
34
+ `)}function le(e,n){let o=new Map,r=new Map;for(let i of e){let s=n[i.id]?.tools,t;if(Array.isArray(s)&&s.length>0)t=[...s].sort();else{let c=D[i.nodeType];c?.length>0&&(t=[...c].sort())}if(t){let c=`${t.map(a=>a.replace(/[^a-zA-Z0-9]/g,"")).join("And")}Tools`;o.set(i.id,c),r.has(c)||r.set(c,t)}}return{toolsPerNode:o,toolIdsByVar:r}}function fe(e,n){let o=[],r=[],i=new Map,s=new Set;for(let t of e)i.has(t.source)||i.set(t.source,[]),i.get(t.source).push(t);for(let t of e)if(!n.has(t.source))if(n.has(t.target)){if(s.has(t.target))continue;s.add(t.target);let a=(i.get(t.target)||[]).find(l=>l.data?.conditionalCode||l.conditionalCode);a&&r.push({source:t.source,code:a.data?.conditionalCode||a.conditionalCode})}else o.push({source:t.source,target:t.target});return{simpleEdges:o,conditionalEdges:r}}function ue(e,n,o){let r=new Set;for(let s of n)o.has(s.target)||r.add(s.target);let i=e.find(s=>!r.has(s.id));return i?i.id:e[0]?.id}function W(e){return e.replace(/[^a-zA-Z0-9]/g,"_")}export{_e as generateNodeConfigsJson,xe as generateWorkflowCode};
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Fetch deadlines — the ONE declaration, so the engine's HTTP doors cannot
3
+ * drift apart.
4
+ * ============================================================================
5
+ *
6
+ * WHY THIS FILE EXISTS AT ALL. Node's global fetch has NO default timeout, and
7
+ * A HANG IS NOT A THROW: a connection that is accepted and then never answered
8
+ * is not an error any `catch` can see, it is a process that stops. Every HTTP
9
+ * door in this engine is already written for failure — a trigger rejection is
10
+ * booked per-child by the caller's `Promise.allSettled`, a poll transport throw
11
+ * is retried, a `begin` failure falls back to the HTTP path — and NONE of that
12
+ * code can run for the one failure mode that actually costs a run.
13
+ *
14
+ * MEASURED, not hypothetical: board-runner run 4b49371e (2026-08-24) sat 7m33s
15
+ * inside the identical unbounded shape until the container watchdog killed it,
16
+ * and a tick that had already done all of its work recorded nothing. The same
17
+ * class has been closed in workflow-templates' lib/kb.js (d7e3184),
18
+ * lib/platform-api.js (7a355cc), _shared/tracker.js (539483e) and
19
+ * @zibby/core's backend-client.js.
20
+ *
21
+ * WHY THE HELPERS LIVE HERE AND NOT NEXT TO THEIR CALL SITES. The engine has
22
+ * two files that dispatch a child — `sub-graph-executor.ts` (HTTP) and
23
+ * `in-process-subgraph.ts` (in-process, which FALLS BACK to the other) — and
24
+ * they are two halves of one dispatch. Copying a clamp, a `TimeoutError` check
25
+ * and a budget into both is precisely the TWO-PLACES shape that produced every
26
+ * incident this rule was written for: a pair that must agree with nothing to
27
+ * scream when it drifts. One declaration, N consumers, no tripwire needed
28
+ * because there is nothing to keep in sync.
29
+ *
30
+ * ⚠️ Deliberately DEPENDENCY-FREE (not even the logger) so any module can
31
+ * import it without a cycle — `in-process-subgraph.ts` is imported BY
32
+ * `sub-graph-executor.ts`, so the budgets could not have lived in the latter.
33
+ */
34
+ export declare const SUBGRAPH_TRIGGER_TIMEOUT_MS = 30000;
35
+ export declare const SUBGRAPH_POLL_TIMEOUT_MS = 15000;
36
+ export declare const SUBGRAPH_BUNDLE_TIMEOUT_MS = 60000;
37
+ /** curl's connect phase only — a stalled DNS/TCP handshake, distinct from a
38
+ * slow but progressing transfer. Not separately overridable: it is a fixed
39
+ * fraction of the class, and one more knob would be one more thing to drift. */
40
+ export declare const SUBGRAPH_CONNECT_TIMEOUT_MS = 10000;
41
+ export declare const TIMEOUT_FLOOR_MS = 1000;
42
+ export declare const TIMEOUT_CEILING_MS = 120000;
43
+ /**
44
+ * Read a budget from the environment, or fall back. Clamped to
45
+ * [TIMEOUT_FLOOR_MS, TIMEOUT_CEILING_MS]; anything unparseable or non-positive
46
+ * (`0`, `-1`, `''`, `'soon'`) falls back rather than disabling the bound.
47
+ */
48
+ export declare function timeoutMsFrom(knob: string, fallback: number, env?: any): number;
49
+ /**
50
+ * ONE deadline for ONE call: the `signal` the request AND its body reads share
51
+ * — a response whose headers arrive and whose body then stalls is the same
52
+ * hang, and bounding only the first half leaves the door open — plus the
53
+ * `label` a timeout reports itself with.
54
+ *
55
+ * The label names the budget AND its knob because whoever reads the run log has
56
+ * to tell a SLOW control plane (raise the knob, or accept the failure) from a
57
+ * BROKEN one (an ordinary transport error, which keeps its existing wording).
58
+ * One spelling for both is how a hang stays invisible for as long as this one
59
+ * did.
60
+ */
61
+ export declare function makeDeadline(ms: number, knob: string): {
62
+ signal: AbortSignal;
63
+ label: string;
64
+ };
65
+ /** Build a deadline straight from a knob + default. */
66
+ export declare function deadlineFor(knob: string, fallback: number): {
67
+ signal: AbortSignal;
68
+ label: string;
69
+ };
70
+ /**
71
+ * `AbortSignal.timeout` aborts with a `TimeoutError` DOMException (undici
72
+ * rejects the fetch — and any in-flight body read — with that same reason); a
73
+ * caller-cancelled signal aborts with `AbortError`. Both mean "we stopped
74
+ * waiting"; NEITHER means "the far end said no", which is why every call site
75
+ * branches on this before deciding whether to reword an error or rethrow it
76
+ * unchanged.
77
+ */
78
+ export declare function isTimeoutError(err: any): boolean;
@@ -0,0 +1 @@
1
+ var i=3e4,M=15e3,T=6e4,u=1e4,s=1e3,E=12e4;function o(t,r,e=process.env){let n=Number(e[t]);return Number.isFinite(n)&&n>0?Math.min(12e4,Math.max(1e3,Math.floor(n))):r}function _(t,r){return{signal:AbortSignal.timeout(t),label:`after ${t}ms (${r})`}}function a(t,r){return _(o(t,r),t)}function m(t){return t?.name==="TimeoutError"||t?.name==="AbortError"}export{T as SUBGRAPH_BUNDLE_TIMEOUT_MS,u as SUBGRAPH_CONNECT_TIMEOUT_MS,M as SUBGRAPH_POLL_TIMEOUT_MS,i as SUBGRAPH_TRIGGER_TIMEOUT_MS,E as TIMEOUT_CEILING_MS,s as TIMEOUT_FLOOR_MS,a as deadlineFor,m as isTimeoutError,_ as makeDeadline,o as timeoutMsFrom};