awaitly 1.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/LICENSE +21 -0
- package/README.md +1278 -0
- package/dist/batch.cjs +2 -0
- package/dist/batch.cjs.map +1 -0
- package/dist/batch.d.cts +197 -0
- package/dist/batch.d.ts +197 -0
- package/dist/batch.js +2 -0
- package/dist/batch.js.map +1 -0
- package/dist/circuit-breaker.cjs +2 -0
- package/dist/circuit-breaker.cjs.map +1 -0
- package/dist/circuit-breaker.d.cts +208 -0
- package/dist/circuit-breaker.d.ts +208 -0
- package/dist/circuit-breaker.js +2 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/conditional.cjs +2 -0
- package/dist/conditional.cjs.map +1 -0
- package/dist/conditional.d.cts +249 -0
- package/dist/conditional.d.ts +249 -0
- package/dist/conditional.js +2 -0
- package/dist/conditional.js.map +1 -0
- package/dist/core-BuTBsR0x.d.cts +2325 -0
- package/dist/core-BuTBsR0x.d.ts +2325 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +3 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/devtools.cjs +11 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.cts +176 -0
- package/dist/devtools.d.ts +176 -0
- package/dist/devtools.js +11 -0
- package/dist/devtools.js.map +1 -0
- package/dist/duration.cjs +2 -0
- package/dist/duration.cjs.map +1 -0
- package/dist/duration.d.cts +246 -0
- package/dist/duration.d.ts +246 -0
- package/dist/duration.js +2 -0
- package/dist/duration.js.map +1 -0
- package/dist/hitl.cjs +2 -0
- package/dist/hitl.cjs.map +1 -0
- package/dist/hitl.d.cts +337 -0
- package/dist/hitl.d.ts +337 -0
- package/dist/hitl.js +2 -0
- package/dist/hitl.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/match.cjs +2 -0
- package/dist/match.cjs.map +1 -0
- package/dist/match.d.cts +209 -0
- package/dist/match.d.ts +209 -0
- package/dist/match.js +2 -0
- package/dist/match.js.map +1 -0
- package/dist/otel.cjs +2 -0
- package/dist/otel.cjs.map +1 -0
- package/dist/otel.d.cts +185 -0
- package/dist/otel.d.ts +185 -0
- package/dist/otel.js +2 -0
- package/dist/otel.js.map +1 -0
- package/dist/persistence.cjs +2 -0
- package/dist/persistence.cjs.map +1 -0
- package/dist/persistence.d.cts +572 -0
- package/dist/persistence.d.ts +572 -0
- package/dist/persistence.js +2 -0
- package/dist/persistence.js.map +1 -0
- package/dist/policies.cjs +2 -0
- package/dist/policies.cjs.map +1 -0
- package/dist/policies.d.cts +378 -0
- package/dist/policies.d.ts +378 -0
- package/dist/policies.js +2 -0
- package/dist/policies.js.map +1 -0
- package/dist/ratelimit.cjs +2 -0
- package/dist/ratelimit.cjs.map +1 -0
- package/dist/ratelimit.d.cts +279 -0
- package/dist/ratelimit.d.ts +279 -0
- package/dist/ratelimit.js +2 -0
- package/dist/ratelimit.js.map +1 -0
- package/dist/reliability.cjs +2 -0
- package/dist/reliability.cjs.map +1 -0
- package/dist/reliability.d.cts +5 -0
- package/dist/reliability.d.ts +5 -0
- package/dist/reliability.js +2 -0
- package/dist/reliability.js.map +1 -0
- package/dist/resource.cjs +2 -0
- package/dist/resource.cjs.map +1 -0
- package/dist/resource.d.cts +171 -0
- package/dist/resource.d.ts +171 -0
- package/dist/resource.js +2 -0
- package/dist/resource.js.map +1 -0
- package/dist/retry.cjs +2 -0
- package/dist/retry.cjs.map +1 -0
- package/dist/retry.d.cts +2 -0
- package/dist/retry.d.ts +2 -0
- package/dist/retry.js +2 -0
- package/dist/retry.js.map +1 -0
- package/dist/saga.cjs +2 -0
- package/dist/saga.cjs.map +1 -0
- package/dist/saga.d.cts +231 -0
- package/dist/saga.d.ts +231 -0
- package/dist/saga.js +2 -0
- package/dist/saga.js.map +1 -0
- package/dist/schedule.cjs +2 -0
- package/dist/schedule.cjs.map +1 -0
- package/dist/schedule.d.cts +387 -0
- package/dist/schedule.d.ts +387 -0
- package/dist/schedule.js +2 -0
- package/dist/schedule.js.map +1 -0
- package/dist/tagged-error.cjs +2 -0
- package/dist/tagged-error.cjs.map +1 -0
- package/dist/tagged-error.d.cts +252 -0
- package/dist/tagged-error.d.ts +252 -0
- package/dist/tagged-error.js +2 -0
- package/dist/tagged-error.js.map +1 -0
- package/dist/testing.cjs +2 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +228 -0
- package/dist/testing.d.ts +228 -0
- package/dist/testing.js +2 -0
- package/dist/testing.js.map +1 -0
- package/dist/visualize.cjs +1573 -0
- package/dist/visualize.cjs.map +1 -0
- package/dist/visualize.d.cts +1415 -0
- package/dist/visualize.d.ts +1415 -0
- package/dist/visualize.js +1573 -0
- package/dist/visualize.js.map +1 -0
- package/dist/webhook.cjs +2 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +469 -0
- package/dist/webhook.d.ts +469 -0
- package/dist/webhook.js +2 -0
- package/dist/webhook.js.map +1 -0
- package/dist/workflow-entry-C6nH8ByN.d.ts +858 -0
- package/dist/workflow-entry-RRTlSg_4.d.cts +858 -0
- package/dist/workflow.cjs +2 -0
- package/dist/workflow.cjs.map +1 -0
- package/dist/workflow.d.cts +2 -0
- package/dist/workflow.d.ts +2 -0
- package/dist/workflow.js +2 -0
- package/dist/workflow.js.map +1 -0
- package/docs/advanced.md +1548 -0
- package/docs/api.md +513 -0
- package/docs/coming-from-neverthrow.md +1013 -0
- package/docs/match.md +417 -0
- package/docs/pino-logging-example.md +396 -0
- package/docs/policies.md +508 -0
- package/docs/resource-management.md +509 -0
- package/docs/schedule.md +467 -0
- package/docs/tagged-error.md +785 -0
- package/docs/visualization.md +430 -0
- package/docs/visualize-examples.md +330 -0
- package/package.json +227 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { W as WorkflowEvent } from './core-BuTBsR0x.cjs';
|
|
2
|
+
import { CollectableEvent, VisualizerOptions, DecisionStartEvent, DecisionBranchEvent, DecisionEndEvent, OutputFormat } from './visualize.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* awaitly/devtools
|
|
6
|
+
*
|
|
7
|
+
* Developer tools for workflow debugging, visualization, and analysis.
|
|
8
|
+
* Provides timeline rendering, run diffing, and live visualization.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A recorded workflow run with events and metadata.
|
|
13
|
+
*/
|
|
14
|
+
interface WorkflowRun {
|
|
15
|
+
/** Unique identifier for this run */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Workflow name */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Start timestamp */
|
|
20
|
+
startTime: number;
|
|
21
|
+
/** End timestamp (undefined if still running) */
|
|
22
|
+
endTime?: number;
|
|
23
|
+
/** Duration in milliseconds */
|
|
24
|
+
durationMs?: number;
|
|
25
|
+
/** Whether the workflow succeeded */
|
|
26
|
+
success?: boolean;
|
|
27
|
+
/** Error if the workflow failed */
|
|
28
|
+
error?: unknown;
|
|
29
|
+
/** All events from this run */
|
|
30
|
+
events: CollectableEvent[];
|
|
31
|
+
/** Custom metadata */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Difference between two workflow runs.
|
|
36
|
+
*/
|
|
37
|
+
interface RunDiff {
|
|
38
|
+
/** Steps that were added in the new run */
|
|
39
|
+
added: StepDiff[];
|
|
40
|
+
/** Steps that were removed from the new run */
|
|
41
|
+
removed: StepDiff[];
|
|
42
|
+
/** Steps that changed between runs */
|
|
43
|
+
changed: StepDiff[];
|
|
44
|
+
/** Steps that are identical */
|
|
45
|
+
unchanged: string[];
|
|
46
|
+
/** Overall status change */
|
|
47
|
+
statusChange?: {
|
|
48
|
+
from: "success" | "error" | "running";
|
|
49
|
+
to: "success" | "error" | "running";
|
|
50
|
+
};
|
|
51
|
+
/** Duration change in milliseconds */
|
|
52
|
+
durationChange?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Information about a step difference.
|
|
56
|
+
*/
|
|
57
|
+
interface StepDiff {
|
|
58
|
+
/** Step name or key */
|
|
59
|
+
step: string;
|
|
60
|
+
/** Type of change */
|
|
61
|
+
type: "added" | "removed" | "status" | "duration" | "error";
|
|
62
|
+
/** Previous value (for changes) */
|
|
63
|
+
from?: unknown;
|
|
64
|
+
/** New value (for changes) */
|
|
65
|
+
to?: unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Timeline entry for a step.
|
|
69
|
+
*/
|
|
70
|
+
interface TimelineEntry {
|
|
71
|
+
/** Step name */
|
|
72
|
+
name: string;
|
|
73
|
+
/** Step key (if any) */
|
|
74
|
+
key?: string;
|
|
75
|
+
/** Start time (relative to workflow start) */
|
|
76
|
+
startMs: number;
|
|
77
|
+
/** End time (relative to workflow start) */
|
|
78
|
+
endMs?: number;
|
|
79
|
+
/** Duration in milliseconds */
|
|
80
|
+
durationMs?: number;
|
|
81
|
+
/** Step status */
|
|
82
|
+
status: "pending" | "running" | "success" | "error" | "skipped" | "cached";
|
|
83
|
+
/** Error if failed */
|
|
84
|
+
error?: unknown;
|
|
85
|
+
/** Parent scope (for nested steps) */
|
|
86
|
+
parent?: string;
|
|
87
|
+
/** Retry attempt number */
|
|
88
|
+
attempt?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Devtools configuration options.
|
|
92
|
+
*/
|
|
93
|
+
interface DevtoolsOptions extends VisualizerOptions {
|
|
94
|
+
/** Enable console logging of events */
|
|
95
|
+
logEvents?: boolean;
|
|
96
|
+
/** Maximum number of runs to keep in history */
|
|
97
|
+
maxHistory?: number;
|
|
98
|
+
/** Custom logger function */
|
|
99
|
+
logger?: (message: string) => void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Devtools instance for workflow debugging.
|
|
103
|
+
*/
|
|
104
|
+
interface Devtools {
|
|
105
|
+
/** Handle a workflow event */
|
|
106
|
+
handleEvent: (event: WorkflowEvent<unknown>) => void;
|
|
107
|
+
/** Handle a decision event */
|
|
108
|
+
handleDecisionEvent: (event: DecisionStartEvent | DecisionBranchEvent | DecisionEndEvent) => void;
|
|
109
|
+
/** Get the current run */
|
|
110
|
+
getCurrentRun: () => WorkflowRun | undefined;
|
|
111
|
+
/** Get run history */
|
|
112
|
+
getHistory: () => WorkflowRun[];
|
|
113
|
+
/** Get a specific run by ID */
|
|
114
|
+
getRun: (id: string) => WorkflowRun | undefined;
|
|
115
|
+
/** Compare two runs */
|
|
116
|
+
diff: (runId1: string, runId2: string) => RunDiff | undefined;
|
|
117
|
+
/** Compare current run with a previous run */
|
|
118
|
+
diffWithPrevious: () => RunDiff | undefined;
|
|
119
|
+
/** Render current state */
|
|
120
|
+
render: () => string;
|
|
121
|
+
/** Render to a specific format */
|
|
122
|
+
renderAs: (format: OutputFormat) => string;
|
|
123
|
+
/** Render as Mermaid diagram */
|
|
124
|
+
renderMermaid: () => string;
|
|
125
|
+
/** Render as ASCII timeline */
|
|
126
|
+
renderTimeline: () => string;
|
|
127
|
+
/** Get timeline data for current run */
|
|
128
|
+
getTimeline: () => TimelineEntry[];
|
|
129
|
+
/** Clear all history */
|
|
130
|
+
clearHistory: () => void;
|
|
131
|
+
/** Reset current run */
|
|
132
|
+
reset: () => void;
|
|
133
|
+
/** Export run data as JSON */
|
|
134
|
+
exportRun: (runId?: string) => string;
|
|
135
|
+
/** Import run data from JSON */
|
|
136
|
+
importRun: (json: string) => WorkflowRun;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create a devtools instance for workflow debugging.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const devtools = createDevtools({ workflowName: 'checkout' });
|
|
144
|
+
*
|
|
145
|
+
* const workflow = createWorkflow(deps, {
|
|
146
|
+
* onEvent: devtools.handleEvent,
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* await workflow(async (step) => { ... });
|
|
150
|
+
*
|
|
151
|
+
* // Visualize
|
|
152
|
+
* console.log(devtools.render());
|
|
153
|
+
* console.log(devtools.renderMermaid());
|
|
154
|
+
*
|
|
155
|
+
* // Compare with previous run
|
|
156
|
+
* const diff = devtools.diffWithPrevious();
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function createDevtools(options?: DevtoolsOptions): Devtools;
|
|
160
|
+
/**
|
|
161
|
+
* Render a run diff as a string.
|
|
162
|
+
*/
|
|
163
|
+
declare function renderDiff(diff: RunDiff): string;
|
|
164
|
+
/**
|
|
165
|
+
* Quick visualization helper for a single workflow run.
|
|
166
|
+
*/
|
|
167
|
+
declare function quickVisualize(workflowFn: (handleEvent: (event: WorkflowEvent<unknown>) => void) => Promise<unknown>, options?: DevtoolsOptions): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Create an event handler that logs to console with pretty formatting.
|
|
170
|
+
*/
|
|
171
|
+
declare function createConsoleLogger(options?: {
|
|
172
|
+
prefix?: string;
|
|
173
|
+
colors?: boolean;
|
|
174
|
+
}): (event: WorkflowEvent<unknown>) => void;
|
|
175
|
+
|
|
176
|
+
export { type Devtools, type DevtoolsOptions, type RunDiff, type StepDiff, type TimelineEntry, type WorkflowRun, createConsoleLogger, createDevtools, quickVisualize, renderDiff };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { W as WorkflowEvent } from './core-BuTBsR0x.js';
|
|
2
|
+
import { CollectableEvent, VisualizerOptions, DecisionStartEvent, DecisionBranchEvent, DecisionEndEvent, OutputFormat } from './visualize.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* awaitly/devtools
|
|
6
|
+
*
|
|
7
|
+
* Developer tools for workflow debugging, visualization, and analysis.
|
|
8
|
+
* Provides timeline rendering, run diffing, and live visualization.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A recorded workflow run with events and metadata.
|
|
13
|
+
*/
|
|
14
|
+
interface WorkflowRun {
|
|
15
|
+
/** Unique identifier for this run */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Workflow name */
|
|
18
|
+
name?: string;
|
|
19
|
+
/** Start timestamp */
|
|
20
|
+
startTime: number;
|
|
21
|
+
/** End timestamp (undefined if still running) */
|
|
22
|
+
endTime?: number;
|
|
23
|
+
/** Duration in milliseconds */
|
|
24
|
+
durationMs?: number;
|
|
25
|
+
/** Whether the workflow succeeded */
|
|
26
|
+
success?: boolean;
|
|
27
|
+
/** Error if the workflow failed */
|
|
28
|
+
error?: unknown;
|
|
29
|
+
/** All events from this run */
|
|
30
|
+
events: CollectableEvent[];
|
|
31
|
+
/** Custom metadata */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Difference between two workflow runs.
|
|
36
|
+
*/
|
|
37
|
+
interface RunDiff {
|
|
38
|
+
/** Steps that were added in the new run */
|
|
39
|
+
added: StepDiff[];
|
|
40
|
+
/** Steps that were removed from the new run */
|
|
41
|
+
removed: StepDiff[];
|
|
42
|
+
/** Steps that changed between runs */
|
|
43
|
+
changed: StepDiff[];
|
|
44
|
+
/** Steps that are identical */
|
|
45
|
+
unchanged: string[];
|
|
46
|
+
/** Overall status change */
|
|
47
|
+
statusChange?: {
|
|
48
|
+
from: "success" | "error" | "running";
|
|
49
|
+
to: "success" | "error" | "running";
|
|
50
|
+
};
|
|
51
|
+
/** Duration change in milliseconds */
|
|
52
|
+
durationChange?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Information about a step difference.
|
|
56
|
+
*/
|
|
57
|
+
interface StepDiff {
|
|
58
|
+
/** Step name or key */
|
|
59
|
+
step: string;
|
|
60
|
+
/** Type of change */
|
|
61
|
+
type: "added" | "removed" | "status" | "duration" | "error";
|
|
62
|
+
/** Previous value (for changes) */
|
|
63
|
+
from?: unknown;
|
|
64
|
+
/** New value (for changes) */
|
|
65
|
+
to?: unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Timeline entry for a step.
|
|
69
|
+
*/
|
|
70
|
+
interface TimelineEntry {
|
|
71
|
+
/** Step name */
|
|
72
|
+
name: string;
|
|
73
|
+
/** Step key (if any) */
|
|
74
|
+
key?: string;
|
|
75
|
+
/** Start time (relative to workflow start) */
|
|
76
|
+
startMs: number;
|
|
77
|
+
/** End time (relative to workflow start) */
|
|
78
|
+
endMs?: number;
|
|
79
|
+
/** Duration in milliseconds */
|
|
80
|
+
durationMs?: number;
|
|
81
|
+
/** Step status */
|
|
82
|
+
status: "pending" | "running" | "success" | "error" | "skipped" | "cached";
|
|
83
|
+
/** Error if failed */
|
|
84
|
+
error?: unknown;
|
|
85
|
+
/** Parent scope (for nested steps) */
|
|
86
|
+
parent?: string;
|
|
87
|
+
/** Retry attempt number */
|
|
88
|
+
attempt?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Devtools configuration options.
|
|
92
|
+
*/
|
|
93
|
+
interface DevtoolsOptions extends VisualizerOptions {
|
|
94
|
+
/** Enable console logging of events */
|
|
95
|
+
logEvents?: boolean;
|
|
96
|
+
/** Maximum number of runs to keep in history */
|
|
97
|
+
maxHistory?: number;
|
|
98
|
+
/** Custom logger function */
|
|
99
|
+
logger?: (message: string) => void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Devtools instance for workflow debugging.
|
|
103
|
+
*/
|
|
104
|
+
interface Devtools {
|
|
105
|
+
/** Handle a workflow event */
|
|
106
|
+
handleEvent: (event: WorkflowEvent<unknown>) => void;
|
|
107
|
+
/** Handle a decision event */
|
|
108
|
+
handleDecisionEvent: (event: DecisionStartEvent | DecisionBranchEvent | DecisionEndEvent) => void;
|
|
109
|
+
/** Get the current run */
|
|
110
|
+
getCurrentRun: () => WorkflowRun | undefined;
|
|
111
|
+
/** Get run history */
|
|
112
|
+
getHistory: () => WorkflowRun[];
|
|
113
|
+
/** Get a specific run by ID */
|
|
114
|
+
getRun: (id: string) => WorkflowRun | undefined;
|
|
115
|
+
/** Compare two runs */
|
|
116
|
+
diff: (runId1: string, runId2: string) => RunDiff | undefined;
|
|
117
|
+
/** Compare current run with a previous run */
|
|
118
|
+
diffWithPrevious: () => RunDiff | undefined;
|
|
119
|
+
/** Render current state */
|
|
120
|
+
render: () => string;
|
|
121
|
+
/** Render to a specific format */
|
|
122
|
+
renderAs: (format: OutputFormat) => string;
|
|
123
|
+
/** Render as Mermaid diagram */
|
|
124
|
+
renderMermaid: () => string;
|
|
125
|
+
/** Render as ASCII timeline */
|
|
126
|
+
renderTimeline: () => string;
|
|
127
|
+
/** Get timeline data for current run */
|
|
128
|
+
getTimeline: () => TimelineEntry[];
|
|
129
|
+
/** Clear all history */
|
|
130
|
+
clearHistory: () => void;
|
|
131
|
+
/** Reset current run */
|
|
132
|
+
reset: () => void;
|
|
133
|
+
/** Export run data as JSON */
|
|
134
|
+
exportRun: (runId?: string) => string;
|
|
135
|
+
/** Import run data from JSON */
|
|
136
|
+
importRun: (json: string) => WorkflowRun;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Create a devtools instance for workflow debugging.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const devtools = createDevtools({ workflowName: 'checkout' });
|
|
144
|
+
*
|
|
145
|
+
* const workflow = createWorkflow(deps, {
|
|
146
|
+
* onEvent: devtools.handleEvent,
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* await workflow(async (step) => { ... });
|
|
150
|
+
*
|
|
151
|
+
* // Visualize
|
|
152
|
+
* console.log(devtools.render());
|
|
153
|
+
* console.log(devtools.renderMermaid());
|
|
154
|
+
*
|
|
155
|
+
* // Compare with previous run
|
|
156
|
+
* const diff = devtools.diffWithPrevious();
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function createDevtools(options?: DevtoolsOptions): Devtools;
|
|
160
|
+
/**
|
|
161
|
+
* Render a run diff as a string.
|
|
162
|
+
*/
|
|
163
|
+
declare function renderDiff(diff: RunDiff): string;
|
|
164
|
+
/**
|
|
165
|
+
* Quick visualization helper for a single workflow run.
|
|
166
|
+
*/
|
|
167
|
+
declare function quickVisualize(workflowFn: (handleEvent: (event: WorkflowEvent<unknown>) => void) => Promise<unknown>, options?: DevtoolsOptions): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Create an event handler that logs to console with pretty formatting.
|
|
170
|
+
*/
|
|
171
|
+
declare function createConsoleLogger(options?: {
|
|
172
|
+
prefix?: string;
|
|
173
|
+
colors?: boolean;
|
|
174
|
+
}): (event: WorkflowEvent<unknown>) => void;
|
|
175
|
+
|
|
176
|
+
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 C(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),n=Math.round(e%6e4/1e3);return n===0?`${t}m`:`${t}m ${n}s`}function ge(){return`node_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Ve(e){for(let t of e)if((t.type==="parallel"||t.type==="race"||t.type==="sequence")&&!t.id.startsWith("detected_")||"decisionId"in t)return!0;return!1}function we(e,t={}){if(Ve(e))return e;let{minOverlapMs:n=0,maxGapMs:o=5}=t,i=[],r=[];for(let c=0;c<e.length;c++){let d=e[c];d.type==="step"&&d.startTs!==void 0?i.push({node:d,startTs:d.startTs,endTs:d.endTs??d.startTs+(d.durationMs??0),originalIndex:c}):r.push({node:d,originalIndex:c})}if(i.length<=1)return e;i.sort((c,d)=>c.startTs-d.startTs);let s=[],a=[i[0]];for(let c=1;c<i.length;c++){let d=i[c],p=Math.min(...a.map(x=>x.startTs)),f=Math.max(...a.map(x=>x.endTs)),m=d.startTs<=p+o,v=d.startTs<f;if(!m&&!v){s.push(a),a=[d];continue}let g=v?Math.min(d.endTs,f)-d.startTs:0;m||g>=n?a.push(d):(s.push(a),a=[d])}s.push(a);let u=[];for(let c of s){let d=Math.min(...c.map(p=>p.originalIndex));if(c.length===1)u.push({node:c[0].node,position:d});else{let p=c.map(g=>g.node),f=Math.min(...c.map(g=>g.startTs)),m=Math.max(...c.map(g=>g.endTs)),v={type:"parallel",id:`detected_parallel_${f}`,name:`${p.length} parallel steps`,state:je(p),mode:"all",children:p,startTs:f,endTs:m,durationMs:m-f};u.push({node:v,position:d})}}for(let{node:c,originalIndex:d}of r)u.push({node:c,position:d});return u.sort((c,d)=>c.position-d.position),u.map(c=>c.node)}function je(e){return e.some(r=>r.state==="error")?"error":e.some(r=>r.state==="running")?"running":e.some(r=>r.state==="pending")?"pending":(e.every(r=>r.state==="success"||r.state==="cached"),"success")}function te(e={}){let{detectParallel:t=!0,parallelDetection:n,enableSnapshots:o=!1,maxSnapshots:i=1e3}=e,r,s,a="pending",u,c,d=new Map,p=[],f=[],m=[],v=Date.now(),g=v,x={onAfterStep:new Map},y=[],$=0;function D(l){return l.stepId??l.stepKey??l.name??ge()}function k(l){if(f.length>0){let h=f[f.length-1];for(let _ of h.branches.values())if(_.taken){_.children.push(l),g=Date.now();return}let w=Array.from(h.branches.values())[0];if(w){w.children.push(l),g=Date.now();return}}p.length>0?p[p.length-1].children.push(l):m.push(l),g=Date.now()}function T(l){if(!o)return;let h=O(),w=new Map;for(let[P,X]of d)w.set(P,{id:X.id,name:X.name,key:X.key,startTs:X.startTs,retryCount:X.retryCount,timedOut:X.timedOut,timeoutMs:X.timeoutMs});let _={id:`snapshot_${$}`,eventIndex:$,event:structuredClone(l),ir:structuredClone(h),timestamp:Date.now(),activeSteps:w};y.push(_),y.length>i&&y.shift(),$++}function R(l){switch(l.type){case"workflow_start":r=l.workflowId,s=l.ts,a="running",v=Date.now(),g=v,x.onAfterStep=new Map;break;case"workflow_success":a="success",c=l.durationMs,g=Date.now();break;case"workflow_error":a="error",u=l.error,c=l.durationMs,g=Date.now();break;case"step_start":{let h=D(l);d.set(h,{id:h,name:l.name,key:l.stepKey,startTs:l.ts,retryCount:0,timedOut:!1}),g=Date.now();break}case"step_success":{let h=D(l),w=d.get(h);if(w){let _={type:"step",id:w.id,name:w.name,key:w.key,state:"success",startTs:w.startTs,endTs:l.ts,durationMs:l.durationMs,...w.retryCount>0&&{retryCount:w.retryCount},...w.timedOut&&{timedOut:!0,timeoutMs:w.timeoutMs}};k(_),d.delete(h)}break}case"step_error":{let h=D(l),w=d.get(h);if(w){let _={type:"step",id:w.id,name:w.name,key:w.key,state:"error",startTs:w.startTs,endTs:l.ts,durationMs:l.durationMs,error:l.error,...w.retryCount>0&&{retryCount:w.retryCount},...w.timedOut&&{timedOut:!0,timeoutMs:w.timeoutMs}};k(_),d.delete(h)}break}case"step_aborted":{let h=D(l),w=d.get(h);if(w){let _={type:"step",id:w.id,name:w.name,key:w.key,state:"aborted",startTs:w.startTs,endTs:l.ts,durationMs:l.durationMs,...w.retryCount>0&&{retryCount:w.retryCount},...w.timedOut&&{timedOut:!0,timeoutMs:w.timeoutMs}};k(_),d.delete(h)}break}case"step_cache_hit":{let w={type:"step",id:D(l),name:l.name,key:l.stepKey,state:"cached",startTs:l.ts,endTs:l.ts,durationMs:0};k(w);break}case"step_cache_miss":break;case"step_complete":break;case"step_timeout":{let h=D(l),w=d.get(h);w&&(w.timedOut=!0,w.timeoutMs=l.timeoutMs),g=Date.now();break}case"step_retry":{let h=D(l),w=d.get(h);w&&(w.retryCount=(l.attempt??1)-1),g=Date.now();break}case"step_retries_exhausted":g=Date.now();break;case"step_skipped":{let w={type:"step",id:D(l),name:l.name,key:l.stepKey,state:"skipped",startTs:l.ts,endTs:l.ts,durationMs:0};k(w);break}case"hook_should_run":{let h={type:"shouldRun",state:"success",ts:l.ts,durationMs:l.durationMs,context:{result:l.result,skipped:l.skipped}};x.shouldRun=h,g=Date.now();break}case"hook_should_run_error":{let h={type:"shouldRun",state:"error",ts:l.ts,durationMs:l.durationMs,error:l.error};x.shouldRun=h,g=Date.now();break}case"hook_before_start":{let h={type:"onBeforeStart",state:"success",ts:l.ts,durationMs:l.durationMs,context:{result:l.result,skipped:l.skipped}};x.onBeforeStart=h,g=Date.now();break}case"hook_before_start_error":{let h={type:"onBeforeStart",state:"error",ts:l.ts,durationMs:l.durationMs,error:l.error};x.onBeforeStart=h,g=Date.now();break}case"hook_after_step":{let h={type:"onAfterStep",state:"success",ts:l.ts,durationMs:l.durationMs,context:{stepKey:l.stepKey}};x.onAfterStep.set(l.stepKey,h),g=Date.now();break}case"hook_after_step_error":{let h={type:"onAfterStep",state:"error",ts:l.ts,durationMs:l.durationMs,error:l.error,context:{stepKey:l.stepKey}};x.onAfterStep.set(l.stepKey,h),g=Date.now();break}}T(l)}function N(l){if(l.type==="scope_start")p.push({id:l.scopeId,name:l.name,type:l.scopeType,startTs:l.ts,children:[]}),g=Date.now();else if(l.type==="scope_end"){let h=p.pop();if(h){let w=h.type==="race"?{type:"race",id:h.id,name:h.name,state:W(h.children),startTs:h.startTs,endTs:l.ts,durationMs:l.durationMs,children:h.children,winnerId:l.winnerId}:{type:"parallel",id:h.id,name:h.name,state:W(h.children),startTs:h.startTs,endTs:l.ts,durationMs:l.durationMs,children:h.children,mode:h.type==="allSettled"?"allSettled":"all"};k(w)}}}function L(l){if(l.type==="decision_start")f.push({id:l.decisionId,name:l.name,condition:l.condition,decisionValue:l.decisionValue,startTs:l.ts,branches:new Map}),g=Date.now();else if(l.type==="decision_branch"){let h=f[f.length-1];if(h&&h.id===l.decisionId){let w=l.branchLabel,_=h.branches.get(w);_?_.taken=l.taken:h.branches.set(w,{label:l.branchLabel,condition:l.condition,taken:l.taken,children:[]}),g=Date.now()}}else if(l.type==="decision_end"){let h=f.pop();if(h&&h.id===l.decisionId){let w=Array.from(h.branches.values()),_={type:"decision",id:h.id,name:h.name,state:W(w.flatMap(P=>P.taken?P.children:[])),startTs:h.startTs,endTs:l.ts,durationMs:l.durationMs,condition:h.condition,decisionValue:h.decisionValue,branchTaken:l.branchTaken??h.branchTaken,branches:w};k(_)}}}function W(l){return l.length===0?"success":l.some(P=>P.state==="error")?"error":l.every(P=>P.state==="success"||P.state==="cached")?"success":l.some(P=>P.state==="running")?"running":"pending"}function S(){let l=[...m];for(let[,h]of d)l.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}});return l}function O(){let l=S();t&&(l=we(l,n));let h={type:"workflow",id:r??ge(),workflowId:r??"unknown",state:a,startTs:s,durationMs:c,children:l,error:u},w=x.shouldRun!==void 0||x.onBeforeStart!==void 0||x.onAfterStep.size>0;return{root:h,metadata:{createdAt:v,lastUpdatedAt:g},...w&&{hooks:x}}}function se(){r=void 0,s=void 0,a="pending",u=void 0,c=void 0,d.clear(),p.length=0,f.length=0,m=[],v=Date.now(),g=v,x={onAfterStep:new Map},y.length=0,$=0}function ae(){return[...y]}function ze(l){return y[l]}function Fe(l){return y[l]?.ir}function Ke(){y.length=0,$=0}return{handleEvent:R,handleScopeEvent:N,handleDecisionEvent:L,getIR:O,reset:se,getSnapshots:ae,getSnapshotAt:ze,getIRAt:Fe,clearSnapshots:Ke,get hasActiveSteps(){return d.size>0},get state(){return a},get snapshotCount(){return y.length},get snapshotsEnabled(){return o}}}function B(e){return e.type==="step"}function Re(e){return e.type==="sequence"}function z(e){return e.type==="parallel"}function H(e){return e.type==="race"}function F(e){return e.type==="decision"}var be="\x1B[0m",Ue="\x1B[1m",$e="\x1B[2m",Ye="\x1B[31m",Je="\x1B[32m",Xe="\x1B[33m",qe="\x1B[34m",Ee="\x1B[90m",Ge="\x1B[37m";function U(e,t){return t?`${t}${e}${be}`:e}function ne(e){return`${Ue}${e}${be}`}function E(e){return`${$e}${e}${be}`}var K={pending:Ge,running:Xe,success:Je,error:Ye,aborted:Ee,cached:qe,skipped:$e+Ee};function Ze(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 re(e,t){let n=Ze(e);return U(n,t[e])}function ve(e,t,n){return U(e,n[t])}function Y(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}var b={topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",teeRight:"\u251C",teeLeft:"\u2524",teeDown:"\u252C",teeUp:"\u2534",cross:"\u253C"},Z={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},Qe="\x1B[0m";function et(e){return e<.2?Z.cold:e<.4?Z.cool:e<.6?Z.neutral:e<.8?Z.warm:e<.95?Z.hot:Z.critical}function Ie(e,t){let n=et(t);return n?`${n}${e}${Qe}`:e}var De="\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";function ke(e,t=10){if(e.length===0)return"";let n=e.slice(-t),o=Math.min(...n),r=Math.max(...n)-o||1;return n.map(s=>{let a=(s-o)/r,u=Math.floor(a*(De.length-1));return De[u]}).join("")}function ye(e,t){let n=Y(e).length,o=Math.max(0,t-n);return e+" ".repeat(o)}function tt(e,t){if(!t)return b.horizontal.repeat(e);let n=` ${t} `,o=e-n.length;if(o<4)return b.horizontal.repeat(e);let i=2,r=o-i;return b.horizontal.repeat(i)+n+b.horizontal.repeat(r)}function Ne(e,t,n){let o=e.state==="success"?U("\u2699",n.success):U("\u26A0",n.error),i=e.durationMs!==void 0?E(` [${C(e.durationMs)}]`):"",r="";e.type==="shouldRun"&&e.context?.skipped?r=E(" \u2192 workflow skipped"):e.type==="shouldRun"&&e.context?.result===!0?r=E(" \u2192 proceed"):e.type==="onBeforeStart"&&e.context?.skipped?r=E(" \u2192 workflow skipped"):e.type==="onAfterStep"&&e.context?.stepKey&&(r=E(` (${e.context.stepKey})`));let s=e.state==="error"&&e.error?E(` error: ${String(e.error)}`):"";return`${o} ${E(t)}${r}${i}${s}`}function nt(e,t){let n=[];return e.shouldRun&&n.push(Ne(e.shouldRun,"shouldRun",t)),e.onBeforeStart&&n.push(Ne(e.onBeforeStart,"onBeforeStart",t)),n.length>0&&n.push(E("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),n}function q(){return{name:"ascii",supportsLive:!0,render(e,t){let n={...K,...t.colors},o=t.terminalWidth??60,i=o-4,r=[],s=e.root.name??"workflow",a=ne(s);if(r.push(`${b.topLeft}${tt(o-2,a)}${b.topRight}`),r.push(`${b.vertical}${" ".repeat(o-2)}${b.vertical}`),e.hooks){let c=nt(e.hooks,n);for(let d of c)r.push(`${b.vertical} ${ye(d,i)}${b.vertical}`)}let u=ce(e.root.children,t,n,0,e.hooks);for(let c of u)r.push(`${b.vertical} ${ye(c,i)}${b.vertical}`);if(r.push(`${b.vertical}${" ".repeat(o-2)}${b.vertical}`),e.root.durationMs!==void 0&&t.showTimings){let c=e.root.state==="success"?"Completed":"Failed",p=`${ve(c,e.root.state,n)} in ${C(e.root.durationMs)}`;r.push(`${b.vertical} ${ye(p,i)}${b.vertical}`),r.push(`${b.vertical}${" ".repeat(o-2)}${b.vertical}`)}return r.push(`${b.bottomLeft}${b.horizontal.repeat(o-2)}${b.bottomRight}`),r.join(`
|
|
2
|
+
`)}}}function ce(e,t,n,o,i){let r=[];for(let s of e)B(s)?r.push(xe(s,t,n,i)):z(s)?r.push(...rt(s,t,n,o,i)):H(s)?r.push(...ot(s,t,n,o,i)):F(s)&&r.push(...it(s,t,n,o,i));return r}function xe(e,t,n,o){let i=re(e.state,n),r=e.name??e.key??"step",s=t,a=e.name??e.id,u=s.showHeatmap&&s.heatmapData?s.heatmapData.heat.get(e.id)??s.heatmapData.heat.get(a):void 0,c;u!==void 0?c=Ie(r,u):c=ve(r,e.state,n);let d=`${i} ${c}`;if(t.showKeys&&e.key&&(d+=E(` [key: ${e.key}]`)),e.input!==void 0){let p=typeof e.input=="string"?e.input:JSON.stringify(e.input).slice(0,30);d+=E(` [in: ${p}${p.length>=30?"...":""}]`)}if(e.output!==void 0&&e.state==="success"){let p=typeof e.output=="string"?e.output:JSON.stringify(e.output).slice(0,30);d+=E(` [out: ${p}${p.length>=30?"...":""}]`)}if(t.showTimings&&e.durationMs!==void 0){let p=C(e.durationMs),f=u!==void 0?Ie(`[${p}]`,u):E(`[${p}]`);d+=` ${f}`}if(s.showSparklines&&s.timingHistory){let p=s.timingHistory.get(a);p&&p.length>1&&(d+=` ${E(ke(p))}`)}if(e.retryCount!==void 0&&e.retryCount>0&&(d+=E(` [${e.retryCount} ${e.retryCount===1?"retry":"retries"}]`)),e.timedOut){let p=e.timeoutMs!==void 0?` ${e.timeoutMs}ms`:"";d+=E(` [timeout${p}]`)}if(o&&e.key&&o.onAfterStep.has(e.key)){let p=o.onAfterStep.get(e.key),f=p.state==="success"?U("\u2699",n.success):U("\u26A0",n.error),m=p.durationMs!==void 0?E(` ${C(p.durationMs)}`):"";d+=` ${f}${m}`}return d}function rt(e,t,n,o,i){let r=[],s=" ".repeat(o),a=re(e.state,n),u=e.name??"parallel",c=e.mode==="allSettled"?" (allSettled)":"";if(r.push(`${s}${b.teeRight}${b.teeDown}${b.horizontal} ${a} ${ne(u)}${c}`),e.children.length===0)r.push(`${s}${b.vertical} ${E("(operations not individually tracked)")}`),r.push(`${s}${b.vertical} ${E("(wrap each operation with step() to see individual steps)")}`);else for(let d=0;d<e.children.length;d++){let p=e.children[d],m=d===e.children.length-1?`${s}${b.vertical} ${b.bottomLeft}`:`${s}${b.vertical} ${b.teeRight}`;if(B(p))r.push(`${m} ${xe(p,t,n,i)}`);else{let v=ce([p],t,n,o+1,i);for(let g of v)r.push(`${s}${b.vertical} ${g}`)}}return t.showTimings&&e.durationMs!==void 0&&r.push(`${s}${b.bottomLeft}${b.horizontal}${b.horizontal} ${E(`[${C(e.durationMs)}]`)}`),r}function ot(e,t,n,o,i){let r=[],s=" ".repeat(o),a=re(e.state,n),u=e.name??"race";if(r.push(`${s}${b.teeRight}\u26A1 ${a} ${ne(u)}`),e.children.length===0)r.push(`${s}${b.vertical} ${E("(operations not individually tracked)")}`),r.push(`${s}${b.vertical} ${E("(wrap each operation with step() to see individual steps)")}`);else for(let c=0;c<e.children.length;c++){let d=e.children[c],f=c===e.children.length-1?`${s}${b.vertical} ${b.bottomLeft}`:`${s}${b.vertical} ${b.teeRight}`,v=e.winnerId&&d.id===e.winnerId?E(" (winner)"):"";if(B(d))r.push(`${f} ${xe(d,t,n,i)}${v}`);else{let g=ce([d],t,n,o+1,i);for(let x of g)r.push(`${s}${b.vertical} ${x}`)}}return t.showTimings&&e.durationMs!==void 0&&r.push(`${s}${b.bottomLeft}${b.horizontal}${b.horizontal} ${E(`[${C(e.durationMs)}]`)}`),r}function it(e,t,n,o,i){let r=[],s=" ".repeat(o),a=re(e.state,n),u=e.name??"decision",c=e.condition?E(` (${e.condition})`):"",d=e.decisionValue!==void 0?E(` = ${String(e.decisionValue)}`):"",p=e.branchTaken!==void 0?E(` \u2192 ${String(e.branchTaken)}`):"";r.push(`${s}${b.teeRight}${b.teeDown}${b.horizontal} ${a} ${ne(u)}${c}${d}${p}`);for(let f=0;f<e.branches.length;f++){let m=e.branches[f],g=f===e.branches.length-1?`${s}${b.vertical} ${b.bottomLeft}`:`${s}${b.vertical} ${b.teeRight}`,x=m.taken?"\u2713":"\u2298",y=m.taken?n.success:n.skipped,$=U(`${x} ${m.label}`,y),D=m.condition?E(` (${m.condition})`):"";if(r.push(`${g} ${$}${D}`),m.children.length>0){let k=ce(m.children,t,n,o+1,i);for(let T of k)r.push(`${s}${b.vertical} ${T}`)}else m.taken||r.push(`${s}${b.vertical} ${E("(skipped)")}`)}return t.showTimings&&e.durationMs!==void 0&&r.push(`${s}${b.bottomLeft}${b.horizontal}${b.horizontal} ${E(`[${C(e.durationMs)}]`)}`),r}function oe(e){return e<.2?"cold":e<.4?"cool":e<.6?"neutral":e<.8?"warm":e<.95?"hot":"critical"}function st(){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"]}function at(){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 ct(e){return`heat_${e}`}function dt(){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 lt(e,t,n){let o;if(e.shouldRun){let i="hook_shouldRun",r=e.shouldRun.state==="success"?"hook_success":"hook_error",s=e.shouldRun.state==="success"?"\u2699":"\u26A0",a=n.showTimings&&e.shouldRun.durationMs!==void 0?` ${C(e.shouldRun.durationMs)}`:"",u=e.shouldRun.context?.skipped?"\\nskipped workflow":e.shouldRun.context?.result===!0?"\\nproceed":"";t.push(` ${i}[["${s} shouldRun${u}${a}"]]:::${r}`),o=i}if(e.onBeforeStart){let i="hook_beforeStart",r=e.onBeforeStart.state==="success"?"hook_success":"hook_error",s=e.onBeforeStart.state==="success"?"\u2699":"\u26A0",a=n.showTimings&&e.onBeforeStart.durationMs!==void 0?` ${C(e.onBeforeStart.durationMs)}`:"",u=e.onBeforeStart.context?.skipped?"\\nskipped workflow":"";t.push(` ${i}[["${s} onBeforeStart${u}${a}"]]:::${r}`),o&&t.push(` ${o} --> ${i}`),o=i}return{lastHookId:o}}var Me=0;function ie(e="node"){return`${e}_${++Me}`}function ut(){Me=0}function A(e){return e.replace(/[{}[\]()]/g,"").replace(/[<>]/g,"").replace(/"/g,"'").trim()}function Te(e){return A(e).replace(/[[\]]/g,"")}function de(){return{name:"mermaid",supportsLive:!1,render(e,t){ut();let n=[],o=t;n.push("flowchart TD");let i;e.hooks&&(i=lt(e.hooks,n,t).lastHookId);let r="start";n.push(` ${r}(("\u25B6 Start"))`),i&&n.push(` ${i} --> ${r}`);let s=r;for(let a of e.root.children){let u=le(a,t,n,o,e.hooks);n.push(` ${s} --> ${u.entryId}`),s=u.exitId}if(e.root.state==="success"||e.root.state==="error"){let a="finish",u=e.root.state==="success"?"\u2713":"\u2717",c=e.root.state==="success"?"Done":"Failed",d=`(("${u} ${c}"))`,p=e.root.state==="success"?":::success":":::error";n.push(` ${a}${d}${p}`),n.push(` ${s} --> ${a}`)}return n.push(""),n.push(...st()),o.showHeatmap&&n.push(...at()),e.hooks&&n.push(...dt()),n.join(`
|
|
3
|
+
`)}}}function le(e,t,n,o,i){if(B(e))return pt(e,t,n,o,i);if(z(e))return ft(e,t,n,o,i);if(H(e))return mt(e,t,n,o,i);if(F(e))return ht(e,t,n,o,i);let r=ie("unknown");return n.push(` ${r}[Unknown Node]`),{entryId:r,exitId:r}}function pt(e,t,n,o,i){let r=t,s=r.showRetryEdges??!0,a=r.showErrorEdges??!0,u=r.showTimeoutEdges??!0,c=e.key?`step_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ie("step"),d=A(e.name??e.key??"Step"),p=t.showTimings&&e.durationMs!==void 0?` ${C(e.durationMs)}`:"",f="";switch(e.state){case"success":f="\u2713 ";break;case"error":f="\u2717 ";break;case"cached":f="\u{1F4BE} ";break;case"running":f="\u23F3 ";break;case"skipped":f="\u2298 ";break}let m="";if(e.input!==void 0){let k=typeof e.input=="string"?A(e.input):A(JSON.stringify(e.input).slice(0,20));m+=`\\nin: ${k}`}if(e.output!==void 0&&e.state==="success"){let k=typeof e.output=="string"?A(e.output):A(JSON.stringify(e.output).slice(0,20));m+=`\\nout: ${k}`}let v="";if(i&&e.key&&i.onAfterStep.has(e.key)){let k=i.onAfterStep.get(e.key),T=k.state==="success"?"\u2699":"\u26A0",R=t.showTimings&&k.durationMs!==void 0?` ${C(k.durationMs)}`:"";v=`\\n${T} hook${R}`}let g=(f+d+m+v+p).trim(),x,y=e.name??e.id,$=o?.showHeatmap&&o.heatmapData?o.heatmapData.heat.get(e.id)??o.heatmapData.heat.get(y):void 0;if($!==void 0){let k=oe($);x=ct(k)}else x=e.state;let D;switch(e.state){case"error":D=`{{${g}}}`;break;case"cached":D=`[(${g})]`;break;case"skipped":D=`[${g}]:::skipped`;break;default:D=`[${g}]`}if(n.push(` ${c}${D}:::${x}`),s&&e.retryCount!==void 0&&e.retryCount>0){let k=`\u21BB ${e.retryCount} retr${e.retryCount===1?"y":"ies"}`;n.push(` ${c} -.->|"${k}"| ${c}`)}if(a&&e.state==="error"&&e.error!==void 0){let k=`ERR_${c}`,T=A(String(e.error)).slice(0,30);n.push(` ${k}{{${T}}}`),n.push(` ${c} -->|error| ${k}`),n.push(` style ${k} fill:#fee2e2,stroke:#dc2626`)}if(u&&e.timedOut){let k=`TO_${c}`,T=e.timeoutMs!==void 0?`${e.timeoutMs}ms`:"";n.push(` ${k}{{\u23F1 Timeout ${T}}}`),n.push(` ${c} -.->|timeout| ${k}`),n.push(` style ${k} fill:#fef3c7,stroke:#f59e0b`)}return{entryId:c,exitId:c}}function ft(e,t,n,o,i){let r=ie("parallel"),s=`${r}_fork`,a=`${r}_join`,u=Te(e.name??"Parallel"),c=e.mode==="allSettled"?" (allSettled)":"";if(e.children.length===0){let f=r,m=A(`${u}${c}`),v="operations not individually tracked",g=t.showTimings&&e.durationMs!==void 0?` ${C(e.durationMs)}`:"";return n.push(` ${f}[${m}${g}\\n${v}]:::${e.state}`),{entryId:f,exitId:f}}n.push(` subgraph ${r}["${u}${c}"]`),n.push(" direction TB"),n.push(` ${s}{"\u26A1 Fork"}`);let d=[];for(let f of e.children){let m=le(f,t,n,o,i);n.push(` ${s} --> ${m.entryId}`),d.push(m.exitId)}n.push(` ${a}{"\u2713 Join"}`);for(let f of d)n.push(` ${f} --> ${a}`);n.push(" end");let p=e.state;return n.push(` class ${r} ${p}`),{entryId:s,exitId:a}}function mt(e,t,n,o,i){let r=ie("race"),s=`${r}_start`,a=`${r}_end`,u=Te(e.name??"Race");if(e.children.length===0){let f=r,m=A(u),v="operations not individually tracked",g=t.showTimings&&e.durationMs!==void 0?` ${C(e.durationMs)}`:"";return n.push(` ${f}[\u26A1 ${m}${g}\\n${v}]:::${e.state}`),{entryId:f,exitId:f}}n.push(` subgraph ${r}["\u26A1 ${u}"]`),n.push(" direction TB"),n.push(` ${s}(("\u{1F3C1} Start"))`);let c=[],d;for(let f of e.children){let m=le(f,t,n,o,i),v=B(f)&&e.winnerId===f.id;n.push(` ${s} --> ${m.entryId}`),v&&(d=m.exitId),c.push({exitId:m.exitId,isWinner:v})}n.push(` ${a}(("\u2713 First"))`);for(let{exitId:f,isWinner:m}of c)m&&d?n.push(` ${f} ==>|\u{1F3C6} Winner| ${a}`):e.winnerId?n.push(` ${f} -. cancelled .-> ${a}`):n.push(` ${f} --> ${a}`);n.push(" end");let p=e.state;return n.push(` class ${r} ${p}`),{entryId:s,exitId:a}}function ht(e,t,n,o,i){let r=e.key?`decision_${e.key.replace(/[^a-zA-Z0-9]/g,"_")}`:ie("decision"),s=A(e.condition??"condition"),a=e.decisionValue!==void 0?` = ${A(String(e.decisionValue)).slice(0,30)}`:"",u=`${s}${a}`.trim();n.push(` ${r}{${u}}`);let c=[],d;for(let p of e.branches){let f=`${r}_${p.label.replace(/[^a-zA-Z0-9]/g,"_")}`,m=A(p.label),v=p.taken?`${m} \u2713`:`${m} skipped`,g=p.taken?":::success":":::skipped";n.push(` ${f}[${v}]${g}`);let x=p.condition?`|${A(p.condition).replace(/\|/g,"")}|`:"";if(n.push(` ${r} -->${x} ${f}`),p.children.length>0){let y=f;for(let $ of p.children){let D=le($,t,n,o,i);n.push(` ${y} --> ${D.entryId}`),y=D.exitId}c.push(y),p.taken&&(d=y)}else c.push(f),p.taken&&(d=f)}return d?{entryId:r,exitId:d}:{entryId:r,exitId:r}}var I={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"},gt={cold:"\x1B[34m",cool:"\x1B[36m",neutral:"",warm:"\x1B[33m",hot:"\x1B[31m",critical:"\x1B[41m"},wt="\x1B[0m";function bt(e,t){let n=[],o=[];for(let i=0;i<t;i++)n.push(Array(e).fill(" ")),o.push(Array(e).fill(void 0));return{cells:n,colors:o,width:e,height:t}}function M(e,t,n,o,i){t>=0&&t<e.width&&n>=0&&n<e.height&&(e.cells[n][t]=o,i&&(e.colors[n][t]=i))}function Ce(e,t,n){return t>=0&&t<e.width&&n>=0&&n<e.height?e.cells[n][t]:" "}function vt(e,t,n,o,i){M(e,t,n,I.topLeft);for(let r=1;r<o-1;r++)M(e,t+r,n,I.horizontal);M(e,t+o-1,n,I.topRight);for(let r=1;r<i-1;r++)M(e,t,n+r,I.vertical),M(e,t+o-1,n+r,I.vertical);M(e,t,n+i-1,I.bottomLeft);for(let r=1;r<o-1;r++)M(e,t+r,n+i-1,I.horizontal);M(e,t+o-1,n+i-1,I.bottomRight)}function Le(e,t,n,o,i){let r=Y(o).split("");for(let s=0;s<r.length;s++)M(e,t+s,n,r[s],i)}function V(e,t,n,o){let i=Math.min(n,o),r=Math.max(n,o);for(let s=i;s<=r;s++){let a=Ce(e,t,s);a===I.horizontal?M(e,t,s,I.cross):(a===" "||a===I.vertical)&&M(e,t,s,I.vertical)}}function Oe(e,t,n,o){let i=Math.min(n,o),r=Math.max(n,o);for(let s=i;s<=r;s++){let a=Ce(e,s,t);a===I.vertical?M(e,s,t,I.cross):(a===" "||a===I.horizontal)&&M(e,s,t,I.horizontal)}}function G(e,t,n){M(e,t,n,I.arrowDown)}function yt(e){let t=[];for(let n=0;n<e.height;n++){let o="";for(let i=0;i<e.width;i++){let r=e.colors[n][i],s=e.cells[n][i];r?o+=r+s+wt:o+=s}t.push(o.trimEnd())}for(;t.length>0&&t[t.length-1]==="";)t.pop();return t.join(`
|
|
4
|
+
`)}var j=11,J=2,Q=2,ue=3;function _e(e,t){if(e.length<=t)return[e];let n=e.split(" "),o=[],i="";for(let r of n)i?i.length+1+r.length<=t?i+=" "+r:(o.push(i),i=r):i=r;if(i&&o.push(i),o.length===0)for(let r=0;r<e.length;r+=t)o.push(e.slice(r,r+t));return o}function We(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 kt(e,t,n){let o=t.showStartEnd??!0,i=t,r=Math.floor(n/2),s=[],a=0;if(o){let u=pe("start","start",["\u25B6 Start"],"success",r,a);s.push(u),a=u.bottomY+Q}for(let u of e.root.children){let c=fe(u,r,a,n-4,t,i);s.push(c.node),a=c.bottomY+Q}if(o&&(e.root.state==="success"||e.root.state==="error")){let u=e.root.state==="success"?"\u2713 Done":"\u2717 Failed",c=pe("end","end",[u],e.root.state,r,a);s.push(c),a=c.bottomY}return{nodes:s,totalHeight:a+2}}function pe(e,t,n,o,i,r){let s=Math.max(...n.map(d=>Y(d).length)),a=Math.max(j,s+J*2),u=n.length+2,c=i-Math.floor(a/2);return{id:e,type:t,label:n,state:o,x:c,y:r,width:a,height:u,centerX:i,bottomY:r+u-1}}function fe(e,t,n,o,i,r){if(B(e))return xt(e,t,n,o,i,r);if(z(e)||H(e))return St(e,t,n,o,i,r);if(F(e))return Rt(e,t,n,o,i,r);let s=pe(e.id,"step",["?"],e.state,t,n);return{node:s,bottomY:s.bottomY}}function xt(e,t,n,o,i,r){let s=e.name??e.key??"step",a=We(e.state),u=[],c=`${a} ${s}`,d=Math.min(o-J*2,40);if(u.push(..._e(c,d)),i.showTimings&&e.durationMs!==void 0&&u.push(`[${C(e.durationMs)}]`),e.retryCount&&e.retryCount>0&&u.push(`${e.retryCount}x retry`),e.timedOut&&u.push("timeout"),r?.showSparklines&&r.timingHistory){let y=e.name??e.id,$=r.timingHistory.get(y);$&&$.length>1&&u.push(ke($,8))}let p=Math.max(...u.map(y=>Y(y).length)),f=Math.max(j,p+J*2),m=u.length+2,v=t-Math.floor(f/2),g;if(r?.showHeatmap&&r.heatmapData){let y=e.name??e.id;g=r.heatmapData.heat.get(e.id)??r.heatmapData.heat.get(y)}let x={id:e.id,type:"step",label:u,state:e.state,x:v,y:n,width:f,height:m,centerX:t,bottomY:n+m-1,metadata:g!==void 0?{heat:g}:void 0};return{node:x,bottomY:x.bottomY}}function St(e,t,n,o,i,r){let s=H(e),a=e.name??(s?"race":"parallel"),c=`${s?"\u26A1":"\u2AD8"} ${a}`;if(e.children.length===0){let N=[c,"(not tracked)"],L=pe(e.id,s?"race":"parallel",N,e.state,t,n);return{node:L,bottomY:L.bottomY}}let d=Math.floor((o-ue*(e.children.length-1))/e.children.length),p=[];for(let N of e.children){let L=Se(N,Math.max(d,j),i,r);p.push(L.width)}let f=p.reduce((N,L)=>N+L,0)+ue*(e.children.length-1),m=f>o&&e.children.length>1,v=Math.max(j,c.length+J*2),g=3,x=t-Math.floor(v/2),y=n;y+=g,y+=1,y+=1;let $=[];if(m)for(let N=0;N<e.children.length;N++){let L=e.children[N],W=fe(L,t,y,o,i,r);s&&H(e)&&e.winnerId===L.id&&(W.node.metadata={...W.node.metadata,isWinner:!0}),$.push(W.node),y=W.bottomY+Q}else{let N=t-Math.floor(f/2);for(let L=0;L<e.children.length;L++){let W=e.children[L],S=N+Math.floor(p[L]/2),O=fe(W,S,y,p[L],i,r);s&&H(e)&&e.winnerId===W.id&&(O.node.metadata={...O.node.metadata,isWinner:!0}),$.push(O.node),N+=p[L]+ue}}let D=Math.max(...$.map(N=>N.bottomY)),T=!m&&$.length>1?D+2:D;return{node:{id:e.id,type:s?"race":"parallel",label:[c],state:e.state,x,y:n,width:v,height:g,centerX:t,bottomY:T,children:$,metadata:{verticalLayout:m}},bottomY:T}}function Rt(e,t,n,o,i,r){let s=e.name??"decision",a=e.condition?` (${e.condition.slice(0,20)})`:"",u=`\u25C7 ${s}${a}`,c=Math.min(o-J*2,40),d=_e(u,c),p=Math.max(...d.map(k=>Y(k).length)),f=Math.max(j,p+J*2),m=d.length+2,v=t-Math.floor(f/2),g=e.branches.find(k=>k.taken);if(!g||g.children.length===0){let k={id:e.id,type:"decision",label:d,state:e.state,x:v,y:n,width:f,height:m,centerX:t,bottomY:n+m-1};return{node:k,bottomY:k.bottomY}}let x=n+m+Q,y=[];for(let k of g.children){let T=fe(k,t,x,o,i,r);y.push(T.node),x=T.bottomY+Q}let $=y.length>0?y[y.length-1].bottomY:n+m-1;return{node:{id:e.id,type:"decision",label:d,state:e.state,x:v,y:n,width:f,height:m,centerX:t,bottomY:$,children:y},bottomY:$}}function Se(e,t,n,o){if(B(e)){let i=e.name??e.key??"step",r=We(e.state),s=1;n.showTimings&&e.durationMs!==void 0&&s++,e.retryCount&&e.retryCount>0&&s++,e.timedOut&&s++,o?.showSparklines&&o.timingHistory?.has(e.name??e.id)&&s++;let a=Math.min(t,Math.max(j,`${r} ${i}`.length+J*2)),u=s+2;return{width:a,height:u}}if(z(e)||H(e)){if(e.children.length===0)return{width:j+4,height:4};let i=Math.floor(t/e.children.length),r=0,s=0;for(let a of e.children){let u=Se(a,i,n,o);r+=u.width,s=Math.max(s,u.height)}return r+=ue*(e.children.length-1),{width:Math.max(r,j),height:5+s+2}}if(F(e)){let i=e.branches.find(s=>s.taken),r=0;if(i)for(let s of i.children){let a=Se(s,t,n,o);r+=a.height+Q}return{width:Math.min(t,30),height:3+r}}return{width:j,height:3}}function Et(e,t,n){let o={...K,...n.colors};for(let i=0;i<t.length;i++){let r=t[i],s=i===t.length-1;if(me(e,r,o),!s){let a=t[i+1],u=r.centerX,c=r.bottomY+1,d=a.centerX,p=a.y-1;V(e,u,c,p-1),G(e,d,p)}}}function me(e,t,n){let o=t.type!=="start",i=t.type!=="end"&&(!t.children||t.children.length===0);vt(e,t.x,t.y,t.width,t.height),o&&M(e,t.centerX,t.y,I.teeUp),(i||t.children&&t.children.length>0)&&M(e,t.centerX,t.y+t.height-1,I.teeDown);let r=t.width-J*2,s=Dt(t,n);for(let a=0;a<t.label.length;a++){let u=t.label[a],c=t.x+1+Math.floor((r-Y(u).length)/2),d=t.y+1+a;Le(e,c,d,u,s)}t.metadata?.isWinner&&Le(e,t.x+t.width-2,t.y,"\u{1F3C6}"),t.children&&t.children.length>0&&(t.type==="parallel"||t.type==="race"?$t(e,t,n):It(e,t,n))}function $t(e,t,n){let o=t.children;if(o.length===0)return;let i=t.y+t.height,r=t.centerX;if(t.metadata?.verticalLayout===!0){let a=o[0];V(e,r,i,a.y-2),G(e,a.centerX,a.y-1);for(let u=0;u<o.length;u++){let c=o[u];if(me(e,c,n),u<o.length-1){let d=o[u+1];V(e,c.centerX,c.bottomY+1,d.y-2),G(e,d.centerX,d.y-1)}}return}if(o.length===1)V(e,r,i,o[0].y-2),G(e,o[0].centerX,o[0].y-1);else{let a=o.map(d=>d.centerX),u=Math.min(...a),c=Math.max(...a);V(e,r,i,i+1),Oe(e,i+1,u,c),M(e,r,i+1,I.teeUp);for(let d of o){let p=d.centerX;p===u?M(e,p,i+1,I.topLeft):p===c?M(e,p,i+1,I.topRight):p!==r&&M(e,p,i+1,I.teeDown),V(e,p,i+2,d.y-2),G(e,p,d.y-1)}}for(let a of o)me(e,a,n);if(o.length>1){let a=o.map(m=>m.bottomY),u=Math.max(...a),c=u+1,d=o.map(m=>m.centerX),p=Math.min(...d),f=Math.max(...d);for(let m of o)m.bottomY<u&&V(e,m.centerX,m.bottomY+1,c-1);Oe(e,c,p,f);for(let m of o){let v=m.centerX;v===p?M(e,v,c,I.bottomLeft):v===f?M(e,v,c,I.bottomRight):M(e,v,c,I.teeUp)}M(e,t.centerX,c,I.teeDown),M(e,t.centerX,c+1,I.vertical)}}function It(e,t,n){let o=t.children;if(o.length===0)return;let i=t.y+t.height,r=o[0];V(e,t.centerX,i,r.y-2),G(e,r.centerX,r.y-1);for(let s=0;s<o.length;s++){let a=o[s];if(me(e,a,n),s<o.length-1){let u=o[s+1];V(e,a.centerX,a.bottomY+1,u.y-2),G(e,u.centerX,u.y-1)}}}function Dt(e,t){if(e.metadata?.heat!==void 0){let n=oe(e.metadata.heat);return gt[n]||void 0}return t[e.state]||void 0}function ee(){return{name:"flowchart",supportsLive:!1,render(e,t){let n=t.terminalWidth??80,{nodes:o,totalHeight:i}=kt(e,t,n),r=bt(n,i);return Et(r,o,t),yt(r)}}}function Nt(e){return e.replace(/\x1b\[[0-9;]*m/g,"")}function Mt(e){let t=[];function n(o){for(let i of o)if(B(i))t.push(i);else if(Re(i))n(i.children);else if(z(i)||H(i))n(i.children);else if(F(i))for(let r of i.branches)n(r.children)}return n(e),t}function Tt(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 Lt(e){let t=0,n=0,o=0,i=0,r=0,s;for(let a of e)a.state==="success"&&t++,a.state==="error"&&n++,a.state==="cached"&&o++,a.state==="skipped"&&i++,a.retryCount!==void 0&&(r+=a.retryCount),a.durationMs!==void 0&&(!s||a.durationMs>s.durationMs)&&(s={name:a.name??a.key??a.id,durationMs:a.durationMs});return{totalSteps:e.length,successCount:t,errorCount:n,cacheHits:o,skippedCount:i,totalRetries:r,slowestStep:s}}function Ot(e){let t={};if(e.shouldRun&&(t.shouldRun={result:e.shouldRun.context?.result,durationMs:e.shouldRun.durationMs},e.shouldRun.error&&(t.shouldRun.error=String(e.shouldRun.error))),e.onBeforeStart&&(t.onBeforeStart={durationMs:e.onBeforeStart.durationMs},e.onBeforeStart.error&&(t.onBeforeStart.error=String(e.onBeforeStart.error))),e.onAfterStep.size>0){t.onAfterStep=[];for(let[n,o]of e.onAfterStep){let i={stepKey:n};o.durationMs!==void 0&&(i.durationMs=o.durationMs),o.error&&(i.error=String(o.error)),t.onAfterStep.push(i)}}return t}function Ct(e,t){let n=e.root,o=Mt(n.children),i=t.includeDiagram??!0,r=t.stripAnsiColors??!0,s={workflow:{id:n.workflowId,name:n.name,state:n.state,durationMs:n.durationMs,startedAt:n.startTs,completedAt:n.endTs},steps:o.map(Tt),summary:Lt(o)};if(e.hooks){let a=Ot(e.hooks);Object.keys(a).length>0&&(s.hooks=a)}if(i){let c=((t.diagramFormat??"ascii")==="flowchart"?ee():q()).render(e,t);r&&(c=Nt(c)),s.diagram=c}return s}function he(){return{name:"logger",supportsLive:!1,render(e,t){let o=Ct(e,t);return JSON.stringify(o)}}}import{createServer as An}from"http";import{execFile as zn}from"child_process";function Be(e={}){let{workflowName:t,detectParallel:n=!0,showTimings:o=!0,showKeys:i=!1,colors:r}=e,s=te({detectParallel:n}),a=new Set,u=q(),c=de(),d=he(),p=ee(),f={showTimings:o,showKeys:i,terminalWidth:process.stdout?.columns??80,colors:{...K,...r}};function m(){if(a.size>0){let R=s.getIR();for(let N of a)N(R)}}function v(R){if(R.type==="scope_start"||R.type==="scope_end"){g(R);return}s.handleEvent(R),R.type,m()}function g(R){s.handleScopeEvent(R),m()}function x(R){s.handleDecisionEvent(R),m()}function y(){let R=s.getIR();return t&&!R.root.name&&(R.root.name=t),R}function $(){let R=y();return u.render(R,f)}function D(R){let N=y();switch(R){case"ascii":return u.render(N,f);case"mermaid":return c.render(N,f);case"json":return JSON.stringify(N,null,2);case"logger":return d.render(N,f);case"flowchart":return p.render(N,f);default:throw new Error(`Unknown format: ${R}`)}}function k(){s.reset(),m()}function T(R){return a.add(R),()=>a.delete(R)}return{handleEvent:v,handleScopeEvent:g,handleDecisionEvent:x,getIR:y,render:$,renderAs:D,reset:k,onUpdate:T}}function Pe(e={}){let{logEvents:t=!1,maxHistory:n=10,logger:o=console.log}=e,i=Be(e),r=[],s,a=0;function u(S){if(s)for(r.push(s);r.length>n;)r.shift();a=Date.now(),s={id:S,name:e.workflowName,startTime:a,events:[]},i.reset()}function c(S,O){s&&(s.endTime=Date.now(),s.durationMs=s.endTime-s.startTime,s.success=S,s.error=O)}function d(S){t&&o(`[devtools] ${S.type}: ${JSON.stringify(S)}`),S.type==="workflow_start"&&u(S.workflowId),s&&s.events.push(S),i.handleEvent(S),S.type==="workflow_success"?c(!0):S.type==="workflow_error"&&c(!1,S.error)}function p(S){t&&o(`[devtools] ${S.type}: ${JSON.stringify(S)}`),s&&s.events.push(S),i.handleDecisionEvent(S)}function f(){return s}function m(){return[...r]}function v(S){return s?.id===S?s:r.find(O=>O.id===S)}function g(S,O){let se=v(S),ae=v(O);if(!(!se||!ae))return He(se,ae)}function x(){if(!s||r.length===0)return;let S=r[r.length-1];return He(S,s)}function y(){return i.render()}function $(S){return i.renderAs(S)}function D(){return i.renderAs("mermaid")}function k(){let S=T();return At(S)}function T(){return s?Ht(s.events,a):[]}function R(){r.length=0}function N(){s=void 0,i.reset()}function L(S){let O=S?v(S):s;return O?JSON.stringify(O,null,2):"{}"}function W(S){let O=JSON.parse(S);return r.push(O),O}return{handleEvent:d,handleDecisionEvent:p,getCurrentRun:f,getHistory:m,getRun:v,diff:g,diffWithPrevious:x,render:y,renderAs:$,renderMermaid:D,renderTimeline:k,getTimeline:T,clearHistory:R,reset:N,exportRun:L,importRun:W}}function He(e,t){let n=Ae(e.events),o=Ae(t.events),i=[],r=[],s=[],a=[];for(let[f,m]of o){let v=n.get(f);v?v.status!==m.status?s.push({step:f,type:"status",from:v.status,to:m.status}):v.durationMs!==m.durationMs?s.push({step:f,type:"duration",from:v.durationMs,to:m.durationMs}):a.push(f):i.push({step:f,type:"added",to:m.status})}for(let[f]of n)o.has(f)||r.push({step:f,type:"removed",from:n.get(f)?.status});let u,c=e.success===void 0?"running":e.success?"success":"error",d=t.success===void 0?"running":t.success?"success":"error";c!==d&&(u={from:c,to:d});let p;return e.durationMs!==void 0&&t.durationMs!==void 0&&(p=t.durationMs-e.durationMs),{added:i,removed:r,changed:s,unchanged:a,statusChange:u,durationChange:p}}function Ae(e){let t=new Map;for(let n of e)if(n.type==="step_start"){let o=n,i=o.name||o.stepKey||o.stepId;t.set(i,{name:i,key:o.stepKey,status:"running"})}else if(n.type==="step_success"){let o=n,i=o.name||o.stepKey||o.stepId,r=t.get(i);r&&(r.status="success",r.durationMs=o.durationMs)}else if(n.type==="step_error"){let o=n,i=o.name||o.stepKey||o.stepId,r=t.get(i);r&&(r.status="error",r.durationMs=o.durationMs,r.error=o.error)}else if(n.type==="step_cache_hit"){let o=n,i=o.name||o.stepKey;t.set(i,{name:i,key:o.stepKey,status:"cached"})}else if(n.type==="step_skipped"){let o=n,i=o.name||o.stepKey||"unknown";t.set(i,{name:i,key:o.stepKey,status:"skipped"})}return t}function Ht(e,t){let n=[],o=new Map;for(let i of e)if(i.type==="step_start"){let r=i,s=r.name||r.stepKey||r.stepId;o.set(s,r.ts),n.push({name:s,key:r.stepKey,startMs:r.ts-t,status:"running"})}else if(i.type==="step_success"){let r=i,s=r.name||r.stepKey||r.stepId,a=n.find(u=>u.name===s&&u.status==="running");a&&(a.endMs=r.ts-t,a.durationMs=r.durationMs,a.status="success")}else if(i.type==="step_error"){let r=i,s=r.name||r.stepKey||r.stepId,a=n.find(u=>u.name===s&&u.status==="running");a&&(a.endMs=r.ts-t,a.durationMs=r.durationMs,a.status="error",a.error=r.error)}else if(i.type==="step_cache_hit"){let r=i,s=r.name||r.stepKey;n.push({name:s,key:r.stepKey,startMs:r.ts-t,endMs:r.ts-t,durationMs:0,status:"cached"})}else if(i.type==="step_skipped"){let r=i,s=r.name||r.stepKey||"unknown";n.push({name:s,key:r.stepKey,startMs:r.ts-t,endMs:r.ts-t,durationMs:0,status:"skipped"})}return n}function At(e){if(e.length===0)return"No timeline data";let t=[];t.push("Timeline:"),t.push("\u2500".repeat(60));let n=Math.max(...e.map(i=>i.endMs??i.startMs+100)),o=40;for(let i of e){let r=Math.floor(i.startMs/n*o),s=Math.floor((i.endMs??i.startMs+10)/n*o),a=Math.max(1,s-r),u=Pt(i.status),c=" ".repeat(r)+u.repeat(a),d=i.durationMs!==void 0?`${i.durationMs}ms`:"?";t.push(`${i.name.padEnd(20)} |${c.padEnd(o)}| ${d}`)}return t.push("\u2500".repeat(60)),t.join(`
|
|
5
|
+
`)}function Pt(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 zt(e){let t=[];if(e.statusChange&&t.push(`Status: ${e.statusChange.from} \u2192 ${e.statusChange.to}`),e.durationChange!==void 0){let n=e.durationChange>=0?"+":"";t.push(`Duration: ${n}${e.durationChange}ms`)}if(e.added.length>0){t.push(`
|
|
6
|
+
Added steps:`);for(let n of e.added)t.push(` + ${n.step}`)}if(e.removed.length>0){t.push(`
|
|
7
|
+
Removed steps:`);for(let n of e.removed)t.push(` - ${n.step}`)}if(e.changed.length>0){t.push(`
|
|
8
|
+
Changed steps:`);for(let n of e.changed)t.push(` ~ ${n.step}: ${n.from} \u2192 ${n.to}`)}return e.unchanged.length>0&&t.push(`
|
|
9
|
+
Unchanged: ${e.unchanged.length} steps`),t.join(`
|
|
10
|
+
`)}function Ft(e,t={}){let n=Pe(t);return e(n.handleEvent).then(()=>n.render())}function Kt(e={}){let{prefix:t="[workflow]",colors:n=!0}=e,o=n?{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 i=>{let r=new Date().toISOString().slice(11,23),s="";switch(i.type){case"workflow_start":s=`${o.blue}\u23F5 Workflow started${o.reset}`;break;case"workflow_success":s=`${o.green}\u2713 Workflow completed${o.reset} ${o.dim}(${i.durationMs}ms)${o.reset}`;break;case"workflow_error":s=`${o.red}\u2717 Workflow failed${o.reset}`;break;case"step_start":s=`${o.cyan}\u2192 ${i.name||i.stepKey||i.stepId}${o.reset}`;break;case"step_success":s=`${o.green}\u2713 ${i.name||i.stepKey||i.stepId}${o.reset} ${o.dim}(${i.durationMs}ms)${o.reset}`;break;case"step_error":s=`${o.red}\u2717 ${i.name||i.stepKey||i.stepId}${o.reset}`;break;case"step_cache_hit":s=`${o.yellow}\u26A1 ${i.name||i.stepKey} (cached)${o.reset}`;break;case"step_retry":s=`${o.yellow}\u21BB ${i.name||i.stepKey||i.stepId} retry ${i.attempt}/${i.maxAttempts}${o.reset}`;break;default:s=`${o.dim}${i.type}${o.reset}`}console.log(`${o.dim}${r}${o.reset} ${t} ${s}`)}}export{Kt as createConsoleLogger,Pe as createDevtools,Ft as quickVisualize,zt as renderDiff};
|
|
11
|
+
//# sourceMappingURL=devtools.js.map
|