@gobing-ai/ts-dual-workflow-engine 0.3.12 → 0.3.14
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 +178 -76
- package/dist/events.d.ts +30 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/persistence.d.ts +19 -1
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +41 -0
- package/dist/run-lifecycle.d.ts +6 -0
- package/dist/run-lifecycle.d.ts.map +1 -1
- package/dist/run-lifecycle.js +68 -14
- package/dist/schema-sql.d.ts +1 -1
- package/dist/schema-sql.d.ts.map +1 -1
- package/dist/schema-sql.js +17 -2
- package/dist/state-machine.d.ts.map +1 -1
- package/dist/state-machine.js +9 -4
- package/dist/transition-flow.d.ts.map +1 -1
- package/dist/transition-flow.js +9 -5
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/events.ts +32 -9
- package/src/host.ts +5 -1
- package/src/index.ts +2 -0
- package/src/persistence.ts +88 -1
- package/src/run-lifecycle.ts +71 -14
- package/src/schema-sql.ts +17 -2
- package/src/state-machine.ts +26 -8
- package/src/transition-flow.ts +23 -12
- package/src/types.ts +28 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @gobing-ai/ts-dual-workflow-engine
|
|
2
2
|
|
|
3
|
-
State-machine and transition-flow workflow runtime with pluggable action runners, guard runners, trust-gated extension loading,
|
|
3
|
+
State-machine and transition-flow workflow runtime with pluggable action runners, guard runners, trust-gated extension loading, memory or database persistence, and rich observability.
|
|
4
4
|
|
|
5
5
|
## What It Provides
|
|
6
6
|
|
|
@@ -13,37 +13,145 @@ State-machine and transition-flow workflow runtime with pluggable action runners
|
|
|
13
13
|
|
|
14
14
|
The package exposes:
|
|
15
15
|
|
|
16
|
+
### Runners & Host
|
|
17
|
+
|
|
16
18
|
| Export | Purpose |
|
|
17
19
|
|--------|---------|
|
|
18
20
|
| `WorkflowService` | High-level loader and runner for both workflow kinds |
|
|
19
21
|
| `StateMachineDriver` | Direct state-machine execution |
|
|
20
22
|
| `TransitionFlowDriver` | Direct transition-flow execution |
|
|
21
23
|
| `WorkflowEngineHost` | Capability registry for action runners and guard runners |
|
|
22
|
-
| `createDefaultWorkflowEngineHost()` | Creates a host with built-in `note`, `shell`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
| `createDefaultWorkflowEngineHost()` | Creates a host with built-in `note`, `shell`, `event.emit`, `always`, `never`, and `action-ok` capabilities |
|
|
25
|
+
|
|
26
|
+
### Built-in Actions & Guards
|
|
27
|
+
|
|
28
|
+
| Export | Purpose |
|
|
29
|
+
|--------|---------|
|
|
30
|
+
| `NoteActionRunner` | Records a note in result data and emits `workflow.hitl.note` |
|
|
31
|
+
| `ShellActionRunner` | Shell command backed by `@gobing-ai/ts-runtime` `ProcessExecutor` |
|
|
32
|
+
| `EventEmitActionRunner` | Emits `workflow.custom` events for user-defined observability |
|
|
33
|
+
| `always` guard | Always passes |
|
|
34
|
+
| `never` guard | Always rejects |
|
|
35
|
+
| `action-ok` guard | Passes when the last action succeeded (`lastActionResult?.ok === true`) |
|
|
36
|
+
|
|
37
|
+
### Persistence
|
|
38
|
+
|
|
39
|
+
| Export | Purpose |
|
|
40
|
+
|--------|---------|
|
|
26
41
|
| `MemoryWorkflowPersistenceAdapter` | In-memory persistence for tests and short-lived runs |
|
|
27
42
|
| `DbWorkflowPersistenceAdapter` | DB-backed persistence over `@gobing-ai/ts-db` |
|
|
28
|
-
| `applyWorkflowEngineSchema()` | Installs the package-owned DB schema |
|
|
29
|
-
| `WORKFLOW_ENGINE_SCHEMA_SQL` | Raw SQL DDL for the workflow engine tables |
|
|
43
|
+
| `applyWorkflowEngineSchema()` | Installs the package-owned DB schema (idempotent; safe to call before every write) |
|
|
44
|
+
| `WORKFLOW_ENGINE_SCHEMA_SQL` | Raw SQL DDL for the 5 workflow engine tables |
|
|
45
|
+
|
|
46
|
+
### Configuration & Validation
|
|
47
|
+
|
|
48
|
+
| Export | Purpose |
|
|
49
|
+
|--------|---------|
|
|
30
50
|
| `loadWorkflowDef()` / `loadWorkflowDefFromText()` | YAML/JSON workflow loading and validation |
|
|
31
51
|
| `validateWorkflowDef()` | Semantic invariant checking beyond Zod schema |
|
|
32
|
-
| `loadWorkflowExtensionsIntoHost()` | Trust-gated extension module loading for actions and guards |
|
|
33
|
-
| `mergeVars()` / `resolveTemplates()` / `resolveTemplateString()` | Variable merging and `${...}` template resolution |
|
|
34
|
-
| `resolveOnErrorPolicy()` | Resolves effective `OnErrorPolicy` from action, workflow default, and run options |
|
|
35
|
-
| `OnErrorPolicy` | Type: `'fail' | 'continue'` — action error-handling strategy |
|
|
36
|
-
| `allowedEnv()` / `runtimeBuiltins()` | Environment allowlist projection and built-in template injection |
|
|
37
52
|
| `StateMachineWorkflowDefSchema` / `TransitionFlowWorkflowDefSchema` / `WorkflowDefSchema` | Zod schemas for workflow definition validation |
|
|
38
53
|
| `ActionDefSchema` / `GuardDefSchema` | Zod schemas for action and guard definitions |
|
|
39
|
-
|
|
54
|
+
|
|
55
|
+
### Extensions
|
|
56
|
+
|
|
57
|
+
| Export | Purpose |
|
|
58
|
+
|--------|---------|
|
|
59
|
+
| `loadWorkflowExtensionsIntoHost()` | Trust-gated extension module loading for actions and guards |
|
|
40
60
|
| `WorkflowExtensionRef` / `LoadWorkflowExtensionsOptions` / `WorkflowExtensionKind` | Extension loading types |
|
|
61
|
+
|
|
62
|
+
### Runtime
|
|
63
|
+
|
|
64
|
+
| Export | Purpose |
|
|
65
|
+
|--------|---------|
|
|
66
|
+
| `RunLifecycle` | Shared run bookkeeping: identity, persistence sequencing, OTel spans, structured logging, and optional event bus emission |
|
|
67
|
+
| `mergeVars()` / `mergeSetVars()` | Variable merging with run-override semantics |
|
|
68
|
+
| `resolveTemplates()` / `resolveTemplateString()` | `${...}` template resolution in options objects |
|
|
69
|
+
| `runtimeBuiltins()` | Injects runtime template values (`workflow`, `runId`, `state`, `iteration`, etc.) |
|
|
70
|
+
| `allowedEnv()` | Environment allowlist projection over `process.env` |
|
|
71
|
+
| `resolveOnErrorPolicy()` | Resolves effective `OnErrorPolicy` from action, workflow default, and run options |
|
|
72
|
+
|
|
73
|
+
### Types & Errors
|
|
74
|
+
|
|
75
|
+
| Export | Purpose |
|
|
76
|
+
|--------|---------|
|
|
77
|
+
| `WorkflowEngineEvents` | Typed event map — all events prefixed `workflow.` |
|
|
78
|
+
| `OnErrorPolicy` | Type: `'fail' | 'continue'` |
|
|
79
|
+
| `HitlRequest` / `HitlAnswer` / `HitlResponder` | Human-in-the-loop interaction contracts (interfaces only; no implementation) |
|
|
80
|
+
| `FSMError` / `WorkflowValidationError` / `RunCollisionError` | Structured error classes |
|
|
41
81
|
| `ActionRunner` / `GuardRunner` / `WorkflowDef` / `WorkflowRunResult` … | Type-only exports for all domain types |
|
|
42
|
-
| `WorkflowEngineEvents` | Typed event map for workflow-engine observability. All events prefixed `workflow.` — see [Observability](#observability) |
|
|
43
82
|
|
|
44
|
-
##
|
|
83
|
+
## DB Schema
|
|
45
84
|
|
|
46
|
-
|
|
85
|
+
The engine owns 5 tables. `applyWorkflowEngineSchema()` installs them idempotently (all `CREATE TABLE IF NOT EXISTS`). The schema applies every write path (`createRun`, `loadRun`, `listRuns`) so late-schema callers always find the tables.
|
|
86
|
+
|
|
87
|
+
```mermaid
|
|
88
|
+
erDiagram
|
|
89
|
+
runs {
|
|
90
|
+
TEXT id PK "run identifier (caller-provided or auto-generated)"
|
|
91
|
+
TEXT workflow_name "human-readable workflow name"
|
|
92
|
+
TEXT mode "'state-machine' or 'transition-flow'"
|
|
93
|
+
TEXT status "NOT NULL — 'running'|'done'|'failed'"
|
|
94
|
+
TEXT agent "agent identifier"
|
|
95
|
+
TEXT started_at "ISO 8601 timestamp"
|
|
96
|
+
TEXT completed_at "ISO 8601, null until terminal"
|
|
97
|
+
TEXT metadata_json "JSON object, defaults '{}'"
|
|
98
|
+
INTEGER created_at "epoch ms"
|
|
99
|
+
INTEGER updated_at "epoch ms"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
phase_runs {
|
|
103
|
+
TEXT id PK "composite key: {runId}:phase:{phase}:{uuid}"
|
|
104
|
+
TEXT run_id FK "references runs.id"
|
|
105
|
+
TEXT phase "state or node id"
|
|
106
|
+
TEXT status "NOT NULL — 'running'|'done'|'failed'"
|
|
107
|
+
TEXT started_at "ISO 8601, nullable"
|
|
108
|
+
TEXT completed_at "ISO 8601, nullable"
|
|
109
|
+
INTEGER created_at "epoch ms"
|
|
110
|
+
INTEGER updated_at "epoch ms"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
transition_runs {
|
|
114
|
+
TEXT id PK "composite key: {runId}:transition:{from}:{to}:{uuid}"
|
|
115
|
+
TEXT run_id FK "references runs.id"
|
|
116
|
+
TEXT from_state "source state/node id"
|
|
117
|
+
TEXT to_state "target state/node id"
|
|
118
|
+
TEXT trigger "guard kind or null for unconditional"
|
|
119
|
+
TEXT status "NOT NULL — always 'done'"
|
|
120
|
+
INTEGER created_at "epoch ms"
|
|
121
|
+
INTEGER updated_at "epoch ms"
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
workflow_states {
|
|
125
|
+
TEXT id PK "composite key: {runId}:state:{state}:{uuid}"
|
|
126
|
+
TEXT run_id FK "references runs.id"
|
|
127
|
+
TEXT state "state or node id"
|
|
128
|
+
TEXT data_json "serialized workflow data"
|
|
129
|
+
INTEGER created_at "epoch ms"
|
|
130
|
+
INTEGER updated_at "epoch ms"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
action_runs {
|
|
134
|
+
TEXT id PK "UUID"
|
|
135
|
+
TEXT run_id FK "references runs.id"
|
|
136
|
+
TEXT node "state or node id where the action executed"
|
|
137
|
+
TEXT kind "action kind string"
|
|
138
|
+
TEXT status "NOT NULL — 'running'|'done'|'failed'"
|
|
139
|
+
INTEGER duration_ms "wall-clock ms, populated on finalize"
|
|
140
|
+
INTEGER ok "1 for success, 0 for failure, null until finalize"
|
|
141
|
+
TEXT result_json "serialized action result, null for noop"
|
|
142
|
+
TEXT started_at "ISO 8601, nullable"
|
|
143
|
+
TEXT completed_at "ISO 8601, nullable"
|
|
144
|
+
INTEGER created_at "epoch ms"
|
|
145
|
+
INTEGER updated_at "epoch ms"
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
runs ||--o{ phase_runs : "has"
|
|
149
|
+
runs ||--o{ transition_runs : "has"
|
|
150
|
+
runs ||--o{ workflow_states : "has"
|
|
151
|
+
runs ||--o{ action_runs : "has"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Architecture
|
|
47
155
|
|
|
48
156
|
```
|
|
49
157
|
┌──────────────────────────────────────────────────────┐
|
|
@@ -67,6 +175,7 @@ The package exposes:
|
|
|
67
175
|
│ • persistence (createRun, savePhase, │
|
|
68
176
|
│ saveTransition, finalizeRun) │
|
|
69
177
|
│ • OTel span + structured logging │
|
|
178
|
+
│ • event bus emission (opt-in) │
|
|
70
179
|
└───────────────┬───────────────────────┘
|
|
71
180
|
│
|
|
72
181
|
┌────────────┼────────────┐
|
|
@@ -80,6 +189,7 @@ The package exposes:
|
|
|
80
189
|
```
|
|
81
190
|
|
|
82
191
|
### State-Machine Step Execution
|
|
192
|
+
|
|
83
193
|
The state-machine driver runs a loop until reaching a terminal state, failure, or iteration bound. Each iteration:
|
|
84
194
|
|
|
85
195
|
1. Persists the state snapshot and marks its phase `running`
|
|
@@ -310,18 +420,23 @@ const result = await driver.run(
|
|
|
310
420
|
result.status; // "done"
|
|
311
421
|
result.finalState; // "done"
|
|
312
422
|
captureAction.seen; // ["approved"]
|
|
423
|
+
```
|
|
313
424
|
|
|
314
|
-
|
|
315
|
-
|
|
425
|
+
The driver persists each state snapshot, phase update, transition, and final run status through the configured persistence adapter.
|
|
426
|
+
|
|
427
|
+
### Error Resilience — `onError: 'continue'`
|
|
428
|
+
|
|
429
|
+
```ts
|
|
430
|
+
const host = new WorkflowEngineHost()
|
|
316
431
|
.registerAction(failableAction)
|
|
317
432
|
.registerGuard({ kind: 'always', evaluate: async () => true });
|
|
318
433
|
|
|
319
|
-
const
|
|
320
|
-
host
|
|
434
|
+
const driver = new StateMachineDriver({
|
|
435
|
+
host,
|
|
321
436
|
persistence: new MemoryWorkflowPersistenceAdapter(),
|
|
322
437
|
});
|
|
323
438
|
|
|
324
|
-
const
|
|
439
|
+
const result = await driver.run({
|
|
325
440
|
name: 'resilient-approval',
|
|
326
441
|
initialState: 'draft',
|
|
327
442
|
terminalStates: ['done'],
|
|
@@ -332,11 +447,8 @@ const resilientResult = await resilientDriver.run({
|
|
|
332
447
|
],
|
|
333
448
|
transitions: [{ from: 'draft', to: 'done', guard: { kind: 'always' } }],
|
|
334
449
|
});
|
|
335
|
-
|
|
336
450
|
```
|
|
337
451
|
|
|
338
|
-
The driver persists each state snapshot, phase update, transition, and final run status through the configured persistence adapter.
|
|
339
|
-
|
|
340
452
|
## Transition Flow Example
|
|
341
453
|
|
|
342
454
|
```ts
|
|
@@ -367,7 +479,7 @@ result.status; // "done"
|
|
|
367
479
|
result.finalState; // "done"
|
|
368
480
|
```
|
|
369
481
|
|
|
370
|
-
The default host includes built-in `note
|
|
482
|
+
The default host includes built-in `note`, `shell`, `event.emit`, `always`, `never`, and `action-ok` capabilities. For production systems, register domain-specific runners and keep shell execution explicit.
|
|
371
483
|
|
|
372
484
|
## Load Workflows from YAML
|
|
373
485
|
|
|
@@ -378,7 +490,7 @@ const workflow = await loadWorkflowDef('./workflows/approval.yaml');
|
|
|
378
490
|
await service.run(workflow, { runId: 'approval-1' });
|
|
379
491
|
```
|
|
380
492
|
|
|
381
|
-
`loadWorkflowDef(path)` reads YAML or JSON from disk. File loads honor a top-level `$schema` ref by default, then validate the internal structural schema and semantic references before returning a `WorkflowDef`. The `$schema` value resolves from the bundled package schema
|
|
493
|
+
`loadWorkflowDef(path)` reads YAML or JSON from disk. File loads honor a top-level `$schema` ref by default, then validate the internal structural schema and semantic references before returning a `WorkflowDef`. The `$schema` value resolves from the bundled package schema — no network access; quote the value, since YAML treats a leading `@` as reserved. `loadWorkflowDefFromText(text, source)` handles inline definitions with internal validation only.
|
|
382
494
|
|
|
383
495
|
### State-machine YAML
|
|
384
496
|
|
|
@@ -524,7 +636,7 @@ const service = new WorkflowService(
|
|
|
524
636
|
);
|
|
525
637
|
```
|
|
526
638
|
|
|
527
|
-
Use `service.listRuns()` to read persisted run records. The adapter stores
|
|
639
|
+
Use `service.listRuns()` to read persisted run records. The adapter stores runs, phase snapshots, transition records, workflow state snapshots, and action runs across 5 tables. Schema is applied idempotently on every write path — late callers always find the tables. `DbWorkflowPersistenceAdapter` throws `RunCollisionError` on duplicate run ids. Corrupt payloads or DB errors during `processOnce()`/poll cycles on a queue consumer (when used with `@gobing-ai/ts-infra`'s `EventBus.createJobHandler()` bridge) are handled gracefully.
|
|
528
640
|
|
|
529
641
|
## Custom Actions and Guards
|
|
530
642
|
|
|
@@ -554,7 +666,7 @@ host.registerGuard({
|
|
|
554
666
|
});
|
|
555
667
|
```
|
|
556
668
|
|
|
557
|
-
Registered actions and guards are available to any workflow definition by their `kind` string. Internally, the host uses `CapabilityRegistry` from `@gobing-ai/ts-runtime/extension` to track registrations with origin metadata (`'builtin'`, `'extension'`, or `'core'`).
|
|
669
|
+
Registered actions and guards are available to any workflow definition by their `kind` string. Internally, the host uses `CapabilityRegistry` from `@gobing-ai/ts-runtime/extension` to track registrations with origin metadata (`'builtin'`, `'extension'`, or `'core'`). Query origin with `host.actionOrigin(kind)` / `host.guardOrigin(kind)`.
|
|
558
670
|
|
|
559
671
|
## Extension Loading
|
|
560
672
|
|
|
@@ -602,17 +714,7 @@ await loadWorkflowExtensionsIntoHost(
|
|
|
602
714
|
);
|
|
603
715
|
```
|
|
604
716
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
Override warnings are emitted through an optional `logger.warn` callback when an extension replaces a built-in capability:
|
|
608
|
-
|
|
609
|
-
```ts
|
|
610
|
-
await loadWorkflowExtensionsIntoHost(host, refs, {
|
|
611
|
-
allowExtensions: true,
|
|
612
|
-
moduleLoader: (absPath) => import(absPath),
|
|
613
|
-
logger: { warn: (msg) => console.warn(msg) },
|
|
614
|
-
});
|
|
615
|
-
```
|
|
717
|
+
When a ref has `kind: 'actions'`, only the module's `actions[]` entries are registered; `guards[]` in the same module are ignored (and vice versa). Override warnings are emitted through an optional `logger.warn` callback when an extension replaces a built-in capability.
|
|
616
718
|
|
|
617
719
|
### Security
|
|
618
720
|
|
|
@@ -624,8 +726,6 @@ await loadWorkflowExtensionsIntoHost(host, refs, {
|
|
|
624
726
|
|
|
625
727
|
## Zod Schemas
|
|
626
728
|
|
|
627
|
-
The package exports Zod schemas for programmatic validation:
|
|
628
|
-
|
|
629
729
|
```ts
|
|
630
730
|
import { StateMachineWorkflowDefSchema, WorkflowDefSchema } from '@gobing-ai/ts-dual-workflow-engine';
|
|
631
731
|
|
|
@@ -666,7 +766,7 @@ resolveTemplateString('Run ${runId} in ${runtime}', {
|
|
|
666
766
|
|
|
667
767
|
## Observability
|
|
668
768
|
|
|
669
|
-
The workflow engine uses a **three-layer observability model
|
|
769
|
+
The workflow engine uses a **three-layer observability model**:
|
|
670
770
|
|
|
671
771
|
| Layer | Tool | Consumer |
|
|
672
772
|
|-------|------|----------|
|
|
@@ -682,59 +782,60 @@ All three layers are **additive** — EventBus does not replace logging or traci
|
|
|
682
782
|
|
|
683
783
|
| Event | Payload | When |
|
|
684
784
|
|-------|---------|------|
|
|
685
|
-
| `workflow.run.started` | `{ workflowName, mode, runId }` | When a run begins (inside the span) |
|
|
686
|
-
| `workflow.run.done` | `{ finalState, transitionsTaken }` | When a run completes successfully |
|
|
687
|
-
| `workflow.run.failed` | `{ finalState, reason }` | When a run fails |
|
|
688
|
-
| `workflow.node.enter` | `{ node, transitionsTaken }` | When entering a state or node |
|
|
689
|
-
| `workflow.node.transition` | `{ from, to, trigger }` | On a state/node transition |
|
|
690
|
-
| `workflow.action.start` | `{ node, kind }` | When an action starts executing |
|
|
691
|
-
| `workflow.action.done` | `{ node, kind, durationMs, ok }` | When an action finishes (success or failure) |
|
|
692
|
-
| `workflow.action.failed_continue` | `{ node, transitionsTaken, error? }` | When a non-fatal action failure is continued past
|
|
693
|
-
| `workflow.custom` | `{ name, payload }` | Emitted by the builtin `event.emit` action
|
|
694
|
-
| `workflow.hitl.note` | `{ node, message }` | Emitted by the builtin `note` action
|
|
785
|
+
| `workflow.run.started` | `{ workflowName, mode, runId, dryRun }` | When a run begins (inside the span) |
|
|
786
|
+
| `workflow.run.done` | `{ runId, finalState, transitionsTaken }` | When a run completes successfully |
|
|
787
|
+
| `workflow.run.failed` | `{ runId, finalState, reason }` | When a run fails |
|
|
788
|
+
| `workflow.node.enter` | `{ runId, node, transitionsTaken }` | When entering a state or node |
|
|
789
|
+
| `workflow.node.transition` | `{ runId, from, to, trigger }` | On a state/node transition |
|
|
790
|
+
| `workflow.action.start` | `{ runId, node, kind }` | When an action starts executing |
|
|
791
|
+
| `workflow.action.done` | `{ runId, node, kind, durationMs, ok }` | When an action finishes (success or failure) |
|
|
792
|
+
| `workflow.action.failed_continue` | `{ runId, node, transitionsTaken, error? }` | When a non-fatal action failure is continued past |
|
|
793
|
+
| `workflow.custom` | `{ name, payload }` | Emitted by the builtin `event.emit` action |
|
|
794
|
+
| `workflow.hitl.note` | `{ runId, node, message }` | Emitted by the builtin `note` action |
|
|
795
|
+
| `workflow.guard.evaluated` | `{ runId, from, to, kind, passed }` | When a guard condition is evaluated (fires for every guard) |
|
|
796
|
+
| `workflow.hitl.ask` | `{ runId, node, kind, message }` | When an interactive HITL prompt is presented |
|
|
797
|
+
| `workflow.hitl.response` | `{ runId, node, ok }` | When a HITL prompt receives a response |
|
|
798
|
+
|
|
799
|
+
### Compatibility Policy
|
|
800
|
+
|
|
801
|
+
The event map is a **cross-package public contract**. Policy: **additive-only** — new events allowed, new optional payload fields allowed; never rename, remove, or repurpose an existing event or field.
|
|
802
|
+
|
|
803
|
+
### Subscriber Contract
|
|
804
|
+
|
|
805
|
+
Event handlers registered via `EventBus.on()` or `EventBus.once()` **must** be:
|
|
806
|
+
- **Fast** — handlers run synchronously on the emit call path; slow handlers stall the workflow execution
|
|
807
|
+
- **Non-throwing** — handler errors are swallowed by `EventBus`; durable behavior must never depend on event delivery
|
|
808
|
+
- **Best-effort** — the engine emits via `void emit()` (fire-and-forget); async handlers are not awaited
|
|
809
|
+
|
|
810
|
+
For **durable** audit/history/telemetry, use the persistence layer — every record is written incrementally during the run via direct adapter calls, not through the event bus.
|
|
811
|
+
|
|
695
812
|
### Usage
|
|
696
813
|
|
|
697
814
|
Pass an `EventBus` via `WorkflowRunOptions.events`:
|
|
698
815
|
|
|
699
816
|
```ts
|
|
700
|
-
import { WorkflowService, createDefaultWorkflowEngineHost, MemoryWorkflowPersistenceAdapter } from '@gobing-ai/ts-dual-workflow-engine';
|
|
701
817
|
import { EventBus } from '@gobing-ai/ts-infra';
|
|
702
818
|
import type { WorkflowEngineEvents } from '@gobing-ai/ts-dual-workflow-engine';
|
|
703
819
|
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
console.log(`Action ${data.kind} on ${data.node}: ${data.ok ? 'ok' : 'fail'} (${data.durationMs}ms)`);
|
|
820
|
+
const events = new EventBus<WorkflowEngineEvents>();
|
|
821
|
+
events.on('workflow.action.done', ({ runId, kind, durationMs, ok }) => {
|
|
822
|
+
console.log(`Action ${kind} in run ${runId}: ${durationMs}ms, ok=${ok}`);
|
|
708
823
|
});
|
|
709
824
|
|
|
710
|
-
|
|
711
|
-
console.log(`Run done at ${data.finalState} (${data.transitionsTaken} transitions)`);
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
const service = new WorkflowService(
|
|
715
|
-
createDefaultWorkflowEngineHost(),
|
|
716
|
-
new MemoryWorkflowPersistenceAdapter(),
|
|
717
|
-
);
|
|
718
|
-
|
|
719
|
-
const result = await service.run(workflow, { events: bus });
|
|
825
|
+
await service.run(workflow, { runId: 'r1', events });
|
|
720
826
|
```
|
|
721
827
|
|
|
722
|
-
### Zero-overhead default
|
|
723
|
-
|
|
724
828
|
When no `events` option is provided, the engine incurs zero observability overhead — no emit calls, no handler invocations. The event bus is purely opt-in.
|
|
725
829
|
|
|
726
|
-
### Action-level events
|
|
727
|
-
|
|
728
|
-
`workflow.action.start` and `workflow.action.done` fire for nodes that have an action configured. A node without an action emits neither. `durationMs` is measured from action start to settlement, and `ok` reflects the action result (`true` for success, `false` for failure).
|
|
729
|
-
|
|
730
830
|
## RunLifecycle
|
|
731
831
|
|
|
732
832
|
`RunLifecycle` is the shared bookkeeping layer both drivers delegate to. It manages:
|
|
733
833
|
|
|
734
834
|
- **Run identity** — generates a `runId` (or honors caller-provided), timestamps, and run record
|
|
735
835
|
- **Persistence sequencing** — `createRun` → `savePhase`/`saveWorkflowState` per step → `finalizeRun` at the end
|
|
736
|
-
- **Observability** — wraps the full run in an OTel span, emits span events, logs each lifecycle event through `@gobing-ai/ts-infra` logger, and optionally emits `WorkflowEngineEvents` via an injected `EventBus`
|
|
737
|
-
- **Error resilience** — `warnActionFailed()` logs non-fatal warnings for `onError: 'continue'` actions
|
|
836
|
+
- **Observability** — wraps the full run in an OTel span, emits span events, logs each lifecycle event through `@gobing-ai/ts-infra` logger, and optionally emits `WorkflowEngineEvents` via an injected `EventBus`
|
|
837
|
+
- **Error resilience** — `warnActionFailed()` logs non-fatal warnings for `onError: 'continue'` actions
|
|
838
|
+
|
|
738
839
|
```ts
|
|
739
840
|
import { RunLifecycle, type RunLifecycleDeps } from '@gobing-ai/ts-dual-workflow-engine';
|
|
740
841
|
|
|
@@ -767,7 +868,7 @@ Run failures caused by actions or guards are returned as `WorkflowRunResult` wit
|
|
|
767
868
|
Actions, workflow definitions, and `WorkflowRunOptions` accept `onError?: 'fail' | 'continue'`.
|
|
768
869
|
The resolved policy follows precedence `action.onError ?? workflow.defaultOnError ?? runOptions.onError ?? 'fail'`.
|
|
769
870
|
|
|
770
|
-
- **`'fail'`** (default): the run halts immediately with `status: 'failed'
|
|
871
|
+
- **`'fail'`** (default): the run halts immediately with `status: 'failed'`.
|
|
771
872
|
- **`'continue'`**: logs a structured warning through `RunLifecycle.warnActionFailed()` and advances to the next
|
|
772
873
|
state, node, guard, or edge evaluation. A node with no outbound edges that fails with `'continue'` still
|
|
773
874
|
terminates as `done`.
|
|
@@ -778,3 +879,4 @@ The resolved policy follows precedence `action.onError ?? workflow.defaultOnErro
|
|
|
778
879
|
- Persistence is adapter-based. Downstream apps own DB lifecycle and migration ordering.
|
|
779
880
|
- Action and guard runners are the extension points. Keep domain behavior there, not in workflow parsing.
|
|
780
881
|
- The host's `CapabilityRegistry` tracks the origin (`'builtin'`, `'extension'`, `'core'`) of every registered action and guard — query it with `host.actionOrigin(kind)` / `host.guardOrigin(kind)`.
|
|
882
|
+
- HITL types (`HitlRequest`, `HitlAnswer`, `HitlResponder`) are interfaces only — this package ships no HITL implementation.
|
package/dist/events.d.ts
CHANGED
|
@@ -5,35 +5,42 @@ export type WorkflowEngineEvents = {
|
|
|
5
5
|
workflowName: string;
|
|
6
6
|
mode: string;
|
|
7
7
|
runId: string;
|
|
8
|
+
dryRun: boolean;
|
|
8
9
|
}) => void;
|
|
9
10
|
/** Emitted when a run completes successfully. */
|
|
10
11
|
'workflow.run.done': (data: {
|
|
12
|
+
runId: string;
|
|
11
13
|
finalState: string;
|
|
12
14
|
transitionsTaken: number;
|
|
13
15
|
}) => void;
|
|
14
16
|
/** Emitted when a run fails. */
|
|
15
17
|
'workflow.run.failed': (data: {
|
|
18
|
+
runId: string;
|
|
16
19
|
finalState: string;
|
|
17
20
|
reason: string;
|
|
18
21
|
}) => void;
|
|
19
22
|
/** Emitted when entering a state or node. */
|
|
20
23
|
'workflow.node.enter': (data: {
|
|
24
|
+
runId: string;
|
|
21
25
|
node: string;
|
|
22
26
|
transitionsTaken: number;
|
|
23
27
|
}) => void;
|
|
24
28
|
/** Emitted on a state/node transition. */
|
|
25
29
|
'workflow.node.transition': (data: {
|
|
30
|
+
runId: string;
|
|
26
31
|
from: string;
|
|
27
32
|
to: string;
|
|
28
33
|
trigger: string | null;
|
|
29
34
|
}) => void;
|
|
30
35
|
/** Emitted when an action starts executing. */
|
|
31
36
|
'workflow.action.start': (data: {
|
|
37
|
+
runId: string;
|
|
32
38
|
node: string;
|
|
33
39
|
kind: string;
|
|
34
40
|
}) => void;
|
|
35
41
|
/** Emitted when an action finishes executing (success or failure). */
|
|
36
42
|
'workflow.action.done': (data: {
|
|
43
|
+
runId: string;
|
|
37
44
|
node: string;
|
|
38
45
|
kind: string;
|
|
39
46
|
durationMs: number;
|
|
@@ -41,6 +48,7 @@ export type WorkflowEngineEvents = {
|
|
|
41
48
|
}) => void;
|
|
42
49
|
/** Emitted when a non-fatal action failure is continued past (onError: 'continue'). */
|
|
43
50
|
'workflow.action.failed_continue': (data: {
|
|
51
|
+
runId: string;
|
|
44
52
|
node: string;
|
|
45
53
|
transitionsTaken: number;
|
|
46
54
|
error?: string;
|
|
@@ -52,8 +60,30 @@ export type WorkflowEngineEvents = {
|
|
|
52
60
|
}) => void;
|
|
53
61
|
/** Emitted by the builtin `note` action for workflow-visible annotations. */
|
|
54
62
|
'workflow.hitl.note': (data: {
|
|
63
|
+
runId: string;
|
|
64
|
+
node: string;
|
|
65
|
+
message: string;
|
|
66
|
+
}) => void;
|
|
67
|
+
/** Emitted when a guard condition is evaluated. Fires for every guard, including rejected ones. */
|
|
68
|
+
'workflow.guard.evaluated': (data: {
|
|
69
|
+
runId: string;
|
|
70
|
+
from: string;
|
|
71
|
+
to: string;
|
|
72
|
+
kind: string;
|
|
73
|
+
passed: boolean;
|
|
74
|
+
}) => void;
|
|
75
|
+
/** Emitted when an interactive HITL prompt is presented and the engine waits for input. */
|
|
76
|
+
'workflow.hitl.ask': (data: {
|
|
77
|
+
runId: string;
|
|
55
78
|
node: string;
|
|
79
|
+
kind: string;
|
|
56
80
|
message: string;
|
|
57
81
|
}) => void;
|
|
82
|
+
/** Emitted when an interactive HITL prompt receives a response. */
|
|
83
|
+
'workflow.hitl.response': (data: {
|
|
84
|
+
runId: string;
|
|
85
|
+
node: string;
|
|
86
|
+
ok: boolean;
|
|
87
|
+
}) => void;
|
|
58
88
|
};
|
|
59
89
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,MAAM,oBAAoB,GAAG;IAC/B,mDAAmD;IACnD,sBAAsB,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,MAAM,MAAM,oBAAoB,GAAG;IAC/B,mDAAmD;IACnD,sBAAsB,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC/G,iDAAiD;IACjD,mBAAmB,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACrG,gCAAgC;IAChC,qBAAqB,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAA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,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAI/G;AAED,4FAA4F;AAC5F,wBAAgB,+BAA+B,CAC3C,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,eAAe,CAAA;CAAO,GACpD,kBAAkB,CAepB;AAED,gFAAgF;AAChF,qBAAa,gBAAiB,YAAW,YAAY;IACjD,QAAQ,CAAC,IAAI,UAAU;IAEvB,kEAAkE;IAC5D,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;CASrG;AAED,yFAAyF;AACzF,qBAAa,qBAAsB,YAAW,YAAY;IACtD,QAAQ,CAAC,IAAI,gBAAgB;IAEvB,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;CAOrG;AAED,kEAAkE;AAClE,qBAAa,iBAAkB,YAAW,YAAY;IAGtC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAF5C,QAAQ,CAAC,IAAI,WAAW;gBAEK,eAAe,EAAE,eAAe;IAE7D;;;;;;;;OAQG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;CAkBpG"}
|
package/dist/host.js
CHANGED
|
@@ -74,7 +74,11 @@ export class NoteActionRunner {
|
|
|
74
74
|
/** Execute a no-op note action with observable event emission. */
|
|
75
75
|
async execute(options, context) {
|
|
76
76
|
const message = String(options.message ?? '');
|
|
77
|
-
void context?.events?.emit('workflow.hitl.note', {
|
|
77
|
+
void context?.events?.emit('workflow.hitl.note', {
|
|
78
|
+
runId: context.runId,
|
|
79
|
+
node: context.stateOrNodeId,
|
|
80
|
+
message,
|
|
81
|
+
});
|
|
78
82
|
return { ok: true, data: { message } };
|
|
79
83
|
}
|
|
80
84
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export { WORKFLOW_ENGINE_SCHEMA_SQL } from './schema-sql';
|
|
|
11
11
|
export { WorkflowService } from './service';
|
|
12
12
|
export { StateMachineDriver, type StateMachineDriverOptions } from './state-machine';
|
|
13
13
|
export { TransitionFlowDriver, type TransitionFlowDriverOptions } from './transition-flow';
|
|
14
|
-
export type { ActionDef, ActionResult, ActionRunContext, ActionRunner, Env, FlowEdgeDef, FlowNodeDef, GuardContext, GuardDef, GuardRunner, OnErrorPolicy, StateDef, StateMachineWorkflowDef, TransitionDef, TransitionFlowWorkflowDef, Vars, WorkflowDef, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunRecord, WorkflowRunResult, WorkflowStatus, } from './types';
|
|
14
|
+
export type { ActionDef, ActionRedactor, ActionResult, ActionRunContext, ActionRunner, ActionRunRecord, Env, FlowEdgeDef, FlowNodeDef, GuardContext, GuardDef, GuardRunner, OnErrorPolicy, StateDef, StateMachineWorkflowDef, TransitionDef, TransitionFlowWorkflowDef, Vars, WorkflowDef, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunRecord, WorkflowRunResult, WorkflowStatus, } from './types';
|
|
15
15
|
export { mergeSetVars, mergeVars, resolveOnErrorPolicy, resolveTemplateString, resolveTemplates, type VariableContext, } from './variables';
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAChF,YAAY,EAAE,oB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E,KAAK,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAC3F,YAAY,EACR,SAAS,EACT,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,GAAG,EACH,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,aAAa,EACb,QAAQ,EACR,uBAAuB,EACvB,aAAa,EACb,yBAAyB,EACzB,IAAI,EACJ,WAAW,EACX,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACH,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,eAAe,GACvB,MAAM,aAAa,CAAC"}
|
package/dist/persistence.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DbAdapter } from '@gobing-ai/ts-db';
|
|
2
|
-
import type { WorkflowPersistenceAdapter, WorkflowRunRecord, WorkflowStatus } from './types';
|
|
2
|
+
import type { ActionRedactor, WorkflowPersistenceAdapter, WorkflowRunRecord, WorkflowStatus } from './types';
|
|
3
3
|
/** Apply workflow-engine-owned schema to a database adapter. */
|
|
4
4
|
export declare function applyWorkflowEngineSchema(db: DbAdapter): Promise<void>;
|
|
5
5
|
/** SQLite/D1-compatible workflow persistence adapter backed by ts-db. */
|
|
@@ -16,6 +16,10 @@ export declare class DbWorkflowPersistenceAdapter implements WorkflowPersistence
|
|
|
16
16
|
saveTransition(runId: string, from: string, to: string, trigger: string | null): Promise<void>;
|
|
17
17
|
/** Save the latest workflow state snapshot. */
|
|
18
18
|
saveWorkflowState(runId: string, state: string, data: Record<string, unknown>): Promise<void>;
|
|
19
|
+
/** Insert a running action row. Returns the row id for later finalization. */
|
|
20
|
+
saveActionStart(runId: string, node: string, kind: string): Promise<string>;
|
|
21
|
+
/** Finalize an action row with duration, ok flag, and optional redacted result. */
|
|
22
|
+
saveActionFinalize(actionId: string, status: WorkflowStatus, durationMs: number, ok: boolean, result?: unknown, _redactor?: ActionRedactor): Promise<void>;
|
|
19
23
|
/** Load a single run by id. */
|
|
20
24
|
loadRun(runId: string): Promise<WorkflowRunRecord | undefined>;
|
|
21
25
|
/** List persisted workflow runs. */
|
|
@@ -44,6 +48,20 @@ export declare class MemoryWorkflowPersistenceAdapter implements WorkflowPersist
|
|
|
44
48
|
createRun(record: WorkflowRunRecord): Promise<void>;
|
|
45
49
|
/** Finalize a run with terminal status and timestamp. */
|
|
46
50
|
finalizeRun(runId: string, status: WorkflowStatus, completedAt: string): Promise<void>;
|
|
51
|
+
readonly actionRuns: Array<{
|
|
52
|
+
id: string;
|
|
53
|
+
runId: string;
|
|
54
|
+
node: string;
|
|
55
|
+
kind: string;
|
|
56
|
+
status: WorkflowStatus;
|
|
57
|
+
durationMs: number | null;
|
|
58
|
+
ok: number | null;
|
|
59
|
+
resultJson: string | null;
|
|
60
|
+
}>;
|
|
61
|
+
/** Insert a running action row. */
|
|
62
|
+
saveActionStart(runId: string, node: string, kind: string): Promise<string>;
|
|
63
|
+
/** Finalize an action row. */
|
|
64
|
+
saveActionFinalize(actionId: string, status: WorkflowStatus, durationMs: number, ok: boolean, result?: unknown, _redactor?: ActionRedactor): Promise<void>;
|
|
47
65
|
/** Save one phase/state execution record. */
|
|
48
66
|
savePhase(runId: string, phase: string, status: WorkflowStatus): Promise<void>;
|
|
49
67
|
/** Save one transition record. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../src/persistence.ts"],"names":[],"mappings":"AAAA,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