@wooksjs/event-wf 0.6.6 → 0.7.1
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 +7 -65
- package/dist/index.cjs +119 -59
- package/dist/index.d.ts +74 -27
- package/dist/index.mjs +102 -55
- package/package.json +6 -6
- package/skills/wooksjs-event-wf/SKILL.md +7 -7
- package/skills/wooksjs-event-wf/core.md +133 -67
- package/skills/wooksjs-event-wf/event-core.md +251 -374
- package/skills/wooksjs-event-wf/workflows.md +39 -48
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# @wooksjs/event-wf
|
|
2
2
|
|
|
3
|
-
**!!! This is work-in-progress library, breaking changes are expected !!!**
|
|
4
|
-
|
|
5
3
|
<p align="center">
|
|
6
4
|
<img src="../../wooks-logo.png" width="450px"><br>
|
|
7
5
|
<a href="https://github.com/wooksjs/wooksjs/blob/main/LICENSE">
|
|
@@ -9,71 +7,17 @@
|
|
|
9
7
|
</a>
|
|
10
8
|
</p>
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
The primary features of `@wooksjs/event-wf` include:
|
|
15
|
-
|
|
16
|
-
- Support for conditional workflow branching based on dynamic conditions.
|
|
17
|
-
- Support for parametric steps and workflows.
|
|
18
|
-
- Support for user input requirements and interaction during the workflows.
|
|
10
|
+
Workflow event processing for the Wooks framework. Manage complex workflows with conditional branching, parametric steps, and user input requirements, built on top of [@prostojs/wf](https://github.com/prostojs/wf).
|
|
19
11
|
|
|
20
12
|
## Installation
|
|
21
13
|
|
|
22
|
-
To install `@wooksjs/event-wf`, you can use npm:
|
|
23
|
-
|
|
24
14
|
```sh
|
|
25
|
-
npm install
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Quick Start
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
import { useRouteParams } from '@wooksjs/event-core'
|
|
32
|
-
import { createWfApp } from '@wooksjs/event-wf'
|
|
33
|
-
|
|
34
|
-
const app = createWfApp<{ result: number }>()
|
|
35
|
-
|
|
36
|
-
app.step('add', {
|
|
37
|
-
input: 'number',
|
|
38
|
-
handler: 'ctx.result += input',
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
app.step('add/:n', {
|
|
42
|
-
handler: (ctx) => {
|
|
43
|
-
ctx.result += Number(useRouteParams().get('n'))
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
app.flow('adding', [
|
|
48
|
-
{ id: 'add', input: 5 },
|
|
49
|
-
{ id: 'add', input: 2 },
|
|
50
|
-
{
|
|
51
|
-
condition: 'result < 10',
|
|
52
|
-
steps: [{ id: 'add', input: 3 }, { id: 'add', input: 4 }],
|
|
53
|
-
},
|
|
54
|
-
])
|
|
55
|
-
|
|
56
|
-
app.flow('adding-parametric', [
|
|
57
|
-
'add/5',
|
|
58
|
-
'add/2',
|
|
59
|
-
{
|
|
60
|
-
condition: 'result < 10',
|
|
61
|
-
steps: ['add/3', 'add/4'],
|
|
62
|
-
},
|
|
63
|
-
])
|
|
64
|
-
|
|
65
|
-
// Run the 'adding' workflow
|
|
66
|
-
const output = await app.start('adding', { result: 0 })
|
|
67
|
-
console.log(output.state.context) // { result: 14 }
|
|
15
|
+
npm install @wooksjs/event-wf
|
|
68
16
|
```
|
|
69
17
|
|
|
70
18
|
## Documentation
|
|
71
19
|
|
|
72
|
-
For
|
|
73
|
-
|
|
74
|
-
## Contributing
|
|
75
|
-
|
|
76
|
-
Contributions to the `@wooksjs/event-wf` project are welcome. If you find any bugs or have a feature request, please open an issue on [the GitHub repository](https://github.com/wooksjs/wooksjs).
|
|
20
|
+
For full documentation, visit [wooks.moost.org/wf](https://wooks.moost.org/wf/).
|
|
77
21
|
|
|
78
22
|
## AI Agent Skills
|
|
79
23
|
|
|
@@ -81,10 +25,10 @@ This package ships with structured skill files for AI coding agents (Claude Code
|
|
|
81
25
|
|
|
82
26
|
```bash
|
|
83
27
|
# Project-local (recommended — version-locked, commits with your repo)
|
|
84
|
-
npx
|
|
28
|
+
npx wooksjs-event-wf-skill
|
|
85
29
|
|
|
86
30
|
# Global (available across all your projects)
|
|
87
|
-
npx
|
|
31
|
+
npx wooksjs-event-wf-skill --global
|
|
88
32
|
```
|
|
89
33
|
|
|
90
34
|
To keep skills automatically up-to-date, add a postinstall script to your `package.json`:
|
|
@@ -92,13 +36,11 @@ To keep skills automatically up-to-date, add a postinstall script to your `packa
|
|
|
92
36
|
```json
|
|
93
37
|
{
|
|
94
38
|
"scripts": {
|
|
95
|
-
"postinstall": "
|
|
39
|
+
"postinstall": "wooksjs-event-wf-skill --postinstall"
|
|
96
40
|
}
|
|
97
41
|
}
|
|
98
42
|
```
|
|
99
43
|
|
|
100
|
-
This ensures the skill files are refreshed whenever dependencies are installed, without needing a separate command.
|
|
101
|
-
|
|
102
44
|
## License
|
|
103
45
|
|
|
104
|
-
|
|
46
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -6,11 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key$1; i < n; i++) {
|
|
10
|
+
key$1 = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key$1) && key$1 !== except) __defProp(to, key$1, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key$1),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key$1)) || desc.enumerable
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
@@ -25,37 +25,15 @@ const __wooksjs_event_core = __toESM(require("@wooksjs/event-core"));
|
|
|
25
25
|
const __prostojs_wf = __toESM(require("@prostojs/wf"));
|
|
26
26
|
const wooks = __toESM(require("wooks"));
|
|
27
27
|
|
|
28
|
-
//#region packages/event-wf/src/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
options
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/** Creates an async event context for resuming a paused workflow. */
|
|
41
|
-
function resumeWfContext(data, options) {
|
|
42
|
-
return (0, __wooksjs_event_core.createAsyncEventContext)({
|
|
43
|
-
event: {
|
|
44
|
-
...data,
|
|
45
|
-
type: "WF"
|
|
46
|
-
},
|
|
47
|
-
resume: true,
|
|
48
|
-
options
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Wrapper on top of useEventContext that provides
|
|
53
|
-
* proper context types for WF event
|
|
54
|
-
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
55
|
-
*/
|
|
56
|
-
function useWFContext() {
|
|
57
|
-
return (0, __wooksjs_event_core.useAsyncEventContext)("WF");
|
|
58
|
-
}
|
|
28
|
+
//#region packages/event-wf/src/wf-kind.ts
|
|
29
|
+
const wfKind = (0, __wooksjs_event_core.defineEventKind)("WF", {
|
|
30
|
+
schemaId: (0, __wooksjs_event_core.slot)(),
|
|
31
|
+
stepId: (0, __wooksjs_event_core.slot)(),
|
|
32
|
+
inputContext: (0, __wooksjs_event_core.slot)(),
|
|
33
|
+
indexes: (0, __wooksjs_event_core.slot)(),
|
|
34
|
+
input: (0, __wooksjs_event_core.slot)()
|
|
35
|
+
});
|
|
36
|
+
const resumeKey = (0, __wooksjs_event_core.key)("wf.resume");
|
|
59
37
|
|
|
60
38
|
//#endregion
|
|
61
39
|
//#region packages/event-wf/src/composables/wf-state.ts
|
|
@@ -69,18 +47,58 @@ function useWFContext() {
|
|
|
69
47
|
* ```
|
|
70
48
|
*/
|
|
71
49
|
function useWfState() {
|
|
72
|
-
const
|
|
73
|
-
const event = store("event");
|
|
50
|
+
const c = (0, __wooksjs_event_core.current)();
|
|
74
51
|
return {
|
|
75
|
-
ctx: () =>
|
|
76
|
-
input: () =>
|
|
77
|
-
schemaId:
|
|
78
|
-
stepId: () =>
|
|
79
|
-
indexes: () =>
|
|
80
|
-
resume:
|
|
52
|
+
ctx: () => c.get(wfKind.keys.inputContext),
|
|
53
|
+
input: () => c.get(wfKind.keys.input),
|
|
54
|
+
schemaId: c.get(wfKind.keys.schemaId),
|
|
55
|
+
stepId: () => c.get(wfKind.keys.stepId),
|
|
56
|
+
indexes: () => c.get(wfKind.keys.indexes),
|
|
57
|
+
resume: c.get(resumeKey)
|
|
81
58
|
};
|
|
82
59
|
}
|
|
83
60
|
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region packages/event-wf/src/event-wf.ts
|
|
63
|
+
const wfSeeds = (data) => ({
|
|
64
|
+
schemaId: data.schemaId,
|
|
65
|
+
stepId: data.stepId,
|
|
66
|
+
inputContext: data.inputContext,
|
|
67
|
+
indexes: data.indexes,
|
|
68
|
+
input: data.input
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new event context for a fresh workflow execution.
|
|
72
|
+
* When `parentCtx` is provided, the workflow creates a child context
|
|
73
|
+
* linked to the parent, so step handlers can transparently access
|
|
74
|
+
* composables from the parent scope (e.g. HTTP) via the parent chain.
|
|
75
|
+
*/
|
|
76
|
+
function createWfContext(data, options, parentCtx) {
|
|
77
|
+
const ctx = new __wooksjs_event_core.EventContext(parentCtx ? {
|
|
78
|
+
...options,
|
|
79
|
+
parent: parentCtx
|
|
80
|
+
} : options);
|
|
81
|
+
return (fn) => (0, __wooksjs_event_core.run)(ctx, () => {
|
|
82
|
+
ctx.set(resumeKey, false);
|
|
83
|
+
return ctx.seed(wfKind, wfSeeds(data), fn);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates an event context for resuming a paused workflow.
|
|
88
|
+
* When `parentCtx` is provided, the workflow creates a child context
|
|
89
|
+
* linked to the parent.
|
|
90
|
+
*/
|
|
91
|
+
function resumeWfContext(data, options, parentCtx) {
|
|
92
|
+
const ctx = new __wooksjs_event_core.EventContext(parentCtx ? {
|
|
93
|
+
...options,
|
|
94
|
+
parent: parentCtx
|
|
95
|
+
} : options);
|
|
96
|
+
return (fn) => (0, __wooksjs_event_core.run)(ctx, () => {
|
|
97
|
+
ctx.set(resumeKey, true);
|
|
98
|
+
return ctx.seed(wfKind, wfSeeds(data), fn);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
//#endregion
|
|
85
103
|
//#region packages/event-wf/src/workflow.ts
|
|
86
104
|
/** Workflow engine that resolves steps via Wooks router lookup. */
|
|
@@ -92,10 +110,10 @@ var WooksWorkflow = class extends __prostojs_wf.Workflow {
|
|
|
92
110
|
resolveStep(stepId) {
|
|
93
111
|
const stepIdNorm = `/${stepId}`.replace(/\/{2,}/gu, "/");
|
|
94
112
|
try {
|
|
95
|
-
const
|
|
113
|
+
const ctx = (0, __wooksjs_event_core.current)();
|
|
96
114
|
const found = this.wooks.lookup("WF_STEP", stepIdNorm);
|
|
97
115
|
if (found.handlers?.length) {
|
|
98
|
-
|
|
116
|
+
ctx.set(wfKind.keys.stepId, stepIdNorm);
|
|
99
117
|
return found.handlers[0]();
|
|
100
118
|
}
|
|
101
119
|
} catch {
|
|
@@ -145,15 +163,40 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
145
163
|
id
|
|
146
164
|
}));
|
|
147
165
|
}
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Starts a new workflow execution from the beginning.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* // Simple
|
|
172
|
+
* await app.start('my-flow', { result: 0 })
|
|
173
|
+
*
|
|
174
|
+
* // With options
|
|
175
|
+
* await app.start('my-flow', { result: 0 }, { input: 5, eventContext: current() })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
start(schemaId, inputContext, opts) {
|
|
179
|
+
const parentCtx = opts?.eventContext;
|
|
180
|
+
return this._start(schemaId, inputContext, void 0, opts, parentCtx);
|
|
151
181
|
}
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Resumes a previously paused workflow from saved state.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* // With user input
|
|
188
|
+
* await app.resume(output.state, { input: userInput })
|
|
189
|
+
*
|
|
190
|
+
* // Simple retry (no input)
|
|
191
|
+
* await app.resume(output.state)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
resume(state, opts) {
|
|
195
|
+
const parentCtx = opts?.eventContext;
|
|
196
|
+
return this._start(state.schemaId, state.context, state.indexes, opts, parentCtx);
|
|
155
197
|
}
|
|
156
|
-
async _start(schemaId, inputContext, indexes,
|
|
198
|
+
async _start(schemaId, inputContext, indexes, opts, parentCtx) {
|
|
199
|
+
const { input, spy, cleanup } = opts ?? {};
|
|
157
200
|
const resume = !!indexes?.length;
|
|
158
201
|
const runInContext = (resume ? resumeWfContext : createWfContext)({
|
|
159
202
|
inputContext,
|
|
@@ -161,7 +204,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
161
204
|
stepId: null,
|
|
162
205
|
indexes,
|
|
163
206
|
input
|
|
164
|
-
}, this.
|
|
207
|
+
}, this.getEventContextOptions(), parentCtx);
|
|
165
208
|
return runInContext(async () => {
|
|
166
209
|
const { handlers: foundHandlers } = this.wooks.lookup("WF_FLOW", `/${schemaId}`.replace(/^\/+/u, "/"));
|
|
167
210
|
const handlers = foundHandlers || this.opts?.onNotFound && [this.opts.onNotFound] || null;
|
|
@@ -172,8 +215,8 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
172
215
|
if (spy) spy(...args);
|
|
173
216
|
if (firstStep && args[0] === "step") {
|
|
174
217
|
firstStep = false;
|
|
175
|
-
const
|
|
176
|
-
|
|
218
|
+
const ctx = (0, __wooksjs_event_core.current)();
|
|
219
|
+
ctx.set(wfKind.keys.input, void 0);
|
|
177
220
|
}
|
|
178
221
|
};
|
|
179
222
|
try {
|
|
@@ -197,7 +240,11 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
197
240
|
throw error;
|
|
198
241
|
}
|
|
199
242
|
clean();
|
|
200
|
-
if (result.resume) result.resume = (_input) => this.resume(result.state,
|
|
243
|
+
if (result.resume) result.resume = (_input) => this.resume(result.state, {
|
|
244
|
+
input: _input,
|
|
245
|
+
spy,
|
|
246
|
+
cleanup
|
|
247
|
+
});
|
|
201
248
|
return result;
|
|
202
249
|
}
|
|
203
250
|
clean();
|
|
@@ -228,7 +275,7 @@ var WooksWf = class extends wooks.WooksAdapterBase {
|
|
|
228
275
|
* ```ts
|
|
229
276
|
* const app = createWfApp()
|
|
230
277
|
* app.step('process', { handler: (ctx) => ctx })
|
|
231
|
-
* app.flow('my-flow', [
|
|
278
|
+
* app.flow('my-flow', ['process'])
|
|
232
279
|
* await app.start('my-flow', { data: 'hello' })
|
|
233
280
|
* ```
|
|
234
281
|
*/
|
|
@@ -246,7 +293,20 @@ Object.defineProperty(exports, 'StepRetriableError', {
|
|
|
246
293
|
exports.WooksWf = WooksWf;
|
|
247
294
|
exports.createWfApp = createWfApp;
|
|
248
295
|
exports.createWfContext = createWfContext;
|
|
296
|
+
exports.resumeKey = resumeKey;
|
|
249
297
|
exports.resumeWfContext = resumeWfContext;
|
|
250
|
-
exports
|
|
298
|
+
Object.defineProperty(exports, 'useLogger', {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
get: function () {
|
|
301
|
+
return __wooksjs_event_core.useLogger;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
Object.defineProperty(exports, 'useRouteParams', {
|
|
305
|
+
enumerable: true,
|
|
306
|
+
get: function () {
|
|
307
|
+
return __wooksjs_event_core.useRouteParams;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
251
310
|
exports.useWfState = useWfState;
|
|
311
|
+
exports.wfKind = wfKind;
|
|
252
312
|
exports.wfShortcuts = wfShortcuts;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _wooksjs_event_core from '@wooksjs/event-core';
|
|
2
|
-
import {
|
|
2
|
+
import { EventContextOptions, EventContext } from '@wooksjs/event-core';
|
|
3
|
+
export { EventContext, EventContextOptions, useLogger, useRouteParams } from '@wooksjs/event-core';
|
|
3
4
|
import * as wooks from 'wooks';
|
|
4
5
|
import { Wooks, TWooksHandler, TWooksOptions, WooksAdapterBase } from 'wooks';
|
|
5
6
|
import { TConsoleBase } from '@prostojs/logger';
|
|
@@ -18,36 +19,34 @@ export { StepRetriableError, TStepHandler, TWorkflowSchema } from '@prostojs/wf'
|
|
|
18
19
|
declare function useWfState(): {
|
|
19
20
|
ctx: <T>() => T;
|
|
20
21
|
input: <I>() => I | undefined;
|
|
21
|
-
schemaId: string
|
|
22
|
-
stepId: () => string | null
|
|
22
|
+
schemaId: string;
|
|
23
|
+
stepId: () => string | null;
|
|
23
24
|
indexes: () => number[] | undefined;
|
|
24
25
|
resume: boolean;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
interface
|
|
28
|
+
/** Input data for creating a workflow event context. */
|
|
29
|
+
interface TWFEventInput {
|
|
29
30
|
schemaId: string;
|
|
30
31
|
stepId: string | null;
|
|
31
32
|
inputContext: unknown;
|
|
32
33
|
indexes?: number[];
|
|
33
34
|
input?: unknown;
|
|
34
|
-
type: 'WF';
|
|
35
|
-
}
|
|
36
|
-
/** Context store for workflow events, tracking resume state. */
|
|
37
|
-
interface TWFContextStore {
|
|
38
|
-
resume: boolean;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
/** Creates a new async event context for a fresh workflow execution. */
|
|
42
|
-
declare function createWfContext(data: Omit<TWFEventData, 'type'>, options: TEventOptions): <T>(cb: (...a: unknown[]) => T) => T;
|
|
43
|
-
/** Creates an async event context for resuming a paused workflow. */
|
|
44
|
-
declare function resumeWfContext(data: Omit<TWFEventData, 'type'>, options: TEventOptions): <T>(cb: (...a: unknown[]) => T) => T;
|
|
45
37
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
38
|
+
* Creates a new event context for a fresh workflow execution.
|
|
39
|
+
* When `parentCtx` is provided, the workflow creates a child context
|
|
40
|
+
* linked to the parent, so step handlers can transparently access
|
|
41
|
+
* composables from the parent scope (e.g. HTTP) via the parent chain.
|
|
49
42
|
*/
|
|
50
|
-
declare function
|
|
43
|
+
declare function createWfContext(data: TWFEventInput, options: EventContextOptions, parentCtx?: EventContext): <R>(fn: () => R) => R;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an event context for resuming a paused workflow.
|
|
46
|
+
* When `parentCtx` is provided, the workflow creates a child context
|
|
47
|
+
* linked to the parent.
|
|
48
|
+
*/
|
|
49
|
+
declare function resumeWfContext(data: TWFEventInput, options: EventContextOptions, parentCtx?: EventContext): <R>(fn: () => R) => R;
|
|
51
50
|
|
|
52
51
|
/** Workflow engine that resolves steps via Wooks router lookup. */
|
|
53
52
|
declare class WooksWorkflow<T, IR> extends Workflow<T, IR> {
|
|
@@ -67,9 +66,26 @@ interface TWooksWfOptions {
|
|
|
67
66
|
onNotFound?: TWooksHandler;
|
|
68
67
|
onUnknownFlow?: (schemaId: string, raiseError: () => void) => unknown;
|
|
69
68
|
logger?: TConsoleBase;
|
|
70
|
-
eventOptions?:
|
|
69
|
+
eventOptions?: EventContextOptions;
|
|
71
70
|
router?: TWooksOptions['router'];
|
|
72
71
|
}
|
|
72
|
+
/** Options for {@link WooksWf.start} and {@link WooksWf.resume}. */
|
|
73
|
+
interface TWfRunOptions<I = unknown, T = unknown, IR = unknown> {
|
|
74
|
+
/** Input for the current step (consumed after execution). */
|
|
75
|
+
input?: I;
|
|
76
|
+
/** Spy function to observe step execution. */
|
|
77
|
+
spy?: TWorkflowSpy<T, I, IR>;
|
|
78
|
+
/** Cleanup function called when execution ends. */
|
|
79
|
+
cleanup?: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Parent event context. When provided, the workflow creates a child context
|
|
82
|
+
* linked to this parent, so step handlers can transparently read composables
|
|
83
|
+
* from the parent scope (e.g. HTTP composables) via the parent chain.
|
|
84
|
+
*
|
|
85
|
+
* Pass `current()` from within an active event scope (HTTP handler, etc.).
|
|
86
|
+
*/
|
|
87
|
+
eventContext?: EventContext;
|
|
88
|
+
}
|
|
73
89
|
/** Wooks adapter for defining and executing workflow schemas with step-based routing. */
|
|
74
90
|
declare class WooksWf<T = any, IR = any> extends WooksAdapterBase {
|
|
75
91
|
protected opts?: TWooksWfOptions | undefined;
|
|
@@ -87,15 +103,37 @@ declare class WooksWf<T = any, IR = any> extends WooksAdapterBase {
|
|
|
87
103
|
}): wooks.TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
88
104
|
/** Registers a workflow flow schema with the given id. */
|
|
89
105
|
flow(id: string, schema: TWorkflowSchema<T>, prefix?: string, init?: () => void | Promise<void>): wooks.TProstoRouterPathHandle<Record<string, string | string[]>>;
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Starts a new workflow execution from the beginning.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // Simple
|
|
112
|
+
* await app.start('my-flow', { result: 0 })
|
|
113
|
+
*
|
|
114
|
+
* // With options
|
|
115
|
+
* await app.start('my-flow', { result: 0 }, { input: 5, eventContext: current() })
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
start<I>(schemaId: string, inputContext: T, opts?: TWfRunOptions<I, T, IR>): Promise<TFlowOutput<T, I, IR>>;
|
|
119
|
+
/**
|
|
120
|
+
* Resumes a previously paused workflow from saved state.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* // With user input
|
|
125
|
+
* await app.resume(output.state, { input: userInput })
|
|
126
|
+
*
|
|
127
|
+
* // Simple retry (no input)
|
|
128
|
+
* await app.resume(output.state)
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
93
131
|
resume<I>(state: {
|
|
94
132
|
schemaId: string;
|
|
95
133
|
indexes: number[];
|
|
96
134
|
context: T;
|
|
97
|
-
},
|
|
98
|
-
protected _start<I>(schemaId: string, inputContext: T, indexes?: number[],
|
|
135
|
+
}, opts?: TWfRunOptions<I, T, IR>): Promise<TFlowOutput<T, I, IR>>;
|
|
136
|
+
protected _start<I>(schemaId: string, inputContext: T, indexes?: number[], opts?: TWfRunOptions<I, T, IR>, parentCtx?: EventContext): Promise<TFlowOutput<T, I, IR>>;
|
|
99
137
|
protected onError(e: Error): void;
|
|
100
138
|
protected error(e: string | Error): void;
|
|
101
139
|
}
|
|
@@ -108,11 +146,20 @@ declare class WooksWf<T = any, IR = any> extends WooksAdapterBase {
|
|
|
108
146
|
* ```ts
|
|
109
147
|
* const app = createWfApp()
|
|
110
148
|
* app.step('process', { handler: (ctx) => ctx })
|
|
111
|
-
* app.flow('my-flow', [
|
|
149
|
+
* app.flow('my-flow', ['process'])
|
|
112
150
|
* await app.start('my-flow', { data: 'hello' })
|
|
113
151
|
* ```
|
|
114
152
|
*/
|
|
115
153
|
declare function createWfApp<T>(opts?: TWooksWfOptions, wooks?: Wooks | WooksAdapterBase): WooksWf<T, any>;
|
|
116
154
|
|
|
117
|
-
|
|
118
|
-
|
|
155
|
+
declare const wfKind: _wooksjs_event_core.EventKind<{
|
|
156
|
+
schemaId: _wooksjs_event_core.SlotMarker<string>;
|
|
157
|
+
stepId: _wooksjs_event_core.SlotMarker<string | null>;
|
|
158
|
+
inputContext: _wooksjs_event_core.SlotMarker<unknown>;
|
|
159
|
+
indexes: _wooksjs_event_core.SlotMarker<number[] | undefined>;
|
|
160
|
+
input: _wooksjs_event_core.SlotMarker<unknown>;
|
|
161
|
+
}>;
|
|
162
|
+
declare const resumeKey: _wooksjs_event_core.Key<boolean>;
|
|
163
|
+
|
|
164
|
+
export { WooksWf, createWfApp, createWfContext, resumeKey, resumeWfContext, useWfState, wfKind, wfShortcuts };
|
|
165
|
+
export type { TWFEventInput, TWfRunOptions, TWooksWfOptions };
|