@pogodisco/zephyr 1.3.3 → 1.3.4
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/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type ExecutionFrame = {
|
|
|
10
10
|
input?: any;
|
|
11
11
|
output?: any;
|
|
12
12
|
error?: any;
|
|
13
|
+
skipped?: boolean;
|
|
13
14
|
};
|
|
14
15
|
export type ActionParams<Reg, K extends keyof Reg> = Reg[K] extends (...args: infer P) => any ? P : never;
|
|
15
16
|
export type ActionReturn<Reg, K extends keyof Reg> = Reg[K] extends (...args: any[]) => infer R ? Awaited<R> : never;
|
|
@@ -59,9 +59,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
59
59
|
join<ID extends string, ActionName extends keyof Reg & string>(id: ID, action: ActionName, resolve?: ActionParams<Reg, ActionName> extends [] ? (ctx?: {
|
|
60
60
|
input: Input;
|
|
61
61
|
results: Results;
|
|
62
|
+
context: Context;
|
|
62
63
|
}) => undefined : (ctx: {
|
|
63
64
|
input: Input;
|
|
64
65
|
results: Results;
|
|
66
|
+
context: Context;
|
|
65
67
|
}) => ActionParams<Reg, ActionName>): WorkflowBuilder<Reg, Input, Context, [...Steps, StepDef<Reg, ID, ActionName>], Results & { [K in ID]: ActionReturn<Reg, ActionName>; }, undefined>;
|
|
66
68
|
subflow<Prefix extends string, SubInput, SubResults, SubSteps extends StepDef<Reg, any, any>[], SubOutput>(prefix: Prefix, workflow: WorkflowDef<Reg, SubInput, SubResults, SubSteps, SubOutput>, resolveInput?: (ctx: {
|
|
67
69
|
input: Input;
|
|
@@ -73,6 +75,11 @@ export declare class WorkflowBuilder<Reg extends ActionRegistry, Input = unknown
|
|
|
73
75
|
], Results & {
|
|
74
76
|
[K in Prefix]: SubflowResult<SubResults, SubOutput>;
|
|
75
77
|
}>;
|
|
78
|
+
when(predicate: (ctx: {
|
|
79
|
+
input: Input;
|
|
80
|
+
results: Results;
|
|
81
|
+
context: Context;
|
|
82
|
+
}) => boolean): this;
|
|
76
83
|
output<Output>(fn: (ctx: {
|
|
77
84
|
input: Input;
|
|
78
85
|
results: Results;
|
|
@@ -625,6 +625,14 @@ export class WorkflowBuilder {
|
|
|
625
625
|
this.frontier = workflow.endSteps.map((e) => idMap.get(e.id));
|
|
626
626
|
return this;
|
|
627
627
|
}
|
|
628
|
+
when(predicate) {
|
|
629
|
+
const lastStep = this.steps[this.steps.length - 1];
|
|
630
|
+
if (!lastStep) {
|
|
631
|
+
throw new Error("when() must follow a step");
|
|
632
|
+
}
|
|
633
|
+
lastStep.when = predicate;
|
|
634
|
+
return this;
|
|
635
|
+
}
|
|
628
636
|
output(fn) {
|
|
629
637
|
this.outputResolver = fn;
|
|
630
638
|
return this.build();
|
|
@@ -243,8 +243,17 @@ export async function executeWorkflow(workflow, registry, input, middleware = []
|
|
|
243
243
|
};
|
|
244
244
|
const core = async () => {
|
|
245
245
|
frame.attempts++;
|
|
246
|
+
const stepCtx = { input, results, context };
|
|
247
|
+
if (step.when && !step.when(stepCtx)) {
|
|
248
|
+
frame.output = undefined;
|
|
249
|
+
frame.end = Date.now();
|
|
250
|
+
frame.skipped = true;
|
|
251
|
+
results[step.id] = undefined;
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
246
254
|
// 👇 Get the resolved arguments (should be a tuple or undefined)
|
|
247
|
-
const resolvedArgs = step.resolve?.({ input, results, context });
|
|
255
|
+
// const resolvedArgs = step.resolve?.({ input, results, context });
|
|
256
|
+
const resolvedArgs = step.resolve?.(stepCtx);
|
|
248
257
|
frame.input = resolvedArgs;
|
|
249
258
|
try {
|
|
250
259
|
const action = registry[step.action];
|