awaitly-visualizer 20.0.0 → 20.0.2

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.
Files changed (49) hide show
  1. package/binding.gyp +9 -0
  2. package/dist/devtools.cjs +5 -5
  3. package/dist/devtools.cjs.map +1 -1
  4. package/dist/devtools.d.cts +3 -3
  5. package/dist/devtools.d.ts +3 -3
  6. package/dist/devtools.js +5 -5
  7. package/dist/devtools.js.map +1 -1
  8. package/dist/index.browser.cjs +17 -17
  9. package/dist/index.browser.cjs.map +1 -1
  10. package/dist/index.browser.d.cts +4 -4
  11. package/dist/index.browser.d.ts +4 -4
  12. package/dist/index.browser.js +19 -19
  13. package/dist/index.browser.js.map +1 -1
  14. package/dist/index.cjs +20 -20
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +4 -4
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +22 -22
  19. package/dist/index.js.map +1 -1
  20. package/dist/kroki/fetch.cjs.map +1 -1
  21. package/dist/kroki/fetch.d.cts +2 -2
  22. package/dist/kroki/fetch.d.ts +2 -2
  23. package/dist/kroki/fetch.js.map +1 -1
  24. package/dist/notifiers/discord.cjs +2 -2
  25. package/dist/notifiers/discord.cjs.map +1 -1
  26. package/dist/notifiers/discord.d.cts +2 -2
  27. package/dist/notifiers/discord.d.ts +2 -2
  28. package/dist/notifiers/discord.js +2 -2
  29. package/dist/notifiers/discord.js.map +1 -1
  30. package/dist/notifiers/slack.cjs +12 -12
  31. package/dist/notifiers/slack.cjs.map +1 -1
  32. package/dist/notifiers/slack.d.cts +2 -2
  33. package/dist/notifiers/slack.d.ts +2 -2
  34. package/dist/notifiers/slack.js +12 -12
  35. package/dist/notifiers/slack.js.map +1 -1
  36. package/dist/notifiers/webhook.cjs +1 -1
  37. package/dist/notifiers/webhook.cjs.map +1 -1
  38. package/dist/notifiers/webhook.d.cts +2 -2
  39. package/dist/notifiers/webhook.d.ts +2 -2
  40. package/dist/notifiers/webhook.js +2 -2
  41. package/dist/notifiers/webhook.js.map +1 -1
  42. package/dist/{performance-analyzer-MwxDr6ej.d.ts → performance-analyzer-C9WFkUSa.d.cts} +16 -1
  43. package/dist/{performance-analyzer-DyIZZ2rA.d.cts → performance-analyzer-ffmMicjZ.d.ts} +16 -1
  44. package/dist/{types-fuxEig2j.d.ts → types-Bmb5LpD-.d.ts} +1 -1
  45. package/dist/{types-CgO2me2s.d.cts → types-BmktN16n.d.cts} +1 -1
  46. package/dist/{url-BskfOf3W.d.cts → url-CxqaR2K3.d.cts} +6 -1
  47. package/dist/{url-BskfOf3W.d.ts → url-CxqaR2K3.d.ts} +6 -1
  48. package/index.js +1 -0
  49. package/package.json +4 -4
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { WorkflowEvent } from 'awaitly/workflow';
2
2
  export { ScopeType } from 'awaitly/workflow';
3
- import { g as DiagramSource, h as ExportFormat, i as ExportOptions, D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, S as ScopeStartEvent, c as ScopeEndEvent, W as WorkflowIR, O as OutputFormat, V as VisualizerOptions } from './url-BskfOf3W.cjs';
4
- export { A as ActiveStepSnapshot, B as BaseNode, C as ColorScheme, d as DecisionBranch, e as DecisionEvent, f as DecisionNode, E as EnhancedRenderOptions, F as FlowNode, j as FlowchartRenderOptions, H as HTMLRenderOptions, k as HTMLTheme, l as HeatLevel, m as HeatmapData, n as HookExecution, o as HookState, I as IRSnapshot, K as KrokiExportOptions, p as KrokiFormat, L as LayoutDirection, q as LiveVisualizerOptions, M as MermaidInkExportOptions, r as MermaidRenderOptions, N as NodePerformance, P as ParallelNode, R as RaceNode, s as RenderOptions, t as Renderer, u as ScopeEvent, v as SequenceNode, w as ServerMessage, x as StepNode, y as StepSkippedEvent, z as StepState, G as StreamNode, T as TimeTravelState, U as UrlGeneratorOptions, J as VisualizingWorkflowOptions, Q as WebVisualizerMessage, X as WorkflowHooks, Y as WorkflowNode, Z as createUrlGenerator, _ as hasChildren, $ as isDecisionNode, a0 as isParallelNode, a1 as isRaceNode, a2 as isSequenceNode, a3 as isStepNode, a4 as isStreamNode, a5 as toKrokiPngUrl, a6 as toKrokiSvgUrl, a7 as toKrokiUrl } from './url-BskfOf3W.cjs';
5
- export { D as DecisionTracker, H as HookLog, I as IRBuilderOptions, a as IfTracker, L as LiveVisualizer, b as LoggerOutput, c as LoggerRenderOptions, P as ParallelDetectorOptions, d as PerformanceAnalyzer, S as StepLog, e as SwitchTracker, T as TimeTravelController, f as TimeTravelOptions, W as WorkflowRun, g as WorkflowSummary, h as asciiRenderer, i as createIRBuilder, x as createLiveVisualizer, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-DyIZZ2rA.cjs';
6
- export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-CgO2me2s.cjs';
3
+ import { g as DiagramSource, h as ExportFormat, i as ExportOptions, D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, S as ScopeStartEvent, c as ScopeEndEvent, W as WorkflowIR, O as OutputFormat, V as VisualizerOptions } from './url-CxqaR2K3.cjs';
4
+ export { A as ActiveStepSnapshot, B as BaseNode, C as ColorScheme, d as DecisionBranch, e as DecisionEvent, f as DecisionNode, E as EnhancedRenderOptions, F as FlowNode, j as FlowchartRenderOptions, H as HTMLRenderOptions, k as HTMLTheme, l as HeatLevel, m as HeatmapData, n as HookExecution, o as HookState, I as IRSnapshot, K as KrokiExportOptions, p as KrokiFormat, L as LayoutDirection, q as LiveVisualizerOptions, M as MermaidInkExportOptions, r as MermaidRenderOptions, N as NodePerformance, P as ParallelNode, R as RaceNode, s as RenderOptions, t as Renderer, u as ScopeEvent, v as SequenceNode, w as ServerMessage, x as StepNode, y as StepSkippedEvent, z as StepState, G as StreamNode, T as TimeTravelState, U as UrlGeneratorOptions, J as VisualizingWorkflowOptions, Q as WebVisualizerMessage, X as WorkflowHooks, Y as WorkflowNode, Z as createUrlGenerator, _ as hasChildren, $ as isDecisionNode, a0 as isParallelNode, a1 as isRaceNode, a2 as isSequenceNode, a3 as isStepNode, a4 as isStreamNode, a5 as toKrokiPngUrl, a6 as toKrokiSvgUrl, a7 as toKrokiUrl } from './url-CxqaR2K3.cjs';
5
+ export { D as DecisionTracker, H as HookLog, I as IRBuilderOptions, a as IfTracker, L as LiveVisualizer, b as LoggerOutput, c as LoggerRenderOptions, P as ParallelDetectorOptions, d as PerformanceAnalyzer, S as StepLog, e as SwitchTracker, T as TimeTravelController, f as TimeTravelOptions, W as WorkflowRun, g as WorkflowSummary, h as asciiRenderer, i as createIRBuilder, x as createLiveVisualizer, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-C9WFkUSa.cjs';
6
+ export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-BmktN16n.cjs';
7
7
  import { Result } from 'awaitly';
8
8
  import 'awaitly/core';
9
9
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { WorkflowEvent } from 'awaitly/workflow';
2
2
  export { ScopeType } from 'awaitly/workflow';
3
- import { g as DiagramSource, h as ExportFormat, i as ExportOptions, D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, S as ScopeStartEvent, c as ScopeEndEvent, W as WorkflowIR, O as OutputFormat, V as VisualizerOptions } from './url-BskfOf3W.js';
4
- export { A as ActiveStepSnapshot, B as BaseNode, C as ColorScheme, d as DecisionBranch, e as DecisionEvent, f as DecisionNode, E as EnhancedRenderOptions, F as FlowNode, j as FlowchartRenderOptions, H as HTMLRenderOptions, k as HTMLTheme, l as HeatLevel, m as HeatmapData, n as HookExecution, o as HookState, I as IRSnapshot, K as KrokiExportOptions, p as KrokiFormat, L as LayoutDirection, q as LiveVisualizerOptions, M as MermaidInkExportOptions, r as MermaidRenderOptions, N as NodePerformance, P as ParallelNode, R as RaceNode, s as RenderOptions, t as Renderer, u as ScopeEvent, v as SequenceNode, w as ServerMessage, x as StepNode, y as StepSkippedEvent, z as StepState, G as StreamNode, T as TimeTravelState, U as UrlGeneratorOptions, J as VisualizingWorkflowOptions, Q as WebVisualizerMessage, X as WorkflowHooks, Y as WorkflowNode, Z as createUrlGenerator, _ as hasChildren, $ as isDecisionNode, a0 as isParallelNode, a1 as isRaceNode, a2 as isSequenceNode, a3 as isStepNode, a4 as isStreamNode, a5 as toKrokiPngUrl, a6 as toKrokiSvgUrl, a7 as toKrokiUrl } from './url-BskfOf3W.js';
5
- export { D as DecisionTracker, H as HookLog, I as IRBuilderOptions, a as IfTracker, L as LiveVisualizer, b as LoggerOutput, c as LoggerRenderOptions, P as ParallelDetectorOptions, d as PerformanceAnalyzer, S as StepLog, e as SwitchTracker, T as TimeTravelController, f as TimeTravelOptions, W as WorkflowRun, g as WorkflowSummary, h as asciiRenderer, i as createIRBuilder, x as createLiveVisualizer, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-MwxDr6ej.js';
6
- export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-fuxEig2j.js';
3
+ import { g as DiagramSource, h as ExportFormat, i as ExportOptions, D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, S as ScopeStartEvent, c as ScopeEndEvent, W as WorkflowIR, O as OutputFormat, V as VisualizerOptions } from './url-CxqaR2K3.js';
4
+ export { A as ActiveStepSnapshot, B as BaseNode, C as ColorScheme, d as DecisionBranch, e as DecisionEvent, f as DecisionNode, E as EnhancedRenderOptions, F as FlowNode, j as FlowchartRenderOptions, H as HTMLRenderOptions, k as HTMLTheme, l as HeatLevel, m as HeatmapData, n as HookExecution, o as HookState, I as IRSnapshot, K as KrokiExportOptions, p as KrokiFormat, L as LayoutDirection, q as LiveVisualizerOptions, M as MermaidInkExportOptions, r as MermaidRenderOptions, N as NodePerformance, P as ParallelNode, R as RaceNode, s as RenderOptions, t as Renderer, u as ScopeEvent, v as SequenceNode, w as ServerMessage, x as StepNode, y as StepSkippedEvent, z as StepState, G as StreamNode, T as TimeTravelState, U as UrlGeneratorOptions, J as VisualizingWorkflowOptions, Q as WebVisualizerMessage, X as WorkflowHooks, Y as WorkflowNode, Z as createUrlGenerator, _ as hasChildren, $ as isDecisionNode, a0 as isParallelNode, a1 as isRaceNode, a2 as isSequenceNode, a3 as isStepNode, a4 as isStreamNode, a5 as toKrokiPngUrl, a6 as toKrokiSvgUrl, a7 as toKrokiUrl } from './url-CxqaR2K3.js';
5
+ export { D as DecisionTracker, H as HookLog, I as IRBuilderOptions, a as IfTracker, L as LiveVisualizer, b as LoggerOutput, c as LoggerRenderOptions, P as ParallelDetectorOptions, d as PerformanceAnalyzer, S as StepLog, e as SwitchTracker, T as TimeTravelController, f as TimeTravelOptions, W as WorkflowRun, g as WorkflowSummary, h as asciiRenderer, i as createIRBuilder, x as createLiveVisualizer, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-ffmMicjZ.js';
6
+ export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-Bmb5LpD-.js';
7
7
  import { Result } from 'awaitly';
8
8
  import 'awaitly/core';
9
9
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- 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 Re(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Nt(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 Ee(e,t={}){if(Nt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,a=[],n=[];for(let d=0;d<e.length;d++){let l=e[d];l.type==="step"&&l.startTs!==void 0?a.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:d}):n.push({node:l,originalIndex:d})}if(a.length<=1)return e;a.sort((d,l)=>d.startTs-l.startTs);let i=[],s=[a[0]];for(let d=1;d<a.length;d++){let l=a[d],p=Math.min(...s.map(T=>T.startTs)),f=Math.max(...s.map(T=>T.endTs)),m=l.startTs<=p+o,w=l.startTs<f;if(!m&&!w){i.push(s),s=[l];continue}let k=w?Math.min(l.endTs,f)-l.startTs:0;m||k>=r?s.push(l):(i.push(s),s=[l])}i.push(s);let u=[];for(let d of i){let l=Math.min(...d.map(p=>p.originalIndex));if(d.length===1)u.push({node:d[0].node,position:l});else{let p=d.map(k=>k.node),f=Math.min(...d.map(k=>k.startTs)),m=Math.max(...d.map(k=>k.endTs)),w={type:"parallel",id:`detected_parallel_${f}`,name:`${p.length} parallel steps`,state:Ot(p),mode:"all",children:p,startTs:f,endTs:m,durationMs:m-f};u.push({node:w,position:l})}}for(let{node:d,originalIndex:l}of n)u.push({node:d,position:l});return u.sort((d,l)=>d.position-l.position),u.map(d=>d.node)}function Ot(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 Dt(e={}){return{detect:t=>Ee(t,e)}}function ce(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:a=1e3}=e,n=o,i=Re(),s,u,d,l="pending",p,f,m=new Map,w=[],k=[],T=new Map,$=[],M=Date.now(),I=M,S={onAfterStep:new Map},x,g=[],y=0;function E(c){return c.stepId??c.stepKey??c.name??Re()}function C(c){if(w.length>0){w[w.length-1].children.push(c),I=Date.now();return}if(k.length>0){let b=k[k.length-1];for(let h of b.branches.values())if(h.taken){h.children.push(c),I=Date.now();return}b.pendingChildren.push(c),I=Date.now();return}$.push(c),I=Date.now()}function N(c){if(!n)return;let b=J(),h=new Map;for(let[W,q]of m)h.set(W,{id:q.id,name:q.name,key:q.key,startTs:q.startTs,retryCount:q.retryCount,timedOut:q.timedOut,timeoutMs:q.timeoutMs});let F={id:`snapshot_${y}`,eventIndex:y,event:structuredClone(c),ir:structuredClone(b),timestamp:Date.now(),activeSteps:h};g.push(F),g.length>a&&g.shift(),y++}function L(c){switch(c.type){case"workflow_start":{$=[],d=void 0,f=void 0,p=void 0,m.clear(),w.length=0,k.length=0,T.clear(),s=c.workflowId,u=c.ts,l="running",M=Date.now(),I=M,x!==void 0&&x!==c.workflowId&&(S.shouldRun=void 0,S.onBeforeStart=void 0),x=c.workflowId,S.onAfterStep=new Map;break}case"workflow_success":l="success",d=c.ts,f=c.durationMs,I=Date.now();break;case"workflow_error":l="error",d=c.ts,p=c.error,f=c.durationMs,I=Date.now();break;case"workflow_cancelled":l="aborted",d=c.ts,f=c.durationMs,I=Date.now();break;case"step_start":{let b=E(c);m.set(b,{id:b,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1}),I=Date.now();break}case"step_success":{let b=E(c),h=m.get(b);if(h){let F={type:"step",id:h.id,name:h.name,key:h.key,state:"success",startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}};C(F),m.delete(b)}break}case"step_error":{let b=E(c),h=m.get(b);if(h){let F={type:"step",id:h.id,name:h.name,key:h.key,state:"error",startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}};C(F),m.delete(b)}break}case"step_aborted":{let b=E(c),h=m.get(b);if(h){let F={type:"step",id:h.id,name:h.name,key:h.key,state:"aborted",startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}};C(F),m.delete(b)}break}case"step_cache_hit":{let h={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};C(h);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let b=E(c),h=m.get(b);h&&(h.timedOut=!0,h.timeoutMs=c.timeoutMs),I=Date.now();break}case"step_retry":{let b=E(c),h=m.get(b);h&&(h.retryCount=(c.attempt??1)-1),I=Date.now();break}case"step_retries_exhausted":I=Date.now();break;case"step_skipped":{let h={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0};C(h);break}case"hook_should_run":{let b={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.shouldRun=b,x=c.workflowId,I=Date.now();break}case"hook_should_run_error":{let b={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.shouldRun=b,x=c.workflowId,I=Date.now();break}case"hook_before_start":{let b={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.onBeforeStart=b,x=c.workflowId,I=Date.now();break}case"hook_before_start_error":{let b={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.onBeforeStart=b,x=c.workflowId,I=Date.now();break}case"hook_after_step":{let b={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),I=Date.now();break}case"hook_after_step_error":{let b={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),I=Date.now();break}case"stream_created":{let b=`${c.workflowId}:${c.namespace}`;T.set(b,{id:Re(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),I=Date.now();break}case"stream_write":{let b=`${c.workflowId}:${c.namespace}`,h=T.get(b);h&&(h.writeCount++,h.finalPosition=Math.max(h.finalPosition,c.position)),I=Date.now();break}case"stream_read":{let b=`${c.workflowId}:${c.namespace}`,h=T.get(b);h&&h.readCount++,I=Date.now();break}case"stream_close":{let b=`${c.workflowId}:${c.namespace}`,h=T.get(b);if(h){h.streamState="closed",h.finalPosition=c.finalPosition;let F={type:"stream",id:h.id,namespace:h.namespace,state:"success",startTs:h.startTs,endTs:c.ts,durationMs:c.ts-h.startTs,writeCount:h.writeCount,readCount:h.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:h.backpressureOccurred};C(F),T.delete(b)}I=Date.now();break}case"stream_error":{let b=`${c.workflowId}:${c.namespace}`,h=T.get(b);if(h){h.streamState="error";let F={type:"stream",id:h.id,namespace:h.namespace,state:"error",error:c.error,startTs:h.startTs,endTs:c.ts,durationMs:c.ts-h.startTs,writeCount:h.writeCount,readCount:h.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:h.backpressureOccurred};C(F),T.delete(b)}I=Date.now();break}case"stream_backpressure":{let b=`${c.workflowId}:${c.namespace}`,h=T.get(b);h&&(h.backpressureOccurred=!0),I=Date.now();break}}N(c)}function P(c){if(c.type==="scope_start")w.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),I=Date.now();else if(c.type==="scope_end"){let b=w.findIndex(W=>W.id===c.scopeId);if(b===-1)return;for(;w.length>b+1;){let W=w.pop(),q=W.type==="race"?{type:"race",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children}:{type:"parallel",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children,mode:W.type==="allSettled"?"allSettled":"all"};w[w.length-1].children.push(q)}let[h]=w.splice(b,1),F=h.type==="race"?{type:"race",id:h.id,name:h.name,state:v(h.children),startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,children:h.children,winnerId:c.winnerId}:{type:"parallel",id:h.id,name:h.name,state:v(h.children),startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,children:h.children,mode:h.type==="allSettled"?"allSettled":"all"};C(F)}}function D(c){if(c.type==="decision_start")k.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),I=Date.now();else if(c.type==="decision_branch"){let b=k.find(h=>h.id===c.decisionId);if(b){let h=c.branchLabel,F=b.branches.get(h);if(F)F.taken=c.taken,c.taken&&b.pendingChildren.length>0&&(F.children.unshift(...b.pendingChildren),b.pendingChildren=[]);else{let W=c.taken?[...b.pendingChildren]:[];c.taken&&(b.pendingChildren=[]),b.branches.set(h,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:W})}I=Date.now()}}else if(c.type==="decision_end"){let b=k.findIndex(h=>h.id===c.decisionId);if(b!==-1){let[h]=k.splice(b,1),F=k.splice(b),W=Array.from(h.branches.values());W.length===0&&h.pendingChildren.length>0&&(W=[{label:"default",taken:!0,children:[...h.pendingChildren]}]);let q=W.find(Ie=>Ie.taken)?.label,Mt={type:"decision",id:h.id,name:h.name,state:v(W.flatMap(Ie=>Ie.taken?Ie.children:[])),startTs:h.startTs,endTs:c.ts,durationMs:c.durationMs,condition:h.condition,decisionValue:h.decisionValue,branchTaken:c.branchTaken??q,branches:W};C(Mt),k.push(...F),I=Date.now()}}}function v(c){return c.length===0?"success":c.some(W=>W.state==="error")?"error":c.every(W=>W.state==="success"||W.state==="cached")?"success":c.some(W=>W.state==="running")?"running":"pending"}function O(){let c=[...$];for(let[,b]of m)c.push({type:"step",id:b.id,name:b.name,key:b.key,state:"running",startTs:b.startTs,...b.retryCount>0&&{retryCount:b.retryCount},...b.timedOut&&{timedOut:!0,timeoutMs:b.timeoutMs}});for(let[,b]of T)c.push({type:"stream",id:b.id,namespace:b.namespace,state:"running",startTs:b.startTs,writeCount:b.writeCount,readCount:b.readCount,finalPosition:b.finalPosition,streamState:b.streamState,backpressureOccurred:b.backpressureOccurred});return c}function J(){let c=O();t&&(c=Ee(c,r));let b={type:"workflow",id:s??i,workflowId:s??i,state:l,startTs:u,endTs:d,durationMs:f,children:c,error:p},h=S.shouldRun!==void 0||S.onBeforeStart!==void 0||S.onAfterStep.size>0;return{root:b,metadata:{createdAt:M,lastUpdatedAt:I},...h&&{hooks:S}}}function re(){s=void 0,u=void 0,d=void 0,l="pending",p=void 0,f=void 0,m.clear(),w.length=0,k.length=0,T.clear(),$=[],M=Date.now(),I=M,S={onAfterStep:new Map},x=void 0,g.length=0,y=0}function tt(){return[...g]}function be(c){return g[c]}function $t(c){return g[c]?.ir}function Tt(){g.length=0,y=0}return{handleEvent:L,handleScopeEvent:P,handleDecisionEvent:D,getIR:J,reset:re,getSnapshots:tt,getSnapshotAt:be,getIRAt:$t,clearSnapshots:Tt,get hasActiveSteps(){return m.size>0},get state(){return l},get snapshotCount(){return g.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}import{ok as Ht,err as Ft}from"awaitly";function V(e){return e.type==="step"}function rt(e){return e.type==="sequence"}function G(e){return e.type==="parallel"}function z(e){return e.type==="race"}function X(e){return e.type==="decision"}function ne(e){return e.type==="stream"}function wn(e){return"children"in e||e.type==="decision"&&"branches"in e}var Fe="\x1B[0m",Ct="\x1B[1m",ot="\x1B[2m",Lt="\x1B[31m",_t="\x1B[32m",Wt="\x1B[33m",Bt="\x1B[34m",nt="\x1B[90m",At="\x1B[37m";function Z(e,t){return t?`${t}${e}${Fe}`:e}function we(e){return`${Ct}${e}${Fe}`}function _(e){return`${ot}${e}${Fe}`}var K={pending:At,running:Wt,success:_t,error:Lt,aborted:nt,cached:Bt,skipped:ot+nt};function Pt(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 ye(e,t){let r=Pt(e);return Z(r,t[e])}function $e(e,t,r){return Z(e,r[t])}function te(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var R={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},pe={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Ut="\x1B[0m";function zt(e){return e<.2?pe.cold:e<.4?pe.cool:e<.6?pe.neutral:e<.8?pe.warm:e<.95?pe.hot:pe.critical}function at(e,t){let r=zt(t);return r?`${r}${e}${Ut}`:e}function Kt(e){try{return Ht(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return Ft("STRINGIFY_ERROR")}}function it(e){let t=Kt(e);return t.ok?t.value:"[unserializable]"}var st="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ze(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 s=(i-o)/n,u=Math.floor(s*(st.length-1));return st[u]}).join("")}function Ue(e,t){let r=te(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function jt(e,t){if(!t)return R.horizontal.repeat(e);let r=` ${t} `,o=te(r).length,a=e-o;if(a<4)return R.horizontal.repeat(e);let n=2,i=a-n;return R.horizontal.repeat(n)+r+R.horizontal.repeat(i)}function dt(e,t,r){let o=e.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),a=e.durationMs!==void 0?_(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=_(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=_(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?_(` error: ${String(e.error)}`):"";return`${o} ${_(t)}${n}${a}${i}`}function Vt(e,t){let r=[];return e.shouldRun&&r.push(dt(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(dt(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(_("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ae(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...K,...t.colors},o=Math.max(t.terminalWidth??60,5),a=o-4,n=[],i=e.root.name??"workflow",s=we(i);if(n.push(`${R.topLeft}${jt(o-2,s)}${R.topRight}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.hooks){let d=Vt(e.hooks,r);for(let l of d)n.push(`${R.vertical} ${Ue(l,a)}${R.vertical}`)}let u=Te(e.root.children,t,r,0,e.hooks);for(let d of u)n.push(`${R.vertical} ${Ue(d,a)}${R.vertical}`);if(n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let d=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",p=`${$e(d,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${R.vertical} ${Ue(p,a)}${R.vertical}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`)}return n.push(`${R.bottomLeft}${R.horizontal.repeat(o-2)}${R.bottomRight}`),n.join(`
2
- `)}}}function Te(e,t,r,o,a){let n=[];for(let i of e)V(i)?n.push(Ke(i,t,r,a)):G(i)?n.push(...Yt(i,t,r,o,a)):z(i)?n.push(...Jt(i,t,r,o,a)):X(i)?n.push(...qt(i,t,r,o,a)):ne(i)&&n.push(Gt(i,t,r));return n}function Ke(e,t,r,o){let a=ye(e.state,r),n=e.name??e.key??"step",i=t,s=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,u;s!==void 0?u=at(n,s):u=$e(n,e.state,r);let d=`${a} ${u}`;if(t.showKeys&&e.key&&e.name&&(d+=_(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:it(e.input).slice(0,30);d+=_(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:it(e.output).slice(0,30);d+=_(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=H(e.durationMs),f=s!==void 0?at(`[${p}]`,s):_(`[${p}]`);d+=` ${f}`}if(i.showSparklines&&i.timingHistory){let p=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);p&&p.length>1&&(d+=` ${_(ze(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(d+=_(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";d+=_(` [timeout${p}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let p=o.onAfterStep.get(l),f=p.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),m=p.durationMs!==void 0?_(` ${H(p.durationMs)}`):"";d+=` ${f}${m}`}return d}function Gt(e,t,r){let o=e.streamState==="active"?Z("\u27F3",r.running):e.streamState==="closed"?Z("\u2713",r.success):Z("\u2717",r.error),a=`stream:${e.namespace}`,n=$e(a,e.state,r),i=_(`[W:${e.writeCount} R:${e.readCount}]`),s=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(s+=` ${_(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(s+=_(" [backpressure]")),e.streamState==="closed"&&(s+=_(` pos:${e.finalPosition}`)),s}function Yt(e,t,r,o,a){let n=[],i=" ".repeat(o),s=ye(e.state,r),u=e.name??"parallel",d=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${R.teeRight}${R.teeDown}${R.horizontal} ${s} ${we(u)}${d}`),e.children.length===0)n.push(`${i}${R.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${R.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],m=l===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`;if(V(p))n.push(`${m} ${Ke(p,t,r,a)}`);else{let w=Te([p],t,r,o+1,a);for(let k of w)n.push(`${i}${R.vertical} ${k}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Jt(e,t,r,o,a){let n=[],i=" ".repeat(o),s=ye(e.state,r),u=e.name??"race";if(n.push(`${i}${R.teeRight}\u26A1 ${s} ${we(u)}`),e.children.length===0)n.push(`${i}${R.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${R.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let d=0;d<e.children.length;d++){let l=e.children[d],f=d===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,w=e.winnerId&&l.id===e.winnerId?_(" (winner)"):"";if(V(l))n.push(`${f} ${Ke(l,t,r,a)}${w}`);else{let k=Te([l],t,r,o+1,a);for(let T of k)n.push(`${i}${R.vertical} ${T}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function qt(e,t,r,o,a){let n=[],i=" ".repeat(o),s=ye(e.state,r),u=e.name??"decision",d=e.condition?_(` (${e.condition})`):"",l=e.decisionValue!==void 0?_(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?_(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${R.teeRight}${R.teeDown}${R.horizontal} ${s} ${we(u)}${d}${l}${p}`);for(let f=0;f<e.branches.length;f++){let m=e.branches[f],k=f===e.branches.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,T=m.taken?"\u2713":"\u2298",$=m.taken?r.success:r.skipped,M=Z(`${T} ${m.label}`,$),I=m.condition?_(` (${m.condition})`):"";if(n.push(`${k} ${M}${I}`),m.children.length>0){let S=Te(m.children,t,r,o+1,a);for(let x of S)n.push(`${i}${R.vertical} ${x}`)}else m.taken||n.push(`${i}${R.vertical} ${_("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}import{ok as Zt,err as Qt}from"awaitly";function je(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...je(r.children)),"branches"in r)for(let o of r.branches)t.push(...je(o.children));return t}function Me(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function ve(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function Xt(){let e=new Map,t=new Map,r=new Map,o=new Map,a=[];function n(S){return S.stepKey??S.stepId??S.name??"unknown"}function i(S){let x=new Map;for(let g of S)switch(g.type){case"step_start":{let y=n(g);x.set(y,{retried:!1,timedOut:!1});break}case"step_retry":{let y=n(g),E=x.get(y);E&&(E.retried=!0);break}case"step_timeout":{let y=n(g),E=x.get(y);E&&(E.timedOut=!0);break}case"step_success":{let y=n(g),E=x.get(y),C=e.get(y)??[];C.push(g.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,r.set(y,P),x.delete(y);break}case"step_error":{let y=n(g),E=x.get(y),C=e.get(y)??[];C.push(g.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,P.errors++,r.set(y,P),x.delete(y);break}}}function s(S){i(S.events)}function u(S){a.push(S)}function d(S){a.length>0&&(i(a),a=[])}function l(S){let x=e.get(S);if(!x||x.length===0)return;let g=[...x].sort((D,v)=>D-v),E=g.reduce((D,v)=>D+v,0)/g.length,C=g.reduce((D,v)=>D+(v-E)**2,0)/g.length,N=t.get(S)??{retried:0,total:1},L=r.get(S)??{errors:0,total:1},P=o.get(S)??{timedOut:0,total:1};return{nodeId:S,avgDurationMs:E,minDurationMs:g[0],maxDurationMs:g[g.length-1],stdDevMs:Math.sqrt(C),samples:g.length,retryRate:N.total>0?N.retried/N.total:0,timeoutRate:P.total>0?P.timedOut/P.total:0,errorRate:L.total>0?L.errors/L.total:0,percentiles:{p50:Me(g,.5),p90:Me(g,.9),p95:Me(g,.95),p99:Me(g,.99)}}}function p(S){return l(S)}function f(S,x="duration"){let g=new Map,y=je(S.root.children),E=[];for(let v of y){let O=("key"in v?v.key:void 0)??v.id??v.name,J=l(O);if(J){let re;switch(x){case"duration":re=J.avgDurationMs;break;case"retryRate":re=J.retryRate;break;case"errorRate":re=J.errorRate;break}E.push({id:v.id,value:re})}}if(E.length===0)return{heat:g,metric:x,stats:{min:0,max:0,mean:0,threshold:0}};let C=E.map(v=>v.value),N=Math.min(...C),L=Math.max(...C),P=C.reduce((v,O)=>v+O,0)/C.length,D=L-N||1;for(let{id:v,value:O}of E)g.set(v,(O-N)/D);return{heat:g,metric:x,stats:{min:N,max:L,mean:P,threshold:P+(L-P)*.5}}}function m(){let S=new Map;for(let x of e.keys()){let g=l(x);g&&S.set(x,g)}return S}function w(S=10){return[...m().values()].sort((g,y)=>y.avgDurationMs-g.avgDurationMs).slice(0,S)}function k(S=10){return[...m().values()].filter(g=>g.errorRate>0).sort((g,y)=>y.errorRate-g.errorRate).slice(0,S)}function T(S=10){return[...m().values()].filter(g=>g.retryRate>0).sort((g,y)=>y.retryRate-g.retryRate).slice(0,S)}function $(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function M(S){let x=JSON.parse(S);e.clear(),t.clear(),r.clear(),o.clear();for(let[g,y]of Object.entries(x.timingData??{}))e.set(g,y);for(let[g,y]of Object.entries(x.retryData??{}))t.set(g,y);for(let[g,y]of Object.entries(x.errorData??{}))r.set(g,y);for(let[g,y]of Object.entries(x.timeoutData??{}))o.set(g,y)}function I(){e.clear(),t.clear(),r.clear(),o.clear(),a=[]}return{addRun:s,addEvent:u,finalizeRun:d,getNodePerformance:p,getHeatmap:f,getSlowestNodes:w,getErrorProneNodes:k,getRetryProneNodes:T,getAllPerformance:m,exportData:$,importData:M,clear:I}}function er(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function tr(){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 rr(e){return`heat_${e}`}function nr(){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 or(e){try{return Zt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return Qt("STRINGIFY_ERROR")}}function ct(e){let t=or(e);return t.ok?t.value:"[unserializable]"}function ar(e,t,r){let o;if(e.shouldRun){let a="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",i=e.shouldRun.state==="success"?"\u2699":"\u26A0",s=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${a}[["${i} shouldRun${u}${s}"]]:::${n}`),o=a}if(e.onBeforeStart){let a="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",s=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${a}[["${i} onBeforeStart${u}${s}"]]:::${n}`),o&&t.push(` ${o} --> ${a}`),o=a}return{lastHookId:o}}var lt=0,Ne=new Set,Oe=new Set;function me(e="node"){return`${e}_${++lt}`}function ir(){lt=0,Ne.clear(),Oe.clear()}function j(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ut(e){return j(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){ir();let r=[],o=t;r.push("flowchart TD");let a;e.hooks&&(a=ar(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),a&&r.push(` ${a} --> ${n}`);let i=n;for(let u of e.root.children){let d=De(u,t,r,o,e.hooks);r.push(` ${i} --> ${d.entryId}`),i=d.exitId}if(["success","error","aborted"].includes(e.root.state)){let u="finish",d=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",l=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",p=`(("${d} ${l}"))`,f=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${p}${f}`),r.push(` ${i} --> ${u}`)}return r.push(""),r.push(...er()),o.showHeatmap&&r.push(...tr()),e.hooks&&r.push(...nr()),r.join(`
3
- `)}}}function De(e,t,r,o,a){if(V(e))return sr(e,t,r,o,a);if(G(e))return dr(e,t,r,o,a);if(z(e))return cr(e,t,r,o,a);if(X(e))return lr(e,t,r,o,a);if(ne(e))return ur(e,t,r);let n=me("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function sr(e,t,r,o,a){let n=t,i=n.showRetryEdges??!0,s=n.showErrorEdges??!0,u=n.showTimeoutEdges??!0,d=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:me("step");if(Oe.has(d)){let g=2;for(;Oe.has(`${d}_${g}`);)g++;d=`${d}_${g}`}Oe.add(d);let l=e.name??e.key??"Step",p=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,f=j(p),m=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",w="";switch(e.state){case"success":w="\u2713 ";break;case"error":w="\u2717 ";break;case"cached":w="\u{1F4BE} ";break;case"running":w="\u23F3 ";break;case"skipped":w="\u2298 ";break}let k="";if(e.input!==void 0){let g=typeof e.input=="string"?j(e.input):j(ct(e.input).slice(0,20));k+=`\\nin: ${g}`}if(e.output!==void 0&&e.state==="success"){let g=typeof e.output=="string"?j(e.output):j(ct(e.output).slice(0,20));k+=`\\nout: ${g}`}let T="",$=e.key??e.id;if(a&&$&&a.onAfterStep.has($)){let g=a.onAfterStep.get($),y=g.state==="success"?"\u2699":"\u26A0",E=t.showTimings&&g.durationMs!==void 0?` ${H(g.durationMs)}`:"";T=`\\n${y} hook${E}`}let M=(w+f+k+T+m).trim(),I,S=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let g=ve(S);I=rr(g)}else I=e.state;let x;switch(e.state){case"error":x=`{{"${M}"}}`;break;case"cached":x=`[("${M}")]`;break;case"skipped":x=`["${M}"]`;break;default:x=`["${M}"]`}if(r.push(` ${d}${x}:::${I}`),i&&e.retryCount!==void 0&&e.retryCount>0){let g=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${d} -.->|"${g}"| ${d}`)}if(s&&e.state==="error"&&e.error!==void 0){let g=`ERR_${d}`,y=j(String(e.error)).slice(0,30);r.push(` ${g}{{"${y}"}}`),r.push(` ${d} -->|error| ${g}`),r.push(` style ${g} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let g=`TO_${d}`,y=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${g}{{"\u23F1 Timeout ${y}"}}`),r.push(` ${d} -.->|timeout| ${g}`),r.push(` style ${g} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:d,exitId:d}}function dr(e,t,r,o,a){let n=me("parallel"),i=`${n}_fork`,s=`${n}_join`,u=ut(e.name??"Parallel"),d=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let f=n,m=j(`${u}${d}`),w="operations not individually tracked",k=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${f}["${m}${k}\\n${w}"]:::${e.state}`),{entryId:f,exitId:f}}r.push(` subgraph ${n}["${u}${d}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let l=[];for(let f of e.children){let m=De(f,t,r,o,a);r.push(` ${i} --> ${m.entryId}`),l.push(m.exitId)}r.push(` ${s}{"\u2713 Join"}`);for(let f of l)r.push(` ${f} --> ${s}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:s}}function cr(e,t,r,o,a){let n=me("race"),i=`${n}_start`,s=`${n}_end`,u=ut(e.name??"Race");if(e.children.length===0){let f=n,m=j(u),w="operations not individually tracked",k=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${f}["\u26A1 ${m}${k}\\n${w}"]:::${e.state}`),{entryId:f,exitId:f}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let d=[],l;for(let f of e.children){let m=De(f,t,r,o,a),w=e.winnerId===f.id;r.push(` ${i} --> ${m.entryId}`),w&&(l=m.exitId),d.push({exitId:m.exitId,isWinner:w})}r.push(` ${s}(("\u2713 First"))`);for(let{exitId:f,isWinner:m}of d)m&&l?r.push(` ${f} ==>|\u{1F3C6} Winner| ${s}`):e.winnerId?r.push(` ${f} -. cancelled .-> ${s}`):r.push(` ${f} --> ${s}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:s}}function lr(e,t,r,o,a){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:me("decision");if(Ne.has(n)){let f=2;for(;Ne.has(`${n}_${f}`);)f++;n=`${n}_${f}`}Ne.add(n);let i=j(e.condition??"condition"),s=e.decisionValue!==void 0?` = ${j(String(e.decisionValue)).slice(0,30)}`:"",u=`${i}${s}`.trim();r.push(` ${n}{"${u}"}`);let d=[],l,p=new Set;for(let f of e.branches){let m=`${n}_${f.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(p.has(m)){let M=2;for(;p.has(`${m}_${M}`);)M++;m=`${m}_${M}`}p.add(m);let w=j(f.label),k=f.taken?`${w} \u2713`:`${w} skipped`,T=f.taken?":::success":":::skipped";r.push(` ${m}["${k}"]${T}`);let $=f.condition?`|${j(f.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${$} ${m}`),f.children.length>0){let M=m;for(let I of f.children){let S=De(I,t,r,o,a);r.push(` ${M} --> ${S.entryId}`),M=S.exitId}d.push(M),f.taken&&(l=M)}else d.push(m),f.taken&&(l=m)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function ur(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${me("")}`,a=`W:${e.writeCount} R:${e.readCount}`,n="";switch(e.streamState){case"active":n="\u27F3 ";break;case"closed":n="\u2713 ";break;case"error":n="\u2717 ";break}let i=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",s=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${j(e.namespace)}\\n${a}${s}${i}`,d;return e.streamState==="error"?d="streamError":e.streamState==="active"?d="streamActive":d="stream",r.push(` ${o}{{"${u}"}}:::${d}`),{entryId:o,exitId:o}}var B={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},pr={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},mr="\x1B[0m";function fr(e,t){let r=[],o=[];for(let a=0;a<t;a++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function A(e,t,r,o,a){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,a&&(e.colors[r][t]=a))}function ft(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function hr(e,t,r,o,a){A(e,t,r,B.topLeft);for(let n=1;n<o-1;n++)A(e,t+n,r,B.horizontal);A(e,t+o-1,r,B.topRight);for(let n=1;n<a-1;n++)A(e,t,r+n,B.vertical),A(e,t+o-1,r+n,B.vertical);A(e,t,r+a-1,B.bottomLeft);for(let n=1;n<o-1;n++)A(e,t+n,r+a-1,B.horizontal);A(e,t+o-1,r+a-1,B.bottomRight)}function pt(e,t,r,o,a){let n=te(o).split("");for(let i=0;i<n.length;i++)A(e,t+i,r,n[i],a)}function oe(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let s=ft(e,t,i);s===B.horizontal?A(e,t,i,B.cross):(s===" "||s===B.vertical)&&A(e,t,i,B.vertical)}}function mt(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let s=ft(e,i,t);s===B.vertical?A(e,i,t,B.cross):(s===" "||s===B.horizontal)&&A(e,i,t,B.horizontal)}}function le(e,t,r){A(e,t,r,B.arrowDown)}function gr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let a=0;a<e.width;a++){let n=e.colors[r][a],i=e.cells[r][a];n?o+=n+i+mr:o+=i}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
4
- `)}var Q=11,ee=2,fe=2,Ce=3;function Ge(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],a="";for(let n of r)a?a.length+1+n.length<=t?a+=" "+n:(o.push(a),a=n):a=n;if(a&&o.push(a),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function ht(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 br(e,t,r){let o=t.showStartEnd??!0,a=t,n=Math.floor(r/2),i=[],s=0;if(o){let d=Le("start","start",["\u25B6 Start"],"success",n,s);i.push(d),s=d.bottomY+fe}for(let d of e.root.children){let l=_e(d,n,s,r-4,t,a);i.push(l.node),s=l.bottomY+fe}if(o&&["success","error","aborted"].includes(e.root.state)){let d=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",l=Le("end","end",[d],e.root.state,n,s);i.push(l),s=l.bottomY}return{nodes:i,totalHeight:s+2}}function Le(e,t,r,o,a,n){let i=Math.max(...r.map(l=>te(l).length)),s=Math.max(Q,i+ee*2),u=r.length+2,d=a-Math.floor(s/2);return{id:e,type:t,label:r,state:o,x:d,y:n,width:s,height:u,centerX:a,bottomY:n+u-1}}function _e(e,t,r,o,a,n){if(V(e))return wr(e,t,r,o,a,n);if(G(e)||z(e))return vr(e,t,r,o,a,n);if(X(e))return kr(e,t,r,o,a,n);if(ne(e))return yr(e,t,r,o,a,n);let i=Le(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function wr(e,t,r,o,a,n){let i=e.name??e.key??"step",s=ht(e.state),u=[],d=`${s} ${i}`;a.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let l=Math.min(o-ee*2,40);if(u.push(...Ge(d,l)),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let $=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);$&&$.length>1&&u.push(ze($,8))}let p=Math.max(...u.map($=>te($).length)),f=Math.max(Q,p+ee*2),m=u.length+2,w=t-Math.floor(f/2),k;if(n?.showHeatmap&&n.heatmapData){let $=e.key??e.name??e.id;k=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get($)}let T={id:e.id,type:"step",label:u,state:e.state,x:w,y:r,width:f,height:m,centerX:t,bottomY:r+m-1,metadata:k!==void 0?{heat:k}:void 0};return{node:T,bottomY:T.bottomY}}function yr(e,t,r,o,a,n){let i=`stream:${e.namespace}`,s=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],d=`${s} ${i}`,l=Math.min(o-ee*2,40);u.push(...Ge(d,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let p=Math.max(...u.map(T=>te(T).length)),f=Math.max(Q,p+ee*2),m=u.length+2,w=t-Math.floor(f/2),k={id:e.id,type:"stream",label:u,state:e.state,x:w,y:r,width:f,height:m,centerX:t,bottomY:r+m-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:k,bottomY:k.bottomY}}function vr(e,t,r,o,a,n){let i=z(e),s=e.name??(i?"race":"parallel"),d=`${i?"\u26A1":"\u2AD8"} ${s}`;if(e.children.length===0){let y=[d,"(not tracked)"],E=Le(e.id,i?"race":"parallel",y,e.state,t,r);return{node:E,bottomY:E.bottomY}}let l=Math.floor((o-Ce*(e.children.length-1))/e.children.length),p=[];for(let y of e.children){let E=Ve(y,Math.max(l,Q),a,n);p.push(E.width)}let f=p.reduce((y,E)=>y+E,0)+Ce*(e.children.length-1),m=f>o&&e.children.length>1,w=Math.max(Q,d.length+ee*2),k=3,T=t-Math.floor(w/2),$=r;$+=k,$+=1,$+=1;let M=[];if(m)for(let y=0;y<e.children.length;y++){let E=e.children[y],C=_e(E,t,$,o,a,n);i&&z(e)&&e.winnerId===E.id&&(C.node.metadata={...C.node.metadata,isWinner:!0}),M.push(C.node),$=C.bottomY+fe}else{let y=t-Math.floor(f/2);for(let E=0;E<e.children.length;E++){let C=e.children[E],N=y+Math.floor(p[E]/2),L=_e(C,N,$,p[E],a,n);i&&z(e)&&e.winnerId===C.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),M.push(L.node),y+=p[E]+Ce}}let I=Math.max(...M.map(y=>y.bottomY)),x=!m&&M.length>1?I+2:I;return{node:{id:e.id,type:i?"race":"parallel",label:[d],state:e.state,x:T,y:r,width:w,height:k,centerX:t,bottomY:x,children:M,metadata:{verticalLayout:m}},bottomY:x}}function kr(e,t,r,o,a,n){let i=e.name??"decision",s=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${i}${s}`,d=Math.min(o-ee*2,40),l=Ge(u,d),p=Math.max(...l.map(x=>te(x).length)),f=Math.max(Q,p+ee*2),m=l.length+2,w=t-Math.floor(f/2),k=e.branches.find(x=>x.taken),T=k&&k.children.length>0?k:e.branches.find(x=>x.children.length>0);if(!T||T.children.length===0){let x={id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:f,height:m,centerX:t,bottomY:r+m-1};return{node:x,bottomY:x.bottomY}}let $=r+m+fe,M=[];for(let x of T.children){let g=_e(x,t,$,o,a,n);M.push(g.node),$=g.bottomY+fe}let I=M.length>0?M[M.length-1].bottomY:r+m-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:f,height:m,centerX:t,bottomY:I,children:M},bottomY:I}}function Ve(e,t,r,o){if(V(e)){let a=e.name??e.key??"step",n=ht(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 s=`${n} ${a}`;r.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let u=Math.min(t,Math.max(Q,s.length+ee*2)),d=i+2;return{width:u,height:d}}if(G(e)||z(e)){if(e.children.length===0)return{width:Q+4,height:4};let a=Math.floor(t/e.children.length),n=0,i=0;for(let s of e.children){let u=Ve(s,a,r,o);n+=u.width,i=Math.max(i,u.height)}return n+=Ce*(e.children.length-1),{width:Math.max(n,Q),height:5+i+2}}if(X(e)){let a=e.branches.find(i=>i.taken),n=0;if(a)for(let i of a.children){let s=Ve(i,t,r,o);n+=s.height+fe}return{width:Math.min(t,30),height:3+n}}if(ne(e)){let a=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(Q,a.length+ee*2+4)),s=n+2;return{width:i,height:s}}return{width:Q,height:3}}function xr(e,t,r){let o={...K,...r.colors};for(let a=0;a<t.length;a++){let n=t[a],i=a===t.length-1;if(We(e,n,o),!i){let s=t[a+1],u=n.centerX,d=n.bottomY+1,l=s.centerX,p=s.y-1;oe(e,u,d,p-1),le(e,l,p)}}}function We(e,t,r){let o=t.type!=="start",a=t.type!=="end"&&(!t.children||t.children.length===0);hr(e,t.x,t.y,t.width,t.height),o&&A(e,t.centerX,t.y,B.teeUp),(a||t.children&&t.children.length>0)&&A(e,t.centerX,t.y+t.height-1,B.teeDown);let n=t.width-ee*2,i=Er(t,r);for(let s=0;s<t.label.length;s++){let u=t.label[s],d=t.x+1+Math.floor((n-te(u).length)/2),l=t.y+1+s;pt(e,d,l,u,i)}t.metadata?.isWinner&&pt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?Sr(e,t,r):Ir(e,t,r))}function Sr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let s=o[0];oe(e,n,a,s.y-2),le(e,s.centerX,s.y-1);for(let u=0;u<o.length;u++){let d=o[u];if(We(e,d,r),u<o.length-1){let l=o[u+1];oe(e,d.centerX,d.bottomY+1,l.y-2),le(e,l.centerX,l.y-1)}}return}if(o.length===1)oe(e,n,a,o[0].y-2),le(e,o[0].centerX,o[0].y-1);else{let s=o.map(l=>l.centerX),u=Math.min(...s),d=Math.max(...s);oe(e,n,a,a+1),mt(e,a+1,u,d),A(e,n,a+1,B.teeUp);for(let l of o){let p=l.centerX;p===u?A(e,p,a+1,B.topLeft):p===d?A(e,p,a+1,B.topRight):p!==n&&A(e,p,a+1,B.teeDown),oe(e,p,a+2,l.y-2),le(e,p,l.y-1)}}for(let s of o)We(e,s,r);if(o.length>1){let s=o.map(m=>m.bottomY),u=Math.max(...s),d=u+1,l=o.map(m=>m.centerX),p=Math.min(...l),f=Math.max(...l);for(let m of o)m.bottomY<u&&oe(e,m.centerX,m.bottomY+1,d-1);mt(e,d,p,f);for(let m of o){let w=m.centerX;w===p?A(e,w,d,B.bottomLeft):w===f?A(e,w,d,B.bottomRight):A(e,w,d,B.teeUp)}A(e,t.centerX,d,B.teeDown),A(e,t.centerX,d+1,B.vertical)}}function Ir(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=o[0];oe(e,t.centerX,a,n.y-2),le(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let s=o[i];if(We(e,s,r),i<o.length-1){let u=o[i+1];oe(e,s.centerX,s.bottomY+1,u.y-2),le(e,u.centerX,u.y-1)}}}var Rr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function Er(e,t){if(e.metadata?.heat!==void 0){let r=ve(e.metadata.heat);return pr[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?Rr[e.metadata.streamState]||void 0:t[e.state]||void 0}function he(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:a}=br(e,t,r),n=fr(r,a);return xr(n,o,t),gr(n)}}}function $r(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Tr(e){let t=[];function r(o){for(let a of o)if(V(a))t.push(a);else if(rt(a))r(a.children);else if(G(a)||z(a))r(a.children);else if(X(a))for(let n of a.branches)n.taken&&r(n.children)}return r(e),t}function Mr(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)),t}function Nr(e){let t=0,r=0,o=0,a=0,n=0,i;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&a++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!i||s.durationMs>i.durationMs)&&(i={name:s.name??s.key??s.id,durationMs:s.durationMs});return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:a,totalRetries:n,slowestStep:i}}function Or(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let a={stepKey:r};o.durationMs!==void 0&&(a.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(a.error=String(o.error)),t.onAfterStep.push(a)}}return t}function Dr(e,t){let r=e.root,o=Tr(r.children),a=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(Mr),summary:Nr(o)};if(e.hooks){let s=Or(e.hooks);Object.keys(s).length>0&&(i.hooks=s)}if(a){let d=((t.diagramFormat??"ascii")==="flowchart"?he():ae()).render(e,t);n&&(d=$r(d)),i.diagram=d}return i}function Be(){return{name:"logger",supportsLive:!1,render(e,t){let o=Dr(e,t);return JSON.stringify(o)}}}import{ok as He,err as ke}from"awaitly";import Cr from"pako";var Lr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function _r(e){let t;if(Lr)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 Ae(e){let r=new TextEncoder().encode(e),o=Cr.deflate(r);return _r(o)}var gt="https://kroki.io";function Ye(e,t,r,o={}){let a=o.baseUrl??gt,n=Ae(r);return`${a}/${e}/${t}/${n}`}function ue(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:K},n=o.render(e,a);return Ye("mermaid",t,n,r)}function Wr(e,t={}){return ue(e,"svg",t)}function Br(e,t={}){return ue(e,"png",t)}function Ar(e={}){let t=e.baseUrl??gt;return{toUrl(r,o){return ue(r,o,{baseUrl:t})},toSvgUrl(r){return ue(r,"svg",{baseUrl:t})},toPngUrl(r){return ue(r,"png",{baseUrl:t})},toPdfUrl(r){return ue(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var bt="https://mermaid.ink";function wt(e){return`pako:${Ae(e)}`}function Pr(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 Hr(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 Pe(e,t,r={}){let o=Pr(r),a=o.baseUrl??bt,n=wt(t),i=Hr(e,o);return`${a}/${e}/${n}${i}`}function Y(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:K},n=o.render(e,a);return Pe(t,n,r)}function Fr(e,t={}){return Y(e,"svg",t)}function Ur(e,t={}){return Y(e,"img",{...t,imageType:"png"})}function zr(e,t={}){return Y(e,"img",{...t,imageType:"jpeg"})}function Kr(e,t={}){return Y(e,"img",{...t,imageType:"webp"})}function jr(e,t={}){return Y(e,"pdf",t)}function Vr(e={}){let t=e.baseUrl??bt;return{toUrl(r,o){return Y(r,o,e)},toSvgUrl(r){return Y(r,"svg",e)},toPngUrl(r){return Y(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return Y(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return Y(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return Y(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}function Gr(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?He(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?ke("UNSUPPORTED_FORMAT"):He(void 0):ke("UNSUPPORTED_FORMAT")}function Yr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Jr(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function xe(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return ke("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return ke("UNSUPPORTED_DIAGRAM_KIND")}}let a=Gr(r.provider,e.kind,t);if(!a.ok)return a;switch(r.provider){case"kroki":return He(Ye(Yr(e.kind),t,e.source,r));case"mermaid-ink":return He(Pe(Jr(t),e.source,r));default:{let n=r;return ke("UNKNOWN_PROVIDER")}}}function yt(e){let t={bg:"#ffffff",bgSecondary:"#f8f9fa",text:"#212529",textMuted:"#6c757d",border:"#dee2e6",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#e9ecef",nodeRunning:"#fff3cd",nodeSuccess:"#d1e7dd",nodeError:"#f8d7da",nodeAborted:"#e9ecef",nodeCached:"#cfe2ff",nodeSkipped:"#f8f9fa",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},r={bg:"#212529",bgSecondary:"#343a40",text:"#f8f9fa",textMuted:"#adb5bd",border:"#495057",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#495057",nodeRunning:"#664d03",nodeSuccess:"#0f5132",nodeError:"#842029",nodeAborted:"#495057",nodeCached:"#084298",nodeSkipped:"#343a40",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},o=n=>`
1
+ 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 Ie(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Nt(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 Ee(e,t={}){if(Nt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,a=[],n=[];for(let s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?a.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(a.length<=1)return e;a.sort((s,l)=>s.startTs-l.startTs);let i=[],d=[a[0]];for(let s=1;s<a.length;s++){let l=a[s],p=Math.min(...d.map(M=>M.startTs)),g=Math.max(...d.map(M=>M.endTs)),f=l.startTs<=p+o,w=l.startTs<g;if(!f&&!w){i.push(d),d=[l];continue}let k=w?Math.min(l.endTs,g)-l.startTs:0;f||k>=r?d.push(l):(i.push(d),d=[l])}i.push(d);let u=[];for(let s of i){let l=Math.min(...s.map(p=>p.originalIndex));if(s.length===1)u.push({node:s[0].node,position:l});else{let p=s.map(k=>k.node),g=Math.min(...s.map(k=>k.startTs)),f=Math.max(...s.map(k=>k.endTs)),w={type:"parallel",id:`detected_parallel_${g}`,name:`${p.length} parallel steps`,state:Dt(p),mode:"all",children:p,startTs:g,endTs:f,durationMs:f-g};u.push({node:w,position:l})}}for(let{node:s,originalIndex:l}of n)u.push({node:s,position:l});return u.sort((s,l)=>s.position-l.position),u.map(s=>s.node)}function Dt(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 Ot(e={}){return{detect:t=>Ee(t,e)}}function ce(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:a=1e3}=e,n=o,i=Ie(),d,u,s,l="pending",p,g,f=new Map,w=[],k=[],M=new Map,$=[],T=Date.now(),R=T,S={onAfterStep:new Map},x,h=[],y=0;function E(c){return c.stepId??c.stepKey??c.name??Ie()}function C(c){if(w.length>0){w[w.length-1].children.push(c),R=Date.now();return}if(k.length>0){let b=k[k.length-1];for(let m of b.branches.values())if(m.taken){m.children.push(c),R=Date.now();return}b.pendingChildren.push(c),R=Date.now();return}$.push(c),R=Date.now()}function N(c){if(!n)return;let b=J(),m=new Map;for(let[W,q]of f)m.set(W,{id:q.id,name:q.name,key:q.key,startTs:q.startTs,retryCount:q.retryCount,timedOut:q.timedOut,timeoutMs:q.timeoutMs});let F={id:`snapshot_${y}`,eventIndex:y,event:structuredClone(c),ir:structuredClone(b),timestamp:Date.now(),activeSteps:m};h.push(F),h.length>a&&h.shift(),y++}function L(c){switch(c.type){case"workflow_start":{$=[],s=void 0,g=void 0,p=void 0,f.clear(),w.length=0,k.length=0,M.clear(),d=c.workflowId,u=c.ts,l="running",T=Date.now(),R=T,x!==void 0&&x!==c.workflowId&&(S.shouldRun=void 0,S.onBeforeStart=void 0),x=c.workflowId,S.onAfterStep=new Map;break}case"workflow_success":l="success",s=c.ts,g=c.durationMs,R=Date.now();break;case"workflow_error":l="error",s=c.ts,p=c.error,g=c.durationMs,R=Date.now();break;case"workflow_cancelled":l="aborted",s=c.ts,g=c.durationMs,R=Date.now();break;case"step_start":{let b=E(c);f.set(b,{id:b,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),R=Date.now();break}case"step_success":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"success",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),f.delete(b)}break}case"step_error":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"error",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};C(F),f.delete(b)}break}case"step_aborted":{let b=E(c),m=f.get(b);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"aborted",startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),f.delete(b)}break}case"step_cache_hit":{let m={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};C(m);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let b=E(c),m=f.get(b);m&&(m.timedOut=!0,m.timeoutMs=c.timeoutMs),R=Date.now();break}case"step_retry":{let b=E(c),m=f.get(b);m&&(m.retryCount=(c.attempt??1)-1),R=Date.now();break}case"step_retries_exhausted":R=Date.now();break;case"step_skipped":{let m={type:"step",id:E(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};C(m);break}case"hook_should_run":{let b={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.shouldRun=b,x=c.workflowId,R=Date.now();break}case"hook_should_run_error":{let b={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.shouldRun=b,x=c.workflowId,R=Date.now();break}case"hook_before_start":{let b={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};S.onBeforeStart=b,x=c.workflowId,R=Date.now();break}case"hook_before_start_error":{let b={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};S.onBeforeStart=b,x=c.workflowId,R=Date.now();break}case"hook_after_step":{let b={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),R=Date.now();break}case"hook_after_step_error":{let b={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};S.onAfterStep.set(c.stepKey,b),R=Date.now();break}case"stream_created":{let b=`${c.workflowId}:${c.namespace}`;M.set(b,{id:Ie(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),R=Date.now();break}case"stream_write":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&(m.writeCount++,m.finalPosition=Math.max(m.finalPosition,c.position)),R=Date.now();break}case"stream_read":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&m.readCount++,R=Date.now();break}case"stream_close":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);if(m){m.streamState="closed",m.finalPosition=c.finalPosition;let F={type:"stream",id:m.id,namespace:m.namespace,state:"success",startTs:m.startTs,endTs:c.ts,durationMs:c.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(b)}R=Date.now();break}case"stream_error":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);if(m){m.streamState="error";let F={type:"stream",id:m.id,namespace:m.namespace,state:"error",error:c.error,startTs:m.startTs,endTs:c.ts,durationMs:c.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(b)}R=Date.now();break}case"stream_backpressure":{let b=`${c.workflowId}:${c.namespace}`,m=M.get(b);m&&(m.backpressureOccurred=!0),R=Date.now();break}}N(c)}function P(c){if(c.type==="scope_start")w.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),R=Date.now();else if(c.type==="scope_end"){let b=w.findIndex(W=>W.id===c.scopeId);if(b===-1)return;for(;w.length>b+1;){let W=w.pop(),q=W.type==="race"?{type:"race",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children}:{type:"parallel",id:W.id,name:W.name,state:v(W.children),startTs:W.startTs,endTs:c.ts,children:W.children,mode:W.type==="allSettled"?"allSettled":"all"};w[w.length-1].children.push(q)}let[m]=w.splice(b,1),F=m.type==="race"?{type:"race",id:m.id,name:m.name,state:v(m.children),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,children:m.children,winnerId:c.winnerId}:{type:"parallel",id:m.id,name:m.name,state:v(m.children),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,children:m.children,mode:m.type==="allSettled"?"allSettled":"all"};C(F)}}function O(c){if(c.type==="decision_start")k.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),R=Date.now();else if(c.type==="decision_branch"){let b=k.find(m=>m.id===c.decisionId);if(b){let m=c.branchLabel,F=b.branches.get(m);if(F)F.taken=c.taken,c.taken&&b.pendingChildren.length>0&&(F.children.unshift(...b.pendingChildren),b.pendingChildren=[]);else{let W=c.taken?[...b.pendingChildren]:[];c.taken&&(b.pendingChildren=[]),b.branches.set(m,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:W})}R=Date.now()}}else if(c.type==="decision_end"){let b=k.findIndex(m=>m.id===c.decisionId);if(b!==-1){let[m]=k.splice(b,1),F=k.splice(b),W=Array.from(m.branches.values());W.length===0&&m.pendingChildren.length>0&&(W=[{label:"default",taken:!0,children:[...m.pendingChildren]}]);let q=W.find(Re=>Re.taken)?.label,Tt={type:"decision",id:m.id,name:m.name,state:v(W.flatMap(Re=>Re.taken?Re.children:[])),startTs:m.startTs,endTs:c.ts,durationMs:c.durationMs,condition:m.condition,decisionValue:m.decisionValue,branchTaken:c.branchTaken??q,branches:W};C(Tt),k.push(...F),R=Date.now()}}}function v(c){return c.length===0?"success":c.some(W=>W.state==="error")?"error":c.every(W=>W.state==="success"||W.state==="cached")?"success":c.some(W=>W.state==="running")?"running":"pending"}function D(){let c=[...$];for(let[,b]of f)c.push({type:"step",id:b.id,name:b.name,key:b.key,state:"running",startTs:b.startTs,...b.retryCount>0&&{retryCount:b.retryCount},...b.timedOut&&{timedOut:!0,timeoutMs:b.timeoutMs}});for(let[,b]of M)c.push({type:"stream",id:b.id,namespace:b.namespace,state:"running",startTs:b.startTs,writeCount:b.writeCount,readCount:b.readCount,finalPosition:b.finalPosition,streamState:b.streamState,backpressureOccurred:b.backpressureOccurred});return c}function J(){let c=D();t&&(c=Ee(c,r));let b={type:"workflow",id:d??i,workflowId:d??i,state:l,startTs:u,endTs:s,durationMs:g,children:c,error:p},m=S.shouldRun!==void 0||S.onBeforeStart!==void 0||S.onAfterStep.size>0;return{root:b,metadata:{createdAt:T,lastUpdatedAt:R},...m&&{hooks:S}}}function re(){d=void 0,u=void 0,s=void 0,l="pending",p=void 0,g=void 0,f.clear(),w.length=0,k.length=0,M.clear(),$=[],T=Date.now(),R=T,S={onAfterStep:new Map},x=void 0,h.length=0,y=0}function tt(){return[...h]}function be(c){return h[c]}function $t(c){return h[c]?.ir}function Mt(){h.length=0,y=0}return{handleEvent:L,handleScopeEvent:P,handleDecisionEvent:O,getIR:J,reset:re,getSnapshots:tt,getSnapshotAt:be,getIRAt:$t,clearSnapshots:Mt,get hasActiveSteps(){return f.size>0},get state(){return l},get snapshotCount(){return h.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}import{ok as Ht,err as Ft}from"awaitly";function V(e){return e.type==="step"}function rt(e){return e.type==="sequence"}function G(e){return e.type==="parallel"}function z(e){return e.type==="race"}function X(e){return e.type==="decision"}function ne(e){return e.type==="stream"}function wn(e){return"children"in e||e.type==="decision"&&"branches"in e}var Fe="\x1B[0m",Ct="\x1B[1m",ot="\x1B[2m",Lt="\x1B[31m",_t="\x1B[32m",Wt="\x1B[33m",Bt="\x1B[34m",nt="\x1B[90m",At="\x1B[37m";function Z(e,t){return t?`${t}${e}${Fe}`:e}function we(e){return`${Ct}${e}${Fe}`}function _(e){return`${ot}${e}${Fe}`}var K={pending:At,running:Wt,success:_t,error:Lt,aborted:nt,cached:Bt,skipped:ot+nt};function Pt(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 ye(e,t){let r=Pt(e);return Z(r,t[e])}function $e(e,t,r){return Z(e,r[t])}function te(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var I={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},pe={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Ut="\x1B[0m";function zt(e){return e<.2?pe.cold:e<.4?pe.cool:e<.6?pe.neutral:e<.8?pe.warm:e<.95?pe.hot:pe.critical}function at(e,t){let r=zt(t);return r?`${r}${e}${Ut}`:e}function Kt(e){try{return Ht(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return Ft("STRINGIFY_ERROR")}}function it(e){let t=Kt(e);return t.ok?t.value:"[unserializable]"}var st="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ze(e,t=10){if(e.length===0)return"";let r=e.slice(-t),o=Math.min(...r),n=Math.max(...r)-o||1;return r.map(i=>{let d=(i-o)/n,u=Math.floor(d*(st.length-1));return st[u]}).join("")}function Ue(e,t){let r=te(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function jt(e,t){if(!t)return I.horizontal.repeat(e);let r=` ${t} `,o=te(r).length,a=e-o;if(a<4)return I.horizontal.repeat(e);let n=2,i=a-n;return I.horizontal.repeat(n)+r+I.horizontal.repeat(i)}function dt(e,t,r){let o=e.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),a=e.durationMs!==void 0?_(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=_(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=_(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=_(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?_(` error: ${String(e.error)}`):"";return`${o} ${_(t)}${n}${a}${i}`}function Vt(e,t){let r=[];return e.shouldRun&&r.push(dt(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(dt(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(_("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ae(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...K,...t.colors},o=Math.max(t.terminalWidth??60,5),a=o-4,n=[],i=e.root.name??"workflow",d=we(i);if(n.push(`${I.topLeft}${jt(o-2,d)}${I.topRight}`),n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`),e.hooks){let s=Vt(e.hooks,r);for(let l of s)n.push(`${I.vertical} ${Ue(l,a)}${I.vertical}`)}let u=Me(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${I.vertical} ${Ue(s,a)}${I.vertical}`);if(n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let s=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",p=`${$e(s,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${I.vertical} ${Ue(p,a)}${I.vertical}`),n.push(`${I.vertical}${" ".repeat(o-2)}${I.vertical}`)}return n.push(`${I.bottomLeft}${I.horizontal.repeat(o-2)}${I.bottomRight}`),n.join(`
2
+ `)}}}function Me(e,t,r,o,a){let n=[];for(let i of e)V(i)?n.push(Ke(i,t,r,a)):G(i)?n.push(...Yt(i,t,r,o,a)):z(i)?n.push(...Jt(i,t,r,o,a)):X(i)?n.push(...qt(i,t,r,o,a)):ne(i)&&n.push(Gt(i,t,r));return n}function Ke(e,t,r,o){let a=ye(e.state,r),n=e.name??e.key??"step",i=t,d=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,u;d!==void 0?u=at(n,d):u=$e(n,e.state,r);let s=`${a} ${u}`;if(t.showKeys&&e.key&&e.name&&(s+=_(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:it(e.input).slice(0,30);s+=_(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:it(e.output).slice(0,30);s+=_(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=H(e.durationMs),g=d!==void 0?at(`[${p}]`,d):_(`[${p}]`);s+=` ${g}`}if(i.showSparklines&&i.timingHistory){let p=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);p&&p.length>1&&(s+=` ${_(ze(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(s+=_(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";s+=_(` [timeout${p}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let p=o.onAfterStep.get(l),g=p.state==="success"?Z("\u2699",r.success):Z("\u26A0",r.error),f=p.durationMs!==void 0?_(` ${H(p.durationMs)}`):"";s+=` ${g}${f}`}return s}function Gt(e,t,r){let o=e.streamState==="active"?Z("\u27F3",r.running):e.streamState==="closed"?Z("\u2713",r.success):Z("\u2717",r.error),a=`stream:${e.namespace}`,n=$e(a,e.state,r),i=_(`[W:${e.writeCount} R:${e.readCount}]`),d=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(d+=` ${_(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(d+=_(" [backpressure]")),e.streamState==="closed"&&(d+=_(` pos:${e.finalPosition}`)),d}function Yt(e,t,r,o,a){let n=[],i=" ".repeat(o),d=ye(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${I.teeRight}${I.teeDown}${I.horizontal} ${d} ${we(u)}${s}`),e.children.length===0)n.push(`${i}${I.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${I.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],f=l===e.children.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`;if(V(p))n.push(`${f} ${Ke(p,t,r,a)}`);else{let w=Me([p],t,r,o+1,a);for(let k of w)n.push(`${i}${I.vertical} ${k}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Jt(e,t,r,o,a){let n=[],i=" ".repeat(o),d=ye(e.state,r),u=e.name??"race";if(n.push(`${i}${I.teeRight}\u26A1 ${d} ${we(u)}`),e.children.length===0)n.push(`${i}${I.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${I.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let s=0;s<e.children.length;s++){let l=e.children[s],g=s===e.children.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`,w=e.winnerId&&l.id===e.winnerId?_(" (winner)"):"";if(V(l))n.push(`${g} ${Ke(l,t,r,a)}${w}`);else{let k=Me([l],t,r,o+1,a);for(let M of k)n.push(`${i}${I.vertical} ${M}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function qt(e,t,r,o,a){let n=[],i=" ".repeat(o),d=ye(e.state,r),u=e.name??"decision",s=e.condition?_(` (${e.condition})`):"",l=e.decisionValue!==void 0?_(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?_(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${I.teeRight}${I.teeDown}${I.horizontal} ${d} ${we(u)}${s}${l}${p}`);for(let g=0;g<e.branches.length;g++){let f=e.branches[g],k=g===e.branches.length-1?`${i}${I.vertical} ${I.bottomLeft}`:`${i}${I.vertical} ${I.teeRight}`,M=f.taken?"\u2713":"\u2298",$=f.taken?r.success:r.skipped,T=Z(`${M} ${f.label}`,$),R=f.condition?_(` (${f.condition})`):"";if(n.push(`${k} ${T}${R}`),f.children.length>0){let S=Me(f.children,t,r,o+1,a);for(let x of S)n.push(`${i}${I.vertical} ${x}`)}else f.taken||n.push(`${i}${I.vertical} ${_("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${I.bottomLeft}${I.horizontal}${I.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}import{ok as Zt,err as Qt}from"awaitly";function je(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...je(r.children)),"branches"in r)for(let o of r.branches)t.push(...je(o.children));return t}function Te(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function ve(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function Xt(){let e=new Map,t=new Map,r=new Map,o=new Map,a=[];function n(S){return S.stepKey??S.stepId??S.name??"unknown"}function i(S){let x=new Map;for(let h of S)switch(h.type){case"step_start":{let y=n(h);x.set(y,{retried:!1,timedOut:!1});break}case"step_retry":{let y=n(h),E=x.get(y);E&&(E.retried=!0);break}case"step_timeout":{let y=n(h),E=x.get(y);E&&(E.timedOut=!0);break}case"step_success":{let y=n(h),E=x.get(y),C=e.get(y)??[];C.push(h.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,r.set(y,P),x.delete(y);break}case"step_error":{let y=n(h),E=x.get(y),C=e.get(y)??[];C.push(h.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,P.errors++,r.set(y,P),x.delete(y);break}}}function d(S){i(S.events)}function u(S){a.push(S)}function s(S){a.length>0&&(i(a),a=[])}function l(S){let x=e.get(S);if(!x||x.length===0)return;let h=[...x].sort((O,v)=>O-v),E=h.reduce((O,v)=>O+v,0)/h.length,C=h.reduce((O,v)=>O+(v-E)**2,0)/h.length,N=t.get(S)??{retried:0,total:1},L=r.get(S)??{errors:0,total:1},P=o.get(S)??{timedOut:0,total:1};return{nodeId:S,avgDurationMs:E,minDurationMs:h[0],maxDurationMs:h[h.length-1],stdDevMs:Math.sqrt(C),samples:h.length,retryRate:N.total>0?N.retried/N.total:0,timeoutRate:P.total>0?P.timedOut/P.total:0,errorRate:L.total>0?L.errors/L.total:0,percentiles:{p50:Te(h,.5),p90:Te(h,.9),p95:Te(h,.95),p99:Te(h,.99)}}}function p(S){return l(S)}function g(S,x="duration"){let h=new Map,y=je(S.root.children),E=[];for(let v of y){let D=("key"in v?v.key:void 0)??v.id??v.name,J=l(D);if(J){let re;switch(x){case"duration":re=J.avgDurationMs;break;case"retryRate":re=J.retryRate;break;case"errorRate":re=J.errorRate;break}E.push({id:v.id,value:re})}}if(E.length===0)return{heat:h,metric:x,stats:{min:0,max:0,mean:0,threshold:0}};let C=E.map(v=>v.value),N=Math.min(...C),L=Math.max(...C),P=C.reduce((v,D)=>v+D,0)/C.length,O=L-N||1;for(let{id:v,value:D}of E)h.set(v,(D-N)/O);return{heat:h,metric:x,stats:{min:N,max:L,mean:P,threshold:P+(L-P)*.5}}}function f(){let S=new Map;for(let x of e.keys()){let h=l(x);h&&S.set(x,h)}return S}function w(S=10){return[...f().values()].sort((h,y)=>y.avgDurationMs-h.avgDurationMs).slice(0,S)}function k(S=10){return[...f().values()].filter(h=>h.errorRate>0).sort((h,y)=>y.errorRate-h.errorRate).slice(0,S)}function M(S=10){return[...f().values()].filter(h=>h.retryRate>0).sort((h,y)=>y.retryRate-h.retryRate).slice(0,S)}function $(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function T(S){let x=JSON.parse(S);e.clear(),t.clear(),r.clear(),o.clear();for(let[h,y]of Object.entries(x.timingData??{}))e.set(h,y);for(let[h,y]of Object.entries(x.retryData??{}))t.set(h,y);for(let[h,y]of Object.entries(x.errorData??{}))r.set(h,y);for(let[h,y]of Object.entries(x.timeoutData??{}))o.set(h,y)}function R(){e.clear(),t.clear(),r.clear(),o.clear(),a=[]}return{addRun:d,addEvent:u,finalizeRun:s,getNodePerformance:p,getHeatmap:g,getSlowestNodes:w,getErrorProneNodes:k,getRetryProneNodes:M,getAllPerformance:f,exportData:$,importData:T,clear:R}}function er(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function tr(){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 rr(e){return`heat_${e}`}function nr(){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 or(e){try{return Zt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let a=Number(o);return Number.isSafeInteger(a)?a:o.toString()}))}catch{return Qt("STRINGIFY_ERROR")}}function ct(e){let t=or(e);return t.ok?t.value:"[unserializable]"}function ar(e,t,r){let o;if(e.shouldRun){let a="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",i=e.shouldRun.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${a}[["${i} shouldRun${u}${d}"]]:::${n}`),o=a}if(e.onBeforeStart){let a="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${a}[["${i} onBeforeStart${u}${d}"]]:::${n}`),o&&t.push(` ${o} --> ${a}`),o=a}return{lastHookId:o}}var lt=0,Ne=new Set,De=new Set;function me(e="node"){return`${e}_${++lt}`}function ir(){lt=0,Ne.clear(),De.clear()}function j(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function ut(e){return j(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){ir();let r=[],o=t;r.push("flowchart TD");let a;e.hooks&&(a=ar(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),a&&r.push(` ${a} --> ${n}`);let i=n;for(let u of e.root.children){let s=Oe(u,t,r,o,e.hooks);r.push(` ${i} --> ${s.entryId}`),i=s.exitId}if(["success","error","aborted"].includes(e.root.state)){let u="finish",s=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",l=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",p=`(("${s} ${l}"))`,g=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${p}${g}`),r.push(` ${i} --> ${u}`)}return r.push(""),r.push(...er()),o.showHeatmap&&r.push(...tr()),e.hooks&&r.push(...nr()),r.join(`
3
+ `)}}}function Oe(e,t,r,o,a){if(V(e))return sr(e,t,r,o,a);if(G(e))return dr(e,t,r,o,a);if(z(e))return cr(e,t,r,o,a);if(X(e))return lr(e,t,r,o,a);if(ne(e))return ur(e,t,r);let n=me("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function sr(e,t,r,o,a){let n=t,i=n.showRetryEdges??!0,d=n.showErrorEdges??!0,u=n.showTimeoutEdges??!0,s=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:me("step");if(De.has(s)){let h=2;for(;De.has(`${s}_${h}`);)h++;s=`${s}_${h}`}De.add(s);let l=e.name??e.key??"Step",p=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,g=j(p),f=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",w="";switch(e.state){case"success":w="\u2713 ";break;case"error":w="\u2717 ";break;case"cached":w="\u{1F4BE} ";break;case"running":w="\u23F3 ";break;case"skipped":w="\u2298 ";break}let k="";if(e.input!==void 0){let h=typeof e.input=="string"?j(e.input):j(ct(e.input).slice(0,20));k+=`\\nin: ${h}`}if(e.output!==void 0&&e.state==="success"){let h=typeof e.output=="string"?j(e.output):j(ct(e.output).slice(0,20));k+=`\\nout: ${h}`}let M="",$=e.key??e.id;if(a&&$&&a.onAfterStep.has($)){let h=a.onAfterStep.get($),y=h.state==="success"?"\u2699":"\u26A0",E=t.showTimings&&h.durationMs!==void 0?` ${H(h.durationMs)}`:"";M=`\\n${y} hook${E}`}let T=(w+g+k+M+f).trim(),R,S=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let h=ve(S);R=rr(h)}else R=e.state;let x;switch(e.state){case"error":x=`{{"${T}"}}`;break;case"cached":x=`[("${T}")]`;break;case"skipped":x=`["${T}"]`;break;default:x=`["${T}"]`}if(r.push(` ${s}${x}:::${R}`),i&&e.retryCount!==void 0&&e.retryCount>0){let h=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${s} -.->|"${h}"| ${s}`)}if(d&&e.state==="error"&&e.error!==void 0){let h=`ERR_${s}`,y=j(String(e.error)).slice(0,30);r.push(` ${h}{{"${y}"}}`),r.push(` ${s} -->|error| ${h}`),r.push(` style ${h} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let h=`TO_${s}`,y=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${h}{{"\u23F1 Timeout ${y}"}}`),r.push(` ${s} -.->|timeout| ${h}`),r.push(` style ${h} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function dr(e,t,r,o,a){let n=me("parallel"),i=`${n}_fork`,d=`${n}_join`,u=ut(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let g=n,f=j(`${u}${s}`),w="operations not individually tracked",k=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["${f}${k}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["${u}${s}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let l=[];for(let g of e.children){let f=Oe(g,t,r,o,a);r.push(` ${i} --> ${f.entryId}`),l.push(f.exitId)}r.push(` ${d}{"\u2713 Join"}`);for(let g of l)r.push(` ${g} --> ${d}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:d}}function cr(e,t,r,o,a){let n=me("race"),i=`${n}_start`,d=`${n}_end`,u=ut(e.name??"Race");if(e.children.length===0){let g=n,f=j(u),w="operations not individually tracked",k=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["\u26A1 ${f}${k}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let s=[],l;for(let g of e.children){let f=Oe(g,t,r,o,a),w=e.winnerId===g.id;r.push(` ${i} --> ${f.entryId}`),w&&(l=f.exitId),s.push({exitId:f.exitId,isWinner:w})}r.push(` ${d}(("\u2713 First"))`);for(let{exitId:g,isWinner:f}of s)f&&l?r.push(` ${g} ==>|\u{1F3C6} Winner| ${d}`):e.winnerId?r.push(` ${g} -. cancelled .-> ${d}`):r.push(` ${g} --> ${d}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:d}}function lr(e,t,r,o,a){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:me("decision");if(Ne.has(n)){let g=2;for(;Ne.has(`${n}_${g}`);)g++;n=`${n}_${g}`}Ne.add(n);let i=j(e.condition??"condition"),d=e.decisionValue!==void 0?` = ${j(String(e.decisionValue)).slice(0,30)}`:"",u=`${i}${d}`.trim();r.push(` ${n}{"${u}"}`);let s=[],l,p=new Set;for(let g of e.branches){let f=`${n}_${g.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(p.has(f)){let T=2;for(;p.has(`${f}_${T}`);)T++;f=`${f}_${T}`}p.add(f);let w=j(g.label),k=g.taken?`${w} \u2713`:`${w} skipped`,M=g.taken?":::success":":::skipped";r.push(` ${f}["${k}"]${M}`);let $=g.condition?`|${j(g.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${$} ${f}`),g.children.length>0){let T=f;for(let R of g.children){let S=Oe(R,t,r,o,a);r.push(` ${T} --> ${S.entryId}`),T=S.exitId}s.push(T),g.taken&&(l=T)}else s.push(f),g.taken&&(l=f)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function ur(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${me("")}`,a=`W:${e.writeCount} R:${e.readCount}`,n="";switch(e.streamState){case"active":n="\u27F3 ";break;case"closed":n="\u2713 ";break;case"error":n="\u2717 ";break}let i=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",d=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${j(e.namespace)}\\n${a}${d}${i}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",r.push(` ${o}{{"${u}"}}:::${s}`),{entryId:o,exitId:o}}var B={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},pr={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},mr="\x1B[0m";function fr(e,t){let r=[],o=[];for(let a=0;a<t;a++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function A(e,t,r,o,a){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,a&&(e.colors[r][t]=a))}function ft(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function gr(e,t,r,o,a){A(e,t,r,B.topLeft);for(let n=1;n<o-1;n++)A(e,t+n,r,B.horizontal);A(e,t+o-1,r,B.topRight);for(let n=1;n<a-1;n++)A(e,t,r+n,B.vertical),A(e,t+o-1,r+n,B.vertical);A(e,t,r+a-1,B.bottomLeft);for(let n=1;n<o-1;n++)A(e,t+n,r+a-1,B.horizontal);A(e,t+o-1,r+a-1,B.bottomRight)}function pt(e,t,r,o,a){let n=te(o).split("");for(let i=0;i<n.length;i++)A(e,t+i,r,n[i],a)}function oe(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let d=ft(e,t,i);d===B.horizontal?A(e,t,i,B.cross):(d===" "||d===B.vertical)&&A(e,t,i,B.vertical)}}function mt(e,t,r,o){let a=Math.min(r,o),n=Math.max(r,o);for(let i=a;i<=n;i++){let d=ft(e,i,t);d===B.vertical?A(e,i,t,B.cross):(d===" "||d===B.horizontal)&&A(e,i,t,B.horizontal)}}function le(e,t,r){A(e,t,r,B.arrowDown)}function hr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let a=0;a<e.width;a++){let n=e.colors[r][a],i=e.cells[r][a];n?o+=n+i+mr:o+=i}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
4
+ `)}var Q=11,ee=2,fe=2,Ce=3;function Ge(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],a="";for(let n of r)a?a.length+1+n.length<=t?a+=" "+n:(o.push(a),a=n):a=n;if(a&&o.push(a),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function gt(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 br(e,t,r){let o=t.showStartEnd??!0,a=t,n=Math.floor(r/2),i=[],d=0;if(o){let s=Le("start","start",["\u25B6 Start"],"success",n,d);i.push(s),d=s.bottomY+fe}for(let s of e.root.children){let l=_e(s,n,d,r-4,t,a);i.push(l.node),d=l.bottomY+fe}if(o&&["success","error","aborted"].includes(e.root.state)){let s=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",l=Le("end","end",[s],e.root.state,n,d);i.push(l),d=l.bottomY}return{nodes:i,totalHeight:d+2}}function Le(e,t,r,o,a,n){let i=Math.max(...r.map(l=>te(l).length)),d=Math.max(Q,i+ee*2),u=r.length+2,s=a-Math.floor(d/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:d,height:u,centerX:a,bottomY:n+u-1}}function _e(e,t,r,o,a,n){if(V(e))return wr(e,t,r,o,a,n);if(G(e)||z(e))return vr(e,t,r,o,a,n);if(X(e))return kr(e,t,r,o,a,n);if(ne(e))return yr(e,t,r,o,a,n);let i=Le(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function wr(e,t,r,o,a,n){let i=e.name??e.key??"step",d=gt(e.state),u=[],s=`${d} ${i}`;a.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-ee*2,40);if(u.push(...Ge(s,l)),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let $=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);$&&$.length>1&&u.push(ze($,8))}let p=Math.max(...u.map($=>te($).length)),g=Math.max(Q,p+ee*2),f=u.length+2,w=t-Math.floor(g/2),k;if(n?.showHeatmap&&n.heatmapData){let $=e.key??e.name??e.id;k=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get($)}let M={id:e.id,type:"step",label:u,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1,metadata:k!==void 0?{heat:k}:void 0};return{node:M,bottomY:M.bottomY}}function yr(e,t,r,o,a,n){let i=`stream:${e.namespace}`,d=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${d} ${i}`,l=Math.min(o-ee*2,40);u.push(...Ge(s,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),a.showTimings&&e.durationMs!==void 0&&u.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let p=Math.max(...u.map(M=>te(M).length)),g=Math.max(Q,p+ee*2),f=u.length+2,w=t-Math.floor(g/2),k={id:e.id,type:"stream",label:u,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:k,bottomY:k.bottomY}}function vr(e,t,r,o,a,n){let i=z(e),d=e.name??(i?"race":"parallel"),s=`${i?"\u26A1":"\u2AD8"} ${d}`;if(e.children.length===0){let y=[s,"(not tracked)"],E=Le(e.id,i?"race":"parallel",y,e.state,t,r);return{node:E,bottomY:E.bottomY}}let l=Math.floor((o-Ce*(e.children.length-1))/e.children.length),p=[];for(let y of e.children){let E=Ve(y,Math.max(l,Q),a,n);p.push(E.width)}let g=p.reduce((y,E)=>y+E,0)+Ce*(e.children.length-1),f=g>o&&e.children.length>1,w=Math.max(Q,s.length+ee*2),k=3,M=t-Math.floor(w/2),$=r;$+=k,$+=1,$+=1;let T=[];if(f)for(let y=0;y<e.children.length;y++){let E=e.children[y],C=_e(E,t,$,o,a,n);i&&z(e)&&e.winnerId===E.id&&(C.node.metadata={...C.node.metadata,isWinner:!0}),T.push(C.node),$=C.bottomY+fe}else{let y=t-Math.floor(g/2);for(let E=0;E<e.children.length;E++){let C=e.children[E],N=y+Math.floor(p[E]/2),L=_e(C,N,$,p[E],a,n);i&&z(e)&&e.winnerId===C.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),T.push(L.node),y+=p[E]+Ce}}let R=Math.max(...T.map(y=>y.bottomY)),x=!f&&T.length>1?R+2:R;return{node:{id:e.id,type:i?"race":"parallel",label:[s],state:e.state,x:M,y:r,width:w,height:k,centerX:t,bottomY:x,children:T,metadata:{verticalLayout:f}},bottomY:x}}function kr(e,t,r,o,a,n){let i=e.name??"decision",d=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${i}${d}`,s=Math.min(o-ee*2,40),l=Ge(u,s),p=Math.max(...l.map(x=>te(x).length)),g=Math.max(Q,p+ee*2),f=l.length+2,w=t-Math.floor(g/2),k=e.branches.find(x=>x.taken),M=k&&k.children.length>0?k:e.branches.find(x=>x.children.length>0);if(!M||M.children.length===0){let x={id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:r+f-1};return{node:x,bottomY:x.bottomY}}let $=r+f+fe,T=[];for(let x of M.children){let h=_e(x,t,$,o,a,n);T.push(h.node),$=h.bottomY+fe}let R=T.length>0?T[T.length-1].bottomY:r+f-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:f,centerX:t,bottomY:R,children:T},bottomY:R}}function Ve(e,t,r,o){if(V(e)){let a=e.name??e.key??"step",n=gt(e.state),i=1;r.showTimings&&e.durationMs!==void 0&&i++,e.retryCount&&e.retryCount>0&&i++,e.timedOut&&i++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&i++;let d=`${n} ${a}`;r.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let u=Math.min(t,Math.max(Q,d.length+ee*2)),s=i+2;return{width:u,height:s}}if(G(e)||z(e)){if(e.children.length===0)return{width:Q+4,height:4};let a=Math.floor(t/e.children.length),n=0,i=0;for(let d of e.children){let u=Ve(d,a,r,o);n+=u.width,i=Math.max(i,u.height)}return n+=Ce*(e.children.length-1),{width:Math.max(n,Q),height:5+i+2}}if(X(e)){let a=e.branches.find(i=>i.taken),n=0;if(a)for(let i of a.children){let d=Ve(i,t,r,o);n+=d.height+fe}return{width:Math.min(t,30),height:3+n}}if(ne(e)){let a=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(Q,a.length+ee*2+4)),d=n+2;return{width:i,height:d}}return{width:Q,height:3}}function xr(e,t,r){let o={...K,...r.colors};for(let a=0;a<t.length;a++){let n=t[a],i=a===t.length-1;if(We(e,n,o),!i){let d=t[a+1],u=n.centerX,s=n.bottomY+1,l=d.centerX,p=d.y-1;oe(e,u,s,p-1),le(e,l,p)}}}function We(e,t,r){let o=t.type!=="start",a=t.type!=="end"&&(!t.children||t.children.length===0);gr(e,t.x,t.y,t.width,t.height),o&&A(e,t.centerX,t.y,B.teeUp),(a||t.children&&t.children.length>0)&&A(e,t.centerX,t.y+t.height-1,B.teeDown);let n=t.width-ee*2,i=Er(t,r);for(let d=0;d<t.label.length;d++){let u=t.label[d],s=t.x+1+Math.floor((n-te(u).length)/2),l=t.y+1+d;pt(e,s,l,u,i)}t.metadata?.isWinner&&pt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?Sr(e,t,r):Rr(e,t,r))}function Sr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let d=o[0];oe(e,n,a,d.y-2),le(e,d.centerX,d.y-1);for(let u=0;u<o.length;u++){let s=o[u];if(We(e,s,r),u<o.length-1){let l=o[u+1];oe(e,s.centerX,s.bottomY+1,l.y-2),le(e,l.centerX,l.y-1)}}return}if(o.length===1)oe(e,n,a,o[0].y-2),le(e,o[0].centerX,o[0].y-1);else{let d=o.map(l=>l.centerX),u=Math.min(...d),s=Math.max(...d);oe(e,n,a,a+1),mt(e,a+1,u,s),A(e,n,a+1,B.teeUp);for(let l of o){let p=l.centerX;p===u?A(e,p,a+1,B.topLeft):p===s?A(e,p,a+1,B.topRight):p!==n&&A(e,p,a+1,B.teeDown),oe(e,p,a+2,l.y-2),le(e,p,l.y-1)}}for(let d of o)We(e,d,r);if(o.length>1){let d=o.map(f=>f.bottomY),u=Math.max(...d),s=u+1,l=o.map(f=>f.centerX),p=Math.min(...l),g=Math.max(...l);for(let f of o)f.bottomY<u&&oe(e,f.centerX,f.bottomY+1,s-1);mt(e,s,p,g);for(let f of o){let w=f.centerX;w===p?A(e,w,s,B.bottomLeft):w===g?A(e,w,s,B.bottomRight):A(e,w,s,B.teeUp)}A(e,t.centerX,s,B.teeDown),A(e,t.centerX,s+1,B.vertical)}}function Rr(e,t,r){let o=t.children;if(o.length===0)return;let a=t.y+t.height,n=o[0];oe(e,t.centerX,a,n.y-2),le(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let d=o[i];if(We(e,d,r),i<o.length-1){let u=o[i+1];oe(e,d.centerX,d.bottomY+1,u.y-2),le(e,u.centerX,u.y-1)}}}var Ir={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function Er(e,t){if(e.metadata?.heat!==void 0){let r=ve(e.metadata.heat);return pr[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?Ir[e.metadata.streamState]||void 0:t[e.state]||void 0}function ge(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:a}=br(e,t,r),n=fr(r,a);return xr(n,o,t),hr(n)}}}function $r(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Mr(e){let t=[];function r(o){for(let a of o)if(V(a))t.push(a);else if(rt(a))r(a.children);else if(G(a)||z(a))r(a.children);else if(X(a))for(let n of a.branches)n.taken&&r(n.children)}return r(e),t}function Tr(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 Nr(e){let t=0,r=0,o=0,a=0,n=0,i;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&a++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!i||s.durationMs>i.durationMs)&&(i={name:s.name??s.key??s.id,durationMs:s.durationMs});let d=new Map;for(let s of e){let l=s.metadata?.domain;if(l&&(s.state==="success"||s.state==="error")){let p=d.get(l)??{total:0,errors:0,totalDuration:0};p.total++,s.state==="error"&&p.errors++,s.durationMs!==void 0&&(p.totalDuration+=s.durationMs),d.set(l,p)}}let u;if(d.size>0){u={};for(let[s,l]of d)u[s]={total:l.total,errors:l.errors,avgDurationMs:l.total>0?Math.round(l.totalDuration/l.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:a,totalRetries:n,slowestStep:i,...u&&{byDomain:u}}}function Dr(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let a={stepKey:r};o.durationMs!==void 0&&(a.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(a.error=String(o.error)),t.onAfterStep.push(a)}}return t}function Or(e,t){let r=e.root,o=Mr(r.children),a=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(Tr),summary:Nr(o)};if(e.hooks){let d=Dr(e.hooks);Object.keys(d).length>0&&(i.hooks=d)}if(a){let s=((t.diagramFormat??"ascii")==="flowchart"?ge():ae()).render(e,t);n&&(s=$r(s)),i.diagram=s}return i}function Be(){return{name:"logger",supportsLive:!1,render(e,t){let o=Or(e,t);return JSON.stringify(o)}}}import{ok as He,err as ke}from"awaitly";import Cr from"pako";var Lr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function _r(e){let t;if(Lr)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 Ae(e){let r=new TextEncoder().encode(e),o=Cr.deflate(r);return _r(o)}var ht="https://kroki.io";function Ye(e,t,r,o={}){let a=o.baseUrl??ht,n=Ae(r);return`${a}/${e}/${t}/${n}`}function ue(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:K},n=o.render(e,a);return Ye("mermaid",t,n,r)}function Wr(e,t={}){return ue(e,"svg",t)}function Br(e,t={}){return ue(e,"png",t)}function Ar(e={}){let t=e.baseUrl??ht;return{toUrl(r,o){return ue(r,o,{baseUrl:t})},toSvgUrl(r){return ue(r,"svg",{baseUrl:t})},toPngUrl(r){return ue(r,"png",{baseUrl:t})},toPdfUrl(r){return ue(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var bt="https://mermaid.ink";function wt(e){return`pako:${Ae(e)}`}function Pr(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 Hr(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 Pe(e,t,r={}){let o=Pr(r),a=o.baseUrl??bt,n=wt(t),i=Hr(e,o);return`${a}/${e}/${n}${i}`}function Y(e,t="svg",r={}){let o=ie(),a={showTimings:!0,showKeys:!1,terminalWidth:80,colors:K},n=o.render(e,a);return Pe(t,n,r)}function Fr(e,t={}){return Y(e,"svg",t)}function Ur(e,t={}){return Y(e,"img",{...t,imageType:"png"})}function zr(e,t={}){return Y(e,"img",{...t,imageType:"jpeg"})}function Kr(e,t={}){return Y(e,"img",{...t,imageType:"webp"})}function jr(e,t={}){return Y(e,"pdf",t)}function Vr(e={}){let t=e.baseUrl??bt;return{toUrl(r,o){return Y(r,o,e)},toSvgUrl(r){return Y(r,"svg",e)},toPngUrl(r){return Y(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return Y(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return Y(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return Y(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}function Gr(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?He(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?ke("UNSUPPORTED_FORMAT"):He(void 0):ke("UNSUPPORTED_FORMAT")}function Yr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Jr(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function xe(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return ke("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return ke("UNSUPPORTED_DIAGRAM_KIND")}}let a=Gr(r.provider,e.kind,t);if(!a.ok)return a;switch(r.provider){case"kroki":return He(Ye(Yr(e.kind),t,e.source,r));case"mermaid-ink":return He(Pe(Jr(t),e.source,r));default:{let n=r;return ke("UNKNOWN_PROVIDER")}}}function yt(e){let t={bg:"#ffffff",bgSecondary:"#f8f9fa",text:"#212529",textMuted:"#6c757d",border:"#dee2e6",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#e9ecef",nodeRunning:"#fff3cd",nodeSuccess:"#d1e7dd",nodeError:"#f8d7da",nodeAborted:"#e9ecef",nodeCached:"#cfe2ff",nodeSkipped:"#f8f9fa",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},r={bg:"#212529",bgSecondary:"#343a40",text:"#f8f9fa",textMuted:"#adb5bd",border:"#495057",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#495057",nodeRunning:"#664d03",nodeSuccess:"#0f5132",nodeError:"#842029",nodeAborted:"#495057",nodeCached:"#084298",nodeSkipped:"#343a40",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},o=n=>`
5
5
  --bg: ${n.bg};
6
6
  --bg-secondary: ${n.bgSecondary};
7
7
  --text: ${n.text};
@@ -1475,41 +1475,41 @@ body {
1475
1475
  return min + 'm ' + sec + 's';
1476
1476
  }
1477
1477
  })();
1478
- `}var se=160,ge=50,Je=40,qr=30,U=20;function Xr(e,t="TB",r){let o=t==="TB"||t==="BT",a=t==="RL"||t==="BT",n=[],i=U,s=U,u=0,d=0;for(let f of e){let m=qe(f,i,s,o,r);n.push(m.node),o?(s+=m.height+qr,u=Math.max(u,m.width),d=s):(i+=m.width+Je,d=Math.max(d,m.height),u=i)}let l=u+U,p=d+U;if(a)for(let f of n)xt(f,l,p,o);return{nodes:n,width:l,height:p}}function xt(e,t,r,o){if(o?e.y=r-e.y-e.height:e.x=t-e.x-e.width,e.children)for(let a of e.children)xt(a,t,r,o)}function qe(e,t,r,o,a){if(V(e)){let n=e.name??e.key??"step",i=a?.showKeys&&e.key&&e.name?`${n} [key: ${e.key}]`:n;return{node:{id:e.id,name:i,type:"step",state:e.state,x:t,y:r,width:se,height:ge,durationMs:e.durationMs},width:se,height:ge}}if(ne(e)){let n=e.streamState==="active"?`stream:${e.namespace} \u27F3`:e.streamState==="error"?`stream:${e.namespace} \u2717`:`stream:${e.namespace} \u2713`;return{node:{id:e.id,name:n,type:"stream",state:e.state,x:t,y:r,width:se,height:ge,durationMs:e.durationMs},width:se,height:ge}}if(G(e)||z(e)){let n=G(e)?"parallel":"race",i=e.name??n,s=[],u=t+U,d=r+U+20,l=0;for(let w of e.children){let k=qe(w,u,d,!0,a);s.push(k.node),u+=k.width+Je,l=Math.max(l,k.height)}let p=u-t-U,f=Math.max(p+U,se+U*2),m=l+U*2+20;return{node:{id:e.id,name:i,type:n,state:e.state,x:t,y:r,width:f,height:m,durationMs:e.durationMs,children:s,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:f,height:m}}if(X(e)){let n=e.name??"decision",i=[],s=t+U,u=r+U+20,d=0;for(let f of e.branches)for(let m of f.children){let w=qe(m,s,u,!0,a);i.push(w.node),s+=w.width+Je,d=Math.max(d,w.height)}let l=Math.max(s-t,se+U*2),p=d+U*2+20;return{node:{id:e.id,name:n,type:"decision",state:e.state,x:t,y:r,width:l,height:p,durationMs:e.durationMs,children:i,containerType:"decision",containerLabel:"DECISION"},width:l,height:p}}return{node:{id:e.id,name:e.name??"unknown",type:e.type,state:e.state,x:t,y:r,width:se,height:ge},width:se,height:ge}}function St(e,t){return e.containerType?Qr(e,t):Zr(e,t)}function Zr(e,t){let o=t&&e.durationMs!==void 0?H(e.durationMs):"";return`
1479
- <g class="wv-node wv-node--${e.state}" data-node-id="${Rt(e.id)}" transform="translate(${e.x}, ${e.y})">
1478
+ `}var se=160,he=50,Je=40,qr=30,U=20;function Xr(e,t="TB",r){let o=t==="TB"||t==="BT",a=t==="RL"||t==="BT",n=[],i=U,d=U,u=0,s=0;for(let g of e){let f=qe(g,i,d,o,r);n.push(f.node),o?(d+=f.height+qr,u=Math.max(u,f.width),s=d):(i+=f.width+Je,s=Math.max(s,f.height),u=i)}let l=u+U,p=s+U;if(a)for(let g of n)xt(g,l,p,o);return{nodes:n,width:l,height:p}}function xt(e,t,r,o){if(o?e.y=r-e.y-e.height:e.x=t-e.x-e.width,e.children)for(let a of e.children)xt(a,t,r,o)}function qe(e,t,r,o,a){if(V(e)){let n=e.name??e.key??"step",i=a?.showKeys&&e.key&&e.name?`${n} [key: ${e.key}]`:n;return{node:{id:e.id,name:i,type:"step",state:e.state,x:t,y:r,width:se,height:he,durationMs:e.durationMs},width:se,height:he}}if(ne(e)){let n=e.streamState==="active"?`stream:${e.namespace} \u27F3`:e.streamState==="error"?`stream:${e.namespace} \u2717`:`stream:${e.namespace} \u2713`;return{node:{id:e.id,name:n,type:"stream",state:e.state,x:t,y:r,width:se,height:he,durationMs:e.durationMs},width:se,height:he}}if(G(e)||z(e)){let n=G(e)?"parallel":"race",i=e.name??n,d=[],u=t+U,s=r+U+20,l=0;for(let w of e.children){let k=qe(w,u,s,!0,a);d.push(k.node),u+=k.width+Je,l=Math.max(l,k.height)}let p=u-t-U,g=Math.max(p+U,se+U*2),f=l+U*2+20;return{node:{id:e.id,name:i,type:n,state:e.state,x:t,y:r,width:g,height:f,durationMs:e.durationMs,children:d,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:g,height:f}}if(X(e)){let n=e.name??"decision",i=[],d=t+U,u=r+U+20,s=0;for(let g of e.branches)for(let f of g.children){let w=qe(f,d,u,!0,a);i.push(w.node),d+=w.width+Je,s=Math.max(s,w.height)}let l=Math.max(d-t,se+U*2),p=s+U*2+20;return{node:{id:e.id,name:n,type:"decision",state:e.state,x:t,y:r,width:l,height:p,durationMs:e.durationMs,children:i,containerType:"decision",containerLabel:"DECISION"},width:l,height:p}}return{node:{id:e.id,name:e.name??"unknown",type:e.type,state:e.state,x:t,y:r,width:se,height:he},width:se,height:he}}function St(e,t){return e.containerType?Qr(e,t):Zr(e,t)}function Zr(e,t){let o=t&&e.durationMs!==void 0?H(e.durationMs):"";return`
1479
+ <g class="wv-node wv-node--${e.state}" data-node-id="${It(e.id)}" transform="translate(${e.x}, ${e.y})">
1480
1480
  <rect width="${e.width}" height="${e.height}" rx="8" ry="8" />
1481
1481
  <text x="${e.width/2}" y="${e.height/2-(o?4:0)}">${Ze(tn(e.name,e.name.includes("[key:")?40:20))}</text>
1482
1482
  ${o?`<text class="wv-node-timing" x="${e.width/2}" y="${e.height/2+12}">${o}</text>`:""}
1483
1483
  </g>
1484
1484
  `}function Qr(e,t){let o=e.children?.map(a=>St(a,t)).join(`
1485
1485
  `)??"";return`
1486
- <g class="wv-container wv-container--${e.containerType}" data-node-id="${Rt(e.id)}" transform="translate(${e.x}, ${e.y})">
1486
+ <g class="wv-container wv-container--${e.containerType}" data-node-id="${It(e.id)}" transform="translate(${e.x}, ${e.y})">
1487
1487
  <rect width="${e.width}" height="${e.height}" rx="12" ry="12" />
1488
1488
  <text class="wv-container-label" x="${U}" y="16">${e.containerLabel}</text>
1489
1489
  <g transform="translate(${-e.x}, ${-e.y})">
1490
1490
  ${o}
1491
1491
  </g>
1492
1492
  </g>
1493
- `}function Xe(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=Xe(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let a=Xe(o.children,t);if(a)return a}}}function en(e,t){let r=[];function o(n,i){if(Math.abs(n.y-i.y)<n.height){let u=n.x+n.width,d=n.y+n.height/2,l=i.x,p=i.y+i.height/2;r.push(`
1494
- <path class="wv-edge" d="M ${u} ${d} L ${l-8} ${p}" />
1493
+ `}function Xe(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=Xe(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let a=Xe(o.children,t);if(a)return a}}}function en(e,t){let r=[];function o(n,i){if(Math.abs(n.y-i.y)<n.height){let u=n.x+n.width,s=n.y+n.height/2,l=i.x,p=i.y+i.height/2;r.push(`
1494
+ <path class="wv-edge" d="M ${u} ${s} L ${l-8} ${p}" />
1495
1495
  <polygon class="wv-edge-arrow" points="${l-8},${p-4} ${l-8},${p+4} ${l},${p}" />
1496
- `)}else{let u=n.x+n.width/2,d=n.y+n.height,l=i.x+i.width/2,p=i.y;r.push(`
1497
- <path class="wv-edge" d="M ${u} ${d} L ${l} ${p-8}" />
1496
+ `)}else{let u=n.x+n.width/2,s=n.y+n.height,l=i.x+i.width/2,p=i.y;r.push(`
1497
+ <path class="wv-edge" d="M ${u} ${s} L ${l} ${p-8}" />
1498
1498
  <polygon class="wv-edge-arrow" points="${l-4},${p-8} ${l+4},${p-8} ${l},${p}" />
1499
- `)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let s=Xe(t.root.children,i.id);if(s&&s.type==="decision"&&s.branches){let u=0;for(let d of s.branches){let l=d.children.length;l>0&&o(i,i.children[u]);for(let p=0;p<l-1;p++)o(i.children[u+p],i.children[u+p+1]);u+=l}}}else if(i.containerType==="parallel"||i.containerType==="race")for(let s of i.children)s.children&&s.children.length>0&&a([s]);else a(i.children)}return a(e),r.join(`
1500
- `)}function It(e,t){let r=Xr(e.root.children,t.layout,t),o=Math.max(r.width,400),a=Math.max(r.height,300),n=r.nodes.map(l=>St(l,t.showTimings)).join(`
1501
- `),i=en(r.nodes,e),s=e.root.name??"Workflow",u=yt(t.theme),d=vt({wsUrl:t.wsUrl,interactive:t.interactive,timeTravel:t.timeTravel,heatmap:t.heatmap});return`<!DOCTYPE html>
1499
+ `)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let d=Xe(t.root.children,i.id);if(d&&d.type==="decision"&&d.branches){let u=0;for(let s of d.branches){let l=s.children.length;l>0&&o(i,i.children[u]);for(let p=0;p<l-1;p++)o(i.children[u+p],i.children[u+p+1]);u+=l}}}else if(i.containerType==="parallel"||i.containerType==="race")for(let d of i.children)d.children&&d.children.length>0&&a([d]);else a(i.children)}return a(e),r.join(`
1500
+ `)}function Rt(e,t){let r=Xr(e.root.children,t.layout,t),o=Math.max(r.width,400),a=Math.max(r.height,300),n=r.nodes.map(l=>St(l,t.showTimings)).join(`
1501
+ `),i=en(r.nodes,e),d=e.root.name??"Workflow",u=yt(t.theme),s=vt({wsUrl:t.wsUrl,interactive:t.interactive,timeTravel:t.timeTravel,heatmap:t.heatmap});return`<!DOCTYPE html>
1502
1502
  <html lang="en">
1503
1503
  <head>
1504
1504
  <meta charset="UTF-8">
1505
1505
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1506
- <title>${Ze(s)} - Workflow Visualizer</title>
1506
+ <title>${Ze(d)} - Workflow Visualizer</title>
1507
1507
  <style>${u}</style>
1508
1508
  </head>
1509
1509
  <body>
1510
1510
  <div class="workflow-visualizer">
1511
1511
  <header class="wv-header">
1512
- <h1>${Ze(s)}</h1>
1512
+ <h1>${Ze(d)}</h1>
1513
1513
  <div class="wv-controls">
1514
1514
  ${t.interactive?`
1515
1515
  <button id="load-json-btn" class="wv-btn" title="Load workflow state from JSON">Load JSON</button>
@@ -1671,12 +1671,12 @@ body {
1671
1671
  ${t.heatmapData?`window.__PERFORMANCE_DATA__ = ${kt({heat:Object.fromEntries(t.heatmapData.heat),metric:t.heatmapData.metric,stats:t.heatmapData.stats})};`:""}
1672
1672
  })();
1673
1673
  </script>
1674
- <script>${d}</script>
1674
+ <script>${s}</script>
1675
1675
  </body>
1676
- </html>`}function Ze(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Rt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function tn(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function rn(e){if(!e.hooks)return e;let t=e.hooks.onAfterStep instanceof Map?Object.fromEntries(e.hooks.onAfterStep):e.hooks.onAfterStep;return{...e,hooks:{...e.hooks,onAfterStep:t}}}function kt(e){let t=new WeakSet;return JSON.stringify(e,(o,a)=>{if(typeof a=="bigint")return a.toString();if(o==="error"&&a!==void 0&&a!==null)return String(a);if(typeof a=="object"&&a!==null){if(t.has(a))return"[Circular]";t.add(a)}return a}).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}var Et={interactive:!0,timeTravel:!0,heatmap:!0,animationDuration:200,theme:"auto",layout:"TB"};function nn(){return{name:"html",supportsLive:!0,render(e,t){let r={...t,...Et,...t};return It(e,r)}}}function on(e,t={}){let r={showTimings:!0,showKeys:!1,colors:{pending:"#6c757d",running:"#ffc107",success:"#198754",error:"#dc3545",aborted:"#6c757d",cached:"#0dcaf0",skipped:"#adb5bd"},...Et,...t};return It(e,r)}var de={clearToEnd:"\x1B[J",cursorUp:e=>`\x1B[${e}A`,cursorToStart:"\x1B[G",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",saveCursor:"\x1B[s",restoreCursor:"\x1B[u"};function an(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,stream:i=process.stdout,updateInterval:s=100}=e,u=ce({detectParallel:r}),d=ae(),l,p={showTimings:o,showKeys:a,terminalWidth:i.columns??80,colors:{...K,...n}},f=!1,m="",w=0,k=null,T=!1;function $(D){i.writable&&i.write(D)}function M(){if(!f)return;let D=y(),v=d.render(D,p);v!==m&&(w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(v),$(`
1677
- `),m=v,w=v.split(`
1678
- `).length)}function I(){f&&(T=!0,k===null&&(k=setTimeout(()=>{k=null,T&&(T=!1,M())},s)))}function S(D){if(D.type==="scope_start"||D.type==="scope_end"){x(D);return}u.handleEvent(D),"workflowName"in D&&typeof D.workflowName=="string"&&(l=D.workflowName),f&&(D.type==="workflow_start"||D.type==="workflow_success"||D.type==="workflow_error"?M():I())}function x(D){u.handleScopeEvent(D),f&&I()}function g(D){u.handleDecisionEvent(D),f&&I()}function y(){let D=u.getIR(),v=t??l??D.root.name;return v&&(D.root.name=v),D}function E(){return d.render(y(),p)}function C(){f||(f=!0,m="",w=0,$(de.hideCursor),M())}function N(){if(!f)return;f=!1,k!==null&&(clearTimeout(k),k=null);let D=y(),v=d.render(D,p);w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(v),$(`
1679
- `),$(de.showCursor)}function L(){k!==null&&(clearTimeout(k),k=null),T=!1,M()}function P(){u.reset(),m="",w=0}return{handleEvent:S,handleScopeEvent:x,handleDecisionEvent:g,getIR:y,render:E,start:C,stop:N,refresh:L,reset:P}}function Qe(e,t={}){let{condition:r,value:o,name:a,workflowId:n=crypto.randomUUID(),emit:i}=t,s=Date.now(),u,d=[];function l(f,m,w){d.push({label:f,condition:w,taken:m}),m&&(u=f),i?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:f,condition:w,taken:m,ts:Date.now()})}function p(){let f=Date.now()-s;i?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:f})}return i?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:a,ts:s}),{takeBranch:l,end:p,getBranchTaken:()=>u,getBranches:()=>[...d]}}function sn(e,t,r={}){let o=Qe(e,{...r,condition:r.condition??String(t),value:r.value??t}),a=!1;return{...o,condition:t,then:()=>{a||(a=!0,o.takeBranch("if",!0),o.takeBranch("else",!1))},else:()=>{a||(a=!0,o.takeBranch("if",!1),o.takeBranch("else",!0))}}}function dn(e,t,r={}){let o=Qe(e,{...r,condition:r.condition??`switch(${String(t)})`,value:t});return{...o,value:t,case:(a,n)=>{o.takeBranch(`case '${a}'`,n,`value === '${a}'`)},default:a=>{o.takeBranch("default",a)}}}function cn(e={}){let{maxSnapshots:t=1e3,autoRecord:r=!0,builderOptions:o={}}=e,a=ce({detectParallel:!1,...o,enableSnapshots:r,maxSnapshots:t}),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},i=new Set,s=null;function u(){let N=S();for(let L of i)L(N)}function d(){n.snapshots=a.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(N){a.handleEvent(N),n.isRecording&&(d(),u())}function p(N){let L=a.getSnapshots();if(!(N<0||N>=L.length))return n.currentIndex=N,n.snapshots=L,u(),L[N].ir}function f(){return p(n.currentIndex+1)}function m(){return p(n.currentIndex-1)}function w(N=1){let L=a.getSnapshots();if(L.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=L),n.playbackSpeed=N,n.isPlaying=!0,u();let P=()=>{if(!n.isPlaying)return;let D=a.getSnapshots();if(n.currentIndex<D.length-1){let v=D[n.currentIndex],re=(D[n.currentIndex+1].timestamp-v.timestamp)/n.playbackSpeed;s=setTimeout(()=>{f(),P()},Math.max(16,re))}else k()};P()}function k(){n.isPlaying=!1,s&&(clearTimeout(s),s=null),u()}function T(){let N=a.getSnapshots();return n.currentIndex>=0&&n.currentIndex<N.length?N[n.currentIndex].ir:a.getIR()}function $(N){return a.getIRAt(N)}function M(){return a.getSnapshots()}function I(N){return a.getSnapshotAt(N)}function S(){return{snapshots:a.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function x(N){return i.add(N),()=>i.delete(N)}function g(){n.isRecording=!0,a.setSnapshotsEnabled(!0),d(),u()}function y(){n.isRecording=!1,a.setSnapshotsEnabled(!1),u()}function E(){k(),a.reset(),a.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function C(){return a}return{handleEvent:l,seek:p,stepForward:f,stepBackward:m,play:w,pause:k,getCurrentIR:T,getIRAt:$,getSnapshots:M,getSnapshotAt:I,getState:S,onStateChange:x,startRecording:g,stopRecording:y,reset:E,getBuilder:C}}function ln(e,t,r={}){let{title:o=t.workflowName,theme:a,mermaidCdnUrl:n="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"}=r,i=JSON.stringify(t,null,2);return`<!DOCTYPE html>
1676
+ </html>`}function Ze(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function It(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function tn(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function rn(e){if(!e.hooks)return e;let t=e.hooks.onAfterStep instanceof Map?Object.fromEntries(e.hooks.onAfterStep):e.hooks.onAfterStep;return{...e,hooks:{...e.hooks,onAfterStep:t}}}function kt(e){let t=new WeakSet;return JSON.stringify(e,(o,a)=>{if(typeof a=="bigint")return a.toString();if(o==="error"&&a!==void 0&&a!==null)return String(a);if(typeof a=="object"&&a!==null){if(t.has(a))return"[Circular]";t.add(a)}return a}).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}var Et={interactive:!0,timeTravel:!0,heatmap:!0,animationDuration:200,theme:"auto",layout:"TB"};function nn(){return{name:"html",supportsLive:!0,render(e,t){let r={...t,...Et,...t};return Rt(e,r)}}}function on(e,t={}){let r={showTimings:!0,showKeys:!1,colors:{pending:"#6c757d",running:"#ffc107",success:"#198754",error:"#dc3545",aborted:"#6c757d",cached:"#0dcaf0",skipped:"#adb5bd"},...Et,...t};return Rt(e,r)}var de={clearToEnd:"\x1B[J",cursorUp:e=>`\x1B[${e}A`,cursorToStart:"\x1B[G",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",saveCursor:"\x1B[s",restoreCursor:"\x1B[u"};function an(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,stream:i=process.stdout,updateInterval:d=100}=e,u=ce({detectParallel:r}),s=ae(),l,p={showTimings:o,showKeys:a,terminalWidth:i.columns??80,colors:{...K,...n}},g=!1,f="",w=0,k=null,M=!1;function $(O){i.writable&&i.write(O)}function T(){if(!g)return;let O=y(),v=s.render(O,p);v!==f&&(w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(v),$(`
1677
+ `),f=v,w=v.split(`
1678
+ `).length)}function R(){g&&(M=!0,k===null&&(k=setTimeout(()=>{k=null,M&&(M=!1,T())},d)))}function S(O){if(O.type==="scope_start"||O.type==="scope_end"){x(O);return}u.handleEvent(O),"workflowName"in O&&typeof O.workflowName=="string"&&(l=O.workflowName),g&&(O.type==="workflow_start"||O.type==="workflow_success"||O.type==="workflow_error"?T():R())}function x(O){u.handleScopeEvent(O),g&&R()}function h(O){u.handleDecisionEvent(O),g&&R()}function y(){let O=u.getIR(),v=t??l??O.root.name;return v&&(O.root.name=v),O}function E(){return s.render(y(),p)}function C(){g||(g=!0,f="",w=0,$(de.hideCursor),T())}function N(){if(!g)return;g=!1,k!==null&&(clearTimeout(k),k=null);let O=y(),v=s.render(O,p);w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(v),$(`
1679
+ `),$(de.showCursor)}function L(){k!==null&&(clearTimeout(k),k=null),M=!1,T()}function P(){u.reset(),f="",w=0}return{handleEvent:S,handleScopeEvent:x,handleDecisionEvent:h,getIR:y,render:E,start:C,stop:N,refresh:L,reset:P}}function Qe(e,t={}){let{condition:r,value:o,name:a,workflowId:n=crypto.randomUUID(),emit:i}=t,d=Date.now(),u,s=[];function l(g,f,w){s.push({label:g,condition:w,taken:f}),f&&(u=g),i?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:g,condition:w,taken:f,ts:Date.now()})}function p(){let g=Date.now()-d;i?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:g})}return i?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:a,ts:d}),{takeBranch:l,end:p,getBranchTaken:()=>u,getBranches:()=>[...s]}}function sn(e,t,r={}){let o=Qe(e,{...r,condition:r.condition??String(t),value:r.value??t}),a=!1;return{...o,condition:t,then:()=>{a||(a=!0,o.takeBranch("if",!0),o.takeBranch("else",!1))},else:()=>{a||(a=!0,o.takeBranch("if",!1),o.takeBranch("else",!0))}}}function dn(e,t,r={}){let o=Qe(e,{...r,condition:r.condition??`switch(${String(t)})`,value:t});return{...o,value:t,case:(a,n)=>{o.takeBranch(`case '${a}'`,n,`value === '${a}'`)},default:a=>{o.takeBranch("default",a)}}}function cn(e={}){let{maxSnapshots:t=1e3,autoRecord:r=!0,builderOptions:o={}}=e,a=ce({detectParallel:!1,...o,enableSnapshots:r,maxSnapshots:t}),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},i=new Set,d=null;function u(){let N=S();for(let L of i)L(N)}function s(){n.snapshots=a.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(N){a.handleEvent(N),n.isRecording&&(s(),u())}function p(N){let L=a.getSnapshots();if(!(N<0||N>=L.length))return n.currentIndex=N,n.snapshots=L,u(),L[N].ir}function g(){return p(n.currentIndex+1)}function f(){return p(n.currentIndex-1)}function w(N=1){let L=a.getSnapshots();if(L.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=L),n.playbackSpeed=N,n.isPlaying=!0,u();let P=()=>{if(!n.isPlaying)return;let O=a.getSnapshots();if(n.currentIndex<O.length-1){let v=O[n.currentIndex],re=(O[n.currentIndex+1].timestamp-v.timestamp)/n.playbackSpeed;d=setTimeout(()=>{g(),P()},Math.max(16,re))}else k()};P()}function k(){n.isPlaying=!1,d&&(clearTimeout(d),d=null),u()}function M(){let N=a.getSnapshots();return n.currentIndex>=0&&n.currentIndex<N.length?N[n.currentIndex].ir:a.getIR()}function $(N){return a.getIRAt(N)}function T(){return a.getSnapshots()}function R(N){return a.getSnapshotAt(N)}function S(){return{snapshots:a.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function x(N){return i.add(N),()=>i.delete(N)}function h(){n.isRecording=!0,a.setSnapshotsEnabled(!0),s(),u()}function y(){n.isRecording=!1,a.setSnapshotsEnabled(!1),u()}function E(){k(),a.reset(),a.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function C(){return a}return{handleEvent:l,seek:p,stepForward:g,stepBackward:f,play:w,pause:k,getCurrentIR:M,getIRAt:$,getSnapshots:T,getSnapshotAt:R,getState:S,onStateChange:x,startRecording:h,stopRecording:y,reset:E,getBuilder:C}}function ln(e,t,r={}){let{title:o=t.workflowName,theme:a,mermaidCdnUrl:n="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"}=r,i=JSON.stringify(t,null,2);return`<!DOCTYPE html>
1680
1680
  <html lang="en">
1681
1681
  <head>
1682
1682
  <meta charset="UTF-8">
@@ -2649,5 +2649,5 @@ ${pn()}
2649
2649
  var initialTheme = resolveTheme();
2650
2650
  applyTheme(initialTheme);
2651
2651
  })();
2652
- `}function Se(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function et(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,export:i}=e,s=ce({detectParallel:r}),u=new Set,d,l=ae(),p=ie(),f=Be(),m=he(),w={showTimings:o,showKeys:a,terminalWidth:process.stdout?.columns??80,colors:{...K,...n}};function k(){if(u.size>0){let v=I();for(let O of u)O(v)}}function T(v){if(v.type==="scope_start"||v.type==="scope_end"){$(v);return}s.handleEvent(v),"workflowName"in v&&typeof v.workflowName=="string"&&(d=v.workflowName),k()}function $(v){s.handleScopeEvent(v),k()}function M(v){s.handleDecisionEvent(v),k()}function I(){let v=s.getIR(),O=t??d??v.root.name;return O&&(v.root.name=O),v}function S(){let v=I();return l.render(v,w)}function x(v){let O=I();switch(v){case"ascii":return l.render(O,w);case"mermaid":return p.render(O,w);case"json":{let J=O.hooks?{...O,hooks:{...O.hooks,onAfterStep:O.hooks.onAfterStep instanceof Map?Object.fromEntries(O.hooks.onAfterStep):O.hooks.onAfterStep??{}}}:O;return JSON.stringify(J,(tt,be)=>typeof be=="bigint"?be.toString():be,2)}case"logger":return f.render(O,w);case"flowchart":return m.render(O,w);default:throw new Error(`Unknown format: ${v}`)}}function g(){s.reset(),k()}function y(v){return u.add(v),()=>u.delete(v)}function E(v,O){if(v)return v;if(i?.default)return i.default;throw new Error(`${O}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function C(){let v=I();return{kind:"mermaid",source:p.render(v,w)}}function N(v){let O=xe(C(),"svg",E(v,"toSvgUrl"),{caller:"toSvgUrl"});if(!O.ok)throw new Error(`toSvgUrl: Export failed - ${O.error}`);return O.value}function L(v){let O=xe(C(),"png",E(v,"toPngUrl"),{caller:"toPngUrl"});if(!O.ok)throw new Error(`toPngUrl: Export failed - ${O.error}`);return O.value}function P(v){let O=xe(C(),"pdf",E(v,"toPdfUrl"),{caller:"toPdfUrl"});if(!O.ok)throw new Error(`toPdfUrl: Export failed - ${O.error}`);return O.value}function D(v,O){switch(v){case"svg":return N(O);case"png":return L(O);case"pdf":return P(O);default:return v}}return{handleEvent:T,handleScopeEvent:$,handleDecisionEvent:M,getIR:I,render:S,renderAs:x,reset:g,onUpdate:y,toUrl:D,toSvgUrl:N,toPngUrl:L,toPdfUrl:P}}function Io(...e){return(t,r)=>{for(let o of e)o(t,r)}}function Ro(e,t={}){let r=et(t);for(let o of e)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()}function Eo(e={}){let t=[];return{handleEvent:r=>{t.push(r)},handleDecisionEvent:r=>{t.push(r)},getEvents:()=>[...t],getWorkflowEvents:()=>t.filter(r=>!r.type.startsWith("decision_")),getDecisionEvents:()=>t.filter(r=>r.type.startsWith("decision_")),clear:()=>{t.length=0},visualize:()=>{let r=et(e);for(let o of t)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()},visualizeAs:r=>{let o=et(e);for(let a of t)a.type.startsWith("decision_")?o.handleDecisionEvent(a):o.handleEvent(a);return o.renderAs(r)}}}export{ae as asciiRenderer,Pe as buildMermaidInkUrl,Io as combineEventHandlers,Eo as createEventCollector,ce as createIRBuilder,an as createLiveVisualizer,Vr as createMermaidInkGenerator,Dt as createParallelDetector,Xt as createPerformanceAnalyzer,cn as createTimeTravelController,Ar as createUrlGenerator,et as createVisualizer,K as defaultColorScheme,Ee as detectParallelGroups,wt as encodeForMermaidInk,Se as escapeHtml,he as flowchartRenderer,ln as generateInteractiveHTML,ve as getHeatLevel,wn as hasChildren,nn as htmlRenderer,X as isDecisionNode,G as isParallelNode,z as isRaceNode,rt as isSequenceNode,V as isStepNode,ne as isStreamNode,Be as loggerRenderer,ie as mermaidRenderer,on as renderToHTML,xe as toExportUrl,Br as toKrokiPngUrl,Wr as toKrokiSvgUrl,ue as toKrokiUrl,zr as toMermaidInkJpegUrl,jr as toMermaidInkPdfUrl,Ur as toMermaidInkPngUrl,Fr as toMermaidInkSvgUrl,Y as toMermaidInkUrl,Kr as toMermaidInkWebpUrl,Qe as trackDecision,sn as trackIf,dn as trackSwitch,Ro as visualizeEvents};
2652
+ `}function Se(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function et(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:a=!1,colors:n,export:i}=e,d=ce({detectParallel:r}),u=new Set,s,l=ae(),p=ie(),g=Be(),f=ge(),w={showTimings:o,showKeys:a,terminalWidth:process.stdout?.columns??80,colors:{...K,...n}};function k(){if(u.size>0){let v=R();for(let D of u)D(v)}}function M(v){if(v.type==="scope_start"||v.type==="scope_end"){$(v);return}d.handleEvent(v),"workflowName"in v&&typeof v.workflowName=="string"&&(s=v.workflowName),k()}function $(v){d.handleScopeEvent(v),k()}function T(v){d.handleDecisionEvent(v),k()}function R(){let v=d.getIR(),D=t??s??v.root.name;return D&&(v.root.name=D),v}function S(){let v=R();return l.render(v,w)}function x(v){let D=R();switch(v){case"ascii":return l.render(D,w);case"mermaid":return p.render(D,w);case"json":{let J=D.hooks?{...D,hooks:{...D.hooks,onAfterStep:D.hooks.onAfterStep instanceof Map?Object.fromEntries(D.hooks.onAfterStep):D.hooks.onAfterStep??{}}}:D;return JSON.stringify(J,(tt,be)=>typeof be=="bigint"?be.toString():be,2)}case"logger":return g.render(D,w);case"flowchart":return f.render(D,w);default:throw new Error(`Unknown format: ${v}`)}}function h(){d.reset(),k()}function y(v){return u.add(v),()=>u.delete(v)}function E(v,D){if(v)return v;if(i?.default)return i.default;throw new Error(`${D}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function C(){let v=R();return{kind:"mermaid",source:p.render(v,w)}}function N(v){let D=xe(C(),"svg",E(v,"toSvgUrl"),{caller:"toSvgUrl"});if(!D.ok)throw new Error(`toSvgUrl: Export failed - ${D.error}`);return D.value}function L(v){let D=xe(C(),"png",E(v,"toPngUrl"),{caller:"toPngUrl"});if(!D.ok)throw new Error(`toPngUrl: Export failed - ${D.error}`);return D.value}function P(v){let D=xe(C(),"pdf",E(v,"toPdfUrl"),{caller:"toPdfUrl"});if(!D.ok)throw new Error(`toPdfUrl: Export failed - ${D.error}`);return D.value}function O(v,D){switch(v){case"svg":return N(D);case"png":return L(D);case"pdf":return P(D);default:return v}}return{handleEvent:M,handleScopeEvent:$,handleDecisionEvent:T,getIR:R,render:S,renderAs:x,reset:h,onUpdate:y,toUrl:O,toSvgUrl:N,toPngUrl:L,toPdfUrl:P}}function Ro(...e){return(t,r)=>{for(let o of e)o(t,r)}}function Io(e,t={}){let r=et(t);for(let o of e)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()}function Eo(e={}){let t=[];return{handleEvent:r=>{t.push(r)},handleDecisionEvent:r=>{t.push(r)},getEvents:()=>[...t],getWorkflowEvents:()=>t.filter(r=>!r.type.startsWith("decision_")),getDecisionEvents:()=>t.filter(r=>r.type.startsWith("decision_")),clear:()=>{t.length=0},visualize:()=>{let r=et(e);for(let o of t)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()},visualizeAs:r=>{let o=et(e);for(let a of t)a.type.startsWith("decision_")?o.handleDecisionEvent(a):o.handleEvent(a);return o.renderAs(r)}}}export{ae as asciiRenderer,Pe as buildMermaidInkUrl,Ro as combineEventHandlers,Eo as createEventCollector,ce as createIRBuilder,an as createLiveVisualizer,Vr as createMermaidInkGenerator,Ot as createParallelDetector,Xt as createPerformanceAnalyzer,cn as createTimeTravelController,Ar as createUrlGenerator,et as createVisualizer,K as defaultColorScheme,Ee as detectParallelGroups,wt as encodeForMermaidInk,Se as escapeHtml,ge as flowchartRenderer,ln as generateInteractiveHTML,ve as getHeatLevel,wn as hasChildren,nn as htmlRenderer,X as isDecisionNode,G as isParallelNode,z as isRaceNode,rt as isSequenceNode,V as isStepNode,ne as isStreamNode,Be as loggerRenderer,ie as mermaidRenderer,on as renderToHTML,xe as toExportUrl,Br as toKrokiPngUrl,Wr as toKrokiSvgUrl,ue as toKrokiUrl,zr as toMermaidInkJpegUrl,jr as toMermaidInkPdfUrl,Ur as toMermaidInkPngUrl,Fr as toMermaidInkSvgUrl,Y as toMermaidInkUrl,Kr as toMermaidInkWebpUrl,Qe as trackDecision,sn as trackIf,dn as trackSwitch,Io as visualizeEvents};
2653
2653
  //# sourceMappingURL=index.js.map