awaitly-visualizer 24.0.0 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +12 -12
  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 +13 -13
  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 +4 -4
@@ -1,10 +1,9 @@
1
1
  import { WorkflowEvent } from 'awaitly/workflow';
2
2
  export { ScopeType } from 'awaitly/workflow';
3
- import { 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, g as DiagramSource, E as EnhancedRenderOptions, h as ExportFormat, i as ExportOptions, 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, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-C9WFkUSa.cjs';
6
- export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-BmktN16n.cjs';
7
- import 'awaitly/core';
3
+ import { 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, g as DiagramSource, E as EnhancedRenderOptions, h as ExportFormat, i as ExportOptions, 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, 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';
8
7
  import 'awaitly';
9
8
 
10
9
  /**
@@ -1,10 +1,9 @@
1
1
  import { WorkflowEvent } from 'awaitly/workflow';
2
2
  export { ScopeType } from 'awaitly/workflow';
3
- import { 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, g as DiagramSource, E as EnhancedRenderOptions, h as ExportFormat, i as ExportOptions, 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, j as createParallelDetector, k as createPerformanceAnalyzer, l as createTimeTravelController, m as defaultColorScheme, n as detectParallelGroups, o as flowchartRenderer, p as getHeatLevel, q as htmlRenderer, r as loggerRenderer, s as mermaidRenderer, t as renderToHTML, u as trackDecision, v as trackIf, w as trackSwitch } from './performance-analyzer-ffmMicjZ.js';
6
- export { D as DiagramProvider, K as KrokiProviderOptions, M as MermaidInkFormat, a as MermaidInkGenerator, b as MermaidInkImageType, c as MermaidInkOptions, d as MermaidInkPaperSize, e as MermaidInkProviderOptions, f as MermaidInkTheme, P as ProviderOptions, g as buildMermaidInkUrl, h as createMermaidInkGenerator, i as encodeForMermaidInk, t as toMermaidInkJpegUrl, j as toMermaidInkPdfUrl, k as toMermaidInkPngUrl, l as toMermaidInkSvgUrl, m as toMermaidInkUrl, n as toMermaidInkWebpUrl } from './types-Bmb5LpD-.js';
7
- import 'awaitly/core';
3
+ import { 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, g as DiagramSource, E as EnhancedRenderOptions, h as ExportFormat, i as ExportOptions, 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, 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';
8
7
  import 'awaitly';
9
8
 
10
9
  /**
@@ -1,7 +1,7 @@
1
- function A(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 ke(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function ve(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,i=[],n=[];for(let s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?i.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(i.length<=1)return e;i.sort((s,l)=>s.startTs-l.startTs);let a=[],d=[i[0]];for(let s=1;s<i.length;s++){let l=i[s],p=Math.min(...d.map($=>$.startTs)),h=Math.max(...d.map($=>$.endTs)),m=l.startTs<=p+o,y=l.startTs<h;if(!m&&!y){a.push(d),d=[l];continue}let v=y?Math.min(l.endTs,h)-l.startTs:0;m||v>=r?d.push(l):(a.push(d),d=[l])}a.push(d);let u=[];for(let s of a){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),h=Math.min(...s.map(v=>v.startTs)),m=Math.max(...s.map(v=>v.endTs)),y={type:"parallel",id:`detected_parallel_${h}`,name:`${p.length} parallel steps`,state:It(p),mode:"all",children:p,startTs:h,endTs:m,durationMs:m-h};u.push({node:y,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 It(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 $t(e={}){return{detect:t=>ve(t,e)}}function he(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:i=1e3}=e,n=o,a=ke(),d,u,s,l="pending",p,h,m=new Map,y=[],v=[],$=new Map,N=[],E=Date.now(),I=E,x={onAfterStep:new Map},S,w=[],g=0;function k(c){return c.stepId??c.stepKey??c.name??ke()}function T(c){if(y.length>0){y[y.length-1].children.push(c),I=Date.now();return}if(v.length>0){let b=v[v.length-1];for(let f of b.branches.values())if(f.taken){f.children.push(c),I=Date.now();return}b.pendingChildren.push(c),I=Date.now();return}N.push(c),I=Date.now()}function M(c){if(!n)return;let b=ne(),f=new Map;for(let[C,Y]of m)f.set(C,{id:Y.id,name:Y.name,key:Y.key,startTs:Y.startTs,retryCount:Y.retryCount,timedOut:Y.timedOut,timeoutMs:Y.timeoutMs});let P={id:`snapshot_${g}`,eventIndex:g,event:structuredClone(c),ir:structuredClone(b),timestamp:Date.now(),activeSteps:f};w.push(P),w.length>i&&w.shift(),g++}function O(c){switch(c.type){case"workflow_start":{N=[],s=void 0,h=void 0,p=void 0,m.clear(),y.length=0,v.length=0,$.clear(),d=c.workflowId,u=c.ts,l="running",E=Date.now(),I=E,S!==void 0&&S!==c.workflowId&&(x.shouldRun=void 0,x.onBeforeStart=void 0),S=c.workflowId,x.onAfterStep=new Map;break}case"workflow_success":l="success",s=c.ts,h=c.durationMs,I=Date.now();break;case"workflow_error":l="error",s=c.ts,p=c.error,h=c.durationMs,I=Date.now();break;case"workflow_cancelled":l="aborted",s=c.ts,h=c.durationMs,I=Date.now();break;case"step_start":{let b=k(c);m.set(b,{id:b,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),I=Date.now();break}case"step_success":{let b=k(c),f=m.get(b);if(f){let P={type:"step",id:f.id,name:f.name,key:f.key,state:"success",startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,...f.retryCount>0&&{retryCount:f.retryCount},...f.timedOut&&{timedOut:!0,timeoutMs:f.timeoutMs},...f.metadata&&{metadata:f.metadata}};T(P),m.delete(b)}break}case"step_error":{let b=k(c),f=m.get(b);if(f){let P={type:"step",id:f.id,name:f.name,key:f.key,state:"error",startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...f.retryCount>0&&{retryCount:f.retryCount},...f.timedOut&&{timedOut:!0,timeoutMs:f.timeoutMs},...f.metadata&&{metadata:f.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};T(P),m.delete(b)}break}case"step_aborted":{let b=k(c),f=m.get(b);if(f){let P={type:"step",id:f.id,name:f.name,key:f.key,state:"aborted",startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,...f.retryCount>0&&{retryCount:f.retryCount},...f.timedOut&&{timedOut:!0,timeoutMs:f.timeoutMs},...f.metadata&&{metadata:f.metadata}};T(P),m.delete(b)}break}case"step_cache_hit":{let f={type:"step",id:k(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};T(f);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let b=k(c),f=m.get(b);f&&(f.timedOut=!0,f.timeoutMs=c.timeoutMs),I=Date.now();break}case"step_retry":{let b=k(c),f=m.get(b);f&&(f.retryCount=(c.attempt??1)-1),I=Date.now();break}case"step_retries_exhausted":I=Date.now();break;case"step_skipped":{let f={type:"step",id:k(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};T(f);break}case"hook_should_run":{let b={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};x.shouldRun=b,S=c.workflowId,I=Date.now();break}case"hook_should_run_error":{let b={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};x.shouldRun=b,S=c.workflowId,I=Date.now();break}case"hook_before_start":{let b={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};x.onBeforeStart=b,S=c.workflowId,I=Date.now();break}case"hook_before_start_error":{let b={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};x.onBeforeStart=b,S=c.workflowId,I=Date.now();break}case"hook_after_step":{let b={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};x.onAfterStep.set(c.stepKey,b),I=Date.now();break}case"hook_after_step_error":{let b={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};x.onAfterStep.set(c.stepKey,b),I=Date.now();break}case"stream_created":{let b=`${c.workflowId}:${c.namespace}`;$.set(b,{id:ke(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),I=Date.now();break}case"stream_write":{let b=`${c.workflowId}:${c.namespace}`,f=$.get(b);f&&(f.writeCount++,f.finalPosition=Math.max(f.finalPosition,c.position)),I=Date.now();break}case"stream_read":{let b=`${c.workflowId}:${c.namespace}`,f=$.get(b);f&&f.readCount++,I=Date.now();break}case"stream_close":{let b=`${c.workflowId}:${c.namespace}`,f=$.get(b);if(f){f.streamState="closed",f.finalPosition=c.finalPosition;let P={type:"stream",id:f.id,namespace:f.namespace,state:"success",startTs:f.startTs,endTs:c.ts,durationMs:c.ts-f.startTs,writeCount:f.writeCount,readCount:f.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:f.backpressureOccurred};T(P),$.delete(b)}I=Date.now();break}case"stream_error":{let b=`${c.workflowId}:${c.namespace}`,f=$.get(b);if(f){f.streamState="error";let P={type:"stream",id:f.id,namespace:f.namespace,state:"error",error:c.error,startTs:f.startTs,endTs:c.ts,durationMs:c.ts-f.startTs,writeCount:f.writeCount,readCount:f.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:f.backpressureOccurred};T(P),$.delete(b)}I=Date.now();break}case"stream_backpressure":{let b=`${c.workflowId}:${c.namespace}`,f=$.get(b);f&&(f.backpressureOccurred=!0),I=Date.now();break}}M(c)}function B(c){if(c.type==="scope_start")y.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),I=Date.now();else if(c.type==="scope_end"){let b=y.findIndex(C=>C.id===c.scopeId);if(b===-1)return;for(;y.length>b+1;){let C=y.pop(),Y=C.type==="race"?{type:"race",id:C.id,name:C.name,state:_(C.children),startTs:C.startTs,endTs:c.ts,children:C.children}:{type:"parallel",id:C.id,name:C.name,state:_(C.children),startTs:C.startTs,endTs:c.ts,children:C.children,mode:C.type==="allSettled"?"allSettled":"all"};y[y.length-1].children.push(Y)}let[f]=y.splice(b,1),P=f.type==="race"?{type:"race",id:f.id,name:f.name,state:_(f.children),startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,children:f.children,winnerId:c.winnerId}:{type:"parallel",id:f.id,name:f.name,state:_(f.children),startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,children:f.children,mode:f.type==="allSettled"?"allSettled":"all"};T(P)}}function U(c){if(c.type==="decision_start")v.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),I=Date.now();else if(c.type==="decision_branch"){let b=v.find(f=>f.id===c.decisionId);if(b){let f=c.branchLabel,P=b.branches.get(f);if(P)P.taken=c.taken,c.taken&&b.pendingChildren.length>0&&(P.children.unshift(...b.pendingChildren),b.pendingChildren=[]);else{let C=c.taken?[...b.pendingChildren]:[];c.taken&&(b.pendingChildren=[]),b.branches.set(f,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:C})}I=Date.now()}}else if(c.type==="decision_end"){let b=v.findIndex(f=>f.id===c.decisionId);if(b!==-1){let[f]=v.splice(b,1),P=v.splice(b),C=Array.from(f.branches.values());C.length===0&&f.pendingChildren.length>0&&(C=[{label:"default",taken:!0,children:[...f.pendingChildren]}]);let Y=C.find(ye=>ye.taken)?.label,St={type:"decision",id:f.id,name:f.name,state:_(C.flatMap(ye=>ye.taken?ye.children:[])),startTs:f.startTs,endTs:c.ts,durationMs:c.durationMs,condition:f.condition,decisionValue:f.decisionValue,branchTaken:c.branchTaken??Y,branches:C};T(St),v.push(...P),I=Date.now()}}}function _(c){return c.length===0?"success":c.some(C=>C.state==="error")?"error":c.every(C=>C.state==="success"||C.state==="cached")?"success":c.some(C=>C.state==="running")?"running":"pending"}function re(){let c=[...N];for(let[,b]of m)c.push({type:"step",id:b.id,name:b.name,key:b.key,state:"running",startTs:b.startTs,...b.retryCount>0&&{retryCount:b.retryCount},...b.timedOut&&{timedOut:!0,timeoutMs:b.timeoutMs}});for(let[,b]of $)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 ne(){let c=re();t&&(c=ve(c,r));let b={type:"workflow",id:d??a,workflowId:d??a,state:l,startTs:u,endTs:s,durationMs:h,children:c,error:p},f=x.shouldRun!==void 0||x.onBeforeStart!==void 0||x.onAfterStep.size>0;return{root:b,metadata:{createdAt:E,lastUpdatedAt:I},...f&&{hooks:x}}}function oe(){d=void 0,u=void 0,s=void 0,l="pending",p=void 0,h=void 0,m.clear(),y.length=0,v.length=0,$.clear(),N=[],E=Date.now(),I=E,x={onAfterStep:new Map},S=void 0,w.length=0,g=0}function yt(){return[...w]}function kt(c){return w[c]}function vt(c){return w[c]?.ir}function xt(){w.length=0,g=0}return{handleEvent:O,handleScopeEvent:B,handleDecisionEvent:U,getIR:ne,reset:oe,getSnapshots:yt,getSnapshotAt:kt,getIRAt:vt,clearSnapshots:xt,get hasActiveSteps(){return m.size>0},get state(){return l},get snapshotCount(){return w.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}import{ok as Lt,err as _t}from"awaitly";function K(e){return e.type==="step"}function Ge(e){return e.type==="sequence"}function j(e){return e.type==="parallel"}function F(e){return e.type==="race"}function J(e){return e.type==="decision"}function ee(e){return e.type==="stream"}function an(e){return"children"in e||e.type==="decision"&&"branches"in e}var Le="\x1B[0m",Et="\x1B[1m",Je="\x1B[2m",Mt="\x1B[31m",Nt="\x1B[32m",Tt="\x1B[33m",Dt="\x1B[34m",Ye="\x1B[90m",Ot="\x1B[37m";function X(e,t){return t?`${t}${e}${Le}`:e}function ge(e){return`${Et}${e}${Le}`}function D(e){return`${Je}${e}${Le}`}var V={pending:Ot,running:Tt,success:Nt,error:Mt,aborted:Ye,cached:Dt,skipped:Je+Ye};function Ct(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 we(e,t){let r=Ct(e);return X(r,t[e])}function xe(e,t,r){return X(e,r[t])}function Q(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"},de={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Wt="\x1B[0m";function Bt(e){return e<.2?de.cold:e<.4?de.cool:e<.6?de.neutral:e<.8?de.warm:e<.95?de.hot:de.critical}function Xe(e,t){let r=Bt(t);return r?`${r}${e}${Wt}`:e}function At(e){try{return Lt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let i=Number(o);return Number.isSafeInteger(i)?i:o.toString()}))}catch{return _t("STRINGIFY_ERROR")}}function qe(e){let t=At(e);return t.ok?t.value:"[unserializable]"}var Ze="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function We(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(a=>{let d=(a-o)/n,u=Math.floor(d*(Ze.length-1));return Ze[u]}).join("")}function _e(e,t){let r=Q(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function Pt(e,t){if(!t)return R.horizontal.repeat(e);let r=` ${t} `,o=Q(r).length,i=e-o;if(i<4)return R.horizontal.repeat(e);let n=2,a=i-n;return R.horizontal.repeat(n)+r+R.horizontal.repeat(a)}function Qe(e,t,r){let o=e.state==="success"?X("\u2699",r.success):X("\u26A0",r.error),i=e.durationMs!==void 0?D(` [${A(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=D(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=D(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=D(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=D(` (${e.context.stepKey})`));let a=e.state==="error"&&e.error?D(` error: ${String(e.error)}`):"";return`${o} ${D(t)}${n}${i}${a}`}function Ht(e,t){let r=[];return e.shouldRun&&r.push(Qe(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Qe(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(D("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function le(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...V,...t.colors},o=Math.max(t.terminalWidth??60,5),i=o-4,n=[],a=e.root.name??"workflow",d=ge(a);if(n.push(`${R.topLeft}${Pt(o-2,d)}${R.topRight}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.hooks){let s=Ht(e.hooks,r);for(let l of s)n.push(`${R.vertical} ${_e(l,i)}${R.vertical}`)}let u=Se(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${R.vertical} ${_e(s,i)}${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=`${xe(s,e.root.state,r)} in ${A(e.root.durationMs)}`;n.push(`${R.vertical} ${_e(p,i)}${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 Se(e,t,r,o,i){let n=[];for(let a of e)K(a)?n.push(Be(a,t,r,i)):j(a)?n.push(...zt(a,t,r,o,i)):F(a)?n.push(...Ut(a,t,r,o,i)):J(a)?n.push(...Kt(a,t,r,o,i)):ee(a)&&n.push(Ft(a,t,r));return n}function Be(e,t,r,o){let i=we(e.state,r),n=e.name??e.key??"step",a=t,d=a.showHeatmap&&a.heatmapData?a.heatmapData.heat.get(e.key??"")??a.heatmapData.heat.get(e.name??"")??a.heatmapData.heat.get(e.id):void 0,u;d!==void 0?u=Xe(n,d):u=xe(n,e.state,r);let s=`${i} ${u}`;if(t.showKeys&&e.key&&e.name&&(s+=D(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:qe(e.input).slice(0,30);s+=D(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:qe(e.output).slice(0,30);s+=D(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=A(e.durationMs),h=d!==void 0?Xe(`[${p}]`,d):D(`[${p}]`);s+=` ${h}`}if(a.showSparklines&&a.timingHistory){let p=a.timingHistory.get(e.key??"")??a.timingHistory.get(e.name??"")??a.timingHistory.get(e.id);p&&p.length>1&&(s+=` ${D(We(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(s+=D(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";s+=D(` [timeout${p}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let p=o.onAfterStep.get(l),h=p.state==="success"?X("\u2699",r.success):X("\u26A0",r.error),m=p.durationMs!==void 0?D(` ${A(p.durationMs)}`):"";s+=` ${h}${m}`}return s}function Ft(e,t,r){let o=e.streamState==="active"?X("\u27F3",r.running):e.streamState==="closed"?X("\u2713",r.success):X("\u2717",r.error),i=`stream:${e.namespace}`,n=xe(i,e.state,r),a=D(`[W:${e.writeCount} R:${e.readCount}]`),d=`${o} ${n} ${a}`;return t.showTimings&&e.durationMs!==void 0&&(d+=` ${D(`[${A(e.durationMs)}]`)}`),e.backpressureOccurred&&(d+=D(" [backpressure]")),e.streamState==="closed"&&(d+=D(` pos:${e.finalPosition}`)),d}function zt(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${a}${R.teeRight}${R.teeDown}${R.horizontal} ${d} ${ge(u)}${s}`),e.children.length===0)n.push(`${a}${R.vertical} ${D("(operations not individually tracked)")}`),n.push(`${a}${R.vertical} ${D("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let p=e.children[l],m=l===e.children.length-1?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`;if(K(p))n.push(`${m} ${Be(p,t,r,i)}`);else{let y=Se([p],t,r,o+1,i);for(let v of y)n.push(`${a}${R.vertical} ${v}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}function Ut(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"race";if(n.push(`${a}${R.teeRight}\u26A1 ${d} ${ge(u)}`),e.children.length===0)n.push(`${a}${R.vertical} ${D("(operations not individually tracked)")}`),n.push(`${a}${R.vertical} ${D("(wrap each operation with step() to see individual steps)")}`);else for(let s=0;s<e.children.length;s++){let l=e.children[s],h=s===e.children.length-1?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`,y=e.winnerId&&l.id===e.winnerId?D(" (winner)"):"";if(K(l))n.push(`${h} ${Be(l,t,r,i)}${y}`);else{let v=Se([l],t,r,o+1,i);for(let $ of v)n.push(`${a}${R.vertical} ${$}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}function Kt(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"decision",s=e.condition?D(` (${e.condition})`):"",l=e.decisionValue!==void 0?D(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?D(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${a}${R.teeRight}${R.teeDown}${R.horizontal} ${d} ${ge(u)}${s}${l}${p}`);for(let h=0;h<e.branches.length;h++){let m=e.branches[h],v=h===e.branches.length-1?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`,$=m.taken?"\u2713":"\u2298",N=m.taken?r.success:r.skipped,E=X(`${$} ${m.label}`,N),I=m.condition?D(` (${m.condition})`):"";if(n.push(`${v} ${E}${I}`),m.children.length>0){let x=Se(m.children,t,r,o+1,i);for(let S of x)n.push(`${a}${R.vertical} ${S}`)}else m.taken||n.push(`${a}${R.vertical} ${D("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}import{ok as Vt,err as Gt}from"awaitly";function Ae(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...Ae(r.children)),"branches"in r)for(let o of r.branches)t.push(...Ae(o.children));return t}function Re(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function be(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function jt(){let e=new Map,t=new Map,r=new Map,o=new Map,i=[];function n(x){return x.stepKey??x.stepId??x.name??"unknown"}function a(x){let S=new Map;for(let w of x)switch(w.type){case"step_start":{let g=n(w);S.set(g,{retried:!1,timedOut:!1});break}case"step_retry":{let g=n(w),k=S.get(g);k&&(k.retried=!0);break}case"step_timeout":{let g=n(w),k=S.get(g);k&&(k.timedOut=!0);break}case"step_success":{let g=n(w),k=S.get(g),T=e.get(g)??[];T.push(w.durationMs),e.set(g,T);let M=t.get(g)??{retried:0,total:0};M.total++,k?.retried&&M.retried++,t.set(g,M);let O=o.get(g)??{timedOut:0,total:0};O.total++,k?.timedOut&&O.timedOut++,o.set(g,O);let B=r.get(g)??{errors:0,total:0};B.total++,r.set(g,B),S.delete(g);break}case"step_error":{let g=n(w),k=S.get(g),T=e.get(g)??[];T.push(w.durationMs),e.set(g,T);let M=t.get(g)??{retried:0,total:0};M.total++,k?.retried&&M.retried++,t.set(g,M);let O=o.get(g)??{timedOut:0,total:0};O.total++,k?.timedOut&&O.timedOut++,o.set(g,O);let B=r.get(g)??{errors:0,total:0};B.total++,B.errors++,r.set(g,B),S.delete(g);break}}}function d(x){a(x.events)}function u(x){i.push(x)}function s(x){i.length>0&&(a(i),i=[])}function l(x){let S=e.get(x);if(!S||S.length===0)return;let w=[...S].sort((U,_)=>U-_),k=w.reduce((U,_)=>U+_,0)/w.length,T=w.reduce((U,_)=>U+(_-k)**2,0)/w.length,M=t.get(x)??{retried:0,total:1},O=r.get(x)??{errors:0,total:1},B=o.get(x)??{timedOut:0,total:1};return{nodeId:x,avgDurationMs:k,minDurationMs:w[0],maxDurationMs:w[w.length-1],stdDevMs:Math.sqrt(T),samples:w.length,retryRate:M.total>0?M.retried/M.total:0,timeoutRate:B.total>0?B.timedOut/B.total:0,errorRate:O.total>0?O.errors/O.total:0,percentiles:{p50:Re(w,.5),p90:Re(w,.9),p95:Re(w,.95),p99:Re(w,.99)}}}function p(x){return l(x)}function h(x,S="duration"){let w=new Map,g=Ae(x.root.children),k=[];for(let _ of g){let re=("key"in _?_.key:void 0)??_.id??_.name,ne=l(re);if(ne){let oe;switch(S){case"duration":oe=ne.avgDurationMs;break;case"retryRate":oe=ne.retryRate;break;case"errorRate":oe=ne.errorRate;break}k.push({id:_.id,value:oe})}}if(k.length===0)return{heat:w,metric:S,stats:{min:0,max:0,mean:0,threshold:0}};let T=k.map(_=>_.value),M=Math.min(...T),O=Math.max(...T),B=T.reduce((_,re)=>_+re,0)/T.length,U=O-M||1;for(let{id:_,value:re}of k)w.set(_,(re-M)/U);return{heat:w,metric:S,stats:{min:M,max:O,mean:B,threshold:B+(O-B)*.5}}}function m(){let x=new Map;for(let S of e.keys()){let w=l(S);w&&x.set(S,w)}return x}function y(x=10){return[...m().values()].sort((w,g)=>g.avgDurationMs-w.avgDurationMs).slice(0,x)}function v(x=10){return[...m().values()].filter(w=>w.errorRate>0).sort((w,g)=>g.errorRate-w.errorRate).slice(0,x)}function $(x=10){return[...m().values()].filter(w=>w.retryRate>0).sort((w,g)=>g.retryRate-w.retryRate).slice(0,x)}function N(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function E(x){let S=JSON.parse(x);e.clear(),t.clear(),r.clear(),o.clear();for(let[w,g]of Object.entries(S.timingData??{}))e.set(w,g);for(let[w,g]of Object.entries(S.retryData??{}))t.set(w,g);for(let[w,g]of Object.entries(S.errorData??{}))r.set(w,g);for(let[w,g]of Object.entries(S.timeoutData??{}))o.set(w,g)}function I(){e.clear(),t.clear(),r.clear(),o.clear(),i=[]}return{addRun:d,addEvent:u,finalizeRun:s,getNodePerformance:p,getHeatmap:h,getSlowestNodes:y,getErrorProneNodes:v,getRetryProneNodes:$,getAllPerformance:m,exportData:N,importData:E,clear:I}}function Yt(){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 Jt(){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 Xt(e){return`heat_${e}`}function qt(){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 Zt(e){try{return Vt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let i=Number(o);return Number.isSafeInteger(i)?i:o.toString()}))}catch{return Gt("STRINGIFY_ERROR")}}function et(e){let t=Zt(e);return t.ok?t.value:"[unserializable]"}function Qt(e,t,r){let o;if(e.shouldRun){let i="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",a=e.shouldRun.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${A(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${i}[["${a} shouldRun${u}${d}"]]:::${n}`),o=i}if(e.onBeforeStart){let i="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",a=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${A(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${i}[["${a} onBeforeStart${u}${d}"]]:::${n}`),o&&t.push(` ${o} --> ${i}`),o=i}return{lastHookId:o}}var tt=0,Ie=new Set,$e=new Set;function ue(e="node"){return`${e}_${++tt}`}function er(){tt=0,Ie.clear(),$e.clear()}function z(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function rt(e){return z(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){er();let r=[],o=t;r.push("flowchart TD");let i;e.hooks&&(i=Qt(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),i&&r.push(` ${i} --> ${n}`);let a=n;for(let u of e.root.children){let s=Ee(u,t,r,o,e.hooks);r.push(` ${a} --> ${s.entryId}`),a=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}"))`,h=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${p}${h}`),r.push(` ${a} --> ${u}`)}return r.push(""),r.push(...Yt()),o.showHeatmap&&r.push(...Jt()),e.hooks&&r.push(...qt()),r.join(`
3
- `)}}}function Ee(e,t,r,o,i){if(K(e))return tr(e,t,r,o,i);if(j(e))return rr(e,t,r,o,i);if(F(e))return nr(e,t,r,o,i);if(J(e))return or(e,t,r,o,i);if(ee(e))return ir(e,t,r);let n=ue("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function tr(e,t,r,o,i){let n=t,a=n.showRetryEdges??!0,d=n.showErrorEdges??!0,u=n.showTimeoutEdges??!0,s=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ue("step");if($e.has(s)){let w=2;for(;$e.has(`${s}_${w}`);)w++;s=`${s}_${w}`}$e.add(s);let l=e.name??e.key??"Step",p=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,h=z(p),m=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"",y="";switch(e.state){case"success":y="\u2713 ";break;case"error":y="\u2717 ";break;case"cached":y="\u{1F4BE} ";break;case"running":y="\u23F3 ";break;case"skipped":y="\u2298 ";break}let v="";if(e.input!==void 0){let w=typeof e.input=="string"?z(e.input):z(et(e.input).slice(0,20));v+=`\\nin: ${w}`}if(e.output!==void 0&&e.state==="success"){let w=typeof e.output=="string"?z(e.output):z(et(e.output).slice(0,20));v+=`\\nout: ${w}`}let $="",N=e.key??e.id;if(i&&N&&i.onAfterStep.has(N)){let w=i.onAfterStep.get(N),g=w.state==="success"?"\u2699":"\u26A0",k=t.showTimings&&w.durationMs!==void 0?` ${A(w.durationMs)}`:"";$=`\\n${g} hook${k}`}let E=(y+h+v+$+m).trim(),I,x=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(x!==void 0){let w=be(x);I=Xt(w)}else I=e.state;let S;switch(e.state){case"error":S=`{{"${E}"}}`;break;case"cached":S=`[("${E}")]`;break;case"skipped":S=`["${E}"]`;break;default:S=`["${E}"]`}if(r.push(` ${s}${S}:::${I}`),a&&e.retryCount!==void 0&&e.retryCount>0){let w=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${s} -.->|"${w}"| ${s}`)}if(d&&e.state==="error"&&e.error!==void 0){let w=`ERR_${s}`,g=z(String(e.error)).slice(0,30);r.push(` ${w}{{"${g}"}}`),r.push(` ${s} -->|error| ${w}`),r.push(` style ${w} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let w=`TO_${s}`,g=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${w}{{"\u23F1 Timeout ${g}"}}`),r.push(` ${s} -.->|timeout| ${w}`),r.push(` style ${w} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function rr(e,t,r,o,i){let n=ue("parallel"),a=`${n}_fork`,d=`${n}_join`,u=rt(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let h=n,m=z(`${u}${s}`),y="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"";return r.push(` ${h}["${m}${v}\\n${y}"]:::${e.state}`),{entryId:h,exitId:h}}r.push(` subgraph ${n}["${u}${s}"]`),r.push(" direction TB"),r.push(` ${a}{"\u26A1 Fork"}`);let l=[];for(let h of e.children){let m=Ee(h,t,r,o,i);r.push(` ${a} --> ${m.entryId}`),l.push(m.exitId)}r.push(` ${d}{"\u2713 Join"}`);for(let h of l)r.push(` ${h} --> ${d}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:a,exitId:d}}function nr(e,t,r,o,i){let n=ue("race"),a=`${n}_start`,d=`${n}_end`,u=rt(e.name??"Race");if(e.children.length===0){let h=n,m=z(u),y="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"";return r.push(` ${h}["\u26A1 ${m}${v}\\n${y}"]:::${e.state}`),{entryId:h,exitId:h}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${a}(("\u{1F3C1} Start"))`);let s=[],l;for(let h of e.children){let m=Ee(h,t,r,o,i),y=e.winnerId===h.id;r.push(` ${a} --> ${m.entryId}`),y&&(l=m.exitId),s.push({exitId:m.exitId,isWinner:y})}r.push(` ${d}(("\u2713 First"))`);for(let{exitId:h,isWinner:m}of s)m&&l?r.push(` ${h} ==>|\u{1F3C6} Winner| ${d}`):e.winnerId?r.push(` ${h} -. cancelled .-> ${d}`):r.push(` ${h} --> ${d}`);r.push(" end");let p=e.state;return r.push(` class ${n} ${p}`),{entryId:a,exitId:d}}function or(e,t,r,o,i){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ue("decision");if(Ie.has(n)){let h=2;for(;Ie.has(`${n}_${h}`);)h++;n=`${n}_${h}`}Ie.add(n);let a=z(e.condition??"condition"),d=e.decisionValue!==void 0?` = ${z(String(e.decisionValue)).slice(0,30)}`:"",u=`${a}${d}`.trim();r.push(` ${n}{"${u}"}`);let s=[],l,p=new Set;for(let h of e.branches){let m=`${n}_${h.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(p.has(m)){let E=2;for(;p.has(`${m}_${E}`);)E++;m=`${m}_${E}`}p.add(m);let y=z(h.label),v=h.taken?`${y} \u2713`:`${y} skipped`,$=h.taken?":::success":":::skipped";r.push(` ${m}["${v}"]${$}`);let N=h.condition?`|${z(h.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${N} ${m}`),h.children.length>0){let E=m;for(let I of h.children){let x=Ee(I,t,r,o,i);r.push(` ${E} --> ${x.entryId}`),E=x.exitId}s.push(E),h.taken&&(l=E)}else s.push(m),h.taken&&(l=m)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function ir(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${ue("")}`,i=`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 a=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"",d=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${z(e.namespace)}\\n${i}${d}${a}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",r.push(` ${o}{{"${u}"}}:::${s}`),{entryId:o,exitId:o}}var L={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},ar={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},sr="\x1B[0m";function cr(e,t){let r=[],o=[];for(let i=0;i<t;i++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function W(e,t,r,o,i){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,i&&(e.colors[r][t]=i))}function it(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function dr(e,t,r,o,i){W(e,t,r,L.topLeft);for(let n=1;n<o-1;n++)W(e,t+n,r,L.horizontal);W(e,t+o-1,r,L.topRight);for(let n=1;n<i-1;n++)W(e,t,r+n,L.vertical),W(e,t+o-1,r+n,L.vertical);W(e,t,r+i-1,L.bottomLeft);for(let n=1;n<o-1;n++)W(e,t+n,r+i-1,L.horizontal);W(e,t+o-1,r+i-1,L.bottomRight)}function nt(e,t,r,o,i){let n=Q(o).split("");for(let a=0;a<n.length;a++)W(e,t+a,r,n[a],i)}function te(e,t,r,o){let i=Math.min(r,o),n=Math.max(r,o);for(let a=i;a<=n;a++){let d=it(e,t,a);d===L.horizontal?W(e,t,a,L.cross):(d===" "||d===L.vertical)&&W(e,t,a,L.vertical)}}function ot(e,t,r,o){let i=Math.min(r,o),n=Math.max(r,o);for(let a=i;a<=n;a++){let d=it(e,a,t);d===L.vertical?W(e,a,t,L.cross):(d===" "||d===L.horizontal)&&W(e,a,t,L.horizontal)}}function se(e,t,r){W(e,t,r,L.arrowDown)}function lr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let i=0;i<e.width;i++){let n=e.colors[r][i],a=e.cells[r][i];n?o+=n+a+sr:o+=a}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
4
- `)}var q=11,Z=2,pe=2,Me=3;function He(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],i="";for(let n of r)i?i.length+1+n.length<=t?i+=" "+n:(o.push(i),i=n):i=n;if(i&&o.push(i),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function at(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function ur(e,t,r){let o=t.showStartEnd??!0,i=t,n=Math.floor(r/2),a=[],d=0;if(o){let s=Ne("start","start",["\u25B6 Start"],"success",n,d);a.push(s),d=s.bottomY+pe}for(let s of e.root.children){let l=Te(s,n,d,r-4,t,i);a.push(l.node),d=l.bottomY+pe}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=Ne("end","end",[s],e.root.state,n,d);a.push(l),d=l.bottomY}return{nodes:a,totalHeight:d+2}}function Ne(e,t,r,o,i,n){let a=Math.max(...r.map(l=>Q(l).length)),d=Math.max(q,a+Z*2),u=r.length+2,s=i-Math.floor(d/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:d,height:u,centerX:i,bottomY:n+u-1}}function Te(e,t,r,o,i,n){if(K(e))return pr(e,t,r,o,i,n);if(j(e)||F(e))return mr(e,t,r,o,i,n);if(J(e))return hr(e,t,r,o,i,n);if(ee(e))return fr(e,t,r,o,i,n);let a=Ne(e.id,"step",["?"],e.state,t,r);return{node:a,bottomY:a.bottomY}}function pr(e,t,r,o,i,n){let a=e.name??e.key??"step",d=at(e.state),u=[],s=`${d} ${a}`;i.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-Z*2,40);if(u.push(...He(s,l)),i.showTimings&&e.durationMs!==void 0&&u.push(`[${A(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let N=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);N&&N.length>1&&u.push(We(N,8))}let p=Math.max(...u.map(N=>Q(N).length)),h=Math.max(q,p+Z*2),m=u.length+2,y=t-Math.floor(h/2),v;if(n?.showHeatmap&&n.heatmapData){let N=e.key??e.name??e.id;v=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(N)}let $={id:e.id,type:"step",label:u,state:e.state,x:y,y:r,width:h,height:m,centerX:t,bottomY:r+m-1,metadata:v!==void 0?{heat:v}:void 0};return{node:$,bottomY:$.bottomY}}function fr(e,t,r,o,i,n){let a=`stream:${e.namespace}`,d=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${d} ${a}`,l=Math.min(o-Z*2,40);u.push(...He(s,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),i.showTimings&&e.durationMs!==void 0&&u.push(`[${A(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let p=Math.max(...u.map($=>Q($).length)),h=Math.max(q,p+Z*2),m=u.length+2,y=t-Math.floor(h/2),v={id:e.id,type:"stream",label:u,state:e.state,x:y,y:r,width:h,height:m,centerX:t,bottomY:r+m-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:v,bottomY:v.bottomY}}function mr(e,t,r,o,i,n){let a=F(e),d=e.name??(a?"race":"parallel"),s=`${a?"\u26A1":"\u2AD8"} ${d}`;if(e.children.length===0){let g=[s,"(not tracked)"],k=Ne(e.id,a?"race":"parallel",g,e.state,t,r);return{node:k,bottomY:k.bottomY}}let l=Math.floor((o-Me*(e.children.length-1))/e.children.length),p=[];for(let g of e.children){let k=Pe(g,Math.max(l,q),i,n);p.push(k.width)}let h=p.reduce((g,k)=>g+k,0)+Me*(e.children.length-1),m=h>o&&e.children.length>1,y=Math.max(q,s.length+Z*2),v=3,$=t-Math.floor(y/2),N=r;N+=v,N+=1,N+=1;let E=[];if(m)for(let g=0;g<e.children.length;g++){let k=e.children[g],T=Te(k,t,N,o,i,n);a&&F(e)&&e.winnerId===k.id&&(T.node.metadata={...T.node.metadata,isWinner:!0}),E.push(T.node),N=T.bottomY+pe}else{let g=t-Math.floor(h/2);for(let k=0;k<e.children.length;k++){let T=e.children[k],M=g+Math.floor(p[k]/2),O=Te(T,M,N,p[k],i,n);a&&F(e)&&e.winnerId===T.id&&(O.node.metadata={...O.node.metadata,isWinner:!0}),E.push(O.node),g+=p[k]+Me}}let I=Math.max(...E.map(g=>g.bottomY)),S=!m&&E.length>1?I+2:I;return{node:{id:e.id,type:a?"race":"parallel",label:[s],state:e.state,x:$,y:r,width:y,height:v,centerX:t,bottomY:S,children:E,metadata:{verticalLayout:m}},bottomY:S}}function hr(e,t,r,o,i,n){let a=e.name??"decision",d=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${a}${d}`,s=Math.min(o-Z*2,40),l=He(u,s),p=Math.max(...l.map(S=>Q(S).length)),h=Math.max(q,p+Z*2),m=l.length+2,y=t-Math.floor(h/2),v=e.branches.find(S=>S.taken),$=v&&v.children.length>0?v:e.branches.find(S=>S.children.length>0);if(!$||$.children.length===0){let S={id:e.id,type:"decision",label:l,state:e.state,x:y,y:r,width:h,height:m,centerX:t,bottomY:r+m-1};return{node:S,bottomY:S.bottomY}}let N=r+m+pe,E=[];for(let S of $.children){let w=Te(S,t,N,o,i,n);E.push(w.node),N=w.bottomY+pe}let I=E.length>0?E[E.length-1].bottomY:r+m-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:y,y:r,width:h,height:m,centerX:t,bottomY:I,children:E},bottomY:I}}function Pe(e,t,r,o){if(K(e)){let i=e.name??e.key??"step",n=at(e.state),a=1;r.showTimings&&e.durationMs!==void 0&&a++,e.retryCount&&e.retryCount>0&&a++,e.timedOut&&a++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&a++;let d=`${n} ${i}`;r.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let u=Math.min(t,Math.max(q,d.length+Z*2)),s=a+2;return{width:u,height:s}}if(j(e)||F(e)){if(e.children.length===0)return{width:q+4,height:4};let i=Math.floor(t/e.children.length),n=0,a=0;for(let d of e.children){let u=Pe(d,i,r,o);n+=u.width,a=Math.max(a,u.height)}return n+=Me*(e.children.length-1),{width:Math.max(n,q),height:5+a+2}}if(J(e)){let i=e.branches.find(a=>a.taken),n=0;if(i)for(let a of i.children){let d=Pe(a,t,r,o);n+=d.height+pe}return{width:Math.min(t,30),height:3+n}}if(ee(e)){let i=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let a=Math.min(t,Math.max(q,i.length+Z*2+4)),d=n+2;return{width:a,height:d}}return{width:q,height:3}}function gr(e,t,r){let o={...V,...r.colors};for(let i=0;i<t.length;i++){let n=t[i],a=i===t.length-1;if(De(e,n,o),!a){let d=t[i+1],u=n.centerX,s=n.bottomY+1,l=d.centerX,p=d.y-1;te(e,u,s,p-1),se(e,l,p)}}}function De(e,t,r){let o=t.type!=="start",i=t.type!=="end"&&(!t.children||t.children.length===0);dr(e,t.x,t.y,t.width,t.height),o&&W(e,t.centerX,t.y,L.teeUp),(i||t.children&&t.children.length>0)&&W(e,t.centerX,t.y+t.height-1,L.teeDown);let n=t.width-Z*2,a=kr(t,r);for(let d=0;d<t.label.length;d++){let u=t.label[d],s=t.x+1+Math.floor((n-Q(u).length)/2),l=t.y+1+d;nt(e,s,l,u,a)}t.metadata?.isWinner&&nt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?wr(e,t,r):br(e,t,r))}function wr(e,t,r){let o=t.children;if(o.length===0)return;let i=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let d=o[0];te(e,n,i,d.y-2),se(e,d.centerX,d.y-1);for(let u=0;u<o.length;u++){let s=o[u];if(De(e,s,r),u<o.length-1){let l=o[u+1];te(e,s.centerX,s.bottomY+1,l.y-2),se(e,l.centerX,l.y-1)}}return}if(o.length===1)te(e,n,i,o[0].y-2),se(e,o[0].centerX,o[0].y-1);else{let d=o.map(l=>l.centerX),u=Math.min(...d),s=Math.max(...d);te(e,n,i,i+1),ot(e,i+1,u,s),W(e,n,i+1,L.teeUp);for(let l of o){let p=l.centerX;p===u?W(e,p,i+1,L.topLeft):p===s?W(e,p,i+1,L.topRight):p!==n&&W(e,p,i+1,L.teeDown),te(e,p,i+2,l.y-2),se(e,p,l.y-1)}}for(let d of o)De(e,d,r);if(o.length>1){let d=o.map(m=>m.bottomY),u=Math.max(...d),s=u+1,l=o.map(m=>m.centerX),p=Math.min(...l),h=Math.max(...l);for(let m of o)m.bottomY<u&&te(e,m.centerX,m.bottomY+1,s-1);ot(e,s,p,h);for(let m of o){let y=m.centerX;y===p?W(e,y,s,L.bottomLeft):y===h?W(e,y,s,L.bottomRight):W(e,y,s,L.teeUp)}W(e,t.centerX,s,L.teeDown),W(e,t.centerX,s+1,L.vertical)}}function br(e,t,r){let o=t.children;if(o.length===0)return;let i=t.y+t.height,n=o[0];te(e,t.centerX,i,n.y-2),se(e,n.centerX,n.y-1);for(let a=0;a<o.length;a++){let d=o[a];if(De(e,d,r),a<o.length-1){let u=o[a+1];te(e,d.centerX,d.bottomY+1,u.y-2),se(e,u.centerX,u.y-1)}}}var yr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function kr(e,t){if(e.metadata?.heat!==void 0){let r=be(e.metadata.heat);return ar[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?yr[e.metadata.streamState]||void 0:t[e.state]||void 0}function fe(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:i}=ur(e,t,r),n=cr(r,i);return gr(n,o,t),lr(n)}}}function vr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function xr(e){let t=[];function r(o){for(let i of o)if(K(i))t.push(i);else if(Ge(i))r(i.children);else if(j(i)||F(i))r(i.children);else if(J(i))for(let n of i.branches)n.taken&&r(n.children)}return r(e),t}function Sr(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 Rr(e){let t=0,r=0,o=0,i=0,n=0,a;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&i++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!a||s.durationMs>a.durationMs)&&(a={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:i,totalRetries:n,slowestStep:a,...u&&{byDomain:u}}}function Ir(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 i={stepKey:r};o.durationMs!==void 0&&(i.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(i.error=String(o.error)),t.onAfterStep.push(i)}}return t}function $r(e,t){let r=e.root,o=xr(r.children),i=t.includeDiagram??!0,n=t.stripAnsiColors??!0,a={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(Sr),summary:Rr(o)};if(e.hooks){let d=Ir(e.hooks);Object.keys(d).length>0&&(a.hooks=d)}if(i){let s=((t.diagramFormat??"ascii")==="flowchart"?fe():le()).render(e,t);n&&(s=vr(s)),a.diagram=s}return a}function Oe(){return{name:"logger",supportsLive:!1,render(e,t){let o=$r(e,t);return JSON.stringify(o)}}}function st(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 A(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 ke(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function ve(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,i=[],n=[];for(let s=0;s<e.length;s++){let l=e[s];l.type==="step"&&l.startTs!==void 0?i.push({node:l,startTs:l.startTs,endTs:l.endTs??l.startTs+(l.durationMs??0),originalIndex:s}):n.push({node:l,originalIndex:s})}if(i.length<=1)return e;i.sort((s,l)=>s.startTs-l.startTs);let a=[],d=[i[0]];for(let s=1;s<i.length;s++){let l=i[s],f=Math.min(...d.map($=>$.startTs)),g=Math.max(...d.map($=>$.endTs)),h=l.startTs<=f+o,y=l.startTs<g;if(!h&&!y){a.push(d),d=[l];continue}let v=y?Math.min(l.endTs,g)-l.startTs:0;h||v>=r?d.push(l):(a.push(d),d=[l])}a.push(d);let u=[];for(let s of a){let l=Math.min(...s.map(f=>f.originalIndex));if(s.length===1)u.push({node:s[0].node,position:l});else{let f=s.map(v=>v.node),g=Math.min(...s.map(v=>v.startTs)),h=Math.max(...s.map(v=>v.endTs)),y={type:"parallel",id:`detected_parallel_${g}`,name:`${f.length} parallel steps`,state:It(f),mode:"all",children:f,startTs:g,endTs:h,durationMs:h-g};u.push({node:y,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 It(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 $t(e={}){return{detect:t=>ve(t,e)}}function he(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:i=1e3}=e,n=o,a=ke(),d,u,s,l="pending",f,g,h=new Map,y=[],v=[],$=new Map,N=[],E=Date.now(),I=E,x={onAfterStep:new Map},S,b=[],w=0;function k(c){return c.stepId??c.stepKey??c.name??ke()}function T(c){if(y.length>0){y[y.length-1].children.push(c),I=Date.now();return}if(v.length>0){let m=v[v.length-1];for(let p of m.branches.values())if(p.taken){p.children.push(c),I=Date.now();return}m.pendingChildren.push(c),I=Date.now();return}N.push(c),I=Date.now()}function M(c){if(!n)return;let m=ne(),p=new Map;for(let[C,Y]of h)p.set(C,{id:Y.id,name:Y.name,key:Y.key,startTs:Y.startTs,retryCount:Y.retryCount,timedOut:Y.timedOut,timeoutMs:Y.timeoutMs});let P={id:`snapshot_${w}`,eventIndex:w,event:structuredClone(c),ir:structuredClone(m),timestamp:Date.now(),activeSteps:p};b.push(P),b.length>i&&b.shift(),w++}function O(c){switch(c.type){case"workflow_start":{N=[],s=void 0,g=void 0,f=void 0,h.clear(),y.length=0,v.length=0,$.clear(),d=c.workflowId,u=c.ts,l="running",E=Date.now(),I=E,S!==void 0&&S!==c.workflowId&&(x.shouldRun=void 0,x.onBeforeStart=void 0),S=c.workflowId,x.onAfterStep=new Map;break}case"workflow_success":l="success",s=c.ts,g=c.durationMs,I=Date.now();break;case"workflow_error":l="error",s=c.ts,f=c.error,g=c.durationMs,I=Date.now();break;case"workflow_cancelled":l="aborted",s=c.ts,g=c.durationMs,I=Date.now();break;case"step_start":{let m=k(c);h.set(m,{id:m,name:c.name,key:c.stepKey,startTs:c.ts,retryCount:0,timedOut:!1,metadata:c.metadata}),I=Date.now();break}case"step_success":{let m=k(c),p=h.get(m);if(p){let P={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};T(P),h.delete(m)}break}case"step_error":{let m=k(c),p=h.get(m);if(p){let P={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,error:c.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata},...c.diagnostics&&{errorDiagnostics:c.diagnostics}};T(P),h.delete(m)}break}case"step_aborted":{let m=k(c),p=h.get(m);if(p){let P={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs},...p.metadata&&{metadata:p.metadata}};T(P),h.delete(m)}break}case"step_cache_hit":{let p={type:"step",id:k(c),name:c.name,key:c.stepKey,state:"cached",startTs:c.ts,endTs:c.ts,durationMs:0};T(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let m=k(c),p=h.get(m);p&&(p.timedOut=!0,p.timeoutMs=c.timeoutMs),I=Date.now();break}case"step_retry":{let m=k(c),p=h.get(m);p&&(p.retryCount=(c.attempt??1)-1),I=Date.now();break}case"step_retries_exhausted":I=Date.now();break;case"step_skipped":{let p={type:"step",id:k(c),name:c.name,key:c.stepKey,state:"skipped",startTs:c.ts,endTs:c.ts,durationMs:0,...c.metadata&&{metadata:c.metadata}};T(p);break}case"decision":{let m=c;if(m.phase==="start"){H({type:"decision_start",workflowId:c.workflowId,decisionId:m.decisionId,name:m.label??m.decisionId,condition:m.label,decisionValue:m.value,ts:m.ts}),H({type:"decision_branch",workflowId:c.workflowId,decisionId:m.decisionId,branchLabel:"then",condition:m.label,taken:m.branch==="then",ts:m.ts}),H({type:"decision_branch",workflowId:c.workflowId,decisionId:m.decisionId,branchLabel:"else",taken:m.branch==="else",ts:m.ts});break}if(m.phase==="end"){H({type:"decision_end",workflowId:c.workflowId,decisionId:m.decisionId,branchTaken:m.branch,ts:m.ts,durationMs:m.durationMs??0});break}let p={type:"decision",id:m.decisionId,name:m.label??m.decisionId,state:"success",startTs:m.ts,endTs:m.ts,durationMs:0,condition:m.label,decisionValue:m.value,branchTaken:m.branch,branches:[{label:"then",condition:m.label,taken:m.branch==="then",children:[]},{label:"else",taken:m.branch==="else",children:[]}]};T(p),I=Date.now();break}case"hook_should_run":{let m={type:"shouldRun",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};x.shouldRun=m,S=c.workflowId,I=Date.now();break}case"hook_should_run_error":{let m={type:"shouldRun",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};x.shouldRun=m,S=c.workflowId,I=Date.now();break}case"hook_before_start":{let m={type:"onBeforeStart",state:"success",ts:c.ts,durationMs:c.durationMs,context:{result:c.result,skipped:c.skipped}};x.onBeforeStart=m,S=c.workflowId,I=Date.now();break}case"hook_before_start_error":{let m={type:"onBeforeStart",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error};x.onBeforeStart=m,S=c.workflowId,I=Date.now();break}case"hook_after_step":{let m={type:"onAfterStep",state:"success",ts:c.ts,durationMs:c.durationMs,context:{stepKey:c.stepKey}};x.onAfterStep.set(c.stepKey,m),I=Date.now();break}case"hook_after_step_error":{let m={type:"onAfterStep",state:"error",ts:c.ts,durationMs:c.durationMs,error:c.error,context:{stepKey:c.stepKey}};x.onAfterStep.set(c.stepKey,m),I=Date.now();break}case"stream_created":{let m=`${c.workflowId}:${c.namespace}`;$.set(m,{id:ke(),namespace:c.namespace,startTs:c.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),I=Date.now();break}case"stream_write":{let m=`${c.workflowId}:${c.namespace}`,p=$.get(m);p&&(p.writeCount++,p.finalPosition=Math.max(p.finalPosition,c.position)),I=Date.now();break}case"stream_read":{let m=`${c.workflowId}:${c.namespace}`,p=$.get(m);p&&p.readCount++,I=Date.now();break}case"stream_close":{let m=`${c.workflowId}:${c.namespace}`,p=$.get(m);if(p){p.streamState="closed",p.finalPosition=c.finalPosition;let P={type:"stream",id:p.id,namespace:p.namespace,state:"success",startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.finalPosition,streamState:"closed",backpressureOccurred:p.backpressureOccurred};T(P),$.delete(m)}I=Date.now();break}case"stream_error":{let m=`${c.workflowId}:${c.namespace}`,p=$.get(m);if(p){p.streamState="error";let P={type:"stream",id:p.id,namespace:p.namespace,state:"error",error:c.error,startTs:p.startTs,endTs:c.ts,durationMs:c.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:c.position,streamState:"error",backpressureOccurred:p.backpressureOccurred};T(P),$.delete(m)}I=Date.now();break}case"stream_backpressure":{let m=`${c.workflowId}:${c.namespace}`,p=$.get(m);p&&(p.backpressureOccurred=!0),I=Date.now();break}}M(c)}function B(c){if(c.type==="scope_start")y.push({id:c.scopeId,name:c.name,type:c.scopeType,startTs:c.ts,children:[]}),I=Date.now();else if(c.type==="scope_end"){let m=y.findIndex(C=>C.id===c.scopeId);if(m===-1)return;for(;y.length>m+1;){let C=y.pop(),Y=C.type==="race"?{type:"race",id:C.id,name:C.name,state:_(C.children),startTs:C.startTs,endTs:c.ts,children:C.children}:{type:"parallel",id:C.id,name:C.name,state:_(C.children),startTs:C.startTs,endTs:c.ts,children:C.children,mode:C.type==="allSettled"?"allSettled":"all"};y[y.length-1].children.push(Y)}let[p]=y.splice(m,1),P=p.type==="race"?{type:"race",id:p.id,name:p.name,state:_(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,winnerId:c.winnerId}:{type:"parallel",id:p.id,name:p.name,state:_(p.children),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,children:p.children,mode:p.type==="allSettled"?"allSettled":"all"};T(P)}}function H(c){if(c.type==="decision_start")v.push({id:c.decisionId,name:c.name,condition:c.condition,decisionValue:c.decisionValue,startTs:c.ts,branches:new Map,pendingChildren:[]}),I=Date.now();else if(c.type==="decision_branch"){let m=v.find(p=>p.id===c.decisionId);if(m){let p=c.branchLabel,P=m.branches.get(p);if(P)P.taken=c.taken,c.taken&&m.pendingChildren.length>0&&(P.children.unshift(...m.pendingChildren),m.pendingChildren=[]);else{let C=c.taken?[...m.pendingChildren]:[];c.taken&&(m.pendingChildren=[]),m.branches.set(p,{label:c.branchLabel,condition:c.condition,taken:c.taken,children:C})}I=Date.now()}}else if(c.type==="decision_end"){let m=v.findIndex(p=>p.id===c.decisionId);if(m!==-1){let[p]=v.splice(m,1),P=v.splice(m),C=Array.from(p.branches.values());C.length===0&&p.pendingChildren.length>0&&(C=[{label:"default",taken:!0,children:[...p.pendingChildren]}]);let Y=C.find(ye=>ye.taken)?.label,St={type:"decision",id:p.id,name:p.name,state:_(C.flatMap(ye=>ye.taken?ye.children:[])),startTs:p.startTs,endTs:c.ts,durationMs:c.durationMs,condition:p.condition,decisionValue:p.decisionValue,branchTaken:c.branchTaken??Y,branches:C};T(St),v.push(...P),I=Date.now()}}}function _(c){return c.length===0?"success":c.some(C=>C.state==="error")?"error":c.every(C=>C.state==="success"||C.state==="cached")?"success":c.some(C=>C.state==="running")?"running":"pending"}function re(){let c=[...N];for(let[,m]of h)c.push({type:"step",id:m.id,name:m.name,key:m.key,state:"running",startTs:m.startTs,...m.retryCount>0&&{retryCount:m.retryCount},...m.timedOut&&{timedOut:!0,timeoutMs:m.timeoutMs}});for(let[,m]of $)c.push({type:"stream",id:m.id,namespace:m.namespace,state:"running",startTs:m.startTs,writeCount:m.writeCount,readCount:m.readCount,finalPosition:m.finalPosition,streamState:m.streamState,backpressureOccurred:m.backpressureOccurred});return c}function ne(){let c=re();t&&(c=ve(c,r));let m={type:"workflow",id:d??a,workflowId:d??a,state:l,startTs:u,endTs:s,durationMs:g,children:c,error:f},p=x.shouldRun!==void 0||x.onBeforeStart!==void 0||x.onAfterStep.size>0;return{root:m,metadata:{createdAt:E,lastUpdatedAt:I},...p&&{hooks:x}}}function oe(){d=void 0,u=void 0,s=void 0,l="pending",f=void 0,g=void 0,h.clear(),y.length=0,v.length=0,$.clear(),N=[],E=Date.now(),I=E,x={onAfterStep:new Map},S=void 0,b.length=0,w=0}function yt(){return[...b]}function kt(c){return b[c]}function vt(c){return b[c]?.ir}function xt(){b.length=0,w=0}return{handleEvent:O,handleScopeEvent:B,handleDecisionEvent:H,getIR:ne,reset:oe,getSnapshots:yt,getSnapshotAt:kt,getIRAt:vt,clearSnapshots:xt,get hasActiveSteps(){return h.size>0},get state(){return l},get snapshotCount(){return b.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(c){n=c}}}import{ok as Lt,err as _t}from"awaitly";function K(e){return e.type==="step"}function Ge(e){return e.type==="sequence"}function j(e){return e.type==="parallel"}function z(e){return e.type==="race"}function J(e){return e.type==="decision"}function ee(e){return e.type==="stream"}function an(e){return"children"in e||e.type==="decision"&&"branches"in e}var Le="\x1B[0m",Et="\x1B[1m",Je="\x1B[2m",Mt="\x1B[31m",Nt="\x1B[32m",Tt="\x1B[33m",Dt="\x1B[34m",Ye="\x1B[90m",Ot="\x1B[37m";function X(e,t){return t?`${t}${e}${Le}`:e}function ge(e){return`${Et}${e}${Le}`}function D(e){return`${Je}${e}${Le}`}var V={pending:Ot,running:Tt,success:Nt,error:Mt,aborted:Ye,cached:Dt,skipped:Je+Ye};function Ct(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 we(e,t){let r=Ct(e);return X(r,t[e])}function xe(e,t,r){return X(e,r[t])}function Q(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"},de={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Wt="\x1B[0m";function Bt(e){return e<.2?de.cold:e<.4?de.cool:e<.6?de.neutral:e<.8?de.warm:e<.95?de.hot:de.critical}function Xe(e,t){let r=Bt(t);return r?`${r}${e}${Wt}`:e}function At(e){try{return Lt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let i=Number(o);return Number.isSafeInteger(i)?i:o.toString()}))}catch{return _t("STRINGIFY_ERROR")}}function qe(e){let t=At(e);return t.ok?t.value:"[unserializable]"}var Ze="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function We(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(a=>{let d=(a-o)/n,u=Math.floor(d*(Ze.length-1));return Ze[u]}).join("")}function _e(e,t){let r=Q(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function Pt(e,t){if(!t)return R.horizontal.repeat(e);let r=` ${t} `,o=Q(r).length,i=e-o;if(i<4)return R.horizontal.repeat(e);let n=2,a=i-n;return R.horizontal.repeat(n)+r+R.horizontal.repeat(a)}function Qe(e,t,r){let o=e.state==="success"?X("\u2699",r.success):X("\u26A0",r.error),i=e.durationMs!==void 0?D(` [${A(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=D(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=D(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=D(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=D(` (${e.context.stepKey})`));let a=e.state==="error"&&e.error?D(` error: ${String(e.error)}`):"";return`${o} ${D(t)}${n}${i}${a}`}function Ht(e,t){let r=[];return e.shouldRun&&r.push(Qe(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Qe(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(D("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function le(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...V,...t.colors},o=Math.max(t.terminalWidth??60,5),i=o-4,n=[],a=e.root.name??"workflow",d=ge(a);if(n.push(`${R.topLeft}${Pt(o-2,d)}${R.topRight}`),n.push(`${R.vertical}${" ".repeat(o-2)}${R.vertical}`),e.hooks){let s=Ht(e.hooks,r);for(let l of s)n.push(`${R.vertical} ${_e(l,i)}${R.vertical}`)}let u=Se(e.root.children,t,r,0,e.hooks);for(let s of u)n.push(`${R.vertical} ${_e(s,i)}${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",f=`${xe(s,e.root.state,r)} in ${A(e.root.durationMs)}`;n.push(`${R.vertical} ${_e(f,i)}${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 Se(e,t,r,o,i){let n=[];for(let a of e)K(a)?n.push(Be(a,t,r,i)):j(a)?n.push(...zt(a,t,r,o,i)):z(a)?n.push(...Ut(a,t,r,o,i)):J(a)?n.push(...Kt(a,t,r,o,i)):ee(a)&&n.push(Ft(a,t,r));return n}function Be(e,t,r,o){let i=we(e.state,r),n=e.name??e.key??"step",a=t,d=a.showHeatmap&&a.heatmapData?a.heatmapData.heat.get(e.key??"")??a.heatmapData.heat.get(e.name??"")??a.heatmapData.heat.get(e.id):void 0,u;d!==void 0?u=Xe(n,d):u=xe(n,e.state,r);let s=`${i} ${u}`;if(t.showKeys&&e.key&&e.name&&(s+=D(` [key: ${e.key}]`)),e.input!==void 0){let f=typeof e.input=="string"?e.input:qe(e.input).slice(0,30);s+=D(` [in: ${f}${f.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let f=typeof e.output=="string"?e.output:qe(e.output).slice(0,30);s+=D(` [out: ${f}${f.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let f=A(e.durationMs),g=d!==void 0?Xe(`[${f}]`,d):D(`[${f}]`);s+=` ${g}`}if(a.showSparklines&&a.timingHistory){let f=a.timingHistory.get(e.key??"")??a.timingHistory.get(e.name??"")??a.timingHistory.get(e.id);f&&f.length>1&&(s+=` ${D(We(f))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(s+=D(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let f=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";s+=D(` [timeout${f}]`)}let l=e.key??e.id;if(o&&l&&o.onAfterStep.has(l)){let f=o.onAfterStep.get(l),g=f.state==="success"?X("\u2699",r.success):X("\u26A0",r.error),h=f.durationMs!==void 0?D(` ${A(f.durationMs)}`):"";s+=` ${g}${h}`}return s}function Ft(e,t,r){let o=e.streamState==="active"?X("\u27F3",r.running):e.streamState==="closed"?X("\u2713",r.success):X("\u2717",r.error),i=`stream:${e.namespace}`,n=xe(i,e.state,r),a=D(`[W:${e.writeCount} R:${e.readCount}]`),d=`${o} ${n} ${a}`;return t.showTimings&&e.durationMs!==void 0&&(d+=` ${D(`[${A(e.durationMs)}]`)}`),e.backpressureOccurred&&(d+=D(" [backpressure]")),e.streamState==="closed"&&(d+=D(` pos:${e.finalPosition}`)),d}function zt(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"parallel",s=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${a}${R.teeRight}${R.teeDown}${R.horizontal} ${d} ${ge(u)}${s}`),e.children.length===0)n.push(`${a}${R.vertical} ${D("(operations not individually tracked)")}`),n.push(`${a}${R.vertical} ${D("(wrap each operation with step() to see individual steps)")}`);else for(let l=0;l<e.children.length;l++){let f=e.children[l],h=l===e.children.length-1?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`;if(K(f))n.push(`${h} ${Be(f,t,r,i)}`);else{let y=Se([f],t,r,o+1,i);for(let v of y)n.push(`${a}${R.vertical} ${v}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}function Ut(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"race";if(n.push(`${a}${R.teeRight}\u26A1 ${d} ${ge(u)}`),e.children.length===0)n.push(`${a}${R.vertical} ${D("(operations not individually tracked)")}`),n.push(`${a}${R.vertical} ${D("(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?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`,y=e.winnerId&&l.id===e.winnerId?D(" (winner)"):"";if(K(l))n.push(`${g} ${Be(l,t,r,i)}${y}`);else{let v=Se([l],t,r,o+1,i);for(let $ of v)n.push(`${a}${R.vertical} ${$}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}function Kt(e,t,r,o,i){let n=[],a=" ".repeat(o),d=we(e.state,r),u=e.name??"decision",s=e.condition?D(` (${e.condition})`):"",l=e.decisionValue!==void 0?D(` = ${String(e.decisionValue)}`):"",f=e.branchTaken!==void 0?D(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${a}${R.teeRight}${R.teeDown}${R.horizontal} ${d} ${ge(u)}${s}${l}${f}`);for(let g=0;g<e.branches.length;g++){let h=e.branches[g],v=g===e.branches.length-1?`${a}${R.vertical} ${R.bottomLeft}`:`${a}${R.vertical} ${R.teeRight}`,$=h.taken?"\u2713":"\u2298",N=h.taken?r.success:r.skipped,E=X(`${$} ${h.label}`,N),I=h.condition?D(` (${h.condition})`):"";if(n.push(`${v} ${E}${I}`),h.children.length>0){let x=Se(h.children,t,r,o+1,i);for(let S of x)n.push(`${a}${R.vertical} ${S}`)}else h.taken||n.push(`${a}${R.vertical} ${D("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${a}${R.bottomLeft}${R.horizontal}${R.horizontal} ${D(`[${A(e.durationMs)}]`)}`),n}import{ok as Vt,err as Gt}from"awaitly";function Ae(e){let t=[];for(let r of e)if(t.push(r),"children"in r&&Array.isArray(r.children)&&t.push(...Ae(r.children)),"branches"in r)for(let o of r.branches)t.push(...Ae(o.children));return t}function Re(e,t){if(e.length===0)return 0;let r=Math.floor(e.length*t);return e[Math.min(r,e.length-1)]}function be(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function jt(){let e=new Map,t=new Map,r=new Map,o=new Map,i=[];function n(x){return x.stepKey??x.stepId??x.name??"unknown"}function a(x){let S=new Map;for(let b of x)switch(b.type){case"step_start":{let w=n(b);S.set(w,{retried:!1,timedOut:!1});break}case"step_retry":{let w=n(b),k=S.get(w);k&&(k.retried=!0);break}case"step_timeout":{let w=n(b),k=S.get(w);k&&(k.timedOut=!0);break}case"step_success":{let w=n(b),k=S.get(w),T=e.get(w)??[];T.push(b.durationMs),e.set(w,T);let M=t.get(w)??{retried:0,total:0};M.total++,k?.retried&&M.retried++,t.set(w,M);let O=o.get(w)??{timedOut:0,total:0};O.total++,k?.timedOut&&O.timedOut++,o.set(w,O);let B=r.get(w)??{errors:0,total:0};B.total++,r.set(w,B),S.delete(w);break}case"step_error":{let w=n(b),k=S.get(w),T=e.get(w)??[];T.push(b.durationMs),e.set(w,T);let M=t.get(w)??{retried:0,total:0};M.total++,k?.retried&&M.retried++,t.set(w,M);let O=o.get(w)??{timedOut:0,total:0};O.total++,k?.timedOut&&O.timedOut++,o.set(w,O);let B=r.get(w)??{errors:0,total:0};B.total++,B.errors++,r.set(w,B),S.delete(w);break}}}function d(x){a(x.events)}function u(x){i.push(x)}function s(x){i.length>0&&(a(i),i=[])}function l(x){let S=e.get(x);if(!S||S.length===0)return;let b=[...S].sort((H,_)=>H-_),k=b.reduce((H,_)=>H+_,0)/b.length,T=b.reduce((H,_)=>H+(_-k)**2,0)/b.length,M=t.get(x)??{retried:0,total:1},O=r.get(x)??{errors:0,total:1},B=o.get(x)??{timedOut:0,total:1};return{nodeId:x,avgDurationMs:k,minDurationMs:b[0],maxDurationMs:b[b.length-1],stdDevMs:Math.sqrt(T),samples:b.length,retryRate:M.total>0?M.retried/M.total:0,timeoutRate:B.total>0?B.timedOut/B.total:0,errorRate:O.total>0?O.errors/O.total:0,percentiles:{p50:Re(b,.5),p90:Re(b,.9),p95:Re(b,.95),p99:Re(b,.99)}}}function f(x){return l(x)}function g(x,S="duration"){let b=new Map,w=Ae(x.root.children),k=[];for(let _ of w){let re=("key"in _?_.key:void 0)??_.id??_.name,ne=l(re);if(ne){let oe;switch(S){case"duration":oe=ne.avgDurationMs;break;case"retryRate":oe=ne.retryRate;break;case"errorRate":oe=ne.errorRate;break}k.push({id:_.id,value:oe})}}if(k.length===0)return{heat:b,metric:S,stats:{min:0,max:0,mean:0,threshold:0}};let T=k.map(_=>_.value),M=Math.min(...T),O=Math.max(...T),B=T.reduce((_,re)=>_+re,0)/T.length,H=O-M||1;for(let{id:_,value:re}of k)b.set(_,(re-M)/H);return{heat:b,metric:S,stats:{min:M,max:O,mean:B,threshold:B+(O-B)*.5}}}function h(){let x=new Map;for(let S of e.keys()){let b=l(S);b&&x.set(S,b)}return x}function y(x=10){return[...h().values()].sort((b,w)=>w.avgDurationMs-b.avgDurationMs).slice(0,x)}function v(x=10){return[...h().values()].filter(b=>b.errorRate>0).sort((b,w)=>w.errorRate-b.errorRate).slice(0,x)}function $(x=10){return[...h().values()].filter(b=>b.retryRate>0).sort((b,w)=>w.retryRate-b.retryRate).slice(0,x)}function N(){return JSON.stringify({timingData:Object.fromEntries(e),retryData:Object.fromEntries(t),errorData:Object.fromEntries(r),timeoutData:Object.fromEntries(o)})}function E(x){let S=JSON.parse(x);e.clear(),t.clear(),r.clear(),o.clear();for(let[b,w]of Object.entries(S.timingData??{}))e.set(b,w);for(let[b,w]of Object.entries(S.retryData??{}))t.set(b,w);for(let[b,w]of Object.entries(S.errorData??{}))r.set(b,w);for(let[b,w]of Object.entries(S.timeoutData??{}))o.set(b,w)}function I(){e.clear(),t.clear(),r.clear(),o.clear(),i=[]}return{addRun:d,addEvent:u,finalizeRun:s,getNodePerformance:f,getHeatmap:g,getSlowestNodes:y,getErrorProneNodes:v,getRetryProneNodes:$,getAllPerformance:h,exportData:N,importData:E,clear:I}}function Yt(){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 Jt(){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 Xt(e){return`heat_${e}`}function qt(){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 Zt(e){try{return Vt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let i=Number(o);return Number.isSafeInteger(i)?i:o.toString()}))}catch{return Gt("STRINGIFY_ERROR")}}function et(e){let t=Zt(e);return t.ok?t.value:"[unserializable]"}function Qt(e,t,r){let o;if(e.shouldRun){let i="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",a=e.shouldRun.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${A(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${i}[["${a} shouldRun${u}${d}"]]:::${n}`),o=i}if(e.onBeforeStart){let i="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",a=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",d=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${A(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${i}[["${a} onBeforeStart${u}${d}"]]:::${n}`),o&&t.push(` ${o} --> ${i}`),o=i}return{lastHookId:o}}var tt=0,Ie=new Set,$e=new Set;function ue(e="node"){return`${e}_${++tt}`}function er(){tt=0,Ie.clear(),$e.clear()}function U(e){return e.replace(/"/g,"#quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").trim()}function rt(e){return U(e).replace(/[{}[\]()]/g,"")}function ie(){return{name:"mermaid",supportsLive:!1,render(e,t){er();let r=[],o=t;r.push("flowchart TD");let i;e.hooks&&(i=Qt(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),i&&r.push(` ${i} --> ${n}`);let a=n;for(let u of e.root.children){let s=Ee(u,t,r,o,e.hooks);r.push(` ${a} --> ${s.entryId}`),a=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",f=`(("${s} ${l}"))`,g=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${u}${f}${g}`),r.push(` ${a} --> ${u}`)}return r.push(""),r.push(...Yt()),o.showHeatmap&&r.push(...Jt()),e.hooks&&r.push(...qt()),r.join(`
3
+ `)}}}function Ee(e,t,r,o,i){if(K(e))return tr(e,t,r,o,i);if(j(e))return rr(e,t,r,o,i);if(z(e))return nr(e,t,r,o,i);if(J(e))return or(e,t,r,o,i);if(ee(e))return ir(e,t,r);let n=ue("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function tr(e,t,r,o,i){let n=t,a=n.showRetryEdges??!0,d=n.showErrorEdges??!0,u=n.showTimeoutEdges??!0,s=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ue("step");if($e.has(s)){let b=2;for(;$e.has(`${s}_${b}`);)b++;s=`${s}_${b}`}$e.add(s);let l=e.name??e.key??"Step",f=t.showKeys&&e.key&&e.name?`${l} [${e.key}]`:l,g=U(f),h=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"",y="";switch(e.state){case"success":y="\u2713 ";break;case"error":y="\u2717 ";break;case"cached":y="\u{1F4BE} ";break;case"running":y="\u23F3 ";break;case"skipped":y="\u2298 ";break}let v="";if(e.input!==void 0){let b=typeof e.input=="string"?U(e.input):U(et(e.input).slice(0,20));v+=`\\nin: ${b}`}if(e.output!==void 0&&e.state==="success"){let b=typeof e.output=="string"?U(e.output):U(et(e.output).slice(0,20));v+=`\\nout: ${b}`}let $="",N=e.key??e.id;if(i&&N&&i.onAfterStep.has(N)){let b=i.onAfterStep.get(N),w=b.state==="success"?"\u2699":"\u26A0",k=t.showTimings&&b.durationMs!==void 0?` ${A(b.durationMs)}`:"";$=`\\n${w} hook${k}`}let E=(y+g+v+$+h).trim(),I,x=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(x!==void 0){let b=be(x);I=Xt(b)}else I=e.state;let S;switch(e.state){case"error":S=`{{"${E}"}}`;break;case"cached":S=`[("${E}")]`;break;case"skipped":S=`["${E}"]`;break;default:S=`["${E}"]`}if(r.push(` ${s}${S}:::${I}`),a&&e.retryCount!==void 0&&e.retryCount>0){let b=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${s} -.->|"${b}"| ${s}`)}if(d&&e.state==="error"&&e.error!==void 0){let b=`ERR_${s}`,w=U(String(e.error)).slice(0,30);r.push(` ${b}{{"${w}"}}`),r.push(` ${s} -->|error| ${b}`),r.push(` style ${b} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let b=`TO_${s}`,w=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${b}{{"\u23F1 Timeout ${w}"}}`),r.push(` ${s} -.->|timeout| ${b}`),r.push(` style ${b} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:s,exitId:s}}function rr(e,t,r,o,i){let n=ue("parallel"),a=`${n}_fork`,d=`${n}_join`,u=rt(e.name??"Parallel"),s=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let g=n,h=U(`${u}${s}`),y="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"";return r.push(` ${g}["${h}${v}\\n${y}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["${u}${s}"]`),r.push(" direction TB"),r.push(` ${a}{"\u26A1 Fork"}`);let l=[];for(let g of e.children){let h=Ee(g,t,r,o,i);r.push(` ${a} --> ${h.entryId}`),l.push(h.exitId)}r.push(` ${d}{"\u2713 Join"}`);for(let g of l)r.push(` ${g} --> ${d}`);r.push(" end");let f=e.state;return r.push(` class ${n} ${f}`),{entryId:a,exitId:d}}function nr(e,t,r,o,i){let n=ue("race"),a=`${n}_start`,d=`${n}_end`,u=rt(e.name??"Race");if(e.children.length===0){let g=n,h=U(u),y="operations not individually tracked",v=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"";return r.push(` ${g}["\u26A1 ${h}${v}\\n${y}"]:::${e.state}`),{entryId:g,exitId:g}}r.push(` subgraph ${n}["\u26A1 ${u}"]`),r.push(" direction TB"),r.push(` ${a}(("\u{1F3C1} Start"))`);let s=[],l;for(let g of e.children){let h=Ee(g,t,r,o,i),y=e.winnerId===g.id;r.push(` ${a} --> ${h.entryId}`),y&&(l=h.exitId),s.push({exitId:h.exitId,isWinner:y})}r.push(` ${d}(("\u2713 First"))`);for(let{exitId:g,isWinner:h}of s)h&&l?r.push(` ${g} ==>|\u{1F3C6} Winner| ${d}`):e.winnerId?r.push(` ${g} -. cancelled .-> ${d}`):r.push(` ${g} --> ${d}`);r.push(" end");let f=e.state;return r.push(` class ${n} ${f}`),{entryId:a,exitId:d}}function or(e,t,r,o,i){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ue("decision");if(Ie.has(n)){let g=2;for(;Ie.has(`${n}_${g}`);)g++;n=`${n}_${g}`}Ie.add(n);let a=U(e.condition??"condition"),d=e.decisionValue!==void 0?` = ${U(String(e.decisionValue)).slice(0,30)}`:"",u=`${a}${d}`.trim();r.push(` ${n}{"${u}"}`);let s=[],l,f=new Set;for(let g of e.branches){let h=`${n}_${g.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(f.has(h)){let E=2;for(;f.has(`${h}_${E}`);)E++;h=`${h}_${E}`}f.add(h);let y=U(g.label),v=g.taken?`${y} \u2713`:`${y} skipped`,$=g.taken?":::success":":::skipped";r.push(` ${h}["${v}"]${$}`);let N=g.condition?`|${U(g.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${N} ${h}`),g.children.length>0){let E=h;for(let I of g.children){let x=Ee(I,t,r,o,i);r.push(` ${E} --> ${x.entryId}`),E=x.exitId}s.push(E),g.taken&&(l=E)}else s.push(h),g.taken&&(l=h)}return l?{entryId:n,exitId:l}:{entryId:n,exitId:n}}function ir(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${ue("")}`,i=`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 a=t.showTimings&&e.durationMs!==void 0?` ${A(e.durationMs)}`:"",d=e.backpressureOccurred?"\\nbackpressure":"",u=`${n}stream:${U(e.namespace)}\\n${i}${d}${a}`,s;return e.streamState==="error"?s="streamError":e.streamState==="active"?s="streamActive":s="stream",r.push(` ${o}{{"${u}"}}:::${s}`),{entryId:o,exitId:o}}var L={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},ar={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},sr="\x1B[0m";function cr(e,t){let r=[],o=[];for(let i=0;i<t;i++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function W(e,t,r,o,i){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,i&&(e.colors[r][t]=i))}function it(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function dr(e,t,r,o,i){W(e,t,r,L.topLeft);for(let n=1;n<o-1;n++)W(e,t+n,r,L.horizontal);W(e,t+o-1,r,L.topRight);for(let n=1;n<i-1;n++)W(e,t,r+n,L.vertical),W(e,t+o-1,r+n,L.vertical);W(e,t,r+i-1,L.bottomLeft);for(let n=1;n<o-1;n++)W(e,t+n,r+i-1,L.horizontal);W(e,t+o-1,r+i-1,L.bottomRight)}function nt(e,t,r,o,i){let n=Q(o).split("");for(let a=0;a<n.length;a++)W(e,t+a,r,n[a],i)}function te(e,t,r,o){let i=Math.min(r,o),n=Math.max(r,o);for(let a=i;a<=n;a++){let d=it(e,t,a);d===L.horizontal?W(e,t,a,L.cross):(d===" "||d===L.vertical)&&W(e,t,a,L.vertical)}}function ot(e,t,r,o){let i=Math.min(r,o),n=Math.max(r,o);for(let a=i;a<=n;a++){let d=it(e,a,t);d===L.vertical?W(e,a,t,L.cross):(d===" "||d===L.horizontal)&&W(e,a,t,L.horizontal)}}function se(e,t,r){W(e,t,r,L.arrowDown)}function lr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let i=0;i<e.width;i++){let n=e.colors[r][i],a=e.cells[r][i];n?o+=n+a+sr:o+=a}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
4
+ `)}var q=11,Z=2,pe=2,Me=3;function He(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],i="";for(let n of r)i?i.length+1+n.length<=t?i+=" "+n:(o.push(i),i=n):i=n;if(i&&o.push(i),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function at(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function ur(e,t,r){let o=t.showStartEnd??!0,i=t,n=Math.floor(r/2),a=[],d=0;if(o){let s=Ne("start","start",["\u25B6 Start"],"success",n,d);a.push(s),d=s.bottomY+pe}for(let s of e.root.children){let l=Te(s,n,d,r-4,t,i);a.push(l.node),d=l.bottomY+pe}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=Ne("end","end",[s],e.root.state,n,d);a.push(l),d=l.bottomY}return{nodes:a,totalHeight:d+2}}function Ne(e,t,r,o,i,n){let a=Math.max(...r.map(l=>Q(l).length)),d=Math.max(q,a+Z*2),u=r.length+2,s=i-Math.floor(d/2);return{id:e,type:t,label:r,state:o,x:s,y:n,width:d,height:u,centerX:i,bottomY:n+u-1}}function Te(e,t,r,o,i,n){if(K(e))return pr(e,t,r,o,i,n);if(j(e)||z(e))return mr(e,t,r,o,i,n);if(J(e))return hr(e,t,r,o,i,n);if(ee(e))return fr(e,t,r,o,i,n);let a=Ne(e.id,"step",["?"],e.state,t,r);return{node:a,bottomY:a.bottomY}}function pr(e,t,r,o,i,n){let a=e.name??e.key??"step",d=at(e.state),u=[],s=`${d} ${a}`;i.showKeys&&e.key&&e.name&&(s+=` [${e.key}]`);let l=Math.min(o-Z*2,40);if(u.push(...He(s,l)),i.showTimings&&e.durationMs!==void 0&&u.push(`[${A(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),n?.showSparklines&&n.timingHistory){let N=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);N&&N.length>1&&u.push(We(N,8))}let f=Math.max(...u.map(N=>Q(N).length)),g=Math.max(q,f+Z*2),h=u.length+2,y=t-Math.floor(g/2),v;if(n?.showHeatmap&&n.heatmapData){let N=e.key??e.name??e.id;v=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(N)}let $={id:e.id,type:"step",label:u,state:e.state,x:y,y:r,width:g,height:h,centerX:t,bottomY:r+h-1,metadata:v!==void 0?{heat:v}:void 0};return{node:$,bottomY:$.bottomY}}function fr(e,t,r,o,i,n){let a=`stream:${e.namespace}`,d=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",u=[],s=`${d} ${a}`,l=Math.min(o-Z*2,40);u.push(...He(s,l)),u.push(`W:${e.writeCount} R:${e.readCount}`),i.showTimings&&e.durationMs!==void 0&&u.push(`[${A(e.durationMs)}]`),e.backpressureOccurred&&u.push("backpressure");let f=Math.max(...u.map($=>Q($).length)),g=Math.max(q,f+Z*2),h=u.length+2,y=t-Math.floor(g/2),v={id:e.id,type:"stream",label:u,state:e.state,x:y,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 mr(e,t,r,o,i,n){let a=z(e),d=e.name??(a?"race":"parallel"),s=`${a?"\u26A1":"\u2AD8"} ${d}`;if(e.children.length===0){let w=[s,"(not tracked)"],k=Ne(e.id,a?"race":"parallel",w,e.state,t,r);return{node:k,bottomY:k.bottomY}}let l=Math.floor((o-Me*(e.children.length-1))/e.children.length),f=[];for(let w of e.children){let k=Pe(w,Math.max(l,q),i,n);f.push(k.width)}let g=f.reduce((w,k)=>w+k,0)+Me*(e.children.length-1),h=g>o&&e.children.length>1,y=Math.max(q,s.length+Z*2),v=3,$=t-Math.floor(y/2),N=r;N+=v,N+=1,N+=1;let E=[];if(h)for(let w=0;w<e.children.length;w++){let k=e.children[w],T=Te(k,t,N,o,i,n);a&&z(e)&&e.winnerId===k.id&&(T.node.metadata={...T.node.metadata,isWinner:!0}),E.push(T.node),N=T.bottomY+pe}else{let w=t-Math.floor(g/2);for(let k=0;k<e.children.length;k++){let T=e.children[k],M=w+Math.floor(f[k]/2),O=Te(T,M,N,f[k],i,n);a&&z(e)&&e.winnerId===T.id&&(O.node.metadata={...O.node.metadata,isWinner:!0}),E.push(O.node),w+=f[k]+Me}}let I=Math.max(...E.map(w=>w.bottomY)),S=!h&&E.length>1?I+2:I;return{node:{id:e.id,type:a?"race":"parallel",label:[s],state:e.state,x:$,y:r,width:y,height:v,centerX:t,bottomY:S,children:E,metadata:{verticalLayout:h}},bottomY:S}}function hr(e,t,r,o,i,n){let a=e.name??"decision",d=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${a}${d}`,s=Math.min(o-Z*2,40),l=He(u,s),f=Math.max(...l.map(S=>Q(S).length)),g=Math.max(q,f+Z*2),h=l.length+2,y=t-Math.floor(g/2),v=e.branches.find(S=>S.taken),$=v&&v.children.length>0?v:e.branches.find(S=>S.children.length>0);if(!$||$.children.length===0){let S={id:e.id,type:"decision",label:l,state:e.state,x:y,y:r,width:g,height:h,centerX:t,bottomY:r+h-1};return{node:S,bottomY:S.bottomY}}let N=r+h+pe,E=[];for(let S of $.children){let b=Te(S,t,N,o,i,n);E.push(b.node),N=b.bottomY+pe}let I=E.length>0?E[E.length-1].bottomY:r+h-1;return{node:{id:e.id,type:"decision",label:l,state:e.state,x:y,y:r,width:g,height:h,centerX:t,bottomY:I,children:E},bottomY:I}}function Pe(e,t,r,o){if(K(e)){let i=e.name??e.key??"step",n=at(e.state),a=1;r.showTimings&&e.durationMs!==void 0&&a++,e.retryCount&&e.retryCount>0&&a++,e.timedOut&&a++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&a++;let d=`${n} ${i}`;r.showKeys&&e.key&&e.name&&(d+=` [${e.key}]`);let u=Math.min(t,Math.max(q,d.length+Z*2)),s=a+2;return{width:u,height:s}}if(j(e)||z(e)){if(e.children.length===0)return{width:q+4,height:4};let i=Math.floor(t/e.children.length),n=0,a=0;for(let d of e.children){let u=Pe(d,i,r,o);n+=u.width,a=Math.max(a,u.height)}return n+=Me*(e.children.length-1),{width:Math.max(n,q),height:5+a+2}}if(J(e)){let i=e.branches.find(a=>a.taken),n=0;if(i)for(let a of i.children){let d=Pe(a,t,r,o);n+=d.height+pe}return{width:Math.min(t,30),height:3+n}}if(ee(e)){let i=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let a=Math.min(t,Math.max(q,i.length+Z*2+4)),d=n+2;return{width:a,height:d}}return{width:q,height:3}}function gr(e,t,r){let o={...V,...r.colors};for(let i=0;i<t.length;i++){let n=t[i],a=i===t.length-1;if(De(e,n,o),!a){let d=t[i+1],u=n.centerX,s=n.bottomY+1,l=d.centerX,f=d.y-1;te(e,u,s,f-1),se(e,l,f)}}}function De(e,t,r){let o=t.type!=="start",i=t.type!=="end"&&(!t.children||t.children.length===0);dr(e,t.x,t.y,t.width,t.height),o&&W(e,t.centerX,t.y,L.teeUp),(i||t.children&&t.children.length>0)&&W(e,t.centerX,t.y+t.height-1,L.teeDown);let n=t.width-Z*2,a=kr(t,r);for(let d=0;d<t.label.length;d++){let u=t.label[d],s=t.x+1+Math.floor((n-Q(u).length)/2),l=t.y+1+d;nt(e,s,l,u,a)}t.metadata?.isWinner&&nt(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?wr(e,t,r):br(e,t,r))}function wr(e,t,r){let o=t.children;if(o.length===0)return;let i=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let d=o[0];te(e,n,i,d.y-2),se(e,d.centerX,d.y-1);for(let u=0;u<o.length;u++){let s=o[u];if(De(e,s,r),u<o.length-1){let l=o[u+1];te(e,s.centerX,s.bottomY+1,l.y-2),se(e,l.centerX,l.y-1)}}return}if(o.length===1)te(e,n,i,o[0].y-2),se(e,o[0].centerX,o[0].y-1);else{let d=o.map(l=>l.centerX),u=Math.min(...d),s=Math.max(...d);te(e,n,i,i+1),ot(e,i+1,u,s),W(e,n,i+1,L.teeUp);for(let l of o){let f=l.centerX;f===u?W(e,f,i+1,L.topLeft):f===s?W(e,f,i+1,L.topRight):f!==n&&W(e,f,i+1,L.teeDown),te(e,f,i+2,l.y-2),se(e,f,l.y-1)}}for(let d of o)De(e,d,r);if(o.length>1){let d=o.map(h=>h.bottomY),u=Math.max(...d),s=u+1,l=o.map(h=>h.centerX),f=Math.min(...l),g=Math.max(...l);for(let h of o)h.bottomY<u&&te(e,h.centerX,h.bottomY+1,s-1);ot(e,s,f,g);for(let h of o){let y=h.centerX;y===f?W(e,y,s,L.bottomLeft):y===g?W(e,y,s,L.bottomRight):W(e,y,s,L.teeUp)}W(e,t.centerX,s,L.teeDown),W(e,t.centerX,s+1,L.vertical)}}function br(e,t,r){let o=t.children;if(o.length===0)return;let i=t.y+t.height,n=o[0];te(e,t.centerX,i,n.y-2),se(e,n.centerX,n.y-1);for(let a=0;a<o.length;a++){let d=o[a];if(De(e,d,r),a<o.length-1){let u=o[a+1];te(e,d.centerX,d.bottomY+1,u.y-2),se(e,u.centerX,u.y-1)}}}var yr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function kr(e,t){if(e.metadata?.heat!==void 0){let r=be(e.metadata.heat);return ar[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?yr[e.metadata.streamState]||void 0:t[e.state]||void 0}function fe(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:i}=ur(e,t,r),n=cr(r,i);return gr(n,o,t),lr(n)}}}function vr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function xr(e){let t=[];function r(o){for(let i of o)if(K(i))t.push(i);else if(Ge(i))r(i.children);else if(j(i)||z(i))r(i.children);else if(J(i))for(let n of i.branches)n.taken&&r(n.children)}return r(e),t}function Sr(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 Rr(e){let t=0,r=0,o=0,i=0,n=0,a;for(let s of e)s.state==="success"&&t++,s.state==="error"&&r++,s.state==="cached"&&o++,s.state==="skipped"&&i++,s.retryCount!==void 0&&(n+=s.retryCount),s.durationMs!==void 0&&(!a||s.durationMs>a.durationMs)&&(a={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 f=d.get(l)??{total:0,errors:0,totalDuration:0};f.total++,s.state==="error"&&f.errors++,s.durationMs!==void 0&&(f.totalDuration+=s.durationMs),d.set(l,f)}}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:i,totalRetries:n,slowestStep:a,...u&&{byDomain:u}}}function Ir(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 i={stepKey:r};o.durationMs!==void 0&&(i.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(i.error=String(o.error)),t.onAfterStep.push(i)}}return t}function $r(e,t){let r=e.root,o=xr(r.children),i=t.includeDiagram??!0,n=t.stripAnsiColors??!0,a={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(Sr),summary:Rr(o)};if(e.hooks){let d=Ir(e.hooks);Object.keys(d).length>0&&(a.hooks=d)}if(i){let s=((t.diagramFormat??"ascii")==="flowchart"?fe():le()).render(e,t);n&&(s=vr(s)),a.diagram=s}return a}function Oe(){return{name:"logger",supportsLive:!1,render(e,t){let o=$r(e,t);return JSON.stringify(o)}}}function st(e){let t={bg:"#ffffff",bgSecondary:"#f8f9fa",text:"#212529",textMuted:"#6c757d",border:"#dee2e6",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#e9ecef",nodeRunning:"#fff3cd",nodeSuccess:"#d1e7dd",nodeError:"#f8d7da",nodeAborted:"#e9ecef",nodeCached:"#cfe2ff",nodeSkipped:"#f8f9fa",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},r={bg:"#212529",bgSecondary:"#343a40",text:"#f8f9fa",textMuted:"#adb5bd",border:"#495057",primary:"#0d6efd",success:"#198754",error:"#dc3545",warning:"#ffc107",info:"#0dcaf0",muted:"#6c757d",nodePending:"#495057",nodeRunning:"#664d03",nodeSuccess:"#0f5132",nodeError:"#842029",nodeAborted:"#495057",nodeCached:"#084298",nodeSkipped:"#343a40",heatCold:"#0d6efd",heatCool:"#0dcaf0",heatNeutral:"#6c757d",heatWarm:"#ffc107",heatHot:"#fd7e14",heatCritical:"#dc3545"},o=n=>`
5
5
  --bg: ${n.bg};
6
6
  --bg-secondary: ${n.bgSecondary};
7
7
  --text: ${n.text};
@@ -1475,7 +1475,7 @@ body {
1475
1475
  return min + 'm ' + sec + 's';
1476
1476
  }
1477
1477
  })();
1478
- `}var ae=160,me=50,Fe=40,Er=30,H=20;function Mr(e,t="TB",r){let o=t==="TB"||t==="BT",i=t==="RL"||t==="BT",n=[],a=H,d=H,u=0,s=0;for(let h of e){let m=ze(h,a,d,o,r);n.push(m.node),o?(d+=m.height+Er,u=Math.max(u,m.width),s=d):(a+=m.width+Fe,s=Math.max(s,m.height),u=a)}let l=u+H,p=s+H;if(i)for(let h of n)lt(h,l,p,o);return{nodes:n,width:l,height:p}}function lt(e,t,r,o){if(o?e.y=r-e.y-e.height:e.x=t-e.x-e.width,e.children)for(let i of e.children)lt(i,t,r,o)}function ze(e,t,r,o,i){if(K(e)){let n=e.name??e.key??"step",a=i?.showKeys&&e.key&&e.name?`${n} [key: ${e.key}]`:n;return{node:{id:e.id,name:a,type:"step",state:e.state,x:t,y:r,width:ae,height:me,durationMs:e.durationMs},width:ae,height:me}}if(ee(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:ae,height:me,durationMs:e.durationMs},width:ae,height:me}}if(j(e)||F(e)){let n=j(e)?"parallel":"race",a=e.name??n,d=[],u=t+H,s=r+H+20,l=0;for(let y of e.children){let v=ze(y,u,s,!0,i);d.push(v.node),u+=v.width+Fe,l=Math.max(l,v.height)}let p=u-t-H,h=Math.max(p+H,ae+H*2),m=l+H*2+20;return{node:{id:e.id,name:a,type:n,state:e.state,x:t,y:r,width:h,height:m,durationMs:e.durationMs,children:d,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:h,height:m}}if(J(e)){let n=e.name??"decision",a=[],d=t+H,u=r+H+20,s=0;for(let h of e.branches)for(let m of h.children){let y=ze(m,d,u,!0,i);a.push(y.node),d+=y.width+Fe,s=Math.max(s,y.height)}let l=Math.max(d-t,ae+H*2),p=s+H*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:a,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:ae,height:me},width:ae,height:me}}function ut(e,t){return e.containerType?Tr(e,t):Nr(e,t)}function Nr(e,t){let o=t&&e.durationMs!==void 0?A(e.durationMs):"";return`
1478
+ `}var ae=160,me=50,Fe=40,Er=30,F=20;function Mr(e,t="TB",r){let o=t==="TB"||t==="BT",i=t==="RL"||t==="BT",n=[],a=F,d=F,u=0,s=0;for(let g of e){let h=ze(g,a,d,o,r);n.push(h.node),o?(d+=h.height+Er,u=Math.max(u,h.width),s=d):(a+=h.width+Fe,s=Math.max(s,h.height),u=a)}let l=u+F,f=s+F;if(i)for(let g of n)lt(g,l,f,o);return{nodes:n,width:l,height:f}}function lt(e,t,r,o){if(o?e.y=r-e.y-e.height:e.x=t-e.x-e.width,e.children)for(let i of e.children)lt(i,t,r,o)}function ze(e,t,r,o,i){if(K(e)){let n=e.name??e.key??"step",a=i?.showKeys&&e.key&&e.name?`${n} [key: ${e.key}]`:n;return{node:{id:e.id,name:a,type:"step",state:e.state,x:t,y:r,width:ae,height:me,durationMs:e.durationMs},width:ae,height:me}}if(ee(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:ae,height:me,durationMs:e.durationMs},width:ae,height:me}}if(j(e)||z(e)){let n=j(e)?"parallel":"race",a=e.name??n,d=[],u=t+F,s=r+F+20,l=0;for(let y of e.children){let v=ze(y,u,s,!0,i);d.push(v.node),u+=v.width+Fe,l=Math.max(l,v.height)}let f=u-t-F,g=Math.max(f+F,ae+F*2),h=l+F*2+20;return{node:{id:e.id,name:a,type:n,state:e.state,x:t,y:r,width:g,height:h,durationMs:e.durationMs,children:d,containerType:n,containerLabel:n==="parallel"?"PARALLEL":"RACE"},width:g,height:h}}if(J(e)){let n=e.name??"decision",a=[],d=t+F,u=r+F+20,s=0;for(let g of e.branches)for(let h of g.children){let y=ze(h,d,u,!0,i);a.push(y.node),d+=y.width+Fe,s=Math.max(s,y.height)}let l=Math.max(d-t,ae+F*2),f=s+F*2+20;return{node:{id:e.id,name:n,type:"decision",state:e.state,x:t,y:r,width:l,height:f,durationMs:e.durationMs,children:a,containerType:"decision",containerLabel:"DECISION"},width:l,height:f}}return{node:{id:e.id,name:e.name??"unknown",type:e.type,state:e.state,x:t,y:r,width:ae,height:me},width:ae,height:me}}function ut(e,t){return e.containerType?Tr(e,t):Nr(e,t)}function Nr(e,t){let o=t&&e.durationMs!==void 0?A(e.durationMs):"";return`
1479
1479
  <g class="wv-node wv-node--${e.state}" data-node-id="${ft(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)}">${Ke(Or(e.name,e.name.includes("[key:")?40:20))}</text>
@@ -1485,18 +1485,18 @@ body {
1485
1485
  `)??"";return`
1486
1486
  <g class="wv-container wv-container--${e.containerType}" data-node-id="${ft(e.id)}" transform="translate(${e.x}, ${e.y})">
1487
1487
  <rect width="${e.width}" height="${e.height}" rx="12" ry="12" />
1488
- <text class="wv-container-label" x="${H}" y="16">${e.containerLabel}</text>
1488
+ <text class="wv-container-label" x="${F}" y="16">${e.containerLabel}</text>
1489
1489
  <g transform="translate(${-e.x}, ${-e.y})">
1490
1490
  ${o}
1491
1491
  </g>
1492
1492
  </g>
1493
- `}function Ue(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=Ue(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let i=Ue(o.children,t);if(i)return i}}}function Dr(e,t){let r=[];function o(n,a){if(Math.abs(n.y-a.y)<n.height){let u=n.x+n.width,s=n.y+n.height/2,l=a.x,p=a.y+a.height/2;r.push(`
1494
- <path class="wv-edge" d="M ${u} ${s} L ${l-8} ${p}" />
1495
- <polygon class="wv-edge-arrow" points="${l-8},${p-4} ${l-8},${p+4} ${l},${p}" />
1496
- `)}else{let u=n.x+n.width/2,s=n.y+n.height,l=a.x+a.width/2,p=a.y;r.push(`
1497
- <path class="wv-edge" d="M ${u} ${s} L ${l} ${p-8}" />
1498
- <polygon class="wv-edge-arrow" points="${l-4},${p-8} ${l+4},${p-8} ${l},${p}" />
1499
- `)}}function i(n){for(let a=0;a<n.length-1;a++)o(n[a],n[a+1]);for(let a of n)if(a.children&&a.children.length>0)if(a.containerType==="decision"){let d=Ue(t.root.children,a.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(a,a.children[u]);for(let p=0;p<l-1;p++)o(a.children[u+p],a.children[u+p+1]);u+=l}}}else if(a.containerType==="parallel"||a.containerType==="race")for(let d of a.children)d.children&&d.children.length>0&&i([d]);else i(a.children)}return i(e),r.join(`
1493
+ `}function Ue(e,t){for(let r of e){if(r.id===t)return r;if("children"in r&&r.children){let o=Ue(r.children,t);if(o)return o}if("branches"in r&&r.branches)for(let o of r.branches){let i=Ue(o.children,t);if(i)return i}}}function Dr(e,t){let r=[];function o(n,a){if(Math.abs(n.y-a.y)<n.height){let u=n.x+n.width,s=n.y+n.height/2,l=a.x,f=a.y+a.height/2;r.push(`
1494
+ <path class="wv-edge" d="M ${u} ${s} L ${l-8} ${f}" />
1495
+ <polygon class="wv-edge-arrow" points="${l-8},${f-4} ${l-8},${f+4} ${l},${f}" />
1496
+ `)}else{let u=n.x+n.width/2,s=n.y+n.height,l=a.x+a.width/2,f=a.y;r.push(`
1497
+ <path class="wv-edge" d="M ${u} ${s} L ${l} ${f-8}" />
1498
+ <polygon class="wv-edge-arrow" points="${l-4},${f-8} ${l+4},${f-8} ${l},${f}" />
1499
+ `)}}function i(n){for(let a=0;a<n.length-1;a++)o(n[a],n[a+1]);for(let a of n)if(a.children&&a.children.length>0)if(a.containerType==="decision"){let d=Ue(t.root.children,a.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(a,a.children[u]);for(let f=0;f<l-1;f++)o(a.children[u+f],a.children[u+f+1]);u+=l}}}else if(a.containerType==="parallel"||a.containerType==="race")for(let d of a.children)d.children&&d.children.length>0&&i([d]);else i(a.children)}return i(e),r.join(`
1500
1500
  `)}function pt(e,t){let r=Mr(e.root.children,t.layout,t),o=Math.max(r.width,400),i=Math.max(r.height,300),n=r.nodes.map(l=>ut(l,t.showTimings)).join(`
1501
1501
  `),a=Dr(r.nodes,e),d=e.root.name??"Workflow",u=st(t.theme),s=ct({wsUrl:t.wsUrl,interactive:t.interactive,timeTravel:t.timeTravel,heatmap:t.heatmap});return`<!DOCTYPE html>
1502
1502
  <html lang="en">
@@ -1673,5 +1673,5 @@ body {
1673
1673
  </script>
1674
1674
  <script>${s}</script>
1675
1675
  </body>
1676
- </html>`}function Ke(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function ft(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Or(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function Cr(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 dt(e){let t=new WeakSet;return JSON.stringify(e,(o,i)=>{if(typeof i=="bigint")return i.toString();if(o==="error"&&i!==void 0&&i!==null)return String(i);if(typeof i=="object"&&i!==null){if(t.has(i))return"[Circular]";t.add(i)}return i}).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}var mt={interactive:!0,timeTravel:!0,heatmap:!0,animationDuration:200,theme:"auto",layout:"TB"};function Lr(){return{name:"html",supportsLive:!0,render(e,t){let r={...t,...mt,...t};return pt(e,r)}}}function _r(e,t={}){let r={showTimings:!0,showKeys:!1,colors:{pending:"#6c757d",running:"#ffc107",success:"#198754",error:"#dc3545",aborted:"#6c757d",cached:"#0dcaf0",skipped:"#adb5bd"},...mt,...t};return pt(e,r)}function je(e,t={}){let{condition:r,value:o,name:i,workflowId:n=crypto.randomUUID(),emit:a}=t,d=Date.now(),u,s=[];function l(h,m,y){s.push({label:h,condition:y,taken:m}),m&&(u=h),a?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:h,condition:y,taken:m,ts:Date.now()})}function p(){let h=Date.now()-d;a?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:h})}return a?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:i,ts:d}),{takeBranch:l,end:p,getBranchTaken:()=>u,getBranches:()=>[...s]}}function Wr(e,t,r={}){let o=je(e,{...r,condition:r.condition??String(t),value:r.value??t}),i=!1;return{...o,condition:t,then:()=>{i||(i=!0,o.takeBranch("if",!0),o.takeBranch("else",!1))},else:()=>{i||(i=!0,o.takeBranch("if",!1),o.takeBranch("else",!0))}}}function Br(e,t,r={}){let o=je(e,{...r,condition:r.condition??`switch(${String(t)})`,value:t});return{...o,value:t,case:(i,n)=>{o.takeBranch(`case '${i}'`,n,`value === '${i}'`)},default:i=>{o.takeBranch("default",i)}}}function Ar(e={}){let{maxSnapshots:t=1e3,autoRecord:r=!0,builderOptions:o={}}=e,i=he({detectParallel:!1,...o,enableSnapshots:r,maxSnapshots:t}),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},a=new Set,d=null;function u(){let M=x();for(let O of a)O(M)}function s(){n.snapshots=i.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(M){i.handleEvent(M),n.isRecording&&(s(),u())}function p(M){let O=i.getSnapshots();if(!(M<0||M>=O.length))return n.currentIndex=M,n.snapshots=O,u(),O[M].ir}function h(){return p(n.currentIndex+1)}function m(){return p(n.currentIndex-1)}function y(M=1){let O=i.getSnapshots();if(O.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=O),n.playbackSpeed=M,n.isPlaying=!0,u();let B=()=>{if(!n.isPlaying)return;let U=i.getSnapshots();if(n.currentIndex<U.length-1){let _=U[n.currentIndex],oe=(U[n.currentIndex+1].timestamp-_.timestamp)/n.playbackSpeed;d=setTimeout(()=>{h(),B()},Math.max(16,oe))}else v()};B()}function v(){n.isPlaying=!1,d&&(clearTimeout(d),d=null),u()}function $(){let M=i.getSnapshots();return n.currentIndex>=0&&n.currentIndex<M.length?M[n.currentIndex].ir:i.getIR()}function N(M){return i.getIRAt(M)}function E(){return i.getSnapshots()}function I(M){return i.getSnapshotAt(M)}function x(){return{snapshots:i.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function S(M){return a.add(M),()=>a.delete(M)}function w(){n.isRecording=!0,i.setSnapshotsEnabled(!0),s(),u()}function g(){n.isRecording=!1,i.setSnapshotsEnabled(!1),u()}function k(){v(),i.reset(),i.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function T(){return i}return{handleEvent:l,seek:p,stepForward:h,stepBackward:m,play:y,pause:v,getCurrentIR:$,getIRAt:N,getSnapshots:E,getSnapshotAt:I,getState:x,onStateChange:S,startRecording:w,stopRecording:g,reset:k,getBuilder:T}}import Pr from"pako";var Hr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Fr(e){let t;if(Hr)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 Ce(e){let r=new TextEncoder().encode(e),o=Pr.deflate(r);return Fr(o)}var ht="https://kroki.io";function zr(e,t,r,o={}){let i=o.baseUrl??ht,n=Ce(r);return`${i}/${e}/${t}/${n}`}function ce(e,t="svg",r={}){let o=ie(),i={showTimings:!0,showKeys:!1,terminalWidth:80,colors:V},n=o.render(e,i);return zr("mermaid",t,n,r)}function Ur(e,t={}){return ce(e,"svg",t)}function Kr(e,t={}){return ce(e,"png",t)}function jr(e={}){let t=e.baseUrl??ht;return{toUrl(r,o){return ce(r,o,{baseUrl:t})},toSvgUrl(r){return ce(r,"svg",{baseUrl:t})},toPngUrl(r){return ce(r,"png",{baseUrl:t})},toPdfUrl(r){return ce(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var gt="https://mermaid.ink";function wt(e){return`pako:${Ce(e)}`}function Vr(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 Gr(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 bt(e,t,r={}){let o=Vr(r),i=o.baseUrl??gt,n=wt(t),a=Gr(e,o);return`${i}/${e}/${n}${a}`}function G(e,t="svg",r={}){let o=ie(),i={showTimings:!0,showKeys:!1,terminalWidth:80,colors:V},n=o.render(e,i);return bt(t,n,r)}function Yr(e,t={}){return G(e,"svg",t)}function Jr(e,t={}){return G(e,"img",{...t,imageType:"png"})}function Xr(e,t={}){return G(e,"img",{...t,imageType:"jpeg"})}function qr(e,t={}){return G(e,"img",{...t,imageType:"webp"})}function Zr(e,t={}){return G(e,"pdf",t)}function Qr(e={}){let t=e.baseUrl??gt;return{toUrl(r,o){return G(r,o,e)},toSvgUrl(r){return G(r,"svg",e)},toPngUrl(r){return G(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return G(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return G(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return G(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}var ro=()=>{throw new Error("createLiveVisualizer is not available in browser. It requires Node.js process.stdout.")};function Ve(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:i=!1,colors:n}=e,a=he({detectParallel:r}),d=new Set,u,s=le(),l=ie(),p=Oe(),h=fe(),m={showTimings:o,showKeys:i,terminalWidth:80,colors:{...V,...n}};function y(){if(d.size>0){let g=a.getIR();for(let k of d)k(g)}}function v(g){if(g.type==="scope_start"||g.type==="scope_end"){$(g);return}a.handleEvent(g),"workflowName"in g&&typeof g.workflowName=="string"&&(u=g.workflowName),y()}function $(g){a.handleScopeEvent(g),y()}function N(g){a.handleDecisionEvent(g),y()}function E(){let g=a.getIR(),k=t??u??g.root.name;return k&&(g.root.name=k),g}function I(){let g=E();return s.render(g,m)}function x(g){let k=E();switch(g){case"ascii":return s.render(k,m);case"mermaid":return l.render(k,m);case"json":{let T=k.hooks?{...k,hooks:{...k.hooks,onAfterStep:k.hooks.onAfterStep instanceof Map?Object.fromEntries(k.hooks.onAfterStep):k.hooks.onAfterStep??{}}}:k;return JSON.stringify(T,(O,B)=>typeof B=="bigint"?B.toString():B,2)}case"logger":return p.render(k,m);case"flowchart":return h.render(k,m);default:throw new Error(`Unknown format: ${g}`)}}function S(){a.reset(),y()}function w(g){return d.add(g),()=>d.delete(g)}return{handleEvent:v,handleScopeEvent:$,handleDecisionEvent:N,getIR:E,render:I,renderAs:x,reset:S,onUpdate:w}}function no(...e){return(t,r)=>{for(let o of e)o(t,r)}}function oo(e,t={}){let r=Ve(t);for(let o of e)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()}function io(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=Ve(e);for(let o of t)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()},visualizeAs:r=>{let o=Ve(e);for(let i of t)i.type.startsWith("decision_")?o.handleDecisionEvent(i):o.handleEvent(i);return o.renderAs(r)}}}export{le as asciiRenderer,bt as buildMermaidInkUrl,no as combineEventHandlers,io as createEventCollector,he as createIRBuilder,ro as createLiveVisualizer,Qr as createMermaidInkGenerator,$t as createParallelDetector,jt as createPerformanceAnalyzer,Ar as createTimeTravelController,jr as createUrlGenerator,Ve as createVisualizer,V as defaultColorScheme,ve as detectParallelGroups,wt as encodeForMermaidInk,fe as flowchartRenderer,be as getHeatLevel,an as hasChildren,Lr as htmlRenderer,J as isDecisionNode,j as isParallelNode,F as isRaceNode,Ge as isSequenceNode,K as isStepNode,ee as isStreamNode,Oe as loggerRenderer,ie as mermaidRenderer,_r as renderToHTML,Kr as toKrokiPngUrl,Ur as toKrokiSvgUrl,ce as toKrokiUrl,Xr as toMermaidInkJpegUrl,Zr as toMermaidInkPdfUrl,Jr as toMermaidInkPngUrl,Yr as toMermaidInkSvgUrl,G as toMermaidInkUrl,qr as toMermaidInkWebpUrl,je as trackDecision,Wr as trackIf,Br as trackSwitch,oo as visualizeEvents};
1676
+ </html>`}function Ke(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function ft(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Or(e,t){return e.length<=t?e:e.slice(0,t-1)+"\u2026"}function Cr(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 dt(e){let t=new WeakSet;return JSON.stringify(e,(o,i)=>{if(typeof i=="bigint")return i.toString();if(o==="error"&&i!==void 0&&i!==null)return String(i);if(typeof i=="object"&&i!==null){if(t.has(i))return"[Circular]";t.add(i)}return i}).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}var mt={interactive:!0,timeTravel:!0,heatmap:!0,animationDuration:200,theme:"auto",layout:"TB"};function Lr(){return{name:"html",supportsLive:!0,render(e,t){let r={...t,...mt,...t};return pt(e,r)}}}function _r(e,t={}){let r={showTimings:!0,showKeys:!1,colors:{pending:"#6c757d",running:"#ffc107",success:"#198754",error:"#dc3545",aborted:"#6c757d",cached:"#0dcaf0",skipped:"#adb5bd"},...mt,...t};return pt(e,r)}function je(e,t={}){let{condition:r,value:o,name:i,workflowId:n=crypto.randomUUID(),emit:a}=t,d=Date.now(),u,s=[];function l(g,h,y){s.push({label:g,condition:y,taken:h}),h&&(u=g),a?.({type:"decision_branch",workflowId:n,decisionId:e,branchLabel:g,condition:y,taken:h,ts:Date.now()})}function f(){let g=Date.now()-d;a?.({type:"decision_end",workflowId:n,decisionId:e,branchTaken:u,ts:Date.now(),durationMs:g})}return a?.({type:"decision_start",workflowId:n,decisionId:e,condition:r,decisionValue:o,name:i,ts:d}),{takeBranch:l,end:f,getBranchTaken:()=>u,getBranches:()=>[...s]}}function Wr(e,t,r={}){let o=je(e,{...r,condition:r.condition??String(t),value:r.value??t}),i=!1;return{...o,condition:t,then:()=>{i||(i=!0,o.takeBranch("if",!0),o.takeBranch("else",!1))},else:()=>{i||(i=!0,o.takeBranch("if",!1),o.takeBranch("else",!0))}}}function Br(e,t,r={}){let o=je(e,{...r,condition:r.condition??`switch(${String(t)})`,value:t});return{...o,value:t,case:(i,n)=>{o.takeBranch(`case '${i}'`,n,`value === '${i}'`)},default:i=>{o.takeBranch("default",i)}}}function Ar(e={}){let{maxSnapshots:t=1e3,autoRecord:r=!0,builderOptions:o={}}=e,i=he({detectParallel:!1,...o,enableSnapshots:r,maxSnapshots:t}),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},a=new Set,d=null;function u(){let M=x();for(let O of a)O(M)}function s(){n.snapshots=i.getSnapshots(),n.isRecording&&n.snapshots.length>0&&(n.currentIndex=n.snapshots.length-1)}function l(M){i.handleEvent(M),n.isRecording&&(s(),u())}function f(M){let O=i.getSnapshots();if(!(M<0||M>=O.length))return n.currentIndex=M,n.snapshots=O,u(),O[M].ir}function g(){return f(n.currentIndex+1)}function h(){return f(n.currentIndex-1)}function y(M=1){let O=i.getSnapshots();if(O.length===0)return;n.currentIndex===-1&&(n.currentIndex=0,n.snapshots=O),n.playbackSpeed=M,n.isPlaying=!0,u();let B=()=>{if(!n.isPlaying)return;let H=i.getSnapshots();if(n.currentIndex<H.length-1){let _=H[n.currentIndex],oe=(H[n.currentIndex+1].timestamp-_.timestamp)/n.playbackSpeed;d=setTimeout(()=>{g(),B()},Math.max(16,oe))}else v()};B()}function v(){n.isPlaying=!1,d&&(clearTimeout(d),d=null),u()}function $(){let M=i.getSnapshots();return n.currentIndex>=0&&n.currentIndex<M.length?M[n.currentIndex].ir:i.getIR()}function N(M){return i.getIRAt(M)}function E(){return i.getSnapshots()}function I(M){return i.getSnapshotAt(M)}function x(){return{snapshots:i.getSnapshots(),currentIndex:n.currentIndex,isPlaying:n.isPlaying,playbackSpeed:n.playbackSpeed,isRecording:n.isRecording}}function S(M){return a.add(M),()=>a.delete(M)}function b(){n.isRecording=!0,i.setSnapshotsEnabled(!0),s(),u()}function w(){n.isRecording=!1,i.setSnapshotsEnabled(!1),u()}function k(){v(),i.reset(),i.setSnapshotsEnabled(r),n={snapshots:[],currentIndex:-1,isPlaying:!1,playbackSpeed:1,isRecording:r},u()}function T(){return i}return{handleEvent:l,seek:f,stepForward:g,stepBackward:h,play:y,pause:v,getCurrentIR:$,getIRAt:N,getSnapshots:E,getSnapshotAt:I,getState:x,onStateChange:S,startRecording:b,stopRecording:w,reset:k,getBuilder:T}}import Pr from"pako";var Hr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Fr(e){let t;if(Hr)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 Ce(e){let r=new TextEncoder().encode(e),o=Pr.deflate(r);return Fr(o)}var ht="https://kroki.io";function zr(e,t,r,o={}){let i=o.baseUrl??ht,n=Ce(r);return`${i}/${e}/${t}/${n}`}function ce(e,t="svg",r={}){let o=ie(),i={showTimings:!0,showKeys:!1,terminalWidth:80,colors:V},n=o.render(e,i);return zr("mermaid",t,n,r)}function Ur(e,t={}){return ce(e,"svg",t)}function Kr(e,t={}){return ce(e,"png",t)}function jr(e={}){let t=e.baseUrl??ht;return{toUrl(r,o){return ce(r,o,{baseUrl:t})},toSvgUrl(r){return ce(r,"svg",{baseUrl:t})},toPngUrl(r){return ce(r,"png",{baseUrl:t})},toPdfUrl(r){return ce(r,"pdf",{baseUrl:t})},getBaseUrl(){return t}}}var gt="https://mermaid.ink";function wt(e){return`pako:${Ce(e)}`}function Vr(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 Gr(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 bt(e,t,r={}){let o=Vr(r),i=o.baseUrl??gt,n=wt(t),a=Gr(e,o);return`${i}/${e}/${n}${a}`}function G(e,t="svg",r={}){let o=ie(),i={showTimings:!0,showKeys:!1,terminalWidth:80,colors:V},n=o.render(e,i);return bt(t,n,r)}function Yr(e,t={}){return G(e,"svg",t)}function Jr(e,t={}){return G(e,"img",{...t,imageType:"png"})}function Xr(e,t={}){return G(e,"img",{...t,imageType:"jpeg"})}function qr(e,t={}){return G(e,"img",{...t,imageType:"webp"})}function Zr(e,t={}){return G(e,"pdf",t)}function Qr(e={}){let t=e.baseUrl??gt;return{toUrl(r,o){return G(r,o,e)},toSvgUrl(r){return G(r,"svg",e)},toPngUrl(r){return G(r,"img",{...e,imageType:"png"})},toJpegUrl(r){return G(r,"img",{...e,imageType:"jpeg"})},toWebpUrl(r){return G(r,"img",{...e,imageType:"webp"})},toPdfUrl(r){return G(r,"pdf",e)},getBaseUrl(){return t},getOptions(){return{...e}}}}var ro=()=>{throw new Error("createLiveVisualizer is not available in browser. It requires Node.js process.stdout.")};function Ve(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:i=!1,colors:n}=e,a=he({detectParallel:r}),d=new Set,u,s=le(),l=ie(),f=Oe(),g=fe(),h={showTimings:o,showKeys:i,terminalWidth:80,colors:{...V,...n}};function y(){if(d.size>0){let w=a.getIR();for(let k of d)k(w)}}function v(w){if(w.type==="scope_start"||w.type==="scope_end"){$(w);return}a.handleEvent(w),"workflowName"in w&&typeof w.workflowName=="string"&&(u=w.workflowName),y()}function $(w){a.handleScopeEvent(w),y()}function N(w){a.handleDecisionEvent(w),y()}function E(){let w=a.getIR(),k=t??u??w.root.name;return k&&(w.root.name=k),w}function I(){let w=E();return s.render(w,h)}function x(w){let k=E();switch(w){case"ascii":return s.render(k,h);case"mermaid":return l.render(k,h);case"json":{let T=k.hooks?{...k,hooks:{...k.hooks,onAfterStep:k.hooks.onAfterStep instanceof Map?Object.fromEntries(k.hooks.onAfterStep):k.hooks.onAfterStep??{}}}:k;return JSON.stringify(T,(O,B)=>typeof B=="bigint"?B.toString():B,2)}case"logger":return f.render(k,h);case"flowchart":return g.render(k,h);default:throw new Error(`Unknown format: ${w}`)}}function S(){a.reset(),y()}function b(w){return d.add(w),()=>d.delete(w)}return{handleEvent:v,handleScopeEvent:$,handleDecisionEvent:N,getIR:E,render:I,renderAs:x,reset:S,onUpdate:b}}function no(...e){return(t,r)=>{for(let o of e)o(t,r)}}function oo(e,t={}){let r=Ve(t);for(let o of e)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()}function io(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=Ve(e);for(let o of t)o.type.startsWith("decision_")?r.handleDecisionEvent(o):r.handleEvent(o);return r.render()},visualizeAs:r=>{let o=Ve(e);for(let i of t)i.type.startsWith("decision_")?o.handleDecisionEvent(i):o.handleEvent(i);return o.renderAs(r)}}}export{le as asciiRenderer,bt as buildMermaidInkUrl,no as combineEventHandlers,io as createEventCollector,he as createIRBuilder,ro as createLiveVisualizer,Qr as createMermaidInkGenerator,$t as createParallelDetector,jt as createPerformanceAnalyzer,Ar as createTimeTravelController,jr as createUrlGenerator,Ve as createVisualizer,V as defaultColorScheme,ve as detectParallelGroups,wt as encodeForMermaidInk,fe as flowchartRenderer,be as getHeatLevel,an as hasChildren,Lr as htmlRenderer,J as isDecisionNode,j as isParallelNode,z as isRaceNode,Ge as isSequenceNode,K as isStepNode,ee as isStreamNode,Oe as loggerRenderer,ie as mermaidRenderer,_r as renderToHTML,Kr as toKrokiPngUrl,Ur as toKrokiSvgUrl,ce as toKrokiUrl,Xr as toMermaidInkJpegUrl,Zr as toMermaidInkPdfUrl,Jr as toMermaidInkPngUrl,Yr as toMermaidInkSvgUrl,G as toMermaidInkUrl,qr as toMermaidInkWebpUrl,je as trackDecision,Wr as trackIf,Br as trackSwitch,oo as visualizeEvents};
1677
1677
  //# sourceMappingURL=index.browser.js.map