@jive-sh/workflow-platform 0.4.0 → 0.5.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/README.md +8 -6
- package/dist/dashboard/drilldown.js +2 -2
- package/dist/dashboard/drilldown.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/steps.js +48 -26
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +4 -0
- package/dist/storage/sqlite-store.js.map +1 -1
- package/dist/views/runs-now.js +1 -1
- package/dist/views/runs-now.js.map +1 -1
- package/dist/views/step-funnel.js +1 -1
- package/dist/views/step-funnel.js.map +1 -1
- package/dist/views/step-graph.js +1 -1
- package/dist/views/step-graph.js.map +1 -1
- package/dist/views/workflow-flows.js +53 -0
- package/dist/views/workflow-flows.js.map +1 -0
- package/dist/views/workflows-view.js +15 -6
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/dashboard/dashboard.css +13 -1
- package/src/dashboard/drilldown.ts +2 -3
- package/src/dashboard/step-graph.tsx +18 -10
- package/src/dashboard/workflow-dag.tsx +204 -0
- package/src/dashboard/workflows-dashboard.tsx +19 -9
- package/src/index.ts +1 -0
- package/src/steps.ts +72 -39
- package/src/storage/sqlite-store.ts +11 -1
- package/src/storage/task-store.ts +23 -0
- package/src/views/runs-now.ts +2 -2
- package/src/views/step-funnel.ts +2 -2
- package/src/views/step-graph.ts +4 -4
- package/src/views/workflow-flows.ts +97 -0
- package/src/views/workflows-view.ts +29 -13
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* THE PROJECT'S WORKFLOWS AS A DAG, laid out by ELK's layered algorithm (`elkjs`, which the host page brings, as it brings
|
|
5
|
+
* React): each workflow one node, in layers in topological order of the forward edges, so every forward arrow points down;
|
|
6
|
+
* each stage's layers kept together (ELK's partitions, one per stage in the project's order) and shown as a band named in
|
|
7
|
+
* a gutter on the left that no edge enters. Edges are routed orthogonally around the nodes, each with its label beside its
|
|
8
|
+
* own line and its arrowhead at its target. A send-back, the only edge against the flow, is routed apart by ELK as a feedback
|
|
9
|
+
* edge, dashed and labelled "sends back". A box's name opens that workflow's own level. Workflows no work flows to or from are not drawn: the list of steps under the map has them.
|
|
10
|
+
*
|
|
11
|
+
* Chosen over dagre (`@dagrejs/dagre`): ELK routes edges around nodes and places labels beside their own edges, lays out
|
|
12
|
+
* partitions in order and routes feedback edges apart; dagre does none of those, and its edges and labels cross nodes.
|
|
13
|
+
*/
|
|
14
|
+
import ELK, { type ElkNode } from 'elkjs/lib/elk.bundled.js';
|
|
15
|
+
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from 'react';
|
|
16
|
+
import type { WorkflowFlow } from '../views/workflow-flows';
|
|
17
|
+
import type { WorkflowView, WorkflowsView } from '../views/workflows-view';
|
|
18
|
+
import { QueueBar } from './queue-bar';
|
|
19
|
+
|
|
20
|
+
/** An edge's label: what it is, and along a wait how many wait. */
|
|
21
|
+
const flowLabel = (f: WorkflowFlow): string => (f.kind === 'waits on' ? `${f.waiting.toLocaleString('en-US')} wait on it` : f.kind);
|
|
22
|
+
/** An edge's line: solid feeds, dashed sends back, dotted gives input, dash-dot waits on. */
|
|
23
|
+
const DASH: Readonly<Record<WorkflowFlow['kind'], string | undefined>> = { feeds: undefined, 'sends back': '7 4', 'gives input': '1.5 3.5', 'waits on': '7 3 1.5 3' };
|
|
24
|
+
|
|
25
|
+
/** The node's width; its height is measured from what it shows. */
|
|
26
|
+
const NODE_WIDTH = 250;
|
|
27
|
+
/** The left gutter the stages are named in. */
|
|
28
|
+
const GUTTER = 104;
|
|
29
|
+
const LABEL_HEIGHT = 15;
|
|
30
|
+
const labelWidth = (text: string) => Math.ceil(text.length * 6.3) + 10;
|
|
31
|
+
|
|
32
|
+
interface Laid {
|
|
33
|
+
readonly nodes: ReadonlyMap<string, { readonly x: number; readonly y: number; readonly h: number }>;
|
|
34
|
+
readonly edges: ReadonlyArray<{ readonly flow: WorkflowFlow; readonly points: ReadonlyArray<{ readonly x: number; readonly y: number }>; readonly label: { readonly x: number; readonly y: number; readonly w: number } | null }>;
|
|
35
|
+
readonly width: number;
|
|
36
|
+
readonly height: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const elk = new ELK();
|
|
40
|
+
|
|
41
|
+
/** The layout of the linked workflows, given each node's height. */
|
|
42
|
+
const layOut = async (input: {
|
|
43
|
+
/** In pipeline order: by stage, then by depth through forward edges within it. */
|
|
44
|
+
readonly workflows: ReadonlyArray<{ readonly name: string; readonly stage: number; readonly height: number }>;
|
|
45
|
+
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
46
|
+
}): Promise<Laid> => {
|
|
47
|
+
const asked: ElkNode = {
|
|
48
|
+
id: 'workflows',
|
|
49
|
+
layoutOptions: {
|
|
50
|
+
'elk.algorithm': 'layered',
|
|
51
|
+
'elk.direction': 'DOWN',
|
|
52
|
+
'elk.edgeRouting': 'ORTHOGONAL',
|
|
53
|
+
'elk.partitioning.activate': 'true',
|
|
54
|
+
// One layering for all, so every stage's layers come before the next stage's; laid out apart, unconnected groups sat side by side.
|
|
55
|
+
'elk.separateConnectedComponents': 'false',
|
|
56
|
+
'elk.layered.feedbackEdges': 'true',
|
|
57
|
+
// The platform's pipeline order decides which edges go against the flow: only one to a workflow earlier in it, a
|
|
58
|
+
// send-back. Left to itself, ELK kept Retry near-misses' send-back as forward and drew Decompile's feed going up.
|
|
59
|
+
'elk.layered.cycleBreaking.strategy': 'MODEL_ORDER',
|
|
60
|
+
'elk.layered.considerModelOrder.strategy': 'NODES_AND_EDGES',
|
|
61
|
+
'elk.layered.spacing.nodeNodeBetweenLayers': '64',
|
|
62
|
+
'elk.spacing.nodeNode': '36',
|
|
63
|
+
'elk.spacing.edgeNode': '18',
|
|
64
|
+
'elk.spacing.edgeEdge': '12',
|
|
65
|
+
'elk.spacing.edgeLabel': '4',
|
|
66
|
+
'elk.layered.edgeLabels.sideSelection': 'SMART_DOWN',
|
|
67
|
+
'elk.padding': `[top=34,left=${GUTTER},bottom=16,right=16]`,
|
|
68
|
+
},
|
|
69
|
+
children: input.workflows.map((w) => ({ id: w.name, width: NODE_WIDTH, height: w.height, layoutOptions: { 'elk.partitioning.partition': String(w.stage) } })),
|
|
70
|
+
edges: input.flows.map((f, i) => ({ id: `edge-${i}`, sources: [f.from], targets: [f.to], labels: [{ id: `label-${i}`, text: flowLabel(f), width: labelWidth(flowLabel(f)), height: LABEL_HEIGHT }] })),
|
|
71
|
+
};
|
|
72
|
+
const graph = await elk.layout(asked);
|
|
73
|
+
const nodes = new Map((graph.children ?? []).map((c) => [c.id, { x: c.x ?? 0, y: c.y ?? 0, h: c.height ?? 0 }]));
|
|
74
|
+
const edges = (graph.edges ?? []).map((e, i) => {
|
|
75
|
+
const s = e.sections?.[0];
|
|
76
|
+
const label = e.labels?.[0];
|
|
77
|
+
return {
|
|
78
|
+
flow: input.flows[i]!,
|
|
79
|
+
points: s === undefined ? [] : [s.startPoint, ...(s.bendPoints ?? []), s.endPoint],
|
|
80
|
+
label: label === undefined || label.x === undefined || label.y === undefined ? null : { x: label.x, y: label.y, w: label.width ?? 0 },
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return { nodes, edges, width: graph.width ?? 0, height: graph.height ?? 0 };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export interface WorkflowDagProps {
|
|
87
|
+
readonly view: WorkflowsView;
|
|
88
|
+
readonly phaseLabel: (phase: string) => string;
|
|
89
|
+
/** A box's runs and agents now, with its limit controls. */
|
|
90
|
+
readonly nodeStatus: (w: WorkflowView) => ReactNode;
|
|
91
|
+
/** The address of a workflow's own level, which its box's name opens. */
|
|
92
|
+
readonly hrefOfWorkflow: (workflow: string) => string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function Node({ w, nodeStatus, href, style }: { readonly w: WorkflowView; readonly nodeStatus: (w: WorkflowView) => ReactNode; readonly href: string; readonly style?: CSSProperties }) {
|
|
96
|
+
return (
|
|
97
|
+
<div data-workflow={w.name} className="wp-node" style={style}>
|
|
98
|
+
<a className="wp-node-name" href={href} title={`Open ${w.name}: ${w.description}`}>{w.name} ›</a>
|
|
99
|
+
{w.queue === null ? null : <QueueBar queue={w.queue} />}
|
|
100
|
+
<div className="wp-node-status">{nodeStatus(w)}</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function WorkflowDag({ view, phaseLabel, nodeStatus, hrefOfWorkflow }: WorkflowDagProps) {
|
|
106
|
+
const all = view.groups.flatMap((g) => g.workflows);
|
|
107
|
+
const linkedNames = new Set(view.flows.flatMap((f) => [f.from, f.to]));
|
|
108
|
+
const linked = all.filter((w) => linkedNames.has(w.name));
|
|
109
|
+
const stageOf = new Map(view.groups.map((g, i) => [g.phase, i]));
|
|
110
|
+
|
|
111
|
+
// Each box's height, measured as drawn, then the layout from them; laid out again whenever a height or the flows change.
|
|
112
|
+
const map = useRef<HTMLDivElement>(null);
|
|
113
|
+
const [heights, setHeights] = useState<string>('');
|
|
114
|
+
const [laid, setLaid] = useState<Laid | null>(null);
|
|
115
|
+
const [failed, setFailed] = useState<string | null>(null);
|
|
116
|
+
// Opened at its first box: on a phone the box shows one box across, and a map opened at its left edge showed none.
|
|
117
|
+
const scrollBox = useRef<HTMLDivElement>(null);
|
|
118
|
+
const opened = useRef(false);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (laid === null || opened.current || scrollBox.current === null) return;
|
|
121
|
+
const first = [...laid.nodes.values()].sort((a, b) => a.y - b.y || a.x - b.x)[0];
|
|
122
|
+
if (first === undefined) return;
|
|
123
|
+
opened.current = true;
|
|
124
|
+
if (scrollBox.current.clientWidth < laid.width) scrollBox.current.scrollLeft = Math.max(0, first.x - 12);
|
|
125
|
+
}, [laid]);
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
const el = map.current;
|
|
128
|
+
if (el === null) return;
|
|
129
|
+
const measure = () => setHeights(JSON.stringify([...el.querySelectorAll('[data-workflow]')].map((n) => [n.getAttribute('data-workflow'), Math.ceil(n.getBoundingClientRect().height)])));
|
|
130
|
+
measure();
|
|
131
|
+
const watch = new ResizeObserver(measure);
|
|
132
|
+
for (const n of el.querySelectorAll('[data-workflow]')) watch.observe(n);
|
|
133
|
+
return () => watch.disconnect();
|
|
134
|
+
}, [view.at, linked.length]);
|
|
135
|
+
const flowsKey = JSON.stringify(view.flows.map((f) => [f.from, f.to, f.kind, flowLabel(f)]));
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (heights === '') return;
|
|
138
|
+
const h = new Map(JSON.parse(heights) as Array<[string, number]>);
|
|
139
|
+
let current = true;
|
|
140
|
+
const inOrder = [...linked].sort((a, b) => a.place.stage - b.place.stage || a.place.depth - b.place.depth || a.name.localeCompare(b.name));
|
|
141
|
+
layOut({ workflows: inOrder.map((w) => ({ name: w.name, stage: stageOf.get(w.phase) ?? 0, height: h.get(w.name) ?? 120 })), flows: view.flows })
|
|
142
|
+
.then((l) => { if (current) { setLaid(l); setFailed(null); } })
|
|
143
|
+
.catch((e: unknown) => { if (current) setFailed(e instanceof Error ? e.message : String(e)); });
|
|
144
|
+
return () => { current = false; };
|
|
145
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `linked` and `stageOf` follow `heights` and `flowsKey`.
|
|
146
|
+
}, [heights, flowsKey]);
|
|
147
|
+
|
|
148
|
+
// Each stage's band: from the top of its first box to the bottom of its last.
|
|
149
|
+
const bands = laid === null ? [] : view.groups.flatMap((g) => {
|
|
150
|
+
const ys = linked.filter((w) => w.phase === g.phase).flatMap((w) => { const n = laid.nodes.get(w.name); return n === undefined ? [] : [{ top: n.y, bottom: n.y + n.h }]; });
|
|
151
|
+
return ys.length === 0 ? [] : [{ phase: g.phase, top: Math.min(...ys.map((y) => y.top)) - 24, bottom: Math.max(...ys.map((y) => y.bottom)) + 14 }];
|
|
152
|
+
});
|
|
153
|
+
if (linked.length === 0) return null;
|
|
154
|
+
const others = all.length - linked.length;
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div className="wp-dag-wrap">
|
|
158
|
+
<p className="wp-line wp-mut">
|
|
159
|
+
Each box is one workflow; its name opens it. Arrows point the way work goes, down the page: a solid arrow feeds the next
|
|
160
|
+
workflow's tasks; dashed, “sends back”, returns work to an earlier one. Each stage is a band, named on the left.
|
|
161
|
+
{others === 0 ? null : ` The ${others.toLocaleString('en-US')} workflow${others === 1 ? '' : 's'} no work flows to or from ${others === 1 ? 'is' : 'are'} in the list of steps below.`}
|
|
162
|
+
</p>
|
|
163
|
+
{failed === null ? null : <p className="wp-line wp-bad">The map could not be laid out: {failed}</p>}
|
|
164
|
+
<div ref={scrollBox} className="wp-dag-scroll">
|
|
165
|
+
<div ref={map} className="wp-dag" style={{ width: laid === null ? undefined : laid.width, height: laid === null ? undefined : laid.height }}>
|
|
166
|
+
{laid === null ? null : (
|
|
167
|
+
<svg className="wp-dag-edges" width={laid.width} height={laid.height} aria-hidden="true">
|
|
168
|
+
<defs>
|
|
169
|
+
<marker id="wp-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="11" markerHeight="11" markerUnits="userSpaceOnUse" orient="auto">
|
|
170
|
+
<path d="M0,0 L10,5 L0,10 z" fill="var(--wp-edge)" />
|
|
171
|
+
</marker>
|
|
172
|
+
</defs>
|
|
173
|
+
{bands.map((b, i) => (
|
|
174
|
+
<g key={b.phase}>
|
|
175
|
+
<rect x={0} y={b.top} width={laid.width} height={b.bottom - b.top} fill={i % 2 === 0 ? 'var(--wp-band)' : 'transparent'} />
|
|
176
|
+
<foreignObject x={6} y={b.top + 6} width={GUTTER - 16} height={Math.max(40, b.bottom - b.top - 12)}>
|
|
177
|
+
<div className="wp-band-name">{phaseLabel(b.phase)}</div>
|
|
178
|
+
</foreignObject>
|
|
179
|
+
</g>
|
|
180
|
+
))}
|
|
181
|
+
{laid.edges.map(({ flow, points }) => (
|
|
182
|
+
<polyline key={`${flow.from}>${flow.to}>${flow.kind}`} points={points.map((p) => `${p.x},${p.y}`).join(' ')} fill="none" stroke="var(--wp-edge)"
|
|
183
|
+
strokeWidth={flow.kind === 'feeds' ? 1.8 : 1.5} strokeDasharray={DASH[flow.kind]} markerEnd="url(#wp-arrow)" />
|
|
184
|
+
))}
|
|
185
|
+
{laid.edges.map(({ flow, label }) => (label === null ? null : (
|
|
186
|
+
<g key={`label:${flow.from}>${flow.to}>${flow.kind}`}>
|
|
187
|
+
<rect x={label.x} y={label.y} width={label.w} height={LABEL_HEIGHT} rx={3} fill="var(--wp-bg)" stroke="var(--wp-edge)" strokeWidth="0.7" />
|
|
188
|
+
<text x={label.x + 5} y={label.y + 11} fontSize="10.5" fill="var(--wp-fg)">{flowLabel(flow)}{flow.why === null ? null : <title>{flow.why}</title>}</text>
|
|
189
|
+
</g>
|
|
190
|
+
)))}
|
|
191
|
+
</svg>
|
|
192
|
+
)}
|
|
193
|
+
{linked.map((w) => {
|
|
194
|
+
const at = laid?.nodes.get(w.name);
|
|
195
|
+
return (
|
|
196
|
+
<Node key={w.name} w={w} nodeStatus={nodeStatus} href={hrefOfWorkflow(w.name)}
|
|
197
|
+
style={at === undefined ? { position: 'absolute', left: 0, top: 0, visibility: 'hidden' } : { position: 'absolute', left: at.x, top: at.y }} />
|
|
198
|
+
);
|
|
199
|
+
})}
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
@@ -20,6 +20,7 @@ import { QueueBar } from './queue-bar';
|
|
|
20
20
|
import { QueueChart } from './queue-chart';
|
|
21
21
|
import { Breadcrumb, StepList } from './workflow-drilldown';
|
|
22
22
|
import { StepGraph } from './step-graph';
|
|
23
|
+
import { WorkflowDag } from './workflow-dag';
|
|
23
24
|
import { AgentUsageLine } from './agent-usage-line';
|
|
24
25
|
import type { AgentUsage } from './agent-usage';
|
|
25
26
|
import { MachineControls } from './machine-controls';
|
|
@@ -48,7 +49,8 @@ export type LimitName = 'runs' | 'agents';
|
|
|
48
49
|
export type SetLimit = (r: { readonly workflow: string; readonly limit: LimitName; readonly value: number | null }) => Promise<void>;
|
|
49
50
|
/** What starts a workflow's runs, in words. */
|
|
50
51
|
const startsLine = (w: WorkflowView): string =>
|
|
51
|
-
w.startsOn.kind === '
|
|
52
|
+
w.startsOn.kind === 'a step' ? `Runs as a step of ${w.startsOn.of.join(', ')}.`
|
|
53
|
+
: w.startsOn.kind === 'queue' ? 'Runs on its queue.'
|
|
52
54
|
: w.startsOn.kind === 'inputs' ? `Runs when its inputs change: ${w.startsOn.says}.`
|
|
53
55
|
: 'Runs on a timer or a request.';
|
|
54
56
|
|
|
@@ -109,12 +111,12 @@ export const usePolledJson = <A,>(url: string, everyMs: number): { readonly data
|
|
|
109
111
|
return { data, error };
|
|
110
112
|
};
|
|
111
113
|
|
|
112
|
-
const costCells = (c: StepCost | null,
|
|
114
|
+
const costCells = (c: StepCost | null, agentic: boolean): ReactNode => (
|
|
113
115
|
<>
|
|
114
116
|
<td className="wp-r">{c === null ? '' : c.calls.toLocaleString('en-US')}</td>
|
|
115
117
|
<td className={c !== null && c.failed > 0 ? 'wp-r wp-bad' : 'wp-r'}>{c === null || c.failed === 0 ? '' : c.failed.toLocaleString('en-US')}</td>
|
|
116
118
|
<td className="wp-r">{c === null ? '' : duration(c.seconds)}</td>
|
|
117
|
-
<td className="wp-r">{c === null || !
|
|
119
|
+
<td className="wp-r">{c === null || !agentic ? '' : `${compact(c.inputTokens)} / ${compact(c.outputTokens)}`}</td>
|
|
118
120
|
<td className="wp-r">{c === null ? '' : duration(c.cpuSeconds)}</td>
|
|
119
121
|
<td className="wp-r">{c === null || c.items === 0 ? '' : c.items.toLocaleString('en-US')}</td>
|
|
120
122
|
</>
|
|
@@ -136,7 +138,7 @@ function StepsTable({ workflow, usesAgents, runs, now }: { readonly workflow: Wo
|
|
|
136
138
|
<div className="wp-tablewrap"><table className="wp-table">
|
|
137
139
|
<thead>
|
|
138
140
|
<tr>
|
|
139
|
-
<th>step</th><th title="
|
|
141
|
+
<th>step</th><th title="Deterministic: code only. Agentic: an agent does it. Classification: a separate classifier model decides.">how it runs</th><th>runs now</th>
|
|
140
142
|
<th className="wp-r">calls</th><th className="wp-r">failed</th><th className="wp-r">time</th>
|
|
141
143
|
<th className="wp-r" title="Input tokens, fresh and cached / output tokens">tokens in / out</th>
|
|
142
144
|
<th className="wp-r" title="Its own and its processes' CPU">CPU</th><th className="wp-r">items</th>
|
|
@@ -150,9 +152,9 @@ function StepsTable({ workflow, usesAgents, runs, now }: { readonly workflow: Wo
|
|
|
150
152
|
<Fragment key={s.name}>
|
|
151
153
|
<tr>
|
|
152
154
|
<td title={s.description} className={s.declared ? '' : 'wp-bad'}>{s.name}{s.declared ? '' : ' (not declared)'}</td>
|
|
153
|
-
<td>{s.
|
|
155
|
+
<td>{s.runs ?? ''}</td>
|
|
154
156
|
<td className="wp-mut">{nowCell(at, now)}</td>
|
|
155
|
-
{costCells(s.cost, s.
|
|
157
|
+
{costCells(s.cost, s.runs === 'agentic')}
|
|
156
158
|
<td className="wp-mut" title={s.endings.map((e) => `${e.records} ${e.outcome}: ${e.reason}`).join('\n')}>{s.endings.length === 0 ? '' : `${s.endings[0]!.reason} (${s.endings[0]!.records})`}</td>
|
|
157
159
|
</tr>
|
|
158
160
|
{at?.waitingOn === null || at?.waitingOn === undefined ? null : (
|
|
@@ -284,7 +286,7 @@ const FIGURES_EVERY_MS = 15_000;
|
|
|
284
286
|
* An open workflow: what it gave and cost, its steps, its step graph and where its runs stopped, read from its own records
|
|
285
287
|
* while it is open. The figures of the workflow opened before it are never shown under this one's name.
|
|
286
288
|
*/
|
|
287
|
-
function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly now: number; readonly figuresUrl: (workflow: string) => string }) {
|
|
289
|
+
function WorkflowDetail({ workflow, runs, now, figuresUrl, hrefOfWorkflow }: { readonly workflow: WorkflowView; readonly runs: WorkflowRunsNow | undefined; readonly now: number; readonly figuresUrl: (workflow: string) => string; readonly hrefOfWorkflow: (workflow: string) => string }) {
|
|
288
290
|
const read = usePolledJson<WorkflowFigures>(figuresUrl(workflow.name), FIGURES_EVERY_MS);
|
|
289
291
|
const figures = read.data !== null && read.data.workflow === workflow.name ? read.data : null;
|
|
290
292
|
return (
|
|
@@ -307,7 +309,7 @@ function WorkflowDetail({ workflow, runs, now, figuresUrl }: { readonly workflow
|
|
|
307
309
|
<p className="wp-line">{runCostLine(figures)}</p>
|
|
308
310
|
<StepsTable workflow={figures} usesAgents={workflow.usesAgents} runs={runs} now={now} />
|
|
309
311
|
<h4 className="wp-h4">Step graph</h4>
|
|
310
|
-
<div className="wp-tablewrap"><StepGraph graph={figures.graph} /></div>
|
|
312
|
+
<div className="wp-tablewrap"><StepGraph graph={figures.graph} hrefOfWorkflow={hrefOfWorkflow} /></div>
|
|
311
313
|
<h4 className="wp-h4">Where runs stopped</h4>
|
|
312
314
|
<FunnelTable funnel={figures.funnel} />
|
|
313
315
|
</>
|
|
@@ -344,12 +346,20 @@ function DrillLevelView({ data, path, hrefOf, now, figuresUrl, sourceHref, phase
|
|
|
344
346
|
{/* Its tasks over time: at the top a row for each step that has tasks; below it, the workflow opened and each such step of its own. */}
|
|
345
347
|
<QueueChart view={data.view} level={path.join("/")} rowWord={w === null ? "step" : "workflow"}
|
|
346
348
|
workflows={[...(w === null ? [] : [w]), ...level.steps.flatMap((s) => { const sub = s.workflow === null ? undefined : workflowOf(s.workflow); return sub === undefined || sub.name === w?.name ? [] : [sub]; })]} />
|
|
349
|
+
{/* At the top, the map of its steps: each workflow a box whose name opens it, with the arrows work takes between them. */}
|
|
350
|
+
{w !== null ? null : (
|
|
351
|
+
<>
|
|
352
|
+
<h3 className="wp-h3">Map</h3>
|
|
353
|
+
<WorkflowDag view={data.view} phaseLabel={phaseLabel} hrefOfWorkflow={(name) => hrefOf([name])}
|
|
354
|
+
nodeStatus={(node) => <WorkflowStatus workflow={node} runs={runsOf(node.name)} limits={node.limits} setLimit={setLimit} />} />
|
|
355
|
+
</>
|
|
356
|
+
)}
|
|
347
357
|
<h3 className="wp-h3">Steps</h3>
|
|
348
358
|
<StepList
|
|
349
359
|
steps={level.steps} path={level.crumbs[level.crumbs.length - 1]!.path} hrefOf={hrefOf} workflowOf={workflowOf} runsOf={runsOf} runs={runs}
|
|
350
360
|
{...(w === null ? { groupKey: (s: StepSummary) => stageOf(s.workflow), groupOf: (s: StepSummary) => { const stage = stageOf(s.workflow); return stage === null ? null : phaseLabel(stage); } } : {})}
|
|
351
361
|
/>
|
|
352
|
-
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} />}
|
|
362
|
+
{w === null ? null : <WorkflowDetail workflow={w} runs={runs} now={now} figuresUrl={figuresUrl} hrefOfWorkflow={(name) => hrefOf([...level.crumbs[level.crumbs.length - 1]!.path, name])} />}
|
|
353
363
|
</section>
|
|
354
364
|
);
|
|
355
365
|
}
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ export * from './views/runs-now';
|
|
|
50
50
|
export * from './views/step-funnel';
|
|
51
51
|
export * from './views/step-graph';
|
|
52
52
|
export * from './views/workflows-view';
|
|
53
|
+
export * from './views/workflow-flows';
|
|
53
54
|
export type { NewNote, TaskStore, TextChange } from './storage/task-store';
|
|
54
55
|
export type { AgentUsage, UsageLimit } from './dashboard/agent-usage';
|
|
55
56
|
|
package/src/steps.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* writes its one record (`storage/step-records.ts`): start, end, outcome, tokens, compiles, and a heartbeat while an agent
|
|
7
7
|
* works. A dashboard derives all it says from those records and these declarations.
|
|
8
8
|
*
|
|
9
|
-
* const PICK = defineStep({ name: 'Pick',
|
|
9
|
+
* const PICK = defineStep({ name: 'Pick', runs: 'deterministic', description: '...', at: import.meta.path, success: Schema.Number });
|
|
10
10
|
* export const MyWorkflow = defineWorkflow({ phase: 'main', description: '...', at: import.meta.path, steps: () => [PICK],
|
|
11
11
|
* graph: () => [{ from: RUN_STARTS, to: PICK.name, when: 'each run' }, { from: PICK.name, to: RUN_ENDS, when: 'always' }] })('My workflow', { payload, success, error, idempotencyKey });
|
|
12
12
|
* ... yield* PICK.run(Effect.gen(...)); a repeating step gives its number: PICK.run(body, { call: 2 })
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* first agent step: an item that passes now is finished, with no agent and no tokens; one that fails gives the agent the
|
|
24
24
|
* exact failure as its input; one that cannot be tested says why.
|
|
25
25
|
*
|
|
26
|
-
* An agent call needs `AgentStep`, which only
|
|
26
|
+
* An agent call needs `AgentStep`, which only a step that runs agentically (`runs: 'agentic'`) provides, so it cannot compile anywhere else.
|
|
27
27
|
*
|
|
28
28
|
* A BUDGET LIMITS THE AGENTS WORKING, NOT ONLY THE RUNS STARTED. Before each agent step, a run its workflow's budget has no
|
|
29
29
|
* room for ends: oldest runs keep their places, so with 10 going and a budget of 5 exactly the newest 5 end, and no two runs
|
|
@@ -72,7 +72,7 @@ export interface ApiUsage {
|
|
|
72
72
|
readonly output_tokens?: number | null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/** Provided only inside
|
|
75
|
+
/** Provided only inside a step that runs agentically; an agent call reports what it spent through it. */
|
|
76
76
|
export class AgentStep extends Context.Service<AgentStep, {
|
|
77
77
|
/** A request's usage so far, by the message it belongs to, as it arrives: the step's record shows it at once. */
|
|
78
78
|
readonly usage: (message: string, model: string | null, usage: ApiUsage) => void;
|
|
@@ -98,28 +98,40 @@ export const isStoodDown = (failure: unknown): boolean => failure === STOOD_DOWN
|
|
|
98
98
|
|
|
99
99
|
/** Whether a run is surplus: it is past the budget in the workflow's runs, oldest first. A run not listed is not counted. Pure. */
|
|
100
100
|
export const surplusRun = (oldestFirst: ReadonlyArray<string>, run: string, budget: number): boolean => oldestFirst.indexOf(run) >= budget;
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
102
|
/**
|
|
103
103
|
* WHAT A STEP IS, as a page says it in words. Alex, 2026-11-19: "there are different kinds of workflow steps. like a check,
|
|
104
104
|
* like a sub workflow."
|
|
105
105
|
*
|
|
106
|
-
* step
|
|
107
|
-
* agent calls an agent;
|
|
106
|
+
* step does part of the work;
|
|
108
107
|
* check decides whether the work passes;
|
|
109
108
|
* sub-workflow a workflow used as a step of another workflow (`StepDeclaration.workflow` names it).
|
|
110
109
|
*/
|
|
111
|
-
export const STEP_KINDS = ['step', '
|
|
110
|
+
export const STEP_KINDS = ['step', 'check', 'sub-workflow'] as const;
|
|
112
111
|
export type StepKind = (typeof STEP_KINDS)[number];
|
|
113
112
|
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
/**
|
|
114
|
+
* HOW A STEP RUNS, a separate question from what it is. Alex, 2026-11-19: "rather than 'no ai' or 'agent' I think a step
|
|
115
|
+
* should be labeled as one of the following 'deterministic', 'agentic' or 'classification' where that third option allows
|
|
116
|
+
* for steps which use a separate classifier model".
|
|
117
|
+
*
|
|
118
|
+
* deterministic code only;
|
|
119
|
+
* agentic an agent does it: it waits for one of its workflow's agents (`untilAgentSlot`);
|
|
120
|
+
* classification a separate classifier model decides.
|
|
121
|
+
*
|
|
122
|
+
* A step or a check is any of the three. A sub-workflow step states none: its workflow's own steps state theirs.
|
|
123
|
+
*/
|
|
124
|
+
export const STEP_RUNS = ['deterministic', 'agentic', 'classification'] as const;
|
|
125
|
+
export type StepRuns = (typeof STEP_RUNS)[number];
|
|
126
|
+
|
|
127
|
+
/** A step's kind, from its declaration: the kind it states, a check where it is its workflow's test, a step otherwise. Pure. */
|
|
128
|
+
export const stepKindOf = (s: Pick<StepDeclaration, 'test' | 'kind'>): StepKind => s.kind ?? (s.test === true ? 'check' : 'step');
|
|
117
129
|
|
|
118
130
|
export interface StepDeclaration {
|
|
119
131
|
readonly name: string;
|
|
120
|
-
/**
|
|
121
|
-
readonly
|
|
122
|
-
/** What it is where it is
|
|
132
|
+
/** How it runs; none for a sub-workflow step. */
|
|
133
|
+
readonly runs: StepRuns | null;
|
|
134
|
+
/** What it is where it is not a plain step (`stepKindOf`). */
|
|
123
135
|
readonly kind?: 'check' | 'sub-workflow';
|
|
124
136
|
/** For a sub-workflow step: the workflow it runs, by name. */
|
|
125
137
|
readonly workflow?: string;
|
|
@@ -218,6 +230,11 @@ export interface WorkflowDeclaration<Phase extends string = string, R = never> {
|
|
|
218
230
|
readonly items?: () => Effect.Effect<ReadonlyArray<string>, unknown, R>;
|
|
219
231
|
/** Its Pick takes the first task of its queue it can claim (`tasks.ts` `queueOrder`), so a dashboard lists that queue. */
|
|
220
232
|
readonly picksQueueHead?: true;
|
|
233
|
+
/**
|
|
234
|
+
* The workflows whose results become its tasks: the arrows of the project's map (`views/workflow-flows.ts`). A workflow
|
|
235
|
+
* used as a step of another needs none: it is drawn inside that one.
|
|
236
|
+
*/
|
|
237
|
+
readonly fedBy?: ReadonlyArray<string>;
|
|
221
238
|
/** Its step graph (`StepEdge`); none until it declares one. */
|
|
222
239
|
readonly graph?: () => ReadonlyArray<StepEdge>;
|
|
223
240
|
/** What it runs on (`WorkflowInputs`); none until it declares them, and it runs whenever its trigger says. */
|
|
@@ -250,7 +267,7 @@ export const runLimitOf = (d: Pick<WorkflowDeclaration<string, unknown>, 'pendin
|
|
|
250
267
|
export const hasAList = (d: Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items'>): boolean => d.pending !== undefined || d.items !== undefined;
|
|
251
268
|
|
|
252
269
|
/** Whether a step uses an agent: it is an agent step, or a sub-workflow step whose workflow has one at any depth. Pure. */
|
|
253
|
-
export const stepUsesAnAgent = (s: Pick<StepDeclaration, '
|
|
270
|
+
export const stepUsesAnAgent = (s: Pick<StepDeclaration, 'runs' | 'agentUnder'>): boolean => s.runs === 'agentic' || s.agentUnder?.() === true;
|
|
254
271
|
|
|
255
272
|
/** Whether a workflow's budget rules it: a declared list, and an agent step of its own or under a sub-workflow step. Pure. */
|
|
256
273
|
export const keptRunningByItsBudget = (d: Pick<WorkflowDeclaration<string, unknown>, 'pending' | 'items' | 'steps'>): boolean =>
|
|
@@ -402,6 +419,8 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
402
419
|
* against the agents' limit of the workflow at the top. Kept while the run goes: it never changes.
|
|
403
420
|
*/
|
|
404
421
|
const TOPS = new Map<string, { readonly run: string; readonly workflow: string }>();
|
|
422
|
+
/** Each workflow's start with no run limit asked, by name: what a sub-workflow step starts it by (`defineSubWorkflow`). */
|
|
423
|
+
const STARTS_AS_A_STEP = new Map<string, (payload: unknown) => Effect.Effect<unknown, unknown, unknown>>();
|
|
405
424
|
const topOf = (workflow: string, run: string): Effect.Effect<{ readonly run: string; readonly workflow: string }, StorageError> => {
|
|
406
425
|
const known = TOPS.get(run);
|
|
407
426
|
if (known !== undefined) return Effect.succeed(known);
|
|
@@ -520,16 +539,16 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
520
539
|
const toolInputs: string[] = [];
|
|
521
540
|
let before: TreeHashes | null = null;
|
|
522
541
|
let recordId: number | null = null;
|
|
523
|
-
let meter = new StepMeter(null, step.
|
|
542
|
+
let meter = new StepMeter(null, (step.runs === 'agentic'), [], null);
|
|
524
543
|
return Effect.acquireUseRelease(
|
|
525
544
|
Effect.flatMap(Effect.gen(function* () {
|
|
526
545
|
yield* checkEdge(instance.workflow._tag, instance.executionId, step.name);
|
|
527
546
|
// A sub-workflow step is run again when its workflow has ended: it takes its open record up again, and names the run it started.
|
|
528
|
-
const id = yield* recorded('open its record', records.openStepRun({ workflow: instance.workflow._tag, run: instance.executionId, step: step.name, call, agent: step.
|
|
547
|
+
const id = yield* recorded('open its record', records.openStepRun({ workflow: instance.workflow._tag, run: instance.executionId, step: step.name, call, agent: (step.runs === 'agentic'), subject, ...(childRun === null ? {} : { resume: true as const }) }));
|
|
529
548
|
if (id !== null && childRun !== null) yield* recorded('name the run it started', records.setStepChild({ id, childRun }));
|
|
530
|
-
const beat = step.
|
|
549
|
+
const beat = (step.runs === 'agentic') && id !== null ? setInterval(() => recordNow('its heartbeat', records.beatStepRun(id)), AGENT_BEAT_MS) : null;
|
|
531
550
|
recordId = id;
|
|
532
|
-
meter = new StepMeter(id, step.
|
|
551
|
+
meter = new StepMeter(id, (step.runs === 'agentic'), step.writes ?? [], null);
|
|
533
552
|
meterOpened(meter);
|
|
534
553
|
return { id, beat };
|
|
535
554
|
}), (opened) => (mayWrite === undefined
|
|
@@ -543,7 +562,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
543
562
|
return opened;
|
|
544
563
|
}))),
|
|
545
564
|
() => pipe(
|
|
546
|
-
step.
|
|
565
|
+
(step.runs === 'agentic') ? Effect.andThen(untilAgentSlot(instance, () => recordId), execute) : execute,
|
|
547
566
|
// What it changed, on its record, and a change it named outside where it may write refuses the step.
|
|
548
567
|
Effect.tap(() => Effect.suspend(() => {
|
|
549
568
|
const earlier = before;
|
|
@@ -560,12 +579,12 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
560
579
|
})),
|
|
561
580
|
Effect.provideService(CurrentMeter, meter),
|
|
562
581
|
Effect.provideService(deps.CurrentStepUsage, meter),
|
|
563
|
-
step.
|
|
582
|
+
(step.runs === 'agentic') ? Effect.provideService(AgentStep, { usage, report, touched: (inputs) => { toolInputs.push(...inputs); }, waiting: (why) => { if (recordId !== null) recordNow('say what it waits on', records.setStepWaiting({ id: recordId, waiting: why })); } }) : (e) => e,
|
|
564
583
|
) as Effect.Effect<A, E, Exclude<R2, AgentStep>>,
|
|
565
584
|
({ id, beat }, exit) => Effect.gen(function* () {
|
|
566
585
|
if (beat !== null) clearInterval(beat);
|
|
567
586
|
// Its agent slot is free for its workflow's next run waiting on one.
|
|
568
|
-
if (step.
|
|
587
|
+
if ((step.runs === 'agentic')) deps.wakes.wakePicksOf(TOPS.get(instance.executionId)?.workflow ?? instance.workflow._tag, 'an agent step ended');
|
|
569
588
|
// An interrupted step is no move: the run does it again.
|
|
570
589
|
if (Exit.isSuccess(exit) || !Cause.hasInterrupts(exit.cause)) lastStepRan.set(instance.executionId, { step: step.name, failed: !Exit.isSuccess(exit) });
|
|
571
590
|
meterClosed(meter);
|
|
@@ -608,16 +627,19 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
608
627
|
*
|
|
609
628
|
* A step between those goes on, so what an agent step just made is still checked and recorded.
|
|
610
629
|
*/
|
|
611
|
-
const standDownIfSurplus = (step: { readonly agent: boolean; readonly picks: boolean }) => Effect.flatMap(WorkflowEngine.WorkflowInstance, (instance) =>
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
return Effect.
|
|
630
|
+
const standDownIfSurplus = (step: { readonly agent: boolean; readonly picks: boolean }) => Effect.flatMap(WorkflowEngine.WorkflowInstance, (instance) =>
|
|
631
|
+
// A run a sub-workflow step started is its top run's work: its steps stand down as that run's own would, by that
|
|
632
|
+
// workflow's budget. Asked of its own, a step with no agent stood the run above down where that run's own never would.
|
|
633
|
+
Effect.flatMap(Effect.orElseSucceed(topOf(instance.workflow._tag, instance.executionId), () => ({ run: instance.executionId, workflow: instance.workflow._tag })), (top) => {
|
|
634
|
+
const declared = DECLARED.get(top.workflow);
|
|
635
|
+
const budgetKeepsIt = declared !== undefined && keptRunningByItsBudget(declared);
|
|
636
|
+
if (!step.agent && (budgetKeepsIt || (!step.picks && lastStepRan.has(instance.executionId)))) return Effect.void;
|
|
637
|
+
return Effect.flatMap(AgentBudgets, (budgets) => Effect.flatMap(budgets.standsDown(instance.workflow._tag, instance.executionId), (surplus) => {
|
|
638
|
+
if (!surplus) return Effect.void;
|
|
639
|
+
console.log(`[run limit] ${instance.workflow._tag} run ${instance.executionId} stood down: its workflow has more runs going than its run limit`);
|
|
640
|
+
return Effect.fail(STOOD_DOWN);
|
|
641
|
+
}));
|
|
619
642
|
}));
|
|
620
|
-
});
|
|
621
643
|
|
|
622
644
|
/** One run of a workflow picks at a time: its choice is on its step record before the next reads what is taken. */
|
|
623
645
|
const pickingOneAtATime = <A, E, R2>(workflow: string, pick: Effect.Effect<A, E, R2>): Effect.Effect<A, E, R2> => {
|
|
@@ -669,7 +691,8 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
669
691
|
/** A step: its declaration, and `run`, the only way to run it. */
|
|
670
692
|
const defineStep = <A>(d: {
|
|
671
693
|
readonly name: string;
|
|
672
|
-
|
|
694
|
+
/** How it runs (`StepRuns`). */
|
|
695
|
+
readonly runs: StepRuns;
|
|
673
696
|
readonly description: string;
|
|
674
697
|
/** `import.meta.path`, for its link. */
|
|
675
698
|
readonly at: string;
|
|
@@ -680,7 +703,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
680
703
|
readonly subject?: (a: A) => string | null;
|
|
681
704
|
/** For an agent step with tools: the paths, from the project's root, it may change (`step-files.ts`). */
|
|
682
705
|
readonly mayWrite?: ReadonlyArray<string>;
|
|
683
|
-
/**
|
|
706
|
+
/** A check decides whether the work passes (`StepKind`); absent, a plain step. */
|
|
684
707
|
readonly kind?: 'check';
|
|
685
708
|
/** Marks the no-agent test an item goes through first. Use `defineItemTest` where the step only tests. */
|
|
686
709
|
readonly test?: true;
|
|
@@ -701,7 +724,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
701
724
|
}) => {
|
|
702
725
|
const writes = [...(d.mayWrite ?? []), ...(d.writes ?? [])];
|
|
703
726
|
const declaration: StepDeclaration = {
|
|
704
|
-
name: d.name,
|
|
727
|
+
name: d.name, runs: d.runs, description: d.description, ...(d.kind === undefined ? {} : { kind: d.kind }), ...(d.test === undefined ? {} : { test: true }), ...(d.shared === undefined ? {} : { shared: true }), ...(d.perItem === undefined ? {} : { perItem: true }), ...(d.picked === undefined ? {} : { picks: true }),
|
|
705
728
|
...(writes.length === 0 ? {} : { writes }),
|
|
706
729
|
source: d.prompt ?? { path: sourcePath(d.at), anchor: `'${d.name}'` },
|
|
707
730
|
};
|
|
@@ -713,7 +736,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
713
736
|
success: d.success,
|
|
714
737
|
error: Schema.String,
|
|
715
738
|
execute: pipe(
|
|
716
|
-
standDownIfSurplus({ agent: d.
|
|
739
|
+
standDownIfSurplus({ agent: d.runs === 'agentic', picks: d.picked !== undefined }),
|
|
717
740
|
Effect.andThen(measured(declaration, options?.call ?? null, options?.subject ?? null, d.subject, d.reason, d.mayWrite, d.picked === undefined ? execute : untilPicked(d.picked, execute))),
|
|
718
741
|
Effect.retry({ while: deps.isTransientFailure, times: 10, schedule: Schedule.spaced('3 seconds') }),
|
|
719
742
|
Effect.mapError(describeFailure),
|
|
@@ -743,7 +766,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
743
766
|
|
|
744
767
|
/** The no-agent test step of a workflow, before its first agent step. */
|
|
745
768
|
const defineItemTest = (d: { readonly description: string; readonly at: string }) => {
|
|
746
|
-
const step = defineStep({ name: 'Test',
|
|
769
|
+
const step = defineStep({ name: 'Test', runs: 'deterministic', test: true, description: d.description, at: d.at, prompt: { path: sourcePath(d.at), anchor: 'defineItemTest(' }, success: ItemTest });
|
|
747
770
|
return { ...step, run: <E, R2>(test: Effect.Effect<ItemTest, E, R2>, options?: { readonly call?: number; readonly subject?: string }) => step.run(heldToItsList(test, options?.subject ?? null), options) };
|
|
748
771
|
};
|
|
749
772
|
|
|
@@ -762,7 +785,8 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
762
785
|
* the workflow's steps work on the item the run above works on, with no code naming it (`StepRecords.openStepRun`);
|
|
763
786
|
* its agent steps count against the agents' limit of the workflow at the top, and stand down with its run (`topOf`).
|
|
764
787
|
*
|
|
765
|
-
* Its
|
|
788
|
+
* Its start is the step's, so no run limit of its own gates it: the run above is the one a limit lets start or not, and a
|
|
789
|
+
* limit on a workflow used only as a step would fail the steps of runs already going.
|
|
766
790
|
*/
|
|
767
791
|
const defineSubWorkflow = <P, A, R2>(d: {
|
|
768
792
|
/** The workflow, as `defineWorkflow` gave it: define it above the workflow that uses it. */
|
|
@@ -778,8 +802,9 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
778
802
|
const isDeclared = Schema.is(d.success);
|
|
779
803
|
const given = (result: unknown): Effect.Effect<A, string> => (isDeclared(result) ? Effect.succeed(result) : Effect.fail(`${child} gave a result that is not what this step declares`));
|
|
780
804
|
const name = d.as ?? child;
|
|
805
|
+
const startAsAStep = (payload: P): Effect.Effect<unknown, unknown, R2> => ((STARTS_AS_A_STEP.get(child) ?? d.workflow.execute) as (payload: P) => Effect.Effect<unknown, unknown, R2>)(payload);
|
|
781
806
|
const declaration: StepDeclaration = {
|
|
782
|
-
name,
|
|
807
|
+
name, runs: null, kind: 'sub-workflow', workflow: child,
|
|
783
808
|
description: DECLARED.get(child)?.description ?? `Runs ${child}.`,
|
|
784
809
|
source: DECLARED.get(child)?.source ?? { path: sourcePath(d.at), anchor: `'${child}'` },
|
|
785
810
|
agentUnder: () => {
|
|
@@ -802,7 +827,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
802
827
|
execute: pipe(
|
|
803
828
|
standDownIfSurplus({ agent: false, picks: false }),
|
|
804
829
|
Effect.andThen(Effect.flatMap(d.workflow.executionId(payload), (childRun) =>
|
|
805
|
-
measured(declaration, options?.call ?? null, null, undefined, undefined, undefined, Effect.flatMap(
|
|
830
|
+
measured(declaration, options?.call ?? null, null, undefined, undefined, undefined, Effect.flatMap(startAsAStep(payload), given), childRun))),
|
|
806
831
|
Effect.mapError(describeFailure),
|
|
807
832
|
),
|
|
808
833
|
}),
|
|
@@ -858,6 +883,11 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
858
883
|
/** Every item it has a task for, done or not (`WorkflowDeclaration.items`), in place of `pending`. */
|
|
859
884
|
readonly items?: () => Effect.Effect<ReadonlyArray<string>, unknown, R>;
|
|
860
885
|
readonly picksQueueHead?: true;
|
|
886
|
+
/**
|
|
887
|
+
* The workflows whose results become its tasks: the arrows of the project's map (`views/workflow-flows.ts`). A workflow
|
|
888
|
+
* used as a step of another needs none: it is drawn inside that one.
|
|
889
|
+
*/
|
|
890
|
+
readonly fedBy?: ReadonlyArray<string>;
|
|
861
891
|
/** Its step graph: which step can follow which, and when. */
|
|
862
892
|
readonly graph?: () => ReadonlyArray<StepEdge>;
|
|
863
893
|
/** What it runs on: its trigger starts a run only when they changed (`runIfInputsChanged`). */
|
|
@@ -897,6 +927,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
897
927
|
...(d.pending === undefined ? {} : { pending: d.pending }),
|
|
898
928
|
...(d.items === undefined ? {} : { items: d.items }),
|
|
899
929
|
...(d.picksQueueHead === undefined ? {} : { picksQueueHead: d.picksQueueHead }),
|
|
930
|
+
...(d.fedBy === undefined ? {} : { fedBy: d.fedBy }),
|
|
900
931
|
...(d.inputs === undefined ? {} : { inputs: d.inputs }),
|
|
901
932
|
...(d.taskInputs === undefined ? {} : { taskInputs: d.taskInputs }),
|
|
902
933
|
item: d.item,
|
|
@@ -907,6 +938,8 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
907
938
|
executionIdOf: (payload) => workflow.executionId(payload),
|
|
908
939
|
});
|
|
909
940
|
const toLayer = workflow.toLayer.bind(workflow);
|
|
941
|
+
// Its start as a step of another workflow, which no run limit of its own gates (`defineSubWorkflow`).
|
|
942
|
+
STARTS_AS_A_STEP.set(name, execute as (payload: unknown) => Effect.Effect<unknown, unknown, unknown>);
|
|
910
943
|
Object.assign(workflow, { execute: gatedExecute });
|
|
911
944
|
// Every run of every workflow ends here: its items' outcomes are recorded, and the next run can start at once.
|
|
912
945
|
return Object.assign(workflow, {
|
|
@@ -995,7 +1028,7 @@ export const makeSteps = <Phase extends string, R>(deps: {
|
|
|
995
1028
|
states: { readonly phase: Phase; readonly description: string; readonly stepDescription: string; readonly at: string; readonly writes?: ReadonlyArray<string>; readonly inputs?: WorkflowInputs<R> },
|
|
996
1029
|
name: string, step: string, success: Schema.Codec<A, unknown>, execute: Effect.Effect<A, E, R2>,
|
|
997
1030
|
) => {
|
|
998
|
-
const theStep = defineStep({ name: step,
|
|
1031
|
+
const theStep = defineStep({ name: step, runs: 'deterministic', shared: true, description: states.stepDescription, at: states.at, success, ...(states.writes === undefined ? {} : { writes: states.writes }) });
|
|
999
1032
|
const workflow = defineWorkflow({ phase: states.phase, description: states.description, at: states.at, steps: () => [theStep], item: null, ...(states.inputs === undefined ? {} : { inputs: states.inputs }),
|
|
1000
1033
|
graph: () => [{ from: RUN_STARTS, to: step, when: 'each turn' }, { from: step, to: RUN_ENDS, when: 'always' }] })(name, {
|
|
1001
1034
|
payload: { turn: Schema.Number },
|