Skip to content

Commit

Permalink
feat: update flows
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D committed Dec 19, 2024
1 parent a0a303f commit 5e68aec
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/experimental/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ export class Flow<
next = run.steps.at(0)?.name!;
} else if (response.next === Flow.PREV) {
next = run.steps.at(-2)?.name!;
} else if (response.next === Flow.NEXT) {
next = this.findStep(next).next;
} else if (response.next === Flow.SELF) {
next = run.steps.at(-1)?.name!;
} else if (!response.next || response.next === Flow.NEXT) {
next = this.findStep(next).next || Flow.END;
} else {
next = response.next || Flow.END;
next = response.next;
}
} catch (error) {
await runContext.emitter.emit("error", {
Expand All @@ -266,7 +266,14 @@ export class Flow<
}
}

run.result = (this.input.outputSchema ?? this.input.schema).parse(run.state);
run.result = (this.input.outputSchema ?? this.input.schema)
.parseAsync(run.state)
.catch((err) => {
throw new FlowError(
`Flow has ended but it's state does not adhere to the flow's output schema.`,
{ run: shallowCopy(run), errors: [err] },
);
});
return run;
},
);
Expand Down

0 comments on commit 5e68aec

Please sign in to comment.