@jive-sh/workflow-platform 0.7.0 → 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 -435
- 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 -196
- 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 -238
- 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 -148
- package/dist/dashboard/drilldown.js +0 -47
- 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/run-doing-words.js +0 -29
- package/dist/dashboard/run-doing-words.js.map +0 -1
- package/dist/dashboard/setting-words.js +0 -18
- package/dist/dashboard/setting-words.js.map +0 -1
- package/dist/dashboard/spending-words.js +0 -24
- 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 -79
- 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/retention.js +0 -59
- package/dist/retention.js.map +0 -1
- package/dist/settings.js +0 -88
- package/dist/settings.js.map +0 -1
- package/dist/spending-limit.js +0 -82
- 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-times.js +0 -114
- package/dist/step-times.js.map +0 -1
- package/dist/step-usage.js +0 -19
- package/dist/step-usage.js.map +0 -1
- package/dist/steps.js +0 -1205
- package/dist/steps.js.map +0 -1
- package/dist/storage/agent-claims.js +0 -3
- package/dist/storage/agent-claims.js.map +0 -1
- package/dist/storage/budgets.js +0 -121
- package/dist/storage/budgets.js.map +0 -1
- package/dist/storage/engine-records.js +0 -91
- 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 -901
- 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 -30
- package/dist/storage/task-store.js.map +0 -1
- package/dist/system-workflows.js +0 -54
- package/dist/system-workflows.js.map +0 -1
- package/dist/tasks.js +0 -500
- 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 -117
- 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 -39
- package/dist/views/step-graph.js.map +0 -1
- package/dist/views/workflows-view.js +0 -236
- package/dist/views/workflows-view.js.map +0 -1
- package/src/budget-states.ts +0 -54
- 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 -148
- package/src/dashboard/drilldown.ts +0 -70
- package/src/dashboard/index.tsx +0 -4
- package/src/dashboard/limits-and-runs.tsx +0 -191
- package/src/dashboard/machine-controls.tsx +0 -53
- package/src/dashboard/queue-bar.tsx +0 -62
- package/src/dashboard/queue-chart.tsx +0 -149
- package/src/dashboard/queue-lines.ts +0 -87
- package/src/dashboard/queue-table.ts +0 -37
- package/src/dashboard/run-doing-words.ts +0 -41
- package/src/dashboard/setting-words.ts +0 -30
- package/src/dashboard/spending-limit-control.tsx +0 -47
- package/src/dashboard/spending-words.ts +0 -32
- package/src/dashboard/time-distribution.tsx +0 -61
- package/src/dashboard/workflow-dag.tsx +0 -322
- package/src/dashboard/workflow-drilldown.tsx +0 -31
- package/src/dashboard/workflows-dashboard.tsx +0 -532
- package/src/failure.ts +0 -36
- package/src/keep-running.ts +0 -85
- package/src/outside-failure.ts +0 -39
- package/src/pick-wakes.ts +0 -182
- package/src/project.ts +0 -127
- package/src/queue-counts.ts +0 -64
- package/src/reasons.ts +0 -30
- package/src/retention.ts +0 -90
- package/src/settings.ts +0 -171
- package/src/spending-limit.ts +0 -139
- package/src/step-files.ts +0 -208
- package/src/step-meter.ts +0 -120
- package/src/step-times.ts +0 -151
- package/src/step-usage.ts +0 -23
- package/src/steps.ts +0 -1616
- package/src/storage/agent-claims.ts +0 -63
- package/src/storage/budgets.ts +0 -152
- package/src/storage/engine-records.ts +0 -119
- 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 -1022
- package/src/storage/step-records.ts +0 -358
- package/src/storage/storage-error.ts +0 -35
- package/src/storage/task-store.ts +0 -235
- package/src/system-workflows.ts +0 -70
- package/src/tasks.ts +0 -586
- package/src/views/format.ts +0 -40
- package/src/views/runs-now.ts +0 -188
- package/src/views/step-funnel.ts +0 -163
- package/src/views/step-graph.ts +0 -77
- package/src/views/workflows-view.ts +0 -484
- package/src/workflow-dag.test.tsx +0 -89
- package/src/workflow-page.test.tsx +0 -170
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { paginationOptsValidator } from "convex/server"
|
|
2
|
+
import { v } from "convex/values"
|
|
3
|
+
import { query } from "./_generated/server"
|
|
4
|
+
import type { Doc } from "./_generated/dataModel"
|
|
5
|
+
import { noSpend, skippedOtherValidator, type StepSpend, stepSpendValidator, taskFileValidator } from "../src/graph"
|
|
6
|
+
|
|
7
|
+
const spreadValidator = v.object({ median: v.number(), p90: v.number() })
|
|
8
|
+
|
|
9
|
+
/** The nearest-rank percentile of `values`, or 0 when there are none. */
|
|
10
|
+
const percentile = (values: ReadonlyArray<number>, fraction: number): number => {
|
|
11
|
+
if (values.length === 0) return 0
|
|
12
|
+
const sorted = [...values].sort((a, b) => a - b)
|
|
13
|
+
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(fraction * sorted.length) - 1))]!
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const spreadOf = (values: ReadonlyArray<number>) => ({ median: percentile(values, 0.5), p90: percentile(values, 0.9) })
|
|
17
|
+
|
|
18
|
+
const tokensOf = (run: Doc<"stepRuns">) => run.spend.fresh + run.spend.cacheWrite + run.spend.cacheRead + run.spend.output
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* One step's figures over the runs that started in `[since, until)`: how many runs, how they ended, what they spent,
|
|
22
|
+
* and, per task (a task's runs added up, retries included), the spread of wall time, CPU and tokens over the tasks
|
|
23
|
+
* whose runs have all finished.
|
|
24
|
+
*/
|
|
25
|
+
export const stepStats = query({
|
|
26
|
+
args: { workflow: v.string(), step: v.string(), since: v.number(), until: v.optional(v.number()) },
|
|
27
|
+
returns: v.object({
|
|
28
|
+
calls: v.number(),
|
|
29
|
+
running: v.number(),
|
|
30
|
+
failed: v.number(),
|
|
31
|
+
endStates: v.array(v.object({ endState: v.string(), runs: v.number() })),
|
|
32
|
+
spend: v.object({
|
|
33
|
+
fresh: v.number(),
|
|
34
|
+
cacheWrite: v.number(),
|
|
35
|
+
cacheRead: v.number(),
|
|
36
|
+
output: v.number(),
|
|
37
|
+
requests: v.number(),
|
|
38
|
+
costUsd: v.number(),
|
|
39
|
+
compiles: v.number(),
|
|
40
|
+
}),
|
|
41
|
+
/** The wall time of the finished runs, added up, so it can be split across steps. */
|
|
42
|
+
wallSeconds: v.number(),
|
|
43
|
+
cpuSeconds: v.object({ own: v.number(), child: v.number() }),
|
|
44
|
+
peakMemoryMb: v.number(),
|
|
45
|
+
filesWritten: v.number(),
|
|
46
|
+
agents: v.array(v.object({ agent: v.string(), runs: v.number() })),
|
|
47
|
+
tasks: v.number(),
|
|
48
|
+
perTask: v.object({ wallSeconds: spreadValidator, cpuSeconds: spreadValidator, tokens: spreadValidator }),
|
|
49
|
+
}),
|
|
50
|
+
handler: async (ctx, args) => {
|
|
51
|
+
const until = args.until ?? Number.MAX_SAFE_INTEGER
|
|
52
|
+
const runs = await ctx.db
|
|
53
|
+
.query("stepRuns")
|
|
54
|
+
.withIndex("by_workflow_step_started", (q) => q.eq("workflow", args.workflow).eq("step", args.step).gte("startedAt", args.since).lt("startedAt", until))
|
|
55
|
+
.collect()
|
|
56
|
+
const count = (what: (run: Doc<"stepRuns">) => string | undefined) => {
|
|
57
|
+
const counts = new Map<string, number>()
|
|
58
|
+
for (const run of runs) {
|
|
59
|
+
const key = what(run)
|
|
60
|
+
if (key !== undefined) counts.set(key, (counts.get(key) ?? 0) + 1)
|
|
61
|
+
}
|
|
62
|
+
return [...counts.entries()]
|
|
63
|
+
}
|
|
64
|
+
const sum = (what: (run: Doc<"stepRuns">) => number) => runs.reduce((total, run) => total + what(run), 0)
|
|
65
|
+
|
|
66
|
+
const byTask = new Map<string, Array<Doc<"stepRuns">>>()
|
|
67
|
+
for (const run of runs) byTask.set(run.task, [...(byTask.get(run.task) ?? []), run])
|
|
68
|
+
const finishedTasks = [...byTask.values()].filter((taskRuns) => taskRuns.every((run) => run.endedAt !== undefined))
|
|
69
|
+
const perTask = (what: (run: Doc<"stepRuns">) => number) => finishedTasks.map((taskRuns) => taskRuns.reduce((total, run) => total + what(run), 0))
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
calls: runs.length,
|
|
73
|
+
running: runs.filter((run) => run.status === "running").length,
|
|
74
|
+
failed: runs.filter((run) => run.status === "failed").length,
|
|
75
|
+
endStates: count((run) => run.endState).map(([endState, total]) => ({ endState, runs: total })),
|
|
76
|
+
spend: {
|
|
77
|
+
fresh: sum((run) => run.spend.fresh),
|
|
78
|
+
cacheWrite: sum((run) => run.spend.cacheWrite),
|
|
79
|
+
cacheRead: sum((run) => run.spend.cacheRead),
|
|
80
|
+
output: sum((run) => run.spend.output),
|
|
81
|
+
requests: sum((run) => run.spend.requests),
|
|
82
|
+
costUsd: sum((run) => run.spend.costUsd),
|
|
83
|
+
compiles: sum((run) => run.spend.compiles),
|
|
84
|
+
},
|
|
85
|
+
wallSeconds: sum((run) => (run.endedAt === undefined ? 0 : (run.endedAt - run.startedAt) / 1000)),
|
|
86
|
+
cpuSeconds: { own: sum((run) => run.used.ownCpuSeconds), child: sum((run) => run.used.childCpuSeconds) },
|
|
87
|
+
peakMemoryMb: runs.reduce((peak, run) => Math.max(peak, run.used.peakMemoryMb), 0),
|
|
88
|
+
filesWritten: sum((run) => run.used.filesWritten),
|
|
89
|
+
agents: count((run) => run.agent).map(([agent, total]) => ({ agent, runs: total })),
|
|
90
|
+
tasks: byTask.size,
|
|
91
|
+
perTask: {
|
|
92
|
+
wallSeconds: spreadOf(perTask((run) => ((run.endedAt ?? run.startedAt) - run.startedAt) / 1000)),
|
|
93
|
+
cpuSeconds: spreadOf(perTask((run) => run.used.ownCpuSeconds + run.used.childCpuSeconds)),
|
|
94
|
+
tokens: spreadOf(perTask(tokensOf)),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* What the tasks a parent's sub-workflow step created here spent, over their runs that started in `[since, until)`:
|
|
102
|
+
* the parent's `stepStats` of a sub-workflow step reports this as its spend, since the step itself runs nothing.
|
|
103
|
+
* `perParentTaskTokens` is the spread over the parent's tasks, each one's sub-workflow tasks added up. Spend of a
|
|
104
|
+
* sub-workflow these tasks start in turn is recorded in that sub-workflow's component and not included.
|
|
105
|
+
*/
|
|
106
|
+
export const subWorkflowSpend = query({
|
|
107
|
+
args: { parent: v.object({ workflow: v.string(), step: v.string() }), since: v.number(), until: v.optional(v.number()) },
|
|
108
|
+
returns: v.object({ spend: stepSpendValidator, parentTasks: v.number(), perParentTaskTokens: spreadValidator }),
|
|
109
|
+
handler: async (ctx, args) => {
|
|
110
|
+
const until = args.until ?? Number.MAX_SAFE_INTEGER
|
|
111
|
+
const tasks = await ctx.db
|
|
112
|
+
.query("tasks")
|
|
113
|
+
.withIndex("by_parent_step", (q) => q.eq("parent.workflow", args.parent.workflow).eq("parent.step", args.parent.step))
|
|
114
|
+
.collect()
|
|
115
|
+
let spend: StepSpend = noSpend
|
|
116
|
+
const tokensByParentTask = new Map<string, number>()
|
|
117
|
+
for (const task of tasks) {
|
|
118
|
+
if (task.parent === undefined) continue
|
|
119
|
+
const parentTask = task.parent.task
|
|
120
|
+
const runs = await ctx.db.query("stepRuns").withIndex("by_task", (q) => q.eq("task", task._id)).collect()
|
|
121
|
+
for (const run of runs.filter((candidate) => candidate.startedAt >= args.since && candidate.startedAt < until)) {
|
|
122
|
+
spend = {
|
|
123
|
+
fresh: spend.fresh + run.spend.fresh,
|
|
124
|
+
cacheWrite: spend.cacheWrite + run.spend.cacheWrite,
|
|
125
|
+
cacheRead: spend.cacheRead + run.spend.cacheRead,
|
|
126
|
+
output: spend.output + run.spend.output,
|
|
127
|
+
requests: spend.requests + run.spend.requests,
|
|
128
|
+
costUsd: spend.costUsd + run.spend.costUsd,
|
|
129
|
+
compiles: spend.compiles + run.spend.compiles,
|
|
130
|
+
}
|
|
131
|
+
tokensByParentTask.set(parentTask, (tokensByParentTask.get(parentTask) ?? 0) + tokensOf(run))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { spend, parentTasks: tokensByParentTask.size, perParentTaskTokens: spreadOf([...tokensByParentTask.values()]) }
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* One step's runs, newest first, a page at a time: those that started at or after `since` when given. Each run comes
|
|
140
|
+
* with its task, which try it was, when it started and ended, how it ended, its agent, spend and transcripts.
|
|
141
|
+
*/
|
|
142
|
+
export const stepRuns = query({
|
|
143
|
+
args: { workflow: v.string(), step: v.string(), since: v.optional(v.number()), paginationOpts: paginationOptsValidator },
|
|
144
|
+
returns: v.object({
|
|
145
|
+
page: v.array(
|
|
146
|
+
v.object({
|
|
147
|
+
task: v.id("tasks"),
|
|
148
|
+
call: v.number(),
|
|
149
|
+
status: v.string(),
|
|
150
|
+
startedAt: v.number(),
|
|
151
|
+
endedAt: v.optional(v.number()),
|
|
152
|
+
endState: v.optional(v.string()),
|
|
153
|
+
error: v.optional(v.string()),
|
|
154
|
+
agent: v.optional(v.string()),
|
|
155
|
+
spend: stepSpendValidator,
|
|
156
|
+
transcripts: v.array(taskFileValidator),
|
|
157
|
+
skippedOthers: v.optional(v.array(skippedOtherValidator)),
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
isDone: v.boolean(),
|
|
161
|
+
continueCursor: v.string(),
|
|
162
|
+
}),
|
|
163
|
+
handler: async (ctx, args) => {
|
|
164
|
+
const since = args.since ?? 0
|
|
165
|
+
const runs = await ctx.db
|
|
166
|
+
.query("stepRuns")
|
|
167
|
+
.withIndex("by_workflow_step_started", (q) => q.eq("workflow", args.workflow).eq("step", args.step).gte("startedAt", since))
|
|
168
|
+
.order("desc")
|
|
169
|
+
.paginate(args.paginationOpts)
|
|
170
|
+
return {
|
|
171
|
+
isDone: runs.isDone,
|
|
172
|
+
continueCursor: runs.continueCursor,
|
|
173
|
+
page: runs.page.map((run) => ({
|
|
174
|
+
task: run.task,
|
|
175
|
+
call: run.call,
|
|
176
|
+
status: run.status,
|
|
177
|
+
startedAt: run.startedAt,
|
|
178
|
+
...(run.endedAt !== undefined ? { endedAt: run.endedAt } : {}),
|
|
179
|
+
...(run.endState !== undefined ? { endState: run.endState } : {}),
|
|
180
|
+
...(run.error !== undefined ? { error: run.error } : {}),
|
|
181
|
+
...(run.agent !== undefined ? { agent: run.agent } : {}),
|
|
182
|
+
spend: run.spend,
|
|
183
|
+
transcripts: run.transcripts,
|
|
184
|
+
...(run.skippedOthers !== undefined ? { skippedOthers: run.skippedOthers } : {}),
|
|
185
|
+
})),
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
})
|