@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/code-generator.js +17 -17
- package/dist/graph-compiler.js +21 -21
- package/dist/graph.js +20 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -32
- package/dist/node-registry.js +10 -10
- package/dist/node.js +18 -18
- package/dist/strategy-registry.d.ts +16 -0
- package/dist/strategy-registry.js +6 -6
- package/package.json +1 -1
package/dist/node.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
var
|
|
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
|
-
${
|
|
3
|
+
${m.join(`
|
|
4
4
|
|
|
5
|
-
`)}`)}let
|
|
6
|
-
fields: ${
|
|
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
|
-
${
|
|
10
|
-
`)}`}let
|
|
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
|
-
${
|
|
17
|
-
`),
|
|
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}};
|
|
20
|
-
`?(
|
|
21
|
-
${
|
|
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=`${
|
|
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(
|
|
29
|
-
`)}stepInfo(t){this.step(t)}stepTool(t){this._origStdoutWrite?this._writeDot(
|
|
30
|
-
`)}stepMemory(t){let e=
|
|
31
|
-
`)}stepFail(t){this._origStdoutWrite?this._writeDot(
|
|
32
|
-
`)}nodeStart(t){this._currentNode=t,this._emitGraphLogMarker({phase:"node_begin",node:t}),this._rawWrite(`${
|
|
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
|
-
${
|
|
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
|
|
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
|
|
6
|
-
fields: ${
|
|
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
|
|
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
|
-
`),
|
|
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};
|