@jive-sh/workflow-platform 1.3.0 → 1.4.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 +4 -1
- package/dashboard/README.md +4 -2
- package/dashboard/live.ts +4 -0
- package/dashboard/view.ts +38 -7
- package/dist/definition/program-build.js.map +1 -1
- package/package.json +1 -1
- package/src/definition/program-build.ts +11 -0
- package/worker/step-meter.test.ts +31 -0
- package/worker/step-meter.ts +6 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ It ships its source, and three entry points:
|
|
|
22
22
|
| `@jive-sh/workflow-platform` | Defining workflows (`Workflow.make`, `TaskSchema.make`), the step services (`AgentRunner`, `FileStore`, `ProgramBuild`, `Tasks`) and the graph types |
|
|
23
23
|
| `@jive-sh/workflow-platform/component/convex.config.js` | The Convex component a workforce installs once per workflow (`app.use(workflowPlatform, { name })`) |
|
|
24
24
|
| `@jive-sh/workflow-platform/worker/index.js` | The worker loop (`workOnce`, `workUntilIdle`, `workForever`) and its Convex client |
|
|
25
|
-
| `@jive-sh/workflow-platform/dashboard/index.js` | The workflow views: a workflow's diagram with tasks, time, tokens or cost on every step and queue, a pie of it by step, and a panel of each step's tasks, access, stats and runs with their transcripts ([dashboard/README.md](dashboard/README.md); 1.2.0) |
|
|
25
|
+
| `@jive-sh/workflow-platform/dashboard/index.js` | The workflow views: a workflow's diagram with tasks, time, tokens or cost on every step and queue, a pie of it by step, and a panel of each step's tasks, access, stats and runs with their transcripts ([dashboard/README.md](dashboard/README.md); 1.2.0; 1.4.1 fits each diagram to its width at a readable scale) |
|
|
26
26
|
|
|
27
27
|
Write `.js` in the import: TypeScript and Convex's bundler both resolve it to the shipped `.ts`. Convex's codegen
|
|
28
28
|
writes `@jive-sh/workflow-platform/component/_generated/component.js` into an app installing the component, for the
|
|
@@ -79,6 +79,9 @@ worker gives a run only what its step lists.
|
|
|
79
79
|
re-opened after its parent moved on is kept on the parent as a note.
|
|
80
80
|
- **Agents:** `AgentRunner` with no tools, a reading mode or a working mode with write scopes, a cached input, and a
|
|
81
81
|
turn limit; the organization implements it.
|
|
82
|
+
- **Builds:** `ProgramBuild` builds the whole program, or (1.4.0) compiles one function's unit with
|
|
83
|
+
`compileUnit({ address })`, saying whether it compiles and the compiler's first error; each unit compile counts as
|
|
84
|
+
one of the step's compiles.
|
|
82
85
|
- **Queues:** requeue with a note, move tasks to the front, an in-progress limit per workflow or per field value (a
|
|
83
86
|
lock across steps), and retention of records (7 days and the newest 10,000 runs by default).
|
|
84
87
|
- **Records:** every step run's worker, times, end state, error, spend (tokens by kind, requests, cost, compiles),
|
package/dashboard/README.md
CHANGED
|
@@ -4,7 +4,9 @@ A browser view of one workflow, read live from the workforce's queries:
|
|
|
4
4
|
|
|
5
5
|
- **The diagram:** the workflow's BPMN, laid out top to bottom when the view opens and drawn like a UML activity
|
|
6
6
|
diagram. Steps are rounded boxes, and an agent step has a robot. A decision is a plain diamond with its question
|
|
7
|
-
beside it and the end-state names on its lines; a merge is a plain diamond.
|
|
7
|
+
beside it and the end-state names on its lines; a merge is a plain diamond. It fills the width of the canvas's
|
|
8
|
+
parent, never smaller than a scale its names and badges can be read at (0.85), nor larger than 1.25; the canvas
|
|
9
|
+
takes the height that needs, and a diagram too wide at 0.85 is wider than its parent, for the parent to scroll.
|
|
8
10
|
- **A metric on every box and queue,** picked in a dropdown:
|
|
9
11
|
- **Tasks** (the default): the tasks in each step, queued in front of it, and ended at each end state.
|
|
10
12
|
- **Time:** each step's median time per task, and how long each queue's tasks have waited (median and longest).
|
|
@@ -39,7 +41,7 @@ const view = await mountWorkflowView({
|
|
|
39
41
|
queries: api.workforce, // the workforce functions the app exports
|
|
40
42
|
workflow: "matchAFunction",
|
|
41
43
|
bpmn: matchAFunctionBpmn, // the workflow package's .bpmn
|
|
42
|
-
elements: { canvas, panel, picker, pie }, //
|
|
44
|
+
elements: { canvas, panel, picker, pie }, // the diagram's element (the view sizes it), a panel, a <select>, a pie box
|
|
43
45
|
dark: true,
|
|
44
46
|
taskName: (fields) => (typeof fields["address"] === "string" ? fields["address"] : undefined),
|
|
45
47
|
fileHref: (file) => `/files/${file.ref}`, // where the page can open a stored file, such as a transcript
|
package/dashboard/live.ts
CHANGED
|
@@ -54,6 +54,10 @@ export interface WorkforceQueries {
|
|
|
54
54
|
|
|
55
55
|
/** Where the view goes on the page. */
|
|
56
56
|
export interface ViewElements {
|
|
57
|
+
/**
|
|
58
|
+
* The diagram's element. The view sets its width and height: the diagram fills its parent's width, at no less than
|
|
59
|
+
* a scale its names and badges can be read at, so give the parent the width to fill and let it scroll sideways.
|
|
60
|
+
*/
|
|
57
61
|
readonly canvas: HTMLElement
|
|
58
62
|
readonly panel: HTMLElement
|
|
59
63
|
/** The metric dropdown; filled by the view. */
|
package/dashboard/view.ts
CHANGED
|
@@ -23,9 +23,15 @@ interface DiagramElement {
|
|
|
23
23
|
|
|
24
24
|
const jiveAttribute = (element: DiagramElement, name: string): string | undefined => element.businessObject?.$attrs?.[`jive:${name}`]
|
|
25
25
|
|
|
26
|
-
/** Room around the
|
|
26
|
+
/** Room around the diagram, in diagram units. */
|
|
27
27
|
const VIEW_MARGIN = 40
|
|
28
28
|
|
|
29
|
+
/** The smallest scale a diagram is drawn at: smaller, its names and badges can't be read without zooming. */
|
|
30
|
+
const MIN_SCALE = 0.85
|
|
31
|
+
|
|
32
|
+
/** The largest: a small diagram is drawn at a little over its own size, not blown up to fill a wide window. */
|
|
33
|
+
const MAX_SCALE = 1.25
|
|
34
|
+
|
|
29
35
|
/** The overlay type of the badges, so a new set replaces the old. */
|
|
30
36
|
const BADGE_OVERLAY = "jive-badge"
|
|
31
37
|
|
|
@@ -118,13 +124,37 @@ export const drawWorkflow = async (input: {
|
|
|
118
124
|
const canvas = viewer.get("canvas") as {
|
|
119
125
|
addMarker: (id: string, marker: string) => void
|
|
120
126
|
removeMarker: (id: string, marker: string) => void
|
|
121
|
-
|
|
122
|
-
viewbox: (box?: { x: number; y: number; width: number; height: number }) => {
|
|
127
|
+
resized: () => void
|
|
128
|
+
viewbox: (box?: { x: number; y: number; width: number; height: number }) => {
|
|
129
|
+
readonly x: number
|
|
130
|
+
readonly y: number
|
|
131
|
+
readonly width: number
|
|
132
|
+
readonly height: number
|
|
133
|
+
/** The bounds of everything drawn. */
|
|
134
|
+
readonly inner: { readonly x: number; readonly y: number; readonly width: number; readonly height: number }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// The diagram fills the width of the canvas's parent, at a scale between MIN_SCALE and MAX_SCALE, and the canvas takes
|
|
138
|
+
// the height that needs, so the page scrolls instead of the diagram shrinking until its names and badges can't be read.
|
|
139
|
+
// A diagram too wide for its parent at MIN_SCALE is wider than it, for the parent to scroll sideways.
|
|
140
|
+
const diagram = canvas.viewbox().inner
|
|
141
|
+
// A margin keeps the outermost start and end circles and their badges whole.
|
|
142
|
+
const box = { x: diagram.x - VIEW_MARGIN, y: diagram.y - VIEW_MARGIN, width: diagram.width + 2 * VIEW_MARGIN, height: diagram.height + 2 * VIEW_MARGIN }
|
|
143
|
+
let fittedTo = -1
|
|
144
|
+
const fitToWidth = () => {
|
|
145
|
+
const available = (input.canvas.parentElement ?? input.canvas).clientWidth
|
|
146
|
+
// Sizing the canvas can resize its parent (a scrollbar comes or goes); refit only when the width changed.
|
|
147
|
+
if (available === fittedTo) return
|
|
148
|
+
fittedTo = available
|
|
149
|
+
const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, available / box.width))
|
|
150
|
+
input.canvas.style.width = `${Math.floor(box.width * scale)}px`
|
|
151
|
+
input.canvas.style.height = `${Math.ceil(box.height * scale)}px`
|
|
152
|
+
canvas.resized()
|
|
153
|
+
canvas.viewbox(box)
|
|
123
154
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
canvas.viewbox({ x: fitted.x - VIEW_MARGIN, y: fitted.y - VIEW_MARGIN, width: fitted.width + 2 * VIEW_MARGIN, height: fitted.height + 2 * VIEW_MARGIN })
|
|
155
|
+
fitToWidth()
|
|
156
|
+
const parentResized = new ResizeObserver(() => fitToWidth())
|
|
157
|
+
if (input.canvas.parentElement !== null) parentResized.observe(input.canvas.parentElement)
|
|
128
158
|
|
|
129
159
|
let selected: DiagramElement | null = null
|
|
130
160
|
const close = () => {
|
|
@@ -185,6 +215,7 @@ export const drawWorkflow = async (input: {
|
|
|
185
215
|
if (selected !== null) void show(selected)
|
|
186
216
|
},
|
|
187
217
|
destroy: () => {
|
|
218
|
+
parentResized.disconnect()
|
|
188
219
|
input.canvas.removeEventListener("click", onBadge)
|
|
189
220
|
viewer.destroy()
|
|
190
221
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program-build.js","sourceRoot":"","sources":["../../../../src/definition/program-build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAA4B,MAAM,QAAQ,CAAA;AAEhE,sHAAsH;AACtH,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAA8B;IACzG,IAAa,OAAO;QAClB,OAAO,6BAA6B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IAC1D,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"program-build.js","sourceRoot":"","sources":["../../../../src/definition/program-build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAA4B,MAAM,QAAQ,CAAA;AAEhE,sHAAsH;AACtH,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAA8B;IACzG,IAAa,OAAO;QAClB,OAAO,6BAA6B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IAC1D,CAAC;CACF;AAiCD,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,OAAO,EAA+B,CAAC,cAAc,CAAC;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jive-sh/workflow-platform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Durable workflows in Convex: one workflow primitive with a task schema, queues on every line, workflow budgets, named end states, events and sub-workflows; worker processes run the steps.",
|
|
@@ -17,6 +17,12 @@ export interface ProgramBuildResult {
|
|
|
17
17
|
readonly failure: Option.Option<string>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Whether one function's unit compiles now, and the compiler's first error when it doesn't. */
|
|
21
|
+
export interface UnitCompiled {
|
|
22
|
+
readonly compiles: boolean
|
|
23
|
+
readonly error: Option.Option<string>
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
/**
|
|
21
27
|
* The interface a workflow's build step uses to build the program it works on: compile what changed, link it, and
|
|
22
28
|
* publish the result where the organization serves it. The organization provides the implementation (which toolchain,
|
|
@@ -25,6 +31,11 @@ export interface ProgramBuildResult {
|
|
|
25
31
|
*/
|
|
26
32
|
export interface IProgramBuild {
|
|
27
33
|
build(input: { readonly changedFunctions: ReadonlyArray<string> }): Effect.fn.Return<ProgramBuildResult, ProgramBuildFailed>
|
|
34
|
+
/**
|
|
35
|
+
* Compiles the unit of the function at `address` from its source now, alone, against the program's headers, so a step
|
|
36
|
+
* learns whether that one function compiles without a whole build. The worker records it as one compile.
|
|
37
|
+
*/
|
|
38
|
+
compileUnit(input: { readonly address: number }): Effect.fn.Return<UnitCompiled, ProgramBuildFailed>
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
export class ProgramBuild extends Context.Service<ProgramBuild, IProgramBuild>()("ProgramBuild") {}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Effect, Option } from "effect"
|
|
3
|
+
import { type IProgramBuild, ProgramBuildFailed } from "../src/definition/program-build"
|
|
4
|
+
import { StepMeter } from "./step-meter"
|
|
5
|
+
|
|
6
|
+
/** A build whose whole-program builds compile three functions, and whose unit compiles always compile. */
|
|
7
|
+
const build: IProgramBuild = {
|
|
8
|
+
*build() {
|
|
9
|
+
return { linked: true, functions: { total: 3, compiled: 3, failing: 0, excluded: 0 }, failure: Option.none() }
|
|
10
|
+
},
|
|
11
|
+
*compileUnit() {
|
|
12
|
+
return yield* Effect.succeed({ compiles: true, error: Option.none() })
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("a step's compiles", () => {
|
|
17
|
+
test("count a build's compiled functions and one for each unit compile", async () => {
|
|
18
|
+
const meter = new StepMeter()
|
|
19
|
+
const metered = meter.meteredProgramBuild(build)
|
|
20
|
+
const compiles = await Effect.runPromise(
|
|
21
|
+
Effect.gen(function* () {
|
|
22
|
+
yield* metered.build({ changedFunctions: [] })
|
|
23
|
+
yield* metered.compileUnit({ address: 0x401000 })
|
|
24
|
+
yield* metered.compileUnit({ address: 0x401200 })
|
|
25
|
+
return (yield* meter.measurements({ files: [], reported: {}, fingerprint: Option.none() })).spend.compiles
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
expect(compiles).toBe(5)
|
|
29
|
+
expect(new ProgramBuildFailed({ cause: "x" }).message).toBe("the program build failed: x")
|
|
30
|
+
})
|
|
31
|
+
})
|
package/worker/step-meter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Option } from "effect"
|
|
2
2
|
import type { AgentRunInput, AgentRunResult, IAgentRunner } from "../src/definition/agent-runner"
|
|
3
|
-
import type { IProgramBuild, ProgramBuildResult } from "../src/definition/program-build"
|
|
3
|
+
import type { IProgramBuild, ProgramBuildResult, UnitCompiled } from "../src/definition/program-build"
|
|
4
4
|
import type { TaskFile } from "../src/graph"
|
|
5
5
|
import { noSpend, type StepMeasurements, type StepSpend } from "../src/graph"
|
|
6
6
|
|
|
@@ -36,6 +36,11 @@ export class StepMeter {
|
|
|
36
36
|
meter.spend = { ...meter.spend, compiles: meter.spend.compiles + result.functions.compiled }
|
|
37
37
|
return result
|
|
38
38
|
},
|
|
39
|
+
*compileUnit(input: { readonly address: number }) {
|
|
40
|
+
const result: UnitCompiled = yield* inner.compileUnit(input)
|
|
41
|
+
meter.spend = { ...meter.spend, compiles: meter.spend.compiles + 1 }
|
|
42
|
+
return result
|
|
43
|
+
},
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|