@gobing-ai/ts-dual-workflow-engine 0.2.7 → 0.2.9

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/src/config.ts CHANGED
@@ -1,26 +1,24 @@
1
- import { getFs } from '@gobing-ai/ts-runtime';
2
- import { parse } from 'yaml';
1
+ import { loadStructuredConfig, parseYamlObject } from '@gobing-ai/ts-runtime';
3
2
  import { WorkflowValidationError } from './errors';
4
- import { WorkflowDefSchema } from './schema';
3
+ import { StateMachineWorkflowDefSchema, TransitionFlowWorkflowDefSchema } from './schema';
5
4
  import type { WorkflowDef } from './types';
6
5
 
6
+ export interface WorkflowLoadOptions {
7
+ /** When true, honor a top-level `$schema` ref. Defaults to true for file loads. */
8
+ validateSchema?: boolean;
9
+ /** Optional fetch implementation for remote HTTP(S) schema refs. */
10
+ fetch?: (input: string) => Promise<Response>;
11
+ }
12
+
7
13
  /** Load a workflow definition from YAML or JSON text. */
8
14
  export function loadWorkflowDefFromText(text: string, source = '<inline>'): WorkflowDef {
9
- const parsed = source.endsWith('.json') ? JSON.parse(text) : parse(text);
10
- const result = WorkflowDefSchema.safeParse(parsed);
11
- if (!result.success) {
12
- throw new WorkflowValidationError(
13
- `Workflow definition failed schema validation for ${source}: ${result.error.issues.map((issue) => issue.message).join('; ')}`,
14
- result.error.issues,
15
- );
16
- }
17
- validateWorkflowDef(result.data as WorkflowDef);
18
- return result.data as WorkflowDef;
15
+ const parsed = source.endsWith('.json') ? JSON.parse(text) : parseYamlObject(text);
16
+ return parseWorkflowDef(parsed, source);
19
17
  }
20
18
 
21
19
  /** Load a workflow definition from a filesystem path. */
22
- export async function loadWorkflowDef(path: string): Promise<WorkflowDef> {
23
- return loadWorkflowDefFromText(await getFs().readFile(path), path);
20
+ export async function loadWorkflowDef(path: string, options: WorkflowLoadOptions = {}): Promise<WorkflowDef> {
21
+ return parseWorkflowDef(await loadStructuredConfig(path, options), path);
24
22
  }
25
23
 
26
24
  /** Validate semantic workflow invariants beyond structural Zod checks. */
@@ -33,25 +31,203 @@ export function validateWorkflowDef(workflow: WorkflowDef): void {
33
31
  }
34
32
 
35
33
  function validateStateMachine(workflow: Extract<WorkflowDef, { kind?: 'state-machine' }>): void {
36
- const states = new Set(workflow.states.map((state) => state.id));
34
+ const errors: string[] = [];
35
+ const ids = workflow.states.map((state) => state.id);
36
+ const states = new Set(ids);
37
+ const terminals = new Set(workflow.terminalStates ?? []);
38
+
39
+ // Duplicate state ids.
40
+ for (const id of duplicates(ids)) errors.push(`State "${id}" is declared more than once`);
41
+
42
+ // Initial state must be declared and must not be terminal.
37
43
  if (!states.has(workflow.initialState)) {
38
- throw new WorkflowValidationError(`Initial state "${workflow.initialState}" is not declared`);
44
+ errors.push(`Initial state "${workflow.initialState}" is not declared`);
45
+ } else if (terminals.has(workflow.initialState)) {
46
+ errors.push(`Initial state "${workflow.initialState}" must not be a terminal state`);
47
+ }
48
+
49
+ // Terminal states must be declared.
50
+ for (const terminal of terminals) {
51
+ if (!states.has(terminal)) errors.push(`Terminal state "${terminal}" is not declared`);
39
52
  }
53
+
54
+ // Transition endpoints must be declared.
55
+ type Transition = (typeof workflow.transitions)[number];
56
+ const outboundByState = new Map<string, Transition[]>();
40
57
  for (const transition of workflow.transitions) {
41
- if (!states.has(transition.from))
42
- throw new WorkflowValidationError(`Transition source "${transition.from}" is not declared`);
43
- if (!states.has(transition.to))
44
- throw new WorkflowValidationError(`Transition target "${transition.to}" is not declared`);
58
+ if (!states.has(transition.from)) errors.push(`Transition source "${transition.from}" is not declared`);
59
+ if (!states.has(transition.to)) errors.push(`Transition target "${transition.to}" is not declared`);
60
+ const list = outboundByState.get(transition.from) ?? [];
61
+ list.push(transition);
62
+ outboundByState.set(transition.from, list);
63
+ }
64
+
65
+ // Explicit terminal states must not declare outgoing transitions. Note: a state
66
+ // with NO transitions is treated as an implicit terminal by the driver (it stops
67
+ // there), so a missing transition is NOT an error; only an *explicit* terminal
68
+ // that also declares transitions is contradictory.
69
+ for (const state of workflow.states) {
70
+ const outbound = outboundByState.get(state.id) ?? [];
71
+ if (terminals.has(state.id)) {
72
+ if (outbound.length > 0) errors.push(`Terminal state "${state.id}" must not declare transitions`);
73
+ continue;
74
+ }
75
+ // An unguarded transition is unconditional, so anything after it is dead —
76
+ // it must be declared last among a state's outgoing transitions.
77
+ const ungatedIndex = outbound.findIndex((transition) => transition.guard === undefined);
78
+ if (ungatedIndex !== -1 && ungatedIndex < outbound.length - 1) {
79
+ errors.push(
80
+ `State "${state.id}" has an unguarded transition that is not last; later transitions are unreachable`,
81
+ );
82
+ }
45
83
  }
84
+
85
+ // Template variable references must resolve against declared vars / env allowlist.
86
+ errors.push(...checkVariableReferences(collectActionOptions(workflow), workflow.vars, workflow.env));
87
+
88
+ throwIfErrors(workflow, errors);
46
89
  }
47
90
 
48
- function validateTransitionFlow(workflow: Extract<WorkflowDef, { kind: 'transition-flow' }>): void {
49
- const nodes = new Set(workflow.nodes.map((node) => node.id));
50
- if (!nodes.has(workflow.initialNode)) {
51
- throw new WorkflowValidationError(`Initial node "${workflow.initialNode}" is not declared`);
91
+ function parseWorkflowDef(parsed: unknown, source: string): WorkflowDef {
92
+ // Parse against the specific dialect schema (not the union) so errors carry the
93
+ // exact failing field path instead of the union's generic "Invalid input".
94
+ const schema = selectWorkflowSchema(parsed);
95
+ const result = schema.safeParse(parsed);
96
+ if (!result.success) {
97
+ throw new WorkflowValidationError(
98
+ `Workflow definition failed schema validation for ${source}: ${formatWorkflowIssues(result.error.issues)}`,
99
+ result.error.issues,
100
+ );
52
101
  }
102
+ validateWorkflowDef(result.data as WorkflowDef);
103
+ return result.data as WorkflowDef;
104
+ }
105
+
106
+ /** Pick the dialect schema by the shape of the input so diagnostics are field-precise. */
107
+ function selectWorkflowSchema(
108
+ parsed: unknown,
109
+ ): typeof StateMachineWorkflowDefSchema | typeof TransitionFlowWorkflowDefSchema {
110
+ if (parsed !== null && typeof parsed === 'object') {
111
+ const value = parsed as Record<string, unknown>;
112
+ if (value.kind === 'transition-flow' || 'nodes' in value || 'edges' in value || 'initialNode' in value) {
113
+ return TransitionFlowWorkflowDefSchema;
114
+ }
115
+ }
116
+ return StateMachineWorkflowDefSchema;
117
+ }
118
+
119
+ /** Render Zod issues as `path: message` fragments so the offending field is obvious. */
120
+ function formatWorkflowIssues(issues: readonly { path: PropertyKey[]; message: string }[]): string {
121
+ return issues
122
+ .map((issue) => {
123
+ const path = issue.path.map(String).join('.');
124
+ return path.length > 0 ? `${path}: ${issue.message}` : issue.message;
125
+ })
126
+ .join('; ');
127
+ }
128
+
129
+ function validateTransitionFlow(workflow: Extract<WorkflowDef, { kind: 'transition-flow' }>): void {
130
+ const errors: string[] = [];
131
+ const ids = workflow.nodes.map((node) => node.id);
132
+ const nodes = new Set(ids);
133
+
134
+ // Duplicate node ids.
135
+ for (const id of duplicates(ids)) errors.push(`Node "${id}" is declared more than once`);
136
+
137
+ // Initial node must be declared.
138
+ if (!nodes.has(workflow.initialNode)) errors.push(`Initial node "${workflow.initialNode}" is not declared`);
139
+
140
+ // Edge endpoints must be declared; duplicate from→to edges are ambiguous.
141
+ const seenEdges = new Set<string>();
53
142
  for (const edge of workflow.edges) {
54
- if (!nodes.has(edge.from)) throw new WorkflowValidationError(`Edge source "${edge.from}" is not declared`);
55
- if (!nodes.has(edge.to)) throw new WorkflowValidationError(`Edge target "${edge.to}" is not declared`);
143
+ if (!nodes.has(edge.from)) errors.push(`Edge source "${edge.from}" is not declared`);
144
+ if (!nodes.has(edge.to)) errors.push(`Edge target "${edge.to}" is not declared`);
145
+ const key = `${edge.from}→${edge.to}`;
146
+ if (seenEdges.has(key)) errors.push(`Duplicate edge "${key}"`);
147
+ seenEdges.add(key);
148
+ }
149
+
150
+ // Template variable references must resolve.
151
+ errors.push(...checkVariableReferences(collectActionOptions(workflow), workflow.vars, workflow.env));
152
+
153
+ throwIfErrors(workflow, errors);
154
+ }
155
+
156
+ /** Return the ids that appear more than once, in first-seen order. */
157
+ function duplicates(ids: readonly string[]): string[] {
158
+ const seen = new Set<string>();
159
+ const dupes = new Set<string>();
160
+ for (const id of ids) {
161
+ if (seen.has(id)) dupes.add(id);
162
+ seen.add(id);
163
+ }
164
+ return [...dupes];
165
+ }
166
+
167
+ /** Gather every action `options` object across a workflow's states/nodes for template scanning. */
168
+ function collectActionOptions(workflow: WorkflowDef): Record<string, unknown>[] {
169
+ const optionSets: Record<string, unknown>[] = [];
170
+ const actions =
171
+ workflow.kind === 'transition-flow'
172
+ ? workflow.nodes.flatMap((node) => (node.action ? [node.action] : []))
173
+ : workflow.states.flatMap((state) => [...(state.onEnter ?? []), ...(state.onExit ?? [])]);
174
+ for (const action of actions) {
175
+ if (action.options) optionSets.push(action.options);
176
+ }
177
+ return optionSets;
178
+ }
179
+
180
+ /** Reserved template namespaces always available at runtime (not user-declared vars). */
181
+ const RUNTIME_TEMPLATE_NAMESPACES = new Set([
182
+ 'workflow',
183
+ 'runId',
184
+ 'task',
185
+ 'state',
186
+ 'node',
187
+ 'iteration',
188
+ 'run',
189
+ 'runtime',
190
+ ]);
191
+
192
+ /**
193
+ * Check `${...}` template references inside action options resolve to something:
194
+ * a declared `vars.X`, an env-allowlisted `env.X`, or a reserved runtime namespace.
195
+ */
196
+ function checkVariableReferences(
197
+ optionSets: readonly Record<string, unknown>[],
198
+ vars: Record<string, string> | undefined,
199
+ env: { allow?: readonly string[] } | undefined,
200
+ ): string[] {
201
+ const declaredVars = new Set(Object.keys(vars ?? {}));
202
+ const allowedEnv = new Set(env?.allow ?? []);
203
+ const errors: string[] = [];
204
+ const reference = /\$\{([^}]+)\}/g;
205
+ for (const options of optionSets) {
206
+ for (const value of Object.values(options)) {
207
+ if (typeof value !== 'string') continue;
208
+ for (const match of value.matchAll(reference)) {
209
+ const expr = (match[1] ?? '').trim();
210
+ const [namespace, name] = expr.includes('.') ? expr.split('.', 2) : [expr, undefined];
211
+ if (namespace === 'vars') {
212
+ if (name !== undefined && !declaredVars.has(name)) {
213
+ errors.push(`Unknown variable reference "\${${expr}}" (no var "${name}" declared)`);
214
+ }
215
+ } else if (namespace === 'env') {
216
+ if (name !== undefined && !allowedEnv.has(name)) {
217
+ errors.push(`Env reference "\${${expr}}" is not in env.allow`);
218
+ }
219
+ } else if (namespace !== undefined && !RUNTIME_TEMPLATE_NAMESPACES.has(namespace)) {
220
+ errors.push(`Unknown template reference "\${${expr}}"`);
221
+ }
222
+ }
223
+ }
224
+ }
225
+ return errors;
226
+ }
227
+
228
+ /** Throw a single aggregated validation error when any invariant failed. */
229
+ function throwIfErrors(workflow: WorkflowDef, errors: readonly string[]): void {
230
+ if (errors.length > 0) {
231
+ throw new WorkflowValidationError(`Workflow "${workflow.name}" is invalid: ${errors.join('; ')}`, errors);
56
232
  }
57
233
  }
package/src/schema.ts CHANGED
@@ -1,5 +1,28 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ /** Identifier names reserved for runtime template namespaces; not allowed as user vars. */
4
+ const RESERVED_VAR_NAMES = new Set(['task', 'state', 'node', 'iteration', 'run', 'runtime']);
5
+
6
+ /** Valid identifier pattern for variable and env names. */
7
+ const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
8
+
9
+ /** User variables: identifier-keyed string map; reserved runtime names are rejected. */
10
+ const VarsSchema = z.record(z.string(), z.string()).superRefine((vars, ctx) => {
11
+ for (const key of Object.keys(vars)) {
12
+ if (!IDENTIFIER.test(key)) {
13
+ ctx.addIssue({ code: 'custom', message: `Invalid variable name "${key}" (must be a valid identifier)` });
14
+ }
15
+ if (RESERVED_VAR_NAMES.has(key)) {
16
+ ctx.addIssue({ code: 'custom', message: `Variable name "${key}" is reserved for runtime use` });
17
+ }
18
+ }
19
+ });
20
+
21
+ /** Environment allowlist: identifier-named env vars exposed to templates. */
22
+ const EnvSchema = z.object({
23
+ allow: z.array(z.string().regex(IDENTIFIER, 'env.allow entries must be valid identifiers')).optional(),
24
+ });
25
+
3
26
  /** Zod schema for workflow action definitions. */
4
27
  export const ActionDefSchema = z.object({
5
28
  kind: z.string().min(1),
@@ -13,55 +36,79 @@ export const GuardDefSchema = z.object({
13
36
  });
14
37
 
15
38
  /** Zod schema for state-machine workflow definitions. */
16
- export const StateMachineWorkflowDefSchema = z.object({
17
- kind: z.literal('state-machine').optional(),
18
- name: z.string().min(1),
19
- initialState: z.string().min(1),
20
- terminalStates: z.array(z.string().min(1)).optional(),
21
- iterationBound: z.number().int().positive().optional(),
22
- vars: z.record(z.string(), z.string()).optional(),
23
- env: z.object({ allow: z.array(z.string()).optional() }).optional(),
24
- states: z.array(
25
- z.object({
26
- id: z.string().min(1),
27
- onEnter: z.array(ActionDefSchema).optional(),
28
- onExit: z.array(ActionDefSchema).optional(),
29
- }),
30
- ),
31
- transitions: z.array(
32
- z.object({
33
- from: z.string().min(1),
34
- to: z.string().min(1),
35
- trigger: z.string().optional(),
36
- guard: GuardDefSchema.optional(),
37
- }),
38
- ),
39
- });
39
+ export const StateMachineWorkflowDefSchema = z
40
+ .object({
41
+ $schema: z.string().optional(),
42
+ kind: z.literal('state-machine').optional(),
43
+ name: z.string().min(1),
44
+ // Optional, behavior-free document version tag (accepted for forward/backward compat).
45
+ version: z.string().optional(),
46
+ description: z.string().optional(),
47
+ initialState: z.string().min(1),
48
+ terminalStates: z.array(z.string().min(1)).optional(),
49
+ iterationBound: z.number().int().positive().optional(),
50
+ vars: VarsSchema.optional(),
51
+ env: EnvSchema.optional(),
52
+ states: z.array(
53
+ z
54
+ .object({
55
+ id: z.string().min(1),
56
+ description: z.string().optional(),
57
+ onEnter: z.array(ActionDefSchema).optional(),
58
+ onExit: z.array(ActionDefSchema).optional(),
59
+ })
60
+ .strict(),
61
+ ),
62
+ transitions: z.array(
63
+ z
64
+ .object({
65
+ from: z.string().min(1),
66
+ to: z.string().min(1),
67
+ description: z.string().optional(),
68
+ trigger: z.string().optional(),
69
+ guard: GuardDefSchema.optional(),
70
+ })
71
+ .strict(),
72
+ ),
73
+ })
74
+ .strict();
40
75
 
41
76
  /** Zod schema for transition-flow workflow definitions. */
42
- export const TransitionFlowWorkflowDefSchema = z.object({
43
- kind: z.literal('transition-flow'),
44
- name: z.string().min(1),
45
- initialNode: z.string().min(1),
46
- terminalNodes: z.array(z.string().min(1)).optional(),
47
- iterationBound: z.number().int().positive().optional(),
48
- vars: z.record(z.string(), z.string()).optional(),
49
- env: z.object({ allow: z.array(z.string()).optional() }).optional(),
50
- nodes: z.array(
51
- z.object({
52
- id: z.string().min(1),
53
- type: z.enum(['action', 'gate', 'parallel', 'decision']).optional(),
54
- action: ActionDefSchema.optional(),
55
- }),
56
- ),
57
- edges: z.array(
58
- z.object({
59
- from: z.string().min(1),
60
- to: z.string().min(1),
61
- condition: GuardDefSchema.optional(),
62
- }),
63
- ),
64
- });
77
+ export const TransitionFlowWorkflowDefSchema = z
78
+ .object({
79
+ $schema: z.string().optional(),
80
+ kind: z.literal('transition-flow'),
81
+ name: z.string().min(1),
82
+ // Optional, behavior-free document version tag (accepted for forward/backward compat).
83
+ version: z.string().optional(),
84
+ description: z.string().optional(),
85
+ initialNode: z.string().min(1),
86
+ terminalNodes: z.array(z.string().min(1)).optional(),
87
+ iterationBound: z.number().int().positive().optional(),
88
+ vars: VarsSchema.optional(),
89
+ env: EnvSchema.optional(),
90
+ nodes: z.array(
91
+ z
92
+ .object({
93
+ id: z.string().min(1),
94
+ description: z.string().optional(),
95
+ type: z.enum(['action', 'gate', 'parallel', 'decision']).optional(),
96
+ action: ActionDefSchema.optional(),
97
+ })
98
+ .strict(),
99
+ ),
100
+ edges: z.array(
101
+ z
102
+ .object({
103
+ from: z.string().min(1),
104
+ to: z.string().min(1),
105
+ description: z.string().optional(),
106
+ condition: GuardDefSchema.optional(),
107
+ })
108
+ .strict(),
109
+ ),
110
+ })
111
+ .strict();
65
112
 
66
113
  /** Zod schema for either supported workflow definition shape. */
67
114
  export const WorkflowDefSchema = z.union([StateMachineWorkflowDefSchema, TransitionFlowWorkflowDefSchema]);
@@ -54,6 +54,7 @@ export class StateMachineDriver {
54
54
  vars,
55
55
  env,
56
56
  options,
57
+ transitionsTaken,
57
58
  );
58
59
  if (lastActionResult?.ok === false)
59
60
  return await this.fail(
@@ -103,6 +104,7 @@ export class StateMachineDriver {
103
104
  vars,
104
105
  env,
105
106
  options,
107
+ transitionsTaken,
106
108
  );
107
109
  if (exitResult?.ok === false)
108
110
  return await this.fail(runId, workflow.name, mode, current.id, transitionsTaken, exitResult.error);
@@ -139,13 +141,14 @@ export class StateMachineDriver {
139
141
  vars: Record<string, string>,
140
142
  env: Record<string, string>,
141
143
  options: WorkflowRunOptions,
144
+ transitionsTaken: number,
142
145
  ): Promise<ActionResult | undefined> {
143
146
  let last: ActionResult | undefined;
144
147
  for (const action of actions) {
145
148
  const resolved = resolveTemplates(action.options ?? {}, {
146
149
  vars,
147
150
  env,
148
- builtins: { workflow: workflowName, state: stateId, runId },
151
+ builtins: runtimeBuiltins(workflowName, stateId, runId, transitionsTaken),
149
152
  });
150
153
  last = await this.options.host.runAction(action.kind, resolved, {
151
154
  runId,
@@ -186,6 +189,25 @@ export class StateMachineDriver {
186
189
  }
187
190
  }
188
191
 
192
+ /** Built-in bare template values available to state-machine action options. */
193
+ function runtimeBuiltins(
194
+ workflowName: string,
195
+ stateId: string,
196
+ runId: string,
197
+ transitionsTaken: number,
198
+ ): Record<string, string | number> {
199
+ return {
200
+ workflow: workflowName,
201
+ runId,
202
+ task: workflowName,
203
+ state: stateId,
204
+ node: stateId,
205
+ iteration: transitionsTaken,
206
+ run: runId,
207
+ runtime: 'state-machine',
208
+ };
209
+ }
210
+
189
211
  async function firstPassingTransition(
190
212
  transitions: StateMachineWorkflowDef['transitions'],
191
213
  host: WorkflowEngineHost,
@@ -1,4 +1,5 @@
1
1
  import { getProcessEnv } from '@gobing-ai/ts-runtime';
2
+ import { FSMError } from './errors';
2
3
  import type { WorkflowEngineHost } from './host';
3
4
  import type {
4
5
  ActionResult,
@@ -37,7 +38,7 @@ export class TransitionFlowDriver {
37
38
  const iterationBound = workflow.iterationBound ?? 50;
38
39
 
39
40
  if (current === undefined) {
40
- throw new Error(`Initial node "${workflow.initialNode}" is not declared`);
41
+ throw new FSMError(`Initial node "${workflow.initialNode}" is not declared`);
41
42
  }
42
43
 
43
44
  while (true) {
@@ -50,7 +51,7 @@ export class TransitionFlowDriver {
50
51
  const resolved = resolveTemplates(current.action.options ?? {}, {
51
52
  vars,
52
53
  env,
53
- builtins: { workflow: workflow.name, node: current.id, runId },
54
+ builtins: runtimeBuiltins(workflow.name, current.id, runId, transitionsTaken),
54
55
  });
55
56
  lastActionResult = await this.options.host.runAction(current.action.kind, resolved, {
56
57
  runId,
@@ -110,7 +111,7 @@ export class TransitionFlowDriver {
110
111
 
111
112
  // 7. Move to the target node and repeat.
112
113
  const nextNode = nodes.get(edge.to);
113
- if (nextNode === undefined) throw new Error(`Edge target "${edge.to}" is not declared`);
114
+ if (nextNode === undefined) throw new FSMError(`Edge target "${edge.to}" is not declared`);
114
115
  current = nextNode;
115
116
  }
116
117
  }
@@ -141,6 +142,25 @@ export class TransitionFlowDriver {
141
142
  }
142
143
  }
143
144
 
145
+ /** Built-in bare template values available to transition-flow action options. */
146
+ function runtimeBuiltins(
147
+ workflowName: string,
148
+ nodeId: string,
149
+ runId: string,
150
+ transitionsTaken: number,
151
+ ): Record<string, string | number> {
152
+ return {
153
+ workflow: workflowName,
154
+ runId,
155
+ task: workflowName,
156
+ state: nodeId,
157
+ node: nodeId,
158
+ iteration: transitionsTaken,
159
+ run: runId,
160
+ runtime: 'transition-flow',
161
+ };
162
+ }
163
+
144
164
  async function firstPassingEdge(
145
165
  edges: TransitionFlowWorkflowDef['edges'],
146
166
  host: WorkflowEngineHost,
package/src/types.ts CHANGED
@@ -24,6 +24,8 @@ export interface GuardDef {
24
24
  /** One state in a state-machine workflow. */
25
25
  export interface StateDef {
26
26
  readonly id: string;
27
+ /** Optional human description of what this state does. */
28
+ readonly description?: string;
27
29
  readonly onEnter?: readonly ActionDef[];
28
30
  readonly onExit?: readonly ActionDef[];
29
31
  }
@@ -32,6 +34,8 @@ export interface StateDef {
32
34
  export interface TransitionDef {
33
35
  readonly from: string;
34
36
  readonly to: string;
37
+ /** Optional human description of when/why this transition is taken. */
38
+ readonly description?: string;
35
39
  readonly trigger?: string;
36
40
  readonly guard?: GuardDef;
37
41
  }
@@ -40,6 +44,10 @@ export interface TransitionDef {
40
44
  export interface StateMachineWorkflowDef {
41
45
  readonly kind?: 'state-machine';
42
46
  readonly name: string;
47
+ /** Optional behavior-free document version tag. */
48
+ readonly version?: string;
49
+ /** Optional human description of the workflow's purpose. */
50
+ readonly description?: string;
43
51
  readonly initialState: string;
44
52
  readonly terminalStates?: readonly string[];
45
53
  readonly iterationBound?: number;
@@ -52,6 +60,8 @@ export interface StateMachineWorkflowDef {
52
60
  /** Transition-flow node definition. */
53
61
  export interface FlowNodeDef {
54
62
  readonly id: string;
63
+ /** Optional human description of what this node does. */
64
+ readonly description?: string;
55
65
  readonly type?: 'action' | 'gate' | 'parallel' | 'decision';
56
66
  readonly action?: ActionDef;
57
67
  }
@@ -60,6 +70,8 @@ export interface FlowNodeDef {
60
70
  export interface FlowEdgeDef {
61
71
  readonly from: string;
62
72
  readonly to: string;
73
+ /** Optional human description of when/why this edge is taken. */
74
+ readonly description?: string;
63
75
  readonly condition?: GuardDef;
64
76
  }
65
77
 
@@ -67,6 +79,10 @@ export interface FlowEdgeDef {
67
79
  export interface TransitionFlowWorkflowDef {
68
80
  readonly kind: 'transition-flow';
69
81
  readonly name: string;
82
+ /** Optional behavior-free document version tag. */
83
+ readonly version?: string;
84
+ /** Optional human description of the workflow's purpose. */
85
+ readonly description?: string;
70
86
  readonly initialNode: string;
71
87
  readonly terminalNodes?: readonly string[];
72
88
  readonly iterationBound?: number;