@gobing-ai/ts-dual-workflow-engine 0.5.16 → 0.5.18
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 +43 -0
- package/dist/config.js +1 -1
- package/dist/dag.d.ts +30 -1
- package/dist/dag.d.ts.map +1 -1
- package/dist/dag.js +390 -116
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/persistence.d.ts +16 -6
- package/dist/persistence.d.ts.map +1 -1
- package/dist/persistence.js +84 -18
- package/dist/run-lifecycle.d.ts +2 -0
- package/dist/run-lifecycle.d.ts.map +1 -1
- package/dist/run-lifecycle.js +4 -0
- package/dist/schema.d.ts +32 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +15 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +33 -7
- package/dist/transition-flow.d.ts.map +1 -1
- package/dist/transition-flow.js +111 -40
- package/dist/types.d.ts +24 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/schemas/state-machine-workflow.schema.json +12 -0
- package/src/config.ts +1 -1
- package/src/dag.ts +443 -138
- package/src/index.ts +2 -0
- package/src/persistence.ts +119 -15
- package/src/run-lifecycle.ts +5 -0
- package/src/schema.ts +16 -0
- package/src/service.ts +31 -7
- package/src/transition-flow.ts +147 -36
- package/src/types.ts +29 -1
package/README.md
CHANGED
|
@@ -164,6 +164,24 @@ erDiagram
|
|
|
164
164
|
| `transition-flow` | `TransitionFlowDriver` | Single-cursor node/edge walk; declared fork/join regions run branches concurrently |
|
|
165
165
|
| `dag` | `DagDriver` | Nodes dispatch as their `dependsOn` prerequisites settle; acyclic only (ADR-034) |
|
|
166
166
|
|
|
167
|
+
Structured parallel nodes declare `branches` and a `join` target. Branches keep isolated variable
|
|
168
|
+
deltas; paused branches resume from their saved node without replaying completed siblings. With
|
|
169
|
+
`failurePolicy: 'collect'`, the join action runs with merged outputs before aggregate failure is
|
|
170
|
+
recorded; `fail-fast` cancels active siblings. Branch checkpoints and join commits use the run's
|
|
171
|
+
owner-attempt fence. `saveBranchFinalize` accepts an optional checkpoint with `parallelNode`, `node`,
|
|
172
|
+
and `ownerAttempt`; `commitJoin` accepts optional owner-attempt, transition-count and collected-failure
|
|
173
|
+
arguments. Collected failure is preserved across restart at the join.
|
|
174
|
+
|
|
175
|
+
DAG nodes publish completion and string variable deltas only after their action audit and terminal
|
|
176
|
+
ledger write settle. Recovery uses the `__dag__` ledger: completed actions stay completed, and
|
|
177
|
+
`transitionsTaken` counts distinct done/paused nodes without counting acknowledgements or replays twice.
|
|
178
|
+
Recovered variables merge in this order: workflow defaults, snapshot baseline, completed-node deltas
|
|
179
|
+
in stable topological order (declaration order breaks ties), then caller overrides. Live sibling
|
|
180
|
+
collisions follow durable completion order. A pause action completes before acknowledgement;
|
|
181
|
+
`skip-enter` acknowledges it once, while `rerun-enter` requires that node's `resumeRerun: true` marker.
|
|
182
|
+
Every previously unfinished action needs its own marker for replay. Recovery is at least once for
|
|
183
|
+
action effects not yet durably recorded; stop or reconcile the previous owner before resuming.
|
|
184
|
+
|
|
167
185
|
All three delegate run identity, persistence sequencing, and observability to `RunLifecycle`:
|
|
168
186
|
|
|
169
187
|
```
|
|
@@ -618,6 +636,31 @@ caller override flag, because a mid-graph start on a state that assumed earlier
|
|
|
618
636
|
rather than silently skip them. Resume semantics (`skip-enter` / `rerun-enter`, `resumeRerun`) are a
|
|
619
637
|
separate, unchanged path. See ADR-035.
|
|
620
638
|
|
|
639
|
+
## State Display Metadata
|
|
640
|
+
|
|
641
|
+
A state-machine state may declare presentation-only `display` metadata for plan/UI generators that read
|
|
642
|
+
the workflow definition. The engine accepts and preserves it but never reads it at run time — a
|
|
643
|
+
workflow with and without `display` runs identically.
|
|
644
|
+
|
|
645
|
+
```yaml
|
|
646
|
+
states:
|
|
647
|
+
- id: fetch
|
|
648
|
+
display:
|
|
649
|
+
phase: fetch # required: the phase group this state belongs to
|
|
650
|
+
phaseTitle: Fetch # optional: human title of the phase group
|
|
651
|
+
title: Pull sources # optional: human title of the state in plan/UI views
|
|
652
|
+
show: plan # optional: 'plan' (default) or 'on-entry'
|
|
653
|
+
onEnter:
|
|
654
|
+
- kind: note
|
|
655
|
+
options: { message: fetching }
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
`display` is validated, not interpreted: `phase` is required and non-empty, the other keys are optional,
|
|
659
|
+
unknown sub-keys are rejected (the schema is strict), and `show` accepts only `'plan'` or `'on-entry'`.
|
|
660
|
+
Malformed metadata fails `loadWorkflowDef` / `loadWorkflowDefFromText` with a `WorkflowValidationError`
|
|
661
|
+
naming the state's `display` field. The default for absent `show` is `plan`, interpreted by consumers —
|
|
662
|
+
never by this engine. See ADR-036.
|
|
663
|
+
|
|
621
664
|
## Variables and Environment
|
|
622
665
|
|
|
623
666
|
Actions receive resolved template values. The engine supports:
|
package/dist/config.js
CHANGED
|
@@ -206,7 +206,7 @@ function validateTransitionFlow(workflow) {
|
|
|
206
206
|
if (visited.has(currentId))
|
|
207
207
|
return;
|
|
208
208
|
const currentNode = nodeMap.get(currentId);
|
|
209
|
-
if (currentNode && currentNode.
|
|
209
|
+
if (currentNode && currentNode.type === 'parallel') {
|
|
210
210
|
errors.push(`Parallel node "${currentNode.id}" is nested inside parallel node "${node.id}" (nested parallel regions are forbidden)`);
|
|
211
211
|
}
|
|
212
212
|
visiting.add(currentId);
|
package/dist/dag.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WorkflowEngineHost } from './host';
|
|
2
|
-
import type { DagWorkflowDef, WorkflowPersistenceAdapter, WorkflowRunOptions, WorkflowRunResult } from './types';
|
|
2
|
+
import type { DagNodeDef, DagWorkflowDef, WorkflowBranchRecord, WorkflowPersistenceAdapter, WorkflowResumeMode, WorkflowRunOptions, WorkflowRunResult } from './types';
|
|
3
3
|
/** Dependencies required by the static dependency DAG driver. */
|
|
4
4
|
export interface DagDriverOptions {
|
|
5
5
|
readonly host: WorkflowEngineHost;
|
|
@@ -7,6 +7,35 @@ export interface DagDriverOptions {
|
|
|
7
7
|
}
|
|
8
8
|
/** Execution status of a single DAG node within a run. */
|
|
9
9
|
export type DagNodeStatus = 'pending' | 'ready' | 'running' | 'done' | 'failed' | 'skipped' | 'paused';
|
|
10
|
+
/**
|
|
11
|
+
* Stable topological order over declared nodes: repeatedly take the earliest
|
|
12
|
+
* declared node whose dependencies are all placed (declaration order breaks
|
|
13
|
+
* ties between equally ready nodes). Leftover nodes (validated-elsewhere
|
|
14
|
+
* cycles) keep declaration order. Task 0104 Design 4.
|
|
15
|
+
*/
|
|
16
|
+
export declare function dagTopoOrder(nodes: readonly DagNodeDef[]): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Ledger-derived resume anchor for runs without a snapshot (task 0104 Design 1):
|
|
19
|
+
* the first paused row in declaration order, otherwise the first unfinished
|
|
20
|
+
* declared row, otherwise the first declared node.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deriveDagResumeAnchor(nodes: readonly DagNodeDef[], statusByNode: ReadonlyMap<string, WorkflowBranchRecord['status']>): string | undefined;
|
|
23
|
+
/** Result of DAG resume admission checks (task 0104 Design 6). */
|
|
24
|
+
export interface DagResumeAdmission {
|
|
25
|
+
/** Declared node naming where the resumed run logically continues from. */
|
|
26
|
+
readonly anchor: string;
|
|
27
|
+
/** Paused node whose acknowledgement this resume performs, if any. */
|
|
28
|
+
readonly pausedTarget?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* DAG-only resume admission (task 0104 Design 6). Checks every previously
|
|
32
|
+
* unfinished (running/pending) action node: it may replay only under
|
|
33
|
+
* rerun-enter with its own resumeRerun marker — never-started nodes need no
|
|
34
|
+
* marker, done non-paused rows never replay. A paused anchor replays under
|
|
35
|
+
* rerun-enter only with its marker; skip-enter is always safe (acknowledgement).
|
|
36
|
+
* Exported for service.ts admission only — not part of the public package surface.
|
|
37
|
+
*/
|
|
38
|
+
export declare function assertDagResumeAllowed(workflow: DagWorkflowDef, runId: string, persistence: WorkflowPersistenceAdapter, resumeMode: WorkflowResumeMode): Promise<DagResumeAdmission>;
|
|
10
39
|
/**
|
|
11
40
|
* Static dependency DAG workflow driver (task 0100, ADR-034).
|
|
12
41
|
* Manages an in-process ready queue of runnable nodes, dispatching them as upstream
|
package/dist/dag.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dag.d.ts","sourceRoot":"","sources":["../src/dag.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dag.d.ts","sourceRoot":"","sources":["../src/dag.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EACR,UAAU,EACV,cAAc,EAEd,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACpB,MAAM,SAAS,CAAC;AAGjB,iEAAiE;AACjE,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,0BAA0B,CAAC;CACpD;AAED,0DAA0D;AAC1D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAKvG;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,EAAE,CAenE;AAoCD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACjC,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC,GAClE,MAAM,GAAG,SAAS,CASpB;AAED,kEAAkE;AAClE,MAAM,WAAW,kBAAkB;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CACxC,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,0BAA0B,EACvC,UAAU,EAAE,kBAAkB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA0C7B;AAED;;;;;GAKG;AACH,qBAAa,SAAS;IACN,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,gBAAgB;IAEtD,2DAA2D;IACrD,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAUjG,wCAAwC;IAClC,MAAM,CACR,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,GAAE,kBAAuB,GACjC,OAAO,CAAC,iBAAiB,CAAC;YAmBf,IAAI;CAmYrB"}
|