awaitly-visualizer 23.0.1 → 25.0.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/dist/devtools.cjs +6 -6
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.d.cts +3 -4
- package/dist/devtools.d.ts +3 -4
- package/dist/devtools.js +4 -4
- package/dist/devtools.js.map +1 -1
- package/dist/index.browser.cjs +14 -14
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +4 -5
- package/dist/index.browser.d.ts +4 -5
- package/dist/index.browser.js +14 -14
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +24 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -6
- package/dist/index.d.ts +25 -6
- package/dist/index.js +24 -24
- package/dist/index.js.map +1 -1
- package/dist/kroki/fetch.cjs +2 -2
- package/dist/kroki/fetch.cjs.map +1 -1
- package/dist/kroki/fetch.d.cts +1 -2
- package/dist/kroki/fetch.d.ts +1 -2
- package/dist/kroki/fetch.js +2 -2
- package/dist/kroki/fetch.js.map +1 -1
- package/dist/notifiers/discord.cjs +2 -2
- package/dist/notifiers/discord.cjs.map +1 -1
- package/dist/notifiers/discord.d.cts +2 -3
- package/dist/notifiers/discord.d.ts +2 -3
- package/dist/notifiers/discord.js +2 -2
- package/dist/notifiers/discord.js.map +1 -1
- package/dist/notifiers/slack.cjs +24 -24
- package/dist/notifiers/slack.cjs.map +1 -1
- package/dist/notifiers/slack.d.cts +2 -3
- package/dist/notifiers/slack.d.ts +2 -3
- package/dist/notifiers/slack.js +24 -24
- package/dist/notifiers/slack.js.map +1 -1
- package/dist/notifiers/webhook.cjs +2 -2
- package/dist/notifiers/webhook.cjs.map +1 -1
- package/dist/notifiers/webhook.d.cts +2 -3
- package/dist/notifiers/webhook.d.ts +2 -3
- package/dist/notifiers/webhook.js +2 -2
- package/dist/notifiers/webhook.js.map +1 -1
- package/dist/{performance-analyzer-ffmMicjZ.d.ts → performance-analyzer-BCzSirud.d.ts} +1 -1
- package/dist/{performance-analyzer-C9WFkUSa.d.cts → performance-analyzer-dTsqap8v.d.cts} +1 -1
- package/dist/{types-BmktN16n.d.cts → types-Cxa5QZ0j.d.cts} +1 -1
- package/dist/{types-Bmb5LpD-.d.ts → types-J_mgQ3lz.d.ts} +1 -1
- package/dist/{url-CxqaR2K3.d.cts → url-DD8-D8H4.d.cts} +4 -4
- package/dist/{url-CxqaR2K3.d.ts → url-DD8-D8H4.d.ts} +4 -4
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var Zt=Object.create;var Me=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var er=Object.getOwnPropertyNames;var tr=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty;var nr=(e,t)=>{for(var r in t)Me(e,r,{get:t[r],enumerable:!0})},it=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of er(t))!rr.call(e,a)&&a!==r&&Me(e,a,{get:()=>t[a],enumerable:!(o=Qt(t,a))||o.enumerable});return e};var or=(e,t,r)=>(r=e!=null?Zt(tr(e)):{},it(t||!e||!e.__esModule?Me(r,"default",{value:e,enumerable:!0}):r,e)),ar=e=>it(Me({},"__esModule",{value:!0}),e);var Rn={};nr(Rn,{asciiRenderer:()=>ae,buildMermaidInkUrl:()=>Ee,combineEventHandlers:()=>kn,createEventCollector:()=>Sn,createIRBuilder:()=>de,createLiveVisualizer:()=>Kt,createMermaidInkGenerator:()=>Ct,createParallelDetector:()=>st,createPerformanceAnalyzer:()=>ft,createTimeTravelController:()=>Gt,createUrlGenerator:()=>Et,createVisualizer:()=>Ke,defaultColorScheme:()=>z,detectParallelGroups:()=>xe,encodeForMermaidInk:()=>et,escapeHtml:()=>ve,flowchartRenderer:()=>me,generateInteractiveHTML:()=>Yt,getHeatLevel:()=>ge,hasChildren:()=>dr,htmlRenderer:()=>Ut,isDecisionNode:()=>J,isParallelNode:()=>G,isRaceNode:()=>U,isSequenceNode:()=>je,isStepNode:()=>j,isStreamNode:()=>re,loggerRenderer:()=>Ie,mermaidRenderer:()=>ie,renderToHTML:()=>zt,toExportUrl:()=>we,toKrokiPngUrl:()=>It,toKrokiSvgUrl:()=>Rt,toKrokiUrl:()=>ce,toMermaidInkJpegUrl:()=>Nt,toMermaidInkPdfUrl:()=>Ot,toMermaidInkPngUrl:()=>Tt,toMermaidInkSvgUrl:()=>Mt,toMermaidInkUrl:()=>Y,toMermaidInkWebpUrl:()=>Dt,trackDecision:()=>ze,trackIf:()=>jt,trackSwitch:()=>Vt,visualizeEvents:()=>xn});module.exports=ar(Rn);function H(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let t=Math.floor(e/6e4),r=Math.round(e%6e4/1e3);return r>=60&&(t+=1,r=0),r===0?`${t}m`:`${t}m ${r}s`}function Te(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function ir(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function xe(e,t={}){if(ir(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,a=[],n=[];for(let s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?a.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(a.length<=1)return e;a.sort((s,l)=>s.startTs-l.startTs);let i=[],d=[a[0]];for(let s=1;s<a.length;s++){let l=a[s],p=Math.min(...d.map(M=>M.startTs)),g=Math.max(...d.map(M=>M.endTs)),f=l.startTs<=p+o,w=l.startTs<g;if(!f&&!w){i.push(d),d=[l];continue}let k=w?Math.min(l.endTs,g)-l.startTs:0;f||k>=r?d.push(l):(i.push(d),d=[l])}i.push(d);let u=[];for(let s of i){let l=Math.min(...s.map(p=>p.originalIndex));if(s.length===1)u.push({node:s[0].node,position:l});else{let p=s.map(k=>k.node),g=Math.min(...s.map(k=>k.startTs)),f=Math.max(...s.map(k=>k.endTs)),w={type:"parallel",id:`detected_parallel_${g}`,name:`${p.length} parallel steps`,state:sr(p),mode:"all",children:p,startTs:g,endTs:f,durationMs:f-g};u.push({node:w,position:l})}}for(let{node:s,originalIndex:l}of n)u.push({node:s,position:l});return u.sort((s,l)=>s.position-l.position),u.map(s=>s.node)}function sr(e){return e.some(n=>n.state==="error")?"error":e.some(n=>n.state==="running")?"running":e.some(n=>n.state==="pending")?"pending":(e.every(n=>n.state==="success"||n.state==="cached"),"success")}function st(e={}){return{detect:t=>xe(t,e)}}function de(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:a=1e3}=e,n=o,i=Te(),d,u,s,l="pending",p,g,f=new Map,w=[],k=[],M=new Map,$=[],T=Date.now(),R=T,S={onAfterStep:new Map},x,h=[],y=0;function E(c){return c.stepId??c.stepKey??c.name??Te()}function C(c){if(w.length>0){w[w.length-1].children.push(c),R=Date.now();return}if(k.length>0){let b=k[k.length-1];for(let m of b.branches.values())if(m.taken){m.children.push(c),R=Date.now();return}b.pendingChildren.push(c),R=Date.now();return}$.push(c),R=Date.now()}function N(c){if(!n)return;let b=q(),m=new Map;for(let[W,X]of f)m.set(W,{id:X.id,name:X.name,key:X.key,startTs:X.startTs,retryCount:X.retryCount,timedOut:X.timedOut,timeoutMs:X.timeoutMs});let F={id:`snapshot_${y}`,eventIndex:y,event:structuredClone(c),ir:structuredClone(b),timestamp:Date.now(),activeSteps:m};h.push(F),h.length>a&&h.shift(),y++}function L(c){switch(c.type){case"workflow_start":{$=[],s=void 0,g=void 0,p=void 0,f.clear(),w.length=0,k.length=0,M.clear(),d=c.workflowId,u=c.ts,l="running",T=Date.now(),R=T,x!==void 0&&x!==c.workflowId&&(S.shouldRun=void 0,S.onBeforeStart=void 0),x=c.workflowId,S.onAfterStep=new Map;break}case"workflow_success":l="success",s=c.ts,g=c.durationMs,R=Date.now();break;case"workflow_error":l="error",s=c.ts,p=c.error,g=c.durationMs,R=Date.now();break;case"workflow_cancelled":l="aborted",s=c.ts,g=c.durationMs,R=Date.now();break;case"step_start":{let b=E(c);f.set(b,{id:b,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),R=Date.now();break}case"step_success":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"success",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),f.delete(b)}break}case"step_error":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"error",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};C(F),f.delete(b)}break}case"step_aborted":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"aborted",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),f.delete(b)}break}case"step_cache_hit":{let m={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};C(m);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let b=E(c),m=f.get(b);m&&(m.timedOut=!0,m.timeoutMs=c.timeoutMs),R=Date.now();break}case"step_retry":{let b=E(c),m=f.get(b);m&&(m.retryCount=(c.attempt??1)-1),R=Date.now();break}case"step_retries_exhausted":R=Date.now();break;case"step_skipped":{let m={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};C(m);break}case"hook_should_run":{let b={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.shouldRun=b,x=c.workflowId,R=Date.now();break}case"hook_should_run_error":{let b={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.shouldRun=b,x=c.workflowId,R=Date.now();break}case"hook_before_start":{let b={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.onBeforeStart=b,x=c.workflowId,R=Date.now();break}case"hook_before_start_error":{let b={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.onBeforeStart=b,x=c.workflowId,R=Date.now();break}case"hook_after_step":{let b={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),R=Date.now();break}case"hook_after_step_error":{let b={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),R=Date.now();break}case"stream_created":{let b=`${c.workflowId}:${c.namespace}`;M.set(b,{id:Te(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),R=Date.now();break}case"stream_write":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&(m.writeCount++,m.finalPosition=Math.max(m.finalPosition,c.position)),R=Date.now();break}case"stream_read":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&m.readCount++,R=Date.now();break}case"stream_close":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);if(m){m.streamState="closed",m.finalPosition=c.finalPosition;let F={type:"stream",id:m.id,namespace:m.namespace,state:"success",startTs:m.startTs,endTs:c.ts,durationMs:c.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(b)}R=Date.now();break}case"stream_error":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);if(m){m.streamState="error";let F={type:"stream",id:m.id,namespace:m.namespace,state:"error",error:c.error,startTs:m.startTs,endTs:c.ts,durationMs:c.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(b)}R=Date.now();break}case"stream_backpressure":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&(m.backpressureOccurred=!0),R=Date.now();break}}N(c)}function P(c){if(c.type==="scope_start")w.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),R=Date.now();else if(c.type==="scope_end"){let b=w.findIndex(W=>W.id===c.scopeId);if(b===-1)return;for(;w.length>b+1;){let W=w.pop(),X=W.type==="race"?{type:"race",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children}:{type:"parallel",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children,mode:W.type==="allSettled"?"allSettled":"all"};w[w.length-1].children.push(X)}let[m]=w.splice(b,1),F=m.type==="race"?{type:"race",id:m.id,name:m.name,state:v(m.children),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,children:m.children,winnerId:c.winnerId}:{type:"parallel",id:m.id,name:m.name,state:v(m.children),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,children:m.children,mode:m.type==="allSettled"?"allSettled":"all"};C(F)}}function O(c){if(c.type==="decision_start")k.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),R=Date.now();else if(c.type==="decision_branch"){let b=k.find(m=>m.id===c.decisionId);if(b){let m=c.branchLabel,F=b.branches.get(m);if(F)F.taken=c.taken,c.taken&&b.pendingChildren.length>0&&(F.children.unshift(...b.pendingChildren),b.pendingChildren=[]);else{let W=c.taken?[...b.pendingChildren]:[];c.taken&&(b.pendingChildren=[]),b.branches.set(m,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:W})}R=Date.now()}}else if(c.type==="decision_end"){let b=k.findIndex(m=>m.id===c.decisionId);if(b!==-1){let[m]=k.splice(b,1),F=k.splice(b),W=Array.from(m.branches.values());W.length===0&&m.pendingChildren.length>0&&(W=[{label:"default",taken:!0,children:[...m.pendingChildren]}]);let X=W.find($e=>$e.taken)?.label,Xt={type:"decision",id:m.id,name:m.name,state:v(W.flatMap($e=>$e.taken?$e.children:[])),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,condition:m.condition,decisionValue:m.decisionValue,branchTaken:c.branchTaken??X,branches:W};C(Xt),k.push(...F),R=Date.now()}}}function v(c){return c.length===0?"success":c.some(W=>W.state==="error")?"error":c.every(W=>W.state==="success"||W.state==="cached")?"success":c.some(W=>W.state==="running")?"running":"pending"}function D(){let c=[...$];for(let[,b]of f)c.push({type:"step",id:b.id,name:b.name,key:b.key,state:"running",startTs:b.startTs,...b.retryCount>0&&{retryCount:b.retryCount},...b.timedOut&&{timedOut:!0,timeoutMs:b.timeoutMs}});for(let[,b]of M)c.push({type:"stream",id:b.id,namespace:b.namespace,state:"running",startTs:b.startTs,writeCount:b.writeCount,readCount:b.readCount,finalPosition:b.finalPosition,streamState:b.streamState,backpressureOccurred:b.backpressureOccurred});return c}function q(){let c=D();t&&(c=xe(c,r));let b={type:"workflow",id:d??i,workflowId:d??i,state:l,startTs:u,endTs:s,durationMs:g,children:c,error:p},m=S.shouldRun!==void 0||S.onBeforeStart!==void 0||S.onAfterStep.size>0;return{root:b,metadata:{createdAt:T,lastUpdatedAt:R},...m&&{hooks:S}}}function oe(){d=void 0,u=void 0,s=void 0,l="pending",p=void 0,g=void 0,f.clear(),w.length=0,k.length=0,M.clear(),$=[],T=Date.now(),R=T,S={onAfterStep:new Map},x=void 0,h.length=0,y=0}function at(){return[...h]}function ke(c){return h[c]}function Jt(c){return h[c]?.ir}function qt(){h.length=0,y=0}return{handleEvent:L,handleScopeEvent:P,handleDecisionEvent:O,getIR:q,reset:oe,getSnapshots:at,getSnapshotAt:ke,getIRAt:Jt,clearSnapshots:qt,get hasActiveSteps(){return f.size>0},get state(){return l},get snapshotCount(){return h.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}var De=require("awaitly");function j(e){return e.type==="step"}function je(e){return e.type==="sequence"}function G(e){return e.type==="parallel"}function U(e){return e.type==="race"}function J(e){return e.type==="decision"}function re(e){return e.type==="stream"}function dr(e){return"children"in e||e.type==="decision"&&"branches"in e}var Ve="\x1B[0m",cr="\x1B[1m",ct="\x1B[2m",lr="\x1B[31m",ur="\x1B[32m",pr="\x1B[33m",mr="\x1B[34m",dt="\x1B[90m",fr="\x1B[37m";function Z(e,t){return t?`${t}${e}${Ve}`:e}function Se(e){return`${cr}${e}${Ve}`}function _(e){return`${ct}${e}${Ve}`}var z={pending:fr,running:pr,success:ur,error:lr,aborted:dt,cached:mr,skipped:ct+dt};function gr(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 Re(e,t){let r=gr(e);return Z(r,t[e])}function Ne(e,t,r){return Z(e,r[t])}function ne(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var I={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},fe={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},hr="\x1B[0m";function br(e){return e<.2?fe.cold:e<.4?fe.cool:e<.6?fe.neutral:e<.8?fe.warm:e<.95?fe.hot:fe.critical}function lt(e,t){let r=br(t);return r?`${r}${e}${hr}`:e}function wr(e){try{return(0,De.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return(0,De.err)("STRINGIFY_ERROR")}}function ut(e){let t=wr(e);return t.ok?t.value:"[unserializable]"}var pt="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function Ye(e,t=10){if(e.length===0)return"";let r=e.slice(-t),o=Math.min(...r),n=Math.max(...r)-o||1;return r.map(i=>{let d=(i-o)/n,u=Math.floor(d*(pt.length-1));return pt[u]}).join("")}function Ge(e,t){let r=ne(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function yr(e,t){if(!t)return I.horizontal.repeat(e);let r=` ${t} `,o=ne(r).length,a=e-o;if(a<4)return I.horizontal.repeat(e);let n=2,i=a-n;return I.horizontal.repeat(n)+r+I.horizontal.repeat(i)}function mt(e,t,r){let o=e.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),a=e.durationMs!==void 0?_(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=_(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=_(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?_(` error: ${String(e.error)}`):"";return`${o} ${_(t)}${n}${a}${i}`}function vr(e,t){let r=[];return e.shouldRun&&r.push(mt(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(mt(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(_("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ae(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...z,...t.colors},o=Math.max(t.terminalWidth??60,5),a=o-4,n=[],i=e.root.name??"workflow",d=Se(i);if(n.push(`${I.topLeft}${yr(o-2,d)}${I.topRight}`),n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`),e.hooks){let s=vr(e.hooks,r);for(let l of s)n.push(`${I.vertical} ${Ge(l,a)}${I.vertical}`)}let u=Oe(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${I.vertical} ${Ge(s,a)}${I.vertical}`);if(n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let s=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",p=`${Ne(s,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${I.vertical} ${Ge(p,a)}${I.vertical}`),n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`)}return n.push(`${I.bottomLeft}${I.horizontal.repeat(o-2)}${I.bottomRight}`),n.join(`
|
|
2
|
-
`)}}}function Oe(e,t,r,o,a){let n=[];for(let i of e)j(i)?n.push(Je(i,t,r,a)):G(i)?n.push(...xr(i,t,r,o,a)):U(i)?n.push(...Sr(i,t,r,o,a)):J(i)?n.push(...Rr(i,t,r,o,a)):re(i)&&n.push(kr(i,t,r));return n}function Je(e,t,r,o){let a=Re(e.state,r),n=e.name??e.key??"step",i=t,d=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,u;d!==void 0?u=lt(n,d):u=Ne(n,e.state,r);let s=`${a} ${u}`;if(t.showKeys&&e.key&&e.name&&(s+=_(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:ut(e.input).slice(0,30);s+=_(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:ut(e.output).slice(0,30);s+=_(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=H(e.durationMs),g=d!==void 0?lt(`[${p}]`,d):_(`[${p}]`);s+=` ${g}`}if(i.showSparklines&&i.timingHistory){let p=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);p&&p.length>1&&(s+=` ${_(Ye(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(s+=_(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";s+=_(` [timeout${p}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let p=o.onAfterStep.get(l),g=p.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),f=p.durationMs!==void 0?_(` ${H(p.durationMs)}`):"";s+=` ${g}${f}`}return s}function kr(e,t,r){let o=e.streamState==="active"?Z("\u27F3",r.running):e.streamState==="closed"?Z("\u2713",r.success):Z("\u2717",r.error),a=`stream:${e.namespace}`,n=Ne(a,e.state,r),i=_(`[W:${e.writeCount} R:${e.readCount}]`),d=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(d+=` ${_(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(d+=_(" [backpressure]")),e.streamState==="closed"&&(d+=_(` pos:${e.finalPosition}`)),d}function xr(e,t,r,o,a){let n=[],i=" ".repeat(o),d=Re(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${I.teeRight}${I.teeDown}${I.horizontal} ${d} ${Se(u)}${s}`),e.children.length===0)n.push(`${i}${I.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${I.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],f=l===e.children.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`;if(j(p))n.push(`${f} ${Je(p,t,r,a)}`);else{let w=Oe([p],t,r,o+1,a);for(let k of w)n.push(`${i}${I.vertical} ${k}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Sr(e,t,r,o,a){let n=[],i=" ".repeat(o),d=Re(e.state,r),u=e.name??"race";if(n.push(`${i}${I.teeRight}\u26A1 ${d} ${Se(u)}`),e.children.length===0)n.push(`${i}${I.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${I.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let s=0;s<e.children.length;s++){let l=e.children[s],g=s===e.children.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`,w=e.winnerId&&l.id===e.winnerId?_(" (winner)"):"";if(j(l))n.push(`${g} ${Je(l,t,r,a)}${w}`);else{let k=Oe([l],t,r,o+1,a);for(let M of k)n.push(`${i}${I.vertical} ${M}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Rr(e,t,r,o,a){let n=[],i=" ".repeat(o),d=Re(e.state,r),u=e.name??"decision",s=e.condition?_(` (${e.condition})`):"",l=e.decisionValue!==void 0?_(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?_(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${I.teeRight}${I.teeDown}${I.horizontal} ${d} ${Se(u)}${s}${l}${p}`);for(let g=0;g<e.branches.length;g++){let f=e.branches[g],k=g===e.branches.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`,M=f.taken?"\u2713":"\u2298",$=f.taken?r.success:r.skipped,T=Z(`${M} ${f.label}`,$),R=f.condition?_(` (${f.condition})`):"";if(n.push(`${k} ${T}${R}`),f.children.length>0){let S=Oe(f.children,t,r,o+1,a);for(let x of S)n.push(`${i}${I.vertical} ${x}`)}else f.taken||n.push(`${i}${I.vertical} ${_("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}var We=require("awaitly");function qe(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...qe(r.children)),"branches"in r)for(let o of r.branches)t.push(...qe(o.children));return t}function Ce(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function ge(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function ft(){let e=new Map,t=new Map,r=new Map,o=new Map,a=[];function n(S){return S.stepKey??S.stepId??S.name??"unknown"}function i(S){let x=new Map;for(let h of S)switch(h.type){case"step_start":{let y=n(h);x.set(y,{retried:!1,timedOut:!1});break}case"step_retry":{let y=n(h),E=x.get(y);E&&(E.retried=!0);break}case"step_timeout":{let y=n(h),E=x.get(y);E&&(E.timedOut=!0);break}case"step_success":{let y=n(h),E=x.get(y),C=e.get(y)??[];C.push(h.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,r.set(y,P),x.delete(y);break}case"step_error":{let y=n(h),E=x.get(y),C=e.get(y)??[];C.push(h.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,P.errors++,r.set(y,P),x.delete(y);break}}}function d(S){i(S.events)}function u(S){a.push(S)}function s(S){a.length>0&&(i(a),a=[])}function l(S){let x=e.get(S);if(!x||x.length===0)return;let h=[...x].sort((O,v)=>O-v),E=h.reduce((O,v)=>O+v,0)/h.length,C=h.reduce((O,v)=>O+(v-E)**2,0)/h.length,N=t.get(S)??{retried:0,total:1},L=r.get(S)??{errors:0,total:1},P=o.get(S)??{timedOut:0,total:1};return{nodeId:S,avgDurationMs:E,minDurationMs:h[0],maxDurationMs:h[h.length-1],stdDevMs:Math.sqrt(C),samples:h.length,retryRate:N.total>0?N.retried/N.total:0,timeoutRate:P.total>0?P.timedOut/P.total:0,errorRate:L.total>0?L.errors/L.total:0,percentiles:{p50:Ce(h,.5),p90:Ce(h,.9),p95:Ce(h,.95),p99:Ce(h,.99)}}}function p(S){return l(S)}function g(S,x="duration"){let h=new Map,y=qe(S.root.children),E=[];for(let v of y){let D=("key"in v?v.key:void 0)??v.id??v.name,q=l(D);if(q){let oe;switch(x){case"duration":oe=q.avgDurationMs;break;case"retryRate":oe=q.retryRate;break;case"errorRate":oe=q.errorRate;break}E.push({id:v.id,value:oe})}}if(E.length===0)return{heat:h,metric:x,stats:{min:0,max:0,mean:0,threshold:0}};let C=E.map(v=>v.value),N=Math.min(...C),L=Math.max(...C),P=C.reduce((v,D)=>v+D,0)/C.length,O=L-N||1;for(let{id:v,value:D}of E)h.set(v,(D-N)/O);return{heat:h,metric:x,stats:{min:N,max:L,mean:P,threshold:P+(L-P)*.5}}}function f(){let S=new Map;for(let x of e.keys()){let h=l(x);h&&S.set(x,h)}return S}function w(S=10){return[...f().values()].sort((h,y)=>y.avgDurationMs-h.avgDurationMs).slice(0,S)}function k(S=10){return[...f().values()].filter(h=>h.errorRate>0).sort((h,y)=>y.errorRate-h.errorRate).slice(0,S)}function M(S=10){return[...f().values()].filter(h=>h.retryRate>0).sort((h,y)=>y.retryRate-h.retryRate).slice(0,S)}function $(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function T(S){let x=JSON.parse(S);e.clear(),t.clear(),r.clear(),o.clear();for(let[h,y]of Object.entries(x.timingData??{}))e.set(h,y);for(let[h,y]of Object.entries(x.retryData??{}))t.set(h,y);for(let[h,y]of Object.entries(x.errorData??{}))r.set(h,y);for(let[h,y]of Object.entries(x.timeoutData??{}))o.set(h,y)}function R(){e.clear(),t.clear(),r.clear(),o.clear(),a=[]}return{addRun:d,addEvent:u,finalizeRun:s,getNodePerformance:p,getHeatmap:g,getSlowestNodes:w,getErrorProneNodes:k,getRetryProneNodes:M,getAllPerformance:f,exportData:$,importData:T,clear:R}}function Ir(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function Er(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function $r(e){return`heat_${e}`}function Mr(){return[" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e"," classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d"]}function Tr(e){try{return(0,We.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return(0,We.err)("STRINGIFY_ERROR")}}function gt(e){let t=Tr(e);return t.ok?t.value:"[unserializable]"}function Nr(e,t,r){let o;if(e.shouldRun){let a="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",i=e.shouldRun.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${a}[["${i} shouldRun${u}${d}"]]:::${n}`),o=a}if(e.onBeforeStart){let a="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${a}[["${i} onBeforeStart${u}${d}"]]:::${n}`),o&&t.push(` ${o} --> ${a}`),o=a}return{lastHookId:o}}var ht=0,Le=new Set,_e=new Set;function he(e="node"){return`${e}_${++ht}`}function Dr(){ht=0,Le.clear(),_e.clear()}function V(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function bt(e){return V(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){Dr();let r=[],o=t;r.push("flowchart TD");let a;e.hooks&&(a=Nr(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),a&&r.push(` ${a} --> ${n}`);let i=n;for(let u of e.root.children){let s=Be(u,t,r,o,e.hooks);r.push(` ${i} --> ${s.entryId}`),i=s.exitId}if(["success","error","aborted"].includes(e.root.state)){let u="finish",s=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",l=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",p=`(("${s} ${l}"))`,g=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${p}${g}`),r.push(` ${i} --> ${u}`)}return r.push(""),r.push(...Ir()),o.showHeatmap&&r.push(...Er()),e.hooks&&r.push(...Mr()),r.join(`
|
|
3
|
-
`)}}}function Be(e,t,r,o,a){if(j(e))return
|
|
4
|
-
`)}var Q=11,ee=2,be=2,Ae=3;function Ze(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],a="";for(let n of r)a?a.length+1+n.length<=t?a+=" "+n:(o.push(a),a=n):a=n;if(a&&o.push(a),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function kt(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function Ur(e,t,r){let o=t.showStartEnd??!0,a=t,n=Math.floor(r/2),i=[],d=0;if(o){let s=Pe("start","start",["\u25B6 Start"],"success",n,d);i.push(s),d=s.bottomY+be}for(let s of e.root.children){let l=He(s,n,d,r-4,t,a);i.push(l.node),d=l.bottomY+be}if(o&&["success","error","aborted"].includes(e.root.state)){let s=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",l=Pe("end","end",[s],e.root.state,n,d);i.push(l),d=l.bottomY}return{nodes:i,totalHeight:d+2}}function Pe(e,t,r,o,a,n){let i=Math.max(...r.map(l=>ne(l).length)),d=Math.max(Q,i+ee*2),u=r.length+2,s=a-Math.floor(d/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:d,height:u,centerX:a,bottomY:n+u-1}}function He(e,t,r,o,a,n){if(j(e))return zr(e,t,r,o,a,n);if(G(e)||U(e))return jr(e,t,r,o,a,n);if(J(e))return Vr(e,t,r,o,a,n);if(re(e))return Kr(e,t,r,o,a,n);let i=Pe(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function zr(e,t,r,o,a,n){let i=e.name??e.key??"step",d=kt(e.state),u=[],s=`${d} ${i}`;a.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-ee*2,40);if(u.push(...Ze(s,l)),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let $=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);$&&$.length>1&&u.push(Ye($,8))}let p=Math.max(...u.map($=>ne($).length)),g=Math.max(Q,p+ee*2),f=u.length+2,w=t-Math.floor(g/2),k;if(n?.showHeatmap&&n.heatmapData){let $=e.key??e.name??e.id;k=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get($)}let M={id:e.id,type:"step",label:u,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1,metadata:k!==void 0?{heat:k}:void 0};return{node:M,bottomY:M.bottomY}}function Kr(e,t,r,o,a,n){let i=`stream:${e.namespace}`,d=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${d} ${i}`,l=Math.min(o-ee*2,40);u.push(...Ze(s,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let p=Math.max(...u.map(M=>ne(M).length)),g=Math.max(Q,p+ee*2),f=u.length+2,w=t-Math.floor(g/2),k={id:e.id,type:"stream",label:u,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:k,bottomY:k.bottomY}}function jr(e,t,r,o,a,n){let i=U(e),d=e.name??(i?"race":"parallel"),s=`${i?"\u26A1":"\u2AD8"} ${d}`;if(e.children.length===0){let y=[s,"(not tracked)"],E=Pe(e.id,i?"race":"parallel",y,e.state,t,r);return{node:E,bottomY:E.bottomY}}let l=Math.floor((o-Ae*(e.children.length-1))/e.children.length),p=[];for(let y of e.children){let E=Xe(y,Math.max(l,Q),a,n);p.push(E.width)}let g=p.reduce((y,E)=>y+E,0)+Ae*(e.children.length-1),f=g>o&&e.children.length>1,w=Math.max(Q,s.length+ee*2),k=3,M=t-Math.floor(w/2),$=r;$+=k,$+=1,$+=1;let T=[];if(f)for(let y=0;y<e.children.length;y++){let E=e.children[y],C=He(E,t,$,o,a,n);i&&U(e)&&e.winnerId===E.id&&(C.node.metadata={...C.node.metadata,isWinner:!0}),T.push(C.node),$=C.bottomY+be}else{let y=t-Math.floor(g/2);for(let E=0;E<e.children.length;E++){let C=e.children[E],N=y+Math.floor(p[E]/2),L=He(C,N,$,p[E],a,n);i&&U(e)&&e.winnerId===C.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),T.push(L.node),y+=p[E]+Ae}}let R=Math.max(...T.map(y=>y.bottomY)),x=!f&&T.length>1?R+2:R;return{node:{id:e.id,type:i?"race":"parallel",label:[s],state:e.state,x:M,y:r,width:w,height:k,centerX:t,bottomY:x,children:T,metadata:{verticalLayout:f}},bottomY:x}}function Vr(e,t,r,o,a,n){let i=e.name??"decision",d=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${i}${d}`,s=Math.min(o-ee*2,40),l=Ze(u,s),p=Math.max(...l.map(x=>ne(x).length)),g=Math.max(Q,p+ee*2),f=l.length+2,w=t-Math.floor(g/2),k=e.branches.find(x=>x.taken),M=k&&k.children.length>0?k:e.branches.find(x=>x.children.length>0);if(!M||M.children.length===0){let x={id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1};return{node:x,bottomY:x.bottomY}}let $=r+f+be,T=[];for(let x of M.children){let h=He(x,t,$,o,a,n);T.push(h.node),$=h.bottomY+be}let R=T.length>0?T[T.length-1].bottomY:r+f-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:R,children:T},bottomY:R}}function Xe(e,t,r,o){if(j(e)){let a=e.name??e.key??"step",n=kt(e.state),i=1;r.showTimings&&e.durationMs!==void 0&&i++,e.retryCount&&e.retryCount>0&&i++,e.timedOut&&i++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&i++;let d=`${n} ${a}`;r.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let u=Math.min(t,Math.max(Q,d.length+ee*2)),s=i+2;return{width:u,height:s}}if(G(e)||U(e)){if(e.children.length===0)return{width:Q+4,height:4};let a=Math.floor(t/e.children.length),n=0,i=0;for(let d of e.children){let u=Xe(d,a,r,o);n+=u.width,i=Math.max(i,u.height)}return n+=Ae*(e.children.length-1),{width:Math.max(n,Q),height:5+i+2}}if(J(e)){let a=e.branches.find(i=>i.taken),n=0;if(a)for(let i of a.children){let d=Xe(i,t,r,o);n+=d.height+be}return{width:Math.min(t,30),height:3+n}}if(re(e)){let a=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(Q,a.length+ee*2+4)),d=n+2;return{width:i,height:d}}return{width:Q,height:3}}function Gr(e,t,r){let o={...z,...r.colors};for(let a=0;a<t.length;a++){let n=t[a],i=a===t.length-1;if(Fe(e,n,o),!i){let d=t[a+1],u=n.centerX,s=n.bottomY+1,l=d.centerX,p=d.y-1;se(e,u,s,p-1),pe(e,l,p)}}}function Fe(e,t,r){let o=t.type!=="start",a=t.type!=="end"&&(!t.children||t.children.length===0);Hr(e,t.x,t.y,t.width,t.height),o&&A(e,t.centerX,t.y,B.teeUp),(a||t.children&&t.children.length>0)&&A(e,t.centerX,t.y+t.height-1,B.teeDown);let n=t.width-ee*2,i=Xr(t,r);for(let d=0;d<t.label.length;d++){let u=t.label[d],s=t.x+1+Math.floor((n-ne(u).length)/2),l=t.y+1+d;wt(e,s,l,u,i)}t.metadata?.isWinner&&wt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?Yr(e,t,r):Jr(e,t,r))}function Yr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let d=o[0];se(e,n,a,d.y-2),pe(e,d.centerX,d.y-1);for(let u=0;u<o.length;u++){let s=o[u];if(Fe(e,s,r),u<o.length-1){let l=o[u+1];se(e,s.centerX,s.bottomY+1,l.y-2),pe(e,l.centerX,l.y-1)}}return}if(o.length===1)se(e,n,a,o[0].y-2),pe(e,o[0].centerX,o[0].y-1);else{let d=o.map(l=>l.centerX),u=Math.min(...d),s=Math.max(...d);se(e,n,a,a+1),yt(e,a+1,u,s),A(e,n,a+1,B.teeUp);for(let l of o){let p=l.centerX;p===u?A(e,p,a+1,B.topLeft):p===s?A(e,p,a+1,B.topRight):p!==n&&A(e,p,a+1,B.teeDown),se(e,p,a+2,l.y-2),pe(e,p,l.y-1)}}for(let d of o)Fe(e,d,r);if(o.length>1){let d=o.map(f=>f.bottomY),u=Math.max(...d),s=u+1,l=o.map(f=>f.centerX),p=Math.min(...l),g=Math.max(...l);for(let f of o)f.bottomY<u&&se(e,f.centerX,f.bottomY+1,s-1);yt(e,s,p,g);for(let f of o){let w=f.centerX;w===p?A(e,w,s,B.bottomLeft):w===g?A(e,w,s,B.bottomRight):A(e,w,s,B.teeUp)}A(e,t.centerX,s,B.teeDown),A(e,t.centerX,s+1,B.vertical)}}function Jr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=o[0];se(e,t.centerX,a,n.y-2),pe(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let d=o[i];if(Fe(e,d,r),i<o.length-1){let u=o[i+1];se(e,d.centerX,d.bottomY+1,u.y-2),pe(e,u.centerX,u.y-1)}}}var qr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function Xr(e,t){if(e.metadata?.heat!==void 0){let r=ge(e.metadata.heat);return Br[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?qr[e.metadata.streamState]||void 0:t[e.state]||void 0}function me(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:a}=Ur(e,t,r),n=Pr(r,a);return Gr(n,o,t),Fr(n)}}}function Zr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Qr(e){let t=[];function r(o){for(let a of o)if(j(a))t.push(a);else if(je(a))r(a.children);else if(G(a)||U(a))r(a.children);else if(J(a))for(let n of a.branches)n.taken&&r(n.children)}return r(e),t}function en(e){let t={id:e.id,name:e.name??e.key??e.id,state:e.state};return e.key&&(t.key=e.key),e.durationMs!==void 0&&(t.durationMs=e.durationMs),e.startTs!==void 0&&(t.startTs=e.startTs),e.endTs!==void 0&&(t.endTs=e.endTs),e.retryCount!==void 0&&e.retryCount>0&&(t.retryCount=e.retryCount),e.timedOut&&(t.timedOut=!0,e.timeoutMs!==void 0&&(t.timeoutMs=e.timeoutMs)),e.error!==void 0&&(t.error=typeof e.error=="string"?e.error:String(e.error)),e.metadata&&(e.metadata.domain&&(t.domain=e.metadata.domain),e.metadata.owner&&(t.owner=e.metadata.owner),e.metadata.intent&&(t.intent=e.metadata.intent),e.metadata.calls?.length&&(t.calls=e.metadata.calls)),e.errorDiagnostics&&(t.errorDiagnostics={tag:e.errorDiagnostics.tag,origin:e.errorDiagnostics.origin},e.errorDiagnostics.classification?.severity&&(t.errorDiagnostics.severity=e.errorDiagnostics.classification.severity),e.errorDiagnostics.classification?.retryable!==void 0&&(t.errorDiagnostics.retryable=e.errorDiagnostics.classification.retryable)),t}function tn(e){let t=0,r=0,o=0,a=0,n=0,i;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&a++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!i||s.durationMs>i.durationMs)&&(i={name:s.name??s.key??s.id,durationMs:s.durationMs});let d=new Map;for(let s of e){let l=s.metadata?.domain;if(l&&(s.state==="success"||s.state==="error")){let p=d.get(l)??{total:0,errors:0,totalDuration:0};p.total++,s.state==="error"&&p.errors++,s.durationMs!==void 0&&(p.totalDuration+=s.durationMs),d.set(l,p)}}let u;if(d.size>0){u={};for(let[s,l]of d)u[s]={total:l.total,errors:l.errors,avgDurationMs:l.total>0?Math.round(l.totalDuration/l.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:a,totalRetries:n,slowestStep:i,...u&&{byDomain:u}}}function rn(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let a={stepKey:r};o.durationMs!==void 0&&(a.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(a.error=String(o.error)),t.onAfterStep.push(a)}}return t}function nn(e,t){let r=e.root,o=Qr(r.children),a=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(en),summary:tn(o)};if(e.hooks){let d=rn(e.hooks);Object.keys(d).length>0&&(i.hooks=d)}if(a){let s=((t.diagramFormat??"ascii")==="flowchart"?me():ae()).render(e,t);n&&(s=Zr(s)),i.diagram=s}return i}function Ie(){return{name:"logger",supportsLive:!1,render(e,t){let o=nn(e,t);return JSON.stringify(o)}}}var te=require("awaitly");var xt=or(require("pako"),1),on=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function an(e){let t;if(on)t=globalThis.Buffer.from(e).toString("base64");else{let r="";for(let o=0;o<e.length;o++)r+=String.fromCharCode(e[o]);t=btoa(r)}return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ue(e){let r=new TextEncoder().encode(e),o=xt.default.deflate(r);return an(o)}var St="https://kroki.io";function Qe(e,t,r,o={}){let a=o.baseUrl??St,n=Ue(r);return`${a}/${e}/${t}/${n}`}function ce(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:z},n=o.render(e,a);return Qe("mermaid",t,n,r)}function Rt(e,t={}){return ce(e,"svg",t)}function It(e,t={}){return ce(e,"png",t)}function Et(e={}){let t=e.baseUrl??St;return{toUrl(r,o){return ce(r,o,{baseUrl:t})},toSvgUrl(r){return ce(r,"svg",{baseUrl:t})},toPngUrl(r){return ce(r,"png",{baseUrl:t})},toPdfUrl(r){return ce(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var $t="https://mermaid.ink";function et(e){return`pako:${Ue(e)}`}function sn(e){if("provider"in e){let t=e;return{theme:t.mermaidTheme,bgColor:t.background,scale:t.scale,fit:t.fit,width:t.width,height:t.height,paper:t.paper,imageType:"png"}}return e}function dn(e,t){let r=[];return t.bgColor&&r.push(`bgColor=${encodeURIComponent(t.bgColor)}`),t.theme&&r.push(`theme=${t.theme}`),t.width!==void 0&&r.push(`width=${t.width}`),t.height!==void 0&&r.push(`height=${t.height}`),t.scale!==void 0&&(t.width!==void 0||t.height!==void 0)&&r.push(`scale=${t.scale}`),e==="img"&&t.imageType&&t.imageType!=="jpeg"&&r.push(`type=${t.imageType}`),e==="pdf"&&(t.fit&&r.push("fit"),t.paper&&!t.fit&&r.push(`paper=${t.paper}`),t.landscape&&!t.fit&&r.push("landscape")),r.length>0?`?${r.join("&")}`:""}function Ee(e,t,r={}){let o=sn(r),a=o.baseUrl??$t,n=et(t),i=dn(e,o);return`${a}/${e}/${n}${i}`}function Y(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:z},n=o.render(e,a);return Ee(t,n,r)}function Mt(e,t={}){return Y(e,"svg",t)}function Tt(e,t={}){return Y(e,"img",{...t,imageType:"png"})}function Nt(e,t={}){return Y(e,"img",{...t,imageType:"jpeg"})}function Dt(e,t={}){return Y(e,"img",{...t,imageType:"webp"})}function Ot(e,t={}){return Y(e,"pdf",t)}function Ct(e={}){let t=e.baseUrl??$t;return{toUrl(r,o){return Y(r,o,e)},toSvgUrl(r){return Y(r,"svg",e)},toPngUrl(r){return Y(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return Y(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return Y(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return Y(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}function cn(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,te.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,te.err)("UNSUPPORTED_FORMAT"):(0,te.ok)(void 0):(0,te.err)("UNSUPPORTED_FORMAT")}function ln(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function un(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function we(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,te.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,te.err)("UNSUPPORTED_DIAGRAM_KIND")}}let a=cn(r.provider,e.kind,t);if(!a.ok)return a;switch(r.provider){case"kroki":return(0,te.ok)(Qe(ln(e.kind),t,e.source,r));case"mermaid-ink":return(0,te.ok)(Ee(un(t),e.source,r));default:{let n=r;return(0,te.err)("UNKNOWN_PROVIDER")}}}function Lt(e){let t={bg:"#ffffff",bgSecondary:"#f8f9fa",text:"#212529",textMuted:"#6c757d",border:"#dee2e6",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#e9ecef",nodeRunning:"#fff3cd",nodeSuccess:"#d1e7dd",nodeError:"#f8d7da",nodeAborted:"#e9ecef",nodeCached:"#cfe2ff",nodeSkipped:"#f8f9fa",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},r={bg:"#212529",bgSecondary:"#343a40",text:"#f8f9fa",textMuted:"#adb5bd",border:"#495057",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#495057",nodeRunning:"#664d03",nodeSuccess:"#0f5132",nodeError:"#842029",nodeAborted:"#495057",nodeCached:"#084298",nodeSkipped:"#343a40",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},o=n=>`
|
|
1
|
+
"use strict";var Qt=Object.create;var Me=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var tr=Object.getOwnPropertyNames;var rr=Object.getPrototypeOf,nr=Object.prototype.hasOwnProperty;var or=(e,t)=>{for(var r in t)Me(e,r,{get:t[r],enumerable:!0})},it=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of tr(t))!nr.call(e,a)&&a!==r&&Me(e,a,{get:()=>t[a],enumerable:!(o=er(t,a))||o.enumerable});return e};var ar=(e,t,r)=>(r=e!=null?Qt(rr(e)):{},it(t||!e||!e.__esModule?Me(r,"default",{value:e,enumerable:!0}):r,e)),ir=e=>it(Me({},"__esModule",{value:!0}),e);var Rn={};or(Rn,{asciiRenderer:()=>ae,buildMermaidInkUrl:()=>Ee,combineEventHandlers:()=>xn,createEventCollector:()=>In,createIRBuilder:()=>de,createLiveVisualizer:()=>Kt,createMermaidInkGenerator:()=>Ct,createParallelDetector:()=>st,createPerformanceAnalyzer:()=>ft,createTimeTravelController:()=>Yt,createUrlGenerator:()=>Et,createVisualizer:()=>Ke,defaultColorScheme:()=>z,detectParallelGroups:()=>xe,devEvents:()=>jt,encodeForMermaidInk:()=>et,escapeHtml:()=>ke,flowchartRenderer:()=>me,generateInteractiveHTML:()=>Jt,getHeatLevel:()=>he,hasChildren:()=>cr,htmlRenderer:()=>Ut,isDecisionNode:()=>J,isParallelNode:()=>G,isRaceNode:()=>U,isSequenceNode:()=>je,isStepNode:()=>j,isStreamNode:()=>re,loggerRenderer:()=>Re,mermaidRenderer:()=>ie,renderToHTML:()=>zt,toExportUrl:()=>we,toKrokiPngUrl:()=>Rt,toKrokiSvgUrl:()=>It,toKrokiUrl:()=>ce,toMermaidInkJpegUrl:()=>Nt,toMermaidInkPdfUrl:()=>Ot,toMermaidInkPngUrl:()=>Tt,toMermaidInkSvgUrl:()=>Mt,toMermaidInkUrl:()=>Y,toMermaidInkWebpUrl:()=>Dt,trackDecision:()=>ze,trackIf:()=>Vt,trackSwitch:()=>Gt,visualizeEvents:()=>Sn});module.exports=ir(Rn);function H(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let t=Math.floor(e/6e4),r=Math.round(e%6e4/1e3);return r>=60&&(t+=1,r=0),r===0?`${t}m`:`${t}m ${r}s`}function Te(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function sr(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function xe(e,t={}){if(sr(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,a=[],n=[];for(let s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?a.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(a.length<=1)return e;a.sort((s,l)=>s.startTs-l.startTs);let i=[],c=[a[0]];for(let s=1;s<a.length;s++){let l=a[s],p=Math.min(...c.map(M=>M.startTs)),g=Math.max(...c.map(M=>M.endTs)),h=l.startTs<=p+o,w=l.startTs<g;if(!h&&!w){i.push(c),c=[l];continue}let v=w?Math.min(l.endTs,g)-l.startTs:0;h||v>=r?c.push(l):(i.push(c),c=[l])}i.push(c);let u=[];for(let s of i){let l=Math.min(...s.map(p=>p.originalIndex));if(s.length===1)u.push({node:s[0].node,position:l});else{let p=s.map(v=>v.node),g=Math.min(...s.map(v=>v.startTs)),h=Math.max(...s.map(v=>v.endTs)),w={type:"parallel",id:`detected_parallel_${g}`,name:`${p.length} parallel steps`,state:dr(p),mode:"all",children:p,startTs:g,endTs:h,durationMs:h-g};u.push({node:w,position:l})}}for(let{node:s,originalIndex:l}of n)u.push({node:s,position:l});return u.sort((s,l)=>s.position-l.position),u.map(s=>s.node)}function dr(e){return e.some(n=>n.state==="error")?"error":e.some(n=>n.state==="running")?"running":e.some(n=>n.state==="pending")?"pending":(e.every(n=>n.state==="success"||n.state==="cached"),"success")}function st(e={}){return{detect:t=>xe(t,e)}}function de(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:a=1e3}=e,n=o,i=Te(),c,u,s,l="pending",p,g,h=new Map,w=[],v=[],M=new Map,$=[],T=Date.now(),I=T,S={onAfterStep:new Map},x,b=[],y=0;function E(d){return d.stepId??d.stepKey??d.name??Te()}function C(d){if(w.length>0){w[w.length-1].children.push(d),I=Date.now();return}if(v.length>0){let f=v[v.length-1];for(let m of f.branches.values())if(m.taken){m.children.push(d),I=Date.now();return}f.pendingChildren.push(d),I=Date.now();return}$.push(d),I=Date.now()}function N(d){if(!n)return;let f=q(),m=new Map;for(let[W,X]of h)m.set(W,{id:X.id,name:X.name,key:X.key,startTs:X.startTs,retryCount:X.retryCount,timedOut:X.timedOut,timeoutMs:X.timeoutMs});let F={id:`snapshot_${y}`,eventIndex:y,event:structuredClone(d),ir:structuredClone(f),timestamp:Date.now(),activeSteps:m};b.push(F),b.length>a&&b.shift(),y++}function L(d){switch(d.type){case"workflow_start":{$=[],s=void 0,g=void 0,p=void 0,h.clear(),w.length=0,v.length=0,M.clear(),c=d.workflowId,u=d.ts,l="running",T=Date.now(),I=T,x!==void 0&&x!==d.workflowId&&(S.shouldRun=void 0,S.onBeforeStart=void 0),x=d.workflowId,S.onAfterStep=new Map;break}case"workflow_success":l="success",s=d.ts,g=d.durationMs,I=Date.now();break;case"workflow_error":l="error",s=d.ts,p=d.error,g=d.durationMs,I=Date.now();break;case"workflow_cancelled":l="aborted",s=d.ts,g=d.durationMs,I=Date.now();break;case"step_start":{let f=E(d);h.set(f,{id:f,name:d.name,key:d.stepKey,startTs:d.ts,retryCount:0,timedOut:!1,metadata:d.metadata}),I=Date.now();break}case"step_success":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"success",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),h.delete(f)}break}case"step_error":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"error",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,error:d.error,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata},...d.diagnostics&&{errorDiagnostics:d.diagnostics}};C(F),h.delete(f)}break}case"step_aborted":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"aborted",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),h.delete(f)}break}case"step_cache_hit":{let m={type:"step",id:E(d),name:d.name,key:d.stepKey,state:"cached",startTs:d.ts,endTs:d.ts,durationMs:0};C(m);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let f=E(d),m=h.get(f);m&&(m.timedOut=!0,m.timeoutMs=d.timeoutMs),I=Date.now();break}case"step_retry":{let f=E(d),m=h.get(f);m&&(m.retryCount=(d.attempt??1)-1),I=Date.now();break}case"step_retries_exhausted":I=Date.now();break;case"step_skipped":{let m={type:"step",id:E(d),name:d.name,key:d.stepKey,state:"skipped",startTs:d.ts,endTs:d.ts,durationMs:0,...d.metadata&&{metadata:d.metadata}};C(m);break}case"decision":{let f=d;if(f.phase==="start"){D({type:"decision_start",workflowId:d.workflowId,decisionId:f.decisionId,name:f.label??f.decisionId,condition:f.label,decisionValue:f.value,ts:f.ts}),D({type:"decision_branch",workflowId:d.workflowId,decisionId:f.decisionId,branchLabel:"then",condition:f.label,taken:f.branch==="then",ts:f.ts}),D({type:"decision_branch",workflowId:d.workflowId,decisionId:f.decisionId,branchLabel:"else",taken:f.branch==="else",ts:f.ts});break}if(f.phase==="end"){D({type:"decision_end",workflowId:d.workflowId,decisionId:f.decisionId,branchTaken:f.branch,ts:f.ts,durationMs:f.durationMs??0});break}let m={type:"decision",id:f.decisionId,name:f.label??f.decisionId,state:"success",startTs:f.ts,endTs:f.ts,durationMs:0,condition:f.label,decisionValue:f.value,branchTaken:f.branch,branches:[{label:"then",condition:f.label,taken:f.branch==="then",children:[]},{label:"else",taken:f.branch==="else",children:[]}]};C(m),I=Date.now();break}case"hook_should_run":{let f={type:"shouldRun",state:"success",ts:d.ts,durationMs:d.durationMs,context:{result:d.result,skipped:d.skipped}};S.shouldRun=f,x=d.workflowId,I=Date.now();break}case"hook_should_run_error":{let f={type:"shouldRun",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error};S.shouldRun=f,x=d.workflowId,I=Date.now();break}case"hook_before_start":{let f={type:"onBeforeStart",state:"success",ts:d.ts,durationMs:d.durationMs,context:{result:d.result,skipped:d.skipped}};S.onBeforeStart=f,x=d.workflowId,I=Date.now();break}case"hook_before_start_error":{let f={type:"onBeforeStart",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error};S.onBeforeStart=f,x=d.workflowId,I=Date.now();break}case"hook_after_step":{let f={type:"onAfterStep",state:"success",ts:d.ts,durationMs:d.durationMs,context:{stepKey:d.stepKey}};S.onAfterStep.set(d.stepKey,f),I=Date.now();break}case"hook_after_step_error":{let f={type:"onAfterStep",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error,context:{stepKey:d.stepKey}};S.onAfterStep.set(d.stepKey,f),I=Date.now();break}case"stream_created":{let f=`${d.workflowId}:${d.namespace}`;M.set(f,{id:Te(),namespace:d.namespace,startTs:d.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),I=Date.now();break}case"stream_write":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&(m.writeCount++,m.finalPosition=Math.max(m.finalPosition,d.position)),I=Date.now();break}case"stream_read":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&m.readCount++,I=Date.now();break}case"stream_close":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);if(m){m.streamState="closed",m.finalPosition=d.finalPosition;let F={type:"stream",id:m.id,namespace:m.namespace,state:"success",startTs:m.startTs,endTs:d.ts,durationMs:d.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:d.finalPosition,streamState:"closed",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(f)}I=Date.now();break}case"stream_error":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);if(m){m.streamState="error";let F={type:"stream",id:m.id,namespace:m.namespace,state:"error",error:d.error,startTs:m.startTs,endTs:d.ts,durationMs:d.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:d.position,streamState:"error",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(f)}I=Date.now();break}case"stream_backpressure":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&(m.backpressureOccurred=!0),I=Date.now();break}}N(d)}function P(d){if(d.type==="scope_start")w.push({id:d.scopeId,name:d.name,type:d.scopeType,startTs:d.ts,children:[]}),I=Date.now();else if(d.type==="scope_end"){let f=w.findIndex(W=>W.id===d.scopeId);if(f===-1)return;for(;w.length>f+1;){let W=w.pop(),X=W.type==="race"?{type:"race",id:W.id,name:W.name,state:k(W.children),startTs:W.startTs,endTs:d.ts,children:W.children}:{type:"parallel",id:W.id,name:W.name,state:k(W.children),startTs:W.startTs,endTs:d.ts,children:W.children,mode:W.type==="allSettled"?"allSettled":"all"};w[w.length-1].children.push(X)}let[m]=w.splice(f,1),F=m.type==="race"?{type:"race",id:m.id,name:m.name,state:k(m.children),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,children:m.children,winnerId:d.winnerId}:{type:"parallel",id:m.id,name:m.name,state:k(m.children),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,children:m.children,mode:m.type==="allSettled"?"allSettled":"all"};C(F)}}function D(d){if(d.type==="decision_start")v.push({id:d.decisionId,name:d.name,condition:d.condition,decisionValue:d.decisionValue,startTs:d.ts,branches:new Map,pendingChildren:[]}),I=Date.now();else if(d.type==="decision_branch"){let f=v.find(m=>m.id===d.decisionId);if(f){let m=d.branchLabel,F=f.branches.get(m);if(F)F.taken=d.taken,d.taken&&f.pendingChildren.length>0&&(F.children.unshift(...f.pendingChildren),f.pendingChildren=[]);else{let W=d.taken?[...f.pendingChildren]:[];d.taken&&(f.pendingChildren=[]),f.branches.set(m,{label:d.branchLabel,condition:d.condition,taken:d.taken,children:W})}I=Date.now()}}else if(d.type==="decision_end"){let f=v.findIndex(m=>m.id===d.decisionId);if(f!==-1){let[m]=v.splice(f,1),F=v.splice(f),W=Array.from(m.branches.values());W.length===0&&m.pendingChildren.length>0&&(W=[{label:"default",taken:!0,children:[...m.pendingChildren]}]);let X=W.find($e=>$e.taken)?.label,Zt={type:"decision",id:m.id,name:m.name,state:k(W.flatMap($e=>$e.taken?$e.children:[])),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,condition:m.condition,decisionValue:m.decisionValue,branchTaken:d.branchTaken??X,branches:W};C(Zt),v.push(...F),I=Date.now()}}}function k(d){return d.length===0?"success":d.some(W=>W.state==="error")?"error":d.every(W=>W.state==="success"||W.state==="cached")?"success":d.some(W=>W.state==="running")?"running":"pending"}function O(){let d=[...$];for(let[,f]of h)d.push({type:"step",id:f.id,name:f.name,key:f.key,state:"running",startTs:f.startTs,...f.retryCount>0&&{retryCount:f.retryCount},...f.timedOut&&{timedOut:!0,timeoutMs:f.timeoutMs}});for(let[,f]of M)d.push({type:"stream",id:f.id,namespace:f.namespace,state:"running",startTs:f.startTs,writeCount:f.writeCount,readCount:f.readCount,finalPosition:f.finalPosition,streamState:f.streamState,backpressureOccurred:f.backpressureOccurred});return d}function q(){let d=O();t&&(d=xe(d,r));let f={type:"workflow",id:c??i,workflowId:c??i,state:l,startTs:u,endTs:s,durationMs:g,children:d,error:p},m=S.shouldRun!==void 0||S.onBeforeStart!==void 0||S.onAfterStep.size>0;return{root:f,metadata:{createdAt:T,lastUpdatedAt:I},...m&&{hooks:S}}}function oe(){c=void 0,u=void 0,s=void 0,l="pending",p=void 0,g=void 0,h.clear(),w.length=0,v.length=0,M.clear(),$=[],T=Date.now(),I=T,S={onAfterStep:new Map},x=void 0,b.length=0,y=0}function at(){return[...b]}function ve(d){return b[d]}function qt(d){return b[d]?.ir}function Xt(){b.length=0,y=0}return{handleEvent:L,handleScopeEvent:P,handleDecisionEvent:D,getIR:q,reset:oe,getSnapshots:at,getSnapshotAt:ve,getIRAt:qt,clearSnapshots:Xt,get hasActiveSteps(){return h.size>0},get state(){return l},get snapshotCount(){return b.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(d){n=d}}}var De=require("awaitly");function j(e){return e.type==="step"}function je(e){return e.type==="sequence"}function G(e){return e.type==="parallel"}function U(e){return e.type==="race"}function J(e){return e.type==="decision"}function re(e){return e.type==="stream"}function cr(e){return"children"in e||e.type==="decision"&&"branches"in e}var Ve="\x1B[0m",lr="\x1B[1m",ct="\x1B[2m",ur="\x1B[31m",pr="\x1B[32m",mr="\x1B[33m",fr="\x1B[34m",dt="\x1B[90m",hr="\x1B[37m";function Z(e,t){return t?`${t}${e}${Ve}`:e}function Se(e){return`${lr}${e}${Ve}`}function _(e){return`${ct}${e}${Ve}`}var z={pending:hr,running:mr,success:pr,error:ur,aborted:dt,cached:fr,skipped:ct+dt};function gr(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 Ie(e,t){let r=gr(e);return Z(r,t[e])}function Ne(e,t,r){return Z(e,r[t])}function ne(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var R={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},fe={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},br="\x1B[0m";function wr(e){return e<.2?fe.cold:e<.4?fe.cool:e<.6?fe.neutral:e<.8?fe.warm:e<.95?fe.hot:fe.critical}function lt(e,t){let r=wr(t);return r?`${r}${e}${br}`:e}function yr(e){try{return(0,De.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return(0,De.err)("STRINGIFY_ERROR")}}function ut(e){let t=yr(e);return t.ok?t.value:"[unserializable]"}var pt="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function Ye(e,t=10){if(e.length===0)return"";let r=e.slice(-t),o=Math.min(...r),n=Math.max(...r)-o||1;return r.map(i=>{let c=(i-o)/n,u=Math.floor(c*(pt.length-1));return pt[u]}).join("")}function Ge(e,t){let r=ne(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function kr(e,t){if(!t)return R.horizontal.repeat(e);let r=` ${t} `,o=ne(r).length,a=e-o;if(a<4)return R.horizontal.repeat(e);let n=2,i=a-n;return R.horizontal.repeat(n)+r+R.horizontal.repeat(i)}function mt(e,t,r){let o=e.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),a=e.durationMs!==void 0?_(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=_(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=_(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?_(` error: ${String(e.error)}`):"";return`${o} ${_(t)}${n}${a}${i}`}function vr(e,t){let r=[];return e.shouldRun&&r.push(mt(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(mt(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(_("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ae(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...z,...t.colors},o=Math.max(t.terminalWidth??60,5),a=o-4,n=[],i=e.root.name??"workflow",c=Se(i);if(n.push(`${R.topLeft}${kr(o-2,c)}${R.topRight}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.hooks){let s=vr(e.hooks,r);for(let l of s)n.push(`${R.vertical} ${Ge(l,a)}${R.vertical}`)}let u=Oe(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${R.vertical} ${Ge(s,a)}${R.vertical}`);if(n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let s=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",p=`${Ne(s,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${R.vertical} ${Ge(p,a)}${R.vertical}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`)}return n.push(`${R.bottomLeft}${R.horizontal.repeat(o-2)}${R.bottomRight}`),n.join(`
|
|
2
|
+
`)}}}function Oe(e,t,r,o,a){let n=[];for(let i of e)j(i)?n.push(Je(i,t,r,a)):G(i)?n.push(...Sr(i,t,r,o,a)):U(i)?n.push(...Ir(i,t,r,o,a)):J(i)?n.push(...Rr(i,t,r,o,a)):re(i)&&n.push(xr(i,t,r));return n}function Je(e,t,r,o){let a=Ie(e.state,r),n=e.name??e.key??"step",i=t,c=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,u;c!==void 0?u=lt(n,c):u=Ne(n,e.state,r);let s=`${a} ${u}`;if(t.showKeys&&e.key&&e.name&&(s+=_(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:ut(e.input).slice(0,30);s+=_(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:ut(e.output).slice(0,30);s+=_(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=H(e.durationMs),g=c!==void 0?lt(`[${p}]`,c):_(`[${p}]`);s+=` ${g}`}if(i.showSparklines&&i.timingHistory){let p=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);p&&p.length>1&&(s+=` ${_(Ye(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(s+=_(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";s+=_(` [timeout${p}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let p=o.onAfterStep.get(l),g=p.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),h=p.durationMs!==void 0?_(` ${H(p.durationMs)}`):"";s+=` ${g}${h}`}return s}function xr(e,t,r){let o=e.streamState==="active"?Z("\u27F3",r.running):e.streamState==="closed"?Z("\u2713",r.success):Z("\u2717",r.error),a=`stream:${e.namespace}`,n=Ne(a,e.state,r),i=_(`[W:${e.writeCount} R:${e.readCount}]`),c=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(c+=` ${_(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(c+=_(" [backpressure]")),e.streamState==="closed"&&(c+=_(` pos:${e.finalPosition}`)),c}function Sr(e,t,r,o,a){let n=[],i=" ".repeat(o),c=Ie(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${R.teeRight}${R.teeDown}${R.horizontal} ${c} ${Se(u)}${s}`),e.children.length===0)n.push(`${i}${R.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${R.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],h=l===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`;if(j(p))n.push(`${h} ${Je(p,t,r,a)}`);else{let w=Oe([p],t,r,o+1,a);for(let v of w)n.push(`${i}${R.vertical} ${v}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Ir(e,t,r,o,a){let n=[],i=" ".repeat(o),c=Ie(e.state,r),u=e.name??"race";if(n.push(`${i}${R.teeRight}\u26A1 ${c} ${Se(u)}`),e.children.length===0)n.push(`${i}${R.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${R.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let s=0;s<e.children.length;s++){let l=e.children[s],g=s===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,w=e.winnerId&&l.id===e.winnerId?_(" (winner)"):"";if(j(l))n.push(`${g} ${Je(l,t,r,a)}${w}`);else{let v=Oe([l],t,r,o+1,a);for(let M of v)n.push(`${i}${R.vertical} ${M}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Rr(e,t,r,o,a){let n=[],i=" ".repeat(o),c=Ie(e.state,r),u=e.name??"decision",s=e.condition?_(` (${e.condition})`):"",l=e.decisionValue!==void 0?_(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?_(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${R.teeRight}${R.teeDown}${R.horizontal} ${c} ${Se(u)}${s}${l}${p}`);for(let g=0;g<e.branches.length;g++){let h=e.branches[g],v=g===e.branches.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,M=h.taken?"\u2713":"\u2298",$=h.taken?r.success:r.skipped,T=Z(`${M} ${h.label}`,$),I=h.condition?_(` (${h.condition})`):"";if(n.push(`${v} ${T}${I}`),h.children.length>0){let S=Oe(h.children,t,r,o+1,a);for(let x of S)n.push(`${i}${R.vertical} ${x}`)}else h.taken||n.push(`${i}${R.vertical} ${_("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}var We=require("awaitly");function qe(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...qe(r.children)),"branches"in r)for(let o of r.branches)t.push(...qe(o.children));return t}function Ce(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function he(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function ft(){let e=new Map,t=new Map,r=new Map,o=new Map,a=[];function n(S){return S.stepKey??S.stepId??S.name??"unknown"}function i(S){let x=new Map;for(let b of S)switch(b.type){case"step_start":{let y=n(b);x.set(y,{retried:!1,timedOut:!1});break}case"step_retry":{let y=n(b),E=x.get(y);E&&(E.retried=!0);break}case"step_timeout":{let y=n(b),E=x.get(y);E&&(E.timedOut=!0);break}case"step_success":{let y=n(b),E=x.get(y),C=e.get(y)??[];C.push(b.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,r.set(y,P),x.delete(y);break}case"step_error":{let y=n(b),E=x.get(y),C=e.get(y)??[];C.push(b.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,P.errors++,r.set(y,P),x.delete(y);break}}}function c(S){i(S.events)}function u(S){a.push(S)}function s(S){a.length>0&&(i(a),a=[])}function l(S){let x=e.get(S);if(!x||x.length===0)return;let b=[...x].sort((D,k)=>D-k),E=b.reduce((D,k)=>D+k,0)/b.length,C=b.reduce((D,k)=>D+(k-E)**2,0)/b.length,N=t.get(S)??{retried:0,total:1},L=r.get(S)??{errors:0,total:1},P=o.get(S)??{timedOut:0,total:1};return{nodeId:S,avgDurationMs:E,minDurationMs:b[0],maxDurationMs:b[b.length-1],stdDevMs:Math.sqrt(C),samples:b.length,retryRate:N.total>0?N.retried/N.total:0,timeoutRate:P.total>0?P.timedOut/P.total:0,errorRate:L.total>0?L.errors/L.total:0,percentiles:{p50:Ce(b,.5),p90:Ce(b,.9),p95:Ce(b,.95),p99:Ce(b,.99)}}}function p(S){return l(S)}function g(S,x="duration"){let b=new Map,y=qe(S.root.children),E=[];for(let k of y){let O=("key"in k?k.key:void 0)??k.id??k.name,q=l(O);if(q){let oe;switch(x){case"duration":oe=q.avgDurationMs;break;case"retryRate":oe=q.retryRate;break;case"errorRate":oe=q.errorRate;break}E.push({id:k.id,value:oe})}}if(E.length===0)return{heat:b,metric:x,stats:{min:0,max:0,mean:0,threshold:0}};let C=E.map(k=>k.value),N=Math.min(...C),L=Math.max(...C),P=C.reduce((k,O)=>k+O,0)/C.length,D=L-N||1;for(let{id:k,value:O}of E)b.set(k,(O-N)/D);return{heat:b,metric:x,stats:{min:N,max:L,mean:P,threshold:P+(L-P)*.5}}}function h(){let S=new Map;for(let x of e.keys()){let b=l(x);b&&S.set(x,b)}return S}function w(S=10){return[...h().values()].sort((b,y)=>y.avgDurationMs-b.avgDurationMs).slice(0,S)}function v(S=10){return[...h().values()].filter(b=>b.errorRate>0).sort((b,y)=>y.errorRate-b.errorRate).slice(0,S)}function M(S=10){return[...h().values()].filter(b=>b.retryRate>0).sort((b,y)=>y.retryRate-b.retryRate).slice(0,S)}function $(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function T(S){let x=JSON.parse(S);e.clear(),t.clear(),r.clear(),o.clear();for(let[b,y]of Object.entries(x.timingData??{}))e.set(b,y);for(let[b,y]of Object.entries(x.retryData??{}))t.set(b,y);for(let[b,y]of Object.entries(x.errorData??{}))r.set(b,y);for(let[b,y]of Object.entries(x.timeoutData??{}))o.set(b,y)}function I(){e.clear(),t.clear(),r.clear(),o.clear(),a=[]}return{addRun:c,addEvent:u,finalizeRun:s,getNodePerformance:p,getHeatmap:g,getSlowestNodes:w,getErrorProneNodes:v,getRetryProneNodes:M,getAllPerformance:h,exportData:$,importData:T,clear:I}}function Er(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function $r(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function Mr(e){return`heat_${e}`}function Tr(){return[" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e"," classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d"]}function Nr(e){try{return(0,We.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return(0,We.err)("STRINGIFY_ERROR")}}function ht(e){let t=Nr(e);return t.ok?t.value:"[unserializable]"}function Dr(e,t,r){let o;if(e.shouldRun){let a="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",i=e.shouldRun.state==="success"?"\u2699":"\u26A0",c=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${a}[["${i} shouldRun${u}${c}"]]:::${n}`),o=a}if(e.onBeforeStart){let a="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",c=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${a}[["${i} onBeforeStart${u}${c}"]]:::${n}`),o&&t.push(` ${o} --> ${a}`),o=a}return{lastHookId:o}}var gt=0,Le=new Set,_e=new Set;function ge(e="node"){return`${e}_${++gt}`}function Or(){gt=0,Le.clear(),_e.clear()}function V(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function bt(e){return V(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){Or();let r=[],o=t;r.push("flowchart TD");let a;e.hooks&&(a=Dr(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),a&&r.push(` ${a} --> ${n}`);let i=n;for(let u of e.root.children){let s=Be(u,t,r,o,e.hooks);r.push(` ${i} --> ${s.entryId}`),i=s.exitId}if(["success","error","aborted"].includes(e.root.state)){let u="finish",s=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",l=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",p=`(("${s} ${l}"))`,g=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${p}${g}`),r.push(` ${i} --> ${u}`)}return r.push(""),r.push(...Er()),o.showHeatmap&&r.push(...$r()),e.hooks&&r.push(...Tr()),r.join(`
|
|
3
|
+
`)}}}function Be(e,t,r,o,a){if(j(e))return Cr(e,t,r,o,a);if(G(e))return Lr(e,t,r,o,a);if(U(e))return _r(e,t,r,o,a);if(J(e))return Wr(e,t,r,o,a);if(re(e))return Br(e,t,r);let n=ge("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function Cr(e,t,r,o,a){let n=t,i=n.showRetryEdges??!0,c=n.showErrorEdges??!0,u=n.showTimeoutEdges??!0,s=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ge("step");if(_e.has(s)){let b=2;for(;_e.has(`${s}_${b}`);)b++;s=`${s}_${b}`}_e.add(s);let l=e.name??e.key??"Step",p=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,g=V(p),h=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",w="";switch(e.state){case"success":w="\u2713 ";break;case"error":w="\u2717 ";break;case"cached":w="\u{1F4BE} ";break;case"running":w="\u23F3 ";break;case"skipped":w="\u2298 ";break}let v="";if(e.input!==void 0){let b=typeof e.input=="string"?V(e.input):V(ht(e.input).slice(0,20));v+=`\\nin: ${b}`}if(e.output!==void 0&&e.state==="success"){let b=typeof e.output=="string"?V(e.output):V(ht(e.output).slice(0,20));v+=`\\nout: ${b}`}let M="",$=e.key??e.id;if(a&&$&&a.onAfterStep.has($)){let b=a.onAfterStep.get($),y=b.state==="success"?"\u2699":"\u26A0",E=t.showTimings&&b.durationMs!==void 0?` ${H(b.durationMs)}`:"";M=`\\n${y} hook${E}`}let T=(w+g+v+M+h).trim(),I,S=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let b=he(S);I=Mr(b)}else I=e.state;let x;switch(e.state){case"error":x=`{{"${T}"}}`;break;case"cached":x=`[("${T}")]`;break;case"skipped":x=`["${T}"]`;break;default:x=`["${T}"]`}if(r.push(` ${s}${x}:::${I}`),i&&e.retryCount!==void 0&&e.retryCount>0){let b=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${s} -.->|"${b}"| ${s}`)}if(c&&e.state==="error"&&e.error!==void 0){let b=`ERR_${s}`,y=V(String(e.error)).slice(0,30);r.push(` ${b}{{"${y}"}}`),r.push(` ${s} -->|error| ${b}`),r.push(` style ${b} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let b=`TO_${s}`,y=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${b}{{"\u23F1 Timeout ${y}"}}`),r.push(` ${s} -.->|timeout| ${b}`),r.push(` style ${b} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function Lr(e,t,r,o,a){let n=ge("parallel"),i=`${n}_fork`,c=`${n}_join`,u=bt(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let g=n,h=V(`${u}${s}`),w="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["${h}${v}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["${u}${s}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let l=[];for(let g of e.children){let h=Be(g,t,r,o,a);r.push(` ${i} --> ${h.entryId}`),l.push(h.exitId)}r.push(` ${c}{"\u2713 Join"}`);for(let g of l)r.push(` ${g} --> ${c}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:c}}function _r(e,t,r,o,a){let n=ge("race"),i=`${n}_start`,c=`${n}_end`,u=bt(e.name??"Race");if(e.children.length===0){let g=n,h=V(u),w="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["\u26A1 ${h}${v}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let s=[],l;for(let g of e.children){let h=Be(g,t,r,o,a),w=e.winnerId===g.id;r.push(` ${i} --> ${h.entryId}`),w&&(l=h.exitId),s.push({exitId:h.exitId,isWinner:w})}r.push(` ${c}(("\u2713 First"))`);for(let{exitId:g,isWinner:h}of s)h&&l?r.push(` ${g} ==>|\u{1F3C6} Winner| ${c}`):e.winnerId?r.push(` ${g} -. cancelled .-> ${c}`):r.push(` ${g} --> ${c}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:c}}function Wr(e,t,r,o,a){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ge("decision");if(Le.has(n)){let g=2;for(;Le.has(`${n}_${g}`);)g++;n=`${n}_${g}`}Le.add(n);let i=V(e.condition??"condition"),c=e.decisionValue!==void 0?` = ${V(String(e.decisionValue)).slice(0,30)}`:"",u=`${i}${c}`.trim();r.push(` ${n}{"${u}"}`);let s=[],l,p=new Set;for(let g of e.branches){let h=`${n}_${g.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(p.has(h)){let T=2;for(;p.has(`${h}_${T}`);)T++;h=`${h}_${T}`}p.add(h);let w=V(g.label),v=g.taken?`${w} \u2713`:`${w} skipped`,M=g.taken?":::success":":::skipped";r.push(` ${h}["${v}"]${M}`);let $=g.condition?`|${V(g.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${$} ${h}`),g.children.length>0){let T=h;for(let I of g.children){let S=Be(I,t,r,o,a);r.push(` ${T} --> ${S.entryId}`),T=S.exitId}s.push(T),g.taken&&(l=T)}else s.push(h),g.taken&&(l=h)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function Br(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${ge("")}`,a=`W:${e.writeCount} R:${e.readCount}`,n="";switch(e.streamState){case"active":n="\u27F3 ";break;case"closed":n="\u2713 ";break;case"error":n="\u2717 ";break}let i=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",c=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${V(e.namespace)}\\n${a}${c}${i}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",r.push(` ${o}{{"${u}"}}:::${s}`),{entryId:o,exitId:o}}var B={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},Ar={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Pr="\x1B[0m";function Hr(e,t){let r=[],o=[];for(let a=0;a<t;a++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function A(e,t,r,o,a){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,a&&(e.colors[r][t]=a))}function kt(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function Fr(e,t,r,o,a){A(e,t,r,B.topLeft);for(let n=1;n<o-1;n++)A(e,t+n,r,B.horizontal);A(e,t+o-1,r,B.topRight);for(let n=1;n<a-1;n++)A(e,t,r+n,B.vertical),A(e,t+o-1,r+n,B.vertical);A(e,t,r+a-1,B.bottomLeft);for(let n=1;n<o-1;n++)A(e,t+n,r+a-1,B.horizontal);A(e,t+o-1,r+a-1,B.bottomRight)}function wt(e,t,r,o,a){let n=ne(o).split("");for(let i=0;i<n.length;i++)A(e,t+i,r,n[i],a)}function se(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let c=kt(e,t,i);c===B.horizontal?A(e,t,i,B.cross):(c===" "||c===B.vertical)&&A(e,t,i,B.vertical)}}function yt(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let c=kt(e,i,t);c===B.vertical?A(e,i,t,B.cross):(c===" "||c===B.horizontal)&&A(e,i,t,B.horizontal)}}function pe(e,t,r){A(e,t,r,B.arrowDown)}function Ur(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let a=0;a<e.width;a++){let n=e.colors[r][a],i=e.cells[r][a];n?o+=n+i+Pr:o+=i}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
|
|
4
|
+
`)}var Q=11,ee=2,be=2,Ae=3;function Ze(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],a="";for(let n of r)a?a.length+1+n.length<=t?a+=" "+n:(o.push(a),a=n):a=n;if(a&&o.push(a),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function vt(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function zr(e,t,r){let o=t.showStartEnd??!0,a=t,n=Math.floor(r/2),i=[],c=0;if(o){let s=Pe("start","start",["\u25B6 Start"],"success",n,c);i.push(s),c=s.bottomY+be}for(let s of e.root.children){let l=He(s,n,c,r-4,t,a);i.push(l.node),c=l.bottomY+be}if(o&&["success","error","aborted"].includes(e.root.state)){let s=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",l=Pe("end","end",[s],e.root.state,n,c);i.push(l),c=l.bottomY}return{nodes:i,totalHeight:c+2}}function Pe(e,t,r,o,a,n){let i=Math.max(...r.map(l=>ne(l).length)),c=Math.max(Q,i+ee*2),u=r.length+2,s=a-Math.floor(c/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:c,height:u,centerX:a,bottomY:n+u-1}}function He(e,t,r,o,a,n){if(j(e))return Kr(e,t,r,o,a,n);if(G(e)||U(e))return Vr(e,t,r,o,a,n);if(J(e))return Gr(e,t,r,o,a,n);if(re(e))return jr(e,t,r,o,a,n);let i=Pe(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function Kr(e,t,r,o,a,n){let i=e.name??e.key??"step",c=vt(e.state),u=[],s=`${c} ${i}`;a.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-ee*2,40);if(u.push(...Ze(s,l)),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let $=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);$&&$.length>1&&u.push(Ye($,8))}let p=Math.max(...u.map($=>ne($).length)),g=Math.max(Q,p+ee*2),h=u.length+2,w=t-Math.floor(g/2),v;if(n?.showHeatmap&&n.heatmapData){let $=e.key??e.name??e.id;v=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get($)}let M={id:e.id,type:"step",label:u,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1,metadata:v!==void 0?{heat:v}:void 0};return{node:M,bottomY:M.bottomY}}function jr(e,t,r,o,a,n){let i=`stream:${e.namespace}`,c=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${c} ${i}`,l=Math.min(o-ee*2,40);u.push(...Ze(s,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let p=Math.max(...u.map(M=>ne(M).length)),g=Math.max(Q,p+ee*2),h=u.length+2,w=t-Math.floor(g/2),v={id:e.id,type:"stream",label:u,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:v,bottomY:v.bottomY}}function Vr(e,t,r,o,a,n){let i=U(e),c=e.name??(i?"race":"parallel"),s=`${i?"\u26A1":"\u2AD8"} ${c}`;if(e.children.length===0){let y=[s,"(not tracked)"],E=Pe(e.id,i?"race":"parallel",y,e.state,t,r);return{node:E,bottomY:E.bottomY}}let l=Math.floor((o-Ae*(e.children.length-1))/e.children.length),p=[];for(let y of e.children){let E=Xe(y,Math.max(l,Q),a,n);p.push(E.width)}let g=p.reduce((y,E)=>y+E,0)+Ae*(e.children.length-1),h=g>o&&e.children.length>1,w=Math.max(Q,s.length+ee*2),v=3,M=t-Math.floor(w/2),$=r;$+=v,$+=1,$+=1;let T=[];if(h)for(let y=0;y<e.children.length;y++){let E=e.children[y],C=He(E,t,$,o,a,n);i&&U(e)&&e.winnerId===E.id&&(C.node.metadata={...C.node.metadata,isWinner:!0}),T.push(C.node),$=C.bottomY+be}else{let y=t-Math.floor(g/2);for(let E=0;E<e.children.length;E++){let C=e.children[E],N=y+Math.floor(p[E]/2),L=He(C,N,$,p[E],a,n);i&&U(e)&&e.winnerId===C.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),T.push(L.node),y+=p[E]+Ae}}let I=Math.max(...T.map(y=>y.bottomY)),x=!h&&T.length>1?I+2:I;return{node:{id:e.id,type:i?"race":"parallel",label:[s],state:e.state,x:M,y:r,width:w,height:v,centerX:t,bottomY:x,children:T,metadata:{verticalLayout:h}},bottomY:x}}function Gr(e,t,r,o,a,n){let i=e.name??"decision",c=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${i}${c}`,s=Math.min(o-ee*2,40),l=Ze(u,s),p=Math.max(...l.map(x=>ne(x).length)),g=Math.max(Q,p+ee*2),h=l.length+2,w=t-Math.floor(g/2),v=e.branches.find(x=>x.taken),M=v&&v.children.length>0?v:e.branches.find(x=>x.children.length>0);if(!M||M.children.length===0){let x={id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1};return{node:x,bottomY:x.bottomY}}let $=r+h+be,T=[];for(let x of M.children){let b=He(x,t,$,o,a,n);T.push(b.node),$=b.bottomY+be}let I=T.length>0?T[T.length-1].bottomY:r+h-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:I,children:T},bottomY:I}}function Xe(e,t,r,o){if(j(e)){let a=e.name??e.key??"step",n=vt(e.state),i=1;r.showTimings&&e.durationMs!==void 0&&i++,e.retryCount&&e.retryCount>0&&i++,e.timedOut&&i++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&i++;let c=`${n} ${a}`;r.showKeys&&e.key&&e.name&&(c+=` [${e.key}]`);let u=Math.min(t,Math.max(Q,c.length+ee*2)),s=i+2;return{width:u,height:s}}if(G(e)||U(e)){if(e.children.length===0)return{width:Q+4,height:4};let a=Math.floor(t/e.children.length),n=0,i=0;for(let c of e.children){let u=Xe(c,a,r,o);n+=u.width,i=Math.max(i,u.height)}return n+=Ae*(e.children.length-1),{width:Math.max(n,Q),height:5+i+2}}if(J(e)){let a=e.branches.find(i=>i.taken),n=0;if(a)for(let i of a.children){let c=Xe(i,t,r,o);n+=c.height+be}return{width:Math.min(t,30),height:3+n}}if(re(e)){let a=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(Q,a.length+ee*2+4)),c=n+2;return{width:i,height:c}}return{width:Q,height:3}}function Yr(e,t,r){let o={...z,...r.colors};for(let a=0;a<t.length;a++){let n=t[a],i=a===t.length-1;if(Fe(e,n,o),!i){let c=t[a+1],u=n.centerX,s=n.bottomY+1,l=c.centerX,p=c.y-1;se(e,u,s,p-1),pe(e,l,p)}}}function Fe(e,t,r){let o=t.type!=="start",a=t.type!=="end"&&(!t.children||t.children.length===0);Fr(e,t.x,t.y,t.width,t.height),o&&A(e,t.centerX,t.y,B.teeUp),(a||t.children&&t.children.length>0)&&A(e,t.centerX,t.y+t.height-1,B.teeDown);let n=t.width-ee*2,i=Zr(t,r);for(let c=0;c<t.label.length;c++){let u=t.label[c],s=t.x+1+Math.floor((n-ne(u).length)/2),l=t.y+1+c;wt(e,s,l,u,i)}t.metadata?.isWinner&&wt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?Jr(e,t,r):qr(e,t,r))}function Jr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let c=o[0];se(e,n,a,c.y-2),pe(e,c.centerX,c.y-1);for(let u=0;u<o.length;u++){let s=o[u];if(Fe(e,s,r),u<o.length-1){let l=o[u+1];se(e,s.centerX,s.bottomY+1,l.y-2),pe(e,l.centerX,l.y-1)}}return}if(o.length===1)se(e,n,a,o[0].y-2),pe(e,o[0].centerX,o[0].y-1);else{let c=o.map(l=>l.centerX),u=Math.min(...c),s=Math.max(...c);se(e,n,a,a+1),yt(e,a+1,u,s),A(e,n,a+1,B.teeUp);for(let l of o){let p=l.centerX;p===u?A(e,p,a+1,B.topLeft):p===s?A(e,p,a+1,B.topRight):p!==n&&A(e,p,a+1,B.teeDown),se(e,p,a+2,l.y-2),pe(e,p,l.y-1)}}for(let c of o)Fe(e,c,r);if(o.length>1){let c=o.map(h=>h.bottomY),u=Math.max(...c),s=u+1,l=o.map(h=>h.centerX),p=Math.min(...l),g=Math.max(...l);for(let h of o)h.bottomY<u&&se(e,h.centerX,h.bottomY+1,s-1);yt(e,s,p,g);for(let h of o){let w=h.centerX;w===p?A(e,w,s,B.bottomLeft):w===g?A(e,w,s,B.bottomRight):A(e,w,s,B.teeUp)}A(e,t.centerX,s,B.teeDown),A(e,t.centerX,s+1,B.vertical)}}function qr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=o[0];se(e,t.centerX,a,n.y-2),pe(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let c=o[i];if(Fe(e,c,r),i<o.length-1){let u=o[i+1];se(e,c.centerX,c.bottomY+1,u.y-2),pe(e,u.centerX,u.y-1)}}}var Xr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function Zr(e,t){if(e.metadata?.heat!==void 0){let r=he(e.metadata.heat);return Ar[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?Xr[e.metadata.streamState]||void 0:t[e.state]||void 0}function me(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:a}=zr(e,t,r),n=Hr(r,a);return Yr(n,o,t),Ur(n)}}}function Qr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function en(e){let t=[];function r(o){for(let a of o)if(j(a))t.push(a);else if(je(a))r(a.children);else if(G(a)||U(a))r(a.children);else if(J(a))for(let n of a.branches)n.taken&&r(n.children)}return r(e),t}function tn(e){let t={id:e.id,name:e.name??e.key??e.id,state:e.state};return e.key&&(t.key=e.key),e.durationMs!==void 0&&(t.durationMs=e.durationMs),e.startTs!==void 0&&(t.startTs=e.startTs),e.endTs!==void 0&&(t.endTs=e.endTs),e.retryCount!==void 0&&e.retryCount>0&&(t.retryCount=e.retryCount),e.timedOut&&(t.timedOut=!0,e.timeoutMs!==void 0&&(t.timeoutMs=e.timeoutMs)),e.error!==void 0&&(t.error=typeof e.error=="string"?e.error:String(e.error)),e.metadata&&(e.metadata.domain&&(t.domain=e.metadata.domain),e.metadata.owner&&(t.owner=e.metadata.owner),e.metadata.intent&&(t.intent=e.metadata.intent),e.metadata.calls?.length&&(t.calls=e.metadata.calls)),e.errorDiagnostics&&(t.errorDiagnostics={tag:e.errorDiagnostics.tag,origin:e.errorDiagnostics.origin},e.errorDiagnostics.classification?.severity&&(t.errorDiagnostics.severity=e.errorDiagnostics.classification.severity),e.errorDiagnostics.classification?.retryable!==void 0&&(t.errorDiagnostics.retryable=e.errorDiagnostics.classification.retryable)),t}function rn(e){let t=0,r=0,o=0,a=0,n=0,i;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&a++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!i||s.durationMs>i.durationMs)&&(i={name:s.name??s.key??s.id,durationMs:s.durationMs});let c=new Map;for(let s of e){let l=s.metadata?.domain;if(l&&(s.state==="success"||s.state==="error")){let p=c.get(l)??{total:0,errors:0,totalDuration:0};p.total++,s.state==="error"&&p.errors++,s.durationMs!==void 0&&(p.totalDuration+=s.durationMs),c.set(l,p)}}let u;if(c.size>0){u={};for(let[s,l]of c)u[s]={total:l.total,errors:l.errors,avgDurationMs:l.total>0?Math.round(l.totalDuration/l.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:a,totalRetries:n,slowestStep:i,...u&&{byDomain:u}}}function nn(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let a={stepKey:r};o.durationMs!==void 0&&(a.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(a.error=String(o.error)),t.onAfterStep.push(a)}}return t}function on(e,t){let r=e.root,o=en(r.children),a=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(tn),summary:rn(o)};if(e.hooks){let c=nn(e.hooks);Object.keys(c).length>0&&(i.hooks=c)}if(a){let s=((t.diagramFormat??"ascii")==="flowchart"?me():ae()).render(e,t);n&&(s=Qr(s)),i.diagram=s}return i}function Re(){return{name:"logger",supportsLive:!1,render(e,t){let o=on(e,t);return JSON.stringify(o)}}}var te=require("awaitly");var xt=ar(require("pako"),1),an=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function sn(e){let t;if(an)t=globalThis.Buffer.from(e).toString("base64");else{let r="";for(let o=0;o<e.length;o++)r+=String.fromCharCode(e[o]);t=btoa(r)}return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ue(e){let r=new TextEncoder().encode(e),o=xt.default.deflate(r);return sn(o)}var St="https://kroki.io";function Qe(e,t,r,o={}){let a=o.baseUrl??St,n=Ue(r);return`${a}/${e}/${t}/${n}`}function ce(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:z},n=o.render(e,a);return Qe("mermaid",t,n,r)}function It(e,t={}){return ce(e,"svg",t)}function Rt(e,t={}){return ce(e,"png",t)}function Et(e={}){let t=e.baseUrl??St;return{toUrl(r,o){return ce(r,o,{baseUrl:t})},toSvgUrl(r){return ce(r,"svg",{baseUrl:t})},toPngUrl(r){return ce(r,"png",{baseUrl:t})},toPdfUrl(r){return ce(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var $t="https://mermaid.ink";function et(e){return`pako:${Ue(e)}`}function dn(e){if("provider"in e){let t=e;return{theme:t.mermaidTheme,bgColor:t.background,scale:t.scale,fit:t.fit,width:t.width,height:t.height,paper:t.paper,imageType:"png"}}return e}function cn(e,t){let r=[];return t.bgColor&&r.push(`bgColor=${encodeURIComponent(t.bgColor)}`),t.theme&&r.push(`theme=${t.theme}`),t.width!==void 0&&r.push(`width=${t.width}`),t.height!==void 0&&r.push(`height=${t.height}`),t.scale!==void 0&&(t.width!==void 0||t.height!==void 0)&&r.push(`scale=${t.scale}`),e==="img"&&t.imageType&&t.imageType!=="jpeg"&&r.push(`type=${t.imageType}`),e==="pdf"&&(t.fit&&r.push("fit"),t.paper&&!t.fit&&r.push(`paper=${t.paper}`),t.landscape&&!t.fit&&r.push("landscape")),r.length>0?`?${r.join("&")}`:""}function Ee(e,t,r={}){let o=dn(r),a=o.baseUrl??$t,n=et(t),i=cn(e,o);return`${a}/${e}/${n}${i}`}function Y(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:z},n=o.render(e,a);return Ee(t,n,r)}function Mt(e,t={}){return Y(e,"svg",t)}function Tt(e,t={}){return Y(e,"img",{...t,imageType:"png"})}function Nt(e,t={}){return Y(e,"img",{...t,imageType:"jpeg"})}function Dt(e,t={}){return Y(e,"img",{...t,imageType:"webp"})}function Ot(e,t={}){return Y(e,"pdf",t)}function Ct(e={}){let t=e.baseUrl??$t;return{toUrl(r,o){return Y(r,o,e)},toSvgUrl(r){return Y(r,"svg",e)},toPngUrl(r){return Y(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return Y(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return Y(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return Y(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}function ln(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,te.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,te.err)("UNSUPPORTED_FORMAT"):(0,te.ok)(void 0):(0,te.err)("UNSUPPORTED_FORMAT")}function un(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function pn(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function we(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,te.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,te.err)("UNSUPPORTED_DIAGRAM_KIND")}}let a=ln(r.provider,e.kind,t);if(!a.ok)return a;switch(r.provider){case"kroki":return(0,te.ok)(Qe(un(e.kind),t,e.source,r));case"mermaid-ink":return(0,te.ok)(Ee(pn(t),e.source,r));default:{let n=r;return(0,te.err)("UNKNOWN_PROVIDER")}}}function Lt(e){let t={bg:"#ffffff",bgSecondary:"#f8f9fa",text:"#212529",textMuted:"#6c757d",border:"#dee2e6",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#e9ecef",nodeRunning:"#fff3cd",nodeSuccess:"#d1e7dd",nodeError:"#f8d7da",nodeAborted:"#e9ecef",nodeCached:"#cfe2ff",nodeSkipped:"#f8f9fa",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},r={bg:"#212529",bgSecondary:"#343a40",text:"#f8f9fa",textMuted:"#adb5bd",border:"#495057",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#495057",nodeRunning:"#664d03",nodeSuccess:"#0f5132",nodeError:"#842029",nodeAborted:"#495057",nodeCached:"#084298",nodeSkipped:"#343a40",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},o=n=>`
|
|
5
5
|
--bg: ${n.bg};
|
|
6
6
|
--bg-secondary: ${n.bgSecondary};
|
|
7
7
|
--text: ${n.text};
|
|
@@ -1475,10 +1475,10 @@ body {
|
|
|
1475
1475
|
return min + 'm ' + sec + 's';
|
|
1476
1476
|
}
|
|
1477
1477
|
})();
|
|
1478
|
-
`}var le=160,ye=50,tt=40,
|
|
1478
|
+
`}var le=160,ye=50,tt=40,mn=30,K=20;function fn(e,t="TB",r){let o=t==="TB"||t==="BT",a=t==="RL"||t==="BT",n=[],i=K,c=K,u=0,s=0;for(let g of e){let h=rt(g,i,c,o,r);n.push(h.node),o?(c+=h.height+mn,u=Math.max(u,h.width),s=c):(i+=h.width+tt,s=Math.max(s,h.height),u=i)}let l=u+K,p=s+K;if(a)for(let g of n)Bt(g,l,p,o);return{nodes:n,width:l,height:p}}function Bt(e,t,r,o){if(o?e.y=r-e.y-e.height:e.x=t-e.x-e.width,e.children)for(let a of e.children)Bt(a,t,r,o)}function rt(e,t,r,o,a){if(j(e)){let n=e.name??e.key??"step",i=a?.showKeys&&e.key&&e.name?`${n} [key: ${e.key}]`:n;return{node:{id:e.id,name:i,type:"step",state:e.state,x:t,y:r,width:le,height:ye,durationMs:e.durationMs},width:le,height:ye}}if(re(e)){let n=e.streamState==="active"?`stream:${e.namespace} \u27F3`:e.streamState==="error"?`stream:${e.namespace} \u2717`:`stream:${e.namespace} \u2713`;return{node:{id:e.id,name:n,type:"stream",state:e.state,x:t,y:r,width:le,height:ye,durationMs:e.durationMs},width:le,height:ye}}if(G(e)||U(e)){let n=G(e)?"parallel":"race",i=e.name??n,c=[],u=t+K,s=r+K+20,l=0;for(let w of e.children){let v=rt(w,u,s,!0,a);c.push(v.node),u+=v.width+tt,l=Math.max(l,v.height)}let p=u-t-K,g=Math.max(p+K,le+K*2),h=l+K*2+20;return{node:{id:e.id,name:i,type:n,state:e.state,x:t,y:r,width:g,height:h,durationMs:e.durationMs,children:c,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:g,height:h}}if(J(e)){let n=e.name??"decision",i=[],c=t+K,u=r+K+20,s=0;for(let g of e.branches)for(let h of g.children){let w=rt(h,c,u,!0,a);i.push(w.node),c+=w.width+tt,s=Math.max(s,w.height)}let l=Math.max(c-t,le+K*2),p=s+K*2+20;return{node:{id:e.id,name:n,type:"decision",state:e.state,x:t,y:r,width:l,height:p,durationMs:e.durationMs,children:i,containerType:"decision",containerLabel:"DECISION"},width:l,height:p}}return{node:{id:e.id,name:e.name??"unknown",type:e.type,state:e.state,x:t,y:r,width:le,height:ye},width:le,height:ye}}function At(e,t){return e.containerType?gn(e,t):hn(e,t)}function hn(e,t){let o=t&&e.durationMs!==void 0?H(e.durationMs):"";return`
|
|
1479
1479
|
<g class="wv-node wv-node--${e.state}" data-node-id="${Ht(e.id)}" transform="translate(${e.x}, ${e.y})">
|
|
1480
1480
|
<rect width="${e.width}" height="${e.height}" rx="8" ry="8" />
|
|
1481
|
-
<text x="${e.width/2}" y="${e.height/2-(o?4:0)}">${ot(
|
|
1481
|
+
<text x="${e.width/2}" y="${e.height/2-(o?4:0)}">${ot(wn(e.name,e.name.includes("[key:")?40:20))}</text>
|
|
1482
1482
|
${o?`<text class="wv-node-timing" x="${e.width/2}" y="${e.height/2+12}">${o}</text>`:""}
|
|
1483
1483
|
</g>
|
|
1484
1484
|
`}function gn(e,t){let o=e.children?.map(a=>At(a,t)).join(`
|
|
@@ -1490,26 +1490,26 @@ body {
|
|
|
1490
1490
|
${o}
|
|
1491
1491
|
</g>
|
|
1492
1492
|
</g>
|
|
1493
|
-
`}function nt(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=nt(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let a=nt(o.children,t);if(a)return a}}}function
|
|
1493
|
+
`}function nt(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=nt(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let a=nt(o.children,t);if(a)return a}}}function bn(e,t){let r=[];function o(n,i){if(Math.abs(n.y-i.y)<n.height){let u=n.x+n.width,s=n.y+n.height/2,l=i.x,p=i.y+i.height/2;r.push(`
|
|
1494
1494
|
<path class="wv-edge" d="M ${u} ${s} L ${l-8} ${p}" />
|
|
1495
1495
|
<polygon class="wv-edge-arrow" points="${l-8},${p-4} ${l-8},${p+4} ${l},${p}" />
|
|
1496
1496
|
`)}else{let u=n.x+n.width/2,s=n.y+n.height,l=i.x+i.width/2,p=i.y;r.push(`
|
|
1497
1497
|
<path class="wv-edge" d="M ${u} ${s} L ${l} ${p-8}" />
|
|
1498
1498
|
<polygon class="wv-edge-arrow" points="${l-4},${p-8} ${l+4},${p-8} ${l},${p}" />
|
|
1499
|
-
`)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let
|
|
1500
|
-
`)}function Pt(e,t){let r=
|
|
1501
|
-
`),i=
|
|
1499
|
+
`)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let c=nt(t.root.children,i.id);if(c&&c.type==="decision"&&c.branches){let u=0;for(let s of c.branches){let l=s.children.length;l>0&&o(i,i.children[u]);for(let p=0;p<l-1;p++)o(i.children[u+p],i.children[u+p+1]);u+=l}}}else if(i.containerType==="parallel"||i.containerType==="race")for(let c of i.children)c.children&&c.children.length>0&&a([c]);else a(i.children)}return a(e),r.join(`
|
|
1500
|
+
`)}function Pt(e,t){let r=fn(e.root.children,t.layout,t),o=Math.max(r.width,400),a=Math.max(r.height,300),n=r.nodes.map(l=>At(l,t.showTimings)).join(`
|
|
1501
|
+
`),i=bn(r.nodes,e),c=e.root.name??"Workflow",u=Lt(t.theme),s=_t({wsUrl:t.wsUrl,interactive:t.interactive,timeTravel:t.timeTravel,heatmap:t.heatmap});return`<!DOCTYPE html>
|
|
1502
1502
|
<html lang="en">
|
|
1503
1503
|
<head>
|
|
1504
1504
|
<meta charset="UTF-8">
|
|
1505
1505
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1506
|
-
<title>${ot(
|
|
1506
|
+
<title>${ot(c)} - Workflow Visualizer</title>
|
|
1507
1507
|
<style>${u}</style>
|
|
1508
1508
|
</head>
|
|
1509
1509
|
<body>
|
|
1510
1510
|
<div class="workflow-visualizer">
|
|
1511
1511
|
<header class="wv-header">
|
|
1512
|
-
<h1>${ot(
|
|
1512
|
+
<h1>${ot(c)}</h1>
|
|
1513
1513
|
<div class="wv-controls">
|
|
1514
1514
|
${t.interactive?`
|
|
1515
1515
|
<button id="load-json-btn" class="wv-btn" title="Load workflow state from JSON">Load JSON</button>
|
|
@@ -1599,7 +1599,7 @@ body {
|
|
|
1599
1599
|
<script>
|
|
1600
1600
|
// Check if we have a saved IR in sessionStorage (from Load JSON)
|
|
1601
1601
|
(function() {
|
|
1602
|
-
let initialIR = ${Wt(
|
|
1602
|
+
let initialIR = ${Wt(yn(e))};
|
|
1603
1603
|
try {
|
|
1604
1604
|
const savedIR = sessionStorage.getItem('workflow_ir');
|
|
1605
1605
|
if (savedIR) {
|
|
@@ -1673,34 +1673,34 @@ body {
|
|
|
1673
1673
|
</script>
|
|
1674
1674
|
<script>${s}</script>
|
|
1675
1675
|
</body>
|
|
1676
|
-
</html>`}function ot(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ht(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function
|
|
1677
|
-
`),
|
|
1678
|
-
`).length)}function
|
|
1679
|
-
`),$(ue.showCursor)}function L(){
|
|
1676
|
+
</html>`}function ot(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Ht(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function wn(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function yn(e){if(!e.hooks)return e;let t=e.hooks.onAfterStep instanceof Map?Object.fromEntries(e.hooks.onAfterStep):e.hooks.onAfterStep;return{...e,hooks:{...e.hooks,onAfterStep:t}}}function Wt(e){let t=new WeakSet;return JSON.stringify(e,(o,a)=>{if(typeof a=="bigint")return a.toString();if(o==="error"&&a!==void 0&&a!==null)return String(a);if(typeof a=="object"&&a!==null){if(t.has(a))return"[Circular]";t.add(a)}return a}).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}var Ft={interactive:!0,timeTravel:!0,heatmap:!0,animationDuration:200,theme:"auto",layout:"TB"};function Ut(){return{name:"html",supportsLive:!0,render(e,t){let r={...t,...Ft,...t};return Pt(e,r)}}}function zt(e,t={}){let r={showTimings:!0,showKeys:!1,colors:{pending:"#6c757d",running:"#ffc107",success:"#198754",error:"#dc3545",aborted:"#6c757d",cached:"#0dcaf0",skipped:"#adb5bd"},...Ft,...t};return Pt(e,r)}var ue={clearToEnd:"\x1B[J",cursorUp:e=>`\x1B[${e}A`,cursorToStart:"\x1B[G",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",saveCursor:"\x1B[s",restoreCursor:"\x1B[u"};function Kt(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,stream:i=process.stdout,updateInterval:c=100}=e,u=de({detectParallel:r}),s=ae(),l,p={showTimings:o,showKeys:a,terminalWidth:i.columns??80,colors:{...z,...n}},g=!1,h="",w=0,v=null,M=!1;function $(D){i.writable&&i.write(D)}function T(){if(!g)return;let D=y(),k=s.render(D,p);k!==h&&(w>0&&($(ue.cursorUp(w)),$(ue.cursorToStart),$(ue.clearToEnd)),$(k),$(`
|
|
1677
|
+
`),h=k,w=k.split(`
|
|
1678
|
+
`).length)}function I(){g&&(M=!0,v===null&&(v=setTimeout(()=>{v=null,M&&(M=!1,T())},c)))}function S(D){if(D.type==="scope_start"||D.type==="scope_end"){x(D);return}u.handleEvent(D),"workflowName"in D&&typeof D.workflowName=="string"&&(l=D.workflowName),g&&(D.type==="workflow_start"||D.type==="workflow_success"||D.type==="workflow_error"?T():I())}function x(D){u.handleScopeEvent(D),g&&I()}function b(D){u.handleDecisionEvent(D),g&&I()}function y(){let D=u.getIR(),k=t??l??D.root.name;return k&&(D.root.name=k),D}function E(){return s.render(y(),p)}function C(){g||(g=!0,h="",w=0,$(ue.hideCursor),T())}function N(){if(!g)return;g=!1,v!==null&&(clearTimeout(v),v=null);let D=y(),k=s.render(D,p);w>0&&($(ue.cursorUp(w)),$(ue.cursorToStart),$(ue.clearToEnd)),$(k),$(`
|
|
1679
|
+
`),$(ue.showCursor)}function L(){v!==null&&(clearTimeout(v),v=null),M=!1,T()}function P(){u.reset(),h="",w=0}return{handleEvent:S,handleScopeEvent:x,handleDecisionEvent:b,getIR:y,render:E,start:C,stop:N,refresh:L,reset:P}}function jt(e="http://localhost:4747"){let t=`${e.replace(/\/$/,"")}/events`,r=[],o=!1,a=()=>{if(o=!1,r.length===0)return;let n=r;r=[];try{let i=JSON.stringify(n,(c,u)=>typeof u=="bigint"?u.toString():u);fetch(t,{method:"POST",headers:{"content-type":"application/json"},body:i}).catch(()=>{})}catch{}};return n=>{r.push(n),o||(o=!0,queueMicrotask(a))}}function ze(e,t={}){let{condition:r,value:o,name:a,workflowId:n=crypto.randomUUID(),emit:i}=t,c=Date.now(),u,s=[];function l(g,h,w){s.push({label:g,condition:w,taken:h}),h&&(u=g),i?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:g,condition:w,taken:h,ts:Date.now()})}function p(){let g=Date.now()-c;i?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:g})}return i?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:a,ts:c}),{takeBranch:l,end:p,getBranchTaken:()=>u,getBranches:()=>[...s]}}function Vt(e,t,r={}){let o=ze(e,{...r,condition:r.condition??String(t),value:r.value??t}),a=!1;return{...o,condition:t,then:()=>{a||(a=!0,o.takeBranch("if",!0),o.takeBranch("else",!1))},else:()=>{a||(a=!0,o.takeBranch("if",!1),o.takeBranch("else",!0))}}}function Gt(e,t,r={}){let o=ze(e,{...r,condition:r.condition??`switch(${String(t)})`,value:t});return{...o,value:t,case:(a,n)=>{o.takeBranch(`case '${a}'`,n,`value === '${a}'`)},default:a=>{o.takeBranch("default",a)}}}function Yt(e={}){let{maxSnapshots:t=1e3,autoRecord:r=!0,builderOptions:o={}}=e,a=de({detectParallel:!1,...o,enableSnapshots:r,maxSnapshots:t}),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},i=new Set,c=null;function u(){let N=S();for(let L of i)L(N)}function s(){n.snapshots=a.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(N){a.handleEvent(N),n.isRecording&&(s(),u())}function p(N){let L=a.getSnapshots();if(!(N<0||N>=L.length))return n.currentIndex=N,n.snapshots=L,u(),L[N].ir}function g(){return p(n.currentIndex+1)}function h(){return p(n.currentIndex-1)}function w(N=1){let L=a.getSnapshots();if(L.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=L),n.playbackSpeed=N,n.isPlaying=!0,u();let P=()=>{if(!n.isPlaying)return;let D=a.getSnapshots();if(n.currentIndex<D.length-1){let k=D[n.currentIndex],oe=(D[n.currentIndex+1].timestamp-k.timestamp)/n.playbackSpeed;c=setTimeout(()=>{g(),P()},Math.max(16,oe))}else v()};P()}function v(){n.isPlaying=!1,c&&(clearTimeout(c),c=null),u()}function M(){let N=a.getSnapshots();return n.currentIndex>=0&&n.currentIndex<N.length?N[n.currentIndex].ir:a.getIR()}function $(N){return a.getIRAt(N)}function T(){return a.getSnapshots()}function I(N){return a.getSnapshotAt(N)}function S(){return{snapshots:a.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function x(N){return i.add(N),()=>i.delete(N)}function b(){n.isRecording=!0,a.setSnapshotsEnabled(!0),s(),u()}function y(){n.isRecording=!1,a.setSnapshotsEnabled(!1),u()}function E(){v(),a.reset(),a.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function C(){return a}return{handleEvent:l,seek:p,stepForward:g,stepBackward:h,play:w,pause:v,getCurrentIR:M,getIRAt:$,getSnapshots:T,getSnapshotAt:I,getState:S,onStateChange:x,startRecording:b,stopRecording:y,reset:E,getBuilder:C}}function Jt(e,t,r={}){let{title:o=t.workflowName,theme:a,mermaidCdnUrl:n="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"}=r,i=JSON.stringify(t,null,2);return`<!DOCTYPE html>
|
|
1680
1680
|
<html lang="en">
|
|
1681
1681
|
<head>
|
|
1682
1682
|
<meta charset="UTF-8">
|
|
1683
1683
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1684
|
-
<title>${
|
|
1684
|
+
<title>${ke(o)} \u2014 Workflow Diagram</title>
|
|
1685
1685
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
1686
1686
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
1687
1687
|
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=DM+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
1688
1688
|
<script src="${n}"></script>
|
|
1689
1689
|
<style>
|
|
1690
|
-
${
|
|
1690
|
+
${kn()}
|
|
1691
1691
|
</style>
|
|
1692
1692
|
</head>
|
|
1693
1693
|
<body>
|
|
1694
1694
|
<header>
|
|
1695
1695
|
<div class="header-left">
|
|
1696
|
-
<h1>${
|
|
1697
|
-
${t.description?`<p class="description">${
|
|
1696
|
+
<h1>${ke(o)}</h1>
|
|
1697
|
+
${t.description?`<p class="description">${ke(t.description)}</p>`:""}
|
|
1698
1698
|
</div>
|
|
1699
1699
|
<div class="header-right">
|
|
1700
1700
|
<span class="badge">${t.stats.totalSteps} steps</span>
|
|
1701
1701
|
${t.stats.conditionalCount>0?`<span class="badge">${t.stats.conditionalCount} conditions</span>`:""}
|
|
1702
1702
|
${t.stats.parallelCount>0?`<span class="badge">${t.stats.parallelCount} parallel</span>`:""}
|
|
1703
|
-
<span class="badge file">${
|
|
1703
|
+
<span class="badge file">${ke(t.filePath)}</span>
|
|
1704
1704
|
<div class="theme-picker">
|
|
1705
1705
|
<button id="theme-btn" aria-label="Change theme" title="Change theme">
|
|
1706
1706
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="6" stroke="currentColor" stroke-width="1.5"/><path d="M8 2a6 6 0 0 1 0 12V2z" fill="currentColor"/></svg>
|
|
@@ -1741,7 +1741,7 @@ ${e}
|
|
|
1741
1741
|
${vn()}
|
|
1742
1742
|
</script>
|
|
1743
1743
|
</body>
|
|
1744
|
-
</html>`}function
|
|
1744
|
+
</html>`}function kn(){return`
|
|
1745
1745
|
/* ================================================================
|
|
1746
1746
|
Theme Definitions \u2014 CSS custom properties per theme
|
|
1747
1747
|
================================================================ */
|
|
@@ -2649,5 +2649,5 @@ ${vn()}
|
|
|
2649
2649
|
var initialTheme = resolveTheme();
|
|
2650
2650
|
applyTheme(initialTheme);
|
|
2651
2651
|
})();
|
|
2652
|
-
`}function
|
|
2652
|
+
`}function ke(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Ke(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,export:i}=e,c=de({detectParallel:r}),u=new Set,s,l=ae(),p=ie(),g=Re(),h=me(),w={showTimings:o,showKeys:a,terminalWidth:process.stdout?.columns??80,colors:{...z,...n}};function v(){if(u.size>0){let k=I();for(let O of u)O(k)}}function M(k){if(k.type==="scope_start"||k.type==="scope_end"){$(k);return}c.handleEvent(k),"workflowName"in k&&typeof k.workflowName=="string"&&(s=k.workflowName),v()}function $(k){c.handleScopeEvent(k),v()}function T(k){c.handleDecisionEvent(k),v()}function I(){let k=c.getIR(),O=t??s??k.root.name;return O&&(k.root.name=O),k}function S(){let k=I();return l.render(k,w)}function x(k){let O=I();switch(k){case"ascii":return l.render(O,w);case"mermaid":return p.render(O,w);case"json":{let q=O.hooks?{...O,hooks:{...O.hooks,onAfterStep:O.hooks.onAfterStep instanceof Map?Object.fromEntries(O.hooks.onAfterStep):O.hooks.onAfterStep??{}}}:O;return JSON.stringify(q,(at,ve)=>typeof ve=="bigint"?ve.toString():ve,2)}case"logger":return g.render(O,w);case"flowchart":return h.render(O,w);default:throw new Error(`Unknown format: ${k}`)}}function b(){c.reset(),v()}function y(k){return u.add(k),()=>u.delete(k)}function E(k,O){if(k)return k;if(i?.default)return i.default;throw new Error(`${O}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function C(){let k=I();return{kind:"mermaid",source:p.render(k,w)}}function N(k){let O=we(C(),"svg",E(k,"toSvgUrl"),{caller:"toSvgUrl"});if(!O.ok)throw new Error(`toSvgUrl: Export failed - ${O.error}`);return O.value}function L(k){let O=we(C(),"png",E(k,"toPngUrl"),{caller:"toPngUrl"});if(!O.ok)throw new Error(`toPngUrl: Export failed - ${O.error}`);return O.value}function P(k){let O=we(C(),"pdf",E(k,"toPdfUrl"),{caller:"toPdfUrl"});if(!O.ok)throw new Error(`toPdfUrl: Export failed - ${O.error}`);return O.value}function D(k,O){switch(k){case"svg":return N(O);case"png":return L(O);case"pdf":return P(O);default:return k}}return{handleEvent:M,handleScopeEvent:$,handleDecisionEvent:T,getIR:I,render:S,renderAs:x,reset:b,onUpdate:y,toUrl:D,toSvgUrl:N,toPngUrl:L,toPdfUrl:P}}function xn(...e){return(t,r)=>{for(let o of e)o(t,r)}}function Sn(e,t={}){let r=Ke(t);for(let o of e)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()}function In(e={}){let t=[];return{handleEvent:r=>{t.push(r)},handleDecisionEvent:r=>{t.push(r)},getEvents:()=>[...t],getWorkflowEvents:()=>t.filter(r=>!r.type.startsWith("decision_")),getDecisionEvents:()=>t.filter(r=>r.type.startsWith("decision_")),clear:()=>{t.length=0},visualize:()=>{let r=Ke(e);for(let o of t)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()},visualizeAs:r=>{let o=Ke(e);for(let a of t)a.type.startsWith("decision_")?o.handleDecisionEvent(a):o.handleEvent(a);return o.renderAs(r)}}}0&&(module.exports={asciiRenderer,buildMermaidInkUrl,combineEventHandlers,createEventCollector,createIRBuilder,createLiveVisualizer,createMermaidInkGenerator,createParallelDetector,createPerformanceAnalyzer,createTimeTravelController,createUrlGenerator,createVisualizer,defaultColorScheme,detectParallelGroups,devEvents,encodeForMermaidInk,escapeHtml,flowchartRenderer,generateInteractiveHTML,getHeatLevel,hasChildren,htmlRenderer,isDecisionNode,isParallelNode,isRaceNode,isSequenceNode,isStepNode,isStreamNode,loggerRenderer,mermaidRenderer,renderToHTML,toExportUrl,toKrokiPngUrl,toKrokiSvgUrl,toKrokiUrl,toMermaidInkJpegUrl,toMermaidInkPdfUrl,toMermaidInkPngUrl,toMermaidInkSvgUrl,toMermaidInkUrl,toMermaidInkWebpUrl,trackDecision,trackIf,trackSwitch,visualizeEvents});
|
|
2653
2653
|
//# sourceMappingURL=index.cjs.map
|