@pogodisco/zephyr 1.3.12 → 1.3.13
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/dist/session.d.ts +11 -16
- package/dist/session.js +9 -33
- package/dist/types.d.ts +0 -2
- package/dist/utils.d.ts +0 -18
- package/dist/utils.js +18 -18
- package/dist/workflow-composer.d.ts +3 -6
- package/dist/workflow-composer.js +12 -60
- package/dist/workflow-executor.d.ts +1 -1
- package/dist/workflow-executor.js +1 -2
- package/dist/workflow-module.d.ts +36 -12
- package/dist/workflow-module.js +28 -23
- package/package.json +1 -1
package/dist/session.d.ts
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import { ActionRegistry, WorkflowObserver } from "./types.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare class WorkflowSession<Reg extends ActionRegistry, Ctx> {
|
|
3
|
+
runtime: {
|
|
4
|
+
run: any;
|
|
5
|
+
getContext: () => Ctx;
|
|
6
|
+
};
|
|
6
7
|
private subscribers;
|
|
7
8
|
private running;
|
|
8
9
|
private queue;
|
|
9
|
-
state: State;
|
|
10
10
|
observers: WorkflowObserver[];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
constructor(baseModule: ModuleFlows<Reg>, registry: Reg, initialContext: State, observers: WorkflowObserver[]);
|
|
18
|
-
getState(): State;
|
|
19
|
-
subscribe(fn: (state: Partial<State>) => void): () => boolean;
|
|
11
|
+
constructor(runtime: {
|
|
12
|
+
run: any;
|
|
13
|
+
getContext: () => Ctx;
|
|
14
|
+
});
|
|
15
|
+
subscribe(fn: (state: Partial<Ctx>) => void): () => boolean;
|
|
20
16
|
private notify;
|
|
21
17
|
/** Queue a workflow execution by key and input; state/context is automatically updated */
|
|
22
|
-
dispatch(
|
|
18
|
+
dispatch(workflow: any, input: any): void;
|
|
23
19
|
private processQueue;
|
|
24
20
|
}
|
|
25
|
-
export {};
|
package/dist/session.js
CHANGED
|
@@ -1,56 +1,32 @@
|
|
|
1
|
-
import { executeWorkflow } from "./workflow-executor.js";
|
|
2
|
-
import { createModule } from "./workflow-module.js";
|
|
3
1
|
export class WorkflowSession {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param registry Action registry
|
|
7
|
-
* @param initialContext Initial context (session state) — will be mutated in workflows
|
|
8
|
-
*/
|
|
9
|
-
constructor(baseModule, registry, initialContext, observers) {
|
|
10
|
-
this.registry = registry;
|
|
2
|
+
constructor(runtime) {
|
|
3
|
+
this.runtime = runtime;
|
|
11
4
|
this.subscribers = new Set();
|
|
12
5
|
this.running = false;
|
|
13
6
|
this.queue = [];
|
|
7
|
+
// public state: State; // session state & workflow context are the same object
|
|
14
8
|
this.observers = [];
|
|
15
|
-
// Use the same object for session state and module context
|
|
16
|
-
this.state = initialContext;
|
|
17
|
-
this.observers = observers;
|
|
18
|
-
// Per-session module: inherits workflows, shares the same state/context object
|
|
19
|
-
this.moduleFlows = createModule({
|
|
20
|
-
registry: this.registry,
|
|
21
|
-
context: this.state,
|
|
22
|
-
use: [baseModule],
|
|
23
|
-
define: () => ({}), // no new flows needed
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
getState() {
|
|
27
|
-
return this.state;
|
|
28
9
|
}
|
|
29
10
|
subscribe(fn) {
|
|
30
11
|
this.subscribers.add(fn);
|
|
31
|
-
fn(this.
|
|
12
|
+
fn(this.runtime.getContext()); // immediately notify
|
|
32
13
|
return () => this.subscribers.delete(fn);
|
|
33
14
|
}
|
|
34
15
|
notify() {
|
|
35
16
|
for (const fn of this.subscribers)
|
|
36
|
-
fn(this.
|
|
17
|
+
fn(this.runtime.getContext());
|
|
37
18
|
}
|
|
38
19
|
/** Queue a workflow execution by key and input; state/context is automatically updated */
|
|
39
|
-
dispatch(
|
|
40
|
-
this.queue.push({
|
|
20
|
+
dispatch(workflow, input) {
|
|
21
|
+
this.queue.push({ workflow, input });
|
|
41
22
|
if (!this.running)
|
|
42
23
|
this.processQueue();
|
|
43
24
|
}
|
|
44
25
|
async processQueue() {
|
|
45
26
|
this.running = true;
|
|
46
27
|
while (this.queue.length) {
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
if (!workflow)
|
|
50
|
-
throw new Error(`Workflow ${String(key)} not found`);
|
|
51
|
-
// state/context already lives on the module; no need to pass a separate context
|
|
52
|
-
await executeWorkflow(workflow, this.registry, input, this.observers);
|
|
53
|
-
// Notify subscribers after workflow mutates state
|
|
28
|
+
const { workflow, input } = this.queue.shift();
|
|
29
|
+
await this.runtime.run(workflow, input);
|
|
54
30
|
this.notify();
|
|
55
31
|
}
|
|
56
32
|
this.running = false;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createWorkflow } from "./workflow-composer.js";
|
|
2
1
|
export type Action<F extends (...args: any[]) => any = (...args: any[]) => any> = F;
|
|
3
2
|
export type ActionRegistry = Record<string, (...args: any[]) => any>;
|
|
4
3
|
export type MergeActionRegistries<A extends ActionRegistry, B extends ActionRegistry> = Simplify<Omit<A, keyof B> & B>;
|
|
@@ -27,4 +26,3 @@ export type WorkflowObserver<Reg extends ActionRegistry = any> = {
|
|
|
27
26
|
frame: ExecutionFrame;
|
|
28
27
|
}, next: () => Promise<any>): Promise<any>;
|
|
29
28
|
};
|
|
30
|
-
export type WF<Reg extends ActionRegistry, Context extends Record<string, any>> = ReturnType<typeof createWorkflow<Reg, Context>>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ActionRegistry } from "./types.js";
|
|
2
|
-
import { WorkflowDef } from "./workflow-composer.js";
|
|
3
1
|
type AnyFn = (...args: any[]) => any;
|
|
4
2
|
/**
|
|
5
3
|
* For generic actions - preserves the generic parameter
|
|
@@ -9,20 +7,4 @@ export declare function genericAction<F extends AnyFn>(fn: F): <T>() => ((...arg
|
|
|
9
7
|
* For fixed actions
|
|
10
8
|
*/
|
|
11
9
|
export declare function fixedAction<F extends AnyFn>(fn: F): () => ((...args: Parameters<F>) => ReturnType<F>);
|
|
12
|
-
export declare function createRunner<Reg extends ActionRegistry>(registry: Reg): <W extends WorkflowDef<Reg, any, any, any, any>>(workflow: W, input: W extends WorkflowDef<Reg, infer I, any, any, any> ? I : never, observers?: any[]) => Promise<{
|
|
13
|
-
output: W extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
|
|
14
|
-
results: W extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
|
|
15
|
-
extras: Record<string, any>;
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* Create a typed runner for a specific module
|
|
19
|
-
* @example
|
|
20
|
-
* const run = createModuleRunner(modWithLoop, regOne);
|
|
21
|
-
* const result = await run("loopWorkflow", { items: ["APPLE"] });
|
|
22
|
-
*/
|
|
23
|
-
export declare function createModuleRunner<M extends Record<string, WorkflowDef<any, any, any, any, any>>, Reg extends ActionRegistry>(module: M, registry: Reg): <K extends keyof M>(key: K, input: M[K] extends WorkflowDef<Reg, infer I, any, any, any> ? I : never, observers?: any[]) => Promise<{
|
|
24
|
-
output: M[K] extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
|
|
25
|
-
results: M[K] extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
|
|
26
|
-
extras: Record<string, any>;
|
|
27
|
-
}>;
|
|
28
10
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { executeWorkflow } from "./workflow-executor.js";
|
|
2
1
|
/**
|
|
3
2
|
* For generic actions - preserves the generic parameter
|
|
4
3
|
*/
|
|
@@ -16,20 +15,21 @@ export function fixedAction(fn) {
|
|
|
16
15
|
return fn;
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
export function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
18
|
+
// export function createRuntime<Reg extends ActionRegistry, Context>(
|
|
19
|
+
// registry: Reg,
|
|
20
|
+
// context: Context,
|
|
21
|
+
// ) {
|
|
22
|
+
// return {
|
|
23
|
+
// run: async <W extends WorkflowDef<Reg, any, any, any, any>>(
|
|
24
|
+
// workflow: W,
|
|
25
|
+
// input: W extends WorkflowDef<Reg, infer I, any, any, any> ? I : never,
|
|
26
|
+
// observers?: WorkflowObserver[],
|
|
27
|
+
// ): Promise<{
|
|
28
|
+
// output: W extends WorkflowDef<Reg, any, any, any, infer O> ? O : never;
|
|
29
|
+
// results: W extends WorkflowDef<Reg, any, infer R, any, any> ? R : never;
|
|
30
|
+
// extras: Record<string, any>;
|
|
31
|
+
// }> => {
|
|
32
|
+
// return executeWorkflow(workflow, registry, input, context, observers);
|
|
33
|
+
// },
|
|
34
|
+
// };
|
|
35
|
+
// }
|
|
@@ -58,7 +58,6 @@ export type WorkflowDef<Reg extends ActionRegistry, Input, Results, Steps extend
|
|
|
58
58
|
input: Input;
|
|
59
59
|
results: Results;
|
|
60
60
|
outputResolver?: (ctx: any) => Output;
|
|
61
|
-
__context?: any;
|
|
62
61
|
};
|
|
63
62
|
type StepRuntimeCtx<I, R, C> = {
|
|
64
63
|
input: I;
|
|
@@ -79,16 +78,14 @@ type MergeBranchSteps<Branches extends readonly any[], Acc extends any[]> = Bran
|
|
|
79
78
|
...Acc,
|
|
80
79
|
...(Head extends WorkflowBuilder<any, any, any, infer S, any> ? S : [])
|
|
81
80
|
]> : Acc;
|
|
82
|
-
export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown, Context
|
|
81
|
+
export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown, Context = unknown, Steps extends StepDef<Reg, any, any>[] = [], Results = {}, Output = undefined> {
|
|
83
82
|
private name;
|
|
84
|
-
private registry;
|
|
85
|
-
private context;
|
|
86
83
|
private steps;
|
|
87
84
|
private frontier;
|
|
88
85
|
private pendingWhen?;
|
|
89
86
|
private outputResolver?;
|
|
90
87
|
private clearPendingWhen;
|
|
91
|
-
constructor(name: string
|
|
88
|
+
constructor(name: string);
|
|
92
89
|
step<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
93
90
|
input: Input;
|
|
94
91
|
results: Results;
|
|
@@ -144,5 +141,5 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
144
141
|
private validateDependencies;
|
|
145
142
|
private getEndSteps;
|
|
146
143
|
}
|
|
147
|
-
export declare function createWorkflow<Reg extends ActionRegistry, Context extends Record<string, any> = {}>(
|
|
144
|
+
export declare function createWorkflow<Reg extends ActionRegistry, Context extends Record<string, any> = {}>(): <Input = unknown>(name: string) => WorkflowBuilder<Reg, Input, Context, [], {}, undefined>;
|
|
148
145
|
export {};
|
|
@@ -5,10 +5,8 @@ export class WorkflowBuilder {
|
|
|
5
5
|
clearPendingWhen() {
|
|
6
6
|
this.pendingWhen = undefined;
|
|
7
7
|
}
|
|
8
|
-
constructor(name
|
|
8
|
+
constructor(name) {
|
|
9
9
|
this.name = name;
|
|
10
|
-
this.registry = registry;
|
|
11
|
-
this.context = context;
|
|
12
10
|
this.steps = [];
|
|
13
11
|
this.frontier = [];
|
|
14
12
|
}
|
|
@@ -37,64 +35,11 @@ export class WorkflowBuilder {
|
|
|
37
35
|
as() {
|
|
38
36
|
return this;
|
|
39
37
|
}
|
|
40
|
-
// parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(
|
|
41
|
-
// ...branches: {
|
|
42
|
-
// [K in keyof Branches]: (
|
|
43
|
-
// builder: WorkflowBuilder<Reg, Input, Context, [], Results>,
|
|
44
|
-
// ) => Branches[K];
|
|
45
|
-
// }
|
|
46
|
-
// ): WorkflowBuilder<
|
|
47
|
-
// Reg,
|
|
48
|
-
// Input,
|
|
49
|
-
// Context,
|
|
50
|
-
// [
|
|
51
|
-
// ...Steps,
|
|
52
|
-
// ...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any>
|
|
53
|
-
// ? S
|
|
54
|
-
// : never),
|
|
55
|
-
// ],
|
|
56
|
-
// Simplify<
|
|
57
|
-
// Results &
|
|
58
|
-
// UnionToIntersection<
|
|
59
|
-
// {
|
|
60
|
-
// [K in keyof Branches]: Branches[K] extends WorkflowBuilder<
|
|
61
|
-
// Reg,
|
|
62
|
-
// any,
|
|
63
|
-
// any,
|
|
64
|
-
// any,
|
|
65
|
-
// infer R
|
|
66
|
-
// >
|
|
67
|
-
// ? R
|
|
68
|
-
// : never;
|
|
69
|
-
// }[number]
|
|
70
|
-
// >
|
|
71
|
-
// >
|
|
72
|
-
// > {
|
|
73
|
-
// const parentFrontier = [...this.frontier];
|
|
74
|
-
// const branchEnds: string[] = [];
|
|
75
|
-
//
|
|
76
|
-
// branches.forEach((branch) => {
|
|
77
|
-
// const b = new WorkflowBuilder<Reg, Input, Context, [], Results>(
|
|
78
|
-
// this.name,
|
|
79
|
-
// this.registry,
|
|
80
|
-
// this.context,
|
|
81
|
-
// );
|
|
82
|
-
//
|
|
83
|
-
// b.frontier = parentFrontier;
|
|
84
|
-
// branch(b);
|
|
85
|
-
// branchEnds.push(...b.frontier);
|
|
86
|
-
// this.steps.push(...(b as any).steps);
|
|
87
|
-
// });
|
|
88
|
-
//
|
|
89
|
-
// this.frontier = branchEnds;
|
|
90
|
-
// this.clearPendingWhen();
|
|
91
|
-
// return this as any;
|
|
92
|
-
// }
|
|
93
38
|
parallel(...branches) {
|
|
94
39
|
const parentFrontier = [...this.frontier];
|
|
95
40
|
const branchEnds = [];
|
|
96
41
|
branches.forEach((branch) => {
|
|
97
|
-
const b = new WorkflowBuilder(this.name
|
|
42
|
+
const b = new WorkflowBuilder(this.name);
|
|
98
43
|
b.frontier = parentFrontier;
|
|
99
44
|
branch(b);
|
|
100
45
|
branchEnds.push(...b.frontier);
|
|
@@ -170,7 +115,6 @@ export class WorkflowBuilder {
|
|
|
170
115
|
input: {},
|
|
171
116
|
results: {},
|
|
172
117
|
outputResolver: this.outputResolver,
|
|
173
|
-
__context: this.context,
|
|
174
118
|
};
|
|
175
119
|
}
|
|
176
120
|
validateDependencies() {
|
|
@@ -194,8 +138,16 @@ export class WorkflowBuilder {
|
|
|
194
138
|
/* ------------------------------------------------ */
|
|
195
139
|
/* WORKFLOW CREATOR */
|
|
196
140
|
/* ------------------------------------------------ */
|
|
197
|
-
export function createWorkflow
|
|
141
|
+
// export function createWorkflow<
|
|
142
|
+
// Reg extends ActionRegistry,
|
|
143
|
+
// Context extends Record<string, any> = {},
|
|
144
|
+
// >(registry: Reg, context?: Context) {
|
|
145
|
+
// return function workflow<Input = unknown>(name: string) {
|
|
146
|
+
// return new WorkflowBuilder<Reg, Input, Context>(name);
|
|
147
|
+
// };
|
|
148
|
+
// }
|
|
149
|
+
export function createWorkflow() {
|
|
198
150
|
return function workflow(name) {
|
|
199
|
-
return new WorkflowBuilder(name
|
|
151
|
+
return new WorkflowBuilder(name);
|
|
200
152
|
};
|
|
201
153
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionRegistry, WorkflowObserver } from "./types.js";
|
|
2
2
|
import { StepDef, WorkflowDef } from "./workflow-composer.js";
|
|
3
|
-
export declare function executeWorkflow<Reg extends ActionRegistry, I, R, O = R, Steps extends StepDef<Reg, any, any>[] = StepDef<Reg, any, any>[]>(workflow: WorkflowDef<Reg, I, R, Steps, O>, registry: Reg, input: I, observers?: WorkflowObserver<Reg>[]): Promise<{
|
|
3
|
+
export declare function executeWorkflow<Reg extends ActionRegistry, I, R, O = R, Steps extends StepDef<Reg, any, any>[] = StepDef<Reg, any, any>[]>(workflow: WorkflowDef<Reg, I, R, Steps, O>, registry: Reg, input: I, context: any, observers?: WorkflowObserver<Reg>[]): Promise<{
|
|
4
4
|
results: R;
|
|
5
5
|
output: O;
|
|
6
6
|
extras: Record<string, any>;
|
|
@@ -39,7 +39,7 @@ async function runWithRetry(actionFn, stepOptions) {
|
|
|
39
39
|
}
|
|
40
40
|
throw lastError;
|
|
41
41
|
}
|
|
42
|
-
export async function executeWorkflow(workflow, registry, input, observers = []) {
|
|
42
|
+
export async function executeWorkflow(workflow, registry, input, context, observers = []) {
|
|
43
43
|
const results = {};
|
|
44
44
|
const extras = {};
|
|
45
45
|
extras.frames = {};
|
|
@@ -93,7 +93,6 @@ export async function executeWorkflow(workflow, registry, input, observers = [])
|
|
|
93
93
|
start: Date.now(),
|
|
94
94
|
};
|
|
95
95
|
extras.frames[stepId] = frame;
|
|
96
|
-
const context = workflow.__context;
|
|
97
96
|
const ctx = {
|
|
98
97
|
stepId,
|
|
99
98
|
input,
|
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
import { ActionRegistry,
|
|
1
|
+
import { ActionRegistry, WorkflowObserver } from "./types.js";
|
|
2
2
|
import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
|
|
3
3
|
type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
|
|
4
|
+
type WorkflowFromDeps<Deps extends Record<string, any>> = {
|
|
5
|
+
[K in keyof Deps]: Deps[K] extends Module<any, any, infer Own, infer SubDeps> ? Own[keyof Own] | WorkflowFromDeps<SubDeps> : never;
|
|
6
|
+
}[keyof Deps];
|
|
4
7
|
type ModuleShape = Record<string, AnyWorkflow>;
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
type ContextFromDeps<Deps> = [keyof Deps] extends [never] ? {} : {
|
|
9
|
+
[K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any> ? Ctx : never;
|
|
10
|
+
}[keyof Deps];
|
|
11
|
+
type FinalContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = Context & ContextFromDeps<Deps>;
|
|
12
|
+
type ModuleMap<Reg extends ActionRegistry> = Record<string, Module<Reg, any, any, any>>;
|
|
13
|
+
export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
|
|
14
|
+
export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
|
|
15
|
+
export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
|
|
16
|
+
type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own extends ModuleShape = {}, Deps extends ModuleMap<Reg> = {}> = {
|
|
17
|
+
own: Own;
|
|
18
|
+
deps: Deps;
|
|
19
|
+
createRuntime: (config: {
|
|
20
|
+
registry: Reg;
|
|
21
|
+
context: FinalContext<Reg, Context, Deps>;
|
|
22
|
+
}) => {
|
|
23
|
+
run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(workflow: W, input: WorkflowInput<W>, obververs?: WorkflowObserver<Reg>[]) => Promise<{
|
|
24
|
+
results: WorkflowResults<W>;
|
|
25
|
+
output: WorkflowOutput<W>;
|
|
26
|
+
extras: Record<string, any>;
|
|
27
|
+
}>;
|
|
28
|
+
getContext: () => FinalContext<Reg, Context, Deps>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type ModuleContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = {
|
|
8
32
|
wf: ReturnType<typeof createWorkflow<Reg, Context>>;
|
|
9
33
|
deps: Deps;
|
|
10
34
|
context: Context;
|
|
@@ -14,12 +38,12 @@ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<str
|
|
|
14
38
|
context: Context;
|
|
15
39
|
}) => T) => T;
|
|
16
40
|
};
|
|
17
|
-
export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
use?:
|
|
23
|
-
define: (ctx: ModuleContext<Reg, Context,
|
|
24
|
-
})
|
|
41
|
+
export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleMap<Reg>, Own extends ModuleShape>(config: {
|
|
42
|
+
use?: Use;
|
|
43
|
+
define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
|
|
44
|
+
}): Module<Reg, Context, Own, Use>;
|
|
45
|
+
export declare function createModuleFactory<Reg extends ActionRegistry, Context extends Record<string, any>>(): <Use extends ModuleMap<Reg> = {}, Own extends ModuleShape = {}>(config: {
|
|
46
|
+
use?: Use;
|
|
47
|
+
define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
|
|
48
|
+
}) => Module<Reg, Context, Own, Use>;
|
|
25
49
|
export {};
|
package/dist/workflow-module.js
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
|
-
import { createWorkflow
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
for (const key in mod) {
|
|
7
|
-
if (!seen.has(key)) {
|
|
8
|
-
seen.add(key);
|
|
9
|
-
result[key] = mod[key];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
export function createModule({ registry, context, use, define, }) {
|
|
16
|
-
const wf = createWorkflow(registry, context);
|
|
17
|
-
// const deps = (use ? Object.assign({}, ...use) : {}) as Deps;
|
|
18
|
-
const deps = (use ? mergeModules(use) : {});
|
|
1
|
+
import { createWorkflow } from "./workflow-composer.js";
|
|
2
|
+
import { executeWorkflow } from "./workflow-executor.js";
|
|
3
|
+
export function createModule(config) {
|
|
4
|
+
const wf = createWorkflow();
|
|
5
|
+
const deps = (config.use ?? {});
|
|
19
6
|
const moduleCtx = {
|
|
20
7
|
wf,
|
|
21
8
|
deps,
|
|
22
|
-
context,
|
|
23
|
-
tools: (factory) => factory({
|
|
9
|
+
context: {},
|
|
10
|
+
tools: (factory) => factory({
|
|
11
|
+
wf,
|
|
12
|
+
deps,
|
|
13
|
+
context: {},
|
|
14
|
+
}),
|
|
24
15
|
};
|
|
25
|
-
const own = define(moduleCtx);
|
|
16
|
+
const own = config.define(moduleCtx);
|
|
26
17
|
return {
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
own,
|
|
19
|
+
deps,
|
|
20
|
+
createRuntime({ registry, context }) {
|
|
21
|
+
const runtimeCtx = { ...context };
|
|
22
|
+
return {
|
|
23
|
+
run: async (workflow, input, observers = []) => {
|
|
24
|
+
return executeWorkflow(workflow, registry, input, context, observers);
|
|
25
|
+
},
|
|
26
|
+
getContext: () => ({ ...runtimeCtx }),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function createModuleFactory() {
|
|
32
|
+
return function (config) {
|
|
33
|
+
return createModule(config);
|
|
29
34
|
};
|
|
30
35
|
}
|