@jive-sh/workflow-platform 0.6.3 → 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/README.md +66 -295
- package/component/_generated/api.ts +72 -0
- package/component/_generated/component.ts +621 -0
- package/component/_generated/dataModel.ts +60 -0
- package/component/_generated/server.ts +169 -0
- package/component/convex.config.ts +3 -0
- package/component/engine.ts +755 -0
- package/component/errors.ts +66 -0
- package/component/events.ts +17 -0
- package/component/notes.ts +13 -0
- package/component/places.ts +136 -0
- package/component/retention.ts +205 -0
- package/component/runEngine.ts +25 -0
- package/component/schema.ts +132 -0
- package/component/steps.ts +188 -0
- package/component/store.ts +512 -0
- package/component/tasks.ts +289 -0
- package/component/worker.ts +109 -0
- package/component/workflows.ts +83 -0
- package/dist/definition/agent-runner.js +9 -0
- package/dist/definition/agent-runner.js.map +1 -0
- package/dist/definition/file-store.js +9 -0
- package/dist/definition/file-store.js.map +1 -0
- package/dist/definition/program-build.js +10 -0
- package/dist/definition/program-build.js.map +1 -0
- package/dist/definition/step.js +1 -0
- package/dist/definition/step.js.map +1 -0
- package/dist/definition/task-schema.js +5 -0
- package/dist/definition/task-schema.js.map +1 -0
- package/dist/definition/tasks.js +9 -0
- package/dist/definition/tasks.js.map +1 -0
- package/dist/definition/workflow.js +111 -0
- package/dist/definition/workflow.js.map +1 -0
- package/dist/graph.js +301 -9
- package/dist/graph.js.map +1 -1
- package/dist/index.js +7 -133
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/definition/agent-runner.ts +59 -0
- package/src/definition/file-store.ts +20 -0
- package/src/definition/program-build.ts +30 -0
- package/src/definition/step.ts +106 -0
- package/src/definition/task-schema.ts +15 -0
- package/src/definition/tasks.ts +43 -0
- package/src/definition/workflow.ts +255 -0
- package/src/graph.ts +341 -19
- package/src/index.ts +8 -168
- package/worker/directory-file-store.ts +42 -0
- package/worker/index.ts +12 -0
- package/worker/platform-client.ts +138 -0
- package/worker/step-meter.ts +80 -0
- package/worker/worker-tasks.ts +27 -0
- package/worker/worker.test.ts +200 -0
- package/worker/worker.ts +240 -0
- package/dist/budget-states.js +0 -30
- package/dist/budget-states.js.map +0 -1
- package/dist/cpu-limit/limiter.js +0 -839
- package/dist/cpu-limit/limiter.js.map +0 -1
- package/dist/cpu-limit/use.js +0 -139
- package/dist/cpu-limit/use.js.map +0 -1
- package/dist/dashboard/agent-usage.js +0 -25
- package/dist/dashboard/agent-usage.js.map +0 -1
- package/dist/dashboard/dashboard.css +0 -134
- package/dist/dashboard/drilldown.js +0 -16
- package/dist/dashboard/drilldown.js.map +0 -1
- package/dist/dashboard/queue-lines.js +0 -44
- package/dist/dashboard/queue-lines.js.map +0 -1
- package/dist/dashboard/queue-table.js +0 -16
- package/dist/dashboard/queue-table.js.map +0 -1
- package/dist/dashboard/spending-words.js +0 -32
- package/dist/dashboard/spending-words.js.map +0 -1
- package/dist/failure.js +0 -35
- package/dist/failure.js.map +0 -1
- package/dist/keep-running.js +0 -77
- package/dist/keep-running.js.map +0 -1
- package/dist/outside-failure.js +0 -31
- package/dist/outside-failure.js.map +0 -1
- package/dist/pick-wakes.js +0 -125
- package/dist/pick-wakes.js.map +0 -1
- package/dist/project.js +0 -1
- package/dist/project.js.map +0 -1
- package/dist/queue-counts.js +0 -51
- package/dist/queue-counts.js.map +0 -1
- package/dist/reasons.js +0 -33
- package/dist/reasons.js.map +0 -1
- package/dist/spending-limit.js +0 -88
- package/dist/spending-limit.js.map +0 -1
- package/dist/step-files.js +0 -200
- package/dist/step-files.js.map +0 -1
- package/dist/step-meter.js +0 -97
- package/dist/step-meter.js.map +0 -1
- package/dist/step-usage.js +0 -19
- package/dist/step-usage.js.map +0 -1
- package/dist/steps.js +0 -920
- package/dist/steps.js.map +0 -1
- package/dist/storage/budgets.js +0 -85
- package/dist/storage/budgets.js.map +0 -1
- package/dist/storage/engine-records.js +0 -75
- package/dist/storage/engine-records.js.map +0 -1
- package/dist/storage/engine-storage.js +0 -67
- package/dist/storage/engine-storage.js.map +0 -1
- package/dist/storage/input-records.js +0 -12
- package/dist/storage/input-records.js.map +0 -1
- package/dist/storage/move-store.js +0 -251
- package/dist/storage/move-store.js.map +0 -1
- package/dist/storage/sqlite-store.js +0 -723
- package/dist/storage/sqlite-store.js.map +0 -1
- package/dist/storage/step-records.js +0 -11
- package/dist/storage/step-records.js.map +0 -1
- package/dist/storage/storage-error.js +0 -19
- package/dist/storage/storage-error.js.map +0 -1
- package/dist/storage/task-store.js +0 -24
- package/dist/storage/task-store.js.map +0 -1
- package/dist/tasks.js +0 -475
- package/dist/tasks.js.map +0 -1
- package/dist/views/format.js +0 -37
- package/dist/views/format.js.map +0 -1
- package/dist/views/runs-now.js +0 -75
- package/dist/views/runs-now.js.map +0 -1
- package/dist/views/step-funnel.js +0 -98
- package/dist/views/step-funnel.js.map +0 -1
- package/dist/views/step-graph.js +0 -34
- package/dist/views/step-graph.js.map +0 -1
- package/dist/views/workflow-flows.js +0 -53
- package/dist/views/workflow-flows.js.map +0 -1
- package/dist/views/workflows-view.js +0 -230
- package/dist/views/workflows-view.js.map +0 -1
- package/src/budget-states.ts +0 -55
- package/src/cpu-limit/limiter.ts +0 -935
- package/src/cpu-limit/use.ts +0 -166
- package/src/dashboard/agent-usage-line.tsx +0 -28
- package/src/dashboard/agent-usage.ts +0 -48
- package/src/dashboard/dashboard.css +0 -134
- package/src/dashboard/drilldown.ts +0 -43
- package/src/dashboard/index.tsx +0 -4
- package/src/dashboard/machine-controls.tsx +0 -53
- package/src/dashboard/queue-bar.tsx +0 -43
- package/src/dashboard/queue-chart.tsx +0 -150
- package/src/dashboard/queue-lines.ts +0 -87
- package/src/dashboard/queue-table.ts +0 -37
- package/src/dashboard/spending-limit-control.tsx +0 -50
- package/src/dashboard/spending-words.ts +0 -50
- package/src/dashboard/step-graph.tsx +0 -106
- package/src/dashboard/workflow-dag.tsx +0 -204
- package/src/dashboard/workflow-drilldown.tsx +0 -89
- package/src/dashboard/workflows-dashboard.tsx +0 -414
- package/src/failure.ts +0 -36
- package/src/keep-running.ts +0 -83
- package/src/outside-failure.ts +0 -39
- package/src/pick-wakes.ts +0 -182
- package/src/project.ts +0 -115
- package/src/queue-counts.ts +0 -64
- package/src/reasons.ts +0 -30
- package/src/spending-limit.ts +0 -156
- package/src/step-files.ts +0 -208
- package/src/step-meter.ts +0 -120
- package/src/step-usage.ts +0 -23
- package/src/steps.ts +0 -1239
- package/src/storage/budgets.ts +0 -113
- package/src/storage/engine-records.ts +0 -102
- package/src/storage/engine-storage.ts +0 -82
- package/src/storage/input-records.ts +0 -43
- package/src/storage/move-store.ts +0 -265
- package/src/storage/sqlite-store.ts +0 -829
- package/src/storage/step-records.ts +0 -306
- package/src/storage/storage-error.ts +0 -35
- package/src/storage/task-store.ts +0 -235
- package/src/tasks.ts +0 -561
- package/src/views/format.ts +0 -40
- package/src/views/runs-now.ts +0 -120
- package/src/views/step-funnel.ts +0 -163
- package/src/views/step-graph.ts +0 -68
- package/src/views/workflow-flows.ts +0 -97
- package/src/views/workflows-view.ts +0 -443
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A PROJECT'S WORKFLOWS AS ITS DASHBOARD SHOWS THEM, READ FROM THE RECORDS AT EACH REQUEST, in two readings:
|
|
3
|
-
*
|
|
4
|
-
* every workflow what it is, its steps with their kinds, its limits, and its tasks by status with their history
|
|
5
|
-
* (`buildWorkflowsView`): what a page shows before a workflow is opened, a few small readings.
|
|
6
|
-
* one workflow its steps and their cost over a window, its step graph with the window's runs on it, and where its
|
|
7
|
-
* runs stopped and why (`buildWorkflowFigures`): read from its own records when a page opens it.
|
|
8
|
-
*
|
|
9
|
-
* Built whole and stored by a job every 5 minutes, the two were one view: 5.7 s of reading on a busy machine, 4.4 s of it
|
|
10
|
-
* three scans of every step record for figures only an opened workflow shows, and a page up to 5 minutes old (2026-11-17).
|
|
11
|
-
* Built from the declarations and the stores alone, so any project's workflows read the same; a project adds its own
|
|
12
|
-
* panels beside it. Where its runs are now (`runs-now.ts`) is read at each request too.
|
|
13
|
-
*/
|
|
14
|
-
import { stepKindOf, stepUsesAnAgent } from '../steps';
|
|
15
|
-
import { pipelinePlaces, workflowFlows } from './workflow-flows';
|
|
16
|
-
import { Effect } from 'effect';
|
|
17
|
-
import { QUEUED_NEEDING_AN_AGENT } from '../queue-counts';
|
|
18
|
-
import { TASK_STATUSES } from '../tasks';
|
|
19
|
-
import { stepFunnel } from './step-funnel';
|
|
20
|
-
import { workflowGraphs } from './step-graph';
|
|
21
|
-
/** How long the queues' history reaches back. */
|
|
22
|
-
export const QUEUE_HISTORY_DAYS = 7;
|
|
23
|
-
const medianOf = (xs) => {
|
|
24
|
-
const sorted = [...xs].sort((a, b) => a - b);
|
|
25
|
-
const mid = Math.floor(sorted.length / 2);
|
|
26
|
-
return sorted.length % 2 === 1 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
|
|
27
|
-
};
|
|
28
|
-
/** A workflow's ended runs as their costs: the median run, figure by figure, and the costliest. Pure. */
|
|
29
|
-
export const runCostsOf = (costs) => {
|
|
30
|
-
const ended = costs.filter((c) => !c.going);
|
|
31
|
-
if (ended.length === 0)
|
|
32
|
-
return { runs: 0, median: null, costliest: null };
|
|
33
|
-
const costliest = ended.reduce((a, b) => (b.cpuSeconds > a.cpuSeconds ? b : a));
|
|
34
|
-
return {
|
|
35
|
-
runs: ended.length,
|
|
36
|
-
median: {
|
|
37
|
-
seconds: medianOf(ended.map((c) => c.seconds)), tokens: medianOf(ended.map((c) => c.tokens)), cpuSeconds: medianOf(ended.map((c) => c.cpuSeconds)),
|
|
38
|
-
childCpuSeconds: medianOf(ended.map((c) => c.childCpuSeconds)), compiles: medianOf(ended.map((c) => c.compiles)),
|
|
39
|
-
},
|
|
40
|
-
costliest: { run: costliest.run, started: costliest.started, seconds: costliest.seconds, tokens: costliest.tokens, cpuSeconds: costliest.cpuSeconds, compiles: costliest.compiles },
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
/** Endings listed per step; the rest are added up as one. */
|
|
44
|
-
export const ENDINGS_LISTED = 4;
|
|
45
|
-
/** A step's records as their endings, commonest first. Pure. */
|
|
46
|
-
export const endingsOf = (records) => {
|
|
47
|
-
const counts = new Map();
|
|
48
|
-
for (const r of records) {
|
|
49
|
-
const outcome = r.outcome ?? 'going';
|
|
50
|
-
const reason = r.reason ?? (r.outcome === null ? 'still going' : 'no reason recorded');
|
|
51
|
-
const key = `${outcome}\u0000${reason}`;
|
|
52
|
-
const was = counts.get(key);
|
|
53
|
-
counts.set(key, { outcome, reason, records: (was?.records ?? 0) + 1 });
|
|
54
|
-
}
|
|
55
|
-
const all = [...counts.values()].sort((a, b) => b.records - a.records || a.reason.localeCompare(b.reason));
|
|
56
|
-
const rest = all.slice(ENDINGS_LISTED).reduce((n, e) => n + e.records, 0);
|
|
57
|
-
return [...all.slice(0, ENDINGS_LISTED), ...(rest === 0 ? [] : [{ outcome: 'other', reason: `${all.length - ENDINGS_LISTED} other endings`, records: rest }])];
|
|
58
|
-
};
|
|
59
|
-
/** A window's yield from its counts. Pure. */
|
|
60
|
-
export const yieldOf = (r) => ({
|
|
61
|
-
...r,
|
|
62
|
-
perRun: r.runs === 0 ? null : r.finished / r.runs,
|
|
63
|
-
perMillionTokens: r.tokens === 0 ? null : (r.finished * 1_000_000) / r.tokens,
|
|
64
|
-
perCompile: r.compiles === 0 ? null : r.finished / r.compiles,
|
|
65
|
-
});
|
|
66
|
-
const NO_COST = { calls: 0, failed: 0, open: 0, seconds: 0, inputTokens: 0, outputTokens: 0, cpuSeconds: 0, compiles: 0, items: 0 };
|
|
67
|
-
const addCosts = (a, b) => ({
|
|
68
|
-
calls: a.calls + b.calls, failed: a.failed + b.failed, open: a.open + b.open, seconds: a.seconds + b.seconds,
|
|
69
|
-
inputTokens: a.inputTokens + b.inputTokens, outputTokens: a.outputTokens + b.outputTokens, cpuSeconds: a.cpuSeconds + b.cpuSeconds,
|
|
70
|
-
compiles: a.compiles + b.compiles, items: a.items + b.items,
|
|
71
|
-
});
|
|
72
|
-
/** One step's rows (one per run, step and subject) as its cost. Pure. */
|
|
73
|
-
export const costOf = (rows) => rows.length === 0 ? null : {
|
|
74
|
-
calls: rows.reduce((n, r) => n + r.calls, 0),
|
|
75
|
-
failed: rows.reduce((n, r) => n + r.failed, 0),
|
|
76
|
-
open: rows.reduce((n, r) => n + r.open, 0),
|
|
77
|
-
seconds: rows.reduce((n, r) => n + r.ms, 0) / 1000,
|
|
78
|
-
inputTokens: rows.reduce((n, r) => n + (r.fresh ?? 0) + (r.cache_write ?? 0) + (r.cache_read ?? 0), 0),
|
|
79
|
-
outputTokens: rows.reduce((n, r) => n + (r.output ?? 0), 0),
|
|
80
|
-
cpuSeconds: rows.reduce((n, r) => n + r.cpu_seconds, 0),
|
|
81
|
-
compiles: rows.reduce((n, r) => n + (r.compiles ?? 0), 0),
|
|
82
|
-
items: new Set(rows.flatMap((r) => (r.subject === null ? [] : [r.subject.toLowerCase()]))).size,
|
|
83
|
-
};
|
|
84
|
-
const noTasks = () => Object.fromEntries(TASK_STATUSES.map((s) => [s, 0]));
|
|
85
|
-
/**
|
|
86
|
-
* The names a count was recorded under before 2026-11-19, when a task stood in one of six buckets, and the status each is
|
|
87
|
-
* part of now. `queued` and `done` kept their names.
|
|
88
|
-
*/
|
|
89
|
-
const RECORDED_BEFORE = { running: 'in progress', waiting: 'blocked', stuck: 'blocked', held: 'blocked' };
|
|
90
|
-
/**
|
|
91
|
-
* THE RECORDED COUNTS (`queueCountsSince`, oldest first) AS THE FOUR STATUSES: a row for each status of each workflow where
|
|
92
|
-
* its count moved. A count recorded under an older name is part of its status until the workflow has a count under the
|
|
93
|
-
* four, which replaces it; one recorded under an older name after that (by code still running as the newer began) is
|
|
94
|
-
* not read. Pure.
|
|
95
|
-
*/
|
|
96
|
-
export const historyByStatus = (recorded) => {
|
|
97
|
-
const raw = new Map();
|
|
98
|
-
const countedByStatus = new Set();
|
|
99
|
-
const last = new Map();
|
|
100
|
-
const out = [];
|
|
101
|
-
recorded.forEach((row, i) => {
|
|
102
|
-
const counts = raw.get(row.workflow) ?? new Map();
|
|
103
|
-
raw.set(row.workflow, counts);
|
|
104
|
-
const olderName = RECORDED_BEFORE[row.bucket] !== undefined;
|
|
105
|
-
if (!olderName && (row.bucket === 'in progress' || row.bucket === 'blocked') && !countedByStatus.has(row.workflow)) {
|
|
106
|
-
countedByStatus.add(row.workflow);
|
|
107
|
-
for (const older of Object.keys(RECORDED_BEFORE))
|
|
108
|
-
counts.delete(older);
|
|
109
|
-
}
|
|
110
|
-
if (!(olderName && countedByStatus.has(row.workflow)))
|
|
111
|
-
counts.set(row.bucket, row.tasks);
|
|
112
|
-
// Every row of one moment is one count of the workflow: its statuses are read once all of them are in.
|
|
113
|
-
const next = recorded[i + 1];
|
|
114
|
-
if (next !== undefined && next.workflow === row.workflow && next.at === row.at)
|
|
115
|
-
return;
|
|
116
|
-
for (const status of TASK_STATUSES) {
|
|
117
|
-
const tasks = [...counts].reduce((sum, [name, n]) => sum + (name === status || RECORDED_BEFORE[name] === status ? n : 0), 0);
|
|
118
|
-
const key = `${row.workflow}\u0000${status}`;
|
|
119
|
-
if (last.get(key) !== tasks)
|
|
120
|
-
out.push({ at: row.at, workflow: row.workflow, bucket: status, tasks });
|
|
121
|
-
last.set(key, tasks);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return out;
|
|
125
|
-
};
|
|
126
|
-
/** Each queue's newest count of queued tasks marked as needing an agent, from the recorded counts (oldest first). Pure. */
|
|
127
|
-
export const queuedNeedingAnAgentNow = (recorded) => new Map(recorded.filter((row) => row.bucket === QUEUED_NEEDING_AN_AGENT).map((row) => [row.workflow, row.tasks]));
|
|
128
|
-
/** Each queue's newest count from its history by status (`historyByStatus`), a status never counted at 0. Pure. */
|
|
129
|
-
export const queuesNow = (history) => {
|
|
130
|
-
const queues = new Map();
|
|
131
|
-
for (const row of history) {
|
|
132
|
-
const queue = queues.get(row.workflow) ?? noTasks();
|
|
133
|
-
if (TASK_STATUSES.includes(row.bucket))
|
|
134
|
-
queue[row.bucket] = row.tasks;
|
|
135
|
-
queues.set(row.workflow, queue);
|
|
136
|
-
}
|
|
137
|
-
return queues;
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* EVERY WORKFLOW AS A PAGE SHOWS IT BEFORE ONE IS OPENED, READ AT THE REQUEST: the declarations, the limits, each queue's
|
|
141
|
-
* counts as last counted and their history. A few small readings of the store, so a
|
|
142
|
-
* page load needs no stored copy of it. `limitsOf` is none where no store is read.
|
|
143
|
-
*/
|
|
144
|
-
export const buildWorkflowsView = (input) => Effect.gen(function* () {
|
|
145
|
-
const stepSummary = (s) => ({ name: s.name, kind: stepKindOf(s), runs: s.runs, description: s.description, workflow: s.workflow ?? null });
|
|
146
|
-
// Until the project declares its top workflow, its steps are every workflow no other workflow uses as a step.
|
|
147
|
-
const usedAsAStep = new Set(input.declared.flatMap((d) => d.steps().flatMap((s) => (s.workflow === undefined ? [] : [s.workflow]))));
|
|
148
|
-
const phases = [...input.phases, ...[...new Set(input.declared.map((d) => d.phase))].filter((p) => !input.phases.includes(p))];
|
|
149
|
-
const recordedCounts = yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400);
|
|
150
|
-
const queueHistory = historyByStatus(recordedCounts);
|
|
151
|
-
const queues = queuesNow(queueHistory);
|
|
152
|
-
const needingAnAgent = queuedNeedingAnAgentNow(recordedCounts);
|
|
153
|
-
// The map is of the top workflow's steps: a workflow used as a step of another is drawn inside that one, not here.
|
|
154
|
-
const onTheMap = input.declared.filter((d) => !usedAsAStep.has(d.name));
|
|
155
|
-
const flows = workflowFlows({ declared: onTheMap, returned: yield* input.taskStore.returnedBetween(), waits: yield* input.taskStore.listedWaits() });
|
|
156
|
-
const places = new Map(pipelinePlaces({ workflows: input.declared.map((d) => ({ name: d.name, stage: d.phase })), stages: phases, flows }).map((p) => [p.workflow, p]));
|
|
157
|
-
const workflowView = (d) => ({
|
|
158
|
-
name: d.name, steps: d.steps().map(stepSummary),
|
|
159
|
-
phase: d.phase, description: d.description, source: { ...d.source, line: input.locate(d.source) }, item: d.item, finishedWord: d.finishedWord,
|
|
160
|
-
usesAgents: d.steps().some(stepUsesAnAgent),
|
|
161
|
-
// A workflow used as a step has no limit of its own to show: its starts are its parent's steps (`defineSubWorkflow`).
|
|
162
|
-
limits: usedAsAStep.has(d.name) ? null : input.limitsOf(d.name),
|
|
163
|
-
place: places.get(d.name),
|
|
164
|
-
queue: d.item === null ? null : queues.get(d.name) ?? noTasks(),
|
|
165
|
-
queuedNeedingAnAgent: d.item === null || !d.steps().some(stepUsesAnAgent) ? null : needingAnAgent.get(d.name) ?? 0,
|
|
166
|
-
startsOn: usedAsAStep.has(d.name) ? { kind: 'a step', of: input.declared.filter((p) => p.steps().some((s) => s.workflow === d.name)).map((p) => p.name) }
|
|
167
|
-
: d.pending !== undefined || d.items !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
|
|
168
|
-
});
|
|
169
|
-
const inPageOrder = phases.flatMap((phase) => input.declared.filter((d) => d.phase === phase));
|
|
170
|
-
return {
|
|
171
|
-
at: input.now,
|
|
172
|
-
top: {
|
|
173
|
-
...input.top,
|
|
174
|
-
steps: inPageOrder.filter((d) => !usedAsAStep.has(d.name)).map((d) => ({ name: d.name, kind: 'sub-workflow', runs: null, description: d.description, workflow: d.name })),
|
|
175
|
-
},
|
|
176
|
-
groups: phases.map((phase) => ({ phase, workflows: input.declared.filter((d) => d.phase === phase).map(workflowView) })).filter((g) => g.workflows.length > 0),
|
|
177
|
-
queueHistory,
|
|
178
|
-
flows,
|
|
179
|
-
spending: input.spending,
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
/**
|
|
183
|
-
* ONE WORKFLOW'S FIGURES OVER THE `hours` BEFORE `now`, READ FROM ITS OWN RECORDS when a page opens it: each step's cost and
|
|
184
|
-
* endings, its step graph with the runs on each edge, where its runs stopped, what a run costs, and what its runs gave
|
|
185
|
-
* against the window before.
|
|
186
|
-
*/
|
|
187
|
-
export const buildWorkflowFigures = (input) => Effect.gen(function* () {
|
|
188
|
-
const d = input.declaration;
|
|
189
|
-
const since = input.now - input.hours * 3600;
|
|
190
|
-
const before = since - input.hours * 3600;
|
|
191
|
-
const own = yield* input.records.stepRunsSince(since, d.name);
|
|
192
|
-
// The window before, for the trend: its records are those since its start, less the window's own.
|
|
193
|
-
const ownBoth = yield* input.records.stepRunsSince(before, d.name);
|
|
194
|
-
const funnelRecords = yield* input.records.funnelRecordsSince(since, d.name);
|
|
195
|
-
const funnelBoth = yield* input.records.funnelRecordsSince(before, d.name);
|
|
196
|
-
const finishedNow = yield* input.records.runOutcomesSince(since, d.name);
|
|
197
|
-
const finishedBoth = yield* input.records.runOutcomesSince(before, d.name);
|
|
198
|
-
const runCosts = yield* input.records.runCostsSince(since, d.name);
|
|
199
|
-
const moves = yield* input.records.stepEdgesSince(since, d.name);
|
|
200
|
-
const going = new Set((yield* input.engine.unfinishedRuns()).map((u) => u.run));
|
|
201
|
-
const link = (s) => ({ ...s, line: input.locate(s) });
|
|
202
|
-
const declaredSteps = d.steps();
|
|
203
|
-
const onlyInRecords = [...new Set(own.map((r) => r.step))].filter((s) => !declaredSteps.some((x) => x.name === s));
|
|
204
|
-
const steps = [
|
|
205
|
-
...declaredSteps.map((s) => ({ name: s.name, runs: s.runs, description: s.description, source: link(s.source), declared: true, cost: costOf(own.filter((r) => r.step === s.name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === s.name)) })),
|
|
206
|
-
...onlyInRecords.map((name) => ({ name, runs: own.some((r) => r.step === name && r.agent === 1) ? 'agentic' : null, description: 'no longer declared', source: link(d.source), declared: false, cost: costOf(own.filter((r) => r.step === name)), endings: endingsOf(funnelRecords.records.filter((r) => r.step === name)) })),
|
|
207
|
-
];
|
|
208
|
-
const funnel = stepFunnel({ declaration: d, records: funnelRecords.records, outcomes: funnelRecords.outcomes, unfinished: going, hours: input.hours, since, now: input.now });
|
|
209
|
-
const funnelBefore = stepFunnel({ declaration: d, records: funnelBoth.records, outcomes: funnelBoth.outcomes, unfinished: going, hours: input.hours, since: before, now: since });
|
|
210
|
-
const costNow = costOf(own) ?? NO_COST;
|
|
211
|
-
const costBoth = costOf(ownBoth) ?? NO_COST;
|
|
212
|
-
const finished = (outcomes) => outcomes.filter((o) => o.finished === 1).length;
|
|
213
|
-
return {
|
|
214
|
-
workflow: d.name, at: input.now, hours: input.hours, since,
|
|
215
|
-
steps,
|
|
216
|
-
total: steps.reduce((t, s) => (s.cost === null ? t : addCosts(t, s.cost)), NO_COST),
|
|
217
|
-
graph: workflowGraphs({ declared: [d], taken: moves.edges, lasts: moves.lasts, going })[0],
|
|
218
|
-
funnel,
|
|
219
|
-
runCosts: runCostsOf(runCosts),
|
|
220
|
-
...(yield* input.reasons),
|
|
221
|
-
yields: {
|
|
222
|
-
now: yieldOf({ runs: funnel.runs, finished: finished(finishedNow), tokens: costNow.inputTokens + costNow.outputTokens, compiles: costNow.compiles }),
|
|
223
|
-
before: yieldOf({
|
|
224
|
-
runs: funnelBefore.runs, finished: finished(finishedBoth) - finished(finishedNow),
|
|
225
|
-
tokens: costBoth.inputTokens + costBoth.outputTokens - (costNow.inputTokens + costNow.outputTokens), compiles: costBoth.compiles - costNow.compiles,
|
|
226
|
-
}),
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
});
|
|
230
|
-
//# sourceMappingURL=workflows-view.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflows-view.js","sourceRoot":"","sources":["../../../../src/views/workflows-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAgG,MAAM,UAAU,CAAC;AACrJ,OAAO,EAAE,cAAc,EAAE,aAAa,EAAyC,MAAM,kBAAkB,CAAC;AAMxG,OAAO,EAAE,MAA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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC;QACnF,KAAK,EAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAE;QAC3F,MAAM;QACN,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC;QAC9B,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QACzB,MAAM,EAAE;YACN,GAAG,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpJ,MAAM,EAAE,OAAO,CAAC;gBACd,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC;gBACjF,MAAM,EAAE,QAAQ,CAAC,WAAW,GAAG,QAAQ,CAAC,YAAY,GAAG,CAAC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ;aACpJ,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/src/budget-states.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/** WHAT EACH BUDGETED WORKFLOW'S LIMITS ASK FOR AGAINST WHAT IT HAS, for a dashboard and the route that sets a limit. Pure. */
|
|
2
|
-
import { runLimit, type WorkflowBudgetRow } from './storage/budgets';
|
|
3
|
-
|
|
4
|
-
export interface WorkflowBudgetState {
|
|
5
|
-
readonly workflow: string;
|
|
6
|
-
readonly phase: string;
|
|
7
|
-
/** Its agents' limit. */
|
|
8
|
-
readonly budget: number;
|
|
9
|
-
/** Its run limit in force: the one set, or the default (`runLimit`). */
|
|
10
|
-
readonly runs: number;
|
|
11
|
-
/** When a limit last changed, unix seconds. */
|
|
12
|
-
readonly changedAt: number;
|
|
13
|
-
/** Its unfinished runs, whichever step they are on, a run waiting for an item included. */
|
|
14
|
-
readonly running: number;
|
|
15
|
-
/** Its declared work. */
|
|
16
|
-
readonly items: number;
|
|
17
|
-
/** When its newest unfinished run started; null with none running. */
|
|
18
|
-
readonly newestStart: number | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const workflowBudgetStates = (
|
|
22
|
-
workflows: ReadonlyArray<{ readonly name: string; readonly phase: string }>,
|
|
23
|
-
budgets: ReadonlyArray<WorkflowBudgetRow>,
|
|
24
|
-
work: ReadonlyArray<{ readonly workflow: string; readonly items: number }>,
|
|
25
|
-
assigned: ReadonlyArray<{ readonly workflow: string; readonly started: number }>,
|
|
26
|
-
): ReadonlyArray<WorkflowBudgetState> =>
|
|
27
|
-
workflows.map((w) => {
|
|
28
|
-
const row = budgets.find((b) => b.workflow === w.name);
|
|
29
|
-
const runs = assigned.filter((a) => a.workflow === w.name);
|
|
30
|
-
const limits = { agents: row?.budget ?? 0, runs: row?.runs ?? null };
|
|
31
|
-
return {
|
|
32
|
-
workflow: w.name, phase: w.phase, budget: limits.agents, runs: runLimit(limits),
|
|
33
|
-
changedAt: row?.changed_at ?? 0, running: runs.length,
|
|
34
|
-
items: work.find((x) => x.workflow === w.name)?.items ?? 0,
|
|
35
|
-
newestStart: runs.length === 0 ? null : Math.max(...runs.map((r) => r.started)),
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
/** Fewer runs going than its run limit: a run with nothing to pick waits for an item, so work or none, it is a fault. */
|
|
40
|
-
export const belowBudget = (w: Pick<WorkflowBudgetState, 'runs' | 'running'>): boolean => w.running < w.runs;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Whether the trigger started a run above the run limit. Every run going now had started by the newest one's start, so that
|
|
44
|
-
* many were going then; if the limit was already this one, that start went over it. Runs above a limit lowered after they
|
|
45
|
-
* started are finishing their call, and end before the next.
|
|
46
|
-
*/
|
|
47
|
-
export const startedAboveBudget = (w: Pick<WorkflowBudgetState, 'runs' | 'running' | 'newestStart' | 'changedAt'>): boolean =>
|
|
48
|
-
w.running > w.runs && w.newestStart !== null && w.newestStart > w.changedAt;
|
|
49
|
-
|
|
50
|
-
/** Why the route refuses a limit, with its status; null when it takes it. `budgeted` is every workflow with limits. */
|
|
51
|
-
export const budgetRefusal = (workflow: string | null, asked: string, budget: unknown, budgeted: ReadonlyArray<string>): { readonly status: number; readonly error: string } | null => {
|
|
52
|
-
if (workflow === null) return { status: 404, error: `no workflow ${asked}` };
|
|
53
|
-
if (!budgeted.includes(workflow)) return { status: 409, error: `${workflow} has no agent step and no list of work, so it has no budget` };
|
|
54
|
-
return typeof budget === 'number' && Number.isInteger(budget) && budget >= 0 ? null : { status: 400, error: 'budget must be a whole number, 0 or more' };
|
|
55
|
-
};
|