awaitly-visualizer 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/devtools.cjs +11 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +181 -0
- package/dist/devtools.d.ts +181 -0
- package/dist/devtools.js +11 -0
- package/dist/devtools.js.map +1 -0
- package/dist/index.browser.d.cts +4 -4
- package/dist/index.browser.d.ts +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/kroki/fetch.d.cts +1 -1
- package/dist/kroki/fetch.d.ts +1 -1
- package/dist/notifiers/discord.d.cts +2 -2
- package/dist/notifiers/discord.d.ts +2 -2
- package/dist/notifiers/slack.d.cts +2 -2
- package/dist/notifiers/slack.d.ts +2 -2
- package/dist/notifiers/webhook.d.cts +2 -2
- package/dist/notifiers/webhook.d.ts +2 -2
- package/dist/{performance-analyzer-BNwE4AiO.d.cts → performance-analyzer-BtXTMIuL.d.cts} +2 -2
- package/dist/{performance-analyzer-B5VF5b1F.d.ts → performance-analyzer-DH1C_5pd.d.ts} +2 -2
- package/dist/{types-BnWc9Wlr.d.cts → types-CgO2me2s.d.cts} +1 -1
- package/dist/{types-BIZSmXif.d.ts → types-fuxEig2j.d.ts} +1 -1
- package/dist/{url-PkfQz4V5.d.cts → url-BskfOf3W.d.cts} +1 -1
- package/dist/{url-PkfQz4V5.d.ts → url-BskfOf3W.d.ts} +1 -1
- package/package.json +12 -3
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { WorkflowEvent } from 'awaitly/workflow';
|
|
2
|
+
import { D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, O as OutputFormat, V as VisualizerOptions } from './url-BskfOf3W.cjs';
|
|
3
|
+
import { CollectableEvent } from './index.cjs';
|
|
4
|
+
import 'awaitly/core';
|
|
5
|
+
import './performance-analyzer-BtXTMIuL.cjs';
|
|
6
|
+
import './types-CgO2me2s.cjs';
|
|
7
|
+
import 'awaitly';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* awaitly/devtools
|
|
11
|
+
*
|
|
12
|
+
* Developer tools for workflow debugging, visualization, and analysis.
|
|
13
|
+
* Provides timeline rendering, run diffing, and live visualization.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A recorded workflow run with events and metadata.
|
|
18
|
+
*/
|
|
19
|
+
interface WorkflowRun {
|
|
20
|
+
/** Unique identifier for this run */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Workflow name */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** Start timestamp */
|
|
25
|
+
startTime: number;
|
|
26
|
+
/** End timestamp (undefined if still running) */
|
|
27
|
+
endTime?: number;
|
|
28
|
+
/** Duration in milliseconds */
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
/** Whether the workflow succeeded */
|
|
31
|
+
success?: boolean;
|
|
32
|
+
/** Error if the workflow failed */
|
|
33
|
+
error?: unknown;
|
|
34
|
+
/** All events from this run */
|
|
35
|
+
events: CollectableEvent[];
|
|
36
|
+
/** Custom metadata */
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Difference between two workflow runs.
|
|
41
|
+
*/
|
|
42
|
+
interface RunDiff {
|
|
43
|
+
/** Steps that were added in the new run */
|
|
44
|
+
added: StepDiff[];
|
|
45
|
+
/** Steps that were removed from the new run */
|
|
46
|
+
removed: StepDiff[];
|
|
47
|
+
/** Steps that changed between runs */
|
|
48
|
+
changed: StepDiff[];
|
|
49
|
+
/** Steps that are identical */
|
|
50
|
+
unchanged: string[];
|
|
51
|
+
/** Overall status change */
|
|
52
|
+
statusChange?: {
|
|
53
|
+
from: "success" | "error" | "running";
|
|
54
|
+
to: "success" | "error" | "running";
|
|
55
|
+
};
|
|
56
|
+
/** Duration change in milliseconds */
|
|
57
|
+
durationChange?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Information about a step difference.
|
|
61
|
+
*/
|
|
62
|
+
interface StepDiff {
|
|
63
|
+
/** Step name or key */
|
|
64
|
+
step: string;
|
|
65
|
+
/** Type of change */
|
|
66
|
+
type: "added" | "removed" | "status" | "duration" | "error";
|
|
67
|
+
/** Previous value (for changes) */
|
|
68
|
+
from?: unknown;
|
|
69
|
+
/** New value (for changes) */
|
|
70
|
+
to?: unknown;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Timeline entry for a step.
|
|
74
|
+
*/
|
|
75
|
+
interface TimelineEntry {
|
|
76
|
+
/** Step name */
|
|
77
|
+
name: string;
|
|
78
|
+
/** Step key (if any) */
|
|
79
|
+
key?: string;
|
|
80
|
+
/** Start time (relative to workflow start) */
|
|
81
|
+
startMs: number;
|
|
82
|
+
/** End time (relative to workflow start) */
|
|
83
|
+
endMs?: number;
|
|
84
|
+
/** Duration in milliseconds */
|
|
85
|
+
durationMs?: number;
|
|
86
|
+
/** Step status */
|
|
87
|
+
status: "pending" | "running" | "success" | "error" | "skipped" | "cached";
|
|
88
|
+
/** Error if failed */
|
|
89
|
+
error?: unknown;
|
|
90
|
+
/** Parent scope (for nested steps) */
|
|
91
|
+
parent?: string;
|
|
92
|
+
/** Retry attempt number */
|
|
93
|
+
attempt?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Devtools configuration options.
|
|
97
|
+
*/
|
|
98
|
+
interface DevtoolsOptions extends VisualizerOptions {
|
|
99
|
+
/** Enable console logging of events */
|
|
100
|
+
logEvents?: boolean;
|
|
101
|
+
/** Maximum number of runs to keep in history */
|
|
102
|
+
maxHistory?: number;
|
|
103
|
+
/** Custom logger function */
|
|
104
|
+
logger?: (message: string) => void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Devtools instance for workflow debugging.
|
|
108
|
+
*/
|
|
109
|
+
interface Devtools {
|
|
110
|
+
/** Handle a workflow event */
|
|
111
|
+
handleEvent: (event: WorkflowEvent<unknown>) => void;
|
|
112
|
+
/** Handle a decision event */
|
|
113
|
+
handleDecisionEvent: (event: DecisionStartEvent | DecisionBranchEvent | DecisionEndEvent) => void;
|
|
114
|
+
/** Get the current run */
|
|
115
|
+
getCurrentRun: () => WorkflowRun | undefined;
|
|
116
|
+
/** Get run history */
|
|
117
|
+
getHistory: () => WorkflowRun[];
|
|
118
|
+
/** Get a specific run by ID */
|
|
119
|
+
getRun: (id: string) => WorkflowRun | undefined;
|
|
120
|
+
/** Compare two runs */
|
|
121
|
+
diff: (runId1: string, runId2: string) => RunDiff | undefined;
|
|
122
|
+
/** Compare current run with a previous run */
|
|
123
|
+
diffWithPrevious: () => RunDiff | undefined;
|
|
124
|
+
/** Render current state */
|
|
125
|
+
render: () => string;
|
|
126
|
+
/** Render to a specific format */
|
|
127
|
+
renderAs: (format: OutputFormat) => string;
|
|
128
|
+
/** Render as Mermaid diagram */
|
|
129
|
+
renderMermaid: () => string;
|
|
130
|
+
/** Render as ASCII timeline */
|
|
131
|
+
renderTimeline: () => string;
|
|
132
|
+
/** Get timeline data for current run */
|
|
133
|
+
getTimeline: () => TimelineEntry[];
|
|
134
|
+
/** Clear all history */
|
|
135
|
+
clearHistory: () => void;
|
|
136
|
+
/** Reset current run */
|
|
137
|
+
reset: () => void;
|
|
138
|
+
/** Export run data as JSON */
|
|
139
|
+
exportRun: (runId?: string) => string;
|
|
140
|
+
/** Import run data from JSON */
|
|
141
|
+
importRun: (json: string) => WorkflowRun;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a devtools instance for workflow debugging.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const devtools = createDevtools({ workflowName: 'checkout' });
|
|
149
|
+
*
|
|
150
|
+
* const workflow = createWorkflow(deps, {
|
|
151
|
+
* onEvent: devtools.handleEvent,
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* await workflow(async (step) => { ... });
|
|
155
|
+
*
|
|
156
|
+
* // Visualize
|
|
157
|
+
* console.log(devtools.render());
|
|
158
|
+
* console.log(devtools.renderMermaid());
|
|
159
|
+
*
|
|
160
|
+
* // Compare with previous run
|
|
161
|
+
* const diff = devtools.diffWithPrevious();
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function createDevtools(options?: DevtoolsOptions): Devtools;
|
|
165
|
+
/**
|
|
166
|
+
* Render a run diff as a string.
|
|
167
|
+
*/
|
|
168
|
+
declare function renderDiff(diff: RunDiff): string;
|
|
169
|
+
/**
|
|
170
|
+
* Quick visualization helper for a single workflow run.
|
|
171
|
+
*/
|
|
172
|
+
declare function quickVisualize(workflowFn: (handleEvent: (event: WorkflowEvent<unknown>) => void) => Promise<unknown>, options?: DevtoolsOptions): Promise<string>;
|
|
173
|
+
/**
|
|
174
|
+
* Create an event handler that logs to console with pretty formatting.
|
|
175
|
+
*/
|
|
176
|
+
declare function createConsoleLogger(options?: {
|
|
177
|
+
prefix?: string;
|
|
178
|
+
colors?: boolean;
|
|
179
|
+
}): (event: WorkflowEvent<unknown>) => void;
|
|
180
|
+
|
|
181
|
+
export { type Devtools, type DevtoolsOptions, type RunDiff, type StepDiff, type TimelineEntry, type WorkflowRun, createConsoleLogger, createDevtools, quickVisualize, renderDiff };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { WorkflowEvent } from 'awaitly/workflow';
|
|
2
|
+
import { D as DecisionStartEvent, a as DecisionBranchEvent, b as DecisionEndEvent, O as OutputFormat, V as VisualizerOptions } from './url-BskfOf3W.js';
|
|
3
|
+
import { CollectableEvent } from './index.js';
|
|
4
|
+
import 'awaitly/core';
|
|
5
|
+
import './performance-analyzer-DH1C_5pd.js';
|
|
6
|
+
import './types-fuxEig2j.js';
|
|
7
|
+
import 'awaitly';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* awaitly/devtools
|
|
11
|
+
*
|
|
12
|
+
* Developer tools for workflow debugging, visualization, and analysis.
|
|
13
|
+
* Provides timeline rendering, run diffing, and live visualization.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A recorded workflow run with events and metadata.
|
|
18
|
+
*/
|
|
19
|
+
interface WorkflowRun {
|
|
20
|
+
/** Unique identifier for this run */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Workflow name */
|
|
23
|
+
name?: string;
|
|
24
|
+
/** Start timestamp */
|
|
25
|
+
startTime: number;
|
|
26
|
+
/** End timestamp (undefined if still running) */
|
|
27
|
+
endTime?: number;
|
|
28
|
+
/** Duration in milliseconds */
|
|
29
|
+
durationMs?: number;
|
|
30
|
+
/** Whether the workflow succeeded */
|
|
31
|
+
success?: boolean;
|
|
32
|
+
/** Error if the workflow failed */
|
|
33
|
+
error?: unknown;
|
|
34
|
+
/** All events from this run */
|
|
35
|
+
events: CollectableEvent[];
|
|
36
|
+
/** Custom metadata */
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Difference between two workflow runs.
|
|
41
|
+
*/
|
|
42
|
+
interface RunDiff {
|
|
43
|
+
/** Steps that were added in the new run */
|
|
44
|
+
added: StepDiff[];
|
|
45
|
+
/** Steps that were removed from the new run */
|
|
46
|
+
removed: StepDiff[];
|
|
47
|
+
/** Steps that changed between runs */
|
|
48
|
+
changed: StepDiff[];
|
|
49
|
+
/** Steps that are identical */
|
|
50
|
+
unchanged: string[];
|
|
51
|
+
/** Overall status change */
|
|
52
|
+
statusChange?: {
|
|
53
|
+
from: "success" | "error" | "running";
|
|
54
|
+
to: "success" | "error" | "running";
|
|
55
|
+
};
|
|
56
|
+
/** Duration change in milliseconds */
|
|
57
|
+
durationChange?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Information about a step difference.
|
|
61
|
+
*/
|
|
62
|
+
interface StepDiff {
|
|
63
|
+
/** Step name or key */
|
|
64
|
+
step: string;
|
|
65
|
+
/** Type of change */
|
|
66
|
+
type: "added" | "removed" | "status" | "duration" | "error";
|
|
67
|
+
/** Previous value (for changes) */
|
|
68
|
+
from?: unknown;
|
|
69
|
+
/** New value (for changes) */
|
|
70
|
+
to?: unknown;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Timeline entry for a step.
|
|
74
|
+
*/
|
|
75
|
+
interface TimelineEntry {
|
|
76
|
+
/** Step name */
|
|
77
|
+
name: string;
|
|
78
|
+
/** Step key (if any) */
|
|
79
|
+
key?: string;
|
|
80
|
+
/** Start time (relative to workflow start) */
|
|
81
|
+
startMs: number;
|
|
82
|
+
/** End time (relative to workflow start) */
|
|
83
|
+
endMs?: number;
|
|
84
|
+
/** Duration in milliseconds */
|
|
85
|
+
durationMs?: number;
|
|
86
|
+
/** Step status */
|
|
87
|
+
status: "pending" | "running" | "success" | "error" | "skipped" | "cached";
|
|
88
|
+
/** Error if failed */
|
|
89
|
+
error?: unknown;
|
|
90
|
+
/** Parent scope (for nested steps) */
|
|
91
|
+
parent?: string;
|
|
92
|
+
/** Retry attempt number */
|
|
93
|
+
attempt?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Devtools configuration options.
|
|
97
|
+
*/
|
|
98
|
+
interface DevtoolsOptions extends VisualizerOptions {
|
|
99
|
+
/** Enable console logging of events */
|
|
100
|
+
logEvents?: boolean;
|
|
101
|
+
/** Maximum number of runs to keep in history */
|
|
102
|
+
maxHistory?: number;
|
|
103
|
+
/** Custom logger function */
|
|
104
|
+
logger?: (message: string) => void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Devtools instance for workflow debugging.
|
|
108
|
+
*/
|
|
109
|
+
interface Devtools {
|
|
110
|
+
/** Handle a workflow event */
|
|
111
|
+
handleEvent: (event: WorkflowEvent<unknown>) => void;
|
|
112
|
+
/** Handle a decision event */
|
|
113
|
+
handleDecisionEvent: (event: DecisionStartEvent | DecisionBranchEvent | DecisionEndEvent) => void;
|
|
114
|
+
/** Get the current run */
|
|
115
|
+
getCurrentRun: () => WorkflowRun | undefined;
|
|
116
|
+
/** Get run history */
|
|
117
|
+
getHistory: () => WorkflowRun[];
|
|
118
|
+
/** Get a specific run by ID */
|
|
119
|
+
getRun: (id: string) => WorkflowRun | undefined;
|
|
120
|
+
/** Compare two runs */
|
|
121
|
+
diff: (runId1: string, runId2: string) => RunDiff | undefined;
|
|
122
|
+
/** Compare current run with a previous run */
|
|
123
|
+
diffWithPrevious: () => RunDiff | undefined;
|
|
124
|
+
/** Render current state */
|
|
125
|
+
render: () => string;
|
|
126
|
+
/** Render to a specific format */
|
|
127
|
+
renderAs: (format: OutputFormat) => string;
|
|
128
|
+
/** Render as Mermaid diagram */
|
|
129
|
+
renderMermaid: () => string;
|
|
130
|
+
/** Render as ASCII timeline */
|
|
131
|
+
renderTimeline: () => string;
|
|
132
|
+
/** Get timeline data for current run */
|
|
133
|
+
getTimeline: () => TimelineEntry[];
|
|
134
|
+
/** Clear all history */
|
|
135
|
+
clearHistory: () => void;
|
|
136
|
+
/** Reset current run */
|
|
137
|
+
reset: () => void;
|
|
138
|
+
/** Export run data as JSON */
|
|
139
|
+
exportRun: (runId?: string) => string;
|
|
140
|
+
/** Import run data from JSON */
|
|
141
|
+
importRun: (json: string) => WorkflowRun;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a devtools instance for workflow debugging.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const devtools = createDevtools({ workflowName: 'checkout' });
|
|
149
|
+
*
|
|
150
|
+
* const workflow = createWorkflow(deps, {
|
|
151
|
+
* onEvent: devtools.handleEvent,
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* await workflow(async (step) => { ... });
|
|
155
|
+
*
|
|
156
|
+
* // Visualize
|
|
157
|
+
* console.log(devtools.render());
|
|
158
|
+
* console.log(devtools.renderMermaid());
|
|
159
|
+
*
|
|
160
|
+
* // Compare with previous run
|
|
161
|
+
* const diff = devtools.diffWithPrevious();
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function createDevtools(options?: DevtoolsOptions): Devtools;
|
|
165
|
+
/**
|
|
166
|
+
* Render a run diff as a string.
|
|
167
|
+
*/
|
|
168
|
+
declare function renderDiff(diff: RunDiff): string;
|
|
169
|
+
/**
|
|
170
|
+
* Quick visualization helper for a single workflow run.
|
|
171
|
+
*/
|
|
172
|
+
declare function quickVisualize(workflowFn: (handleEvent: (event: WorkflowEvent<unknown>) => void) => Promise<unknown>, options?: DevtoolsOptions): Promise<string>;
|
|
173
|
+
/**
|
|
174
|
+
* Create an event handler that logs to console with pretty formatting.
|
|
175
|
+
*/
|
|
176
|
+
declare function createConsoleLogger(options?: {
|
|
177
|
+
prefix?: string;
|
|
178
|
+
colors?: boolean;
|
|
179
|
+
}): (event: WorkflowEvent<unknown>) => void;
|
|
180
|
+
|
|
181
|
+
export { type Devtools, type DevtoolsOptions, type RunDiff, type StepDiff, type TimelineEntry, type WorkflowRun, createConsoleLogger, createDevtools, quickVisualize, renderDiff };
|
package/dist/devtools.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function H(e){if(e<1e3)return`${Math.round(e)}ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,"")}s`;let t=Math.floor(e/6e4),r=Math.round(e%6e4/1e3);return r>=60&&(t+=1,r=0),r===0?`${t}m`:`${t}m ${r}s`}function pe(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function ct(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 Le(e,t={}){if(ct(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:ut(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 ut(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 Pe(e={}){let{detectParallel:t=!0,parallelDetection:r,enableSnapshots:o=!1,maxSnapshots:s=1e3}=e,n=o,i=pe(),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??pe()}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=Me(),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:pe(),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 ee(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,at={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(at),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 Me(){let a=le();t&&(a=Le(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 _e(){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 oe(){return[...R]}function ot(a){return R[a]}function st(a){return R[a]?.ir}function it(){R.length=0,v=0}return{handleEvent:P,handleScopeEvent:ee,handleDecisionEvent:x,getIR:Me,reset:_e,getSnapshots:oe,getSnapshotAt:ot,getIRAt:st,clearSnapshots:it,get hasActiveSteps(){return f.size>0},get state(){return d},get snapshotCount(){return R.length},get snapshotsEnabled(){return n},setSnapshotsEnabled(a){n=a}}}import{ok as kt,err as wt}from"awaitly";function K(e){return e.type==="step"}function Ue(e){return e.type==="sequence"}function Y(e){return e.type==="parallel"}function F(e){return e.type==="race"}function X(e){return e.type==="decision"}function q(e){return e.type==="stream"}var Ie="\x1B[0m",lt="\x1B[1m",Ae="\x1B[2m",dt="\x1B[31m",pt="\x1B[32m",ft="\x1B[33m",mt="\x1B[34m",He="\x1B[90m",gt="\x1B[37m";function z(e,t){return t?`${t}${e}${Ie}`:e}function se(e){return`${lt}${e}${Ie}`}function N(e){return`${Ae}${e}${Ie}`}var Z={pending:gt,running:ft,success:pt,error:dt,aborted:He,cached:mt,skipped:Ae+He};function ht(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 ie(e,t){let r=ht(e);return z(r,t[e])}function fe(e,t,r){return z(e,r[t])}function V(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"},te={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},bt="\x1B[0m";function yt(e){return e<.2?te.cold:e<.4?te.cool:e<.6?te.neutral:e<.8?te.warm:e<.95?te.hot:te.critical}function Fe(e,t){let r=yt(t);return r?`${r}${e}${bt}`:e}function St(e){try{return kt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return wt("STRINGIFY_ERROR")}}function Be(e){let t=St(e);return t.ok?t.value:"[unserializable]"}var Ke="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function Ne(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*(Ke.length-1));return Ke[l]}).join("")}function De(e,t){let r=V(e).length,o=Math.max(0,t-r);return e+" ".repeat(o)}function xt(e,t){if(!t)return w.horizontal.repeat(e);let r=` ${t} `,o=V(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 ze(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 Rt(e,t){let r=[];return e.shouldRun&&r.push(ze(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&r.push(ze(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 ae(){return{name:"ascii",supportsLive:!0,render(e,t){let r={...Z,...t.colors},o=Math.max(t.terminalWidth??60,5),s=o-4,n=[],i=e.root.name??"workflow",c=se(i);if(n.push(`${w.topLeft}${xt(o-2,c)}${w.topRight}`),n.push(`${w.vertical}${" ".repeat(o-2)}${w.vertical}`),e.hooks){let u=Rt(e.hooks,r);for(let d of u)n.push(`${w.vertical} ${De(d,s)}${w.vertical}`)}let l=me(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=`${fe(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 me(e,t,r,o,s){let n=[];for(let i of e)K(i)?n.push(Oe(i,t,r,s)):Y(i)?n.push(...Et(i,t,r,o,s)):F(i)?n.push(...Mt(i,t,r,o,s)):X(i)?n.push(...It(i,t,r,o,s)):q(i)&&n.push($t(i,t,r));return n}function Oe(e,t,r,o){let s=ie(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=Fe(n,c):l=fe(n,e.state,r);let u=`${s} ${l}`;if(t.showKeys&&e.key&&e.name&&(u+=N(` [key: ${e.key}]`)),e.input!==void 0){let g=typeof e.input=="string"?e.input:Be(e.input).slice(0,30);u+=N(` [in: ${g}${g.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let g=typeof e.output=="string"?e.output:Be(e.output).slice(0,30);u+=N(` [out: ${g}${g.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let g=H(e.durationMs),m=c!==void 0?Fe(`[${g}]`,c):N(`[${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+=` ${N(Ne(g))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(u+=N(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let g=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";u+=N(` [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?N(` ${H(g.durationMs)}`):"";u+=` ${m}${f}`}return u}function $t(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=fe(s,e.state,r),i=N(`[W:${e.writeCount} R:${e.readCount}]`),c=`${o} ${n} ${i}`;return t.showTimings&&e.durationMs!==void 0&&(c+=` ${N(`[${H(e.durationMs)}]`)}`),e.backpressureOccurred&&(c+=N(" [backpressure]")),e.streamState==="closed"&&(c+=N(` pos:${e.finalPosition}`)),c}function Et(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ie(e.state,r),l=e.name??"parallel",u=e.mode==="allSettled"?" (allSettled)":"";if(n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${c} ${se(l)}${u}`),e.children.length===0)n.push(`${i}${w.vertical} ${N("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${N("(wrap each operation with step() to see individual steps)")}`);else for(let 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} ${Oe(g,t,r,s)}`);else{let k=me([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} ${N(`[${H(e.durationMs)}]`)}`),n}function Mt(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ie(e.state,r),l=e.name??"race";if(n.push(`${i}${w.teeRight}\u26A1 ${c} ${se(l)}`),e.children.length===0)n.push(`${i}${w.vertical} ${N("(operations not individually tracked)")}`),n.push(`${i}${w.vertical} ${N("(wrap each operation with step() to see individual steps)")}`);else for(let 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?N(" (winner)"):"";if(K(d))n.push(`${m} ${Oe(d,t,r,s)}${k}`);else{let b=me([d],t,r,o+1,s);for(let E of b)n.push(`${i}${w.vertical} ${E}`)}}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${N(`[${H(e.durationMs)}]`)}`),n}function It(e,t,r,o,s){let n=[],i=" ".repeat(o),c=ie(e.state,r),l=e.name??"decision",u=e.condition?N(` (${e.condition})`):"",d=e.decisionValue!==void 0?N(` = ${String(e.decisionValue)}`):"",g=e.branchTaken!==void 0?N(` \u2192 ${String(e.branchTaken)}`):"";n.push(`${i}${w.teeRight}${w.teeDown}${w.horizontal} ${c} ${se(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}`,E=f.taken?"\u2713":"\u2298",D=f.taken?r.success:r.skipped,S=z(`${E} ${f.label}`,D),y=f.condition?N(` (${f.condition})`):"";if(n.push(`${b} ${S}${y}`),f.children.length>0){let C=me(f.children,t,r,o+1,s);for(let I of C)n.push(`${i}${w.vertical} ${I}`)}else f.taken||n.push(`${i}${w.vertical} ${N("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&n.push(`${i}${w.bottomLeft}${w.horizontal}${w.horizontal} ${N(`[${H(e.durationMs)}]`)}`),n}import{ok as Dt,err as Nt}from"awaitly";function ge(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function Ot(){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 vt(){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 Tt(e){return`heat_${e}`}function Ct(){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 Wt(e){try{return Dt(JSON.stringify(e,(r,o)=>{if(typeof o!="bigint")return o;let s=Number(o);return Number.isSafeInteger(s)?s:o.toString()}))}catch{return Nt("STRINGIFY_ERROR")}}function Ge(e){let t=Wt(e);return t.ok?t.value:"[unserializable]"}function _t(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 je=0,he=new Set,ke=new Set;function re(e="node"){return`${e}_${++je}`}function Lt(){je=0,he.clear(),ke.clear()}function A(e){return e.replace(/"/g,"#quot;").replace(/</g,"<").replace(/>/g,">").trim()}function Ve(e){return A(e).replace(/[{}[\]()]/g,"")}function ve(){return{name:"mermaid",supportsLive:!1,render(e,t){Lt();let r=[],o=t;r.push("flowchart TD");let s;e.hooks&&(s=_t(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=we(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(...Ot()),o.showHeatmap&&r.push(...vt()),e.hooks&&r.push(...Ct()),r.join(`
|
|
3
|
+
`)}}}function we(e,t,r,o,s){if(K(e))return Pt(e,t,r,o,s);if(Y(e))return Ut(e,t,r,o,s);if(F(e))return Ht(e,t,r,o,s);if(X(e))return At(e,t,r,o,s);if(q(e))return Ft(e,t,r);let n=re("unknown");return r.push(` ${n}["Unknown Node"]`),{entryId:n,exitId:n}}function Pt(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,"_")}`:re("step");if(ke.has(u)){let R=2;for(;ke.has(`${u}_${R}`);)R++;u=`${u}_${R}`}ke.add(u);let d=e.name??e.key??"Step",g=t.showKeys&&e.key&&e.name?`${d} [${e.key}]`:d,m=A(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 R=typeof e.input=="string"?A(e.input):A(Ge(e.input).slice(0,20));b+=`\\nin: ${R}`}if(e.output!==void 0&&e.state==="success"){let R=typeof e.output=="string"?A(e.output):A(Ge(e.output).slice(0,20));b+=`\\nout: ${R}`}let E="",D=e.key??e.id;if(s&&D&&s.onAfterStep.has(D)){let R=s.onAfterStep.get(D),v=R.state==="success"?"\u2699":"\u26A0",O=t.showTimings&&R.durationMs!==void 0?` ${H(R.durationMs)}`:"";E=`\\n${v} hook${O}`}let S=(k+m+b+E+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 R=ge(C);y=Tt(R)}else y=e.state;let I;switch(e.state){case"error":I=`{{"${S}"}}`;break;case"cached":I=`[("${S}")]`;break;case"skipped":I=`["${S}"]`;break;default:I=`["${S}"]`}if(r.push(` ${u}${I}:::${y}`),i&&e.retryCount!==void 0&&e.retryCount>0){let R=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;r.push(` ${u} -.->|"${R}"| ${u}`)}if(c&&e.state==="error"&&e.error!==void 0){let R=`ERR_${u}`,v=A(String(e.error)).slice(0,30);r.push(` ${R}{{"${v}"}}`),r.push(` ${u} -->|error| ${R}`),r.push(` style ${R} fill:#fee2e2,stroke:#dc2626`)}if(l&&e.timedOut){let R=`TO_${u}`,v=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";r.push(` ${R}{{"\u23F1 Timeout ${v}"}}`),r.push(` ${u} -.->|timeout| ${R}`),r.push(` style ${R} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:u,exitId:u}}function Ut(e,t,r,o,s){let n=re("parallel"),i=`${n}_fork`,c=`${n}_join`,l=Ve(e.name??"Parallel"),u=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let m=n,f=A(`${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=we(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 Ht(e,t,r,o,s){let n=re("race"),i=`${n}_start`,c=`${n}_end`,l=Ve(e.name??"Race");if(e.children.length===0){let m=n,f=A(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=we(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 At(e,t,r,o,s){let n=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:re("decision");if(he.has(n)){let m=2;for(;he.has(`${n}_${m}`);)m++;n=`${n}_${m}`}he.add(n);let i=A(e.condition??"condition"),c=e.decisionValue!==void 0?` = ${A(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 S=2;for(;g.has(`${f}_${S}`);)S++;f=`${f}_${S}`}g.add(f);let k=A(m.label),b=m.taken?`${k} \u2713`:`${k} skipped`,E=m.taken?":::success":":::skipped";r.push(` ${f}["${b}"]${E}`);let D=m.condition?`|${A(m.condition).replace(/\|/g,"")}|`:"";if(r.push(` ${n} -->${D} ${f}`),m.children.length>0){let S=f;for(let y of m.children){let C=we(y,t,r,o,s);r.push(` ${S} --> ${C.entryId}`),S=C.exitId}u.push(S),m.taken&&(d=S)}else u.push(f),m.taken&&(d=f)}return d?{entryId:n,exitId:d}:{entryId:n,exitId:n}}function Ft(e,t,r){let o=`stream_${e.namespace.replace(/[^a-zA-Z0-9]/g,"_")}_${re("")}`,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:${A(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"},Bt={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Kt="\x1B[0m";function zt(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 Je(e,t,r){return t>=0&&t<e.width&&r>=0&&r<e.height?e.cells[r][t]:" "}function Gt(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 Ye(e,t,r,o,s){let n=V(o).split("");for(let i=0;i<n.length;i++)_(e,t+i,r,n[i],s)}function J(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let c=Je(e,t,i);c===W.horizontal?_(e,t,i,W.cross):(c===" "||c===W.vertical)&&_(e,t,i,W.vertical)}}function Xe(e,t,r,o){let s=Math.min(r,o),n=Math.max(r,o);for(let i=s;i<=n;i++){let c=Je(e,i,t);c===W.vertical?_(e,i,t,W.cross):(c===" "||c===W.horizontal)&&_(e,i,t,W.horizontal)}}function Q(e,t,r){_(e,t,r,W.arrowDown)}function jt(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+Kt: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,ne=2,be=3;function Ce(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 qe(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 Vt(e,t,r){let o=t.showStartEnd??!0,s=t,n=Math.floor(r/2),i=[],c=0;if(o){let u=ye("start","start",["\u25B6 Start"],"success",n,c);i.push(u),c=u.bottomY+ne}for(let u of e.root.children){let d=Se(u,n,c,r-4,t,s);i.push(d.node),c=d.bottomY+ne}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=ye("end","end",[u],e.root.state,n,c);i.push(d),c=d.bottomY}return{nodes:i,totalHeight:c+2}}function ye(e,t,r,o,s,n){let i=Math.max(...r.map(d=>V(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 Se(e,t,r,o,s,n){if(K(e))return Yt(e,t,r,o,s,n);if(Y(e)||F(e))return Jt(e,t,r,o,s,n);if(X(e))return qt(e,t,r,o,s,n);if(q(e))return Xt(e,t,r,o,s,n);let i=ye(e.id,"step",["?"],e.state,t,r);return{node:i,bottomY:i.bottomY}}function Yt(e,t,r,o,s,n){let i=e.name??e.key??"step",c=qe(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(...Ce(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(Ne(D,8))}let g=Math.max(...l.map(D=>V(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 Xt(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(...Ce(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=>V(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 Jt(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=ye(e.id,i?"race":"parallel",v,e.state,t,r);return{node:O,bottomY:O.bottomY}}let d=Math.floor((o-be*(e.children.length-1))/e.children.length),g=[];for(let v of e.children){let O=Te(v,Math.max(d,G),s,n);g.push(O.width)}let m=g.reduce((v,O)=>v+O,0)+be*(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=Se(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+ne}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=Se(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]+be}}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 qt(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=Ce(l,u),g=Math.max(...d.map(I=>V(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+ne,S=[];for(let I of E.children){let R=Se(I,t,D,o,s,n);S.push(R.node),D=R.bottomY+ne}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 Te(e,t,r,o){if(K(e)){let s=e.name??e.key??"step",n=qe(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(Y(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=Te(c,s,r,o);n+=l.width,i=Math.max(i,l.height)}return n+=be*(e.children.length-1),{width:Math.max(n,G),height:5+i+2}}if(X(e)){let s=e.branches.find(i=>i.taken),n=0;if(s)for(let i of s.children){let c=Te(i,t,r,o);n+=c.height+ne}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 Zt(e,t,r){let o={...Z,...r.colors};for(let s=0;s<t.length;s++){let n=t[s],i=s===t.length-1;if(xe(e,n,o),!i){let c=t[s+1],l=n.centerX,u=n.bottomY+1,d=c.centerX,g=c.y-1;J(e,l,u,g-1),Q(e,d,g)}}}function xe(e,t,r){let o=t.type!=="start",s=t.type!=="end"&&(!t.children||t.children.length===0);Gt(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=rr(t,r);for(let c=0;c<t.label.length;c++){let l=t.label[c],u=t.x+1+Math.floor((n-V(l).length)/2),d=t.y+1+c;Ye(e,u,d,l,i)}t.metadata?.isWinner&&Ye(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?Qt(e,t,r):er(e,t,r))}function Qt(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];J(e,n,s,c.y-2),Q(e,c.centerX,c.y-1);for(let l=0;l<o.length;l++){let u=o[l];if(xe(e,u,r),l<o.length-1){let d=o[l+1];J(e,u.centerX,u.bottomY+1,d.y-2),Q(e,d.centerX,d.y-1)}}return}if(o.length===1)J(e,n,s,o[0].y-2),Q(e,o[0].centerX,o[0].y-1);else{let c=o.map(d=>d.centerX),l=Math.min(...c),u=Math.max(...c);J(e,n,s,s+1),Xe(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),J(e,g,s+2,d.y-2),Q(e,g,d.y-1)}}for(let c of o)xe(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&&J(e,f.centerX,f.bottomY+1,u-1);Xe(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 er(e,t,r){let o=t.children;if(o.length===0)return;let s=t.y+t.height,n=o[0];J(e,t.centerX,s,n.y-2),Q(e,n.centerX,n.y-1);for(let i=0;i<o.length;i++){let c=o[i];if(xe(e,c,r),i<o.length-1){let l=o[i+1];J(e,c.centerX,c.bottomY+1,l.y-2),Q(e,l.centerX,l.y-1)}}}var tr={active:"\x1B[36m",closed:"\x1B[32m",error:"\x1B[31m"};function rr(e,t){if(e.metadata?.heat!==void 0){let r=ge(e.metadata.heat);return Bt[r]||void 0}return e.type==="stream"&&e.metadata?.streamState?tr[e.metadata.streamState]||void 0:t[e.state]||void 0}function ce(){return{name:"flowchart",supportsLive:!1,render(e,t){let r=t.terminalWidth??80,{nodes:o,totalHeight:s}=Vt(e,t,r),n=zt(r,s);return Zt(n,o,t),jt(n)}}}function nr(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function or(e){let t=[];function r(o){for(let s of o)if(K(s))t.push(s);else if(Ue(s))r(s.children);else if(Y(s)||F(s))r(s.children);else if(X(s))for(let n of s.branches)n.taken&&r(n.children)}return r(e),t}function sr(e){let t={id:e.id,name:e.name??e.key??e.id,state:e.state};return e.key&&(t.key=e.key),e.durationMs!==void 0&&(t.durationMs=e.durationMs),e.startTs!==void 0&&(t.startTs=e.startTs),e.endTs!==void 0&&(t.endTs=e.endTs),e.retryCount!==void 0&&e.retryCount>0&&(t.retryCount=e.retryCount),e.timedOut&&(t.timedOut=!0,e.timeoutMs!==void 0&&(t.timeoutMs=e.timeoutMs)),e.error!==void 0&&(t.error=typeof e.error=="string"?e.error:String(e.error)),t}function ir(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 ar(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 cr(e,t){let r=e.root,o=or(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(sr),summary:ir(o)};if(e.hooks){let c=ar(e.hooks);Object.keys(c).length>0&&(i.hooks=c)}if(s){let u=((t.diagramFormat??"ascii")==="flowchart"?ce():ae()).render(e,t);n&&(u=nr(u)),i.diagram=u}return i}function We(){return{name:"logger",supportsLive:!1,render(e,t){let o=cr(e,t);return JSON.stringify(o)}}}import{ok as $e,err as ue}from"awaitly";import ur from"pako";var lr=typeof globalThis<"u"&&"Buffer"in globalThis&&typeof globalThis.Buffer=="function";function dr(e){let t;if(lr)t=globalThis.Buffer.from(e).toString("base64");else{let r="";for(let o=0;o<e.length;o++)r+=String.fromCharCode(e[o]);t=btoa(r)}return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Re(e){let r=new TextEncoder().encode(e),o=ur.deflate(r);return dr(o)}var pr="https://kroki.io";function Ze(e,t,r,o={}){let s=o.baseUrl??pr,n=Re(r);return`${s}/${e}/${t}/${n}`}var fr="https://mermaid.ink";function mr(e){return`pako:${Re(e)}`}function gr(e){if("provider"in e){let t=e;return{theme:t.mermaidTheme,bgColor:t.background,scale:t.scale,fit:t.fit,width:t.width,height:t.height,paper:t.paper,imageType:"png"}}return e}function hr(e,t){let r=[];return t.bgColor&&r.push(`bgColor=${encodeURIComponent(t.bgColor)}`),t.theme&&r.push(`theme=${t.theme}`),t.width!==void 0&&r.push(`width=${t.width}`),t.height!==void 0&&r.push(`height=${t.height}`),t.scale!==void 0&&(t.width!==void 0||t.height!==void 0)&&r.push(`scale=${t.scale}`),e==="img"&&t.imageType&&t.imageType!=="jpeg"&&r.push(`type=${t.imageType}`),e==="pdf"&&(t.fit&&r.push("fit"),t.paper&&!t.fit&&r.push(`paper=${t.paper}`),t.landscape&&!t.fit&&r.push("landscape")),r.length>0?`?${r.join("&")}`:""}function Qe(e,t,r={}){let o=gr(r),s=o.baseUrl??fr,n=mr(t),i=hr(e,o);return`${s}/${e}/${n}${i}`}function kr(e,t,r){return e==="mermaid-ink"&&t==="mermaid"?$e(void 0):e==="kroki"&&t==="mermaid"?r==="pdf"?ue("UNSUPPORTED_FORMAT"):$e(void 0):ue("UNSUPPORTED_FORMAT")}function wr(e){switch(e){case"mermaid":return"mermaid";case"graphviz":return"graphviz";case"plantuml":return"plantuml"}}function br(e){switch(e){case"svg":return"svg";case"png":return"img";case"pdf":return"pdf"}}function Ee(e,t,r,o={}){switch(e.kind){case"mermaid":break;case"graphviz":case"plantuml":return ue("UNSUPPORTED_DIAGRAM_KIND");default:{let n=e;return ue("UNSUPPORTED_DIAGRAM_KIND")}}let s=kr(r.provider,e.kind,t);if(!s.ok)return s;switch(r.provider){case"kroki":return $e(Ze(wr(e.kind),t,e.source,r));case"mermaid-ink":return $e(Qe(br(t),e.source,r));default:{let n=r;return ue("UNKNOWN_PROVIDER")}}}function et(e={}){let{workflowName:t,detectParallel:r=!0,showTimings:o=!0,showKeys:s=!1,colors:n,export:i}=e,c=Pe({detectParallel:r}),l=new Set,u=ae(),d=ve(),g=We(),m=ce(),f={showTimings:o,showKeys:s,terminalWidth:process.stdout?.columns??80,colors:{...Z,...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,(_e,oe)=>typeof oe=="bigint"?oe.toString():oe,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=Ee(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=Ee(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=Ee(O(),"pdf",v(x,"toPdfUrl"),{caller:"toPdfUrl"});if(!M.ok)throw new Error(`toPdfUrl: Export failed - ${M.error}`);return M.value}function ee(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:ee,toSvgUrl:L,toPngUrl:$,toPdfUrl:P}}function nt(e={}){let{logEvents:t=!1,maxHistory:r=10,logger:o=console.log}=e,s=et(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 ee=k($),x=k(P);if(!(!ee||!x))return tt(ee,x)}function E(){if(!i||n.length===0)return;let $=n[n.length-1];return tt($,i)}function D(){return s.render()}function S($){return s.renderAs($)}function y(){return s.renderAs("mermaid")}function C(){let $=I();return Sr($)}function I(){return i?yr(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 tt(e,t){let r=rt(e.events),o=rt(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 rt(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 yr(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 Sr(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=xr(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 xr(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 Rr(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
|
+
Added steps:`);for(let r of e.added)t.push(` + ${r.step}`)}if(e.removed.length>0){t.push(`
|
|
7
|
+
Removed steps:`);for(let r of e.removed)t.push(` - ${r.step}`)}if(e.changed.length>0){t.push(`
|
|
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
|
+
Unchanged: ${e.unchanged.length} steps`),t.join(`
|
|
10
|
+
`)}function $r(e,t={}){let r=nt(t);return e(r.handleEvent).then(()=>r.render())}function Er(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}`)}}export{Er as createConsoleLogger,nt as createDevtools,$r as quickVisualize,Rr as renderDiff};
|
|
11
|
+
//# sourceMappingURL=devtools.js.map
|