awaitly-visualizer 23.0.1 → 25.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/devtools.cjs +6 -6
  2. package/dist/devtools.cjs.map +1 -1
  3. package/dist/devtools.d.cts +3 -4
  4. package/dist/devtools.d.ts +3 -4
  5. package/dist/devtools.js +4 -4
  6. package/dist/devtools.js.map +1 -1
  7. package/dist/index.browser.cjs +14 -14
  8. package/dist/index.browser.cjs.map +1 -1
  9. package/dist/index.browser.d.cts +4 -5
  10. package/dist/index.browser.d.ts +4 -5
  11. package/dist/index.browser.js +14 -14
  12. package/dist/index.browser.js.map +1 -1
  13. package/dist/index.cjs +24 -24
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +25 -6
  16. package/dist/index.d.ts +25 -6
  17. package/dist/index.js +24 -24
  18. package/dist/index.js.map +1 -1
  19. package/dist/kroki/fetch.cjs +2 -2
  20. package/dist/kroki/fetch.cjs.map +1 -1
  21. package/dist/kroki/fetch.d.cts +1 -2
  22. package/dist/kroki/fetch.d.ts +1 -2
  23. package/dist/kroki/fetch.js +2 -2
  24. package/dist/kroki/fetch.js.map +1 -1
  25. package/dist/notifiers/discord.cjs +2 -2
  26. package/dist/notifiers/discord.cjs.map +1 -1
  27. package/dist/notifiers/discord.d.cts +2 -3
  28. package/dist/notifiers/discord.d.ts +2 -3
  29. package/dist/notifiers/discord.js +2 -2
  30. package/dist/notifiers/discord.js.map +1 -1
  31. package/dist/notifiers/slack.cjs +24 -24
  32. package/dist/notifiers/slack.cjs.map +1 -1
  33. package/dist/notifiers/slack.d.cts +2 -3
  34. package/dist/notifiers/slack.d.ts +2 -3
  35. package/dist/notifiers/slack.js +24 -24
  36. package/dist/notifiers/slack.js.map +1 -1
  37. package/dist/notifiers/webhook.cjs +2 -2
  38. package/dist/notifiers/webhook.cjs.map +1 -1
  39. package/dist/notifiers/webhook.d.cts +2 -3
  40. package/dist/notifiers/webhook.d.ts +2 -3
  41. package/dist/notifiers/webhook.js +2 -2
  42. package/dist/notifiers/webhook.js.map +1 -1
  43. package/dist/{performance-analyzer-ffmMicjZ.d.ts → performance-analyzer-BCzSirud.d.ts} +1 -1
  44. package/dist/{performance-analyzer-C9WFkUSa.d.cts → performance-analyzer-dTsqap8v.d.cts} +1 -1
  45. package/dist/{types-BmktN16n.d.cts → types-Cxa5QZ0j.d.cts} +1 -1
  46. package/dist/{types-Bmb5LpD-.d.ts → types-J_mgQ3lz.d.ts} +1 -1
  47. package/dist/{url-CxqaR2K3.d.cts → url-DD8-D8H4.d.cts} +4 -4
  48. package/dist/{url-CxqaR2K3.d.ts → url-DD8-D8H4.d.ts} +4 -4
  49. package/package.json +6 -6
package/dist/index.d.cts CHANGED
@@ -1,11 +1,30 @@
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-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';
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-DD8-D8H4.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-DD8-D8H4.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-dTsqap8v.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-Cxa5QZ0j.cjs';
7
7
  import { Result } from 'awaitly';
8
- import 'awaitly/core';
8
+
9
+ /**
10
+ * devEvents — stream workflow events into the awaitly dev inspector.
11
+ *
12
+ * Wire it to any workflow's onEvent and every run appears live in the
13
+ * inspector page served by `awaitly-analyze --dev`:
14
+ *
15
+ * ```typescript
16
+ * import { devEvents } from "awaitly-visualizer";
17
+ *
18
+ * const workflow = createWorkflow("checkout", deps, {
19
+ * onEvent: devEvents("http://localhost:4747"),
20
+ * });
21
+ * ```
22
+ *
23
+ * Events are batched per microtask and POSTed fire-and-forget; a dead or
24
+ * absent inspector never affects the workflow.
25
+ */
26
+
27
+ declare function devEvents(url?: string): (event: WorkflowEvent<unknown, unknown>) => void;
9
28
 
10
29
  /**
11
30
  * Unified Export URL Generation
@@ -377,4 +396,4 @@ declare function createEventCollector(options?: VisualizerOptions): {
377
396
  visualizeAs: (format: OutputFormat) => string;
378
397
  };
379
398
 
380
- export { type CollectableEvent, DecisionBranchEvent, DecisionEndEvent, DecisionStartEvent, DiagramSource, ExportFormat, ExportOptions, type InteractiveHTMLOptions, type MermaidHTMLRetryConfig, type MermaidHTMLSourceLocation, type MermaidHTMLTimeoutConfig, type NodeMetadata, OutputFormat, ScopeEndEvent, ScopeStartEvent, VisualizerOptions, WorkflowIR, type WorkflowMetadata, type WorkflowVisualizer, combineEventHandlers, createEventCollector, createVisualizer, escapeHtml, generateInteractiveHTML, toExportUrl, visualizeEvents };
399
+ export { type CollectableEvent, DecisionBranchEvent, DecisionEndEvent, DecisionStartEvent, DiagramSource, ExportFormat, ExportOptions, type InteractiveHTMLOptions, type MermaidHTMLRetryConfig, type MermaidHTMLSourceLocation, type MermaidHTMLTimeoutConfig, type NodeMetadata, OutputFormat, ScopeEndEvent, ScopeStartEvent, VisualizerOptions, WorkflowIR, type WorkflowMetadata, type WorkflowVisualizer, combineEventHandlers, createEventCollector, createVisualizer, devEvents, escapeHtml, generateInteractiveHTML, toExportUrl, visualizeEvents };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,30 @@
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-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';
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-DD8-D8H4.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-DD8-D8H4.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-BCzSirud.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-J_mgQ3lz.js';
7
7
  import { Result } from 'awaitly';
8
- import 'awaitly/core';
8
+
9
+ /**
10
+ * devEvents — stream workflow events into the awaitly dev inspector.
11
+ *
12
+ * Wire it to any workflow's onEvent and every run appears live in the
13
+ * inspector page served by `awaitly-analyze --dev`:
14
+ *
15
+ * ```typescript
16
+ * import { devEvents } from "awaitly-visualizer";
17
+ *
18
+ * const workflow = createWorkflow("checkout", deps, {
19
+ * onEvent: devEvents("http://localhost:4747"),
20
+ * });
21
+ * ```
22
+ *
23
+ * Events are batched per microtask and POSTed fire-and-forget; a dead or
24
+ * absent inspector never affects the workflow.
25
+ */
26
+
27
+ declare function devEvents(url?: string): (event: WorkflowEvent<unknown, unknown>) => void;
9
28
 
10
29
  /**
11
30
  * Unified Export URL Generation
@@ -377,4 +396,4 @@ declare function createEventCollector(options?: VisualizerOptions): {
377
396
  visualizeAs: (format: OutputFormat) => string;
378
397
  };
379
398
 
380
- export { type CollectableEvent, DecisionBranchEvent, DecisionEndEvent, DecisionStartEvent, DiagramSource, ExportFormat, ExportOptions, type InteractiveHTMLOptions, type MermaidHTMLRetryConfig, type MermaidHTMLSourceLocation, type MermaidHTMLTimeoutConfig, type NodeMetadata, OutputFormat, ScopeEndEvent, ScopeStartEvent, VisualizerOptions, WorkflowIR, type WorkflowMetadata, type WorkflowVisualizer, combineEventHandlers, createEventCollector, createVisualizer, escapeHtml, generateInteractiveHTML, toExportUrl, visualizeEvents };
399
+ export { type CollectableEvent, DecisionBranchEvent, DecisionEndEvent, DecisionStartEvent, DiagramSource, ExportFormat, ExportOptions, type InteractiveHTMLOptions, type MermaidHTMLRetryConfig, type MermaidHTMLSourceLocation, type MermaidHTMLTimeoutConfig, type NodeMetadata, OutputFormat, ScopeEndEvent, ScopeStartEvent, VisualizerOptions, WorkflowIR, type WorkflowMetadata, type WorkflowVisualizer, combineEventHandlers, createEventCollector, createVisualizer, devEvents, escapeHtml, generateInteractiveHTML, toExportUrl, visualizeEvents };
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 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=>`
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 s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?a.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(a.length<=1)return e;a.sort((s,l)=>s.startTs-l.startTs);let i=[],c=[a[0]];for(let s=1;s<a.length;s++){let l=a[s],p=Math.min(...c.map(M=>M.startTs)),g=Math.max(...c.map(M=>M.endTs)),h=l.startTs<=p+o,w=l.startTs<g;if(!h&&!w){i.push(c),c=[l];continue}let v=w?Math.min(l.endTs,g)-l.startTs:0;h||v>=r?c.push(l):(i.push(c),c=[l])}i.push(c);let u=[];for(let s of i){let l=Math.min(...s.map(p=>p.originalIndex));if(s.length===1)u.push({node:s[0].node,position:l});else{let p=s.map(v=>v.node),g=Math.min(...s.map(v=>v.startTs)),h=Math.max(...s.map(v=>v.endTs)),w={type:"parallel",id:`detected_parallel_${g}`,name:`${p.length} parallel steps`,state:Dt(p),mode:"all",children:p,startTs:g,endTs:h,durationMs:h-g};u.push({node:w,position:l})}}for(let{node:s,originalIndex:l}of n)u.push({node:s,position:l});return u.sort((s,l)=>s.position-l.position),u.map(s=>s.node)}function 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=Re(),c,u,s,l="pending",p,g,h=new Map,w=[],v=[],M=new Map,$=[],T=Date.now(),I=T,S={onAfterStep:new Map},x,b=[],y=0;function E(d){return d.stepId??d.stepKey??d.name??Re()}function C(d){if(w.length>0){w[w.length-1].children.push(d),I=Date.now();return}if(v.length>0){let f=v[v.length-1];for(let m of f.branches.values())if(m.taken){m.children.push(d),I=Date.now();return}f.pendingChildren.push(d),I=Date.now();return}$.push(d),I=Date.now()}function N(d){if(!n)return;let f=J(),m=new Map;for(let[W,q]of h)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(d),ir:structuredClone(f),timestamp:Date.now(),activeSteps:m};b.push(F),b.length>a&&b.shift(),y++}function L(d){switch(d.type){case"workflow_start":{$=[],s=void 0,g=void 0,p=void 0,h.clear(),w.length=0,v.length=0,M.clear(),c=d.workflowId,u=d.ts,l="running",T=Date.now(),I=T,x!==void 0&&x!==d.workflowId&&(S.shouldRun=void 0,S.onBeforeStart=void 0),x=d.workflowId,S.onAfterStep=new Map;break}case"workflow_success":l="success",s=d.ts,g=d.durationMs,I=Date.now();break;case"workflow_error":l="error",s=d.ts,p=d.error,g=d.durationMs,I=Date.now();break;case"workflow_cancelled":l="aborted",s=d.ts,g=d.durationMs,I=Date.now();break;case"step_start":{let f=E(d);h.set(f,{id:f,name:d.name,key:d.stepKey,startTs:d.ts,retryCount:0,timedOut:!1,metadata:d.metadata}),I=Date.now();break}case"step_success":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"success",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),h.delete(f)}break}case"step_error":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"error",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,error:d.error,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata},...d.diagnostics&&{errorDiagnostics:d.diagnostics}};C(F),h.delete(f)}break}case"step_aborted":{let f=E(d),m=h.get(f);if(m){let F={type:"step",id:m.id,name:m.name,key:m.key,state:"aborted",startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs},...m.metadata&&{metadata:m.metadata}};C(F),h.delete(f)}break}case"step_cache_hit":{let m={type:"step",id:E(d),name:d.name,key:d.stepKey,state:"cached",startTs:d.ts,endTs:d.ts,durationMs:0};C(m);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let f=E(d),m=h.get(f);m&&(m.timedOut=!0,m.timeoutMs=d.timeoutMs),I=Date.now();break}case"step_retry":{let f=E(d),m=h.get(f);m&&(m.retryCount=(d.attempt??1)-1),I=Date.now();break}case"step_retries_exhausted":I=Date.now();break;case"step_skipped":{let m={type:"step",id:E(d),name:d.name,key:d.stepKey,state:"skipped",startTs:d.ts,endTs:d.ts,durationMs:0,...d.metadata&&{metadata:d.metadata}};C(m);break}case"decision":{let f=d;if(f.phase==="start"){D({type:"decision_start",workflowId:d.workflowId,decisionId:f.decisionId,name:f.label??f.decisionId,condition:f.label,decisionValue:f.value,ts:f.ts}),D({type:"decision_branch",workflowId:d.workflowId,decisionId:f.decisionId,branchLabel:"then",condition:f.label,taken:f.branch==="then",ts:f.ts}),D({type:"decision_branch",workflowId:d.workflowId,decisionId:f.decisionId,branchLabel:"else",taken:f.branch==="else",ts:f.ts});break}if(f.phase==="end"){D({type:"decision_end",workflowId:d.workflowId,decisionId:f.decisionId,branchTaken:f.branch,ts:f.ts,durationMs:f.durationMs??0});break}let m={type:"decision",id:f.decisionId,name:f.label??f.decisionId,state:"success",startTs:f.ts,endTs:f.ts,durationMs:0,condition:f.label,decisionValue:f.value,branchTaken:f.branch,branches:[{label:"then",condition:f.label,taken:f.branch==="then",children:[]},{label:"else",taken:f.branch==="else",children:[]}]};C(m),I=Date.now();break}case"hook_should_run":{let f={type:"shouldRun",state:"success",ts:d.ts,durationMs:d.durationMs,context:{result:d.result,skipped:d.skipped}};S.shouldRun=f,x=d.workflowId,I=Date.now();break}case"hook_should_run_error":{let f={type:"shouldRun",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error};S.shouldRun=f,x=d.workflowId,I=Date.now();break}case"hook_before_start":{let f={type:"onBeforeStart",state:"success",ts:d.ts,durationMs:d.durationMs,context:{result:d.result,skipped:d.skipped}};S.onBeforeStart=f,x=d.workflowId,I=Date.now();break}case"hook_before_start_error":{let f={type:"onBeforeStart",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error};S.onBeforeStart=f,x=d.workflowId,I=Date.now();break}case"hook_after_step":{let f={type:"onAfterStep",state:"success",ts:d.ts,durationMs:d.durationMs,context:{stepKey:d.stepKey}};S.onAfterStep.set(d.stepKey,f),I=Date.now();break}case"hook_after_step_error":{let f={type:"onAfterStep",state:"error",ts:d.ts,durationMs:d.durationMs,error:d.error,context:{stepKey:d.stepKey}};S.onAfterStep.set(d.stepKey,f),I=Date.now();break}case"stream_created":{let f=`${d.workflowId}:${d.namespace}`;M.set(f,{id:Re(),namespace:d.namespace,startTs:d.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),I=Date.now();break}case"stream_write":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&(m.writeCount++,m.finalPosition=Math.max(m.finalPosition,d.position)),I=Date.now();break}case"stream_read":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&m.readCount++,I=Date.now();break}case"stream_close":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);if(m){m.streamState="closed",m.finalPosition=d.finalPosition;let F={type:"stream",id:m.id,namespace:m.namespace,state:"success",startTs:m.startTs,endTs:d.ts,durationMs:d.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:d.finalPosition,streamState:"closed",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(f)}I=Date.now();break}case"stream_error":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);if(m){m.streamState="error";let F={type:"stream",id:m.id,namespace:m.namespace,state:"error",error:d.error,startTs:m.startTs,endTs:d.ts,durationMs:d.ts-m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:d.position,streamState:"error",backpressureOccurred:m.backpressureOccurred};C(F),M.delete(f)}I=Date.now();break}case"stream_backpressure":{let f=`${d.workflowId}:${d.namespace}`,m=M.get(f);m&&(m.backpressureOccurred=!0),I=Date.now();break}}N(d)}function P(d){if(d.type==="scope_start")w.push({id:d.scopeId,name:d.name,type:d.scopeType,startTs:d.ts,children:[]}),I=Date.now();else if(d.type==="scope_end"){let f=w.findIndex(W=>W.id===d.scopeId);if(f===-1)return;for(;w.length>f+1;){let W=w.pop(),q=W.type==="race"?{type:"race",id:W.id,name:W.name,state:k(W.children),startTs:W.startTs,endTs:d.ts,children:W.children}:{type:"parallel",id:W.id,name:W.name,state:k(W.children),startTs:W.startTs,endTs:d.ts,children:W.children,mode:W.type==="allSettled"?"allSettled":"all"};w[w.length-1].children.push(q)}let[m]=w.splice(f,1),F=m.type==="race"?{type:"race",id:m.id,name:m.name,state:k(m.children),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,children:m.children,winnerId:d.winnerId}:{type:"parallel",id:m.id,name:m.name,state:k(m.children),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,children:m.children,mode:m.type==="allSettled"?"allSettled":"all"};C(F)}}function D(d){if(d.type==="decision_start")v.push({id:d.decisionId,name:d.name,condition:d.condition,decisionValue:d.decisionValue,startTs:d.ts,branches:new Map,pendingChildren:[]}),I=Date.now();else if(d.type==="decision_branch"){let f=v.find(m=>m.id===d.decisionId);if(f){let m=d.branchLabel,F=f.branches.get(m);if(F)F.taken=d.taken,d.taken&&f.pendingChildren.length>0&&(F.children.unshift(...f.pendingChildren),f.pendingChildren=[]);else{let W=d.taken?[...f.pendingChildren]:[];d.taken&&(f.pendingChildren=[]),f.branches.set(m,{label:d.branchLabel,condition:d.condition,taken:d.taken,children:W})}I=Date.now()}}else if(d.type==="decision_end"){let f=v.findIndex(m=>m.id===d.decisionId);if(f!==-1){let[m]=v.splice(f,1),F=v.splice(f),W=Array.from(m.branches.values());W.length===0&&m.pendingChildren.length>0&&(W=[{label:"default",taken:!0,children:[...m.pendingChildren]}]);let q=W.find(Ie=>Ie.taken)?.label,Tt={type:"decision",id:m.id,name:m.name,state:k(W.flatMap(Ie=>Ie.taken?Ie.children:[])),startTs:m.startTs,endTs:d.ts,durationMs:d.durationMs,condition:m.condition,decisionValue:m.decisionValue,branchTaken:d.branchTaken??q,branches:W};C(Tt),v.push(...F),I=Date.now()}}}function k(d){return d.length===0?"success":d.some(W=>W.state==="error")?"error":d.every(W=>W.state==="success"||W.state==="cached")?"success":d.some(W=>W.state==="running")?"running":"pending"}function O(){let d=[...$];for(let[,f]of h)d.push({type:"step",id:f.id,name:f.name,key:f.key,state:"running",startTs:f.startTs,...f.retryCount>0&&{retryCount:f.retryCount},...f.timedOut&&{timedOut:!0,timeoutMs:f.timeoutMs}});for(let[,f]of M)d.push({type:"stream",id:f.id,namespace:f.namespace,state:"running",startTs:f.startTs,writeCount:f.writeCount,readCount:f.readCount,finalPosition:f.finalPosition,streamState:f.streamState,backpressureOccurred:f.backpressureOccurred});return d}function J(){let d=O();t&&(d=Ee(d,r));let f={type:"workflow",id:c??i,workflowId:c??i,state:l,startTs:u,endTs:s,durationMs:g,children:d,error:p},m=S.shouldRun!==void 0||S.onBeforeStart!==void 0||S.onAfterStep.size>0;return{root:f,metadata:{createdAt:T,lastUpdatedAt:I},...m&&{hooks:S}}}function re(){c=void 0,u=void 0,s=void 0,l="pending",p=void 0,g=void 0,h.clear(),w.length=0,v.length=0,M.clear(),$=[],T=Date.now(),I=T,S={onAfterStep:new Map},x=void 0,b.length=0,y=0}function tt(){return[...b]}function be(d){return b[d]}function $t(d){return b[d]?.ir}function Mt(){b.length=0,y=0}return{handleEvent:L,handleScopeEvent:P,handleDecisionEvent:D,getIR:J,reset:re,getSnapshots:tt,getSnapshotAt:be,getIRAt:$t,clearSnapshots:Mt,get hasActiveSteps(){return h.size>0},get state(){return l},get snapshotCount(){return b.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(d){n=d}}}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 yn(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 c=(i-o)/n,u=Math.floor(c*(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",c=we(i);if(n.push(`${R.topLeft}${jt(o-2,c)}${R.topRight}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.hooks){let s=Vt(e.hooks,r);for(let l of s)n.push(`${R.vertical} ${Ue(l,a)}${R.vertical}`)}let u=Me(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${R.vertical} ${Ue(s,a)}${R.vertical}`);if(n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let s=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",p=`${$e(s,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 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,c=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,u;c!==void 0?u=at(n,c):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=c!==void 0?at(`[${p}]`,c):_(`[${p}]`);s+=` ${g}`}if(i.showSparklines&&i.timingHistory){let p=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);p&&p.length>1&&(s+=` ${_(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),h=p.durationMs!==void 0?_(` ${H(p.durationMs)}`):"";s+=` ${g}${h}`}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}]`),c=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(c+=` ${_(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(c+=_(" [backpressure]")),e.streamState==="closed"&&(c+=_(` pos:${e.finalPosition}`)),c}function Yt(e,t,r,o,a){let n=[],i=" ".repeat(o),c=ye(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${R.teeRight}${R.teeDown}${R.horizontal} ${c} ${we(u)}${s}`),e.children.length===0)n.push(`${i}${R.vertical} ${_("(operations not individually tracked)")}`),n.push(`${i}${R.vertical} ${_("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],h=l===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`;if(V(p))n.push(`${h} ${Ke(p,t,r,a)}`);else{let w=Me([p],t,r,o+1,a);for(let v of w)n.push(`${i}${R.vertical} ${v}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function Jt(e,t,r,o,a){let n=[],i=" ".repeat(o),c=ye(e.state,r),u=e.name??"race";if(n.push(`${i}${R.teeRight}\u26A1 ${c} ${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 s=0;s<e.children.length;s++){let l=e.children[s],g=s===e.children.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,w=e.winnerId&&l.id===e.winnerId?_(" (winner)"):"";if(V(l))n.push(`${g} ${Ke(l,t,r,a)}${w}`);else{let v=Me([l],t,r,o+1,a);for(let M of v)n.push(`${i}${R.vertical} ${M}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}function qt(e,t,r,o,a){let n=[],i=" ".repeat(o),c=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}${R.teeRight}${R.teeDown}${R.horizontal} ${c} ${we(u)}${s}${l}${p}`);for(let g=0;g<e.branches.length;g++){let h=e.branches[g],v=g===e.branches.length-1?`${i}${R.vertical} ${R.bottomLeft}`:`${i}${R.vertical} ${R.teeRight}`,M=h.taken?"\u2713":"\u2298",$=h.taken?r.success:r.skipped,T=Z(`${M} ${h.label}`,$),I=h.condition?_(` (${h.condition})`):"";if(n.push(`${v} ${T}${I}`),h.children.length>0){let S=Me(h.children,t,r,o+1,a);for(let x of S)n.push(`${i}${R.vertical} ${x}`)}else h.taken||n.push(`${i}${R.vertical} ${_("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${R.bottomLeft}${R.horizontal}${R.horizontal} ${_(`[${H(e.durationMs)}]`)}`),n}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 ke(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 b of S)switch(b.type){case"step_start":{let y=n(b);x.set(y,{retried:!1,timedOut:!1});break}case"step_retry":{let y=n(b),E=x.get(y);E&&(E.retried=!0);break}case"step_timeout":{let y=n(b),E=x.get(y);E&&(E.timedOut=!0);break}case"step_success":{let y=n(b),E=x.get(y),C=e.get(y)??[];C.push(b.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,r.set(y,P),x.delete(y);break}case"step_error":{let y=n(b),E=x.get(y),C=e.get(y)??[];C.push(b.durationMs),e.set(y,C);let N=t.get(y)??{retried:0,total:0};N.total++,E?.retried&&N.retried++,t.set(y,N);let L=o.get(y)??{timedOut:0,total:0};L.total++,E?.timedOut&&L.timedOut++,o.set(y,L);let P=r.get(y)??{errors:0,total:0};P.total++,P.errors++,r.set(y,P),x.delete(y);break}}}function c(S){i(S.events)}function u(S){a.push(S)}function s(S){a.length>0&&(i(a),a=[])}function l(S){let x=e.get(S);if(!x||x.length===0)return;let b=[...x].sort((D,k)=>D-k),E=b.reduce((D,k)=>D+k,0)/b.length,C=b.reduce((D,k)=>D+(k-E)**2,0)/b.length,N=t.get(S)??{retried:0,total:1},L=r.get(S)??{errors:0,total:1},P=o.get(S)??{timedOut:0,total:1};return{nodeId:S,avgDurationMs:E,minDurationMs:b[0],maxDurationMs:b[b.length-1],stdDevMs:Math.sqrt(C),samples:b.length,retryRate:N.total>0?N.retried/N.total:0,timeoutRate:P.total>0?P.timedOut/P.total:0,errorRate:L.total>0?L.errors/L.total:0,percentiles:{p50:Te(b,.5),p90:Te(b,.9),p95:Te(b,.95),p99:Te(b,.99)}}}function p(S){return l(S)}function g(S,x="duration"){let b=new Map,y=je(S.root.children),E=[];for(let k of y){let O=("key"in k?k.key:void 0)??k.id??k.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:k.id,value:re})}}if(E.length===0)return{heat:b,metric:x,stats:{min:0,max:0,mean:0,threshold:0}};let C=E.map(k=>k.value),N=Math.min(...C),L=Math.max(...C),P=C.reduce((k,O)=>k+O,0)/C.length,D=L-N||1;for(let{id:k,value:O}of E)b.set(k,(O-N)/D);return{heat:b,metric:x,stats:{min:N,max:L,mean:P,threshold:P+(L-P)*.5}}}function h(){let S=new Map;for(let x of e.keys()){let b=l(x);b&&S.set(x,b)}return S}function w(S=10){return[...h().values()].sort((b,y)=>y.avgDurationMs-b.avgDurationMs).slice(0,S)}function v(S=10){return[...h().values()].filter(b=>b.errorRate>0).sort((b,y)=>y.errorRate-b.errorRate).slice(0,S)}function M(S=10){return[...h().values()].filter(b=>b.retryRate>0).sort((b,y)=>y.retryRate-b.retryRate).slice(0,S)}function $(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function T(S){let x=JSON.parse(S);e.clear(),t.clear(),r.clear(),o.clear();for(let[b,y]of Object.entries(x.timingData??{}))e.set(b,y);for(let[b,y]of Object.entries(x.retryData??{}))t.set(b,y);for(let[b,y]of Object.entries(x.errorData??{}))r.set(b,y);for(let[b,y]of Object.entries(x.timeoutData??{}))o.set(b,y)}function I(){e.clear(),t.clear(),r.clear(),o.clear(),a=[]}return{addRun:c,addEvent:u,finalizeRun:s,getNodePerformance:p,getHeatmap:g,getSlowestNodes:w,getErrorProneNodes:v,getRetryProneNodes:M,getAllPerformance:h,exportData:$,importData:T,clear:I}}function er(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function 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",c=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${a}[["${i} shouldRun${u}${c}"]]:::${n}`),o=a}if(e.onBeforeStart){let a="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",c=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${a}[["${i} onBeforeStart${u}${c}"]]:::${n}`),o&&t.push(` ${o} --> ${a}`),o=a}return{lastHookId:o}}var 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,c=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 b=2;for(;De.has(`${s}_${b}`);)b++;s=`${s}_${b}`}De.add(s);let l=e.name??e.key??"Step",p=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,g=j(p),h=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",w="";switch(e.state){case"success":w="\u2713 ";break;case"error":w="\u2717 ";break;case"cached":w="\u{1F4BE} ";break;case"running":w="\u23F3 ";break;case"skipped":w="\u2298 ";break}let v="";if(e.input!==void 0){let b=typeof e.input=="string"?j(e.input):j(ct(e.input).slice(0,20));v+=`\\nin: ${b}`}if(e.output!==void 0&&e.state==="success"){let b=typeof e.output=="string"?j(e.output):j(ct(e.output).slice(0,20));v+=`\\nout: ${b}`}let M="",$=e.key??e.id;if(a&&$&&a.onAfterStep.has($)){let b=a.onAfterStep.get($),y=b.state==="success"?"\u2699":"\u26A0",E=t.showTimings&&b.durationMs!==void 0?` ${H(b.durationMs)}`:"";M=`\\n${y} hook${E}`}let T=(w+g+v+M+h).trim(),I,S=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(S!==void 0){let b=ke(S);I=rr(b)}else I=e.state;let x;switch(e.state){case"error":x=`{{"${T}"}}`;break;case"cached":x=`[("${T}")]`;break;case"skipped":x=`["${T}"]`;break;default:x=`["${T}"]`}if(r.push(` ${s}${x}:::${I}`),i&&e.retryCount!==void 0&&e.retryCount>0){let b=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${s} -.->|"${b}"| ${s}`)}if(c&&e.state==="error"&&e.error!==void 0){let b=`ERR_${s}`,y=j(String(e.error)).slice(0,30);r.push(` ${b}{{"${y}"}}`),r.push(` ${s} -->|error| ${b}`),r.push(` style ${b} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let b=`TO_${s}`,y=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${b}{{"\u23F1 Timeout ${y}"}}`),r.push(` ${s} -.->|timeout| ${b}`),r.push(` style ${b} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function dr(e,t,r,o,a){let n=me("parallel"),i=`${n}_fork`,c=`${n}_join`,u=ut(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let g=n,h=j(`${u}${s}`),w="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["${h}${v}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["${u}${s}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let l=[];for(let g of e.children){let h=Oe(g,t,r,o,a);r.push(` ${i} --> ${h.entryId}`),l.push(h.exitId)}r.push(` ${c}{"\u2713 Join"}`);for(let g of l)r.push(` ${g} --> ${c}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:c}}function cr(e,t,r,o,a){let n=me("race"),i=`${n}_start`,c=`${n}_end`,u=ut(e.name??"Race");if(e.children.length===0){let g=n,h=j(u),w="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${g}["\u26A1 ${h}${v}\\n${w}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let s=[],l;for(let g of e.children){let h=Oe(g,t,r,o,a),w=e.winnerId===g.id;r.push(` ${i} --> ${h.entryId}`),w&&(l=h.exitId),s.push({exitId:h.exitId,isWinner:w})}r.push(` ${c}(("\u2713 First"))`);for(let{exitId:g,isWinner:h}of s)h&&l?r.push(` ${g} ==>|\u{1F3C6} Winner| ${c}`):e.winnerId?r.push(` ${g} -. cancelled .-> ${c}`):r.push(` ${g} --> ${c}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:i,exitId:c}}function 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"),c=e.decisionValue!==void 0?` = ${j(String(e.decisionValue)).slice(0,30)}`:"",u=`${i}${c}`.trim();r.push(` ${n}{"${u}"}`);let s=[],l,p=new Set;for(let g of e.branches){let h=`${n}_${g.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(p.has(h)){let T=2;for(;p.has(`${h}_${T}`);)T++;h=`${h}_${T}`}p.add(h);let w=j(g.label),v=g.taken?`${w} \u2713`:`${w} skipped`,M=g.taken?":::success":":::skipped";r.push(` ${h}["${v}"]${M}`);let $=g.condition?`|${j(g.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${$} ${h}`),g.children.length>0){let T=h;for(let I of g.children){let S=Oe(I,t,r,o,a);r.push(` ${T} --> ${S.entryId}`),T=S.exitId}s.push(T),g.taken&&(l=T)}else s.push(h),g.taken&&(l=h)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function 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)}`:"",c=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${j(e.namespace)}\\n${a}${c}${i}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",r.push(` ${o}{{"${u}"}}:::${s}`),{entryId:o,exitId:o}}var B={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},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 c=ft(e,t,i);c===B.horizontal?A(e,t,i,B.cross):(c===" "||c===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 c=ft(e,i,t);c===B.vertical?A(e,i,t,B.cross):(c===" "||c===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=[],c=0;if(o){let s=Le("start","start",["\u25B6 Start"],"success",n,c);i.push(s),c=s.bottomY+fe}for(let s of e.root.children){let l=_e(s,n,c,r-4,t,a);i.push(l.node),c=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,c);i.push(l),c=l.bottomY}return{nodes:i,totalHeight:c+2}}function Le(e,t,r,o,a,n){let i=Math.max(...r.map(l=>te(l).length)),c=Math.max(Q,i+ee*2),u=r.length+2,s=a-Math.floor(c/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:c,height:u,centerX:a,bottomY:n+u-1}}function _e(e,t,r,o,a,n){if(V(e))return wr(e,t,r,o,a,n);if(G(e)||z(e))return kr(e,t,r,o,a,n);if(X(e))return vr(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",c=ht(e.state),u=[],s=`${c} ${i}`;a.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-ee*2,40);if(u.push(...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),h=u.length+2,w=t-Math.floor(g/2),v;if(n?.showHeatmap&&n.heatmapData){let $=e.key??e.name??e.id;v=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get($)}let M={id:e.id,type:"step",label:u,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1,metadata:v!==void 0?{heat:v}:void 0};return{node:M,bottomY:M.bottomY}}function yr(e,t,r,o,a,n){let i=`stream:${e.namespace}`,c=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${c} ${i}`,l=Math.min(o-ee*2,40);u.push(...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),h=u.length+2,w=t-Math.floor(g/2),v={id:e.id,type:"stream",label:u,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:v,bottomY:v.bottomY}}function kr(e,t,r,o,a,n){let i=z(e),c=e.name??(i?"race":"parallel"),s=`${i?"\u26A1":"\u2AD8"} ${c}`;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),h=g>o&&e.children.length>1,w=Math.max(Q,s.length+ee*2),v=3,M=t-Math.floor(w/2),$=r;$+=v,$+=1,$+=1;let T=[];if(h)for(let y=0;y<e.children.length;y++){let E=e.children[y],C=_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 I=Math.max(...T.map(y=>y.bottomY)),x=!h&&T.length>1?I+2:I;return{node:{id:e.id,type:i?"race":"parallel",label:[s],state:e.state,x:M,y:r,width:w,height:v,centerX:t,bottomY:x,children:T,metadata:{verticalLayout:h}},bottomY:x}}function vr(e,t,r,o,a,n){let i=e.name??"decision",c=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${i}${c}`,s=Math.min(o-ee*2,40),l=Ge(u,s),p=Math.max(...l.map(x=>te(x).length)),g=Math.max(Q,p+ee*2),h=l.length+2,w=t-Math.floor(g/2),v=e.branches.find(x=>x.taken),M=v&&v.children.length>0?v:e.branches.find(x=>x.children.length>0);if(!M||M.children.length===0){let x={id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:r+h-1};return{node:x,bottomY:x.bottomY}}let $=r+h+fe,T=[];for(let x of M.children){let b=_e(x,t,$,o,a,n);T.push(b.node),$=b.bottomY+fe}let I=T.length>0?T[T.length-1].bottomY:r+h-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:w,y:r,width:g,height:h,centerX:t,bottomY:I,children:T},bottomY:I}}function 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 c=`${n} ${a}`;r.showKeys&&e.key&&e.name&&(c+=` [${e.key}]`);let u=Math.min(t,Math.max(Q,c.length+ee*2)),s=i+2;return{width:u,height:s}}if(G(e)||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 c of e.children){let u=Ve(c,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 c=Ve(i,t,r,o);n+=c.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)),c=n+2;return{width:i,height:c}}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 c=t[a+1],u=n.centerX,s=n.bottomY+1,l=c.centerX,p=c.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);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 c=0;c<t.label.length;c++){let u=t.label[c],s=t.x+1+Math.floor((n-te(u).length)/2),l=t.y+1+c;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):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 c=o[0];oe(e,n,a,c.y-2),le(e,c.centerX,c.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 c=o.map(l=>l.centerX),u=Math.min(...c),s=Math.max(...c);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 c of o)We(e,c,r);if(o.length>1){let c=o.map(h=>h.bottomY),u=Math.max(...c),s=u+1,l=o.map(h=>h.centerX),p=Math.min(...l),g=Math.max(...l);for(let h of o)h.bottomY<u&&oe(e,h.centerX,h.bottomY+1,s-1);mt(e,s,p,g);for(let h of o){let w=h.centerX;w===p?A(e,w,s,B.bottomLeft):w===g?A(e,w,s,B.bottomRight):A(e,w,s,B.teeUp)}A(e,t.centerX,s,B.teeDown),A(e,t.centerX,s+1,B.vertical)}}function 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 c=o[i];if(We(e,c,r),i<o.length-1){let u=o[i+1];oe(e,c.centerX,c.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=ke(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 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 c=new Map;for(let s of e){let l=s.metadata?.domain;if(l&&(s.state==="success"||s.state==="error")){let p=c.get(l)??{total:0,errors:0,totalDuration:0};p.total++,s.state==="error"&&p.errors++,s.durationMs!==void 0&&(p.totalDuration+=s.durationMs),c.set(l,p)}}let u;if(c.size>0){u={};for(let[s,l]of c)u[s]={total:l.total,errors:l.errors,avgDurationMs:l.total>0?Math.round(l.totalDuration/l.total):0}}return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:a,totalRetries:n,slowestStep:i,...u&&{byDomain:u}}}function 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 c=Dr(e.hooks);Object.keys(c).length>0&&(i.hooks=c)}if(a){let s=((t.diagramFormat??"ascii")==="flowchart"?he():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 ve}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"?ve("UNSUPPORTED_FORMAT"):He(void 0):ve("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 ve("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return ve("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 ve("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};
@@ -606,7 +606,7 @@ body {
606
606
  max-height: 95vh;
607
607
  }
608
608
  }
609
- `}function vt(e){return`
609
+ `}function kt(e){return`
610
610
  (function() {
611
611
  'use strict';
612
612
 
@@ -1475,15 +1475,15 @@ body {
1475
1475
  return min + 'm ' + sec + 's';
1476
1476
  }
1477
1477
  })();
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})">
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,c=U,u=0,s=0;for(let g of e){let h=qe(g,i,c,o,r);n.push(h.node),o?(c+=h.height+qr,u=Math.max(u,h.width),s=c):(i+=h.width+Je,s=Math.max(s,h.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: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,c=[],u=t+U,s=r+U+20,l=0;for(let w of e.children){let v=qe(w,u,s,!0,a);c.push(v.node),u+=v.width+Je,l=Math.max(l,v.height)}let p=u-t-U,g=Math.max(p+U,se+U*2),h=l+U*2+20;return{node:{id:e.id,name:i,type:n,state:e.state,x:t,y:r,width:g,height:h,durationMs:e.durationMs,children:c,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:g,height:h}}if(X(e)){let n=e.name??"decision",i=[],c=t+U,u=r+U+20,s=0;for(let g of e.branches)for(let h of g.children){let w=qe(h,c,u,!0,a);i.push(w.node),c+=w.width+Je,s=Math.max(s,w.height)}let l=Math.max(c-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: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})">
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="${It(e.id)}" transform="translate(${e.x}, ${e.y})">
1486
+ <g class="wv-container wv-container--${e.containerType}" data-node-id="${Rt(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})">
@@ -1496,20 +1496,20 @@ body {
1496
1496
  `)}else{let u=n.x+n.width/2,s=n.y+n.height,l=i.x+i.width/2,p=i.y;r.push(`
1497
1497
  <path class="wv-edge" d="M ${u} ${s} L ${l} ${p-8}" />
1498
1498
  <polygon class="wv-edge-arrow" points="${l-4},${p-8} ${l+4},${p-8} ${l},${p}" />
1499
- `)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let 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>
1499
+ `)}}function a(n){for(let i=0;i<n.length-1;i++)o(n[i],n[i+1]);for(let i of n)if(i.children&&i.children.length>0)if(i.containerType==="decision"){let c=Xe(t.root.children,i.id);if(c&&c.type==="decision"&&c.branches){let u=0;for(let s of c.branches){let l=s.children.length;l>0&&o(i,i.children[u]);for(let p=0;p<l-1;p++)o(i.children[u+p],i.children[u+p+1]);u+=l}}}else if(i.containerType==="parallel"||i.containerType==="race")for(let c of i.children)c.children&&c.children.length>0&&a([c]);else a(i.children)}return a(e),r.join(`
1500
+ `)}function 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),c=e.root.name??"Workflow",u=yt(t.theme),s=kt({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(d)} - Workflow Visualizer</title>
1506
+ <title>${Ze(c)} - Workflow Visualizer</title>
1507
1507
  <style>${u}</style>
1508
1508
  </head>
1509
1509
  <body>
1510
1510
  <div class="workflow-visualizer">
1511
1511
  <header class="wv-header">
1512
- <h1>${Ze(d)}</h1>
1512
+ <h1>${Ze(c)}</h1>
1513
1513
  <div class="wv-controls">
1514
1514
  ${t.interactive?`
1515
1515
  <button id="load-json-btn" class="wv-btn" title="Load workflow state from JSON">Load JSON</button>
@@ -1599,7 +1599,7 @@ body {
1599
1599
  <script>
1600
1600
  // Check if we have a saved IR in sessionStorage (from Load JSON)
1601
1601
  (function() {
1602
- let initialIR = ${kt(rn(e))};
1602
+ let initialIR = ${vt(rn(e))};
1603
1603
  try {
1604
1604
  const savedIR = sessionStorage.getItem('workflow_ir');
1605
1605
  if (savedIR) {
@@ -1668,15 +1668,15 @@ body {
1668
1668
 
1669
1669
  window.__WORKFLOW_DATA__ = buildWorkflowDataFromIR(irObj);
1670
1670
 
1671
- ${t.heatmapData?`window.__PERFORMANCE_DATA__ = ${kt({heat:Object.fromEntries(t.heatmapData.heat),metric:t.heatmapData.metric,stats:t.heatmapData.stats})};`:""}
1671
+ ${t.heatmapData?`window.__PERFORMANCE_DATA__ = ${vt({heat:Object.fromEntries(t.heatmapData.heat),metric:t.heatmapData.metric,stats:t.heatmapData.stats})};`:""}
1672
1672
  })();
1673
1673
  </script>
1674
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 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>
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 vt(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:c=100}=e,u=ce({detectParallel:r}),s=ae(),l,p={showTimings:o,showKeys:a,terminalWidth:i.columns??80,colors:{...K,...n}},g=!1,h="",w=0,v=null,M=!1;function $(D){i.writable&&i.write(D)}function T(){if(!g)return;let D=y(),k=s.render(D,p);k!==h&&(w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(k),$(`
1677
+ `),h=k,w=k.split(`
1678
+ `).length)}function I(){g&&(M=!0,v===null&&(v=setTimeout(()=>{v=null,M&&(M=!1,T())},c)))}function S(D){if(D.type==="scope_start"||D.type==="scope_end"){x(D);return}u.handleEvent(D),"workflowName"in D&&typeof D.workflowName=="string"&&(l=D.workflowName),g&&(D.type==="workflow_start"||D.type==="workflow_success"||D.type==="workflow_error"?T():I())}function x(D){u.handleScopeEvent(D),g&&I()}function b(D){u.handleDecisionEvent(D),g&&I()}function y(){let D=u.getIR(),k=t??l??D.root.name;return k&&(D.root.name=k),D}function E(){return s.render(y(),p)}function C(){g||(g=!0,h="",w=0,$(de.hideCursor),T())}function N(){if(!g)return;g=!1,v!==null&&(clearTimeout(v),v=null);let D=y(),k=s.render(D,p);w>0&&($(de.cursorUp(w)),$(de.cursorToStart),$(de.clearToEnd)),$(k),$(`
1679
+ `),$(de.showCursor)}function L(){v!==null&&(clearTimeout(v),v=null),M=!1,T()}function P(){u.reset(),h="",w=0}return{handleEvent:S,handleScopeEvent:x,handleDecisionEvent:b,getIR:y,render:E,start:C,stop:N,refresh:L,reset:P}}function sn(e="http://localhost:4747"){let t=`${e.replace(/\/$/,"")}/events`,r=[],o=!1,a=()=>{if(o=!1,r.length===0)return;let n=r;r=[];try{let i=JSON.stringify(n,(c,u)=>typeof u=="bigint"?u.toString():u);fetch(t,{method:"POST",headers:{"content-type":"application/json"},body:i}).catch(()=>{})}catch{}};return n=>{r.push(n),o||(o=!0,queueMicrotask(a))}}function Qe(e,t={}){let{condition:r,value:o,name:a,workflowId:n=crypto.randomUUID(),emit:i}=t,c=Date.now(),u,s=[];function l(g,h,w){s.push({label:g,condition:w,taken:h}),h&&(u=g),i?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:g,condition:w,taken:h,ts:Date.now()})}function p(){let g=Date.now()-c;i?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:g})}return i?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:a,ts:c}),{takeBranch:l,end:p,getBranchTaken:()=>u,getBranches:()=>[...s]}}function dn(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 cn(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 ln(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,c=null;function u(){let N=S();for(let L of i)L(N)}function s(){n.snapshots=a.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(N){a.handleEvent(N),n.isRecording&&(s(),u())}function p(N){let L=a.getSnapshots();if(!(N<0||N>=L.length))return n.currentIndex=N,n.snapshots=L,u(),L[N].ir}function g(){return p(n.currentIndex+1)}function h(){return p(n.currentIndex-1)}function w(N=1){let L=a.getSnapshots();if(L.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=L),n.playbackSpeed=N,n.isPlaying=!0,u();let P=()=>{if(!n.isPlaying)return;let D=a.getSnapshots();if(n.currentIndex<D.length-1){let k=D[n.currentIndex],re=(D[n.currentIndex+1].timestamp-k.timestamp)/n.playbackSpeed;c=setTimeout(()=>{g(),P()},Math.max(16,re))}else v()};P()}function v(){n.isPlaying=!1,c&&(clearTimeout(c),c=null),u()}function M(){let N=a.getSnapshots();return n.currentIndex>=0&&n.currentIndex<N.length?N[n.currentIndex].ir:a.getIR()}function $(N){return a.getIRAt(N)}function T(){return a.getSnapshots()}function I(N){return a.getSnapshotAt(N)}function S(){return{snapshots:a.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function x(N){return i.add(N),()=>i.delete(N)}function b(){n.isRecording=!0,a.setSnapshotsEnabled(!0),s(),u()}function y(){n.isRecording=!1,a.setSnapshotsEnabled(!1),u()}function E(){v(),a.reset(),a.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function C(){return a}return{handleEvent:l,seek:p,stepForward:g,stepBackward:h,play:w,pause:v,getCurrentIR:M,getIRAt:$,getSnapshots:T,getSnapshotAt:I,getState:S,onStateChange:x,startRecording:b,stopRecording:y,reset:E,getBuilder:C}}function un(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">
@@ -1687,7 +1687,7 @@ body {
1687
1687
  <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=DM+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
1688
1688
  <script src="${n}"></script>
1689
1689
  <style>
1690
- ${un()}
1690
+ ${pn()}
1691
1691
  </style>
1692
1692
  </head>
1693
1693
  <body>
@@ -1738,10 +1738,10 @@ ${e}
1738
1738
  <script>
1739
1739
  const WORKFLOW_DATA = ${i};
1740
1740
  const INITIAL_THEME = ${a?`"${a}"`:"null"};
1741
- ${pn()}
1741
+ ${mn()}
1742
1742
  </script>
1743
1743
  </body>
1744
- </html>`}function un(){return`
1744
+ </html>`}function pn(){return`
1745
1745
  /* ================================================================
1746
1746
  Theme Definitions \u2014 CSS custom properties per theme
1747
1747
  ================================================================ */
@@ -2301,7 +2301,7 @@ ${pn()}
2301
2301
  main { flex-direction: column; }
2302
2302
  #inspector { width: 100%; min-width: 100%; max-height: 40vh; border-left: none; border-top: 1px solid var(--border); }
2303
2303
  }
2304
- `}function pn(){return`
2304
+ `}function mn(){return`
2305
2305
  (function() {
2306
2306
  'use strict';
2307
2307
 
@@ -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,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};
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,c=ce({detectParallel:r}),u=new Set,s,l=ae(),p=ie(),g=Be(),h=he(),w={showTimings:o,showKeys:a,terminalWidth:process.stdout?.columns??80,colors:{...K,...n}};function v(){if(u.size>0){let k=I();for(let O of u)O(k)}}function M(k){if(k.type==="scope_start"||k.type==="scope_end"){$(k);return}c.handleEvent(k),"workflowName"in k&&typeof k.workflowName=="string"&&(s=k.workflowName),v()}function $(k){c.handleScopeEvent(k),v()}function T(k){c.handleDecisionEvent(k),v()}function I(){let k=c.getIR(),O=t??s??k.root.name;return O&&(k.root.name=O),k}function S(){let k=I();return l.render(k,w)}function x(k){let O=I();switch(k){case"ascii":return l.render(O,w);case"mermaid":return p.render(O,w);case"json":{let 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 g.render(O,w);case"flowchart":return h.render(O,w);default:throw new Error(`Unknown format: ${k}`)}}function b(){c.reset(),v()}function y(k){return u.add(k),()=>u.delete(k)}function E(k,O){if(k)return k;if(i?.default)return i.default;throw new Error(`${O}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function C(){let k=I();return{kind:"mermaid",source:p.render(k,w)}}function N(k){let O=xe(C(),"svg",E(k,"toSvgUrl"),{caller:"toSvgUrl"});if(!O.ok)throw new Error(`toSvgUrl: Export failed - ${O.error}`);return O.value}function L(k){let O=xe(C(),"png",E(k,"toPngUrl"),{caller:"toPngUrl"});if(!O.ok)throw new Error(`toPngUrl: Export failed - ${O.error}`);return O.value}function P(k){let O=xe(C(),"pdf",E(k,"toPdfUrl"),{caller:"toPdfUrl"});if(!O.ok)throw new Error(`toPdfUrl: Export failed - ${O.error}`);return O.value}function D(k,O){switch(k){case"svg":return N(O);case"png":return L(O);case"pdf":return P(O);default:return k}}return{handleEvent:M,handleScopeEvent:$,handleDecisionEvent:T,getIR:I,render:S,renderAs:x,reset:b,onUpdate:y,toUrl:D,toSvgUrl:N,toPngUrl:L,toPdfUrl:P}}function Eo(...e){return(t,r)=>{for(let o of e)o(t,r)}}function $o(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 Mo(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,Eo as combineEventHandlers,Mo as createEventCollector,ce as createIRBuilder,an as createLiveVisualizer,Vr as createMermaidInkGenerator,Ot as createParallelDetector,Xt as createPerformanceAnalyzer,ln as createTimeTravelController,Ar as createUrlGenerator,et as createVisualizer,K as defaultColorScheme,Ee as detectParallelGroups,sn as devEvents,wt as encodeForMermaidInk,Se as escapeHtml,he as flowchartRenderer,un as generateInteractiveHTML,ke as getHeatLevel,yn 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,dn as trackIf,cn as trackSwitch,$o as visualizeEvents};
2653
2653
  //# sourceMappingURL=index.js.map