@pogodisco/zephyr 1.2.6 → 1.2.8
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.
|
@@ -26,7 +26,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
26
26
|
private frontier;
|
|
27
27
|
private outputResolver?;
|
|
28
28
|
constructor(name: string, registry: Reg, context: Context);
|
|
29
|
-
step<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve
|
|
29
|
+
step<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
|
|
30
|
+
input: Input;
|
|
31
|
+
results: Results;
|
|
32
|
+
context: Context;
|
|
33
|
+
}) => undefined : (ctx: {
|
|
30
34
|
input: Input;
|
|
31
35
|
results: Results;
|
|
32
36
|
context: Context;
|
|
@@ -36,7 +40,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
36
40
|
], Results & {
|
|
37
41
|
[K in ID]: StepResult<Reg, ActionName>;
|
|
38
42
|
}>;
|
|
39
|
-
seq<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve
|
|
43
|
+
seq<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
|
|
44
|
+
input: Input;
|
|
45
|
+
results: Results;
|
|
46
|
+
context: Context;
|
|
47
|
+
}) => undefined : (ctx: {
|
|
40
48
|
input: Input;
|
|
41
49
|
results: Results;
|
|
42
50
|
context: Context;
|
|
@@ -47,15 +55,18 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
47
55
|
...Steps,
|
|
48
56
|
...(Branches[number] extends WorkflowBuilder<Reg, any, any, infer S, any> ? S : never)
|
|
49
57
|
], Results & (Branches[number] extends WorkflowBuilder<Reg, any, any, any, infer R> ? UnionToIntersection<R> : {})>;
|
|
50
|
-
join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve
|
|
58
|
+
join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: Parameters<Reg[ActionName]>[0] extends undefined ? (ctx?: {
|
|
59
|
+
input: Input;
|
|
60
|
+
results: Results;
|
|
61
|
+
}) => undefined : (ctx: {
|
|
51
62
|
input: Input;
|
|
52
63
|
results: Results;
|
|
53
64
|
}) => Parameters<Reg[ActionName]>[0]): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: Awaited<ReturnType<Reg[ActionName]>>; }, undefined>;
|
|
54
|
-
subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput
|
|
65
|
+
subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput?: (ctx: {
|
|
55
66
|
input: Input;
|
|
56
67
|
results: Results;
|
|
57
68
|
context: Context;
|
|
58
|
-
}) => SubInput): WorkflowBuilder<Reg, Input, Context, [
|
|
69
|
+
}) => [SubInput] extends [never] ? any : SubInput & Record<Exclude<keyof SubInput, keyof any>, never>): WorkflowBuilder<Reg, Input, Context, [
|
|
59
70
|
...Steps,
|
|
60
71
|
...SubSteps
|
|
61
72
|
], Results & {
|
|
@@ -560,7 +560,7 @@ export class WorkflowBuilder {
|
|
|
560
560
|
this.steps.push({
|
|
561
561
|
id,
|
|
562
562
|
action,
|
|
563
|
-
resolve,
|
|
563
|
+
resolve: resolve ?? (() => undefined),
|
|
564
564
|
dependsOn: deps,
|
|
565
565
|
});
|
|
566
566
|
this.frontier = [id];
|
|
@@ -607,7 +607,8 @@ export class WorkflowBuilder {
|
|
|
607
607
|
id: idMap.get(step.id),
|
|
608
608
|
dependsOn: step.dependsOn.map((d) => idMap.get(d)),
|
|
609
609
|
resolve: (ctx) => {
|
|
610
|
-
const subInput = resolveInput(ctx);
|
|
610
|
+
const subInput = resolveInput ? resolveInput(ctx) : undefined;
|
|
611
|
+
// const subInput = resolveInput(ctx);
|
|
611
612
|
return step.resolve({
|
|
612
613
|
input: subInput,
|
|
613
614
|
results: ctx.results,
|
|
@@ -627,9 +628,6 @@ export class WorkflowBuilder {
|
|
|
627
628
|
this.outputResolver = fn;
|
|
628
629
|
return this.build();
|
|
629
630
|
}
|
|
630
|
-
/* ------------------------------------------------ */
|
|
631
|
-
/* Build */
|
|
632
|
-
/* ------------------------------------------------ */
|
|
633
631
|
build() {
|
|
634
632
|
this.validateDependencies();
|
|
635
633
|
return {
|
|
@@ -642,7 +640,6 @@ export class WorkflowBuilder {
|
|
|
642
640
|
outputResolver: this.outputResolver,
|
|
643
641
|
};
|
|
644
642
|
}
|
|
645
|
-
/* ------------------------------------------------ */
|
|
646
643
|
validateDependencies() {
|
|
647
644
|
const stepIds = new Set(this.steps.map((s) => s.id));
|
|
648
645
|
for (const step of this.steps) {
|
|
@@ -132,10 +132,13 @@ export async function executeWorkflow(workflow, registry, input, middleware = []
|
|
|
132
132
|
const ctx = { stepId, input, results, registry, extras, frame };
|
|
133
133
|
const core = async () => {
|
|
134
134
|
frame.attempts++;
|
|
135
|
-
frame.input = step.resolve({ input, results });
|
|
135
|
+
frame.input = step.resolve?.({ input, results }) ?? undefined;
|
|
136
136
|
try {
|
|
137
137
|
const action = registry[step.action];
|
|
138
|
-
const result =
|
|
138
|
+
const result = frame.input === undefined
|
|
139
|
+
? await action()
|
|
140
|
+
: await action(frame.input);
|
|
141
|
+
// const result = await action(frame.input);
|
|
139
142
|
frame.output = result;
|
|
140
143
|
frame.end = Date.now();
|
|
141
144
|
results[step.id] = result;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { ActionRegistry } from "./types.js";
|
|
2
|
-
import { createWorkflow } from "./workflow-composer.js";
|
|
2
|
+
import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
|
|
3
3
|
export declare function workflowModule<Reg extends ActionRegistry, Context extends Record<string, any>, Flows extends Record<string, any>>(registry: Reg, context: Context, factory: (wf: ReturnType<typeof createWorkflow<Reg, Context>>) => Flows): {
|
|
4
4
|
wf: <Input = unknown>(name: string) => import("./workflow-composer.js").WorkflowBuilder<Reg, Input, Context, [], {}, undefined>;
|
|
5
5
|
} & Flows & {
|
|
6
6
|
extend<Extra extends Record<string, any>>(overrides: Extra): Flows & Extra;
|
|
7
7
|
};
|
|
8
|
+
type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
|
|
9
|
+
type ModuleShape = Record<string, AnyWorkflow>;
|
|
10
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
11
|
+
type UnionToIntersectionOrEmpty<U> = [U] extends [never] ? {} : UnionToIntersection<U>;
|
|
12
|
+
export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleShape[] = [], Deps extends ModuleShape = UnionToIntersectionOrEmpty<Use[number]> & ModuleShape, Own extends ModuleShape = {}>({ registry, context, use, define, }: {
|
|
13
|
+
registry: Reg;
|
|
14
|
+
context: Context;
|
|
15
|
+
use?: [...Use];
|
|
16
|
+
define: (wf: ReturnType<typeof createWorkflow<Reg, Context>>, deps: Deps) => Own;
|
|
17
|
+
}): Deps & Own;
|
|
18
|
+
export {};
|
package/dist/workflow-module.js
CHANGED
|
@@ -35,3 +35,12 @@ export function workflowModule(registry, context, factory) {
|
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
export function createModule({ registry, context, use, define, }) {
|
|
39
|
+
const wf = createWorkflow(registry, context);
|
|
40
|
+
const deps = (use ? Object.assign({}, ...use) : {});
|
|
41
|
+
const own = define(wf, deps);
|
|
42
|
+
return {
|
|
43
|
+
...deps,
|
|
44
|
+
...own,
|
|
45
|
+
};
|
|
46
|
+
}
|