- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
import {
Flow, Step, TerminateSessionStep,
Tool, go, stay,
} from "@picoflow/core";
import { z } from "zod";
export class CollectEmailStep extends Step {
getPrompt() {
return "Ask for the customer's account email.";
}
defineTool() {
return [{
name: "capture_email",
description: "Validate and store an account email",
schema: z.object({ email: z.string() }),
}];
}
@Tool
async capture_email(args: Record<string, any>) {
const email = String(args.email ?? "").trim().toLowerCase();
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
return stay("That address is invalid. Ask again.");
}
this.saveState({ email });
return go(TerminateSessionStep).withPrompt(
`Confirm that support will reply to ${email}.`,
);
}
}
export class SupportFlow extends Flow {
protected defineSteps() {
return [
new CollectEmailStep(this).useMemory("support"),
new TerminateSessionStep(this).useMemory("end"),
];
}
}