@jive-sh/workflow-platform 1.4.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 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
@@ -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 }, // a sized element for the diagram, a panel, a <select>, a pie box
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 fitted diagram, in diagram units. */
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
- zoom: (level: "fit-viewport") => void
122
- viewbox: (box?: { x: number; y: number; width: number; height: number }) => { readonly x: number; readonly y: number; readonly width: number; readonly 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
- canvas.zoom("fit-viewport")
125
- // Fitting puts the outermost shapes on the box's edge; a margin keeps the start and end circles and their badges whole.
126
- const fitted = canvas.viewbox()
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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jive-sh/workflow-platform",
3
- "version": "1.4.0",
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.",