Intent routing + confidence fallback01 / 05
Haunted Appliance Support Desk
Tier 1 support for toasters with unfinished business.
flow graph · graphOf(front-desk)
static · run it for the live trace
- calls jev
- your code
- leaf / emit
- fork / join
packages/examples/src/haunted-desk.ts
1/**2 * The Haunted Appliance Support Desk3 * Pattern: intent routing, with a nested decision and a low-confidence escape hatch.4 *5 * One choice picks the team. Jev's confidence says whether to trust it; if it's6 * shaky we hand off to a human instead of guessing. The paranormal branch nests a7 * safety gate and a second route, so a chain is just nodes all the way down.8 */9import { chain, choice, emit, gate, noul, route } from "jevchain";10import type { Example } from "./types";12const paranormal = chain(13 "paranormal-unit",14 gate("anyone-in-danger", {15 title: "Anyone in danger?",16 ask: noul("Is anyone in physical danger right now?", {17 true: "fire, smoke, injury, someone trapped, or threats of harm",18 false: "spooky or annoying, but nobody is getting hurt",19 }),20 pass: { max: 0.5 },21 then: route("classify-entity", {22 title: "What are we dealing with?",23 ask: choice("What is most likely going on with this appliance?", {24 poltergeist: "Objects move, doors open or close, or things get thrown with no one touching them.",25 "possessed-firmware": "The device's screen, voice or app behaves with apparent intent: messages, speech, settings changing themselves.",26 "just-a-draft": "There is a plausible ordinary cause: wind, a loose part, a neighbour, a smart-home routine.",27 }),28 branches: {29 poltergeist: emit("Booked: one (1) exorcist. Please remove fragile items from the countertop.", { id: "book-exorcist" }),30 "possessed-firmware": emit("Try turning it off and on again. If it asks you not to, call us back.", { id: "power-cycle" }),31 "just-a-draft": emit("Closed a window for you, spiritually. Ticket resolved.", { id: "close-window" }),32 },33 }),34 otherwise: emit("🚨 Leave the house now. Sending the fire department AND a priest.", { id: "evacuate" }),35 }),36);38export const hauntedDesk = route("front-desk", {39 title: "Front desk",40 description: "Routes appliance support tickets to the right team, including the one nobody talks about.",41 ask: choice("Which team should handle this appliance support ticket?", {42 repair: "An ordinary mechanical or electrical fault: won't start, leaks, overheats, makes a noise with a normal explanation.",43 billing: "Payments, refunds, invoices, warranties or subscriptions.",44 paranormal: "Behaviour no appliance can do: speaking, moving by itself, knowing things, cold spots, apparitions.",45 }),46 alsoAsk: {47 sarcastic: noul("Is the customer joking or being sarcastic?"),48 angry: noul("Is the customer angry?"),49 },50 lowConfidence: { below: 0.4, then: emit("Unclear. A human will read this. Probably Dave.", { id: "ask-dave" }) },51 branches: {52 repair: emit("Technician booked. Arrival window: 8am to the heat death of the universe.", { id: "book-technician" }),53 billing: emit("Forwarded to billing. They live for this.", { id: "forward-billing" }),54 paranormal,55 },56});58export const example: Example = {59 slug: "haunted-desk",60 title: "Haunted Appliance Support Desk",61 tagline: "Tier 1 support for toasters with unfinished business.",62 pattern: "Intent routing + confidence fallback",63 lesson:64 "Use a choice to pick a handler, and use its confidence as a second axis: when Jev isn't sure, route to a human instead of guessing. Nest gates and routes inside branches for multi-step triage.",65 chain: hauntedDesk,66 file: "haunted-desk.ts",67 inputs: [68 { label: "Whispering toaster", value: "My toaster whispers my name at 3am and the bread comes out cold." },69 { label: "Double charge", value: "I was charged twice for my fridge's extended warranty. Please refund one." },70 { label: "Leaky dishwasher", value: "The dishwasher leaks from the bottom left corner, but only when it drains." },71 { label: "Microwave prophecy", value: "The microwave opened by itself, said 'soon', and now there is smoke coming out of it." },72 { label: "Smart fridge", value: "My smart fridge keeps changing its screen to say 'I see you' and ordering 40 lemons." },73 ],74};