awaitly-visualizer 24.0.0 → 26.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 +12 -12
- 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 +13 -13
- 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 +4 -4
package/dist/devtools.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var gt=Object.create;var fe=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)fe(e,r,{get:t[r],enumerable:!0})},Fe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of kt(t))!bt.call(e,s)&&s!==r&&fe(e,s,{get:()=>t[s],enumerable:!(o=ht(t,s))||o.enumerable});return e};var St=(e,t,r)=>(r=e!=null?gt(wt(e)):{},Fe(t||!e||!e.__esModule?fe(r,"default",{value:e,enumerable:!0}):r,e)),xt=e=>Fe(fe({},"__esModule",{value:!0}),e);var Cr={};yt(Cr,{createConsoleLogger:()=>lt,createDevtools:()=>Pe,quickVisualize:()=>dt,renderDiff:()=>ut});module.exports=xt(Cr);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 me(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(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 Ae(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,s=[],n=[];for(let a=0;a<e.length;a++){let d=e[a];d.type==="step"&&d.startTs!==void 0?s.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:a}):n.push({node:d,originalIndex:a})}if(s.length<=1)return e;s.sort((a,d)=>a.startTs-d.startTs);let i=[],u=[s[0]];for(let a=1;a<s.length;a++){let d=s[a],g=Math.min(...u.map($=>$.startTs)),m=Math.max(...u.map($=>$.endTs)),f=d.startTs<=g+o,k=d.startTs<m;if(!f&&!k){i.push(u),u=[d];continue}let b=k?Math.min(d.endTs,m)-d.startTs:0;f||b>=r?u.push(d):(i.push(u),u=[d])}i.push(u);let l=[];for(let a of i){let d=Math.min(...a.map(g=>g.originalIndex));if(a.length===1)l.push({node:a[0].node,position:d});else{let g=a.map(b=>b.node),m=Math.min(...a.map(b=>b.startTs)),f=Math.max(...a.map(b=>b.endTs)),k={type:"parallel",id:`detected_parallel_${m}`,name:`${g.length} parallel steps`,state:$t(g),mode:"all",children:g,startTs:m,endTs:f,durationMs:f-m};l.push({node:k,position:d})}}for(let{node:a,originalIndex:d}of n)l.push({node:a,position:d});return l.sort((a,d)=>a.position-d.position),l.map(a=>a.node)}function $t(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 Be(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:s=1e3}=e,n=o,i=me(),u,l,a,d="pending",g,m,f=new Map,k=[],b=[],$=new Map,I=[],M=Date.now(),y=M,C={onAfterStep:new Map},D,x=[],T=0;function O(c){return c.stepId??c.stepKey??c.name??me()}function L(c){if(k.length>0){k[k.length-1].children.push(c),y=Date.now();return}if(b.length>0){let h=b[b.length-1];for(let p of h.branches.values())if(p.taken){p.children.push(c),y=Date.now();return}h.pendingChildren.push(c),y=Date.now();return}I.push(c),y=Date.now()}function R(c){if(!n)return;let h=ie(),p=new Map;for(let[v,B]of f)p.set(v,{id:B.id,name:B.name,key:B.key,startTs:B.startTs,retryCount:B.retryCount,timedOut:B.timedOut,timeoutMs:B.timeoutMs});let U={id:`snapshot_${T}`,eventIndex:T,event:structuredClone(c),ir:structuredClone(h),timestamp:Date.now(),activeSteps:p};x.push(U),x.length>s&&x.shift(),T++}function P(c){switch(c.type){case"workflow_start":{I=[],a=void 0,m=void 0,g=void 0,f.clear(),k.length=0,b.length=0,$.clear(),u=c.workflowId,l=c.ts,d="running",M=Date.now(),y=M,D!==void 0&&D!==c.workflowId&&(C.shouldRun=void 0,C.onBeforeStart=void 0),D=c.workflowId,C.onAfterStep=new Map;break}case"workflow_success":d="success",a=c.ts,m=c.durationMs,y=Date.now();break;case"workflow_error":d="error",a=c.ts,g=c.error,m=c.durationMs,y=Date.now();break;case"workflow_cancelled":d="aborted",a=c.ts,m=c.durationMs,y=Date.now();break;case"step_start":{let h=O(c);f.set(h,{id:h,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),y=Date.now();break}case"step_success":{let h=O(c),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};L(U),f.delete(h)}break}case"step_error":{let h=O(c),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};L(U),f.delete(h)}break}case"step_aborted":{let h=O(c),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};L(U),f.delete(h)}break}case"step_cache_hit":{let p={type:"step",id:O(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};L(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let h=O(c),p=f.get(h);p&&(p.timedOut=!0,p.timeoutMs=c.timeoutMs),y=Date.now();break}case"step_retry":{let h=O(c),p=f.get(h);p&&(p.retryCount=(c.attempt??1)-1),y=Date.now();break}case"step_retries_exhausted":y=Date.now();break;case"step_skipped":{let p={type:"step",id:O(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};L(p);break}case"hook_should_run":{let h={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};C.shouldRun=h,D=c.workflowId,y=Date.now();break}case"hook_should_run_error":{let h={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};C.shouldRun=h,D=c.workflowId,y=Date.now();break}case"hook_before_start":{let h={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};C.onBeforeStart=h,D=c.workflowId,y=Date.now();break}case"hook_before_start_error":{let h={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};C.onBeforeStart=h,D=c.workflowId,y=Date.now();break}case"hook_after_step":{let h={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};C.onAfterStep.set(c.stepKey,h),y=Date.now();break}case"hook_after_step_error":{let h={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};C.onAfterStep.set(c.stepKey,h),y=Date.now();break}case"stream_created":{let h=`${c.workflowId}:${c.namespace}`;$.set(h,{id:me(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),y=Date.now();break}case"stream_write":{let h=`${c.workflowId}:${c.namespace}`,p=$.get(h);p&&(p.writeCount++,p.finalPosition=Math.max(p.finalPosition,c.position)),y=Date.now();break}case"stream_read":{let h=`${c.workflowId}:${c.namespace}`,p=$.get(h);p&&p.readCount++,y=Date.now();break}case"stream_close":{let h=`${c.workflowId}:${c.namespace}`,p=$.get(h);if(p){p.streamState="closed",p.finalPosition=c.finalPosition;let U={type:"stream",id:p.id,namespace:p.namespace,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(h)}y=Date.now();break}case"stream_error":{let h=`${c.workflowId}:${c.namespace}`,p=$.get(h);if(p){p.streamState="error";let U={type:"stream",id:p.id,namespace:p.namespace,state:"error",error:c.error,startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(h)}y=Date.now();break}case"stream_backpressure":{let h=`${c.workflowId}:${c.namespace}`,p=$.get(h);p&&(p.backpressureOccurred=!0),y=Date.now();break}}R(c)}function Z(c){if(c.type==="scope_start")k.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),y=Date.now();else if(c.type==="scope_end"){let h=k.findIndex(v=>v.id===c.scopeId);if(h===-1)return;for(;k.length>h+1;){let v=k.pop(),B=v.type==="race"?{type:"race",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:c.ts,children:v.children}:{type:"parallel",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:c.ts,children:v.children,mode:v.type==="allSettled"?"allSettled":"all"};k[k.length-1].children.push(B)}let[p]=k.splice(h,1),U=p.type==="race"?{type:"race",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,winnerId:c.winnerId}:{type:"parallel",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,mode:p.type==="allSettled"?"allSettled":"all"};L(U)}}function re(c){if(c.type==="decision_start")b.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),y=Date.now();else if(c.type==="decision_branch"){let h=b.find(p=>p.id===c.decisionId);if(h){let p=c.branchLabel,U=h.branches.get(p);if(U)U.taken=c.taken,c.taken&&h.pendingChildren.length>0&&(U.children.unshift(...h.pendingChildren),h.pendingChildren=[]);else{let v=c.taken?[...h.pendingChildren]:[];c.taken&&(h.pendingChildren=[]),h.branches.set(p,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:v})}y=Date.now()}}else if(c.type==="decision_end"){let h=b.findIndex(p=>p.id===c.decisionId);if(h!==-1){let[p]=b.splice(h,1),U=b.splice(h),v=Array.from(p.branches.values());v.length===0&&p.pendingChildren.length>0&&(v=[{label:"default",taken:!0,children:[...p.pendingChildren]}]);let B=v.find(pe=>pe.taken)?.label,mt={type:"decision",id:p.id,name:p.name,state:S(v.flatMap(pe=>pe.taken?pe.children:[])),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,condition:p.condition,decisionValue:p.decisionValue,branchTaken:c.branchTaken??B,branches:v};L(mt),b.push(...U),y=Date.now()}}}function S(c){return c.length===0?"success":c.some(v=>v.state==="error")?"error":c.every(v=>v.state==="success"||v.state==="cached")?"success":c.some(v=>v.state==="running")?"running":"pending"}function E(){let c=[...I];for(let[,h]of f)c.push({type:"step",id:h.id,name:h.name,key:h.key,state:"running",startTs:h.startTs,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}});for(let[,h]of $)c.push({type:"stream",id:h.id,namespace:h.namespace,state:"running",startTs:h.startTs,writeCount:h.writeCount,readCount:h.readCount,finalPosition:h.finalPosition,streamState:h.streamState,backpressureOccurred:h.backpressureOccurred});return c}function ie(){let c=E();t&&(c=Ae(c,r));let h={type:"workflow",id:u??i,workflowId:u??i,state:d,startTs:l,endTs:a,durationMs:m,children:c,error:g},p=C.shouldRun!==void 0||C.onBeforeStart!==void 0||C.onAfterStep.size>0;return{root:h,metadata:{createdAt:M,lastUpdatedAt:y},...p&&{hooks:C}}}function Ue(){u=void 0,l=void 0,a=void 0,d="pending",g=void 0,m=void 0,f.clear(),k.length=0,b.length=0,$.clear(),I=[],M=Date.now(),y=M,C={onAfterStep:new Map},D=void 0,x.length=0,T=0}function He(){return[...x]}function ae(c){return x[c]}function pt(c){return x[c]?.ir}function ft(){x.length=0,T=0}return{handleEvent:P,handleScopeEvent:Z,handleDecisionEvent:re,getIR:ie,reset:Ue,getSnapshots:He,getSnapshotAt:ae,getIRAt:pt,clearSnapshots:ft,get hasActiveSteps(){return f.size>0},get state(){return d},get snapshotCount(){return x.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}var he=require("awaitly");function K(e){return e.type==="step"}function Ke(e){return e.type==="sequence"}function X(e){return e.type==="parallel"}function A(e){return e.type==="race"}function J(e){return e.type==="decision"}function Q(e){return e.type==="stream"}var Ne="\x1B[0m",Mt="\x1B[1m",Ge="\x1B[2m",Et="\x1B[31m",It="\x1B[32m",Dt="\x1B[33m",Nt="\x1B[34m",ze="\x1B[90m",Ot="\x1B[37m";function z(e,t){return t?`${t}${e}${Ne}`:e}function ce(e){return`${Mt}${e}${Ne}`}function N(e){return`${Ge}${e}${Ne}`}var ee={pending:Ot,running:Dt,success:It,error:Et,aborted:ze,cached:Nt,skipped:Ge+ze};function vt(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 ue(e,t){let r=vt(e);return z(r,t[e])}function ge(e,t,r){return z(e,r[t])}function Y(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var w={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},ne={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Tt="\x1B[0m";function Ct(e){return e<.2?ne.cold:e<.4?ne.cool:e<.6?ne.neutral:e<.8?ne.warm:e<.95?ne.hot:ne.critical}function je(e,t){let r=Ct(t);return r?`${r}${e}${Tt}`:e}function Wt(e){try{return(0,he.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,he.err)("STRINGIFY_ERROR")}}function Ve(e){let t=Wt(e);return t.ok?t.value:"[unserializable]"}var Ye="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ve(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 u=(i-o)/n,l=Math.floor(u*(Ye.length-1));return Ye[l]}).join("")}function Oe(e,t){let r=Y(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function _t(e,t){if(!t)return w.horizontal.repeat(e);let r=` ${t} `,o=Y(r).length,s=e-o;if(s<4)return w.horizontal.repeat(e);let n=2,i=s-n;return w.horizontal.repeat(n)+r+w.horizontal.repeat(i)}function Xe(e,t,r){let o=e.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),s=e.durationMs!==void 0?N(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=N(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=N(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?N(` error: ${String(e.error)}`):"";return`${o} ${N(t)}${n}${s}${i}`}function Lt(e,t){let r=[];return e.shouldRun&&r.push(Xe(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Xe(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(N("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function de(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...ee,...t.colors},o=Math.max(t.terminalWidth??60,5),s=o-4,n=[],i=e.root.name??"workflow",u=ce(i);if(n.push(`${w.topLeft}${_t(o-2,u)}${w.topRight}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.hooks){let a=Lt(e.hooks,r);for(let d of a)n.push(`${w.vertical} ${Oe(d,s)}${w.vertical}`)}let l=ke(e.root.children,t,r,0,e.hooks);for(let a of l)n.push(`${w.vertical} ${Oe(a,s)}${w.vertical}`);if(n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let a=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",g=`${ge(a,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${w.vertical} ${Oe(g,s)}${w.vertical}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`)}return n.push(`${w.bottomLeft}${w.horizontal.repeat(o-2)}${w.bottomRight}`),n.join(`
|
|
2
|
-
`)}}}function ke(e,t,r,o,s){let n=[];for(let i of e)K(i)?n.push(Te(i,t,r,s)):
|
|
3
|
-
`)}}}function xe(e,t,r,o,s){if(K(e))return Yt(e,t,r,o,s);if(
|
|
4
|
-
`)}var G=11,j=2,se=2,Re=3;function _e(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],s="";for(let n of r)s?s.length+1+n.length<=t?s+=" "+n:(o.push(s),s=n):s=n;if(s&&o.push(s),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function rt(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 or(e,t,r){let o=t.showStartEnd??!0,s=t,n=Math.floor(r/2),i=[],u=0;if(o){let a=$e("start","start",["\u25B6 Start"],"success",n,u);i.push(a),u=a.bottomY+se}for(let a of e.root.children){let d=Me(a,n,u,r-4,t,s);i.push(d.node),u=d.bottomY+se}if(o&&["success","error","aborted"].includes(e.root.state)){let a=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",d=$e("end","end",[a],e.root.state,n,u);i.push(d),u=d.bottomY}return{nodes:i,totalHeight:u+2}}function $e(e,t,r,o,s,n){let i=Math.max(...r.map(d=>Y(d).length)),u=Math.max(G,i+j*2),l=r.length+2,a=s-Math.floor(u/2);return{id:e,type:t,label:r,state:o,x:a,y:n,width:u,height:l,centerX:s,bottomY:n+l-1}}function Me(e,t,r,o,s,n){if(K(e))return sr(e,t,r,o,s,n);if(X(e)||A(e))return ar(e,t,r,o,s,n);if(J(e))return cr(e,t,r,o,s,n);if(Q(e))return ir(e,t,r,o,s,n);let i=$e(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function sr(e,t,r,o,s,n){let i=e.name??e.key??"step",u=rt(e.state),l=[],a=`${u} ${i}`;s.showKeys&&e.key&&e.name&&(a+=` [${e.key}]`);let d=Math.min(o-j*2,40);if(l.push(..._e(a,d)),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&l.push(`${e.retryCount}x retry`),e.timedOut&&l.push("timeout"),n?.showSparklines&&n.timingHistory){let I=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);I&&I.length>1&&l.push(ve(I,8))}let g=Math.max(...l.map(I=>Y(I).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b;if(n?.showHeatmap&&n.heatmapData){let I=e.key??e.name??e.id;b=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(I)}let $={id:e.id,type:"step",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:b!==void 0?{heat:b}:void 0};return{node:$,bottomY:$.bottomY}}function ir(e,t,r,o,s,n){let i=`stream:${e.namespace}`,u=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",l=[],a=`${u} ${i}`,d=Math.min(o-j*2,40);l.push(..._e(a,d)),l.push(`W:${e.writeCount} R:${e.readCount}`),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&l.push("backpressure");let g=Math.max(...l.map($=>Y($).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b={id:e.id,type:"stream",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:b,bottomY:b.bottomY}}function ar(e,t,r,o,s,n){let i=A(e),u=e.name??(i?"race":"parallel"),a=`${i?"\u26A1":"\u2AD8"} ${u}`;if(e.children.length===0){let T=[a,"(not tracked)"],O=$e(e.id,i?"race":"parallel",T,e.state,t,r);return{node:O,bottomY:O.bottomY}}let d=Math.floor((o-Re*(e.children.length-1))/e.children.length),g=[];for(let T of e.children){let O=We(T,Math.max(d,G),s,n);g.push(O.width)}let m=g.reduce((T,O)=>T+O,0)+Re*(e.children.length-1),f=m>o&&e.children.length>1,k=Math.max(G,a.length+j*2),b=3,$=t-Math.floor(k/2),I=r;I+=b,I+=1,I+=1;let M=[];if(f)for(let T=0;T<e.children.length;T++){let O=e.children[T],L=Me(O,t,I,o,s,n);i&&A(e)&&e.winnerId===O.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),M.push(L.node),I=L.bottomY+se}else{let T=t-Math.floor(m/2);for(let O=0;O<e.children.length;O++){let L=e.children[O],R=T+Math.floor(g[O]/2),P=Me(L,R,I,g[O],s,n);i&&A(e)&&e.winnerId===L.id&&(P.node.metadata={...P.node.metadata,isWinner:!0}),M.push(P.node),T+=g[O]+Re}}let y=Math.max(...M.map(T=>T.bottomY)),D=!f&&M.length>1?y+2:y;return{node:{id:e.id,type:i?"race":"parallel",label:[a],state:e.state,x:$,y:r,width:k,height:b,centerX:t,bottomY:D,children:M,metadata:{verticalLayout:f}},bottomY:D}}function cr(e,t,r,o,s,n){let i=e.name??"decision",u=e.condition?` (${e.condition.slice(0,20)})`:"",l=`\u25C7 ${i}${u}`,a=Math.min(o-j*2,40),d=_e(l,a),g=Math.max(...d.map(D=>Y(D).length)),m=Math.max(G,g+j*2),f=d.length+2,k=t-Math.floor(m/2),b=e.branches.find(D=>D.taken),$=b&&b.children.length>0?b:e.branches.find(D=>D.children.length>0);if(!$||$.children.length===0){let D={id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1};return{node:D,bottomY:D.bottomY}}let I=r+f+se,M=[];for(let D of $.children){let x=Me(D,t,I,o,s,n);M.push(x.node),I=x.bottomY+se}let y=M.length>0?M[M.length-1].bottomY:r+f-1;return{node:{id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:y,children:M},bottomY:y}}function We(e,t,r,o){if(K(e)){let s=e.name??e.key??"step",n=rt(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 u=`${n} ${s}`;r.showKeys&&e.key&&e.name&&(u+=` [${e.key}]`);let l=Math.min(t,Math.max(G,u.length+j*2)),a=i+2;return{width:l,height:a}}if(X(e)||A(e)){if(e.children.length===0)return{width:G+4,height:4};let s=Math.floor(t/e.children.length),n=0,i=0;for(let u of e.children){let l=We(u,s,r,o);n+=l.width,i=Math.max(i,l.height)}return n+=Re*(e.children.length-1),{width:Math.max(n,G),height:5+i+2}}if(J(e)){let s=e.branches.find(i=>i.taken),n=0;if(s)for(let i of s.children){let u=We(i,t,r,o);n+=u.height+se}return{width:Math.min(t,30),height:3+n}}if(Q(e)){let s=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(G,s.length+j*2+4)),u=n+2;return{width:i,height:u}}return{width:G,height:3}}function ur(e,t,r){let o={...ee,...r.colors};for(let s=0;s<t.length;s++){let n=t[s],i=s===t.length-1;if(Ee(e,n,o),!i){let u=t[s+1],l=n.centerX,a=n.bottomY+1,d=u.centerX,g=u.y-1;q(e,l,a,g-1),te(e,d,g)}}}function Ee(e,t,r){let o=t.type!=="start",s=t.type!=="end"&&(!t.children||t.children.length===0);rr(e,t.x,t.y,t.width,t.height),o&&_(e,t.centerX,t.y,W.teeUp),(s||t.children&&t.children.length>0)&&_(e,t.centerX,t.y+t.height-1,W.teeDown);let n=t.width-j*2,i=fr(t,r);for(let u=0;u<t.label.length;u++){let l=t.label[u],a=t.x+1+Math.floor((n-Y(l).length)/2),d=t.y+1+u;Qe(e,a,d,l,i)}t.metadata?.isWinner&&Qe(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?dr(e,t,r):lr(e,t,r))}function dr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let u=o[0];q(e,n,s,u.y-2),te(e,u.centerX,u.y-1);for(let l=0;l<o.length;l++){let a=o[l];if(Ee(e,a,r),l<o.length-1){let d=o[l+1];q(e,a.centerX,a.bottomY+1,d.y-2),te(e,d.centerX,d.y-1)}}return}if(o.length===1)q(e,n,s,o[0].y-2),te(e,o[0].centerX,o[0].y-1);else{let u=o.map(d=>d.centerX),l=Math.min(...u),a=Math.max(...u);q(e,n,s,s+1),et(e,s+1,l,a),_(e,n,s+1,W.teeUp);for(let d of o){let g=d.centerX;g===l?_(e,g,s+1,W.topLeft):g===a?_(e,g,s+1,W.topRight):g!==n&&_(e,g,s+1,W.teeDown),q(e,g,s+2,d.y-2),te(e,g,d.y-1)}}for(let u of o)Ee(e,u,r);if(o.length>1){let u=o.map(f=>f.bottomY),l=Math.max(...u),a=l+1,d=o.map(f=>f.centerX),g=Math.min(...d),m=Math.max(...d);for(let f of o)f.bottomY<l&&q(e,f.centerX,f.bottomY+1,a-1);et(e,a,g,m);for(let f of o){let k=f.centerX;k===g?_(e,k,a,W.bottomLeft):k===m?_(e,k,a,W.bottomRight):_(e,k,a,W.teeUp)}_(e,t.centerX,a,W.teeDown),_(e,t.centerX,a+1,W.vertical)}}function lr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=o[0];q(e,t.centerX,s,n.y-2),te(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let u=o[i];if(Ee(e,u,r),i<o.length-1){let l=o[i+1];q(e,u.centerX,u.bottomY+1,l.y-2),te(e,l.centerX,l.y-1)}}}var pr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function fr(e,t){if(e.metadata?.heat!==void 0){let r=we(e.metadata.heat);return Qt[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?pr[e.metadata.streamState]||void 0:t[e.state]||void 0}function le(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:s}=or(e,t,r),n=tr(r,s);return ur(n,o,t),nr(n)}}}function mr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function gr(e){let t=[];function r(o){for(let s of o)if(K(s))t.push(s);else if(Ke(s))r(s.children);else if(X(s)||A(s))r(s.children);else if(J(s))for(let n of s.branches)n.taken&&r(n.children)}return r(e),t}function hr(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 kr(e){let t=0,r=0,o=0,s=0,n=0,i;for(let a of e)a.state==="success"&&t++,a.state==="error"&&r++,a.state==="cached"&&o++,a.state==="skipped"&&s++,a.retryCount!==void 0&&(n+=a.retryCount),a.durationMs!==void 0&&(!i||a.durationMs>i.durationMs)&&(i={name:a.name??a.key??a.id,durationMs:a.durationMs});let u=new Map;for(let a of e){let d=a.metadata?.domain;if(d&&(a.state==="success"||a.state==="error")){let g=u.get(d)??{total:0,errors:0,totalDuration:0};g.total++,a.state==="error"&&g.errors++,a.durationMs!==void 0&&(g.totalDuration+=a.durationMs),u.set(d,g)}}let l;if(u.size>0){l={};for(let[a,d]of u)l[a]={total:d.total,errors:d.errors,avgDurationMs:d.total>0?Math.round(d.totalDuration/d.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:s,totalRetries:n,slowestStep:i,...l&&{byDomain:l}}}function wr(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 s={stepKey:r};o.durationMs!==void 0&&(s.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(s.error=String(o.error)),t.onAfterStep.push(s)}}return t}function br(e,t){let r=e.root,o=gr(r.children),s=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(hr),summary:kr(o)};if(e.hooks){let u=wr(e.hooks);Object.keys(u).length>0&&(i.hooks=u)}if(s){let a=((t.diagramFormat??"ascii")==="flowchart"?le():de()).render(e,t);n&&(a=mr(a)),i.diagram=a}return i}function Le(){return{name:"logger",supportsLive:!1,render(e,t){let o=br(e,t);return JSON.stringify(o)}}}var V=require("awaitly");var nt=St(require("pako"),1),yr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Sr(e){let t;if(yr)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 Ie(e){let r=new TextEncoder().encode(e),o=nt.default.deflate(r);return Sr(o)}var xr="https://kroki.io";function ot(e,t,r,o={}){let s=o.baseUrl??xr,n=Ie(r);return`${s}/${e}/${t}/${n}`}var Rr="https://mermaid.ink";function $r(e){return`pako:${Ie(e)}`}function Mr(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 Er(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 st(e,t,r={}){let o=Mr(r),s=o.baseUrl??Rr,n=$r(t),i=Er(e,o);return`${s}/${e}/${n}${i}`}function Ir(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,V.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,V.err)("UNSUPPORTED_FORMAT"):(0,V.ok)(void 0):(0,V.err)("UNSUPPORTED_FORMAT")}function Dr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Nr(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function De(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND")}}let s=Ir(r.provider,e.kind,t);if(!s.ok)return s;switch(r.provider){case"kroki":return(0,V.ok)(ot(Dr(e.kind),t,e.source,r));case"mermaid-ink":return(0,V.ok)(st(Nr(t),e.source,r));default:{let n=r;return(0,V.err)("UNKNOWN_PROVIDER")}}}function it(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:s=!1,colors:n,export:i}=e,u=Be({detectParallel:r}),l=new Set,a,d=de(),g=Ce(),m=Le(),f=le(),k={showTimings:o,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...ee,...n}};function b(){if(l.size>0){let S=y();for(let E of l)E(S)}}function $(S){if(S.type==="scope_start"||S.type==="scope_end"){I(S);return}u.handleEvent(S),"workflowName"in S&&typeof S.workflowName=="string"&&(a=S.workflowName),b()}function I(S){u.handleScopeEvent(S),b()}function M(S){u.handleDecisionEvent(S),b()}function y(){let S=u.getIR(),E=t??a??S.root.name;return E&&(S.root.name=E),S}function C(){let S=y();return d.render(S,k)}function D(S){let E=y();switch(S){case"ascii":return d.render(E,k);case"mermaid":return g.render(E,k);case"json":{let ie=E.hooks?{...E,hooks:{...E.hooks,onAfterStep:E.hooks.onAfterStep instanceof Map?Object.fromEntries(E.hooks.onAfterStep):E.hooks.onAfterStep??{}}}:E;return JSON.stringify(ie,(He,ae)=>typeof ae=="bigint"?ae.toString():ae,2)}case"logger":return m.render(E,k);case"flowchart":return f.render(E,k);default:throw new Error(`Unknown format: ${S}`)}}function x(){u.reset(),b()}function T(S){return l.add(S),()=>l.delete(S)}function O(S,E){if(S)return S;if(i?.default)return i.default;throw new Error(`${E}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function L(){let S=y();return{kind:"mermaid",source:g.render(S,k)}}function R(S){let E=De(L(),"svg",O(S,"toSvgUrl"),{caller:"toSvgUrl"});if(!E.ok)throw new Error(`toSvgUrl: Export failed - ${E.error}`);return E.value}function P(S){let E=De(L(),"png",O(S,"toPngUrl"),{caller:"toPngUrl"});if(!E.ok)throw new Error(`toPngUrl: Export failed - ${E.error}`);return E.value}function Z(S){let E=De(L(),"pdf",O(S,"toPdfUrl"),{caller:"toPdfUrl"});if(!E.ok)throw new Error(`toPdfUrl: Export failed - ${E.error}`);return E.value}function re(S,E){switch(S){case"svg":return R(E);case"png":return P(E);case"pdf":return Z(E);default:return S}}return{handleEvent:$,handleScopeEvent:I,handleDecisionEvent:M,getIR:y,render:C,renderAs:D,reset:x,onUpdate:T,toUrl:re,toSvgUrl:R,toPngUrl:P,toPdfUrl:Z}}function Pe(e={}){let{logEvents:t=!1,maxHistory:r=10,logger:o=console.log}=e,s=it(e),n=[],i,u=0;function l(R){if(i)for(n.push(i);n.length>r;)n.shift();u=Date.now(),i={id:R,name:e.workflowName,startTime:u,events:[]},s.reset()}function a(R,P){i&&(i.endTime=Date.now(),i.durationMs=i.endTime-i.startTime,i.success=R,i.error=P)}function d(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),R.type==="workflow_start"&&l(R.workflowId),i&&i.events.push(R),s.handleEvent(R),R.type==="workflow_success"?a(!0):R.type==="workflow_error"&&a(!1,R.error)}function g(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),i&&i.events.push(R),s.handleDecisionEvent(R)}function m(){return i}function f(){return[...n]}function k(R){return i?.id===R?i:n.find(P=>P.id===R)}function b(R,P){let Z=k(R),re=k(P);if(!(!Z||!re))return at(Z,re)}function $(){if(!i||n.length===0)return;let R=n[n.length-1];return at(R,i)}function I(){return s.render()}function M(R){return s.renderAs(R)}function y(){return s.renderAs("mermaid")}function C(){let R=D();return vr(R)}function D(){return i?Or(i.events,u):[]}function x(){n.length=0}function T(){i=void 0,s.reset()}function O(R){let P=R?k(R):i;return P?JSON.stringify(P,null,2):"{}"}function L(R){let P=JSON.parse(R);return n.push(P),P}return{handleEvent:d,handleDecisionEvent:g,getCurrentRun:m,getHistory:f,getRun:k,diff:b,diffWithPrevious:$,render:I,renderAs:M,renderMermaid:y,renderTimeline:C,getTimeline:D,clearHistory:x,reset:T,exportRun:O,importRun:L}}function at(e,t){let r=ct(e.events),o=ct(t.events),s=[],n=[],i=[],u=[];for(let[m,f]of o){let k=r.get(m);k?k.status!==f.status?i.push({step:m,type:"status",from:k.status,to:f.status}):k.durationMs!==f.durationMs?i.push({step:m,type:"duration",from:k.durationMs,to:f.durationMs}):u.push(m):s.push({step:m,type:"added",to:f.status})}for(let[m]of r)o.has(m)||n.push({step:m,type:"removed",from:r.get(m)?.status});let l,a=e.success===void 0?"running":e.success?"success":"error",d=t.success===void 0?"running":t.success?"success":"error";a!==d&&(l={from:a,to:d});let g;return e.durationMs!==void 0&&t.durationMs!==void 0&&(g=t.durationMs-e.durationMs),{added:s,removed:n,changed:i,unchanged:u,statusChange:l,durationChange:g}}function ct(e){let t=new Map;for(let r of e)if(r.type==="step_start"){let o=r,s=o.name||o.stepKey||o.stepId;t.set(s,{name:s,key:o.stepKey,status:"running"})}else if(r.type==="step_success"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="success",n.durationMs=o.durationMs)}else if(r.type==="step_error"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="error",n.durationMs=o.durationMs,n.error=o.error)}else if(r.type==="step_cache_hit"){let o=r,s=o.name||o.stepKey;t.set(s,{name:s,key:o.stepKey,status:"cached"})}else if(r.type==="step_skipped"){let o=r,s=o.name||o.stepKey||"unknown";t.set(s,{name:s,key:o.stepKey,status:"skipped"})}return t}function Or(e,t){let r=[],o=new Map;for(let s of e)if(s.type==="step_start"){let n=s,i=n.name||n.stepKey||n.stepId;o.set(i,n.ts),r.push({name:i,key:n.stepKey,startMs:n.ts-t,status:"running"})}else if(s.type==="step_success"){let n=s,i=n.name||n.stepKey||n.stepId,u=r.find(l=>l.name===i&&l.status==="running");u&&(u.endMs=n.ts-t,u.durationMs=n.durationMs,u.status="success")}else if(s.type==="step_error"){let n=s,i=n.name||n.stepKey||n.stepId,u=r.find(l=>l.name===i&&l.status==="running");u&&(u.endMs=n.ts-t,u.durationMs=n.durationMs,u.status="error",u.error=n.error)}else if(s.type==="step_cache_hit"){let n=s,i=n.name||n.stepKey;r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"cached"})}else if(s.type==="step_skipped"){let n=s,i=n.name||n.stepKey||"unknown";r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"skipped"})}return r}function vr(e){if(e.length===0)return"No timeline data";let t=[];t.push("Timeline:"),t.push("\u2500".repeat(60));let r=Math.max(...e.map(s=>s.endMs??s.startMs+100)),o=40;for(let s of e){let n=Math.floor(s.startMs/r*o),i=Math.floor((s.endMs??s.startMs+10)/r*o),u=Math.max(1,i-n),l=Tr(s.status),a=" ".repeat(n)+l.repeat(u),d=s.durationMs!==void 0?`${s.durationMs}ms`:"?";t.push(`${s.name.padEnd(20)} |${a.padEnd(o)}| ${d}`)}return t.push("\u2500".repeat(60)),t.join(`
|
|
5
|
-
`)}function Tr(e){switch(e){case"success":return"\u2588";case"error":return"\u2591";case"running":return"\u2592";case"cached":return"\u2593";case"skipped":return"\xB7";default:return"?"}}function
|
|
1
|
+
"use strict";var gt=Object.create;var fe=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)fe(e,r,{get:t[r],enumerable:!0})},Fe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of kt(t))!bt.call(e,s)&&s!==r&&fe(e,s,{get:()=>t[s],enumerable:!(o=ht(t,s))||o.enumerable});return e};var St=(e,t,r)=>(r=e!=null?gt(wt(e)):{},Fe(t||!e||!e.__esModule?fe(r,"default",{value:e,enumerable:!0}):r,e)),xt=e=>Fe(fe({},"__esModule",{value:!0}),e);var Cr={};yt(Cr,{createConsoleLogger:()=>lt,createDevtools:()=>Pe,quickVisualize:()=>ut,renderDiff:()=>dt});module.exports=xt(Cr);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 me(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(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 Ae(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,s=[],n=[];for(let a=0;a<e.length;a++){let u=e[a];u.type==="step"&&u.startTs!==void 0?s.push({node:u,startTs:u.startTs,endTs:u.endTs??u.startTs+(u.durationMs??0),originalIndex:a}):n.push({node:u,originalIndex:a})}if(s.length<=1)return e;s.sort((a,u)=>a.startTs-u.startTs);let i=[],d=[s[0]];for(let a=1;a<s.length;a++){let u=s[a],h=Math.min(...d.map($=>$.startTs)),g=Math.max(...d.map($=>$.endTs)),m=u.startTs<=h+o,k=u.startTs<g;if(!m&&!k){i.push(d),d=[u];continue}let b=k?Math.min(u.endTs,g)-u.startTs:0;m||b>=r?d.push(u):(i.push(d),d=[u])}i.push(d);let l=[];for(let a of i){let u=Math.min(...a.map(h=>h.originalIndex));if(a.length===1)l.push({node:a[0].node,position:u});else{let h=a.map(b=>b.node),g=Math.min(...a.map(b=>b.startTs)),m=Math.max(...a.map(b=>b.endTs)),k={type:"parallel",id:`detected_parallel_${g}`,name:`${h.length} parallel steps`,state:$t(h),mode:"all",children:h,startTs:g,endTs:m,durationMs:m-g};l.push({node:k,position:u})}}for(let{node:a,originalIndex:u}of n)l.push({node:a,position:u});return l.sort((a,u)=>a.position-u.position),l.map(a=>a.node)}function $t(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 Be(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:s=1e3}=e,n=o,i=me(),d,l,a,u="pending",h,g,m=new Map,k=[],b=[],$=new Map,I=[],M=Date.now(),y=M,C={onAfterStep:new Map},D,x=[],T=0;function O(c){return c.stepId??c.stepKey??c.name??me()}function L(c){if(k.length>0){k[k.length-1].children.push(c),y=Date.now();return}if(b.length>0){let f=b[b.length-1];for(let p of f.branches.values())if(p.taken){p.children.push(c),y=Date.now();return}f.pendingChildren.push(c),y=Date.now();return}I.push(c),y=Date.now()}function R(c){if(!n)return;let f=ie(),p=new Map;for(let[v,B]of m)p.set(v,{id:B.id,name:B.name,key:B.key,startTs:B.startTs,retryCount:B.retryCount,timedOut:B.timedOut,timeoutMs:B.timeoutMs});let U={id:`snapshot_${T}`,eventIndex:T,event:structuredClone(c),ir:structuredClone(f),timestamp:Date.now(),activeSteps:p};x.push(U),x.length>s&&x.shift(),T++}function P(c){switch(c.type){case"workflow_start":{I=[],a=void 0,g=void 0,h=void 0,m.clear(),k.length=0,b.length=0,$.clear(),d=c.workflowId,l=c.ts,u="running",M=Date.now(),y=M,D!==void 0&&D!==c.workflowId&&(C.shouldRun=void 0,C.onBeforeStart=void 0),D=c.workflowId,C.onAfterStep=new Map;break}case"workflow_success":u="success",a=c.ts,g=c.durationMs,y=Date.now();break;case"workflow_error":u="error",a=c.ts,h=c.error,g=c.durationMs,y=Date.now();break;case"workflow_cancelled":u="aborted",a=c.ts,g=c.durationMs,y=Date.now();break;case"step_start":{let f=O(c);m.set(f,{id:f,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),y=Date.now();break}case"step_success":{let f=O(c),p=m.get(f);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};L(U),m.delete(f)}break}case"step_error":{let f=O(c),p=m.get(f);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};L(U),m.delete(f)}break}case"step_aborted":{let f=O(c),p=m.get(f);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};L(U),m.delete(f)}break}case"step_cache_hit":{let p={type:"step",id:O(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};L(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let f=O(c),p=m.get(f);p&&(p.timedOut=!0,p.timeoutMs=c.timeoutMs),y=Date.now();break}case"step_retry":{let f=O(c),p=m.get(f);p&&(p.retryCount=(c.attempt??1)-1),y=Date.now();break}case"step_retries_exhausted":y=Date.now();break;case"step_skipped":{let p={type:"step",id:O(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};L(p);break}case"decision":{let f=c;if(f.phase==="start"){Y({type:"decision_start",workflowId:c.workflowId,decisionId:f.decisionId,name:f.label??f.decisionId,condition:f.label,decisionValue:f.value,ts:f.ts}),Y({type:"decision_branch",workflowId:c.workflowId,decisionId:f.decisionId,branchLabel:"then",condition:f.label,taken:f.branch==="then",ts:f.ts}),Y({type:"decision_branch",workflowId:c.workflowId,decisionId:f.decisionId,branchLabel:"else",taken:f.branch==="else",ts:f.ts});break}if(f.phase==="end"){Y({type:"decision_end",workflowId:c.workflowId,decisionId:f.decisionId,branchTaken:f.branch,ts:f.ts,durationMs:f.durationMs??0});break}let p={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:[]}]};L(p),y=Date.now();break}case"hook_should_run":{let f={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};C.shouldRun=f,D=c.workflowId,y=Date.now();break}case"hook_should_run_error":{let f={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};C.shouldRun=f,D=c.workflowId,y=Date.now();break}case"hook_before_start":{let f={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};C.onBeforeStart=f,D=c.workflowId,y=Date.now();break}case"hook_before_start_error":{let f={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};C.onBeforeStart=f,D=c.workflowId,y=Date.now();break}case"hook_after_step":{let f={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};C.onAfterStep.set(c.stepKey,f),y=Date.now();break}case"hook_after_step_error":{let f={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};C.onAfterStep.set(c.stepKey,f),y=Date.now();break}case"stream_created":{let f=`${c.workflowId}:${c.namespace}`;$.set(f,{id:me(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),y=Date.now();break}case"stream_write":{let f=`${c.workflowId}:${c.namespace}`,p=$.get(f);p&&(p.writeCount++,p.finalPosition=Math.max(p.finalPosition,c.position)),y=Date.now();break}case"stream_read":{let f=`${c.workflowId}:${c.namespace}`,p=$.get(f);p&&p.readCount++,y=Date.now();break}case"stream_close":{let f=`${c.workflowId}:${c.namespace}`,p=$.get(f);if(p){p.streamState="closed",p.finalPosition=c.finalPosition;let U={type:"stream",id:p.id,namespace:p.namespace,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(f)}y=Date.now();break}case"stream_error":{let f=`${c.workflowId}:${c.namespace}`,p=$.get(f);if(p){p.streamState="error";let U={type:"stream",id:p.id,namespace:p.namespace,state:"error",error:c.error,startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(f)}y=Date.now();break}case"stream_backpressure":{let f=`${c.workflowId}:${c.namespace}`,p=$.get(f);p&&(p.backpressureOccurred=!0),y=Date.now();break}}R(c)}function Q(c){if(c.type==="scope_start")k.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),y=Date.now();else if(c.type==="scope_end"){let f=k.findIndex(v=>v.id===c.scopeId);if(f===-1)return;for(;k.length>f+1;){let v=k.pop(),B=v.type==="race"?{type:"race",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:c.ts,children:v.children}:{type:"parallel",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:c.ts,children:v.children,mode:v.type==="allSettled"?"allSettled":"all"};k[k.length-1].children.push(B)}let[p]=k.splice(f,1),U=p.type==="race"?{type:"race",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,winnerId:c.winnerId}:{type:"parallel",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,mode:p.type==="allSettled"?"allSettled":"all"};L(U)}}function Y(c){if(c.type==="decision_start")b.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),y=Date.now();else if(c.type==="decision_branch"){let f=b.find(p=>p.id===c.decisionId);if(f){let p=c.branchLabel,U=f.branches.get(p);if(U)U.taken=c.taken,c.taken&&f.pendingChildren.length>0&&(U.children.unshift(...f.pendingChildren),f.pendingChildren=[]);else{let v=c.taken?[...f.pendingChildren]:[];c.taken&&(f.pendingChildren=[]),f.branches.set(p,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:v})}y=Date.now()}}else if(c.type==="decision_end"){let f=b.findIndex(p=>p.id===c.decisionId);if(f!==-1){let[p]=b.splice(f,1),U=b.splice(f),v=Array.from(p.branches.values());v.length===0&&p.pendingChildren.length>0&&(v=[{label:"default",taken:!0,children:[...p.pendingChildren]}]);let B=v.find(pe=>pe.taken)?.label,mt={type:"decision",id:p.id,name:p.name,state:S(v.flatMap(pe=>pe.taken?pe.children:[])),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,condition:p.condition,decisionValue:p.decisionValue,branchTaken:c.branchTaken??B,branches:v};L(mt),b.push(...U),y=Date.now()}}}function S(c){return c.length===0?"success":c.some(v=>v.state==="error")?"error":c.every(v=>v.state==="success"||v.state==="cached")?"success":c.some(v=>v.state==="running")?"running":"pending"}function E(){let c=[...I];for(let[,f]of m)c.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 $)c.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 c}function ie(){let c=E();t&&(c=Ae(c,r));let f={type:"workflow",id:d??i,workflowId:d??i,state:u,startTs:l,endTs:a,durationMs:g,children:c,error:h},p=C.shouldRun!==void 0||C.onBeforeStart!==void 0||C.onAfterStep.size>0;return{root:f,metadata:{createdAt:M,lastUpdatedAt:y},...p&&{hooks:C}}}function Ue(){d=void 0,l=void 0,a=void 0,u="pending",h=void 0,g=void 0,m.clear(),k.length=0,b.length=0,$.clear(),I=[],M=Date.now(),y=M,C={onAfterStep:new Map},D=void 0,x.length=0,T=0}function He(){return[...x]}function ae(c){return x[c]}function pt(c){return x[c]?.ir}function ft(){x.length=0,T=0}return{handleEvent:P,handleScopeEvent:Q,handleDecisionEvent:Y,getIR:ie,reset:Ue,getSnapshots:He,getSnapshotAt:ae,getIRAt:pt,clearSnapshots:ft,get hasActiveSteps(){return m.size>0},get state(){return u},get snapshotCount(){return x.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}var he=require("awaitly");function K(e){return e.type==="step"}function Ke(e){return e.type==="sequence"}function J(e){return e.type==="parallel"}function A(e){return e.type==="race"}function q(e){return e.type==="decision"}function ee(e){return e.type==="stream"}var Ne="\x1B[0m",Mt="\x1B[1m",Ge="\x1B[2m",Et="\x1B[31m",It="\x1B[32m",Dt="\x1B[33m",Nt="\x1B[34m",ze="\x1B[90m",Ot="\x1B[37m";function z(e,t){return t?`${t}${e}${Ne}`:e}function ce(e){return`${Mt}${e}${Ne}`}function N(e){return`${Ge}${e}${Ne}`}var te={pending:Ot,running:Dt,success:It,error:Et,aborted:ze,cached:Nt,skipped:Ge+ze};function vt(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 de(e,t){let r=vt(e);return z(r,t[e])}function ge(e,t,r){return z(e,r[t])}function X(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var w={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},ne={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Tt="\x1B[0m";function Ct(e){return e<.2?ne.cold:e<.4?ne.cool:e<.6?ne.neutral:e<.8?ne.warm:e<.95?ne.hot:ne.critical}function Ve(e,t){let r=Ct(t);return r?`${r}${e}${Tt}`:e}function Wt(e){try{return(0,he.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,he.err)("STRINGIFY_ERROR")}}function je(e){let t=Wt(e);return t.ok?t.value:"[unserializable]"}var Ye="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ve(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,l=Math.floor(d*(Ye.length-1));return Ye[l]}).join("")}function Oe(e,t){let r=X(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function _t(e,t){if(!t)return w.horizontal.repeat(e);let r=` ${t} `,o=X(r).length,s=e-o;if(s<4)return w.horizontal.repeat(e);let n=2,i=s-n;return w.horizontal.repeat(n)+r+w.horizontal.repeat(i)}function Xe(e,t,r){let o=e.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),s=e.durationMs!==void 0?N(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=N(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=N(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?N(` error: ${String(e.error)}`):"";return`${o} ${N(t)}${n}${s}${i}`}function Lt(e,t){let r=[];return e.shouldRun&&r.push(Xe(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Xe(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(N("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ue(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...te,...t.colors},o=Math.max(t.terminalWidth??60,5),s=o-4,n=[],i=e.root.name??"workflow",d=ce(i);if(n.push(`${w.topLeft}${_t(o-2,d)}${w.topRight}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.hooks){let a=Lt(e.hooks,r);for(let u of a)n.push(`${w.vertical} ${Oe(u,s)}${w.vertical}`)}let l=ke(e.root.children,t,r,0,e.hooks);for(let a of l)n.push(`${w.vertical} ${Oe(a,s)}${w.vertical}`);if(n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let a=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",h=`${ge(a,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${w.vertical} ${Oe(h,s)}${w.vertical}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`)}return n.push(`${w.bottomLeft}${w.horizontal.repeat(o-2)}${w.bottomRight}`),n.join(`
|
|
2
|
+
`)}}}function ke(e,t,r,o,s){let n=[];for(let i of e)K(i)?n.push(Te(i,t,r,s)):J(i)?n.push(...Ut(i,t,r,o,s)):A(i)?n.push(...Ht(i,t,r,o,s)):q(i)?n.push(...Ft(i,t,r,o,s)):ee(i)&&n.push(Pt(i,t,r));return n}function Te(e,t,r,o){let s=de(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,l;d!==void 0?l=Ve(n,d):l=ge(n,e.state,r);let a=`${s} ${l}`;if(t.showKeys&&e.key&&e.name&&(a+=N(` [key: ${e.key}]`)),e.input!==void 0){let h=typeof e.input=="string"?e.input:je(e.input).slice(0,30);a+=N(` [in: ${h}${h.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let h=typeof e.output=="string"?e.output:je(e.output).slice(0,30);a+=N(` [out: ${h}${h.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let h=H(e.durationMs),g=d!==void 0?Ve(`[${h}]`,d):N(`[${h}]`);a+=` ${g}`}if(i.showSparklines&&i.timingHistory){let h=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);h&&h.length>1&&(a+=` ${N(ve(h))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(a+=N(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let h=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";a+=N(` [timeout${h}]`)}let u=e.key??e.id;if(o&&u&&o.onAfterStep.has(u)){let h=o.onAfterStep.get(u),g=h.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),m=h.durationMs!==void 0?N(` ${H(h.durationMs)}`):"";a+=` ${g}${m}`}return a}function Pt(e,t,r){let o=e.streamState==="active"?z("\u27F3",r.running):e.streamState==="closed"?z("\u2713",r.success):z("\u2717",r.error),s=`stream:${e.namespace}`,n=ge(s,e.state,r),i=N(`[W:${e.writeCount} R:${e.readCount}]`),d=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(d+=` ${N(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(d+=N(" [backpressure]")),e.streamState==="closed"&&(d+=N(` pos:${e.finalPosition}`)),d}function Ut(e,t,r,o,s){let n=[],i=" ".repeat(o),d=de(e.state,r),l=e.name??"parallel",a=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${d} ${ce(l)}${a}`),e.children.length===0)n.push(`${i}${w.vertical} ${N("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${N("(wrap each operation with step() to see individual steps)")}`);else for(let u=0;u<e.children.length;u++){let h=e.children[u],m=u===e.children.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`;if(K(h))n.push(`${m} ${Te(h,t,r,s)}`);else{let k=ke([h],t,r,o+1,s);for(let b of k)n.push(`${i}${w.vertical} ${b}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${N(`[${H(e.durationMs)}]`)}`),n}function Ht(e,t,r,o,s){let n=[],i=" ".repeat(o),d=de(e.state,r),l=e.name??"race";if(n.push(`${i}${w.teeRight}\u26A1 ${d} ${ce(l)}`),e.children.length===0)n.push(`${i}${w.vertical} ${N("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${N("(wrap each operation with step() to see individual steps)")}`);else for(let a=0;a<e.children.length;a++){let u=e.children[a],g=a===e.children.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`,k=e.winnerId&&u.id===e.winnerId?N(" (winner)"):"";if(K(u))n.push(`${g} ${Te(u,t,r,s)}${k}`);else{let b=ke([u],t,r,o+1,s);for(let $ of b)n.push(`${i}${w.vertical} ${$}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${N(`[${H(e.durationMs)}]`)}`),n}function Ft(e,t,r,o,s){let n=[],i=" ".repeat(o),d=de(e.state,r),l=e.name??"decision",a=e.condition?N(` (${e.condition})`):"",u=e.decisionValue!==void 0?N(` = ${String(e.decisionValue)}`):"",h=e.branchTaken!==void 0?N(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${d} ${ce(l)}${a}${u}${h}`);for(let g=0;g<e.branches.length;g++){let m=e.branches[g],b=g===e.branches.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`,$=m.taken?"\u2713":"\u2298",I=m.taken?r.success:r.skipped,M=z(`${$} ${m.label}`,I),y=m.condition?N(` (${m.condition})`):"";if(n.push(`${b} ${M}${y}`),m.children.length>0){let C=ke(m.children,t,r,o+1,s);for(let D of C)n.push(`${i}${w.vertical} ${D}`)}else m.taken||n.push(`${i}${w.vertical} ${N("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${N(`[${H(e.durationMs)}]`)}`),n}var Se=require("awaitly");function we(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function At(){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 Bt(){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 Kt(e){return`heat_${e}`}function zt(){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 Gt(e){try{return(0,Se.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,Se.err)("STRINGIFY_ERROR")}}function Je(e){let t=Gt(e);return t.ok?t.value:"[unserializable]"}function Vt(e,t,r){let o;if(e.shouldRun){let s="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)}`:"",l=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${s}[["${i} shouldRun${l}${d}"]]:::${n}`),o=s}if(e.onBeforeStart){let s="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)}`:"",l=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${s}[["${i} onBeforeStart${l}${d}"]]:::${n}`),o&&t.push(` ${o} --> ${s}`),o=s}return{lastHookId:o}}var qe=0,be=new Set,ye=new Set;function oe(e="node"){return`${e}_${++qe}`}function jt(){qe=0,be.clear(),ye.clear()}function F(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function Ze(e){return F(e).replace(/[{}[\]()]/g,"")}function Ce(){return{name:"mermaid",supportsLive:!1,render(e,t){jt();let r=[],o=t;r.push("flowchart TD");let s;e.hooks&&(s=Vt(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),s&&r.push(` ${s} --> ${n}`);let i=n;for(let l of e.root.children){let a=xe(l,t,r,o,e.hooks);r.push(` ${i} --> ${a.entryId}`),i=a.exitId}if(["success","error","aborted"].includes(e.root.state)){let l="finish",a=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",u=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",h=`(("${a} ${u}"))`,g=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${l}${h}${g}`),r.push(` ${i} --> ${l}`)}return r.push(""),r.push(...At()),o.showHeatmap&&r.push(...Bt()),e.hooks&&r.push(...zt()),r.join(`
|
|
3
|
+
`)}}}function xe(e,t,r,o,s){if(K(e))return Yt(e,t,r,o,s);if(J(e))return Xt(e,t,r,o,s);if(A(e))return Jt(e,t,r,o,s);if(q(e))return qt(e,t,r,o,s);if(ee(e))return Zt(e,t,r);let n=oe("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function Yt(e,t,r,o,s){let n=t,i=n.showRetryEdges??!0,d=n.showErrorEdges??!0,l=n.showTimeoutEdges??!0,a=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:oe("step");if(ye.has(a)){let x=2;for(;ye.has(`${a}_${x}`);)x++;a=`${a}_${x}`}ye.add(a);let u=e.name??e.key??"Step",h=t.showKeys&&e.key&&e.name?`${u} [${e.key}]`:u,g=F(h),m=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",k="";switch(e.state){case"success":k="\u2713 ";break;case"error":k="\u2717 ";break;case"cached":k="\u{1F4BE} ";break;case"running":k="\u23F3 ";break;case"skipped":k="\u2298 ";break}let b="";if(e.input!==void 0){let x=typeof e.input=="string"?F(e.input):F(Je(e.input).slice(0,20));b+=`\\nin: ${x}`}if(e.output!==void 0&&e.state==="success"){let x=typeof e.output=="string"?F(e.output):F(Je(e.output).slice(0,20));b+=`\\nout: ${x}`}let $="",I=e.key??e.id;if(s&&I&&s.onAfterStep.has(I)){let x=s.onAfterStep.get(I),T=x.state==="success"?"\u2699":"\u26A0",O=t.showTimings&&x.durationMs!==void 0?` ${H(x.durationMs)}`:"";$=`\\n${T} hook${O}`}let M=(k+g+b+$+m).trim(),y,C=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(C!==void 0){let x=we(C);y=Kt(x)}else y=e.state;let D;switch(e.state){case"error":D=`{{"${M}"}}`;break;case"cached":D=`[("${M}")]`;break;case"skipped":D=`["${M}"]`;break;default:D=`["${M}"]`}if(r.push(` ${a}${D}:::${y}`),i&&e.retryCount!==void 0&&e.retryCount>0){let x=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${a} -.->|"${x}"| ${a}`)}if(d&&e.state==="error"&&e.error!==void 0){let x=`ERR_${a}`,T=F(String(e.error)).slice(0,30);r.push(` ${x}{{"${T}"}}`),r.push(` ${a} -->|error| ${x}`),r.push(` style ${x} fill:#fee2e2,stroke:#dc2626`)}if(l&&e.timedOut){let x=`TO_${a}`,T=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${x}{{"\u23F1 Timeout ${T}"}}`),r.push(` ${a} -.->|timeout| ${x}`),r.push(` style ${x} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:a,exitId:a}}function Xt(e,t,r,o,s){let n=oe("parallel"),i=`${n}_fork`,d=`${n}_join`,l=Ze(e.name??"Parallel"),a=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let g=n,m=F(`${l}${a}`),k="operations not individually tracked",b=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["${m}${b}\\n${k}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["${l}${a}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let u=[];for(let g of e.children){let m=xe(g,t,r,o,s);r.push(` ${i} --> ${m.entryId}`),u.push(m.exitId)}r.push(` ${d}{"\u2713 Join"}`);for(let g of u)r.push(` ${g} --> ${d}`);r.push(" end");let h=e.state;return r.push(` class ${n} ${h}`),{entryId:i,exitId:d}}function Jt(e,t,r,o,s){let n=oe("race"),i=`${n}_start`,d=`${n}_end`,l=Ze(e.name??"Race");if(e.children.length===0){let g=n,m=F(l),k="operations not individually tracked",b=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["\u26A1 ${m}${b}\\n${k}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["\u26A1 ${l}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let a=[],u;for(let g of e.children){let m=xe(g,t,r,o,s),k=e.winnerId===g.id;r.push(` ${i} --> ${m.entryId}`),k&&(u=m.exitId),a.push({exitId:m.exitId,isWinner:k})}r.push(` ${d}(("\u2713 First"))`);for(let{exitId:g,isWinner:m}of a)m&&u?r.push(` ${g} ==>|\u{1F3C6} Winner| ${d}`):e.winnerId?r.push(` ${g} -. cancelled .-> ${d}`):r.push(` ${g} --> ${d}`);r.push(" end");let h=e.state;return r.push(` class ${n} ${h}`),{entryId:i,exitId:d}}function qt(e,t,r,o,s){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:oe("decision");if(be.has(n)){let g=2;for(;be.has(`${n}_${g}`);)g++;n=`${n}_${g}`}be.add(n);let i=F(e.condition??"condition"),d=e.decisionValue!==void 0?` = ${F(String(e.decisionValue)).slice(0,30)}`:"",l=`${i}${d}`.trim();r.push(` ${n}{"${l}"}`);let a=[],u,h=new Set;for(let g of e.branches){let m=`${n}_${g.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(h.has(m)){let M=2;for(;h.has(`${m}_${M}`);)M++;m=`${m}_${M}`}h.add(m);let k=F(g.label),b=g.taken?`${k} \u2713`:`${k} skipped`,$=g.taken?":::success":":::skipped";r.push(` ${m}["${b}"]${$}`);let I=g.condition?`|${F(g.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${I} ${m}`),g.children.length>0){let M=m;for(let y of g.children){let C=xe(y,t,r,o,s);r.push(` ${M} --> ${C.entryId}`),M=C.exitId}a.push(M),g.taken&&(u=M)}else a.push(m),g.taken&&(u=m)}return u?{entryId:n,exitId:u}:{entryId:n,exitId:n}}function Zt(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${oe("")}`,s=`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)}`:"",d=e.backpressureOccurred?"\\nbackpressure":"",l=`${n}stream:${F(e.namespace)}\\n${s}${d}${i}`,a;return e.streamState==="error"?a="streamError":e.streamState==="active"?a="streamActive":a="stream",r.push(` ${o}{{"${l}"}}:::${a}`),{entryId:o,exitId:o}}var W={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"},Qt={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},er="\x1B[0m";function tr(e,t){let r=[],o=[];for(let s=0;s<t;s++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function _(e,t,r,o,s){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,s&&(e.colors[r][t]=s))}function tt(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function rr(e,t,r,o,s){_(e,t,r,W.topLeft);for(let n=1;n<o-1;n++)_(e,t+n,r,W.horizontal);_(e,t+o-1,r,W.topRight);for(let n=1;n<s-1;n++)_(e,t,r+n,W.vertical),_(e,t+o-1,r+n,W.vertical);_(e,t,r+s-1,W.bottomLeft);for(let n=1;n<o-1;n++)_(e,t+n,r+s-1,W.horizontal);_(e,t+o-1,r+s-1,W.bottomRight)}function Qe(e,t,r,o,s){let n=X(o).split("");for(let i=0;i<n.length;i++)_(e,t+i,r,n[i],s)}function Z(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let d=tt(e,t,i);d===W.horizontal?_(e,t,i,W.cross):(d===" "||d===W.vertical)&&_(e,t,i,W.vertical)}}function et(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let d=tt(e,i,t);d===W.vertical?_(e,i,t,W.cross):(d===" "||d===W.horizontal)&&_(e,i,t,W.horizontal)}}function re(e,t,r){_(e,t,r,W.arrowDown)}function nr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let s=0;s<e.width;s++){let n=e.colors[r][s],i=e.cells[r][s];n?o+=n+i+er:o+=i}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
|
|
4
|
+
`)}var G=11,V=2,se=2,Re=3;function _e(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],s="";for(let n of r)s?s.length+1+n.length<=t?s+=" "+n:(o.push(s),s=n):s=n;if(s&&o.push(s),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function rt(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 or(e,t,r){let o=t.showStartEnd??!0,s=t,n=Math.floor(r/2),i=[],d=0;if(o){let a=$e("start","start",["\u25B6 Start"],"success",n,d);i.push(a),d=a.bottomY+se}for(let a of e.root.children){let u=Me(a,n,d,r-4,t,s);i.push(u.node),d=u.bottomY+se}if(o&&["success","error","aborted"].includes(e.root.state)){let a=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",u=$e("end","end",[a],e.root.state,n,d);i.push(u),d=u.bottomY}return{nodes:i,totalHeight:d+2}}function $e(e,t,r,o,s,n){let i=Math.max(...r.map(u=>X(u).length)),d=Math.max(G,i+V*2),l=r.length+2,a=s-Math.floor(d/2);return{id:e,type:t,label:r,state:o,x:a,y:n,width:d,height:l,centerX:s,bottomY:n+l-1}}function Me(e,t,r,o,s,n){if(K(e))return sr(e,t,r,o,s,n);if(J(e)||A(e))return ar(e,t,r,o,s,n);if(q(e))return cr(e,t,r,o,s,n);if(ee(e))return ir(e,t,r,o,s,n);let i=$e(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function sr(e,t,r,o,s,n){let i=e.name??e.key??"step",d=rt(e.state),l=[],a=`${d} ${i}`;s.showKeys&&e.key&&e.name&&(a+=` [${e.key}]`);let u=Math.min(o-V*2,40);if(l.push(..._e(a,u)),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&l.push(`${e.retryCount}x retry`),e.timedOut&&l.push("timeout"),n?.showSparklines&&n.timingHistory){let I=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);I&&I.length>1&&l.push(ve(I,8))}let h=Math.max(...l.map(I=>X(I).length)),g=Math.max(G,h+V*2),m=l.length+2,k=t-Math.floor(g/2),b;if(n?.showHeatmap&&n.heatmapData){let I=e.key??e.name??e.id;b=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(I)}let $={id:e.id,type:"step",label:l,state:e.state,x:k,y:r,width:g,height:m,centerX:t,bottomY:r+m-1,metadata:b!==void 0?{heat:b}:void 0};return{node:$,bottomY:$.bottomY}}function ir(e,t,r,o,s,n){let i=`stream:${e.namespace}`,d=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",l=[],a=`${d} ${i}`,u=Math.min(o-V*2,40);l.push(..._e(a,u)),l.push(`W:${e.writeCount} R:${e.readCount}`),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&l.push("backpressure");let h=Math.max(...l.map($=>X($).length)),g=Math.max(G,h+V*2),m=l.length+2,k=t-Math.floor(g/2),b={id:e.id,type:"stream",label:l,state:e.state,x:k,y:r,width:g,height:m,centerX:t,bottomY:r+m-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:b,bottomY:b.bottomY}}function ar(e,t,r,o,s,n){let i=A(e),d=e.name??(i?"race":"parallel"),a=`${i?"\u26A1":"\u2AD8"} ${d}`;if(e.children.length===0){let T=[a,"(not tracked)"],O=$e(e.id,i?"race":"parallel",T,e.state,t,r);return{node:O,bottomY:O.bottomY}}let u=Math.floor((o-Re*(e.children.length-1))/e.children.length),h=[];for(let T of e.children){let O=We(T,Math.max(u,G),s,n);h.push(O.width)}let g=h.reduce((T,O)=>T+O,0)+Re*(e.children.length-1),m=g>o&&e.children.length>1,k=Math.max(G,a.length+V*2),b=3,$=t-Math.floor(k/2),I=r;I+=b,I+=1,I+=1;let M=[];if(m)for(let T=0;T<e.children.length;T++){let O=e.children[T],L=Me(O,t,I,o,s,n);i&&A(e)&&e.winnerId===O.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),M.push(L.node),I=L.bottomY+se}else{let T=t-Math.floor(g/2);for(let O=0;O<e.children.length;O++){let L=e.children[O],R=T+Math.floor(h[O]/2),P=Me(L,R,I,h[O],s,n);i&&A(e)&&e.winnerId===L.id&&(P.node.metadata={...P.node.metadata,isWinner:!0}),M.push(P.node),T+=h[O]+Re}}let y=Math.max(...M.map(T=>T.bottomY)),D=!m&&M.length>1?y+2:y;return{node:{id:e.id,type:i?"race":"parallel",label:[a],state:e.state,x:$,y:r,width:k,height:b,centerX:t,bottomY:D,children:M,metadata:{verticalLayout:m}},bottomY:D}}function cr(e,t,r,o,s,n){let i=e.name??"decision",d=e.condition?` (${e.condition.slice(0,20)})`:"",l=`\u25C7 ${i}${d}`,a=Math.min(o-V*2,40),u=_e(l,a),h=Math.max(...u.map(D=>X(D).length)),g=Math.max(G,h+V*2),m=u.length+2,k=t-Math.floor(g/2),b=e.branches.find(D=>D.taken),$=b&&b.children.length>0?b:e.branches.find(D=>D.children.length>0);if(!$||$.children.length===0){let D={id:e.id,type:"decision",label:u,state:e.state,x:k,y:r,width:g,height:m,centerX:t,bottomY:r+m-1};return{node:D,bottomY:D.bottomY}}let I=r+m+se,M=[];for(let D of $.children){let x=Me(D,t,I,o,s,n);M.push(x.node),I=x.bottomY+se}let y=M.length>0?M[M.length-1].bottomY:r+m-1;return{node:{id:e.id,type:"decision",label:u,state:e.state,x:k,y:r,width:g,height:m,centerX:t,bottomY:y,children:M},bottomY:y}}function We(e,t,r,o){if(K(e)){let s=e.name??e.key??"step",n=rt(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} ${s}`;r.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let l=Math.min(t,Math.max(G,d.length+V*2)),a=i+2;return{width:l,height:a}}if(J(e)||A(e)){if(e.children.length===0)return{width:G+4,height:4};let s=Math.floor(t/e.children.length),n=0,i=0;for(let d of e.children){let l=We(d,s,r,o);n+=l.width,i=Math.max(i,l.height)}return n+=Re*(e.children.length-1),{width:Math.max(n,G),height:5+i+2}}if(q(e)){let s=e.branches.find(i=>i.taken),n=0;if(s)for(let i of s.children){let d=We(i,t,r,o);n+=d.height+se}return{width:Math.min(t,30),height:3+n}}if(ee(e)){let s=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(G,s.length+V*2+4)),d=n+2;return{width:i,height:d}}return{width:G,height:3}}function dr(e,t,r){let o={...te,...r.colors};for(let s=0;s<t.length;s++){let n=t[s],i=s===t.length-1;if(Ee(e,n,o),!i){let d=t[s+1],l=n.centerX,a=n.bottomY+1,u=d.centerX,h=d.y-1;Z(e,l,a,h-1),re(e,u,h)}}}function Ee(e,t,r){let o=t.type!=="start",s=t.type!=="end"&&(!t.children||t.children.length===0);rr(e,t.x,t.y,t.width,t.height),o&&_(e,t.centerX,t.y,W.teeUp),(s||t.children&&t.children.length>0)&&_(e,t.centerX,t.y+t.height-1,W.teeDown);let n=t.width-V*2,i=fr(t,r);for(let d=0;d<t.label.length;d++){let l=t.label[d],a=t.x+1+Math.floor((n-X(l).length)/2),u=t.y+1+d;Qe(e,a,u,l,i)}t.metadata?.isWinner&&Qe(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?ur(e,t,r):lr(e,t,r))}function ur(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let d=o[0];Z(e,n,s,d.y-2),re(e,d.centerX,d.y-1);for(let l=0;l<o.length;l++){let a=o[l];if(Ee(e,a,r),l<o.length-1){let u=o[l+1];Z(e,a.centerX,a.bottomY+1,u.y-2),re(e,u.centerX,u.y-1)}}return}if(o.length===1)Z(e,n,s,o[0].y-2),re(e,o[0].centerX,o[0].y-1);else{let d=o.map(u=>u.centerX),l=Math.min(...d),a=Math.max(...d);Z(e,n,s,s+1),et(e,s+1,l,a),_(e,n,s+1,W.teeUp);for(let u of o){let h=u.centerX;h===l?_(e,h,s+1,W.topLeft):h===a?_(e,h,s+1,W.topRight):h!==n&&_(e,h,s+1,W.teeDown),Z(e,h,s+2,u.y-2),re(e,h,u.y-1)}}for(let d of o)Ee(e,d,r);if(o.length>1){let d=o.map(m=>m.bottomY),l=Math.max(...d),a=l+1,u=o.map(m=>m.centerX),h=Math.min(...u),g=Math.max(...u);for(let m of o)m.bottomY<l&&Z(e,m.centerX,m.bottomY+1,a-1);et(e,a,h,g);for(let m of o){let k=m.centerX;k===h?_(e,k,a,W.bottomLeft):k===g?_(e,k,a,W.bottomRight):_(e,k,a,W.teeUp)}_(e,t.centerX,a,W.teeDown),_(e,t.centerX,a+1,W.vertical)}}function lr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=o[0];Z(e,t.centerX,s,n.y-2),re(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let d=o[i];if(Ee(e,d,r),i<o.length-1){let l=o[i+1];Z(e,d.centerX,d.bottomY+1,l.y-2),re(e,l.centerX,l.y-1)}}}var pr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function fr(e,t){if(e.metadata?.heat!==void 0){let r=we(e.metadata.heat);return Qt[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?pr[e.metadata.streamState]||void 0:t[e.state]||void 0}function le(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:s}=or(e,t,r),n=tr(r,s);return dr(n,o,t),nr(n)}}}function mr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function gr(e){let t=[];function r(o){for(let s of o)if(K(s))t.push(s);else if(Ke(s))r(s.children);else if(J(s)||A(s))r(s.children);else if(q(s))for(let n of s.branches)n.taken&&r(n.children)}return r(e),t}function hr(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 kr(e){let t=0,r=0,o=0,s=0,n=0,i;for(let a of e)a.state==="success"&&t++,a.state==="error"&&r++,a.state==="cached"&&o++,a.state==="skipped"&&s++,a.retryCount!==void 0&&(n+=a.retryCount),a.durationMs!==void 0&&(!i||a.durationMs>i.durationMs)&&(i={name:a.name??a.key??a.id,durationMs:a.durationMs});let d=new Map;for(let a of e){let u=a.metadata?.domain;if(u&&(a.state==="success"||a.state==="error")){let h=d.get(u)??{total:0,errors:0,totalDuration:0};h.total++,a.state==="error"&&h.errors++,a.durationMs!==void 0&&(h.totalDuration+=a.durationMs),d.set(u,h)}}let l;if(d.size>0){l={};for(let[a,u]of d)l[a]={total:u.total,errors:u.errors,avgDurationMs:u.total>0?Math.round(u.totalDuration/u.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:s,totalRetries:n,slowestStep:i,...l&&{byDomain:l}}}function wr(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 s={stepKey:r};o.durationMs!==void 0&&(s.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(s.error=String(o.error)),t.onAfterStep.push(s)}}return t}function br(e,t){let r=e.root,o=gr(r.children),s=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(hr),summary:kr(o)};if(e.hooks){let d=wr(e.hooks);Object.keys(d).length>0&&(i.hooks=d)}if(s){let a=((t.diagramFormat??"ascii")==="flowchart"?le():ue()).render(e,t);n&&(a=mr(a)),i.diagram=a}return i}function Le(){return{name:"logger",supportsLive:!1,render(e,t){let o=br(e,t);return JSON.stringify(o)}}}var j=require("awaitly");var nt=St(require("pako"),1),yr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Sr(e){let t;if(yr)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 Ie(e){let r=new TextEncoder().encode(e),o=nt.default.deflate(r);return Sr(o)}var xr="https://kroki.io";function ot(e,t,r,o={}){let s=o.baseUrl??xr,n=Ie(r);return`${s}/${e}/${t}/${n}`}var Rr="https://mermaid.ink";function $r(e){return`pako:${Ie(e)}`}function Mr(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 Er(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 st(e,t,r={}){let o=Mr(r),s=o.baseUrl??Rr,n=$r(t),i=Er(e,o);return`${s}/${e}/${n}${i}`}function Ir(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,j.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,j.err)("UNSUPPORTED_FORMAT"):(0,j.ok)(void 0):(0,j.err)("UNSUPPORTED_FORMAT")}function Dr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Nr(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function De(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,j.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,j.err)("UNSUPPORTED_DIAGRAM_KIND")}}let s=Ir(r.provider,e.kind,t);if(!s.ok)return s;switch(r.provider){case"kroki":return(0,j.ok)(ot(Dr(e.kind),t,e.source,r));case"mermaid-ink":return(0,j.ok)(st(Nr(t),e.source,r));default:{let n=r;return(0,j.err)("UNKNOWN_PROVIDER")}}}function it(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:s=!1,colors:n,export:i}=e,d=Be({detectParallel:r}),l=new Set,a,u=ue(),h=Ce(),g=Le(),m=le(),k={showTimings:o,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...te,...n}};function b(){if(l.size>0){let S=y();for(let E of l)E(S)}}function $(S){if(S.type==="scope_start"||S.type==="scope_end"){I(S);return}d.handleEvent(S),"workflowName"in S&&typeof S.workflowName=="string"&&(a=S.workflowName),b()}function I(S){d.handleScopeEvent(S),b()}function M(S){d.handleDecisionEvent(S),b()}function y(){let S=d.getIR(),E=t??a??S.root.name;return E&&(S.root.name=E),S}function C(){let S=y();return u.render(S,k)}function D(S){let E=y();switch(S){case"ascii":return u.render(E,k);case"mermaid":return h.render(E,k);case"json":{let ie=E.hooks?{...E,hooks:{...E.hooks,onAfterStep:E.hooks.onAfterStep instanceof Map?Object.fromEntries(E.hooks.onAfterStep):E.hooks.onAfterStep??{}}}:E;return JSON.stringify(ie,(He,ae)=>typeof ae=="bigint"?ae.toString():ae,2)}case"logger":return g.render(E,k);case"flowchart":return m.render(E,k);default:throw new Error(`Unknown format: ${S}`)}}function x(){d.reset(),b()}function T(S){return l.add(S),()=>l.delete(S)}function O(S,E){if(S)return S;if(i?.default)return i.default;throw new Error(`${E}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function L(){let S=y();return{kind:"mermaid",source:h.render(S,k)}}function R(S){let E=De(L(),"svg",O(S,"toSvgUrl"),{caller:"toSvgUrl"});if(!E.ok)throw new Error(`toSvgUrl: Export failed - ${E.error}`);return E.value}function P(S){let E=De(L(),"png",O(S,"toPngUrl"),{caller:"toPngUrl"});if(!E.ok)throw new Error(`toPngUrl: Export failed - ${E.error}`);return E.value}function Q(S){let E=De(L(),"pdf",O(S,"toPdfUrl"),{caller:"toPdfUrl"});if(!E.ok)throw new Error(`toPdfUrl: Export failed - ${E.error}`);return E.value}function Y(S,E){switch(S){case"svg":return R(E);case"png":return P(E);case"pdf":return Q(E);default:return S}}return{handleEvent:$,handleScopeEvent:I,handleDecisionEvent:M,getIR:y,render:C,renderAs:D,reset:x,onUpdate:T,toUrl:Y,toSvgUrl:R,toPngUrl:P,toPdfUrl:Q}}function Pe(e={}){let{logEvents:t=!1,maxHistory:r=10,logger:o=console.log}=e,s=it(e),n=[],i,d=0;function l(R){if(i)for(n.push(i);n.length>r;)n.shift();d=Date.now(),i={id:R,name:e.workflowName,startTime:d,events:[]},s.reset()}function a(R,P){i&&(i.endTime=Date.now(),i.durationMs=i.endTime-i.startTime,i.success=R,i.error=P)}function u(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),R.type==="workflow_start"&&l(R.workflowId),i&&i.events.push(R),s.handleEvent(R),R.type==="workflow_success"?a(!0):R.type==="workflow_error"&&a(!1,R.error)}function h(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),i&&i.events.push(R),s.handleDecisionEvent(R)}function g(){return i}function m(){return[...n]}function k(R){return i?.id===R?i:n.find(P=>P.id===R)}function b(R,P){let Q=k(R),Y=k(P);if(!(!Q||!Y))return at(Q,Y)}function $(){if(!i||n.length===0)return;let R=n[n.length-1];return at(R,i)}function I(){return s.render()}function M(R){return s.renderAs(R)}function y(){return s.renderAs("mermaid")}function C(){let R=D();return vr(R)}function D(){return i?Or(i.events,d):[]}function x(){n.length=0}function T(){i=void 0,s.reset()}function O(R){let P=R?k(R):i;return P?JSON.stringify(P,null,2):"{}"}function L(R){let P=JSON.parse(R);return n.push(P),P}return{handleEvent:u,handleDecisionEvent:h,getCurrentRun:g,getHistory:m,getRun:k,diff:b,diffWithPrevious:$,render:I,renderAs:M,renderMermaid:y,renderTimeline:C,getTimeline:D,clearHistory:x,reset:T,exportRun:O,importRun:L}}function at(e,t){let r=ct(e.events),o=ct(t.events),s=[],n=[],i=[],d=[];for(let[g,m]of o){let k=r.get(g);k?k.status!==m.status?i.push({step:g,type:"status",from:k.status,to:m.status}):k.durationMs!==m.durationMs?i.push({step:g,type:"duration",from:k.durationMs,to:m.durationMs}):d.push(g):s.push({step:g,type:"added",to:m.status})}for(let[g]of r)o.has(g)||n.push({step:g,type:"removed",from:r.get(g)?.status});let l,a=e.success===void 0?"running":e.success?"success":"error",u=t.success===void 0?"running":t.success?"success":"error";a!==u&&(l={from:a,to:u});let h;return e.durationMs!==void 0&&t.durationMs!==void 0&&(h=t.durationMs-e.durationMs),{added:s,removed:n,changed:i,unchanged:d,statusChange:l,durationChange:h}}function ct(e){let t=new Map;for(let r of e)if(r.type==="step_start"){let o=r,s=o.name||o.stepKey||o.stepId;t.set(s,{name:s,key:o.stepKey,status:"running"})}else if(r.type==="step_success"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="success",n.durationMs=o.durationMs)}else if(r.type==="step_error"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="error",n.durationMs=o.durationMs,n.error=o.error)}else if(r.type==="step_cache_hit"){let o=r,s=o.name||o.stepKey;t.set(s,{name:s,key:o.stepKey,status:"cached"})}else if(r.type==="step_skipped"){let o=r,s=o.name||o.stepKey||"unknown";t.set(s,{name:s,key:o.stepKey,status:"skipped"})}return t}function Or(e,t){let r=[],o=new Map;for(let s of e)if(s.type==="step_start"){let n=s,i=n.name||n.stepKey||n.stepId;o.set(i,n.ts),r.push({name:i,key:n.stepKey,startMs:n.ts-t,status:"running"})}else if(s.type==="step_success"){let n=s,i=n.name||n.stepKey||n.stepId,d=r.find(l=>l.name===i&&l.status==="running");d&&(d.endMs=n.ts-t,d.durationMs=n.durationMs,d.status="success")}else if(s.type==="step_error"){let n=s,i=n.name||n.stepKey||n.stepId,d=r.find(l=>l.name===i&&l.status==="running");d&&(d.endMs=n.ts-t,d.durationMs=n.durationMs,d.status="error",d.error=n.error)}else if(s.type==="step_cache_hit"){let n=s,i=n.name||n.stepKey;r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"cached"})}else if(s.type==="step_skipped"){let n=s,i=n.name||n.stepKey||"unknown";r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"skipped"})}return r}function vr(e){if(e.length===0)return"No timeline data";let t=[];t.push("Timeline:"),t.push("\u2500".repeat(60));let r=Math.max(...e.map(s=>s.endMs??s.startMs+100)),o=40;for(let s of e){let n=Math.floor(s.startMs/r*o),i=Math.floor((s.endMs??s.startMs+10)/r*o),d=Math.max(1,i-n),l=Tr(s.status),a=" ".repeat(n)+l.repeat(d),u=s.durationMs!==void 0?`${s.durationMs}ms`:"?";t.push(`${s.name.padEnd(20)} |${a.padEnd(o)}| ${u}`)}return t.push("\u2500".repeat(60)),t.join(`
|
|
5
|
+
`)}function Tr(e){switch(e){case"success":return"\u2588";case"error":return"\u2591";case"running":return"\u2592";case"cached":return"\u2593";case"skipped":return"\xB7";default:return"?"}}function dt(e){let t=[];if(e.statusChange&&t.push(`Status: ${e.statusChange.from} \u2192 ${e.statusChange.to}`),e.durationChange!==void 0){let r=e.durationChange>=0?"+":"";t.push(`Duration: ${r}${e.durationChange}ms`)}if(e.added.length>0){t.push(`
|
|
6
6
|
Added steps:`);for(let r of e.added)t.push(` + ${r.step}`)}if(e.removed.length>0){t.push(`
|
|
7
7
|
Removed steps:`);for(let r of e.removed)t.push(` - ${r.step}`)}if(e.changed.length>0){t.push(`
|
|
8
8
|
Changed steps:`);for(let r of e.changed)t.push(` ~ ${r.step}: ${r.from} \u2192 ${r.to}`)}return e.unchanged.length>0&&t.push(`
|
|
9
9
|
Unchanged: ${e.unchanged.length} steps`),t.join(`
|
|
10
|
-
`)}function
|
|
10
|
+
`)}function ut(e,t={}){let r=Pe(t);return e(r.handleEvent).then(()=>r.render())}function lt(e={}){let{prefix:t="[workflow]",colors:r=!0}=e,o=r?{reset:"\x1B[0m",dim:"\x1B[2m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"}:{reset:"",dim:"",green:"",red:"",yellow:"",blue:"",cyan:""};return s=>{let n=new Date().toISOString().slice(11,23),i;switch(s.type){case"workflow_start":i=`${o.blue}\u23F5 Workflow started${o.reset}`;break;case"workflow_success":i=`${o.green}\u2713 Workflow completed${o.reset} ${o.dim}(${s.durationMs}ms)${o.reset}`;break;case"workflow_error":i=`${o.red}\u2717 Workflow failed${o.reset}`;break;case"step_start":i=`${o.cyan}\u2192 ${s.name||s.stepKey||s.stepId}${o.reset}`;break;case"step_success":i=`${o.green}\u2713 ${s.name||s.stepKey||s.stepId}${o.reset} ${o.dim}(${s.durationMs}ms)${o.reset}`;break;case"step_error":i=`${o.red}\u2717 ${s.name||s.stepKey||s.stepId}${o.reset}`;break;case"step_cache_hit":i=`${o.yellow}\u26A1 ${s.name||s.stepKey} (cached)${o.reset}`;break;case"step_retry":i=`${o.yellow}\u21BB ${s.name||s.stepKey||s.stepId} retry ${s.attempt}/${s.maxAttempts}${o.reset}`;break;default:i=`${o.dim}${s.type}${o.reset}`}console.log(`${o.dim}${n}${o.reset} ${t} ${i}`)}}0&&(module.exports={createConsoleLogger,createDevtools,quickVisualize,renderDiff});
|
|
11
11
|
//# sourceMappingURL=devtools.cjs.map
|