import { createFlow, START, END } from "@waniwani/sdk/mcp";
import { z } from "zod";
export const quoteFunnel = createFlow({
id: "vehicle_insurance_quote",
title: "Vehicle Insurance Quote",
description: "Use when a user wants a price quote for vehicle insurance.",
state: {
// Fields the user provides
make: z.string().describe("Vehicle make"),
model: z.string().describe("Vehicle model"),
year: z.number().describe("Vehicle year"),
postcode: z.string().describe("Owner postcode"),
// Resolved by validation
vehicleId: z.string().describe("Resolved vehicle ID from your DB"),
// Confirmation state
confirmed: z.boolean().describe("User confirmed the details"),
// Quote state
quoteId: z.string().describe("Quote ID returned by pricing API"),
deductible: z.number().optional().describe("Chosen deductible"),
pricingAction: z.enum(["adjust", "done"]).describe("Adjust loop control"),
},
})
.addNode({
id: "ask_vehicle",
label: "Ask about vehicle",
run: ({ interrupt }) =>
interrupt({
make: {
question: "Tell me about your vehicle: make, model, year, and your postcode.",
context: "Extract make, model, year, and postcode from the user's response.",
},
}),
})
.addNode({
id: "validate",
label: "Validate vehicle + postcode",
hideFromFunnel: true,
run: async ({ state }) => {
// your validation API call
return { vehicleId: "..." };
},
})
.addNode({
id: "show_confirmation",
label: "Confirm details",
run: ({ state, showWidget }) => {
// see Pet Insurance Quote example for the showWidget pattern
return showWidget(/* ... */);
},
})
.addNode({
id: "show_pricing",
label: "Show pricing",
run: async ({ state, showWidget }) => {
// call pricing API, render widget
return { quoteId: "...", /* ... */ };
},
})
// ... edges and adjustment loop
.compile();