@jive-sh/workflow-platform 1.1.0 → 1.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 +5 -3
- package/dashboard/README.md +57 -0
- package/dashboard/activity-look.ts +93 -0
- package/dashboard/bpmn-moddle.d.ts +9 -0
- package/dashboard/dashboard.css +31 -0
- package/dashboard/figures.test.ts +120 -0
- package/dashboard/figures.ts +125 -0
- package/dashboard/index.ts +14 -0
- package/dashboard/layout.test.ts +82 -0
- package/dashboard/layout.ts +168 -0
- package/dashboard/live.ts +334 -0
- package/dashboard/panel.test.ts +72 -0
- package/dashboard/panel.ts +144 -0
- package/dashboard/pie.test.ts +38 -0
- package/dashboard/pie.ts +86 -0
- package/dashboard/places.test.ts +60 -0
- package/dashboard/places.ts +85 -0
- package/dashboard/shapes.ts +39 -0
- package/dashboard/view.ts +192 -0
- package/dashboard/words.test.ts +61 -0
- package/dashboard/words.ts +61 -0
- package/package.json +27 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import type { GraphStep } from "../src/graph"
|
|
3
|
+
import { accessWords, dollars, duration, tokenWords, workflowWords } from "./words"
|
|
4
|
+
|
|
5
|
+
describe("figures in words", () => {
|
|
6
|
+
test("tokens read in millions, thousands or as they are", () => {
|
|
7
|
+
expect(tokenWords(1_234_567)).toBe("1.2 M tokens")
|
|
8
|
+
expect(tokenWords(35_400)).toBe("35 k tokens")
|
|
9
|
+
expect(tokenWords(812)).toBe("812 tokens")
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test("a cost under a cent says so rather than reading $0.00", () => {
|
|
13
|
+
expect(dollars(12.4)).toBe("$12.40")
|
|
14
|
+
expect(dollars(0.004)).toBe("under $0.01")
|
|
15
|
+
expect(dollars(0)).toBe("$0.00")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("a duration names its two largest units", () => {
|
|
19
|
+
expect(duration(4 * 60_000 + 12_000)).toBe("4 min 12 s")
|
|
20
|
+
expect(duration(23 * 60_000)).toBe("23 min")
|
|
21
|
+
expect(duration(2 * 86_400_000 + 3_600_000)).toBe("2 days 1 h")
|
|
22
|
+
expect(duration(9_000)).toBe("9 s")
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test("a workflow's id reads as words, a one-letter word included", () => {
|
|
26
|
+
expect(workflowWords("matchAFunction")).toBe("Match a function")
|
|
27
|
+
expect(workflowWords("fitTheSource")).toBe("Fit the source")
|
|
28
|
+
expect(workflowWords("build")).toBe("Build")
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe("a step's access in words", () => {
|
|
33
|
+
const agent: GraphStep = {
|
|
34
|
+
id: "learnFromBlocked",
|
|
35
|
+
kind: "agent",
|
|
36
|
+
endStates: ["found something new", "nothing new"],
|
|
37
|
+
access: { services: ["AgentRunner", "DecompRecords"], tasks: { read: ["matchAFunction"], write: ["matchAFunction"] } },
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
test("says what the step can use and whose tasks it can read and change, an organization's own service by its words", () => {
|
|
41
|
+
expect(accessWords(agent, { DecompRecords: "decomp-service records" })).toEqual([
|
|
42
|
+
"Can use: agents, decomp-service records.",
|
|
43
|
+
"Can read tasks of: Match a function.",
|
|
44
|
+
"Can change tasks of: Match a function.",
|
|
45
|
+
])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("a service nobody named is shown by its key, and a step with no access says it can use nothing", () => {
|
|
49
|
+
expect(accessWords(agent)[0]).toBe("Can use: agents, DecompRecords.")
|
|
50
|
+
expect(accessWords({ id: "alreadyLearned", kind: "code", endStates: ["not learned yet"], access: { services: [] } })).toEqual([
|
|
51
|
+
"Can use: nothing.",
|
|
52
|
+
"Can read tasks of: nothing.",
|
|
53
|
+
"Can change tasks of: nothing.",
|
|
54
|
+
])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("a sub-workflow step points at its workflow's steps, and an undeclared step says so", () => {
|
|
58
|
+
expect(accessWords({ id: "decompile", kind: "workflow", endStates: ["matched"], workflow: { name: "decompile" } })[0]).toContain("inside the Decompile workflow")
|
|
59
|
+
expect(accessWords({ id: "old", kind: "code", endStates: ["done"] })).toEqual(["Access: not declared."])
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Every figure and name the workflow views show, in words with its unit. Alex reads the views without telling colours
|
|
2
|
+
// apart, so each badge, slice and panel line says what it means in words.
|
|
3
|
+
import type { GraphStep } from "../src/graph"
|
|
4
|
+
|
|
5
|
+
const number = (value: number): string => value.toLocaleString("en-US")
|
|
6
|
+
|
|
7
|
+
/** "1.2 million", or the number itself below a million. */
|
|
8
|
+
export const millions = (value: number): string => (value >= 1_000_000 ? `${(value / 1_000_000).toFixed(1)} million` : number(value))
|
|
9
|
+
|
|
10
|
+
/** "1.2 M tokens", "35 k tokens", "812 tokens". */
|
|
11
|
+
export const tokenWords = (tokens: number): string =>
|
|
12
|
+
tokens >= 1_000_000 ? `${(tokens / 1_000_000).toFixed(1)} M tokens` : tokens >= 1_000 ? `${Math.round(tokens / 1_000)} k tokens` : `${tokens} tokens`
|
|
13
|
+
|
|
14
|
+
/** "$12.40", "$0.83", "under $0.01". */
|
|
15
|
+
export const dollars = (usd: number): string => (usd > 0 && usd < 0.01 ? "under $0.01" : `$${usd.toFixed(2)}`)
|
|
16
|
+
|
|
17
|
+
/** "2 days 1 h", "23 min", "4 min 12 s". */
|
|
18
|
+
export const duration = (ms: number): string => {
|
|
19
|
+
const seconds = Math.round(ms / 1000)
|
|
20
|
+
const days = Math.floor(seconds / 86_400)
|
|
21
|
+
const hours = Math.floor((seconds % 86_400) / 3600)
|
|
22
|
+
const minutes = Math.floor((seconds % 3600) / 60)
|
|
23
|
+
const rest = seconds % 60
|
|
24
|
+
if (days > 0) return hours > 0 ? `${days} day${days === 1 ? "" : "s"} ${hours} h` : `${days} day${days === 1 ? "" : "s"}`
|
|
25
|
+
if (hours > 0) return minutes > 0 ? `${hours} h ${minutes} min` : `${hours} h`
|
|
26
|
+
if (minutes > 0) return rest > 0 && minutes < 10 ? `${minutes} min ${rest} s` : `${minutes} min`
|
|
27
|
+
return `${rest} s`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { number }
|
|
31
|
+
|
|
32
|
+
/** A workflow's name in words: "matchAFunction" is "Match a function". */
|
|
33
|
+
export const workflowWords = (workflow: string): string => {
|
|
34
|
+
const words = workflow
|
|
35
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
36
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The platform's own worker services in words. An organization adds its own (`serviceWords`); any other is shown by its key. */
|
|
42
|
+
export const PLATFORM_SERVICE_WORDS: Readonly<Record<string, string>> = {
|
|
43
|
+
AgentRunner: "agents",
|
|
44
|
+
FileStore: "files",
|
|
45
|
+
ProgramBuild: "program builds",
|
|
46
|
+
Tasks: "tasks",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A step's declared access in words: what its code can use, and whose tasks it can read and change. */
|
|
50
|
+
export const accessWords = (step: GraphStep, serviceWords: Readonly<Record<string, string>> = {}): ReadonlyArray<string> => {
|
|
51
|
+
if (step.workflow !== undefined)
|
|
52
|
+
return [`Access: this step's code runs inside the ${workflowWords(step.workflow.name)} workflow, and each of its steps declares its own.`]
|
|
53
|
+
const access = step.access
|
|
54
|
+
if (access === undefined) return ["Access: not declared."]
|
|
55
|
+
const list = (items: ReadonlyArray<string>) => (items.length === 0 ? "nothing" : items.join(", "))
|
|
56
|
+
return [
|
|
57
|
+
`Can use: ${list(access.services.map((service) => serviceWords[service] ?? PLATFORM_SERVICE_WORDS[service] ?? service))}.`,
|
|
58
|
+
`Can read tasks of: ${list((access.tasks?.read ?? []).map(workflowWords))}.`,
|
|
59
|
+
`Can change tasks of: ${list((access.tasks?.write ?? []).map(workflowWords))}.`,
|
|
60
|
+
]
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jive-sh/workflow-platform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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.",
|
|
@@ -18,17 +18,41 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./README.md": "./README.md",
|
|
20
20
|
"./component/*": "./component/*",
|
|
21
|
-
"./worker/*": "./worker/*"
|
|
21
|
+
"./worker/*": "./worker/*",
|
|
22
|
+
"./dashboard/*": "./dashboard/*"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"README.md",
|
|
25
26
|
"component",
|
|
26
27
|
"worker",
|
|
28
|
+
"dashboard",
|
|
27
29
|
"dist",
|
|
28
30
|
"src"
|
|
29
31
|
],
|
|
30
32
|
"peerDependencies": {
|
|
33
|
+
"bpmn-js": "^18.33.1",
|
|
34
|
+
"bpmn-moddle": "^10.3.1",
|
|
31
35
|
"convex": "^1.51.0",
|
|
32
|
-
"
|
|
36
|
+
"diagram-js": "^15.30.1",
|
|
37
|
+
"effect": "^4.1.7",
|
|
38
|
+
"elkjs": "^0.12.2",
|
|
39
|
+
"tiny-svg": "^4.1.4"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"bpmn-js": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"bpmn-moddle": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"diagram-js": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"elkjs": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"tiny-svg": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
58
|
}
|