awaitly-visualizer 7.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -0
- package/dist/devtools.cjs +6 -6
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +5 -5
- package/dist/devtools.js.map +1 -1
- package/dist/index.browser.cjs +13 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +13 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +1005 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -1
- package/dist/index.d.ts +135 -1
- package/dist/index.js +1005 -33
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# awaitly-visualizer
|
|
2
|
+
|
|
3
|
+
Visualization and rendering for [awaitly](https://github.com/jagreehal/awaitly) workflows: Mermaid diagrams, ASCII art, HTML, export URLs (Kroki / Mermaid.ink), and notifiers (Slack, Discord, webhook).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install awaitly-visualizer awaitly
|
|
9
|
+
# or
|
|
10
|
+
pnpm add awaitly-visualizer awaitly
|
|
11
|
+
# or
|
|
12
|
+
yarn add awaitly-visualizer awaitly
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createWorkflow } from "awaitly/workflow";
|
|
19
|
+
import { createVisualizer } from "awaitly-visualizer";
|
|
20
|
+
|
|
21
|
+
const viz = createVisualizer({ workflowName: "checkout" });
|
|
22
|
+
|
|
23
|
+
const workflow = createWorkflow(
|
|
24
|
+
"checkout",
|
|
25
|
+
{ validateCart, processPayment },
|
|
26
|
+
{ onEvent: viz.handleEvent }
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
await workflow(async (step, { validateCart, processPayment }) => {
|
|
30
|
+
await step("Validate cart", () => validateCart(cart));
|
|
31
|
+
await step("Process payment", () => processPayment(payment));
|
|
32
|
+
return result;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(viz.render()); // ASCII (default)
|
|
36
|
+
console.log(viz.renderAs("mermaid")); // Mermaid flowchart
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Output Formats
|
|
40
|
+
|
|
41
|
+
Use `renderAs(format)` for:
|
|
42
|
+
|
|
43
|
+
| Format | Description |
|
|
44
|
+
| ---------- | ------------------------------ |
|
|
45
|
+
| `ascii` | Terminal-friendly box diagram (default) |
|
|
46
|
+
| `mermaid` | Mermaid flowchart source |
|
|
47
|
+
| `json` | Workflow IR as JSON |
|
|
48
|
+
| `logger` | Step-by-step log style |
|
|
49
|
+
| `flowchart`| Alternative flowchart text |
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
viz.renderAs("mermaid"); // "flowchart LR\n ..."
|
|
53
|
+
viz.renderAs("json"); // JSON string of workflow IR
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Export URLs (SVG, PNG, PDF)
|
|
57
|
+
|
|
58
|
+
Generate image/PDF URLs from the current diagram using Kroki or Mermaid.ink. Pass a provider when calling, or set a default in options:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const viz = createVisualizer({
|
|
62
|
+
workflowName: "checkout",
|
|
63
|
+
export: {
|
|
64
|
+
default: { provider: "kroki" }, // or "mermaid-ink"
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// After running the workflow:
|
|
69
|
+
const svgUrl = viz.toSvgUrl();
|
|
70
|
+
const pngUrl = viz.toPngUrl();
|
|
71
|
+
const pdfUrl = viz.toPdfUrl(); // mermaid-ink only; Kroki does not support PDF for mermaid
|
|
72
|
+
|
|
73
|
+
// Or pass provider per call:
|
|
74
|
+
viz.toSvgUrl({ provider: "mermaid-ink" });
|
|
75
|
+
viz.toUrl("png", { provider: "kroki" });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- **Kroki**: SVG and PNG for Mermaid. Use subpath `awaitly-visualizer/kroki-fetch` for Node-only fetching (e.g. server-side image generation).
|
|
79
|
+
- **Mermaid.ink**: SVG, PNG, JPEG, WebP, PDF. Browser and Node safe.
|
|
80
|
+
|
|
81
|
+
## HTML Renderer
|
|
82
|
+
|
|
83
|
+
Render workflow state to HTML (e.g. for dashboards or reports):
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { htmlRenderer, renderToHTML } from "awaitly-visualizer";
|
|
87
|
+
|
|
88
|
+
const html = htmlRenderer();
|
|
89
|
+
const markup = html.render(viz.getIR(), renderOptions);
|
|
90
|
+
|
|
91
|
+
// Or use the helper with default options:
|
|
92
|
+
const doc = renderToHTML(viz.getIR(), { title: "Checkout workflow" });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Event Collection and Post-Hoc Visualization
|
|
96
|
+
|
|
97
|
+
Collect events and visualize later, or combine with other handlers:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { createEventCollector, visualizeEvents, combineEventHandlers } from "awaitly-visualizer";
|
|
101
|
+
|
|
102
|
+
// Option 1: Event collector
|
|
103
|
+
const collector = createEventCollector({ workflowName: "checkout" });
|
|
104
|
+
const workflow = createWorkflow("checkout", deps, {
|
|
105
|
+
onEvent: collector.handleEvent,
|
|
106
|
+
});
|
|
107
|
+
await workflow(async (step) => { /* ... */ });
|
|
108
|
+
console.log(collector.visualize());
|
|
109
|
+
console.log(collector.visualizeAs("mermaid"));
|
|
110
|
+
|
|
111
|
+
// Option 2: Visualize a list of events
|
|
112
|
+
const events = []; // push from onEvent
|
|
113
|
+
const workflow2 = createWorkflow("checkout", deps, { onEvent: (e) => events.push(e) });
|
|
114
|
+
await workflow2(async (step) => { /* ... */ });
|
|
115
|
+
console.log(visualizeEvents(events, { workflowName: "checkout" }));
|
|
116
|
+
|
|
117
|
+
// Option 3: Combine visualization with logging or metrics
|
|
118
|
+
const viz = createVisualizer({ workflowName: "checkout" });
|
|
119
|
+
const workflow3 = createWorkflow("checkout", deps, {
|
|
120
|
+
onEvent: combineEventHandlers(viz.handleEvent, (e) => console.log(e.type)),
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Decision Tracking (Conditional Branches)
|
|
125
|
+
|
|
126
|
+
Track `trackIf` / `trackSwitch` decision events so branches appear in the visualization. Emit decision events into the same visualizer or collector:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { createVisualizer, trackIf, trackSwitch } from "awaitly-visualizer";
|
|
130
|
+
|
|
131
|
+
const viz = createVisualizer({ workflowName: "checkout" });
|
|
132
|
+
|
|
133
|
+
await workflow(async (step) => {
|
|
134
|
+
const decision = trackIf("discount-check", hasCoupon, {
|
|
135
|
+
emit: viz.handleDecisionEvent,
|
|
136
|
+
});
|
|
137
|
+
if (decision.then) {
|
|
138
|
+
await step("Apply discount", () => applyDiscount(percent));
|
|
139
|
+
}
|
|
140
|
+
// ...
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Time-Travel and Performance Analysis
|
|
145
|
+
|
|
146
|
+
- **Time-travel**: `createTimeTravelController` for replay and stepping through recorded workflow events.
|
|
147
|
+
- **Performance**: `createPerformanceAnalyzer` and `getHeatLevel` for step timing and hot-spot visualization (e.g. heatmap in HTML/ASCII).
|
|
148
|
+
|
|
149
|
+
## Live Terminal Visualization (Node only)
|
|
150
|
+
|
|
151
|
+
In Node, use a live-updating terminal view:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { createLiveVisualizer } from "awaitly-visualizer";
|
|
155
|
+
|
|
156
|
+
const live = createLiveVisualizer(); // uses process.stdout
|
|
157
|
+
const workflow = createWorkflow("checkout", deps, {
|
|
158
|
+
onEvent: live.handleEvent,
|
|
159
|
+
});
|
|
160
|
+
await workflow(async (step) => { /* ... */ });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Not available in browser builds; use the main entry in browsers.
|
|
164
|
+
|
|
165
|
+
## Notifiers (Slack, Discord, Webhook)
|
|
166
|
+
|
|
167
|
+
Send workflow status or diagrams to Slack, Discord, or a generic webhook. Use subpath imports so you don’t pull in unused dependencies:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { createSlackNotifier } from "awaitly-visualizer/notifiers/slack";
|
|
171
|
+
import { createDiscordNotifier } from "awaitly-visualizer/notifiers/discord";
|
|
172
|
+
import { createWebhookNotifier } from "awaitly-visualizer/notifiers/webhook";
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Each notifier can be wired to workflow events (e.g. completion, failure) and can include diagram URLs (Kroki/Mermaid.ink) in messages. See the notifier types and options in the package exports.
|
|
176
|
+
|
|
177
|
+
## Subpath Exports
|
|
178
|
+
|
|
179
|
+
| Subpath | Purpose |
|
|
180
|
+
| ------------------------------ | --------------------------------- |
|
|
181
|
+
| `awaitly-visualizer` | Main API (visualizer, renderers, etc.) |
|
|
182
|
+
| `awaitly-visualizer/kroki-fetch` | Node-only Kroki fetch (e.g. server-side image fetch) |
|
|
183
|
+
| `awaitly-visualizer/notifiers/slack` | Slack notifier (optional `@slack/web-api`) |
|
|
184
|
+
| `awaitly-visualizer/notifiers/discord` | Discord notifier |
|
|
185
|
+
| `awaitly-visualizer/notifiers/webhook` | Generic webhook notifier |
|
|
186
|
+
| `awaitly-visualizer/devtools` | DevTools integration (browser) |
|
|
187
|
+
|
|
188
|
+
In bundlers that respect `exports`, use the main entry for Node and the **browser** conditional for browser builds (e.g. `awaitly-visualizer` → browser build excludes `createLiveVisualizer` and uses a stub; export URL helpers are browser-safe).
|
|
189
|
+
|
|
190
|
+
## Requirements
|
|
191
|
+
|
|
192
|
+
- Node.js >= 22
|
|
193
|
+
- **Peer dependency**: `awaitly` (workspace ^ or same major)
|
|
194
|
+
|
|
195
|
+
Optional:
|
|
196
|
+
|
|
197
|
+
- `@slack/web-api` for the Slack notifier (optional dependency).
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
MIT
|
package/dist/devtools.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var gt=Object.create;var pe=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)pe(e,r,{get:t[r],enumerable:!0})},He=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of kt(t))!bt.call(e,s)&&s!==r&&pe(e,s,{get:()=>t[s],enumerable:!(o=ht(t,s))||o.enumerable});return e};var St=(e,t,r)=>(r=e!=null?gt(wt(e)):{},He(t||!e||!e.__esModule?pe(r,"default",{value:e,enumerable:!0}):r,e)),xt=e=>He(pe({},"__esModule",{value:!0}),e);var Cr={};yt(Cr,{createConsoleLogger:()=>lt,createDevtools:()=>Pe,quickVisualize:()=>ut,renderDiff:()=>ct});module.exports=xt(Cr);function H(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let t=Math.floor(e/6e4),r=Math.round(e%6e4/1e3);return r>=60&&(t+=1,r=0),r===0?`${t}m`:`${t}m ${r}s`}function fe(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function Ae(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,s=[],n=[];for(let u=0;u<e.length;u++){let d=e[u];d.type==="step"&&d.startTs!==void 0?s.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:u}):n.push({node:d,originalIndex:u})}if(s.length<=1)return e;s.sort((u,d)=>u.startTs-d.startTs);let i=[],c=[s[0]];for(let u=1;u<s.length;u++){let d=s[u],g=Math.min(...c.map(E=>E.startTs)),m=Math.max(...c.map(E=>E.endTs)),f=d.startTs<=g+o,k=d.startTs<m;if(!f&&!k){i.push(c),c=[d];continue}let b=k?Math.min(d.endTs,m)-d.startTs:0;f||b>=r?c.push(d):(i.push(c),c=[d])}i.push(c);let l=[];for(let u of i){let d=Math.min(...u.map(g=>g.originalIndex));if(u.length===1)l.push({node:u[0].node,position:d});else{let g=u.map(b=>b.node),m=Math.min(...u.map(b=>b.startTs)),f=Math.max(...u.map(b=>b.endTs)),k={type:"parallel",id:`detected_parallel_${m}`,name:`${g.length} parallel steps`,state:$t(g),mode:"all",children:g,startTs:m,endTs:f,durationMs:f-m};l.push({node:k,position:d})}}for(let{node:u,originalIndex:d}of n)l.push({node:u,position:d});return l.sort((u,d)=>u.position-d.position),l.map(u=>u.node)}function $t(e){return e.some(n=>n.state==="error")?"error":e.some(n=>n.state==="running")?"running":e.some(n=>n.state==="pending")?"pending":(e.every(n=>n.state==="success"||n.state==="cached"),"success")}function Fe(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:s=1e3}=e,n=o,i=fe(),c,l,u,d="pending",g,m,f=new Map,k=[],b=[],E=new Map,D=[],S=Date.now(),y=S,C={onAfterStep:new Map},I,R=[],v=0;function O(a){return a.stepId??a.stepKey??a.name??fe()}function L(a){if(k.length>0){k[k.length-1].children.push(a),y=Date.now();return}if(b.length>0){let h=b[b.length-1];for(let p of h.branches.values())if(p.taken){p.children.push(a),y=Date.now();return}h.pendingChildren.push(a),y=Date.now();return}D.push(a),y=Date.now()}function $(a){if(!n)return;let h=De(),p=new Map;for(let[T,B]of f)p.set(T,{id:B.id,name:B.name,key:B.key,startTs:B.startTs,retryCount:B.retryCount,timedOut:B.timedOut,timeoutMs:B.timeoutMs});let U={id:`snapshot_${v}`,eventIndex:v,event:structuredClone(a),ir:structuredClone(h),timestamp:Date.now(),activeSteps:p};R.push(U),R.length>s&&R.shift(),v++}function P(a){switch(a.type){case"workflow_start":{D=[],u=void 0,m=void 0,g=void 0,f.clear(),k.length=0,b.length=0,E.clear(),c=a.workflowId,l=a.ts,d="running",S=Date.now(),y=S,I!==void 0&&I!==a.workflowId&&(C.shouldRun=void 0,C.onBeforeStart=void 0),I=a.workflowId,C.onAfterStep=new Map;break}case"workflow_success":d="success",u=a.ts,m=a.durationMs,y=Date.now();break;case"workflow_error":d="error",u=a.ts,g=a.error,m=a.durationMs,y=Date.now();break;case"workflow_cancelled":d="aborted",u=a.ts,m=a.durationMs,y=Date.now();break;case"step_start":{let h=O(a);f.set(h,{id:h,name:a.name,key:a.stepKey,startTs:a.ts,retryCount:0,timedOut:!1}),y=Date.now();break}case"step_success":{let h=O(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_error":{let h=O(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,error:a.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_aborted":{let h=O(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_cache_hit":{let p={type:"step",id:O(a),name:a.name,key:a.stepKey,state:"cached",startTs:a.ts,endTs:a.ts,durationMs:0};L(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let h=O(a),p=f.get(h);p&&(p.timedOut=!0,p.timeoutMs=a.timeoutMs),y=Date.now();break}case"step_retry":{let h=O(a),p=f.get(h);p&&(p.retryCount=(a.attempt??1)-1),y=Date.now();break}case"step_retries_exhausted":y=Date.now();break;case"step_skipped":{let p={type:"step",id:O(a),name:a.name,key:a.stepKey,state:"skipped",startTs:a.ts,endTs:a.ts,durationMs:0};L(p);break}case"hook_should_run":{let h={type:"shouldRun",state:"success",ts:a.ts,durationMs:a.durationMs,context:{result:a.result,skipped:a.skipped}};C.shouldRun=h,I=a.workflowId,y=Date.now();break}case"hook_should_run_error":{let h={type:"shouldRun",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error};C.shouldRun=h,I=a.workflowId,y=Date.now();break}case"hook_before_start":{let h={type:"onBeforeStart",state:"success",ts:a.ts,durationMs:a.durationMs,context:{result:a.result,skipped:a.skipped}};C.onBeforeStart=h,I=a.workflowId,y=Date.now();break}case"hook_before_start_error":{let h={type:"onBeforeStart",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error};C.onBeforeStart=h,I=a.workflowId,y=Date.now();break}case"hook_after_step":{let h={type:"onAfterStep",state:"success",ts:a.ts,durationMs:a.durationMs,context:{stepKey:a.stepKey}};C.onAfterStep.set(a.stepKey,h),y=Date.now();break}case"hook_after_step_error":{let h={type:"onAfterStep",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error,context:{stepKey:a.stepKey}};C.onAfterStep.set(a.stepKey,h),y=Date.now();break}case"stream_created":{let h=`${a.workflowId}:${a.namespace}`;E.set(h,{id:fe(),namespace:a.namespace,startTs:a.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),y=Date.now();break}case"stream_write":{let h=`${a.workflowId}:${a.namespace}`,p=E.get(h);p&&(p.writeCount++,p.finalPosition=Math.max(p.finalPosition,a.position)),y=Date.now();break}case"stream_read":{let h=`${a.workflowId}:${a.namespace}`,p=E.get(h);p&&p.readCount++,y=Date.now();break}case"stream_close":{let h=`${a.workflowId}:${a.namespace}`,p=E.get(h);if(p){p.streamState="closed",p.finalPosition=a.finalPosition;let U={type:"stream",id:p.id,namespace:p.namespace,state:"success",startTs:p.startTs,endTs:a.ts,durationMs:a.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:a.finalPosition,streamState:"closed",backpressureOccurred:p.backpressureOccurred};L(U),E.delete(h)}y=Date.now();break}case"stream_error":{let h=`${a.workflowId}:${a.namespace}`,p=E.get(h);if(p){p.streamState="error";let U={type:"stream",id:p.id,namespace:p.namespace,state:"error",error:a.error,startTs:p.startTs,endTs:a.ts,durationMs:a.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:a.position,streamState:"error",backpressureOccurred:p.backpressureOccurred};L(U),E.delete(h)}y=Date.now();break}case"stream_backpressure":{let h=`${a.workflowId}:${a.namespace}`,p=E.get(h);p&&(p.backpressureOccurred=!0),y=Date.now();break}}$(a)}function te(a){if(a.type==="scope_start")k.push({id:a.scopeId,name:a.name,type:a.scopeType,startTs:a.ts,children:[]}),y=Date.now();else if(a.type==="scope_end"){let h=k.findIndex(T=>T.id===a.scopeId);if(h===-1)return;for(;k.length>h+1;){let T=k.pop(),B=T.type==="race"?{type:"race",id:T.id,name:T.name,state:M(T.children),startTs:T.startTs,endTs:a.ts,children:T.children}:{type:"parallel",id:T.id,name:T.name,state:M(T.children),startTs:T.startTs,endTs:a.ts,children:T.children,mode:T.type==="allSettled"?"allSettled":"all"};k[k.length-1].children.push(B)}let[p]=k.splice(h,1),U=p.type==="race"?{type:"race",id:p.id,name:p.name,state:M(p.children),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,children:p.children,winnerId:a.winnerId}:{type:"parallel",id:p.id,name:p.name,state:M(p.children),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,children:p.children,mode:p.type==="allSettled"?"allSettled":"all"};L(U)}}function x(a){if(a.type==="decision_start")b.push({id:a.decisionId,name:a.name,condition:a.condition,decisionValue:a.decisionValue,startTs:a.ts,branches:new Map,pendingChildren:[]}),y=Date.now();else if(a.type==="decision_branch"){let h=b.find(p=>p.id===a.decisionId);if(h){let p=a.branchLabel,U=h.branches.get(p);if(U)U.taken=a.taken,a.taken&&h.pendingChildren.length>0&&(U.children.unshift(...h.pendingChildren),h.pendingChildren=[]);else{let T=a.taken?[...h.pendingChildren]:[];a.taken&&(h.pendingChildren=[]),h.branches.set(p,{label:a.branchLabel,condition:a.condition,taken:a.taken,children:T})}y=Date.now()}}else if(a.type==="decision_end"){let h=b.findIndex(p=>p.id===a.decisionId);if(h!==-1){let[p]=b.splice(h,1),U=b.splice(h),T=Array.from(p.branches.values());T.length===0&&p.pendingChildren.length>0&&(T=[{label:"default",taken:!0,children:[...p.pendingChildren]}]);let B=T.find(de=>de.taken)?.label,mt={type:"decision",id:p.id,name:p.name,state:M(T.flatMap(de=>de.taken?de.children:[])),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,condition:p.condition,decisionValue:p.decisionValue,branchTaken:a.branchTaken??B,branches:T};L(mt),b.push(...U),y=Date.now()}}}function M(a){return a.length===0?"success":a.some(T=>T.state==="error")?"error":a.every(T=>T.state==="success"||T.state==="cached")?"success":a.some(T=>T.state==="running")?"running":"pending"}function le(){let a=[...D];for(let[,h]of f)a.push({type:"step",id:h.id,name:h.name,key:h.key,state:"running",startTs:h.startTs,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}});for(let[,h]of E)a.push({type:"stream",id:h.id,namespace:h.namespace,state:"running",startTs:h.startTs,writeCount:h.writeCount,readCount:h.readCount,finalPosition:h.finalPosition,streamState:h.streamState,backpressureOccurred:h.backpressureOccurred});return a}function De(){let a=le();t&&(a=Ae(a,r));let h={type:"workflow",id:c??i,workflowId:c??i,state:d,startTs:l,endTs:u,durationMs:m,children:a,error:g},p=C.shouldRun!==void 0||C.onBeforeStart!==void 0||C.onAfterStep.size>0;return{root:h,metadata:{createdAt:S,lastUpdatedAt:y},...p&&{hooks:C}}}function Ue(){c=void 0,l=void 0,u=void 0,d="pending",g=void 0,m=void 0,f.clear(),k.length=0,b.length=0,E.clear(),D=[],S=Date.now(),y=S,C={onAfterStep:new Map},I=void 0,R.length=0,v=0}function se(){return[...R]}function dt(a){return R[a]}function pt(a){return R[a]?.ir}function ft(){R.length=0,v=0}return{handleEvent:P,handleScopeEvent:te,handleDecisionEvent:x,getIR:De,reset:Ue,getSnapshots:se,getSnapshotAt:dt,getIRAt:pt,clearSnapshots:ft,get hasActiveSteps(){return f.size>0},get state(){return d},get snapshotCount(){return R.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(a){n=a}}}var ge=require("awaitly");function K(e){return e.type==="step"}function Be(e){return e.type==="sequence"}function X(e){return e.type==="parallel"}function F(e){return e.type==="race"}function J(e){return e.type==="decision"}function Z(e){return e.type==="stream"}var Ne="\x1B[0m",Et="\x1B[1m",ze="\x1B[2m",Mt="\x1B[31m",It="\x1B[32m",Dt="\x1B[33m",Nt="\x1B[34m",Ke="\x1B[90m",Ot="\x1B[37m";function z(e,t){return t?`${t}${e}${Ne}`:e}function ie(e){return`${Et}${e}${Ne}`}function N(e){return`${ze}${e}${Ne}`}var Q={pending:Ot,running:Dt,success:It,error:Mt,aborted:Ke,cached:Nt,skipped:ze+Ke};function vt(e){switch(e){case"pending":return"\u25CB";case"running":return"\u27F3";case"success":return"\u2713";case"error":return"\u2717";case"aborted":return"\u2298";case"cached":return"\u21BA";case"skipped":return"\u2298"}}function ae(e,t){let r=vt(e);return z(r,t[e])}function me(e,t,r){return z(e,r[t])}function Y(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var w={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},re={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Tt="\x1B[0m";function Ct(e){return e<.2?re.cold:e<.4?re.cool:e<.6?re.neutral:e<.8?re.warm:e<.95?re.hot:re.critical}function Ge(e,t){let r=Ct(t);return r?`${r}${e}${Tt}`:e}function Wt(e){try{return(0,ge.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,ge.err)("STRINGIFY_ERROR")}}function je(e){let t=Wt(e);return t.ok?t.value:"[unserializable]"}var Ve="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ve(e,t=10){if(e.length===0)return"";let r=e.slice(-t),o=Math.min(...r),n=Math.max(...r)-o||1;return r.map(i=>{let c=(i-o)/n,l=Math.floor(c*(Ve.length-1));return Ve[l]}).join("")}function Oe(e,t){let r=Y(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function _t(e,t){if(!t)return w.horizontal.repeat(e);let r=` ${t} `,o=Y(r).length,s=e-o;if(s<4)return w.horizontal.repeat(e);let n=2,i=s-n;return w.horizontal.repeat(n)+r+w.horizontal.repeat(i)}function Ye(e,t,r){let o=e.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),s=e.durationMs!==void 0?N(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=N(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=N(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=N(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?N(` error: ${String(e.error)}`):"";return`${o} ${N(t)}${n}${s}${i}`}function Lt(e,t){let r=[];return e.shouldRun&&r.push(Ye(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Ye(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(N("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),r}function ce(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...Q,...t.colors},o=Math.max(t.terminalWidth??60,5),s=o-4,n=[],i=e.root.name??"workflow",c=ie(i);if(n.push(`${w.topLeft}${_t(o-2,c)}${w.topRight}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.hooks){let u=Lt(e.hooks,r);for(let d of u)n.push(`${w.vertical} ${Oe(d,s)}${w.vertical}`)}let l=he(e.root.children,t,r,0,e.hooks);for(let u of l)n.push(`${w.vertical} ${Oe(u,s)}${w.vertical}`);if(n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let u=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",g=`${me(u,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${w.vertical} ${Oe(g,s)}${w.vertical}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`)}return n.push(`${w.bottomLeft}${w.horizontal.repeat(o-2)}${w.bottomRight}`),n.join(`
|
|
2
|
-
`)}}}function
|
|
3
|
-
`)}}}function
|
|
4
|
-
`)}var G=11,j=2,oe=2,xe=3;function _e(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],s="";for(let n of r)s?s.length+1+n.length<=t?s+=" "+n:(o.push(s),s=n):s=n;if(s&&o.push(s),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function tt(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function or(e,t,r){let o=t.showStartEnd??!0,s=t,n=Math.floor(r/2),i=[],c=0;if(o){let u=Re("start","start",["\u25B6 Start"],"success",n,c);i.push(u),c=u.bottomY+oe}for(let u of e.root.children){let d=$e(u,n,c,r-4,t,s);i.push(d.node),c=d.bottomY+oe}if(o&&["success","error","aborted"].includes(e.root.state)){let u=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",d=Re("end","end",[u],e.root.state,n,c);i.push(d),c=d.bottomY}return{nodes:i,totalHeight:c+2}}function Re(e,t,r,o,s,n){let i=Math.max(...r.map(d=>Y(d).length)),c=Math.max(G,i+j*2),l=r.length+2,u=s-Math.floor(c/2);return{id:e,type:t,label:r,state:o,x:u,y:n,width:c,height:l,centerX:s,bottomY:n+l-1}}function $e(e,t,r,o,s,n){if(K(e))return sr(e,t,r,o,s,n);if(X(e)||F(e))return ar(e,t,r,o,s,n);if(J(e))return cr(e,t,r,o,s,n);if(Z(e))return ir(e,t,r,o,s,n);let i=Re(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function sr(e,t,r,o,s,n){let i=e.name??e.key??"step",c=tt(e.state),l=[],u=`${c} ${i}`;s.showKeys&&e.key&&e.name&&(u+=` [${e.key}]`);let d=Math.min(o-j*2,40);if(l.push(..._e(u,d)),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&l.push(`${e.retryCount}x retry`),e.timedOut&&l.push("timeout"),n?.showSparklines&&n.timingHistory){let D=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);D&&D.length>1&&l.push(ve(D,8))}let g=Math.max(...l.map(D=>Y(D).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b;if(n?.showHeatmap&&n.heatmapData){let D=e.key??e.name??e.id;b=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(D)}let E={id:e.id,type:"step",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:b!==void 0?{heat:b}:void 0};return{node:E,bottomY:E.bottomY}}function ir(e,t,r,o,s,n){let i=`stream:${e.namespace}`,c=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",l=[],u=`${c} ${i}`,d=Math.min(o-j*2,40);l.push(..._e(u,d)),l.push(`W:${e.writeCount} R:${e.readCount}`),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&l.push("backpressure");let g=Math.max(...l.map(E=>Y(E).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b={id:e.id,type:"stream",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:b,bottomY:b.bottomY}}function ar(e,t,r,o,s,n){let i=F(e),c=e.name??(i?"race":"parallel"),u=`${i?"\u26A1":"\u2AD8"} ${c}`;if(e.children.length===0){let v=[u,"(not tracked)"],O=Re(e.id,i?"race":"parallel",v,e.state,t,r);return{node:O,bottomY:O.bottomY}}let d=Math.floor((o-xe*(e.children.length-1))/e.children.length),g=[];for(let v of e.children){let O=We(v,Math.max(d,G),s,n);g.push(O.width)}let m=g.reduce((v,O)=>v+O,0)+xe*(e.children.length-1),f=m>o&&e.children.length>1,k=Math.max(G,u.length+j*2),b=3,E=t-Math.floor(k/2),D=r;D+=b,D+=1,D+=1;let S=[];if(f)for(let v=0;v<e.children.length;v++){let O=e.children[v],L=$e(O,t,D,o,s,n);i&&F(e)&&e.winnerId===O.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),S.push(L.node),D=L.bottomY+oe}else{let v=t-Math.floor(m/2);for(let O=0;O<e.children.length;O++){let L=e.children[O],$=v+Math.floor(g[O]/2),P=$e(L,$,D,g[O],s,n);i&&F(e)&&e.winnerId===L.id&&(P.node.metadata={...P.node.metadata,isWinner:!0}),S.push(P.node),v+=g[O]+xe}}let y=Math.max(...S.map(v=>v.bottomY)),I=!f&&S.length>1?y+2:y;return{node:{id:e.id,type:i?"race":"parallel",label:[u],state:e.state,x:E,y:r,width:k,height:b,centerX:t,bottomY:I,children:S,metadata:{verticalLayout:f}},bottomY:I}}function cr(e,t,r,o,s,n){let i=e.name??"decision",c=e.condition?` (${e.condition.slice(0,20)})`:"",l=`\u25C7 ${i}${c}`,u=Math.min(o-j*2,40),d=_e(l,u),g=Math.max(...d.map(I=>Y(I).length)),m=Math.max(G,g+j*2),f=d.length+2,k=t-Math.floor(m/2),b=e.branches.find(I=>I.taken),E=b&&b.children.length>0?b:e.branches.find(I=>I.children.length>0);if(!E||E.children.length===0){let I={id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1};return{node:I,bottomY:I.bottomY}}let D=r+f+oe,S=[];for(let I of E.children){let R=$e(I,t,D,o,s,n);S.push(R.node),D=R.bottomY+oe}let y=S.length>0?S[S.length-1].bottomY:r+f-1;return{node:{id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:y,children:S},bottomY:y}}function We(e,t,r,o){if(K(e)){let s=e.name??e.key??"step",n=tt(e.state),i=1;r.showTimings&&e.durationMs!==void 0&&i++,e.retryCount&&e.retryCount>0&&i++,e.timedOut&&i++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&i++;let c=`${n} ${s}`;r.showKeys&&e.key&&e.name&&(c+=` [${e.key}]`);let l=Math.min(t,Math.max(G,c.length+j*2)),u=i+2;return{width:l,height:u}}if(X(e)||F(e)){if(e.children.length===0)return{width:G+4,height:4};let s=Math.floor(t/e.children.length),n=0,i=0;for(let c of e.children){let l=We(c,s,r,o);n+=l.width,i=Math.max(i,l.height)}return n+=xe*(e.children.length-1),{width:Math.max(n,G),height:5+i+2}}if(J(e)){let s=e.branches.find(i=>i.taken),n=0;if(s)for(let i of s.children){let c=We(i,t,r,o);n+=c.height+oe}return{width:Math.min(t,30),height:3+n}}if(Z(e)){let s=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(G,s.length+j*2+4)),c=n+2;return{width:i,height:c}}return{width:G,height:3}}function ur(e,t,r){let o={...Q,...r.colors};for(let s=0;s<t.length;s++){let n=t[s],i=s===t.length-1;if(Ee(e,n,o),!i){let c=t[s+1],l=n.centerX,u=n.bottomY+1,d=c.centerX,g=c.y-1;q(e,l,u,g-1),ee(e,d,g)}}}function Ee(e,t,r){let o=t.type!=="start",s=t.type!=="end"&&(!t.children||t.children.length===0);rr(e,t.x,t.y,t.width,t.height),o&&_(e,t.centerX,t.y,W.teeUp),(s||t.children&&t.children.length>0)&&_(e,t.centerX,t.y+t.height-1,W.teeDown);let n=t.width-j*2,i=fr(t,r);for(let c=0;c<t.label.length;c++){let l=t.label[c],u=t.x+1+Math.floor((n-Y(l).length)/2),d=t.y+1+c;Ze(e,u,d,l,i)}t.metadata?.isWinner&&Ze(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?lr(e,t,r):dr(e,t,r))}function lr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let c=o[0];q(e,n,s,c.y-2),ee(e,c.centerX,c.y-1);for(let l=0;l<o.length;l++){let u=o[l];if(Ee(e,u,r),l<o.length-1){let d=o[l+1];q(e,u.centerX,u.bottomY+1,d.y-2),ee(e,d.centerX,d.y-1)}}return}if(o.length===1)q(e,n,s,o[0].y-2),ee(e,o[0].centerX,o[0].y-1);else{let c=o.map(d=>d.centerX),l=Math.min(...c),u=Math.max(...c);q(e,n,s,s+1),Qe(e,s+1,l,u),_(e,n,s+1,W.teeUp);for(let d of o){let g=d.centerX;g===l?_(e,g,s+1,W.topLeft):g===u?_(e,g,s+1,W.topRight):g!==n&&_(e,g,s+1,W.teeDown),q(e,g,s+2,d.y-2),ee(e,g,d.y-1)}}for(let c of o)Ee(e,c,r);if(o.length>1){let c=o.map(f=>f.bottomY),l=Math.max(...c),u=l+1,d=o.map(f=>f.centerX),g=Math.min(...d),m=Math.max(...d);for(let f of o)f.bottomY<l&&q(e,f.centerX,f.bottomY+1,u-1);Qe(e,u,g,m);for(let f of o){let k=f.centerX;k===g?_(e,k,u,W.bottomLeft):k===m?_(e,k,u,W.bottomRight):_(e,k,u,W.teeUp)}_(e,t.centerX,u,W.teeDown),_(e,t.centerX,u+1,W.vertical)}}function dr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=o[0];q(e,t.centerX,s,n.y-2),ee(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let c=o[i];if(Ee(e,c,r),i<o.length-1){let l=o[i+1];q(e,c.centerX,c.bottomY+1,l.y-2),ee(e,l.centerX,l.y-1)}}}var pr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function fr(e,t){if(e.metadata?.heat!==void 0){let r=ke(e.metadata.heat);return Qt[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?pr[e.metadata.streamState]||void 0:t[e.state]||void 0}function ue(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:s}=or(e,t,r),n=tr(r,s);return ur(n,o,t),nr(n)}}}function mr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function gr(e){let t=[];function r(o){for(let s of o)if(K(s))t.push(s);else if(Be(s))r(s.children);else if(X(s)||F(s))r(s.children);else if(J(s))for(let n of s.branches)n.taken&&r(n.children)}return r(e),t}function hr(e){let t={id:e.id,name:e.name??e.key??e.id,state:e.state};return e.key&&(t.key=e.key),e.durationMs!==void 0&&(t.durationMs=e.durationMs),e.startTs!==void 0&&(t.startTs=e.startTs),e.endTs!==void 0&&(t.endTs=e.endTs),e.retryCount!==void 0&&e.retryCount>0&&(t.retryCount=e.retryCount),e.timedOut&&(t.timedOut=!0,e.timeoutMs!==void 0&&(t.timeoutMs=e.timeoutMs)),e.error!==void 0&&(t.error=typeof e.error=="string"?e.error:String(e.error)),t}function kr(e){let t=0,r=0,o=0,s=0,n=0,i;for(let c of e)c.state==="success"&&t++,c.state==="error"&&r++,c.state==="cached"&&o++,c.state==="skipped"&&s++,c.retryCount!==void 0&&(n+=c.retryCount),c.durationMs!==void 0&&(!i||c.durationMs>i.durationMs)&&(i={name:c.name??c.key??c.id,durationMs:c.durationMs});return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:s,totalRetries:n,slowestStep:i}}function wr(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let s={stepKey:r};o.durationMs!==void 0&&(s.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(s.error=String(o.error)),t.onAfterStep.push(s)}}return t}function br(e,t){let r=e.root,o=gr(r.children),s=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(hr),summary:kr(o)};if(e.hooks){let c=wr(e.hooks);Object.keys(c).length>0&&(i.hooks=c)}if(s){let u=((t.diagramFormat??"ascii")==="flowchart"?ue():ce()).render(e,t);n&&(u=mr(u)),i.diagram=u}return i}function Le(){return{name:"logger",supportsLive:!1,render(e,t){let o=br(e,t);return JSON.stringify(o)}}}var V=require("awaitly");var rt=St(require("pako"),1),yr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Sr(e){let t;if(yr)t=globalThis.Buffer.from(e).toString("base64");else{let r="";for(let o=0;o<e.length;o++)r+=String.fromCharCode(e[o]);t=btoa(r)}return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Me(e){let r=new TextEncoder().encode(e),o=rt.default.deflate(r);return Sr(o)}var xr="https://kroki.io";function nt(e,t,r,o={}){let s=o.baseUrl??xr,n=Me(r);return`${s}/${e}/${t}/${n}`}var Rr="https://mermaid.ink";function $r(e){return`pako:${Me(e)}`}function Er(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 Mr(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 ot(e,t,r={}){let o=Er(r),s=o.baseUrl??Rr,n=$r(t),i=Mr(e,o);return`${s}/${e}/${n}${i}`}function Ir(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,V.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,V.err)("UNSUPPORTED_FORMAT"):(0,V.ok)(void 0):(0,V.err)("UNSUPPORTED_FORMAT")}function Dr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Nr(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function Ie(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND")}}let s=Ir(r.provider,e.kind,t);if(!s.ok)return s;switch(r.provider){case"kroki":return(0,V.ok)(nt(Dr(e.kind),t,e.source,r));case"mermaid-ink":return(0,V.ok)(ot(Nr(t),e.source,r));default:{let n=r;return(0,V.err)("UNKNOWN_PROVIDER")}}}function st(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:s=!1,colors:n,export:i}=e,c=Fe({detectParallel:r}),l=new Set,u=ce(),d=Ce(),g=Le(),m=ue(),f={showTimings:o,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...Q,...n}};function k(){if(l.size>0){let x=S();for(let M of l)M(x)}}function b(x){if(x.type==="scope_start"||x.type==="scope_end"){E(x);return}c.handleEvent(x),x.type,k()}function E(x){c.handleScopeEvent(x),k()}function D(x){c.handleDecisionEvent(x),k()}function S(){let x=c.getIR();return t&&!x.root.name&&(x.root.name=t),x}function y(){let x=S();return u.render(x,f)}function C(x){let M=S();switch(x){case"ascii":return u.render(M,f);case"mermaid":return d.render(M,f);case"json":{let le=M.hooks?{...M,hooks:{...M.hooks,onAfterStep:M.hooks.onAfterStep instanceof Map?Object.fromEntries(M.hooks.onAfterStep):M.hooks.onAfterStep??{}}}:M;return JSON.stringify(le,(Ue,se)=>typeof se=="bigint"?se.toString():se,2)}case"logger":return g.render(M,f);case"flowchart":return m.render(M,f);default:throw new Error(`Unknown format: ${x}`)}}function I(){c.reset(),k()}function R(x){return l.add(x),()=>l.delete(x)}function v(x,M){if(x)return x;if(i?.default)return i.default;throw new Error(`${M}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function O(){let x=S();return{kind:"mermaid",source:d.render(x,f)}}function L(x){let M=Ie(O(),"svg",v(x,"toSvgUrl"),{caller:"toSvgUrl"});if(!M.ok)throw new Error(`toSvgUrl: Export failed - ${M.error}`);return M.value}function $(x){let M=Ie(O(),"png",v(x,"toPngUrl"),{caller:"toPngUrl"});if(!M.ok)throw new Error(`toPngUrl: Export failed - ${M.error}`);return M.value}function P(x){let M=Ie(O(),"pdf",v(x,"toPdfUrl"),{caller:"toPdfUrl"});if(!M.ok)throw new Error(`toPdfUrl: Export failed - ${M.error}`);return M.value}function te(x,M){switch(x){case"svg":return L(M);case"png":return $(M);case"pdf":return P(M);default:return x}}return{handleEvent:b,handleScopeEvent:E,handleDecisionEvent:D,getIR:S,render:y,renderAs:C,reset:I,onUpdate:R,toUrl:te,toSvgUrl:L,toPngUrl:$,toPdfUrl:P}}function Pe(e={}){let{logEvents:t=!1,maxHistory:r=10,logger:o=console.log}=e,s=st(e),n=[],i,c=0;function l($){if(i)for(n.push(i);n.length>r;)n.shift();c=Date.now(),i={id:$,name:e.workflowName,startTime:c,events:[]},s.reset()}function u($,P){i&&(i.endTime=Date.now(),i.durationMs=i.endTime-i.startTime,i.success=$,i.error=P)}function d($){t&&o(`[devtools] ${$.type}: ${JSON.stringify($)}`),$.type==="workflow_start"&&l($.workflowId),i&&i.events.push($),s.handleEvent($),$.type==="workflow_success"?u(!0):$.type==="workflow_error"&&u(!1,$.error)}function g($){t&&o(`[devtools] ${$.type}: ${JSON.stringify($)}`),i&&i.events.push($),s.handleDecisionEvent($)}function m(){return i}function f(){return[...n]}function k($){return i?.id===$?i:n.find(P=>P.id===$)}function b($,P){let te=k($),x=k(P);if(!(!te||!x))return it(te,x)}function E(){if(!i||n.length===0)return;let $=n[n.length-1];return it($,i)}function D(){return s.render()}function S($){return s.renderAs($)}function y(){return s.renderAs("mermaid")}function C(){let $=I();return vr($)}function I(){return i?Or(i.events,c):[]}function R(){n.length=0}function v(){i=void 0,s.reset()}function O($){let P=$?k($):i;return P?JSON.stringify(P,null,2):"{}"}function L($){let P=JSON.parse($);return n.push(P),P}return{handleEvent:d,handleDecisionEvent:g,getCurrentRun:m,getHistory:f,getRun:k,diff:b,diffWithPrevious:E,render:D,renderAs:S,renderMermaid:y,renderTimeline:C,getTimeline:I,clearHistory:R,reset:v,exportRun:O,importRun:L}}function it(e,t){let r=at(e.events),o=at(t.events),s=[],n=[],i=[],c=[];for(let[m,f]of o){let k=r.get(m);k?k.status!==f.status?i.push({step:m,type:"status",from:k.status,to:f.status}):k.durationMs!==f.durationMs?i.push({step:m,type:"duration",from:k.durationMs,to:f.durationMs}):c.push(m):s.push({step:m,type:"added",to:f.status})}for(let[m]of r)o.has(m)||n.push({step:m,type:"removed",from:r.get(m)?.status});let l,u=e.success===void 0?"running":e.success?"success":"error",d=t.success===void 0?"running":t.success?"success":"error";u!==d&&(l={from:u,to:d});let g;return e.durationMs!==void 0&&t.durationMs!==void 0&&(g=t.durationMs-e.durationMs),{added:s,removed:n,changed:i,unchanged:c,statusChange:l,durationChange:g}}function at(e){let t=new Map;for(let r of e)if(r.type==="step_start"){let o=r,s=o.name||o.stepKey||o.stepId;t.set(s,{name:s,key:o.stepKey,status:"running"})}else if(r.type==="step_success"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="success",n.durationMs=o.durationMs)}else if(r.type==="step_error"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="error",n.durationMs=o.durationMs,n.error=o.error)}else if(r.type==="step_cache_hit"){let o=r,s=o.name||o.stepKey;t.set(s,{name:s,key:o.stepKey,status:"cached"})}else if(r.type==="step_skipped"){let o=r,s=o.name||o.stepKey||"unknown";t.set(s,{name:s,key:o.stepKey,status:"skipped"})}return t}function Or(e,t){let r=[],o=new Map;for(let s of e)if(s.type==="step_start"){let n=s,i=n.name||n.stepKey||n.stepId;o.set(i,n.ts),r.push({name:i,key:n.stepKey,startMs:n.ts-t,status:"running"})}else if(s.type==="step_success"){let n=s,i=n.name||n.stepKey||n.stepId,c=r.find(l=>l.name===i&&l.status==="running");c&&(c.endMs=n.ts-t,c.durationMs=n.durationMs,c.status="success")}else if(s.type==="step_error"){let n=s,i=n.name||n.stepKey||n.stepId,c=r.find(l=>l.name===i&&l.status==="running");c&&(c.endMs=n.ts-t,c.durationMs=n.durationMs,c.status="error",c.error=n.error)}else if(s.type==="step_cache_hit"){let n=s,i=n.name||n.stepKey;r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"cached"})}else if(s.type==="step_skipped"){let n=s,i=n.name||n.stepKey||"unknown";r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"skipped"})}return r}function vr(e){if(e.length===0)return"No timeline data";let t=[];t.push("Timeline:"),t.push("\u2500".repeat(60));let r=Math.max(...e.map(s=>s.endMs??s.startMs+100)),o=40;for(let s of e){let n=Math.floor(s.startMs/r*o),i=Math.floor((s.endMs??s.startMs+10)/r*o),c=Math.max(1,i-n),l=Tr(s.status),u=" ".repeat(n)+l.repeat(c),d=s.durationMs!==void 0?`${s.durationMs}ms`:"?";t.push(`${s.name.padEnd(20)} |${u.padEnd(o)}| ${d}`)}return t.push("\u2500".repeat(60)),t.join(`
|
|
5
|
-
`)}function Tr(e){switch(e){case"success":return"\u2588";case"error":return"\u2591";case"running":return"\u2592";case"cached":return"\u2593";case"skipped":return"\xB7";default:return"?"}}function
|
|
1
|
+
"use strict";var gt=Object.create;var fe=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var wt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var yt=(e,t)=>{for(var r in t)fe(e,r,{get:t[r],enumerable:!0})},Fe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of kt(t))!bt.call(e,s)&&s!==r&&fe(e,s,{get:()=>t[s],enumerable:!(o=ht(t,s))||o.enumerable});return e};var St=(e,t,r)=>(r=e!=null?gt(wt(e)):{},Fe(t||!e||!e.__esModule?fe(r,"default",{value:e,enumerable:!0}):r,e)),xt=e=>Fe(fe({},"__esModule",{value:!0}),e);var Cr={};yt(Cr,{createConsoleLogger:()=>dt,createDevtools:()=>Pe,quickVisualize:()=>lt,renderDiff:()=>ut});module.exports=xt(Cr);function H(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let t=Math.floor(e/6e4),r=Math.round(e%6e4/1e3);return r>=60&&(t+=1,r=0),r===0?`${t}m`:`${t}m ${r}s`}function me(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Rt(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||t.type==="decision")return!0;return!1}function Ae(e,t={}){if(Rt(e))return e;let{minOverlapMs:r=0,maxGapMs:o=5}=t,s=[],n=[];for(let u=0;u<e.length;u++){let d=e[u];d.type==="step"&&d.startTs!==void 0?s.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:u}):n.push({node:d,originalIndex:u})}if(s.length<=1)return e;s.sort((u,d)=>u.startTs-d.startTs);let i=[],c=[s[0]];for(let u=1;u<s.length;u++){let d=s[u],g=Math.min(...c.map($=>$.startTs)),m=Math.max(...c.map($=>$.endTs)),f=d.startTs<=g+o,k=d.startTs<m;if(!f&&!k){i.push(c),c=[d];continue}let b=k?Math.min(d.endTs,m)-d.startTs:0;f||b>=r?c.push(d):(i.push(c),c=[d])}i.push(c);let l=[];for(let u of i){let d=Math.min(...u.map(g=>g.originalIndex));if(u.length===1)l.push({node:u[0].node,position:d});else{let g=u.map(b=>b.node),m=Math.min(...u.map(b=>b.startTs)),f=Math.max(...u.map(b=>b.endTs)),k={type:"parallel",id:`detected_parallel_${m}`,name:`${g.length} parallel steps`,state:$t(g),mode:"all",children:g,startTs:m,endTs:f,durationMs:f-m};l.push({node:k,position:d})}}for(let{node:u,originalIndex:d}of n)l.push({node:u,position:d});return l.sort((u,d)=>u.position-d.position),l.map(u=>u.node)}function $t(e){return e.some(n=>n.state==="error")?"error":e.some(n=>n.state==="running")?"running":e.some(n=>n.state==="pending")?"pending":(e.every(n=>n.state==="success"||n.state==="cached"),"success")}function Be(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:s=1e3}=e,n=o,i=me(),c,l,u,d="pending",g,m,f=new Map,k=[],b=[],$=new Map,I=[],E=Date.now(),y=E,C={onAfterStep:new Map},N,x=[],T=0;function D(a){return a.stepId??a.stepKey??a.name??me()}function L(a){if(k.length>0){k[k.length-1].children.push(a),y=Date.now();return}if(b.length>0){let h=b[b.length-1];for(let p of h.branches.values())if(p.taken){p.children.push(a),y=Date.now();return}h.pendingChildren.push(a),y=Date.now();return}I.push(a),y=Date.now()}function R(a){if(!n)return;let h=ie(),p=new Map;for(let[v,B]of f)p.set(v,{id:B.id,name:B.name,key:B.key,startTs:B.startTs,retryCount:B.retryCount,timedOut:B.timedOut,timeoutMs:B.timeoutMs});let U={id:`snapshot_${T}`,eventIndex:T,event:structuredClone(a),ir:structuredClone(h),timestamp:Date.now(),activeSteps:p};x.push(U),x.length>s&&x.shift(),T++}function P(a){switch(a.type){case"workflow_start":{I=[],u=void 0,m=void 0,g=void 0,f.clear(),k.length=0,b.length=0,$.clear(),c=a.workflowId,l=a.ts,d="running",E=Date.now(),y=E,N!==void 0&&N!==a.workflowId&&(C.shouldRun=void 0,C.onBeforeStart=void 0),N=a.workflowId,C.onAfterStep=new Map;break}case"workflow_success":d="success",u=a.ts,m=a.durationMs,y=Date.now();break;case"workflow_error":d="error",u=a.ts,g=a.error,m=a.durationMs,y=Date.now();break;case"workflow_cancelled":d="aborted",u=a.ts,m=a.durationMs,y=Date.now();break;case"step_start":{let h=D(a);f.set(h,{id:h,name:a.name,key:a.stepKey,startTs:a.ts,retryCount:0,timedOut:!1}),y=Date.now();break}case"step_success":{let h=D(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"success",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_error":{let h=D(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"error",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,error:a.error,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_aborted":{let h=D(a),p=f.get(h);if(p){let U={type:"step",id:p.id,name:p.name,key:p.key,state:"aborted",startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,...p.retryCount>0&&{retryCount:p.retryCount},...p.timedOut&&{timedOut:!0,timeoutMs:p.timeoutMs}};L(U),f.delete(h)}break}case"step_cache_hit":{let p={type:"step",id:D(a),name:a.name,key:a.stepKey,state:"cached",startTs:a.ts,endTs:a.ts,durationMs:0};L(p);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let h=D(a),p=f.get(h);p&&(p.timedOut=!0,p.timeoutMs=a.timeoutMs),y=Date.now();break}case"step_retry":{let h=D(a),p=f.get(h);p&&(p.retryCount=(a.attempt??1)-1),y=Date.now();break}case"step_retries_exhausted":y=Date.now();break;case"step_skipped":{let p={type:"step",id:D(a),name:a.name,key:a.stepKey,state:"skipped",startTs:a.ts,endTs:a.ts,durationMs:0};L(p);break}case"hook_should_run":{let h={type:"shouldRun",state:"success",ts:a.ts,durationMs:a.durationMs,context:{result:a.result,skipped:a.skipped}};C.shouldRun=h,N=a.workflowId,y=Date.now();break}case"hook_should_run_error":{let h={type:"shouldRun",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error};C.shouldRun=h,N=a.workflowId,y=Date.now();break}case"hook_before_start":{let h={type:"onBeforeStart",state:"success",ts:a.ts,durationMs:a.durationMs,context:{result:a.result,skipped:a.skipped}};C.onBeforeStart=h,N=a.workflowId,y=Date.now();break}case"hook_before_start_error":{let h={type:"onBeforeStart",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error};C.onBeforeStart=h,N=a.workflowId,y=Date.now();break}case"hook_after_step":{let h={type:"onAfterStep",state:"success",ts:a.ts,durationMs:a.durationMs,context:{stepKey:a.stepKey}};C.onAfterStep.set(a.stepKey,h),y=Date.now();break}case"hook_after_step_error":{let h={type:"onAfterStep",state:"error",ts:a.ts,durationMs:a.durationMs,error:a.error,context:{stepKey:a.stepKey}};C.onAfterStep.set(a.stepKey,h),y=Date.now();break}case"stream_created":{let h=`${a.workflowId}:${a.namespace}`;$.set(h,{id:me(),namespace:a.namespace,startTs:a.ts,writeCount:0,readCount:0,streamState:"active",backpressureOccurred:!1,finalPosition:0}),y=Date.now();break}case"stream_write":{let h=`${a.workflowId}:${a.namespace}`,p=$.get(h);p&&(p.writeCount++,p.finalPosition=Math.max(p.finalPosition,a.position)),y=Date.now();break}case"stream_read":{let h=`${a.workflowId}:${a.namespace}`,p=$.get(h);p&&p.readCount++,y=Date.now();break}case"stream_close":{let h=`${a.workflowId}:${a.namespace}`,p=$.get(h);if(p){p.streamState="closed",p.finalPosition=a.finalPosition;let U={type:"stream",id:p.id,namespace:p.namespace,state:"success",startTs:p.startTs,endTs:a.ts,durationMs:a.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:a.finalPosition,streamState:"closed",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(h)}y=Date.now();break}case"stream_error":{let h=`${a.workflowId}:${a.namespace}`,p=$.get(h);if(p){p.streamState="error";let U={type:"stream",id:p.id,namespace:p.namespace,state:"error",error:a.error,startTs:p.startTs,endTs:a.ts,durationMs:a.ts-p.startTs,writeCount:p.writeCount,readCount:p.readCount,finalPosition:a.position,streamState:"error",backpressureOccurred:p.backpressureOccurred};L(U),$.delete(h)}y=Date.now();break}case"stream_backpressure":{let h=`${a.workflowId}:${a.namespace}`,p=$.get(h);p&&(p.backpressureOccurred=!0),y=Date.now();break}}R(a)}function Z(a){if(a.type==="scope_start")k.push({id:a.scopeId,name:a.name,type:a.scopeType,startTs:a.ts,children:[]}),y=Date.now();else if(a.type==="scope_end"){let h=k.findIndex(v=>v.id===a.scopeId);if(h===-1)return;for(;k.length>h+1;){let v=k.pop(),B=v.type==="race"?{type:"race",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:a.ts,children:v.children}:{type:"parallel",id:v.id,name:v.name,state:S(v.children),startTs:v.startTs,endTs:a.ts,children:v.children,mode:v.type==="allSettled"?"allSettled":"all"};k[k.length-1].children.push(B)}let[p]=k.splice(h,1),U=p.type==="race"?{type:"race",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,children:p.children,winnerId:a.winnerId}:{type:"parallel",id:p.id,name:p.name,state:S(p.children),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,children:p.children,mode:p.type==="allSettled"?"allSettled":"all"};L(U)}}function re(a){if(a.type==="decision_start")b.push({id:a.decisionId,name:a.name,condition:a.condition,decisionValue:a.decisionValue,startTs:a.ts,branches:new Map,pendingChildren:[]}),y=Date.now();else if(a.type==="decision_branch"){let h=b.find(p=>p.id===a.decisionId);if(h){let p=a.branchLabel,U=h.branches.get(p);if(U)U.taken=a.taken,a.taken&&h.pendingChildren.length>0&&(U.children.unshift(...h.pendingChildren),h.pendingChildren=[]);else{let v=a.taken?[...h.pendingChildren]:[];a.taken&&(h.pendingChildren=[]),h.branches.set(p,{label:a.branchLabel,condition:a.condition,taken:a.taken,children:v})}y=Date.now()}}else if(a.type==="decision_end"){let h=b.findIndex(p=>p.id===a.decisionId);if(h!==-1){let[p]=b.splice(h,1),U=b.splice(h),v=Array.from(p.branches.values());v.length===0&&p.pendingChildren.length>0&&(v=[{label:"default",taken:!0,children:[...p.pendingChildren]}]);let B=v.find(pe=>pe.taken)?.label,mt={type:"decision",id:p.id,name:p.name,state:S(v.flatMap(pe=>pe.taken?pe.children:[])),startTs:p.startTs,endTs:a.ts,durationMs:a.durationMs,condition:p.condition,decisionValue:p.decisionValue,branchTaken:a.branchTaken??B,branches:v};L(mt),b.push(...U),y=Date.now()}}}function S(a){return a.length===0?"success":a.some(v=>v.state==="error")?"error":a.every(v=>v.state==="success"||v.state==="cached")?"success":a.some(v=>v.state==="running")?"running":"pending"}function M(){let a=[...I];for(let[,h]of f)a.push({type:"step",id:h.id,name:h.name,key:h.key,state:"running",startTs:h.startTs,...h.retryCount>0&&{retryCount:h.retryCount},...h.timedOut&&{timedOut:!0,timeoutMs:h.timeoutMs}});for(let[,h]of $)a.push({type:"stream",id:h.id,namespace:h.namespace,state:"running",startTs:h.startTs,writeCount:h.writeCount,readCount:h.readCount,finalPosition:h.finalPosition,streamState:h.streamState,backpressureOccurred:h.backpressureOccurred});return a}function ie(){let a=M();t&&(a=Ae(a,r));let h={type:"workflow",id:c??i,workflowId:c??i,state:d,startTs:l,endTs:u,durationMs:m,children:a,error:g},p=C.shouldRun!==void 0||C.onBeforeStart!==void 0||C.onAfterStep.size>0;return{root:h,metadata:{createdAt:E,lastUpdatedAt:y},...p&&{hooks:C}}}function Ue(){c=void 0,l=void 0,u=void 0,d="pending",g=void 0,m=void 0,f.clear(),k.length=0,b.length=0,$.clear(),I=[],E=Date.now(),y=E,C={onAfterStep:new Map},N=void 0,x.length=0,T=0}function He(){return[...x]}function ae(a){return x[a]}function pt(a){return x[a]?.ir}function ft(){x.length=0,T=0}return{handleEvent:P,handleScopeEvent:Z,handleDecisionEvent:re,getIR:ie,reset:Ue,getSnapshots:He,getSnapshotAt:ae,getIRAt:pt,clearSnapshots:ft,get hasActiveSteps(){return f.size>0},get state(){return d},get snapshotCount(){return x.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(a){n=a}}}var he=require("awaitly");function K(e){return e.type==="step"}function Ke(e){return e.type==="sequence"}function X(e){return e.type==="parallel"}function A(e){return e.type==="race"}function J(e){return e.type==="decision"}function Q(e){return e.type==="stream"}var Oe="\x1B[0m",Et="\x1B[1m",Ge="\x1B[2m",Mt="\x1B[31m",It="\x1B[32m",Nt="\x1B[33m",Ot="\x1B[34m",ze="\x1B[90m",Dt="\x1B[37m";function z(e,t){return t?`${t}${e}${Oe}`:e}function ce(e){return`${Et}${e}${Oe}`}function O(e){return`${Ge}${e}${Oe}`}var ee={pending:Dt,running:Nt,success:It,error:Mt,aborted:ze,cached:Ot,skipped:Ge+ze};function vt(e){switch(e){case"pending":return"\u25CB";case"running":return"\u27F3";case"success":return"\u2713";case"error":return"\u2717";case"aborted":return"\u2298";case"cached":return"\u21BA";case"skipped":return"\u2298"}}function ue(e,t){let r=vt(e);return z(r,t[e])}function ge(e,t,r){return z(e,r[t])}function Y(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var w={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},ne={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Tt="\x1B[0m";function Ct(e){return e<.2?ne.cold:e<.4?ne.cool:e<.6?ne.neutral:e<.8?ne.warm:e<.95?ne.hot:ne.critical}function je(e,t){let r=Ct(t);return r?`${r}${e}${Tt}`:e}function Wt(e){try{return(0,he.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,he.err)("STRINGIFY_ERROR")}}function Ve(e){let t=Wt(e);return t.ok?t.value:"[unserializable]"}var Ye="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ve(e,t=10){if(e.length===0)return"";let r=e.slice(-t),o=Math.min(...r),n=Math.max(...r)-o||1;return r.map(i=>{let c=(i-o)/n,l=Math.floor(c*(Ye.length-1));return Ye[l]}).join("")}function De(e,t){let r=Y(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function _t(e,t){if(!t)return w.horizontal.repeat(e);let r=` ${t} `,o=Y(r).length,s=e-o;if(s<4)return w.horizontal.repeat(e);let n=2,i=s-n;return w.horizontal.repeat(n)+r+w.horizontal.repeat(i)}function Xe(e,t,r){let o=e.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),s=e.durationMs!==void 0?O(` [${H(e.durationMs)}]`):"",n="";e.type==="shouldRun"&&e.context?.skipped?n=O(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?n=O(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?n=O(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(n=O(` (${e.context.stepKey})`));let i=e.state==="error"&&e.error?O(` error: ${String(e.error)}`):"";return`${o} ${O(t)}${n}${s}${i}`}function Lt(e,t){let r=[];return e.shouldRun&&r.push(Xe(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(Xe(e.onBeforeStart,"onBeforeStart",t)),r.length>0&&r.push(O("\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={...ee,...t.colors},o=Math.max(t.terminalWidth??60,5),s=o-4,n=[],i=e.root.name??"workflow",c=ce(i);if(n.push(`${w.topLeft}${_t(o-2,c)}${w.topRight}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.hooks){let u=Lt(e.hooks,r);for(let d of u)n.push(`${w.vertical} ${De(d,s)}${w.vertical}`)}let l=ke(e.root.children,t,r,0,e.hooks);for(let u of l)n.push(`${w.vertical} ${De(u,s)}${w.vertical}`);if(n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let u=e.root.state==="success"?"Completed":e.root.state==="aborted"?"Cancelled":"Failed",g=`${ge(u,e.root.state,r)} in ${H(e.root.durationMs)}`;n.push(`${w.vertical} ${De(g,s)}${w.vertical}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`)}return n.push(`${w.bottomLeft}${w.horizontal.repeat(o-2)}${w.bottomRight}`),n.join(`
|
|
2
|
+
`)}}}function ke(e,t,r,o,s){let n=[];for(let i of e)K(i)?n.push(Te(i,t,r,s)):X(i)?n.push(...Ut(i,t,r,o,s)):A(i)?n.push(...Ht(i,t,r,o,s)):J(i)?n.push(...Ft(i,t,r,o,s)):Q(i)&&n.push(Pt(i,t,r));return n}function Te(e,t,r,o){let s=ue(e.state,r),n=e.name??e.key??"step",i=t,c=i.showHeatmap&&i.heatmapData?i.heatmapData.heat.get(e.key??"")??i.heatmapData.heat.get(e.name??"")??i.heatmapData.heat.get(e.id):void 0,l;c!==void 0?l=je(n,c):l=ge(n,e.state,r);let u=`${s} ${l}`;if(t.showKeys&&e.key&&e.name&&(u+=O(` [key: ${e.key}]`)),e.input!==void 0){let g=typeof e.input=="string"?e.input:Ve(e.input).slice(0,30);u+=O(` [in: ${g}${g.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let g=typeof e.output=="string"?e.output:Ve(e.output).slice(0,30);u+=O(` [out: ${g}${g.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let g=H(e.durationMs),m=c!==void 0?je(`[${g}]`,c):O(`[${g}]`);u+=` ${m}`}if(i.showSparklines&&i.timingHistory){let g=i.timingHistory.get(e.key??"")??i.timingHistory.get(e.name??"")??i.timingHistory.get(e.id);g&&g.length>1&&(u+=` ${O(ve(g))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(u+=O(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let g=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";u+=O(` [timeout${g}]`)}let d=e.key??e.id;if(o&&d&&o.onAfterStep.has(d)){let g=o.onAfterStep.get(d),m=g.state==="success"?z("\u2699",r.success):z("\u26A0",r.error),f=g.durationMs!==void 0?O(` ${H(g.durationMs)}`):"";u+=` ${m}${f}`}return u}function Pt(e,t,r){let o=e.streamState==="active"?z("\u27F3",r.running):e.streamState==="closed"?z("\u2713",r.success):z("\u2717",r.error),s=`stream:${e.namespace}`,n=ge(s,e.state,r),i=O(`[W:${e.writeCount} R:${e.readCount}]`),c=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(c+=` ${O(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(c+=O(" [backpressure]")),e.streamState==="closed"&&(c+=O(` pos:${e.finalPosition}`)),c}function Ut(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ue(e.state,r),l=e.name??"parallel",u=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${c} ${ce(l)}${u}`),e.children.length===0)n.push(`${i}${w.vertical} ${O("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${O("(wrap each operation with step() to see individual steps)")}`);else for(let d=0;d<e.children.length;d++){let g=e.children[d],f=d===e.children.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`;if(K(g))n.push(`${f} ${Te(g,t,r,s)}`);else{let k=ke([g],t,r,o+1,s);for(let b of k)n.push(`${i}${w.vertical} ${b}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${O(`[${H(e.durationMs)}]`)}`),n}function Ht(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ue(e.state,r),l=e.name??"race";if(n.push(`${i}${w.teeRight}\u26A1 ${c} ${ce(l)}`),e.children.length===0)n.push(`${i}${w.vertical} ${O("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${O("(wrap each operation with step() to see individual steps)")}`);else for(let u=0;u<e.children.length;u++){let d=e.children[u],m=u===e.children.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`,k=e.winnerId&&d.id===e.winnerId?O(" (winner)"):"";if(K(d))n.push(`${m} ${Te(d,t,r,s)}${k}`);else{let b=ke([d],t,r,o+1,s);for(let $ of b)n.push(`${i}${w.vertical} ${$}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${O(`[${H(e.durationMs)}]`)}`),n}function Ft(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ue(e.state,r),l=e.name??"decision",u=e.condition?O(` (${e.condition})`):"",d=e.decisionValue!==void 0?O(` = ${String(e.decisionValue)}`):"",g=e.branchTaken!==void 0?O(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${c} ${ce(l)}${u}${d}${g}`);for(let m=0;m<e.branches.length;m++){let f=e.branches[m],b=m===e.branches.length-1?`${i}${w.vertical} ${w.bottomLeft}`:`${i}${w.vertical} ${w.teeRight}`,$=f.taken?"\u2713":"\u2298",I=f.taken?r.success:r.skipped,E=z(`${$} ${f.label}`,I),y=f.condition?O(` (${f.condition})`):"";if(n.push(`${b} ${E}${y}`),f.children.length>0){let C=ke(f.children,t,r,o+1,s);for(let N of C)n.push(`${i}${w.vertical} ${N}`)}else f.taken||n.push(`${i}${w.vertical} ${O("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${O(`[${H(e.durationMs)}]`)}`),n}var Se=require("awaitly");function we(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function At(){return[" classDef pending fill:#f3f4f6,stroke:#9ca3af,stroke-width:2px,color:#374151"," classDef running fill:#fef3c7,stroke:#f59e0b,stroke-width:3px,color:#92400e"," classDef success fill:#d1fae5,stroke:#10b981,stroke-width:3px,color:#065f46"," classDef error fill:#fee2e2,stroke:#ef4444,stroke-width:3px,color:#991b1b"," classDef aborted fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#4b5563,stroke-dasharray: 5 5"," classDef cached fill:#dbeafe,stroke:#3b82f6,stroke-width:3px,color:#1e40af"," classDef skipped fill:#f9fafb,stroke:#d1d5db,stroke-width:2px,color:#6b7280,stroke-dasharray: 5 5"," classDef stream fill:#ede9fe,stroke:#8b5cf6,stroke-width:3px,color:#5b21b6"," classDef streamActive fill:#ddd6fe,stroke:#7c3aed,stroke-width:3px,color:#4c1d95"," classDef streamError fill:#fce7f3,stroke:#db2777,stroke-width:3px,color:#9d174d"]}function Bt(){return[" classDef heat_cold fill:#dbeafe,stroke:#3b82f6,stroke-width:2px,color:#1e40af"," classDef heat_cool fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#0f766e"," classDef heat_neutral fill:#f3f4f6,stroke:#6b7280,stroke-width:2px,color:#374151"," classDef heat_warm fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#92400e"," classDef heat_hot fill:#fed7aa,stroke:#f97316,stroke-width:3px,color:#c2410c"," classDef heat_critical fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#b91c1c"]}function Kt(e){return`heat_${e}`}function zt(){return[" classDef hook_success fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0c4a6e"," classDef hook_error fill:#fef2f2,stroke:#dc2626,stroke-width:2px,color:#7f1d1d"]}function Gt(e){try{return(0,Se.ok)(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return(0,Se.err)("STRINGIFY_ERROR")}}function Je(e){let t=Gt(e);return t.ok?t.value:"[unserializable]"}function jt(e,t,r){let o;if(e.shouldRun){let s="hook_shouldRun",n=e.shouldRun.state==="success"?"hook_success":"hook_error",i=e.shouldRun.state==="success"?"\u2699":"\u26A0",c=r.showTimings&&e.shouldRun.durationMs!==void 0?` ${H(e.shouldRun.durationMs)}`:"",l=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${s}[["${i} shouldRun${l}${c}"]]:::${n}`),o=s}if(e.onBeforeStart){let s="hook_beforeStart",n=e.onBeforeStart.state==="success"?"hook_success":"hook_error",i=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",c=r.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${H(e.onBeforeStart.durationMs)}`:"",l=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${s}[["${i} onBeforeStart${l}${c}"]]:::${n}`),o&&t.push(` ${o} --> ${s}`),o=s}return{lastHookId:o}}var qe=0,be=new Set,ye=new Set;function oe(e="node"){return`${e}_${++qe}`}function Vt(){qe=0,be.clear(),ye.clear()}function F(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function Ze(e){return F(e).replace(/[{}[\]()]/g,"")}function Ce(){return{name:"mermaid",supportsLive:!1,render(e,t){Vt();let r=[],o=t;r.push("flowchart TD");let s;e.hooks&&(s=jt(e.hooks,r,t).lastHookId);let n="start";r.push(` ${n}(("\u25B6 Start"))`),s&&r.push(` ${s} --> ${n}`);let i=n;for(let l of e.root.children){let u=xe(l,t,r,o,e.hooks);r.push(` ${i} --> ${u.entryId}`),i=u.exitId}if(["success","error","aborted"].includes(e.root.state)){let l="finish",u=e.root.state==="success"?"\u2713":e.root.state==="error"?"\u2717":"\u2298",d=e.root.state==="success"?"Done":e.root.state==="error"?"Failed":"Cancelled",g=`(("${u} ${d}"))`,m=e.root.state==="success"?":::success":e.root.state==="error"?":::error":":::aborted";r.push(` ${l}${g}${m}`),r.push(` ${i} --> ${l}`)}return r.push(""),r.push(...At()),o.showHeatmap&&r.push(...Bt()),e.hooks&&r.push(...zt()),r.join(`
|
|
3
|
+
`)}}}function xe(e,t,r,o,s){if(K(e))return Yt(e,t,r,o,s);if(X(e))return Xt(e,t,r,o,s);if(A(e))return Jt(e,t,r,o,s);if(J(e))return qt(e,t,r,o,s);if(Q(e))return Zt(e,t,r);let n=oe("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function Yt(e,t,r,o,s){let n=t,i=n.showRetryEdges??!0,c=n.showErrorEdges??!0,l=n.showTimeoutEdges??!0,u=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:oe("step");if(ye.has(u)){let x=2;for(;ye.has(`${u}_${x}`);)x++;u=`${u}_${x}`}ye.add(u);let d=e.name??e.key??"Step",g=t.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,m=F(g),f=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",k="";switch(e.state){case"success":k="\u2713 ";break;case"error":k="\u2717 ";break;case"cached":k="\u{1F4BE} ";break;case"running":k="\u23F3 ";break;case"skipped":k="\u2298 ";break}let b="";if(e.input!==void 0){let x=typeof e.input=="string"?F(e.input):F(Je(e.input).slice(0,20));b+=`\\nin: ${x}`}if(e.output!==void 0&&e.state==="success"){let x=typeof e.output=="string"?F(e.output):F(Je(e.output).slice(0,20));b+=`\\nout: ${x}`}let $="",I=e.key??e.id;if(s&&I&&s.onAfterStep.has(I)){let x=s.onAfterStep.get(I),T=x.state==="success"?"\u2699":"\u26A0",D=t.showTimings&&x.durationMs!==void 0?` ${H(x.durationMs)}`:"";$=`\\n${T} hook${D}`}let E=(k+m+b+$+f).trim(),y,C=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.key??"")??o.heatmapData.heat.get(e.name??"")??o.heatmapData.heat.get(e.id):void 0;if(C!==void 0){let x=we(C);y=Kt(x)}else y=e.state;let N;switch(e.state){case"error":N=`{{"${E}"}}`;break;case"cached":N=`[("${E}")]`;break;case"skipped":N=`["${E}"]`;break;default:N=`["${E}"]`}if(r.push(` ${u}${N}:::${y}`),i&&e.retryCount!==void 0&&e.retryCount>0){let x=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${u} -.->|"${x}"| ${u}`)}if(c&&e.state==="error"&&e.error!==void 0){let x=`ERR_${u}`,T=F(String(e.error)).slice(0,30);r.push(` ${x}{{"${T}"}}`),r.push(` ${u} -->|error| ${x}`),r.push(` style ${x} fill:#fee2e2,stroke:#dc2626`)}if(l&&e.timedOut){let x=`TO_${u}`,T=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${x}{{"\u23F1 Timeout ${T}"}}`),r.push(` ${u} -.->|timeout| ${x}`),r.push(` style ${x} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:u,exitId:u}}function Xt(e,t,r,o,s){let n=oe("parallel"),i=`${n}_fork`,c=`${n}_join`,l=Ze(e.name??"Parallel"),u=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let m=n,f=F(`${l}${u}`),k="operations not individually tracked",b=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${m}["${f}${b}\\n${k}"]:::${e.state}`),{entryId:m,exitId:m}}r.push(` subgraph ${n}["${l}${u}"]`),r.push(" direction TB"),r.push(` ${i}{"\u26A1 Fork"}`);let d=[];for(let m of e.children){let f=xe(m,t,r,o,s);r.push(` ${i} --> ${f.entryId}`),d.push(f.exitId)}r.push(` ${c}{"\u2713 Join"}`);for(let m of d)r.push(` ${m} --> ${c}`);r.push(" end");let g=e.state;return r.push(` class ${n} ${g}`),{entryId:i,exitId:c}}function Jt(e,t,r,o,s){let n=oe("race"),i=`${n}_start`,c=`${n}_end`,l=Ze(e.name??"Race");if(e.children.length===0){let m=n,f=F(l),k="operations not individually tracked",b=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"";return r.push(` ${m}["\u26A1 ${f}${b}\\n${k}"]:::${e.state}`),{entryId:m,exitId:m}}r.push(` subgraph ${n}["\u26A1 ${l}"]`),r.push(" direction TB"),r.push(` ${i}(("\u{1F3C1} Start"))`);let u=[],d;for(let m of e.children){let f=xe(m,t,r,o,s),k=e.winnerId===m.id;r.push(` ${i} --> ${f.entryId}`),k&&(d=f.exitId),u.push({exitId:f.exitId,isWinner:k})}r.push(` ${c}(("\u2713 First"))`);for(let{exitId:m,isWinner:f}of u)f&&d?r.push(` ${m} ==>|\u{1F3C6} Winner| ${c}`):e.winnerId?r.push(` ${m} -. cancelled .-> ${c}`):r.push(` ${m} --> ${c}`);r.push(" end");let g=e.state;return r.push(` class ${n} ${g}`),{entryId:i,exitId:c}}function qt(e,t,r,o,s){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:oe("decision");if(be.has(n)){let m=2;for(;be.has(`${n}_${m}`);)m++;n=`${n}_${m}`}be.add(n);let i=F(e.condition??"condition"),c=e.decisionValue!==void 0?` = ${F(String(e.decisionValue)).slice(0,30)}`:"",l=`${i}${c}`.trim();r.push(` ${n}{"${l}"}`);let u=[],d,g=new Set;for(let m of e.branches){let f=`${n}_${m.label.replace(/[^a-zA-Z0-9]/g,"_")}`;if(g.has(f)){let E=2;for(;g.has(`${f}_${E}`);)E++;f=`${f}_${E}`}g.add(f);let k=F(m.label),b=m.taken?`${k} \u2713`:`${k} skipped`,$=m.taken?":::success":":::skipped";r.push(` ${f}["${b}"]${$}`);let I=m.condition?`|${F(m.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${I} ${f}`),m.children.length>0){let E=f;for(let y of m.children){let C=xe(y,t,r,o,s);r.push(` ${E} --> ${C.entryId}`),E=C.exitId}u.push(E),m.taken&&(d=E)}else u.push(f),m.taken&&(d=f)}return d?{entryId:n,exitId:d}:{entryId:n,exitId:n}}function Zt(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${oe("")}`,s=`W:${e.writeCount} R:${e.readCount}`,n="";switch(e.streamState){case"active":n="\u27F3 ";break;case"closed":n="\u2713 ";break;case"error":n="\u2717 ";break}let i=t.showTimings&&e.durationMs!==void 0?` ${H(e.durationMs)}`:"",c=e.backpressureOccurred?"\\nbackpressure":"",l=`${n}stream:${F(e.namespace)}\\n${s}${c}${i}`,u;return e.streamState==="error"?u="streamError":e.streamState==="active"?u="streamActive":u="stream",r.push(` ${o}{{"${l}"}}:::${u}`),{entryId:o,exitId:o}}var W={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeDown:"\u252C",teeUp:"\u2534",teeRight:"\u251C",teeLeft:"\u2524",cross:"\u253C",arrowDown:"\u25BC",arrowUp:"\u25B2"},Qt={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},er="\x1B[0m";function tr(e,t){let r=[],o=[];for(let s=0;s<t;s++)r.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:r,colors:o,width:e,height:t}}function _(e,t,r,o,s){t>=0&&t<e.width&&r>=0&&r<e.height&&(e.cells[r][t]=o,s&&(e.colors[r][t]=s))}function tt(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function rr(e,t,r,o,s){_(e,t,r,W.topLeft);for(let n=1;n<o-1;n++)_(e,t+n,r,W.horizontal);_(e,t+o-1,r,W.topRight);for(let n=1;n<s-1;n++)_(e,t,r+n,W.vertical),_(e,t+o-1,r+n,W.vertical);_(e,t,r+s-1,W.bottomLeft);for(let n=1;n<o-1;n++)_(e,t+n,r+s-1,W.horizontal);_(e,t+o-1,r+s-1,W.bottomRight)}function Qe(e,t,r,o,s){let n=Y(o).split("");for(let i=0;i<n.length;i++)_(e,t+i,r,n[i],s)}function q(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let c=tt(e,t,i);c===W.horizontal?_(e,t,i,W.cross):(c===" "||c===W.vertical)&&_(e,t,i,W.vertical)}}function et(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let c=tt(e,i,t);c===W.vertical?_(e,i,t,W.cross):(c===" "||c===W.horizontal)&&_(e,i,t,W.horizontal)}}function te(e,t,r){_(e,t,r,W.arrowDown)}function nr(e){let t=[];for(let r=0;r<e.height;r++){let o="";for(let s=0;s<e.width;s++){let n=e.colors[r][s],i=e.cells[r][s];n?o+=n+i+er:o+=i}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
|
|
4
|
+
`)}var G=11,j=2,se=2,Re=3;function _e(e,t){if(e.length<=t)return[e];let r=e.split(" "),o=[],s="";for(let n of r)s?s.length+1+n.length<=t?s+=" "+n:(o.push(s),s=n):s=n;if(s&&o.push(s),o.length===0)for(let n=0;n<e.length;n+=t)o.push(e.slice(n,n+t));return o}function rt(e){switch(e){case"success":return"\u2713";case"error":return"\u2717";case"running":return"\u27F3";case"pending":return"\u25CB";case"aborted":case"skipped":return"\u2298";case"cached":return"\u21BA";default:return"\u25CB"}}function or(e,t,r){let o=t.showStartEnd??!0,s=t,n=Math.floor(r/2),i=[],c=0;if(o){let u=$e("start","start",["\u25B6 Start"],"success",n,c);i.push(u),c=u.bottomY+se}for(let u of e.root.children){let d=Ee(u,n,c,r-4,t,s);i.push(d.node),c=d.bottomY+se}if(o&&["success","error","aborted"].includes(e.root.state)){let u=e.root.state==="success"?"\u2713 Done":e.root.state==="error"?"\u2717 Failed":"\u2298 Cancelled",d=$e("end","end",[u],e.root.state,n,c);i.push(d),c=d.bottomY}return{nodes:i,totalHeight:c+2}}function $e(e,t,r,o,s,n){let i=Math.max(...r.map(d=>Y(d).length)),c=Math.max(G,i+j*2),l=r.length+2,u=s-Math.floor(c/2);return{id:e,type:t,label:r,state:o,x:u,y:n,width:c,height:l,centerX:s,bottomY:n+l-1}}function Ee(e,t,r,o,s,n){if(K(e))return sr(e,t,r,o,s,n);if(X(e)||A(e))return ar(e,t,r,o,s,n);if(J(e))return cr(e,t,r,o,s,n);if(Q(e))return ir(e,t,r,o,s,n);let i=$e(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function sr(e,t,r,o,s,n){let i=e.name??e.key??"step",c=rt(e.state),l=[],u=`${c} ${i}`;s.showKeys&&e.key&&e.name&&(u+=` [${e.key}]`);let d=Math.min(o-j*2,40);if(l.push(..._e(u,d)),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&l.push(`${e.retryCount}x retry`),e.timedOut&&l.push("timeout"),n?.showSparklines&&n.timingHistory){let I=n.timingHistory.get(e.key??"")??n.timingHistory.get(e.name??"")??n.timingHistory.get(e.id);I&&I.length>1&&l.push(ve(I,8))}let g=Math.max(...l.map(I=>Y(I).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b;if(n?.showHeatmap&&n.heatmapData){let I=e.key??e.name??e.id;b=n.heatmapData.heat.get(e.id)??n.heatmapData.heat.get(I)}let $={id:e.id,type:"step",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:b!==void 0?{heat:b}:void 0};return{node:$,bottomY:$.bottomY}}function ir(e,t,r,o,s,n){let i=`stream:${e.namespace}`,c=e.streamState==="active"?"\u27F3":e.streamState==="closed"?"\u2713":"\u2717",l=[],u=`${c} ${i}`,d=Math.min(o-j*2,40);l.push(..._e(u,d)),l.push(`W:${e.writeCount} R:${e.readCount}`),s.showTimings&&e.durationMs!==void 0&&l.push(`[${H(e.durationMs)}]`),e.backpressureOccurred&&l.push("backpressure");let g=Math.max(...l.map($=>Y($).length)),m=Math.max(G,g+j*2),f=l.length+2,k=t-Math.floor(m/2),b={id:e.id,type:"stream",label:l,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1,metadata:{streamState:e.streamState,backpressureOccurred:e.backpressureOccurred}};return{node:b,bottomY:b.bottomY}}function ar(e,t,r,o,s,n){let i=A(e),c=e.name??(i?"race":"parallel"),u=`${i?"\u26A1":"\u2AD8"} ${c}`;if(e.children.length===0){let T=[u,"(not tracked)"],D=$e(e.id,i?"race":"parallel",T,e.state,t,r);return{node:D,bottomY:D.bottomY}}let d=Math.floor((o-Re*(e.children.length-1))/e.children.length),g=[];for(let T of e.children){let D=We(T,Math.max(d,G),s,n);g.push(D.width)}let m=g.reduce((T,D)=>T+D,0)+Re*(e.children.length-1),f=m>o&&e.children.length>1,k=Math.max(G,u.length+j*2),b=3,$=t-Math.floor(k/2),I=r;I+=b,I+=1,I+=1;let E=[];if(f)for(let T=0;T<e.children.length;T++){let D=e.children[T],L=Ee(D,t,I,o,s,n);i&&A(e)&&e.winnerId===D.id&&(L.node.metadata={...L.node.metadata,isWinner:!0}),E.push(L.node),I=L.bottomY+se}else{let T=t-Math.floor(m/2);for(let D=0;D<e.children.length;D++){let L=e.children[D],R=T+Math.floor(g[D]/2),P=Ee(L,R,I,g[D],s,n);i&&A(e)&&e.winnerId===L.id&&(P.node.metadata={...P.node.metadata,isWinner:!0}),E.push(P.node),T+=g[D]+Re}}let y=Math.max(...E.map(T=>T.bottomY)),N=!f&&E.length>1?y+2:y;return{node:{id:e.id,type:i?"race":"parallel",label:[u],state:e.state,x:$,y:r,width:k,height:b,centerX:t,bottomY:N,children:E,metadata:{verticalLayout:f}},bottomY:N}}function cr(e,t,r,o,s,n){let i=e.name??"decision",c=e.condition?` (${e.condition.slice(0,20)})`:"",l=`\u25C7 ${i}${c}`,u=Math.min(o-j*2,40),d=_e(l,u),g=Math.max(...d.map(N=>Y(N).length)),m=Math.max(G,g+j*2),f=d.length+2,k=t-Math.floor(m/2),b=e.branches.find(N=>N.taken),$=b&&b.children.length>0?b:e.branches.find(N=>N.children.length>0);if(!$||$.children.length===0){let N={id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:r+f-1};return{node:N,bottomY:N.bottomY}}let I=r+f+se,E=[];for(let N of $.children){let x=Ee(N,t,I,o,s,n);E.push(x.node),I=x.bottomY+se}let y=E.length>0?E[E.length-1].bottomY:r+f-1;return{node:{id:e.id,type:"decision",label:d,state:e.state,x:k,y:r,width:m,height:f,centerX:t,bottomY:y,children:E},bottomY:y}}function We(e,t,r,o){if(K(e)){let s=e.name??e.key??"step",n=rt(e.state),i=1;r.showTimings&&e.durationMs!==void 0&&i++,e.retryCount&&e.retryCount>0&&i++,e.timedOut&&i++,o?.showSparklines&&(o.timingHistory?.has(e.key??"")||o.timingHistory?.has(e.name??"")||o.timingHistory?.has(e.id))&&i++;let c=`${n} ${s}`;r.showKeys&&e.key&&e.name&&(c+=` [${e.key}]`);let l=Math.min(t,Math.max(G,c.length+j*2)),u=i+2;return{width:l,height:u}}if(X(e)||A(e)){if(e.children.length===0)return{width:G+4,height:4};let s=Math.floor(t/e.children.length),n=0,i=0;for(let c of e.children){let l=We(c,s,r,o);n+=l.width,i=Math.max(i,l.height)}return n+=Re*(e.children.length-1),{width:Math.max(n,G),height:5+i+2}}if(J(e)){let s=e.branches.find(i=>i.taken),n=0;if(s)for(let i of s.children){let c=We(i,t,r,o);n+=c.height+se}return{width:Math.min(t,30),height:3+n}}if(Q(e)){let s=`stream:${e.namespace}`,n=2;r.showTimings&&e.durationMs!==void 0&&n++,e.backpressureOccurred&&n++;let i=Math.min(t,Math.max(G,s.length+j*2+4)),c=n+2;return{width:i,height:c}}return{width:G,height:3}}function ur(e,t,r){let o={...ee,...r.colors};for(let s=0;s<t.length;s++){let n=t[s],i=s===t.length-1;if(Me(e,n,o),!i){let c=t[s+1],l=n.centerX,u=n.bottomY+1,d=c.centerX,g=c.y-1;q(e,l,u,g-1),te(e,d,g)}}}function Me(e,t,r){let o=t.type!=="start",s=t.type!=="end"&&(!t.children||t.children.length===0);rr(e,t.x,t.y,t.width,t.height),o&&_(e,t.centerX,t.y,W.teeUp),(s||t.children&&t.children.length>0)&&_(e,t.centerX,t.y+t.height-1,W.teeDown);let n=t.width-j*2,i=fr(t,r);for(let c=0;c<t.label.length;c++){let l=t.label[c],u=t.x+1+Math.floor((n-Y(l).length)/2),d=t.y+1+c;Qe(e,u,d,l,i)}t.metadata?.isWinner&&Qe(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?lr(e,t,r):dr(e,t,r))}function lr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=t.centerX;if(t.metadata?.verticalLayout===!0){let c=o[0];q(e,n,s,c.y-2),te(e,c.centerX,c.y-1);for(let l=0;l<o.length;l++){let u=o[l];if(Me(e,u,r),l<o.length-1){let d=o[l+1];q(e,u.centerX,u.bottomY+1,d.y-2),te(e,d.centerX,d.y-1)}}return}if(o.length===1)q(e,n,s,o[0].y-2),te(e,o[0].centerX,o[0].y-1);else{let c=o.map(d=>d.centerX),l=Math.min(...c),u=Math.max(...c);q(e,n,s,s+1),et(e,s+1,l,u),_(e,n,s+1,W.teeUp);for(let d of o){let g=d.centerX;g===l?_(e,g,s+1,W.topLeft):g===u?_(e,g,s+1,W.topRight):g!==n&&_(e,g,s+1,W.teeDown),q(e,g,s+2,d.y-2),te(e,g,d.y-1)}}for(let c of o)Me(e,c,r);if(o.length>1){let c=o.map(f=>f.bottomY),l=Math.max(...c),u=l+1,d=o.map(f=>f.centerX),g=Math.min(...d),m=Math.max(...d);for(let f of o)f.bottomY<l&&q(e,f.centerX,f.bottomY+1,u-1);et(e,u,g,m);for(let f of o){let k=f.centerX;k===g?_(e,k,u,W.bottomLeft):k===m?_(e,k,u,W.bottomRight):_(e,k,u,W.teeUp)}_(e,t.centerX,u,W.teeDown),_(e,t.centerX,u+1,W.vertical)}}function dr(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=o[0];q(e,t.centerX,s,n.y-2),te(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let c=o[i];if(Me(e,c,r),i<o.length-1){let l=o[i+1];q(e,c.centerX,c.bottomY+1,l.y-2),te(e,l.centerX,l.y-1)}}}var pr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function fr(e,t){if(e.metadata?.heat!==void 0){let r=we(e.metadata.heat);return Qt[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?pr[e.metadata.streamState]||void 0:t[e.state]||void 0}function de(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:s}=or(e,t,r),n=tr(r,s);return ur(n,o,t),nr(n)}}}function mr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function gr(e){let t=[];function r(o){for(let s of o)if(K(s))t.push(s);else if(Ke(s))r(s.children);else if(X(s)||A(s))r(s.children);else if(J(s))for(let n of s.branches)n.taken&&r(n.children)}return r(e),t}function hr(e){let t={id:e.id,name:e.name??e.key??e.id,state:e.state};return e.key&&(t.key=e.key),e.durationMs!==void 0&&(t.durationMs=e.durationMs),e.startTs!==void 0&&(t.startTs=e.startTs),e.endTs!==void 0&&(t.endTs=e.endTs),e.retryCount!==void 0&&e.retryCount>0&&(t.retryCount=e.retryCount),e.timedOut&&(t.timedOut=!0,e.timeoutMs!==void 0&&(t.timeoutMs=e.timeoutMs)),e.error!==void 0&&(t.error=typeof e.error=="string"?e.error:String(e.error)),t}function kr(e){let t=0,r=0,o=0,s=0,n=0,i;for(let c of e)c.state==="success"&&t++,c.state==="error"&&r++,c.state==="cached"&&o++,c.state==="skipped"&&s++,c.retryCount!==void 0&&(n+=c.retryCount),c.durationMs!==void 0&&(!i||c.durationMs>i.durationMs)&&(i={name:c.name??c.key??c.id,durationMs:c.durationMs});return{totalSteps:e.length,successCount:t,errorCount:r,cacheHits:o,skippedCount:s,totalRetries:n,slowestStep:i}}function wr(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error!==void 0&&e.shouldRun.error!==null&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error!==void 0&&e.onBeforeStart.error!==null&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[r,o]of e.onAfterStep){let s={stepKey:r};o.durationMs!==void 0&&(s.durationMs=o.durationMs),o.error!==void 0&&o.error!==null&&(s.error=String(o.error)),t.onAfterStep.push(s)}}return t}function br(e,t){let r=e.root,o=gr(r.children),s=t.includeDiagram??!0,n=t.stripAnsiColors??!0,i={workflow:{id:r.workflowId,name:r.name,state:r.state,durationMs:r.durationMs,startedAt:r.startTs,completedAt:r.endTs},steps:o.map(hr),summary:kr(o)};if(e.hooks){let c=wr(e.hooks);Object.keys(c).length>0&&(i.hooks=c)}if(s){let u=((t.diagramFormat??"ascii")==="flowchart"?de():le()).render(e,t);n&&(u=mr(u)),i.diagram=u}return i}function Le(){return{name:"logger",supportsLive:!1,render(e,t){let o=br(e,t);return JSON.stringify(o)}}}var V=require("awaitly");var nt=St(require("pako"),1),yr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function Sr(e){let t;if(yr)t=globalThis.Buffer.from(e).toString("base64");else{let r="";for(let o=0;o<e.length;o++)r+=String.fromCharCode(e[o]);t=btoa(r)}return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ie(e){let r=new TextEncoder().encode(e),o=nt.default.deflate(r);return Sr(o)}var xr="https://kroki.io";function ot(e,t,r,o={}){let s=o.baseUrl??xr,n=Ie(r);return`${s}/${e}/${t}/${n}`}var Rr="https://mermaid.ink";function $r(e){return`pako:${Ie(e)}`}function Er(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 Mr(e,t){let r=[];return t.bgColor&&r.push(`bgColor=${encodeURIComponent(t.bgColor)}`),t.theme&&r.push(`theme=${t.theme}`),t.width!==void 0&&r.push(`width=${t.width}`),t.height!==void 0&&r.push(`height=${t.height}`),t.scale!==void 0&&(t.width!==void 0||t.height!==void 0)&&r.push(`scale=${t.scale}`),e==="img"&&t.imageType&&t.imageType!=="jpeg"&&r.push(`type=${t.imageType}`),e==="pdf"&&(t.fit&&r.push("fit"),t.paper&&!t.fit&&r.push(`paper=${t.paper}`),t.landscape&&!t.fit&&r.push("landscape")),r.length>0?`?${r.join("&")}`:""}function st(e,t,r={}){let o=Er(r),s=o.baseUrl??Rr,n=$r(t),i=Mr(e,o);return`${s}/${e}/${n}${i}`}function Ir(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?(0,V.ok)(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?(0,V.err)("UNSUPPORTED_FORMAT"):(0,V.ok)(void 0):(0,V.err)("UNSUPPORTED_FORMAT")}function Nr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function Or(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function Ne(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return(0,V.err)("UNSUPPORTED_DIAGRAM_KIND")}}let s=Ir(r.provider,e.kind,t);if(!s.ok)return s;switch(r.provider){case"kroki":return(0,V.ok)(ot(Nr(e.kind),t,e.source,r));case"mermaid-ink":return(0,V.ok)(st(Or(t),e.source,r));default:{let n=r;return(0,V.err)("UNKNOWN_PROVIDER")}}}function it(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:s=!1,colors:n,export:i}=e,c=Be({detectParallel:r}),l=new Set,u,d=le(),g=Ce(),m=Le(),f=de(),k={showTimings:o,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...ee,...n}};function b(){if(l.size>0){let S=y();for(let M of l)M(S)}}function $(S){if(S.type==="scope_start"||S.type==="scope_end"){I(S);return}c.handleEvent(S),"workflowName"in S&&typeof S.workflowName=="string"&&(u=S.workflowName),b()}function I(S){c.handleScopeEvent(S),b()}function E(S){c.handleDecisionEvent(S),b()}function y(){let S=c.getIR(),M=t??u??S.root.name;return M&&(S.root.name=M),S}function C(){let S=y();return d.render(S,k)}function N(S){let M=y();switch(S){case"ascii":return d.render(M,k);case"mermaid":return g.render(M,k);case"json":{let ie=M.hooks?{...M,hooks:{...M.hooks,onAfterStep:M.hooks.onAfterStep instanceof Map?Object.fromEntries(M.hooks.onAfterStep):M.hooks.onAfterStep??{}}}:M;return JSON.stringify(ie,(He,ae)=>typeof ae=="bigint"?ae.toString():ae,2)}case"logger":return m.render(M,k);case"flowchart":return f.render(M,k);default:throw new Error(`Unknown format: ${S}`)}}function x(){c.reset(),b()}function T(S){return l.add(S),()=>l.delete(S)}function D(S,M){if(S)return S;if(i?.default)return i.default;throw new Error(`${M}(): No export provider configured. Pass { provider: 'kroki' } or { provider: 'mermaid-ink' }, or set export.default in createVisualizer().`)}function L(){let S=y();return{kind:"mermaid",source:g.render(S,k)}}function R(S){let M=Ne(L(),"svg",D(S,"toSvgUrl"),{caller:"toSvgUrl"});if(!M.ok)throw new Error(`toSvgUrl: Export failed - ${M.error}`);return M.value}function P(S){let M=Ne(L(),"png",D(S,"toPngUrl"),{caller:"toPngUrl"});if(!M.ok)throw new Error(`toPngUrl: Export failed - ${M.error}`);return M.value}function Z(S){let M=Ne(L(),"pdf",D(S,"toPdfUrl"),{caller:"toPdfUrl"});if(!M.ok)throw new Error(`toPdfUrl: Export failed - ${M.error}`);return M.value}function re(S,M){switch(S){case"svg":return R(M);case"png":return P(M);case"pdf":return Z(M);default:return S}}return{handleEvent:$,handleScopeEvent:I,handleDecisionEvent:E,getIR:y,render:C,renderAs:N,reset:x,onUpdate:T,toUrl:re,toSvgUrl:R,toPngUrl:P,toPdfUrl:Z}}function Pe(e={}){let{logEvents:t=!1,maxHistory:r=10,logger:o=console.log}=e,s=it(e),n=[],i,c=0;function l(R){if(i)for(n.push(i);n.length>r;)n.shift();c=Date.now(),i={id:R,name:e.workflowName,startTime:c,events:[]},s.reset()}function u(R,P){i&&(i.endTime=Date.now(),i.durationMs=i.endTime-i.startTime,i.success=R,i.error=P)}function d(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),R.type==="workflow_start"&&l(R.workflowId),i&&i.events.push(R),s.handleEvent(R),R.type==="workflow_success"?u(!0):R.type==="workflow_error"&&u(!1,R.error)}function g(R){t&&o(`[devtools] ${R.type}: ${JSON.stringify(R)}`),i&&i.events.push(R),s.handleDecisionEvent(R)}function m(){return i}function f(){return[...n]}function k(R){return i?.id===R?i:n.find(P=>P.id===R)}function b(R,P){let Z=k(R),re=k(P);if(!(!Z||!re))return at(Z,re)}function $(){if(!i||n.length===0)return;let R=n[n.length-1];return at(R,i)}function I(){return s.render()}function E(R){return s.renderAs(R)}function y(){return s.renderAs("mermaid")}function C(){let R=N();return vr(R)}function N(){return i?Dr(i.events,c):[]}function x(){n.length=0}function T(){i=void 0,s.reset()}function D(R){let P=R?k(R):i;return P?JSON.stringify(P,null,2):"{}"}function L(R){let P=JSON.parse(R);return n.push(P),P}return{handleEvent:d,handleDecisionEvent:g,getCurrentRun:m,getHistory:f,getRun:k,diff:b,diffWithPrevious:$,render:I,renderAs:E,renderMermaid:y,renderTimeline:C,getTimeline:N,clearHistory:x,reset:T,exportRun:D,importRun:L}}function at(e,t){let r=ct(e.events),o=ct(t.events),s=[],n=[],i=[],c=[];for(let[m,f]of o){let k=r.get(m);k?k.status!==f.status?i.push({step:m,type:"status",from:k.status,to:f.status}):k.durationMs!==f.durationMs?i.push({step:m,type:"duration",from:k.durationMs,to:f.durationMs}):c.push(m):s.push({step:m,type:"added",to:f.status})}for(let[m]of r)o.has(m)||n.push({step:m,type:"removed",from:r.get(m)?.status});let l,u=e.success===void 0?"running":e.success?"success":"error",d=t.success===void 0?"running":t.success?"success":"error";u!==d&&(l={from:u,to:d});let g;return e.durationMs!==void 0&&t.durationMs!==void 0&&(g=t.durationMs-e.durationMs),{added:s,removed:n,changed:i,unchanged:c,statusChange:l,durationChange:g}}function ct(e){let t=new Map;for(let r of e)if(r.type==="step_start"){let o=r,s=o.name||o.stepKey||o.stepId;t.set(s,{name:s,key:o.stepKey,status:"running"})}else if(r.type==="step_success"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="success",n.durationMs=o.durationMs)}else if(r.type==="step_error"){let o=r,s=o.name||o.stepKey||o.stepId,n=t.get(s);n&&(n.status="error",n.durationMs=o.durationMs,n.error=o.error)}else if(r.type==="step_cache_hit"){let o=r,s=o.name||o.stepKey;t.set(s,{name:s,key:o.stepKey,status:"cached"})}else if(r.type==="step_skipped"){let o=r,s=o.name||o.stepKey||"unknown";t.set(s,{name:s,key:o.stepKey,status:"skipped"})}return t}function Dr(e,t){let r=[],o=new Map;for(let s of e)if(s.type==="step_start"){let n=s,i=n.name||n.stepKey||n.stepId;o.set(i,n.ts),r.push({name:i,key:n.stepKey,startMs:n.ts-t,status:"running"})}else if(s.type==="step_success"){let n=s,i=n.name||n.stepKey||n.stepId,c=r.find(l=>l.name===i&&l.status==="running");c&&(c.endMs=n.ts-t,c.durationMs=n.durationMs,c.status="success")}else if(s.type==="step_error"){let n=s,i=n.name||n.stepKey||n.stepId,c=r.find(l=>l.name===i&&l.status==="running");c&&(c.endMs=n.ts-t,c.durationMs=n.durationMs,c.status="error",c.error=n.error)}else if(s.type==="step_cache_hit"){let n=s,i=n.name||n.stepKey;r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"cached"})}else if(s.type==="step_skipped"){let n=s,i=n.name||n.stepKey||"unknown";r.push({name:i,key:n.stepKey,startMs:n.ts-t,endMs:n.ts-t,durationMs:0,status:"skipped"})}return r}function vr(e){if(e.length===0)return"No timeline data";let t=[];t.push("Timeline:"),t.push("\u2500".repeat(60));let r=Math.max(...e.map(s=>s.endMs??s.startMs+100)),o=40;for(let s of e){let n=Math.floor(s.startMs/r*o),i=Math.floor((s.endMs??s.startMs+10)/r*o),c=Math.max(1,i-n),l=Tr(s.status),u=" ".repeat(n)+l.repeat(c),d=s.durationMs!==void 0?`${s.durationMs}ms`:"?";t.push(`${s.name.padEnd(20)} |${u.padEnd(o)}| ${d}`)}return t.push("\u2500".repeat(60)),t.join(`
|
|
5
|
+
`)}function Tr(e){switch(e){case"success":return"\u2588";case"error":return"\u2591";case"running":return"\u2592";case"cached":return"\u2593";case"skipped":return"\xB7";default:return"?"}}function ut(e){let t=[];if(e.statusChange&&t.push(`Status: ${e.statusChange.from} \u2192 ${e.statusChange.to}`),e.durationChange!==void 0){let r=e.durationChange>=0?"+":"";t.push(`Duration: ${r}${e.durationChange}ms`)}if(e.added.length>0){t.push(`
|
|
6
6
|
Added steps:`);for(let r of e.added)t.push(` + ${r.step}`)}if(e.removed.length>0){t.push(`
|
|
7
7
|
Removed steps:`);for(let r of e.removed)t.push(` - ${r.step}`)}if(e.changed.length>0){t.push(`
|
|
8
8
|
Changed steps:`);for(let r of e.changed)t.push(` ~ ${r.step}: ${r.from} \u2192 ${r.to}`)}return e.unchanged.length>0&&t.push(`
|
|
9
9
|
Unchanged: ${e.unchanged.length} steps`),t.join(`
|
|
10
|
-
`)}function
|
|
10
|
+
`)}function lt(e,t={}){let r=Pe(t);return e(r.handleEvent).then(()=>r.render())}function dt(e={}){let{prefix:t="[workflow]",colors:r=!0}=e,o=r?{reset:"\x1B[0m",dim:"\x1B[2m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"}:{reset:"",dim:"",green:"",red:"",yellow:"",blue:"",cyan:""};return s=>{let n=new Date().toISOString().slice(11,23),i;switch(s.type){case"workflow_start":i=`${o.blue}\u23F5 Workflow started${o.reset}`;break;case"workflow_success":i=`${o.green}\u2713 Workflow completed${o.reset} ${o.dim}(${s.durationMs}ms)${o.reset}`;break;case"workflow_error":i=`${o.red}\u2717 Workflow failed${o.reset}`;break;case"step_start":i=`${o.cyan}\u2192 ${s.name||s.stepKey||s.stepId}${o.reset}`;break;case"step_success":i=`${o.green}\u2713 ${s.name||s.stepKey||s.stepId}${o.reset} ${o.dim}(${s.durationMs}ms)${o.reset}`;break;case"step_error":i=`${o.red}\u2717 ${s.name||s.stepKey||s.stepId}${o.reset}`;break;case"step_cache_hit":i=`${o.yellow}\u26A1 ${s.name||s.stepKey} (cached)${o.reset}`;break;case"step_retry":i=`${o.yellow}\u21BB ${s.name||s.stepKey||s.stepId} retry ${s.attempt}/${s.maxAttempts}${o.reset}`;break;default:i=`${o.dim}${s.type}${o.reset}`}console.log(`${o.dim}${n}${o.reset} ${t} ${i}`)}}0&&(module.exports={createConsoleLogger,createDevtools,quickVisualize,renderDiff});
|
|
11
11
|
//# sourceMappingURL=devtools.cjs.map
|