@jagreehal/workflow 1.3.0 → 1.4.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.
- package/README.md +119 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +215 -1
- package/dist/core.d.ts +215 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/visualize.cjs +6 -6
- package/dist/visualize.cjs.map +1 -1
- package/dist/visualize.d.cts +6 -0
- package/dist/visualize.d.ts +6 -0
- package/dist/visualize.js +6 -6
- package/dist/visualize.js.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.js +1 -1
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
package/dist/visualize.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var
|
|
2
|
-
`)}}}function J(e,n,t,r){let
|
|
3
|
-
`)}}}function Z(e,n,t){if(O(e))return
|
|
4
|
-
`),
|
|
5
|
-
`).length)}function I(){
|
|
6
|
-
`),
|
|
1
|
+
"use strict";var X=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var ge=(e,n)=>{for(var t in n)X(e,t,{get:n[t],enumerable:!0})},we=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of he(n))!me.call(e,s)&&s!==t&&X(e,s,{get:()=>n[s],enumerable:!(r=fe(n,s))||r.enumerable});return e};var be=e=>we(X({},"__esModule",{value:!0}),e);var Ae={};ge(Ae,{asciiRenderer:()=>W,createEventCollector:()=>Ve,createIRBuilder:()=>F,createLiveVisualizer:()=>le,createParallelDetector:()=>re,createVisualizer:()=>H,defaultColorScheme:()=>M,detectParallelGroups:()=>z,hasChildren:()=>Se,isDecisionNode:()=>A,isParallelNode:()=>P,isRaceNode:()=>V,isSequenceNode:()=>$e,isStepNode:()=>O,mermaidRenderer:()=>j,trackDecision:()=>Y,trackIf:()=>ue,trackSwitch:()=>pe,visualizeEvents:()=>Pe});module.exports=be(Ae);function C(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let n=Math.floor(e/6e4),t=Math.round(e%6e4/1e3);return t===0?`${n}m`:`${n}m ${t}s`}function Q(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function ke(e){for(let n of e)if((n.type==="parallel"||n.type==="race"||n.type==="sequence")&&!n.id.startsWith("detected_")||"decisionId"in n)return!0;return!1}function z(e,n={}){if(ke(e))return e;let{maxGapMs:t=5}=n,r=[],s=[];for(let c=0;c<e.length;c++){let a=e[c];a.type==="step"&&a.startTs!==void 0?r.push({node:a,startTs:a.startTs,endTs:a.endTs??a.startTs+(a.durationMs??0),originalIndex:c}):s.push({node:a,originalIndex:c})}if(r.length<=1)return e;r.sort((c,a)=>c.startTs-a.startTs);let o=[],u=[r[0]];for(let c=1;c<r.length;c++){let a=r[c],l=Math.max(...u.map(m=>m.endTs));a.startTs<=l+t?u.push(a):(o.push(u),u=[a])}o.push(u);let f=[];for(let c of o){let a=Math.min(...c.map(l=>l.originalIndex));if(c.length===1)f.push({node:c[0].node,position:a});else{let l=c.map(w=>w.node),m=Math.min(...c.map(w=>w.startTs)),b=Math.max(...c.map(w=>w.endTs)),g={type:"parallel",id:`detected_parallel_${m}`,name:`${l.length} parallel steps`,state:ye(l),mode:"all",children:l,startTs:m,endTs:b,durationMs:b-m};f.push({node:g,position:a})}}for(let{node:c,originalIndex:a}of s)f.push({node:c,position:a});return f.sort((c,a)=>c.position-a.position),f.map(c=>c.node)}function ye(e){return e.some(o=>o.state==="error")?"error":e.some(o=>o.state==="running")?"running":e.some(o=>o.state==="pending")?"pending":(e.every(o=>o.state==="success"||o.state==="cached"),"success")}function re(e={}){return{detect:n=>z(n,e)}}function F(e={}){let{detectParallel:n=!0,parallelDetection:t}=e,r,s,o="pending",u,f,c=new Map,a=[],l=[],m=[],b=Date.now(),g=b;function w(i){return i.stepId??i.stepKey??i.name??Q()}function y(i){if(l.length>0){let d=l[l.length-1];for(let v of d.branches.values())if(v.taken){v.children.push(i),g=Date.now();return}let p=Array.from(d.branches.values())[0];if(p){p.children.push(i),g=Date.now();return}}a.length>0?a[a.length-1].children.push(i):m.push(i),g=Date.now()}function S(i){switch(i.type){case"workflow_start":r=i.workflowId,s=i.ts,o="running",b=Date.now(),g=b;break;case"workflow_success":o="success",f=i.durationMs,g=Date.now();break;case"workflow_error":o="error",u=i.error,f=i.durationMs,g=Date.now();break;case"step_start":{let d=w(i);c.set(d,{id:d,name:i.name,key:i.stepKey,startTs:i.ts,retryCount:0,timedOut:!1}),g=Date.now();break}case"step_success":{let d=w(i),p=c.get(d);if(p){let v={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:i.ts,durationMs:i.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};y(v),c.delete(d)}break}case"step_error":{let d=w(i),p=c.get(d);if(p){let v={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:i.ts,durationMs:i.durationMs,error:i.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};y(v),c.delete(d)}break}case"step_aborted":{let d=w(i),p=c.get(d);if(p){let v={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:i.ts,durationMs:i.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};y(v),c.delete(d)}break}case"step_cache_hit":{let p={type:"step",id:w(i),name:i.name,key:i.stepKey,state:"cached",startTs:i.ts,endTs:i.ts,durationMs:0};y(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let d=w(i),p=c.get(d);p&&(p.timedOut=!0,p.timeoutMs=i.timeoutMs),g=Date.now();break}case"step_retry":{let d=w(i),p=c.get(d);p&&(p.retryCount=(i.attempt??1)-1),g=Date.now();break}case"step_retries_exhausted":g=Date.now();break;case"step_skipped":{let p={type:"step",id:w(i),name:i.name,key:i.stepKey,state:"skipped",startTs:i.ts,endTs:i.ts,durationMs:0};y(p);break}}}function D(i){if(i.type==="scope_start")a.push({id:i.scopeId,name:i.name,type:i.scopeType,startTs:i.ts,children:[]}),g=Date.now();else if(i.type==="scope_end"){let d=a.pop();if(d){let p=d.type==="race"?{type:"race",id:d.id,name:d.name,state:T(d.children),startTs:d.startTs,endTs:i.ts,durationMs:i.durationMs,children:d.children,winnerId:i.winnerId}:{type:"parallel",id:d.id,name:d.name,state:T(d.children),startTs:d.startTs,endTs:i.ts,durationMs:i.durationMs,children:d.children,mode:d.type==="allSettled"?"allSettled":"all"};y(p)}}}function I(i){if(i.type==="decision_start")l.push({id:i.decisionId,name:i.name,condition:i.condition,decisionValue:i.decisionValue,startTs:i.ts,branches:new Map}),g=Date.now();else if(i.type==="decision_branch"){let d=l[l.length-1];if(d&&d.id===i.decisionId){let p=i.branchLabel,v=d.branches.get(p);v?v.taken=i.taken:d.branches.set(p,{label:i.branchLabel,condition:i.condition,taken:i.taken,children:[]}),g=Date.now()}}else if(i.type==="decision_end"){let d=l.pop();if(d&&d.id===i.decisionId){let p=Array.from(d.branches.values()),v={type:"decision",id:d.id,name:d.name,state:T(p.flatMap(x=>x.taken?x.children:[])),startTs:d.startTs,endTs:i.ts,durationMs:i.durationMs,condition:d.condition,decisionValue:d.decisionValue,branchTaken:i.branchTaken??d.branchTaken,branches:p};y(v)}}}function T(i){return i.length===0?"success":i.some(x=>x.state==="error")?"error":i.every(x=>x.state==="success"||x.state==="cached")?"success":i.some(x=>x.state==="running")?"running":"pending"}function k(){let i=[...m];for(let[,d]of c)i.push({type:"step",id:d.id,name:d.name,key:d.key,state:"running",startTs:d.startTs,...d.retryCount>0&&{retryCount:d.retryCount},...d.timedOut&&{timedOut:!0,timeoutMs:d.timeoutMs}});return i}function R(){let i=k();return n&&(i=z(i,t)),{root:{type:"workflow",id:r??Q(),workflowId:r??"unknown",state:o,startTs:s,durationMs:f,children:i,error:u},metadata:{createdAt:b,lastUpdatedAt:g}}}function B(){r=void 0,s=void 0,o="pending",u=void 0,f=void 0,c.clear(),a.length=0,l.length=0,m=[],b=Date.now(),g=b}return{handleEvent:S,handleScopeEvent:D,handleDecisionEvent:I,getIR:R,reset:B,get hasActiveSteps(){return c.size>0},get state(){return o}}}function O(e){return e.type==="step"}function $e(e){return e.type==="sequence"}function P(e){return e.type==="parallel"}function V(e){return e.type==="race"}function A(e){return e.type==="decision"}function Se(e){return"children"in e||e.type==="decision"&&"branches"in e}var ee="\x1B[0m",ve="\x1B[1m",ie="\x1B[2m",Ee="\x1B[31m",De="\x1B[32m",xe="\x1B[33m",Ne="\x1B[34m",oe="\x1B[90m",Ie="\x1B[37m";function q(e,n){return n?`${n}${e}${ee}`:e}function G(e){return`${ve}${e}${ee}`}function E(e){return`${ie}${e}${ee}`}var M={pending:Ie,running:xe,success:De,error:Ee,aborted:oe,cached:Ne,skipped:ie+oe};function Te(e){switch(e){case"pending":return"\u25CB";case"running":return"\u27F3";case"success":return"\u2713";case"error":return"\u2717";case"aborted":return"\u2298";case"cached":return"\u21BA";case"skipped":return"\u2298"}}function U(e,n){let t=Te(e);return q(t,n[e])}function te(e,n,t){return q(e,t[n])}function se(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var h={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"};function ae(e,n){let t=se(e).length,r=Math.max(0,n-t);return e+" ".repeat(r)}function Re(e,n){if(!n)return h.horizontal.repeat(e);let t=` ${n} `,r=e-t.length;if(r<4)return h.horizontal.repeat(e);let s=2,o=r-s;return h.horizontal.repeat(s)+t+h.horizontal.repeat(o)}function W(){return{name:"ascii",supportsLive:!0,render(e,n){let t={...M,...n.colors},r=n.terminalWidth??60,s=r-4,o=[],u=e.root.name??"workflow",f=G(u);o.push(`${h.topLeft}${Re(r-2,f)}${h.topRight}`),o.push(`${h.vertical}${" ".repeat(r-2)}${h.vertical}`);let c=J(e.root.children,n,t,0);for(let a of c)o.push(`${h.vertical} ${ae(a,s)}${h.vertical}`);if(o.push(`${h.vertical}${" ".repeat(r-2)}${h.vertical}`),e.root.durationMs!==void 0&&n.showTimings){let a=e.root.state==="success"?"Completed":"Failed",m=`${te(a,e.root.state,t)} in ${C(e.root.durationMs)}`;o.push(`${h.vertical} ${ae(m,s)}${h.vertical}`),o.push(`${h.vertical}${" ".repeat(r-2)}${h.vertical}`)}return o.push(`${h.bottomLeft}${h.horizontal.repeat(r-2)}${h.bottomRight}`),o.join(`
|
|
2
|
+
`)}}}function J(e,n,t,r){let s=[];for(let o of e)O(o)?s.push(ne(o,n,t)):P(o)?s.push(...Oe(o,n,t,r)):V(o)?s.push(...Me(o,n,t,r)):A(o)&&s.push(...Ce(o,n,t,r));return s}function ne(e,n,t){let r=U(e.state,t),s=e.name??e.key??"step",o=te(s,e.state,t),u=`${r} ${o}`;if(n.showKeys&&e.key&&(u+=E(` [key: ${e.key}]`)),e.input!==void 0){let f=typeof e.input=="string"?e.input:JSON.stringify(e.input).slice(0,30);u+=E(` [in: ${f}${f.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let f=typeof e.output=="string"?e.output:JSON.stringify(e.output).slice(0,30);u+=E(` [out: ${f}${f.length>=30?"...":""}]`)}if(n.showTimings&&e.durationMs!==void 0&&(u+=E(` [${C(e.durationMs)}]`)),e.retryCount!==void 0&&e.retryCount>0&&(u+=E(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let f=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";u+=E(` [timeout${f}]`)}return u}function Oe(e,n,t,r){let s=[],o=" ".repeat(r),u=U(e.state,t),f=e.name??"parallel",c=e.mode==="allSettled"?" (allSettled)":"";s.push(`${o}${h.teeRight}${h.teeDown}${h.horizontal} ${u} ${G(f)}${c}`);for(let a=0;a<e.children.length;a++){let l=e.children[a],b=a===e.children.length-1?`${o}${h.vertical} ${h.bottomLeft}`:`${o}${h.vertical} ${h.teeRight}`;if(O(l))s.push(`${b} ${ne(l,n,t)}`);else{let g=J([l],n,t,r+1);for(let w of g)s.push(`${o}${h.vertical} ${w}`)}}return n.showTimings&&e.durationMs!==void 0&&s.push(`${o}${h.bottomLeft}${h.horizontal}${h.horizontal} ${E(`[${C(e.durationMs)}]`)}`),s}function Me(e,n,t,r){let s=[],o=" ".repeat(r),u=U(e.state,t),f=e.name??"race";s.push(`${o}${h.teeRight}\u26A1 ${u} ${G(f)}`);for(let c=0;c<e.children.length;c++){let a=e.children[c],m=c===e.children.length-1?`${o}${h.vertical} ${h.bottomLeft}`:`${o}${h.vertical} ${h.teeRight}`,g=e.winnerId&&a.id===e.winnerId?E(" (winner)"):"";if(O(a))s.push(`${m} ${ne(a,n,t)}${g}`);else{let w=J([a],n,t,r+1);for(let y of w)s.push(`${o}${h.vertical} ${y}`)}}return n.showTimings&&e.durationMs!==void 0&&s.push(`${o}${h.bottomLeft}${h.horizontal}${h.horizontal} ${E(`[${C(e.durationMs)}]`)}`),s}function Ce(e,n,t,r){let s=[],o=" ".repeat(r),u=U(e.state,t),f=e.name??"decision",c=e.condition?E(` (${e.condition})`):"",a=e.decisionValue!==void 0?E(` = ${String(e.decisionValue)}`):"",l=e.branchTaken!==void 0?E(` \u2192 ${String(e.branchTaken)}`):"";s.push(`${o}${h.teeRight}${h.teeDown}${h.horizontal} ${u} ${G(f)}${c}${a}${l}`);for(let m=0;m<e.branches.length;m++){let b=e.branches[m],w=m===e.branches.length-1?`${o}${h.vertical} ${h.bottomLeft}`:`${o}${h.vertical} ${h.teeRight}`,y=b.taken?"\u2713":"\u2298",S=b.taken?t.success:t.skipped,D=q(`${y} ${b.label}`,S),I=b.condition?E(` (${b.condition})`):"";if(s.push(`${w} ${D}${I}`),b.children.length>0){let T=J(b.children,n,t,r+1);for(let k of T)s.push(`${o}${h.vertical} ${k}`)}else b.taken||s.push(`${o}${h.vertical} ${E("(skipped)")}`)}return n.showTimings&&e.durationMs!==void 0&&s.push(`${o}${h.bottomLeft}${h.horizontal}${h.horizontal} ${E(`[${C(e.durationMs)}]`)}`),s}function _e(){return[" classDef pending fill:#e5e7eb,stroke:#9ca3af,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,color:#4b5563"," classDef cached fill:#dbeafe,stroke:#3b82f6,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,color:#6b7280"]}var ce=0;function K(e="node"){return`${e}_${++ce}`}function We(){ce=0}function N(e){return e.replace(/[{}[\]()]/g,"").replace(/[<>]/g,"").replace(/"/g,"'").trim()}function de(e){return N(e).replace(/[[\]]/g,"")}function j(){return{name:"mermaid",supportsLive:!1,render(e,n){We();let t=[];t.push("flowchart TD");let r="start";t.push(` ${r}((Start))`);let s=r;for(let o of e.root.children){let u=Z(o,n,t);t.push(` ${s} --> ${u.entryId}`),s=u.exitId}if(e.root.state==="success"||e.root.state==="error"){let o="finish",u=e.root.state==="success"?"((Done))":"((Failed))",f=e.root.state==="success"?":::success":":::error";t.push(` ${o}${u}${f}`),t.push(` ${s} --> ${o}`)}return t.push(""),t.push(..._e()),t.join(`
|
|
3
|
+
`)}}}function Z(e,n,t){if(O(e))return Be(e,n,t);if(P(e))return Le(e,n,t);if(V(e))return Fe(e,n,t);if(A(e))return ze(e,n,t);let r=K("unknown");return t.push(` ${r}[Unknown Node]`),{entryId:r,exitId:r}}function Be(e,n,t){let r=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:K("step"),s=N(e.name??e.key??"Step"),o=n.showTimings&&e.durationMs!==void 0?` ${C(e.durationMs)}`:"",u="";if(e.input!==void 0){let m=typeof e.input=="string"?N(e.input):N(JSON.stringify(e.input).slice(0,20));u+=`\\nin: ${m}`}if(e.output!==void 0&&e.state==="success"){let m=typeof e.output=="string"?N(e.output):N(JSON.stringify(e.output).slice(0,20));u+=`\\nout: ${m}`}let f="";if(e.retryCount!==void 0&&e.retryCount>0&&(f+=`\\n\u21BB${e.retryCount}`),e.timedOut){let m=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";f+=`\\n\u23F1${m}`}let c=(s+u+f+o).trim(),a=e.state,l;switch(e.state){case"error":l=`{{${c}}}`;break;case"cached":l=`[(${c})]`;break;case"skipped":l=`[${c}]:::skipped`;break;default:l=`[${c}]`}return t.push(` ${r}${l}:::${a}`),{entryId:r,exitId:r}}function Le(e,n,t){let r=K("parallel"),s=`${r}_fork`,o=`${r}_join`,u=de(e.name??"Parallel");t.push(` subgraph ${r}[${u}]`),t.push(" direction TB"),t.push(` ${s}{Fork}`);let f=[];for(let a of e.children){let l=Z(a,n,t);t.push(` ${s} --> ${l.entryId}`),f.push(l.exitId)}t.push(` ${o}{Join}`);for(let a of f)t.push(` ${a} --> ${o}`);t.push(" end");let c=e.state;return t.push(` class ${r} ${c}`),{entryId:s,exitId:o}}function Fe(e,n,t){let r=K("race"),s=`${r}_start`,o=`${r}_end`,u=de(e.name??"Race");t.push(` subgraph ${r}["\u26A1 ${u}"]`),t.push(" direction TB"),t.push(` ${s}((Race))`);let f=[];for(let a of e.children){let l=Z(a,n,t);t.push(` ${s} --> ${l.entryId}`),f.push(l.exitId),O(a)&&e.winnerId===a.id&&t.push(` ${l.exitId} -. winner .-> ${o}`)}t.push(` ${o}((First))`);for(let a of f)(!e.winnerId||!e.children.some(l=>O(l)&&l.id===e.winnerId))&&t.push(` ${a} --> ${o}`);t.push(" end");let c=e.state;return t.push(` class ${r} ${c}`),{entryId:s,exitId:o}}function ze(e,n,t){let r=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:K("decision"),s=N(e.condition??"condition"),o=e.decisionValue!==void 0?` = ${N(String(e.decisionValue)).slice(0,30)}`:"",u=`${s}${o}`.trim();t.push(` ${r}{${u}}`);let f=[],c;for(let a of e.branches){let l=`${r}_${a.label.replace(/[^a-zA-Z0-9]/g,"_")}`,m=N(a.label),b=a.taken?`${m} \u2713`:`${m} skipped`,g=a.taken?":::success":":::skipped";t.push(` ${l}[${b}]${g}`);let w=a.condition?`|${N(a.condition).replace(/\|/g,"")}|`:"";if(t.push(` ${r} -->${w} ${l}`),a.children.length>0){let y=l;for(let S of a.children){let D=Z(S,n,t);t.push(` ${y} --> ${D.entryId}`),y=D.exitId}f.push(y),a.taken&&(c=y)}else f.push(l),a.taken&&(c=l)}return c?{entryId:r,exitId:c}:{entryId:r,exitId:r}}var _={clearToEnd:"\x1B[J",cursorUp:e=>`\x1B[${e}A`,cursorToStart:"\x1B[G",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",saveCursor:"\x1B[s",restoreCursor:"\x1B[u"};function le(e={}){let{workflowName:n,detectParallel:t=!0,showTimings:r=!0,showKeys:s=!1,colors:o,stream:u=process.stdout,updateInterval:f=100}=e,c=F({detectParallel:t}),a=W(),l={showTimings:r,showKeys:s,terminalWidth:u.columns??80,colors:{...M,...o}},m=!1,b="",g=0,w=null,y=!1;function S($){u.writable&&u.write($)}function D(){if(!m)return;let $=B(),L=a.render($,l);L!==b&&(g>0&&(S(_.cursorUp(g)),S(_.cursorToStart),S(_.clearToEnd)),S(L),S(`
|
|
4
|
+
`),b=L,g=L.split(`
|
|
5
|
+
`).length)}function I(){m&&(y=!0,w===null&&(w=setTimeout(()=>{w=null,y&&(y=!1,D())},f)))}function T($){if($.type==="scope_start"||$.type==="scope_end"){k($);return}c.handleEvent($),m&&($.type==="workflow_start"||$.type==="workflow_success"||$.type==="workflow_error"?D():I())}function k($){c.handleScopeEvent($),m&&I()}function R($){c.handleDecisionEvent($),m&&I()}function B(){let $=c.getIR();return n&&!$.root.name&&($.root.name=n),$}function i(){return a.render(B(),l)}function d(){m||(m=!0,b="",g=0,S(_.hideCursor),D())}function p(){if(!m)return;m=!1,w!==null&&(clearTimeout(w),w=null);let $=B(),L=a.render($,l);g>0&&(S(_.cursorUp(g)),S(_.cursorToStart),S(_.clearToEnd)),S(L),S(`
|
|
6
|
+
`),S(_.showCursor)}function v(){w!==null&&(clearTimeout(w),w=null),y=!1,D()}function x(){c.reset(),b="",g=0}return{handleEvent:T,handleScopeEvent:k,handleDecisionEvent:R,getIR:B,render:i,start:d,stop:p,refresh:v,reset:x}}function Y(e,n={}){let{condition:t,value:r,name:s,workflowId:o=crypto.randomUUID(),emit:u}=n,f=Date.now(),c,a=[];function l(b,g,w){a.push({label:b,condition:w,taken:g}),g&&(c=b),u?.({type:"decision_branch",workflowId:o,decisionId:e,branchLabel:b,condition:w,taken:g,ts:Date.now()})}function m(){let b=Date.now()-f;u?.({type:"decision_end",workflowId:o,decisionId:e,branchTaken:c,ts:Date.now(),durationMs:b})}return u?.({type:"decision_start",workflowId:o,decisionId:e,condition:t,decisionValue:r,name:s,ts:f}),{takeBranch:l,end:m,getBranchTaken:()=>c,getBranches:()=>[...a]}}function ue(e,n,t={}){let r=Y(e,{...t,condition:t.condition??String(n),value:t.value??n});return{...r,condition:n,then:()=>{r.takeBranch("if",!0)},else:()=>{r.takeBranch("else",!0)}}}function pe(e,n,t={}){let r=Y(e,{...t,condition:t.condition??`switch(${String(n)})`,value:n});return{...r,value:n,case:(s,o)=>{r.takeBranch(`case '${s}'`,o,`value === '${s}'`)},default:s=>{r.takeBranch("default",s)}}}function H(e={}){let{workflowName:n,detectParallel:t=!0,showTimings:r=!0,showKeys:s=!1,colors:o}=e,u=F({detectParallel:t}),f=new Set,c=W(),a=j(),l={showTimings:r,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...M,...o}};function m(){if(f.size>0){let k=u.getIR();for(let R of f)R(k)}}function b(k){if(k.type==="scope_start"||k.type==="scope_end"){g(k);return}u.handleEvent(k),k.type,m()}function g(k){u.handleScopeEvent(k),m()}function w(k){u.handleDecisionEvent(k),m()}function y(){let k=u.getIR();return n&&!k.root.name&&(k.root.name=n),k}function S(){let k=y();return c.render(k,l)}function D(k){let R=y();switch(k){case"ascii":return c.render(R,l);case"mermaid":return a.render(R,l);case"json":return JSON.stringify(R,null,2);default:throw new Error(`Unknown format: ${k}`)}}function I(){u.reset(),m()}function T(k){return f.add(k),()=>f.delete(k)}return{handleEvent:b,handleScopeEvent:g,handleDecisionEvent:w,getIR:y,render:S,renderAs:D,reset:I,onUpdate:T}}function Pe(e,n={}){let t=H(n);for(let r of e)r.type.startsWith("decision_")?t.handleDecisionEvent(r):t.handleEvent(r);return t.render()}function Ve(e={}){let n=[];return{handleEvent:t=>{n.push(t)},handleDecisionEvent:t=>{n.push(t)},getEvents:()=>[...n],getWorkflowEvents:()=>n.filter(t=>!t.type.startsWith("decision_")),getDecisionEvents:()=>n.filter(t=>t.type.startsWith("decision_")),clear:()=>{n.length=0},visualize:()=>{let t=H(e);for(let r of n)r.type.startsWith("decision_")?t.handleDecisionEvent(r):t.handleEvent(r);return t.render()},visualizeAs:t=>{let r=H(e);for(let s of n)s.type.startsWith("decision_")?r.handleDecisionEvent(s):r.handleEvent(s);return r.renderAs(t)}}}0&&(module.exports={asciiRenderer,createEventCollector,createIRBuilder,createLiveVisualizer,createParallelDetector,createVisualizer,defaultColorScheme,detectParallelGroups,hasChildren,isDecisionNode,isParallelNode,isRaceNode,isSequenceNode,isStepNode,mermaidRenderer,trackDecision,trackIf,trackSwitch,visualizeEvents});
|
|
7
7
|
//# sourceMappingURL=visualize.cjs.map
|