@pogodisco/zephyr 1.3.5 → 1.3.7
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/registry.js +0 -40
- package/dist/utils.js +0 -41
- package/dist/workflow-composer.d.ts +53 -28
- package/dist/workflow-composer.js +412 -17
- package/dist/workflow-executor.js +9 -631
- package/dist/workflow-module.d.ts +1 -5
- package/dist/workflow-module.js +1 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/registry.js
CHANGED
|
@@ -1,43 +1,3 @@
|
|
|
1
|
-
// import { Action, ActionRegistry, MergeActionRegistries } from "./types.js";
|
|
2
|
-
//
|
|
3
|
-
// export class ActionRegistryBuilder<R extends ActionRegistry = {}> {
|
|
4
|
-
// private registry: Partial<R> = {};
|
|
5
|
-
//
|
|
6
|
-
// constructor(initial?: R) {
|
|
7
|
-
// if (initial) {
|
|
8
|
-
// this.registry = { ...initial };
|
|
9
|
-
// }
|
|
10
|
-
// }
|
|
11
|
-
//
|
|
12
|
-
// action<K extends string, I, O>(
|
|
13
|
-
// key: K,
|
|
14
|
-
// action: Action<I, O>,
|
|
15
|
-
// ): ActionRegistryBuilder<MergeActionRegistries<R, Record<K, Action<I, O>>>> {
|
|
16
|
-
// (this.registry as any)[key] = action;
|
|
17
|
-
// return this as any;
|
|
18
|
-
// }
|
|
19
|
-
//
|
|
20
|
-
// // Extend with another registry (with override)
|
|
21
|
-
// extend<Other extends ActionRegistry>(
|
|
22
|
-
// other: ActionRegistryBuilder<Other> | Other,
|
|
23
|
-
// ): ActionRegistryBuilder<MergeActionRegistries<R, Other>> {
|
|
24
|
-
// const otherRegistry =
|
|
25
|
-
// other instanceof ActionRegistryBuilder ? other.build() : other;
|
|
26
|
-
//
|
|
27
|
-
// Object.assign(this.registry, otherRegistry);
|
|
28
|
-
// return this as any;
|
|
29
|
-
// }
|
|
30
|
-
//
|
|
31
|
-
// build(): R {
|
|
32
|
-
// return this.registry as R;
|
|
33
|
-
// }
|
|
34
|
-
// }
|
|
35
|
-
//
|
|
36
|
-
// export function createActionRegistry<R extends ActionRegistry = {}>(
|
|
37
|
-
// initial?: R,
|
|
38
|
-
// ): ActionRegistryBuilder<R> {
|
|
39
|
-
// return new ActionRegistryBuilder(initial);
|
|
40
|
-
// }
|
|
41
1
|
export class ActionRegistryBuilder {
|
|
42
2
|
constructor(initial) {
|
|
43
3
|
this.registry = {};
|
package/dist/utils.js
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
// import { defineNode, execNode } from "./node/main.js";
|
|
2
|
-
// import { TaskMap, TaskNodeWithContracts, TasksFromFns } from "./node/types.js";
|
|
3
|
-
//
|
|
4
|
-
// export function createAction<
|
|
5
|
-
// FN extends (args: any) => any, // Allow sync or async
|
|
6
|
-
// Out = Awaited<ReturnType<FN>>, // Unwrap Promise if present
|
|
7
|
-
// >(fn: FN) {
|
|
8
|
-
// // Just return the raw node definition, not wrapped with useNode
|
|
9
|
-
// return defineNode<TasksFromFns<{ run: FN }>, Parameters<FN>[0], Out>({
|
|
10
|
-
// run: {
|
|
11
|
-
// fn, // Function can throw or return data
|
|
12
|
-
// argMap: (r) => r._init,
|
|
13
|
-
// },
|
|
14
|
-
// _output: (r) => r.run as Out,
|
|
15
|
-
// });
|
|
16
|
-
// }
|
|
17
|
-
//
|
|
18
|
-
// export function genericAction<FN extends (args: any) => any>(fn: FN) {
|
|
19
|
-
// return <T = Awaited<ReturnType<FN>>>() => useAction(createAction<FN, T>(fn));
|
|
20
|
-
// }
|
|
21
|
-
//
|
|
22
|
-
// export function fixedAction<
|
|
23
|
-
// FN extends (args: any) => any,
|
|
24
|
-
// T = Awaited<ReturnType<FN>>,
|
|
25
|
-
// >(fn: FN): () => (args: Parameters<FN>[0]) => Promise<T> {
|
|
26
|
-
// return () => useAction(createAction<FN, T>(fn));
|
|
27
|
-
// }
|
|
28
|
-
//
|
|
29
|
-
// export function useAction<
|
|
30
|
-
// T extends TaskMap,
|
|
31
|
-
// I extends Record<string, any> | undefined,
|
|
32
|
-
// O,
|
|
33
|
-
// >(node: TaskNodeWithContracts<T, I, O>) {
|
|
34
|
-
// // Returns a function that graph can call, but WITHOUT withResponse
|
|
35
|
-
// // Just a simple adapter that calls callNode and returns raw _output
|
|
36
|
-
// return async (initArgs: I): Promise<O> => {
|
|
37
|
-
// const result = await execNode(node, initArgs);
|
|
38
|
-
// return result._output; // Just raw data, throws on error
|
|
39
|
-
// };
|
|
40
|
-
// }
|
|
41
|
-
//
|
|
42
1
|
/**
|
|
43
2
|
* For generic actions - preserves the generic parameter
|
|
44
3
|
*/
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { ActionRegistry, ActionReturn } from "./types.js";
|
|
2
|
-
|
|
1
|
+
import { ActionParams, ActionRegistry, ActionReturn } from "./types.js";
|
|
2
|
+
type StepBuilderResult<WB, ID extends string, Default> = WB & {
|
|
3
|
+
as<Override>(): OverrideStepResult<WB, ID, Override>;
|
|
4
|
+
};
|
|
5
|
+
type OverrideStepResult<WB, ID extends string, Override> = WB extends WorkflowBuilder<infer Reg, infer Input, infer Context, infer Steps, infer Results, infer Output> ? WorkflowBuilder<Reg, Input, Context, Steps, Omit<Results, ID> & {
|
|
6
|
+
[K in ID]: Override;
|
|
7
|
+
}, Output> : never;
|
|
8
|
+
type NormalizedCall = {
|
|
3
9
|
kind: "none";
|
|
4
10
|
} | {
|
|
5
11
|
kind: "positional";
|
|
@@ -12,15 +18,42 @@ export type ResolvedStepInput = NormalizedCall | {
|
|
|
12
18
|
kind: "loop";
|
|
13
19
|
items: NormalizedCall[];
|
|
14
20
|
};
|
|
21
|
+
type CallHelpers<Reg extends ActionRegistry, ActionName extends keyof Reg> = {
|
|
22
|
+
args: (...args: ActionParams<Reg, ActionName>) => {
|
|
23
|
+
kind: "positional";
|
|
24
|
+
args: ActionParams<Reg, ActionName>;
|
|
25
|
+
};
|
|
26
|
+
obj: ActionParams<Reg, ActionName> extends [infer A] ? (arg: A) => {
|
|
27
|
+
kind: "object";
|
|
28
|
+
args: A;
|
|
29
|
+
} : never;
|
|
30
|
+
none: () => {
|
|
31
|
+
kind: "none";
|
|
32
|
+
};
|
|
33
|
+
loop: (items: {
|
|
34
|
+
kind: "positional";
|
|
35
|
+
args: ActionParams<Reg, ActionName>;
|
|
36
|
+
}[] | {
|
|
37
|
+
kind: "object";
|
|
38
|
+
args: ActionParams<Reg, ActionName>[0];
|
|
39
|
+
}[]) => {
|
|
40
|
+
kind: "loop";
|
|
41
|
+
items: typeof items;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
15
44
|
type SubflowResult<SubResults, SubOutput> = SubOutput extends undefined ? SubResults : SubOutput;
|
|
16
|
-
|
|
45
|
+
type WorkflowInput<T> = T extends WorkflowDef<any, infer I, any, any, any> ? I : never;
|
|
46
|
+
type WorkflowResults<T> = T extends WorkflowDef<any, any, infer R, any, any> ? R : never;
|
|
47
|
+
type WorkflowOutput<T> = T extends WorkflowDef<any, any, any, any, infer O> ? O : never;
|
|
48
|
+
export type StepResultFromResolve<Reg extends ActionRegistry, ActionName extends keyof Reg, R extends ResolvedStepInput> = R extends {
|
|
49
|
+
kind: "loop";
|
|
50
|
+
} ? ActionReturn<Reg, ActionName>[] : ActionReturn<Reg, ActionName>;
|
|
17
51
|
export type StepDef<Reg extends ActionRegistry, ID extends string = string, ActionName extends keyof Reg = any> = {
|
|
18
52
|
id: ID;
|
|
19
53
|
action: ActionName;
|
|
20
54
|
dependsOn: string[];
|
|
21
55
|
resolve: (ctx: any) => ResolvedStepInput;
|
|
22
56
|
when?: (ctx: any) => boolean;
|
|
23
|
-
loop?: boolean;
|
|
24
57
|
};
|
|
25
58
|
export type WorkflowDef<Reg extends ActionRegistry, Input, Results, Steps extends StepDef<Reg, any, any>[] = StepDef<Reg, any, any>[], Output = undefined> = {
|
|
26
59
|
name: string;
|
|
@@ -41,49 +74,45 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
41
74
|
private frontier;
|
|
42
75
|
private outputResolver?;
|
|
43
76
|
constructor(name: string, registry: Reg, context: Context);
|
|
44
|
-
step<ID extends string, ActionName extends keyof Reg & string,
|
|
77
|
+
step<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
45
78
|
input: Input;
|
|
46
79
|
results: Results;
|
|
47
80
|
context: Context;
|
|
48
|
-
}) =>
|
|
49
|
-
loop?: Loop;
|
|
50
|
-
}): WorkflowBuilder<Reg, Input, Context, [
|
|
81
|
+
} & CallHelpers<Reg, ActionName>) => ResolveOut, dependsOn?: string[], options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [
|
|
51
82
|
...Steps,
|
|
52
83
|
StepDef<Reg, ID, ActionName>
|
|
53
84
|
], Results & {
|
|
54
|
-
[K in ID]:
|
|
55
|
-
}
|
|
56
|
-
seq<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
85
|
+
[K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>;
|
|
86
|
+
}, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
|
|
87
|
+
seq<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
57
88
|
input: Input;
|
|
58
89
|
results: Results;
|
|
59
90
|
context: Context;
|
|
60
|
-
}) =>
|
|
61
|
-
loop?: boolean;
|
|
62
|
-
}): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: ActionReturn<Reg, ActionName> | ActionReturn<Reg, ActionName>[]; }, undefined>;
|
|
91
|
+
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
|
|
63
92
|
parallel<Branches extends WorkflowBuilder<Reg, Input, Context, any, any>[]>(...branches: {
|
|
64
93
|
[K in keyof Branches]: (builder: WorkflowBuilder<Reg, Input, Context, [], Results>) => Branches[K];
|
|
65
94
|
}): WorkflowBuilder<Reg, Input, Context, [
|
|
66
95
|
...Steps,
|
|
67
96
|
...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any> ? S : never)
|
|
68
97
|
], Results & (Branches[number] extends WorkflowBuilder<Reg, any, any, any, infer R> ? UnionToIntersection<R> : {})>;
|
|
69
|
-
join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
98
|
+
join<ID extends string, ActionName extends keyof Reg & string, ResolveOut extends ResolvedStepInput = ResolvedStepInput>(id: ID, action: ActionName, resolve?: (ctx: {
|
|
70
99
|
input: Input;
|
|
71
100
|
results: Results;
|
|
72
101
|
context: Context;
|
|
73
|
-
}) =>
|
|
74
|
-
|
|
75
|
-
}): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: ActionReturn<Reg, ActionName> | ActionReturn<Reg, ActionName>[]; }, undefined>;
|
|
76
|
-
subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput?: (ctx: {
|
|
102
|
+
} & CallHelpers<Reg, ActionName>) => ResolveOut, options?: {}): StepBuilderResult<WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: StepResultFromResolve<Reg, ActionName, ResolveOut>; }, Output>, ID, StepResultFromResolve<Reg, ActionName, ResolveOut>>;
|
|
103
|
+
subflow<Prefix extends string, SubSteps extends StepDef<Reg, any, any>[], WF extends WorkflowDef<Reg, any, any, SubSteps, any>>(prefix: Prefix, workflow: WF, resolveInput: WorkflowInput<WF> extends undefined ? ((ctx: {
|
|
77
104
|
input: Input;
|
|
78
105
|
results: Results;
|
|
79
106
|
context: Context;
|
|
80
|
-
}) =>
|
|
81
|
-
|
|
82
|
-
|
|
107
|
+
}) => WorkflowInput<WF>) | undefined : (ctx: {
|
|
108
|
+
input: Input;
|
|
109
|
+
results: Results;
|
|
110
|
+
context: Context;
|
|
111
|
+
}) => WorkflowInput<WF>, options?: {}): WorkflowBuilder<Reg, Input, Context, [
|
|
83
112
|
...Steps,
|
|
84
|
-
...
|
|
113
|
+
...WF["steps"]
|
|
85
114
|
], Results & {
|
|
86
|
-
[K in Prefix]: SubflowResult<
|
|
115
|
+
[K in Prefix]: SubflowResult<WorkflowResults<WF>, WorkflowOutput<WF>>;
|
|
87
116
|
}>;
|
|
88
117
|
when(predicate: (ctx: {
|
|
89
118
|
input: Input;
|
|
@@ -98,10 +127,6 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
98
127
|
build(): WorkflowDef<Reg, Input, Results, Steps>;
|
|
99
128
|
private validateDependencies;
|
|
100
129
|
private getEndSteps;
|
|
101
|
-
static args: (...args: any[]) => NormalizedCall;
|
|
102
|
-
static obj: (args: any) => NormalizedCall;
|
|
103
|
-
static none: () => NormalizedCall;
|
|
104
|
-
static loop: (items: NormalizedCall[]) => ResolvedStepInput;
|
|
105
130
|
}
|
|
106
131
|
export declare function createWorkflow<Reg extends ActionRegistry, Context extends Record<string, any> = {}>(registry: Reg, context?: Context): <Input = unknown>(name: string) => WorkflowBuilder<Reg, Input, Context, [], {}, undefined>;
|
|
107
132
|
export {};
|