@jive-sh/workflow-platform 0.1.0 → 0.2.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 +17 -5
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/steps.js +40 -3
- package/dist/steps.js.map +1 -1
- package/dist/storage/sqlite-store.js +33 -0
- package/dist/storage/sqlite-store.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 +12 -1
- package/dist/views/workflows-view.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +19 -7
- package/src/steps.ts +48 -3
- package/src/storage/sqlite-store.ts +42 -1
- package/src/storage/task-store.ts +32 -0
- package/src/views/workflow-flows.ts +97 -0
- package/src/views/workflows-view.ts +40 -5
|
@@ -15,8 +15,22 @@ import type { StorageError } from '../storage/storage-error';
|
|
|
15
15
|
import type { EngineRecords } from '../storage/engine-records';
|
|
16
16
|
import type { FunnelStepRecord, RunCost, RunOutcomeRow, StepRecords, StepRunRow } from '../storage/step-records';
|
|
17
17
|
import { bucketCounts, type Bucket, type Tasks } from '../tasks';
|
|
18
|
+
import type { QueueCount, TaskStore } from '../storage/task-store';
|
|
18
19
|
import { stepFunnel, type StepFunnel } from './step-funnel';
|
|
19
20
|
import { workflowGraphs, type WorkflowGraph } from './step-graph';
|
|
21
|
+
import { pipelinePlaces, workflowFlows, type PipelinePlace, type WorkflowFlow } from './workflow-flows';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* WHAT STARTS ITS RUNS, from its declaration: its queue (a list of work, its runs kept going while it has some), its inputs
|
|
25
|
+
* changing (`inputs`, in its own words), or neither, a timer or a request.
|
|
26
|
+
*/
|
|
27
|
+
export type StartsOn =
|
|
28
|
+
| { readonly kind: 'queue' }
|
|
29
|
+
| { readonly kind: 'inputs'; readonly says: string }
|
|
30
|
+
| { readonly kind: 'timer or request' };
|
|
31
|
+
|
|
32
|
+
/** How long the queues' history reaches back. */
|
|
33
|
+
export const QUEUE_HISTORY_DAYS = 7;
|
|
20
34
|
|
|
21
35
|
/** What one step of a workflow cost over the window, from its records: none for a step with no record in it. */
|
|
22
36
|
export interface StepCost {
|
|
@@ -133,10 +147,11 @@ export interface WorkflowView {
|
|
|
133
147
|
readonly finishedWord: string | null;
|
|
134
148
|
readonly usesAgents: boolean;
|
|
135
149
|
/**
|
|
136
|
-
* Its limits: how many of
|
|
137
|
-
*
|
|
150
|
+
* Its limits: how many runs of it may go at once (`runs`, none for no limit; `runsSet` false where that is the default),
|
|
151
|
+
* and, for a workflow its budget keeps going, how many of its runs may be in an agent step at once (`agents`, none for
|
|
152
|
+
* any other). None where no store is read.
|
|
138
153
|
*/
|
|
139
|
-
readonly limits: { readonly agents: number; readonly runs: number; readonly runsSet: boolean } | null;
|
|
154
|
+
readonly limits: { readonly agents: number | null; readonly runs: number | null; readonly runsSet: boolean } | null;
|
|
140
155
|
/** Why it is paused; none while it is not. */
|
|
141
156
|
readonly paused: string | null;
|
|
142
157
|
readonly steps: ReadonlyArray<StepView>;
|
|
@@ -150,6 +165,12 @@ export interface WorkflowView {
|
|
|
150
165
|
readonly yields: { readonly now: Yield; readonly before: Yield };
|
|
151
166
|
/** Its tasks by bucket; none for a workflow with no item. */
|
|
152
167
|
readonly queue: Readonly<Record<Bucket, number>> | null;
|
|
168
|
+
/** What starts its runs. */
|
|
169
|
+
readonly startsOn: StartsOn;
|
|
170
|
+
/** The workflows whose results become its tasks, as declared (`fedBy`). */
|
|
171
|
+
readonly fedBy: ReadonlyArray<string>;
|
|
172
|
+
/** Its place in the pipeline: what the DAG lays it out by. */
|
|
173
|
+
readonly place: PipelinePlace;
|
|
153
174
|
}
|
|
154
175
|
|
|
155
176
|
export interface WorkflowsView {
|
|
@@ -158,6 +179,10 @@ export interface WorkflowsView {
|
|
|
158
179
|
readonly hours: number;
|
|
159
180
|
readonly since: number;
|
|
160
181
|
readonly groups: ReadonlyArray<{ readonly phase: string; readonly workflows: ReadonlyArray<WorkflowView> }>;
|
|
182
|
+
/** Where work goes between workflows: the DAG's edges (`workflow-flows.ts`). */
|
|
183
|
+
readonly flows: ReadonlyArray<WorkflowFlow>;
|
|
184
|
+
/** Each queue's counts over the last `QUEUE_HISTORY_DAYS`, a row where one changed, oldest first. */
|
|
185
|
+
readonly queueHistory: ReadonlyArray<QueueCount>;
|
|
161
186
|
}
|
|
162
187
|
|
|
163
188
|
const NO_COST: StepCost = { calls: 0, failed: 0, open: 0, seconds: 0, inputTokens: 0, outputTokens: 0, cpuSeconds: 0, compiles: 0, items: 0 };
|
|
@@ -182,7 +207,7 @@ export const costOf = (rows: ReadonlyArray<StepRunRow>): StepCost | null =>
|
|
|
182
207
|
items: new Set(rows.flatMap((r) => (r.subject === null ? [] : [r.subject.toLowerCase()]))).size,
|
|
183
208
|
};
|
|
184
209
|
|
|
185
|
-
type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph'> & {
|
|
210
|
+
type Declared = Pick<WorkflowDeclaration<string, unknown>, 'name' | 'phase' | 'description' | 'source' | 'item' | 'finishedWord' | 'graph' | 'fedBy' | 'pending' | 'inputs'> & {
|
|
186
211
|
readonly steps: () => ReadonlyArray<StepDeclaration>;
|
|
187
212
|
};
|
|
188
213
|
|
|
@@ -196,6 +221,8 @@ export const buildWorkflowsView = (input: {
|
|
|
196
221
|
readonly records: StepRecords;
|
|
197
222
|
readonly engine: EngineRecords;
|
|
198
223
|
readonly tasks: Pick<Tasks, 'taskSummaries'>;
|
|
224
|
+
/** The queues' history and the new input between workflows, from the task store. */
|
|
225
|
+
readonly taskStore: Pick<TaskStore, 'queueCountsSince' | 'newInputFlows' | 'listedWaits'>;
|
|
199
226
|
/** The line a definition's text is on now. */
|
|
200
227
|
readonly locate: (source: SourceRef) => number | null;
|
|
201
228
|
readonly limitsOf: (workflow: string) => WorkflowView['limits'];
|
|
@@ -216,6 +243,10 @@ export const buildWorkflowsView = (input: {
|
|
|
216
243
|
const queues = new Map(yield* Effect.forEach(input.declared.filter((d) => d.item !== null), (d) =>
|
|
217
244
|
Effect.map(input.tasks.taskSummaries({ workflow: d.name }), (tasks) => [d.name, bucketCounts(tasks)] as const)));
|
|
218
245
|
const graphs = new Map(workflowGraphs({ declared: input.declared, taken: moves.edges, lasts: moves.lasts, going }).map((g) => [g.workflow, g]));
|
|
246
|
+
const flows = workflowFlows({ declared: input.declared, newInputs: yield* input.taskStore.newInputFlows(), waits: yield* input.taskStore.listedWaits() });
|
|
247
|
+
const phases = [...input.phases, ...[...new Set(input.declared.map((d) => d.phase))].filter((p) => !input.phases.includes(p))];
|
|
248
|
+
const places = new Map(pipelinePlaces({ workflows: input.declared.map((d) => ({ name: d.name, stage: d.phase })), stages: phases, flows }).map((p) => [p.workflow, p]));
|
|
249
|
+
const queueHistory = yield* input.taskStore.queueCountsSince(input.now - QUEUE_HISTORY_DAYS * 86_400);
|
|
219
250
|
|
|
220
251
|
const link = (s: SourceRef): SourceLink => ({ ...s, line: input.locate(s) });
|
|
221
252
|
|
|
@@ -257,12 +288,16 @@ export const buildWorkflowsView = (input: {
|
|
|
257
288
|
total: steps.reduce((t, s) => (s.cost === null ? t : addCosts(t, s.cost)), NO_COST),
|
|
258
289
|
graph: graphs.get(d.name)!,
|
|
259
290
|
queue: queues.get(d.name) ?? null,
|
|
291
|
+
startsOn: d.pending !== undefined ? { kind: 'queue' } : d.inputs !== undefined ? { kind: 'inputs', says: d.inputs.says } : { kind: 'timer or request' },
|
|
292
|
+
fedBy: d.fedBy ?? [],
|
|
293
|
+
place: places.get(d.name)!,
|
|
260
294
|
};
|
|
261
295
|
};
|
|
262
296
|
|
|
263
|
-
const phases = [...input.phases, ...[...new Set(input.declared.map((d) => d.phase))].filter((p) => !input.phases.includes(p))];
|
|
264
297
|
return {
|
|
265
298
|
at: input.now, hours: input.hours, since,
|
|
266
299
|
groups: phases.map((phase) => ({ phase, workflows: input.declared.filter((d) => d.phase === phase).map(workflowView) })).filter((g) => g.workflows.length > 0),
|
|
300
|
+
flows,
|
|
301
|
+
queueHistory,
|
|
267
302
|
};
|
|
268
303
|
});
|