@segmentstream/ontology 0.104.0 → 0.105.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.
@@ -0,0 +1,141 @@
1
+ /**
2
+ * What a workflow does, as its code reads: the steps its `"use workflow"` function calls, the waits,
3
+ * branches, loops and parallel groups around them, and what each step calls. The ontology's build
4
+ * reads it from the workflow's source once per deployment (`./workflow-structure-extract.ts`) and the
5
+ * service serves it beside the runs, so the console can draw the workflow as a map or an outline
6
+ * and lay a run's steps over it.
7
+ *
8
+ * It is a reading of the code, not a trace: a loop's count, the branch a run takes and a call made
9
+ * through a value are known only at run time. `complete` is false when the reading met something
10
+ * it could not follow, and such a place is an `unknown` node rather than a guess.
11
+ *
12
+ * The shape carries no human-language text of its own: names, descriptions and conditions are the
13
+ * workspace's code and comments, and kinds are identifiers the reader presents in its own words.
14
+ */
15
+ /** The version of this shape; a reader ignores fields and node kinds it does not know. */
16
+ export declare const WORKFLOW_STRUCTURE_VERSION = 1;
17
+ export interface WorkflowStructure {
18
+ readonly version: number;
19
+ /** The workflow function's body, in the order it runs. */
20
+ readonly body: ReadonlyArray<StructureNode>;
21
+ /** The steps the body calls, by step key: the step name the run records carry. */
22
+ readonly steps: Readonly<Record<string, StructureStep>>;
23
+ /** False when the reading met a call or a construct it could not follow. */
24
+ readonly complete: boolean;
25
+ }
26
+ /** A `"use step"` function, described once however many places call it. */
27
+ export interface StructureStep {
28
+ /** The function's name in the code. */
29
+ readonly name: string;
30
+ /** The comment above the function, without its comment markers; absent without one. */
31
+ readonly description?: string;
32
+ /** What the step's code calls, in the order it first appears; absent when it calls nothing known. */
33
+ readonly calls?: ReadonlyArray<StepCall>;
34
+ /** Where the function is, relative to the ontology's folder; `line` counts from 1. */
35
+ readonly source?: {
36
+ readonly file: string;
37
+ readonly line: number;
38
+ };
39
+ }
40
+ /**
41
+ * Something a step calls, as the code names it: `target` is the identifier the code calls through
42
+ * (an entity handle such as `Lead`, or a connection such as `apollo`) and `name` the member it calls.
43
+ */
44
+ export type StepCall =
45
+ /** An action of an entity: `Lead.actions.addNote(…)`. */
46
+ {
47
+ readonly kind: "action";
48
+ readonly target: string;
49
+ readonly name: string;
50
+ }
51
+ /** A record operation of an entity: `Lead.find(…)`, `Lead.get(…)`, `Note.create(…)`. */
52
+ | {
53
+ readonly kind: "records";
54
+ readonly target: string;
55
+ readonly name: string;
56
+ }
57
+ /** A request through a connection: `apollo.post("/people/match", …)`. */
58
+ | {
59
+ readonly kind: "request";
60
+ readonly target: string;
61
+ readonly name: string;
62
+ /** The request's path when the code writes it as a literal. */
63
+ readonly path?: string;
64
+ };
65
+ /** One place in the workflow's body. `id` is stable for the same code: a path through the body. */
66
+ export type StructureNode = StepNode | WaitNode | AgentNode | BranchNode | LoopNode | ParallelNode | TryNode | ExitNode | UnknownNode;
67
+ interface NodeBase {
68
+ readonly id: string;
69
+ /** The comment above the statement this node comes from, when it is the statement's first node. */
70
+ readonly note?: string;
71
+ }
72
+ /** A call to a step; `step` is its key in `WorkflowStructure.steps`. */
73
+ export interface StepNode extends NodeBase {
74
+ readonly kind: "step";
75
+ readonly step: string;
76
+ }
77
+ /** The workflow waits: `sleep(…)`, or for a hook or webhook it created to be called. */
78
+ export interface WaitNode extends NodeBase {
79
+ readonly kind: "wait";
80
+ readonly wait: "sleep" | "hook" | "webhook";
81
+ /** The duration or date as the code writes it, for a sleep: `"1d"`, `input.until`. */
82
+ readonly detail?: string;
83
+ }
84
+ /** An agent task the workflow starts and waits for (`agentTask(…)`); `steps` are its step keys. */
85
+ export interface AgentNode extends NodeBase {
86
+ readonly kind: "agent";
87
+ readonly steps: ReadonlyArray<string>;
88
+ }
89
+ /**
90
+ * The workflow takes one of several paths: `if`/`else`, `switch`, `?:` or `&&`/`||`. `condition`
91
+ * is the code's expression; each path's `when` is `"true"` or `"false"` for an `if`, and a case's
92
+ * expression or `"default"` for a `switch`. A path without nodes is kept, so a skip is visible.
93
+ */
94
+ export interface BranchNode extends NodeBase {
95
+ readonly kind: "branch";
96
+ readonly condition: string;
97
+ readonly paths: ReadonlyArray<{
98
+ readonly when: string;
99
+ readonly body: ReadonlyArray<StructureNode>;
100
+ }>;
101
+ }
102
+ /**
103
+ * The workflow repeats `body`: a `for`, `for…of`, `for…in`, `while` or `do…while` statement, or a
104
+ * callback of `map`/`forEach`/`flatMap` (`each`). `over` is the code's condition or iterable.
105
+ */
106
+ export interface LoopNode extends NodeBase {
107
+ readonly kind: "loop";
108
+ readonly loop: "for" | "forOf" | "forIn" | "while" | "doWhile" | "each";
109
+ readonly over: string;
110
+ readonly body: ReadonlyArray<StructureNode>;
111
+ }
112
+ /**
113
+ * The workflow runs branches at once and waits for them: `Promise.all`, `allSettled`, `any` or
114
+ * `race`. With `each`, the one branch runs once per element of that iterable, at the same time.
115
+ */
116
+ export interface ParallelNode extends NodeBase {
117
+ readonly kind: "parallel";
118
+ readonly method: "all" | "allSettled" | "any" | "race";
119
+ readonly each?: string;
120
+ readonly branches: ReadonlyArray<ReadonlyArray<StructureNode>>;
121
+ }
122
+ /** `try`, with what runs when it fails (`catch`) and in any case (`finally`). */
123
+ export interface TryNode extends NodeBase {
124
+ readonly kind: "try";
125
+ readonly body: ReadonlyArray<StructureNode>;
126
+ readonly catch?: ReadonlyArray<StructureNode>;
127
+ readonly finally?: ReadonlyArray<StructureNode>;
128
+ }
129
+ /** The workflow ends here before its last statement: a `return`, or a `throw` that fails the run. */
130
+ export interface ExitNode extends NodeBase {
131
+ readonly kind: "exit";
132
+ readonly exit: "return" | "throw";
133
+ }
134
+ /** An awaited call the reading could not follow; `label` is the code's callee. */
135
+ export interface UnknownNode extends NodeBase {
136
+ readonly kind: "unknown";
137
+ readonly label: string;
138
+ }
139
+ /** The structures of a build's workflows, by the Workflow SDK's id of each workflow function. */
140
+ export type WorkflowStructures = Readonly<Record<string, WorkflowStructure>>;
141
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What a workflow does, as its code reads: the steps its `"use workflow"` function calls, the waits,
3
+ * branches, loops and parallel groups around them, and what each step calls. The ontology's build
4
+ * reads it from the workflow's source once per deployment (`./workflow-structure-extract.ts`) and the
5
+ * service serves it beside the runs, so the console can draw the workflow as a map or an outline
6
+ * and lay a run's steps over it.
7
+ *
8
+ * It is a reading of the code, not a trace: a loop's count, the branch a run takes and a call made
9
+ * through a value are known only at run time. `complete` is false when the reading met something
10
+ * it could not follow, and such a place is an `unknown` node rather than a guess.
11
+ *
12
+ * The shape carries no human-language text of its own: names, descriptions and conditions are the
13
+ * workspace's code and comments, and kinds are identifiers the reader presents in its own words.
14
+ */
15
+ /** The version of this shape; a reader ignores fields and node kinds it does not know. */
16
+ export const WORKFLOW_STRUCTURE_VERSION = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.104.0",
3
+ "version": "0.105.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",
@@ -106,6 +106,7 @@
106
106
  "marked": "15.0.12",
107
107
  "semver": "7.7.4",
108
108
  "tsx": "4.21.0",
109
+ "typescript": "^5.9",
109
110
  "ulid": "~3.0.1",
110
111
  "zod": "~4.6.7"
111
112
  },
@@ -123,7 +124,6 @@
123
124
  "effect": "4.0.0-rc.113",
124
125
  "esbuild": "^0.27.0",
125
126
  "nitro": "3.0.260903-beta",
126
- "typescript": "^5.9",
127
127
  "vitest": "^4.1.12",
128
128
  "workflow": "5.5.0"
129
129
  },