@alexkroman1/aai-cli 15.1.0 → 16.0.1
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/README.md +8 -5
- package/bin.mjs +12 -3
- package/dist/_build-target-55dJisQ-.mjs +649 -0
- package/dist/_build-target.d.ts +105 -108
- package/dist/_deno-output.d.ts +23 -0
- package/dist/_deno-target.d.ts +73 -0
- package/dist/{_init-Bsi3DZNJ.mjs → _init-BzQbV8Zh.mjs} +3 -1
- package/dist/_modal-app.d.ts +77 -0
- package/dist/_modal-output.d.ts +31 -0
- package/dist/_modal-target.d.ts +64 -0
- package/dist/_target-bundle.d.ts +27 -0
- package/dist/_target-drain.d.ts +44 -0
- package/dist/_target-output.d.ts +63 -0
- package/dist/{_templates-CIlJ3Vay.mjs → _templates-CuP74F8D.mjs} +94 -4
- package/dist/_templates.d.ts +14 -1
- package/dist/_vercel-output.d.ts +4 -19
- package/dist/_vercel-target.d.ts +169 -0
- package/dist/{test-D032V2cA.mjs → _vitest-runner-AVR9VtXh.mjs} +28 -68
- package/dist/_vitest-runner.d.ts +154 -0
- package/dist/build-ButI2IKc.mjs +689 -0
- package/dist/build.d.ts +11 -0
- package/dist/cli.mjs +12 -11
- package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
- package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
- package/dist/{init-CQbj3ycf.mjs → init-D363Ls5u.mjs} +2 -2
- package/dist/scaffold/CLAUDE.md +185 -35
- package/dist/scaffold/package.json +4 -4
- package/dist/start.mjs +3 -1
- package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
- package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
- package/dist/templates/briefing-desk/agent.test.ts +347 -55
- package/dist/templates/briefing-desk/agent.ts +12 -0
- package/dist/templates/briefing-desk/shared.ts +220 -31
- package/dist/templates/briefing-desk/slack.ts +108 -0
- package/dist/templates/briefing-desk/system-prompt.md +12 -2
- package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
- package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
- package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
- package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
- package/dist/templates/call-audit/agent.eval.test.ts +5 -0
- package/dist/templates/call-audit/agent.test.ts +6 -1
- package/dist/templates/call-audit/agent.ts +10 -23
- package/dist/templates/call-audit/client.tsx +30 -55
- package/dist/templates/call-audit/guards.test.ts +233 -0
- package/dist/templates/call-audit/workflows/audit.ts +95 -16
- package/dist/templates/call-audit/workflows/ingest.ts +107 -88
- package/dist/templates/call-audit/workflows/media.ts +98 -7
- package/dist/templates/call-audit/workflows/summarize.ts +35 -31
- package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
- package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
- package/dist/templates/code-interpreter/agent.test.ts +44 -56
- package/dist/templates/code-interpreter/system-prompt.md +1 -1
- package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
- package/dist/templates/dispatch-center/agent.test.ts +253 -48
- package/dist/templates/dispatch-center/agent.ts +28 -1
- package/dist/templates/dispatch-center/client.tsx +126 -201
- package/dist/templates/dispatch-center/events.ts +48 -0
- package/dist/templates/dispatch-center/shared.ts +42 -1
- package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
- package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
- package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
- package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
- package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
- package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
- package/dist/templates/executive-assistant/agent.test.ts +672 -0
- package/dist/templates/executive-assistant/agent.ts +50 -0
- package/dist/templates/executive-assistant/calendar.test.ts +198 -0
- package/dist/templates/executive-assistant/client.tsx +195 -0
- package/dist/templates/executive-assistant/inbox.ts +233 -0
- package/dist/templates/executive-assistant/meeting.ts +138 -0
- package/dist/templates/executive-assistant/nodes.ts +152 -0
- package/dist/templates/executive-assistant/prompts.ts +331 -0
- package/dist/templates/executive-assistant/review.ts +425 -0
- package/dist/templates/executive-assistant/shared.ts +490 -0
- package/dist/templates/executive-assistant/system-prompt.md +15 -0
- package/dist/templates/executive-assistant/tools/accept.ts +10 -0
- package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
- package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
- package/dist/templates/executive-assistant/tools/edit.ts +10 -0
- package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
- package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
- package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
- package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
- package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
- package/dist/templates/executive-assistant/tools/respond.ts +10 -0
- package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
- package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
- package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
- package/dist/templates/health-assistant/agent.test.ts +134 -15
- package/dist/templates/health-assistant/agent.ts +8 -1
- package/dist/templates/health-assistant/fda.test.ts +130 -0
- package/dist/templates/health-assistant/fda.ts +75 -16
- package/dist/templates/health-assistant/system-prompt.md +9 -0
- package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
- package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
- package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
- package/dist/templates/hiring-desk/agent.test.ts +1021 -0
- package/dist/templates/hiring-desk/agent.ts +38 -0
- package/dist/templates/hiring-desk/client.tsx +154 -0
- package/dist/templates/hiring-desk/crews.ts +432 -0
- package/dist/templates/hiring-desk/leads.json +86 -0
- package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
- package/dist/templates/hiring-desk/screening-lock.ts +51 -0
- package/dist/templates/hiring-desk/shared.ts +480 -0
- package/dist/templates/hiring-desk/system-prompt.md +21 -0
- package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
- package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
- package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
- package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
- package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
- package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
- package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
- package/dist/templates/hotel-desk/agent.test.ts +1128 -0
- package/dist/templates/hotel-desk/agent.ts +63 -0
- package/dist/templates/hotel-desk/booking.ts +159 -0
- package/dist/templates/hotel-desk/card.ts +92 -0
- package/dist/templates/hotel-desk/catalogs.ts +219 -0
- package/dist/templates/hotel-desk/client.tsx +137 -0
- package/dist/templates/hotel-desk/concierge.ts +99 -0
- package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
- package/dist/templates/hotel-desk/desk.ts +224 -0
- package/dist/templates/hotel-desk/disputes.ts +216 -0
- package/dist/templates/hotel-desk/events.ts +79 -0
- package/dist/templates/hotel-desk/hotel.ts +412 -0
- package/dist/templates/hotel-desk/policies.ts +209 -0
- package/dist/templates/hotel-desk/records.ts +384 -0
- package/dist/templates/hotel-desk/restaurant.ts +147 -0
- package/dist/templates/hotel-desk/seed.ts +955 -0
- package/dist/templates/hotel-desk/shared.ts +354 -0
- package/dist/templates/hotel-desk/system-prompt.md +76 -0
- package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
- package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
- package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
- package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
- package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
- package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
- package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
- package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
- package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
- package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
- package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
- package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
- package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
- package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
- package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
- package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
- package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
- package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
- package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
- package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
- package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
- package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
- package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
- package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
- package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
- package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
- package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
- package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
- package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
- package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
- package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
- package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
- package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
- package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
- package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
- package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
- package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
- package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
- package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
- package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
- package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
- package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
- package/dist/templates/infocom-adventure/agent.test.ts +207 -52
- package/dist/templates/infocom-adventure/agent.ts +14 -3
- package/dist/templates/infocom-adventure/client.tsx +138 -176
- package/dist/templates/infocom-adventure/shared.ts +126 -6
- package/dist/templates/infocom-adventure/system-prompt.md +4 -4
- package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
- package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
- package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
- package/dist/templates/link-digest/agent.eval.test.ts +8 -0
- package/dist/templates/link-digest/agent.test.ts +285 -29
- package/dist/templates/link-digest/agent.ts +9 -0
- package/dist/templates/link-digest/api-client.ts +144 -0
- package/dist/templates/link-digest/client.tsx +11 -30
- package/dist/templates/link-digest/workflows/digest.ts +72 -24
- package/dist/templates/night-owl/agent.eval.test.ts +55 -40
- package/dist/templates/night-owl/agent.test.ts +146 -12
- package/dist/templates/night-owl/client.tsx +50 -17
- package/dist/templates/night-owl/shared.ts +33 -2
- package/dist/templates/night-owl/system-prompt.md +3 -0
- package/dist/templates/night-owl/tools/recommend.ts +4 -1
- package/dist/templates/night-owl/tools/revisit.ts +49 -0
- package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
- package/dist/templates/pipeline-simple/agent.test.ts +48 -91
- package/dist/templates/pipeline-simple/modes.test.ts +151 -0
- package/dist/templates/pipeline-simple/stages.test.ts +332 -0
- package/dist/templates/pizza-ordering/agent.test.ts +94 -38
- package/dist/templates/pizza-ordering/client.tsx +10 -5
- package/dist/templates/pizza-ordering/shared.ts +65 -6
- package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
- package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
- package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
- package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
- package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
- package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
- package/dist/templates/plan-and-execute/agent.test.ts +300 -113
- package/dist/templates/plan-and-execute/client.tsx +18 -7
- package/dist/templates/plan-and-execute/procedure.ts +162 -64
- package/dist/templates/plan-and-execute/prompts.ts +51 -15
- package/dist/templates/plan-and-execute/shared.ts +151 -45
- package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
- package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
- package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
- package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
- package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
- package/dist/templates/podcast-digest/agent.test.ts +126 -51
- package/dist/templates/podcast-digest/client.tsx +104 -68
- package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
- package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
- package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
- package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
- package/dist/templates/recap-workflow/agent.test.ts +207 -26
- package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
- package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
- package/dist/templates/redline/agent.eval.test.ts +40 -3
- package/dist/templates/redline/agent.test.ts +216 -6
- package/dist/templates/redline/agent.ts +54 -34
- package/dist/templates/redline/client.tsx +82 -126
- package/dist/templates/redline/form.ts +74 -0
- package/dist/templates/redline/workflows/prompts.ts +3 -3
- package/dist/templates/redline/workflows/redline.ts +73 -4
- package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
- package/dist/templates/research-workflow/agent.test.ts +436 -126
- package/dist/templates/research-workflow/agent.ts +20 -5
- package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
- package/dist/templates/research-workflow/tools/research_status.ts +39 -4
- package/dist/templates/research-workflow/workflows/filing.ts +164 -0
- package/dist/templates/research-workflow/workflows/notes.ts +69 -0
- package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
- package/dist/templates/research-workflow/workflows/research.ts +227 -280
- package/dist/templates/research-workflow/workflows/review.ts +43 -0
- package/dist/templates/retail/address.ts +29 -35
- package/dist/templates/retail/agent.eval.test.ts +36 -16
- package/dist/templates/retail/agent.test.ts +104 -26
- package/dist/templates/retail/agent.ts +12 -0
- package/dist/templates/retail/cancel.ts +39 -42
- package/dist/templates/retail/client.tsx +111 -176
- package/dist/templates/retail/payment.ts +38 -43
- package/dist/templates/retail/pending.test.ts +16 -8
- package/dist/templates/retail/registry.test.ts +108 -49
- package/dist/templates/retail/resolve.test.ts +2 -63
- package/dist/templates/retail/resolve.ts +16 -56
- package/dist/templates/retail/returns.ts +53 -54
- package/dist/templates/retail/seed.test.ts +2 -1
- package/dist/templates/retail/shared.ts +58 -14
- package/dist/templates/retail/store.test.ts +40 -29
- package/dist/templates/retail/store.ts +60 -23
- package/dist/templates/retail/swap.ts +78 -81
- package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
- package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
- package/dist/templates/roadside-assist/agent.test.ts +617 -0
- package/dist/templates/roadside-assist/agent.ts +85 -0
- package/dist/templates/roadside-assist/call.ts +237 -0
- package/dist/templates/roadside-assist/events.ts +92 -0
- package/dist/templates/roadside-assist/shared.ts +334 -0
- package/dist/templates/roadside-assist/system-prompt.md +37 -0
- package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
- package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
- package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
- package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
- package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
- package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
- package/dist/templates/roadside-assist/yard.test.ts +158 -0
- package/dist/templates/roadside-assist/yard.ts +183 -0
- package/dist/templates/simple/agent.eval.test.ts +4 -1
- package/dist/templates/simple/agent.test.ts +54 -31
- package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
- package/dist/templates/solo-rpg/agent.test.ts +402 -175
- package/dist/templates/solo-rpg/agent.ts +14 -3
- package/dist/templates/solo-rpg/client.tsx +10 -10
- package/dist/templates/solo-rpg/shared.ts +198 -79
- package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
- package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
- package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
- package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
- package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
- package/dist/templates/spoken-summary/agent.test.ts +70 -15
- package/dist/templates/spoken-summary/agent.ts +25 -21
- package/dist/templates/spoken-summary/client.tsx +68 -88
- package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
- package/dist/templates/support-line/agent.test.ts +167 -36
- package/dist/templates/support-line/client.tsx +21 -9
- package/dist/templates/support-line/nodes.ts +74 -32
- package/dist/templates/support-line/procedure.ts +66 -21
- package/dist/templates/support-line/prompts.ts +9 -0
- package/dist/templates/support-line/shared.ts +55 -17
- package/dist/templates/support-line/tools/answer_question.ts +14 -14
- package/dist/templates/transcription-workflow/agent.test.ts +135 -13
- package/dist/templates/transcription-workflow/client.tsx +30 -23
- package/dist/templates/transcription-workflow/recover.test.ts +93 -12
- package/dist/templates/transcription-workflow/recover.ts +29 -5
- package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
- package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
- package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
- package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
- package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
- package/dist/templates/travel-concierge/agent.test.ts +209 -40
- package/dist/templates/travel-concierge/agent.ts +24 -4
- package/dist/templates/travel-concierge/call-events.ts +80 -0
- package/dist/templates/travel-concierge/client.tsx +3 -2
- package/dist/templates/travel-concierge/routing.ts +5 -7
- package/dist/templates/travel-concierge/shared.ts +202 -41
- package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
- package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
- package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
- package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
- package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
- package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
- package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
- package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
- package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
- package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
- package/dist/templates/web-researcher/agent.test.ts +102 -65
- package/dist/templates/web-researcher/agent.ts +93 -1
- package/dist/templates/web-researcher/system-prompt.md +7 -1
- package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
- package/dist/templates/word-wrangler/agent.test.ts +432 -0
- package/dist/templates/word-wrangler/agent.ts +35 -0
- package/dist/templates/word-wrangler/client.tsx +211 -0
- package/dist/templates/word-wrangler/game.ts +107 -0
- package/dist/templates/word-wrangler/guess.ts +63 -0
- package/dist/templates/word-wrangler/player.ts +68 -0
- package/dist/templates/word-wrangler/shared.ts +263 -0
- package/dist/templates/word-wrangler/system-prompt.md +15 -0
- package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
- package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
- package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
- package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
- package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
- package/dist/templates/word-wrangler/words.ts +278 -0
- package/dist/test-Cllnx81G.mjs +83 -0
- package/dist/test.d.ts +9 -114
- package/package.json +5 -5
- package/dist/build-BhEaxBPu.mjs +0 -481
- package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
- package/dist/templates/embedded-assets/agent.test.ts +0 -79
- package/dist/templates/embedded-assets/agent.ts +0 -7
- package/dist/templates/embedded-assets/knowledge.json +0 -20
- package/dist/templates/embedded-assets/shared.ts +0 -17
- package/dist/templates/embedded-assets/system-prompt.md +0 -13
- package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
- package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
- package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
- package/dist/templates/math-buddy/agent.test.ts +0 -126
- package/dist/templates/math-buddy/agent.ts +0 -15
- package/dist/templates/math-buddy/system-prompt.md +0 -12
- package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
- package/dist/templates/personal-finance/agent.test.ts +0 -127
- package/dist/templates/personal-finance/agent.ts +0 -8
- package/dist/templates/personal-finance/system-prompt.md +0 -21
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tool shape for the four concierge catalogs.
|
|
3
|
+
*
|
|
4
|
+
* Their `book_tour`, `book_spa_appointment`, `book_business_center` and
|
|
5
|
+
* `order_flowers` are four `@function_tool`s that differ in which catalog they
|
|
6
|
+
* read, how the total is computed and which extra fields the booking takes —
|
|
7
|
+
* and share everything else: the past-date check, the party cap, the code, the
|
|
8
|
+
* "confirm the fixed details, no further call is needed" directive. The
|
|
9
|
+
* FACTORY holds the shared half and each `tools/` file names one instance,
|
|
10
|
+
* the way `travel-concierge`'s delegation tools do.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { InferSchemaOutput, ToolDef, ToolFailure } from "@alexkroman1/aai";
|
|
14
|
+
import { isClockTime, isToolFailure, toolFailure } from "@alexkroman1/aai";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import {
|
|
17
|
+
digitsOf,
|
|
18
|
+
isIsoDate,
|
|
19
|
+
speakCode,
|
|
20
|
+
speakUsd,
|
|
21
|
+
spokenDate,
|
|
22
|
+
type Ticket,
|
|
23
|
+
TODAY,
|
|
24
|
+
} from "./records.ts";
|
|
25
|
+
import { addTicket, hotelSlot } from "./shared.ts";
|
|
26
|
+
|
|
27
|
+
export interface CatalogBookingSpec<P extends z.ZodObject> {
|
|
28
|
+
description: string;
|
|
29
|
+
inputSchema: P;
|
|
30
|
+
kind: Ticket["kind"];
|
|
31
|
+
prefix: string;
|
|
32
|
+
/**
|
|
33
|
+
* Price and describe one booking from its arguments, or refuse it. `date` is
|
|
34
|
+
* already known to be a real, future date and `time`, where the catalog has
|
|
35
|
+
* one, a real clock time; the cap on party size or hours is the catalog's own
|
|
36
|
+
* and is checked here.
|
|
37
|
+
*
|
|
38
|
+
* The refusal is a {@link ToolFailure} — the shape the factory returns
|
|
39
|
+
* anyway, so a catalog's own cap is now forwarded rather than unpacked and
|
|
40
|
+
* re-wrapped one line later.
|
|
41
|
+
*/
|
|
42
|
+
price(
|
|
43
|
+
args: InferSchemaOutput<P>,
|
|
44
|
+
): { total: number; summary: string; details: Ticket["details"]; confirm: string } | ToolFailure;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Every catalog booking carries a date, a guest name and a phone; two of the
|
|
49
|
+
* four also carry a start `time`. Parsed back out of the arguments rather than
|
|
50
|
+
* asserted: a catalog whose schema dropped one of them fails its first call
|
|
51
|
+
* naming the field, instead of booking with `undefined` for a date.
|
|
52
|
+
*
|
|
53
|
+
* `date` and `time` come back as plain strings on purpose — the point of the
|
|
54
|
+
* re-parse is to catch a catalog that declared `z.string()` where it owed
|
|
55
|
+
* `isoDate()` / `clockTime()`, which a re-declared schema field could not — so
|
|
56
|
+
* the FORMAT is checked here with {@link isIsoDate} and {@link isClockTime},
|
|
57
|
+
* the predicate halves of those two fields.
|
|
58
|
+
*/
|
|
59
|
+
const COMMON = z.object({
|
|
60
|
+
date: z.string(),
|
|
61
|
+
time: z.string().optional(),
|
|
62
|
+
guestName: z.string(),
|
|
63
|
+
guestPhone: z.string(),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export function catalogBookingTool<P extends z.ZodObject>(spec: CatalogBookingSpec<P>): ToolDef {
|
|
67
|
+
return hotelSlot.updateTool({
|
|
68
|
+
description: spec.description,
|
|
69
|
+
inputSchema: spec.inputSchema,
|
|
70
|
+
execute(args, hotel) {
|
|
71
|
+
const common = COMMON.parse(args);
|
|
72
|
+
if (!isIsoDate(common.date))
|
|
73
|
+
return toolFailure(`${common.date} is not a date - use YYYY-MM-DD`);
|
|
74
|
+
if (common.date < TODAY)
|
|
75
|
+
return toolFailure(`${spokenDate(common.date)} is in the past - re-confirm the date`);
|
|
76
|
+
if (common.time !== undefined && !isClockTime(common.time))
|
|
77
|
+
return toolFailure(`${common.time} is not a time - use HH:MM on the 24-hour clock`);
|
|
78
|
+
const priced = spec.price(args);
|
|
79
|
+
if (isToolFailure(priced)) return priced;
|
|
80
|
+
const ticket = addTicket(hotel, spec.kind, spec.prefix, priced.summary, {
|
|
81
|
+
...priced.details,
|
|
82
|
+
guestName: common.guestName,
|
|
83
|
+
guestPhone: digitsOf(common.guestPhone) || common.guestPhone,
|
|
84
|
+
date: common.date,
|
|
85
|
+
total: priced.total,
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
reference: ticket.code,
|
|
89
|
+
spokenReference: speakCode(ticket.code),
|
|
90
|
+
date: spokenDate(common.date),
|
|
91
|
+
total: speakUsd(priced.total),
|
|
92
|
+
booked: priced.summary,
|
|
93
|
+
next:
|
|
94
|
+
`${priced.confirm} These are fixed - give them as facts; no further tool call is needed ` +
|
|
95
|
+
"for this booking.",
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four seams a tool call does not run along.
|
|
3
|
+
*
|
|
4
|
+
* `agent.test.ts` drives the desk through its tools — a call in, forty-one
|
|
5
|
+
* tools, what is on the slot afterwards. Everything here is a rule that holds
|
|
6
|
+
* BETWEEN those calls, and each one is invisible from inside a tool body:
|
|
7
|
+
*
|
|
8
|
+
* - the hang-up, which no tool can observe because the caller is gone —
|
|
9
|
+
* `agent({ events })` and `events.ts`;
|
|
10
|
+
* - the turn where the model owes SPEECH, so the right number of tools is zero
|
|
11
|
+
* — `toolChoice: "none"` on `offering` and `readBack`;
|
|
12
|
+
* - a refusal made once and passed along, rather than unpacked and rebuilt at
|
|
13
|
+
* every hop — `requireVerified`, `requireConfirmedBooking`, `validateCard`,
|
|
14
|
+
* and the `failable` writers that forward them;
|
|
15
|
+
* - a reference the caller SPOKE — an ordinal off a folio, a code with the word
|
|
16
|
+
* "dash" in it, a room number with the word "room" — which is a fact about
|
|
17
|
+
* phones rather than about any one tool.
|
|
18
|
+
*
|
|
19
|
+
* Split from `agent.test.ts` rather than added to it: that file is the tour of
|
|
20
|
+
* the desk, and these are the properties it would bury.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import agentDef from "virtual:aai/agent";
|
|
24
|
+
import type { InferToolInput, ToolContext } from "@alexkroman1/aai";
|
|
25
|
+
import { isToolFailure, resolveOne } from "@alexkroman1/aai";
|
|
26
|
+
import type { SessionEvent } from "@alexkroman1/aai/protocol";
|
|
27
|
+
import { createToolContext, expectDialogOk, toolRunner } from "@alexkroman1/aai/testing";
|
|
28
|
+
import { describe, expect, test } from "vitest";
|
|
29
|
+
import { validateCard } from "./card.ts";
|
|
30
|
+
import { deskFlow } from "./desk.ts";
|
|
31
|
+
import { LINE_ITEM_PICK } from "./disputes.ts";
|
|
32
|
+
import { DESK_EVENTS, recordAbandonedBooking } from "./events.ts";
|
|
33
|
+
import {
|
|
34
|
+
cancelBooking,
|
|
35
|
+
requireConfirmedBooking,
|
|
36
|
+
requireRoom,
|
|
37
|
+
resolveRoomConflict,
|
|
38
|
+
} from "./hotel.ts";
|
|
39
|
+
import { PRICING, type Ticket } from "./records.ts";
|
|
40
|
+
import { hotelSlot, requireVerified } from "./shared.ts";
|
|
41
|
+
import type recordCard from "./tools/record_card.ts";
|
|
42
|
+
|
|
43
|
+
const run = toolRunner(agentDef);
|
|
44
|
+
|
|
45
|
+
/** The event the runtime delivers when the caller is gone. */
|
|
46
|
+
const CALLER_GONE: SessionEvent = { type: "session.timed-out", meta: { id: "evt_1", at: 0 } };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The card fixture, typed by the TOOL rather than restated.
|
|
50
|
+
*
|
|
51
|
+
* `InferToolInput` reads `record_card`'s own schema, so a field renamed or
|
|
52
|
+
* added there fails HERE at compile time — where `run("record_card", …)` takes
|
|
53
|
+
* an untyped record and a stale fixture would only surface as a refusal three
|
|
54
|
+
* assertions later.
|
|
55
|
+
*/
|
|
56
|
+
const A_CARD: InferToolInput<typeof recordCard> = {
|
|
57
|
+
cardNumber: "4532 0000 0001 4471",
|
|
58
|
+
expiryMonth: 12,
|
|
59
|
+
expiryYear: 29,
|
|
60
|
+
securityCode: "321",
|
|
61
|
+
cardholderName: "Maria Whitfield",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** A booking flow open and carrying a name, a phone and a card. */
|
|
65
|
+
async function bookUpToCard(ctx: ToolContext) {
|
|
66
|
+
expectDialogOk(await run("start_room_booking", ctx));
|
|
67
|
+
expectDialogOk(
|
|
68
|
+
await run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
|
|
69
|
+
);
|
|
70
|
+
expectDialogOk(await run("choose_room", { roomType: "queen_2beds", view: "garden" }, ctx));
|
|
71
|
+
expectDialogOk(
|
|
72
|
+
await run(
|
|
73
|
+
"set_extras",
|
|
74
|
+
{ breakfast: true, valet: false, lateCheckout: false, pets: false },
|
|
75
|
+
ctx,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
expectDialogOk(
|
|
79
|
+
await run(
|
|
80
|
+
"record_guest_details",
|
|
81
|
+
{
|
|
82
|
+
firstName: "Maria",
|
|
83
|
+
lastName: "Whitfield",
|
|
84
|
+
email: "maria.whitfield@gmail.com",
|
|
85
|
+
phone: "123-555-0170",
|
|
86
|
+
},
|
|
87
|
+
ctx,
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─── The hang-up handler ─────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
describe("a hang-up mid-booking leaves a lead behind", () => {
|
|
95
|
+
test("the followup carries who they were and how far they got", async () => {
|
|
96
|
+
const ctx = createToolContext();
|
|
97
|
+
await bookUpToCard(ctx);
|
|
98
|
+
|
|
99
|
+
const ticket = recordAbandonedBooking(ctx);
|
|
100
|
+
expect(ticket).not.toBeNull();
|
|
101
|
+
expect(ticket?.kind).toBe("followup");
|
|
102
|
+
expect(ticket?.summary).toBe("abandoned_booking: Maria Whitfield dropped mid-booking");
|
|
103
|
+
expect(ticket?.details).toMatchObject({
|
|
104
|
+
kind: "abandoned_booking",
|
|
105
|
+
callerName: "Maria Whitfield",
|
|
106
|
+
callerPhone: "1235550170",
|
|
107
|
+
status: "open",
|
|
108
|
+
});
|
|
109
|
+
// The step they never reached is the one a human has to finish.
|
|
110
|
+
expect(String(ticket?.details.summary)).toContain("take the card");
|
|
111
|
+
|
|
112
|
+
const hotel = hotelSlot.get(ctx);
|
|
113
|
+
// The draft is gone, so the sidebar stops claiming a booking is in progress,
|
|
114
|
+
// and the ledger entry is what replaces it.
|
|
115
|
+
expect(hotel.draft).toBeNull();
|
|
116
|
+
expect(hotel.tickets.at(-1)?.code).toBe(ticket?.code);
|
|
117
|
+
expect(hotel.log.at(-1)).toBe(
|
|
118
|
+
"followup: abandoned_booking: Maria Whitfield dropped mid-booking",
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a call that ends at the desk writes no followup, only the log line", () => {
|
|
123
|
+
const ctx = createToolContext();
|
|
124
|
+
expect(recordAbandonedBooking(ctx)).toBeNull();
|
|
125
|
+
const hotel = hotelSlot.get(ctx);
|
|
126
|
+
expect(hotel.tickets).toEqual([]);
|
|
127
|
+
expect(hotel.log).toEqual(["Caller gone - call ended"]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("a caller who gave no name still leaves a callable ticket", async () => {
|
|
131
|
+
const ctx = createToolContext();
|
|
132
|
+
expectDialogOk(await run("start_room_booking", ctx));
|
|
133
|
+
const ticket = recordAbandonedBooking(ctx);
|
|
134
|
+
expect(ticket?.details).toMatchObject({
|
|
135
|
+
callerName: "name not given",
|
|
136
|
+
callerPhone: "no number",
|
|
137
|
+
});
|
|
138
|
+
expect(String(ticket?.details.summary)).toContain("ask the caller for dates");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("the agent declares the handler, and it is the one the runtime will call", async () => {
|
|
142
|
+
const handler = agentDef.events?.["session.timed-out"];
|
|
143
|
+
expect(handler).toBe(DESK_EVENTS["session.timed-out"]);
|
|
144
|
+
|
|
145
|
+
const ctx = createToolContext();
|
|
146
|
+
await bookUpToCard(ctx);
|
|
147
|
+
handler?.(CALLER_GONE, { sessionId: ctx.sessionId, env: ctx.env, slots: ctx.slots });
|
|
148
|
+
|
|
149
|
+
const written = hotelSlot.get(ctx).tickets.at(-1) as Ticket | undefined;
|
|
150
|
+
expect(written?.details.kind).toBe("abandoned_booking");
|
|
151
|
+
// The dialog's half of the same event, which writes nothing on its own.
|
|
152
|
+
expect(deskFlow.receive(ctx, CALLER_GONE).state).toBe("hungUp");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ─── Owing SPEECH means no tool at all ───────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
describe("the two owed-speech states forbid every tool, not just the gated one", () => {
|
|
159
|
+
test("readBack and offering hand the model no tools; every other state does", async () => {
|
|
160
|
+
const ctx = createToolContext();
|
|
161
|
+
await bookUpToCard(ctx);
|
|
162
|
+
expect(deskFlow.position(ctx).state).toBe("booking.card");
|
|
163
|
+
expect(deskFlow.voiceConfig(ctx)?.toolChoice).toBeUndefined();
|
|
164
|
+
|
|
165
|
+
expectDialogOk(await run("record_card", A_CARD, ctx));
|
|
166
|
+
expect(deskFlow.position(ctx).state).toBe("booking.readBack");
|
|
167
|
+
expect(deskFlow.voiceConfig(ctx)?.toolChoice).toBe("none");
|
|
168
|
+
// And the read-back is the state that also asks for a steady voice.
|
|
169
|
+
expect(deskFlow.voiceConfig(ctx)?.temperature).toBe(0.2);
|
|
170
|
+
|
|
171
|
+
// The caller answers; the obligation is discharged and the tools come back.
|
|
172
|
+
expect(
|
|
173
|
+
deskFlow.receive(ctx, {
|
|
174
|
+
type: "user-transcript.committed",
|
|
175
|
+
text: "yes, that's right",
|
|
176
|
+
meta: { id: "evt_2", at: 0 },
|
|
177
|
+
}).state,
|
|
178
|
+
).toBe("booking.agreeing");
|
|
179
|
+
expect(deskFlow.voiceConfig(ctx)?.toolChoice).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("a re-dated stay that kills the pick lands on offering, which is also speech-only", async () => {
|
|
183
|
+
const ctx = createToolContext();
|
|
184
|
+
expectDialogOk(await run("start_room_booking", ctx));
|
|
185
|
+
expectDialogOk(
|
|
186
|
+
await run("set_stay", { checkIn: "2026-06-15", checkOut: "2026-06-16", guests: 2 }, ctx),
|
|
187
|
+
);
|
|
188
|
+
expectDialogOk(await run("choose_room", { roomType: "penthouse" }, ctx));
|
|
189
|
+
// The penthouse is occupied through June 12, so the pick does not survive.
|
|
190
|
+
expectDialogOk(
|
|
191
|
+
await run("set_stay", { checkIn: "2026-06-10", checkOut: "2026-06-11", guests: 2 }, ctx),
|
|
192
|
+
);
|
|
193
|
+
expect(deskFlow.position(ctx).state).toBe("booking.offering");
|
|
194
|
+
// `choose_room`'s `when` already refuses here (`agent.test.ts` pins that).
|
|
195
|
+
// What this adds is that NO other tool can be reached either, so the turn
|
|
196
|
+
// ends in the sentence that offers the options rather than in a tool result.
|
|
197
|
+
expect(deskFlow.voiceConfig(ctx)?.toolChoice).toBe("none");
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// ─── The failure vocabulary the tools forward ────────────────────────────────
|
|
202
|
+
|
|
203
|
+
describe("a refusal is one object, made once and passed along", () => {
|
|
204
|
+
test("the helpers answer a ToolFailure the tools return unchanged", () => {
|
|
205
|
+
const ctx = createToolContext();
|
|
206
|
+
const hotel = hotelSlot.get(ctx);
|
|
207
|
+
|
|
208
|
+
const unverified = requireVerified(hotel);
|
|
209
|
+
expect(isToolFailure(unverified) && unverified.error).toContain("Not verified yet");
|
|
210
|
+
|
|
211
|
+
const missing = requireConfirmedBooking(hotel, "HTL-NOPE");
|
|
212
|
+
expect(isToolFailure(missing) && missing.error).toBe("booking not found: HTL-NOPE");
|
|
213
|
+
|
|
214
|
+
const badCard = validateCard({ ...A_CARD, cardNumber: "4532 0000 0001 4472" });
|
|
215
|
+
expect(isToolFailure(badCard) && badCard.error).toContain("fails the card check");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("`failable` forwards the lookup's refusal and writes nothing", () => {
|
|
219
|
+
hotelSlot.update(createToolContext(), (hotel) => {
|
|
220
|
+
const before = hotel.log.length;
|
|
221
|
+
// A cancelled booking is not a CONFIRMED one: the lookup refuses, `orFail`
|
|
222
|
+
// abandons the body, and the "Cancelled …" log line is never written.
|
|
223
|
+
expect(isToolFailure(cancelBooking(hotel, "HTL-XC91"))).toBe(true);
|
|
224
|
+
expect(isToolFailure(resolveRoomConflict(hotel, "HTL-XC91"))).toBe(true);
|
|
225
|
+
expect(hotel.log.length).toBe(before);
|
|
226
|
+
|
|
227
|
+
// And a real one still gets through, with the log line to prove it.
|
|
228
|
+
const cancelled = cancelBooking(hotel, "HTL-GH78");
|
|
229
|
+
expect(isToolFailure(cancelled)).toBe(false);
|
|
230
|
+
expect(hotel.log.at(-1)).toBe("Cancelled HTL-GH78");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// ─── One rule for reading a spoken reference ─────────────────────────────────
|
|
236
|
+
|
|
237
|
+
describe("a spoken reference is resolved, never guessed", () => {
|
|
238
|
+
test("the disputed line is picked by ordinal off the folio just read out", async () => {
|
|
239
|
+
const ctx = createToolContext();
|
|
240
|
+
await run("verify_booking", { lastName: "Lee", confirmationCode: "HTL-GH78" }, ctx);
|
|
241
|
+
const lines = (await run("lookup_invoice", ctx)) as { lineItems: { label: string }[] };
|
|
242
|
+
expect(lines.lineItems[1]?.label).toBe("Late checkout");
|
|
243
|
+
|
|
244
|
+
const byOrdinal = await run(
|
|
245
|
+
"dispute_charge",
|
|
246
|
+
{
|
|
247
|
+
category: "late_checkout_fee",
|
|
248
|
+
lineItemLabel: "the second one",
|
|
249
|
+
callerNote: "Front desk said 1 PM was fine.",
|
|
250
|
+
acceptsOfferedResolution: true,
|
|
251
|
+
},
|
|
252
|
+
ctx,
|
|
253
|
+
);
|
|
254
|
+
expect(byOrdinal).toMatchObject({ outcome: "goodwill_waived", refund: PRICING.lateCheckout });
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("a word that names two lines is REFUSED rather than picked between", () => {
|
|
258
|
+
const folio = [
|
|
259
|
+
{ label: "Room (2 nights)", amount: 56_000 },
|
|
260
|
+
{ label: "Room service", amount: 4200 },
|
|
261
|
+
];
|
|
262
|
+
const ambiguous = resolveOne(folio, "the room charge", LINE_ITEM_PICK);
|
|
263
|
+
expect(isToolFailure(ambiguous) && ambiguous.error).toMatch(
|
|
264
|
+
/matches 2 invoice lines.*Room \(2 nights\).*Room service/,
|
|
265
|
+
);
|
|
266
|
+
// The same scorer picks a single winner once a second word narrows it.
|
|
267
|
+
expect(resolveOne(folio, "the room service charge", LINE_ITEM_PICK)).toEqual(folio[1]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('"R E S dash J K nine zero" finds RES-JK90, and so does res jk90', async () => {
|
|
271
|
+
const ctx = createToolContext();
|
|
272
|
+
for (const spoken of ["RES-JK90", "res jk90", "R E S dash J K 9 0"]) {
|
|
273
|
+
const found = await run(
|
|
274
|
+
"lookup_restaurant_reservation",
|
|
275
|
+
{ lastName: "Bennett", confirmationCode: spoken },
|
|
276
|
+
ctx,
|
|
277
|
+
);
|
|
278
|
+
expect(isToolFailure(found)).toBe(false);
|
|
279
|
+
expect((found as { code: string }).code).toBe("RES-JK90");
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("a spoken room number is read by the same rule", () => {
|
|
284
|
+
const hotel = hotelSlot.get(createToolContext());
|
|
285
|
+
for (const spoken of ["304", "room 304", "Room-304"]) {
|
|
286
|
+
const room = requireRoom(hotel, spoken);
|
|
287
|
+
expect(isToolFailure(room)).toBe(false);
|
|
288
|
+
expect((room as { id: string }).id).toBe("304");
|
|
289
|
+
}
|
|
290
|
+
expect(isToolFailure(requireRoom(hotel, "999"))).toBe(true);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ─── The catalog factory's shared checks ─────────────────────────────────────
|
|
295
|
+
|
|
296
|
+
describe("the catalog factory checks the date AND the time", () => {
|
|
297
|
+
test("a spa booking at an impossible time is refused before it is priced", async () => {
|
|
298
|
+
const ctx = createToolContext();
|
|
299
|
+
const refused = await run(
|
|
300
|
+
"book_spa_appointment",
|
|
301
|
+
{
|
|
302
|
+
service: "deep_tissue_massage",
|
|
303
|
+
date: "2026-06-20",
|
|
304
|
+
time: "25:00",
|
|
305
|
+
partySize: 1,
|
|
306
|
+
guestName: "Maria Whitfield",
|
|
307
|
+
guestPhone: "1235550170",
|
|
308
|
+
},
|
|
309
|
+
ctx,
|
|
310
|
+
);
|
|
311
|
+
expect(isToolFailure(refused) && refused.error).toBe(
|
|
312
|
+
"25:00 is not a time - use HH:MM on the 24-hour clock",
|
|
313
|
+
);
|
|
314
|
+
expect(hotelSlot.get(ctx).tickets).toEqual([]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("a catalog with no time of its own is unaffected", async () => {
|
|
318
|
+
const ctx = createToolContext();
|
|
319
|
+
const ordered = await run(
|
|
320
|
+
"order_flowers",
|
|
321
|
+
{
|
|
322
|
+
arrangement: "bouquet",
|
|
323
|
+
date: "2026-06-20",
|
|
324
|
+
deliverTo: "301",
|
|
325
|
+
cardMessage: "Happy anniversary",
|
|
326
|
+
guestName: "Maria Whitfield",
|
|
327
|
+
guestPhone: "1235550170",
|
|
328
|
+
},
|
|
329
|
+
ctx,
|
|
330
|
+
);
|
|
331
|
+
expect(isToolFailure(ordered)).toBe(false);
|
|
332
|
+
expect(hotelSlot.get(ctx).tickets.at(-1)?.kind).toBe("flowers");
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the CALL is, as a dialog — the receptionist's desk, and the booking flow
|
|
3
|
+
* it hands off to and gets back from.
|
|
4
|
+
*
|
|
5
|
+
* Their architecture is one `HotelReceptionistAgent` whose booking tools each
|
|
6
|
+
* `await` an `AgentTask` — a sub-agent with its own instructions and its own,
|
|
7
|
+
* narrower tool set, that completes with a value. A voice session has one model
|
|
8
|
+
* and one tool list for its whole life, so the sub-agent's two properties come
|
|
9
|
+
* back as two properties of a dialog: its INSTRUCTIONS are the state's
|
|
10
|
+
* `instruction`, in front of the model on every turn while the flow is open, and
|
|
11
|
+
* its NARROWER TOOL SET is the `when` on each booking tool — `confirm_booking`
|
|
12
|
+
* refuses from anywhere but `booking.agreeing`, exactly as their `_closed()`
|
|
13
|
+
* refused a tool called outside its step.
|
|
14
|
+
*
|
|
15
|
+
* | BookRoomTask | here |
|
|
16
|
+
* | --- | --- |
|
|
17
|
+
* | `_Step` enum, `_ALLOWED[step]`, `_closed(tool)` | the `booking` children, each tool's `when`, and the SDK's refusal |
|
|
18
|
+
* | `_step()` derived from the draft | `nextStep` (`booking.ts`), sent by every recording tool |
|
|
19
|
+
* | `_must_offer` (armed when a re-dated pick dies) | `offering`, left on `@user-transcript.committed` |
|
|
20
|
+
* | `_must_read_back` (armed on every change) | `readBack`, left on `@user-transcript.committed` |
|
|
21
|
+
* | `complete(booking)` / `give_up` | `BOOKED` / `ABANDONED`, both back to `desk` |
|
|
22
|
+
*
|
|
23
|
+
* **The two `_Owed` states are the reason this needs `agent({ dialogs })`.** An
|
|
24
|
+
* obligation to SPEAK is discharged by the caller's next turn, which no tool
|
|
25
|
+
* call can observe; a session event can. `offering` and `readBack` each declare
|
|
26
|
+
* one transition, on `@user-transcript.committed`, and the state it leads to is
|
|
27
|
+
* where the gated tool becomes legal. That is their `_Owed.pending(turns)` with
|
|
28
|
+
* the counter deleted — and it holds for a caller who types as for one who
|
|
29
|
+
* speaks, which their comment records as the reason the counter read the
|
|
30
|
+
* history rather than a VAD hook.
|
|
31
|
+
*
|
|
32
|
+
* **`booking`'s `on` map is the step ladder, declared ONCE on the parent.** A
|
|
33
|
+
* recording tool may land the flow on any step (a corrected date invalidates the
|
|
34
|
+
* room, a different room reprices the extras), so every step event is legal
|
|
35
|
+
* from every child. XState's `.child` targets are what make one map serve all
|
|
36
|
+
* eight children without re-entering the parent.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
import type { AnyDialog, ToolChoice } from "@alexkroman1/aai";
|
|
40
|
+
import { dialog } from "@alexkroman1/aai";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The two owed-SPEECH states forbid a tool call outright.
|
|
44
|
+
*
|
|
45
|
+
* `offering` and `readBack` exist because something has to be SAID before the
|
|
46
|
+
* next tool is legal — the options offered, the booking read back — and each
|
|
47
|
+
* one's `when` gate already refuses the tool that would jump the queue. What
|
|
48
|
+
* the gate cannot do is stop the model reaching for a DIFFERENT tool instead of
|
|
49
|
+
* speaking: `lookup_policy` on a cancellation question, a second
|
|
50
|
+
* `record_guest_details` "to be sure". Either way the turn ends with a tool
|
|
51
|
+
* result rather than a sentence, the caller has nothing to answer, and the
|
|
52
|
+
* transition out of the state — `@user-transcript.committed` — never fires.
|
|
53
|
+
*
|
|
54
|
+
* `toolChoice: "none"` is the rule stated instead of asked for: for that turn
|
|
55
|
+
* the model has no tools at all, so the only thing it can produce is the
|
|
56
|
+
* sentence the state's `instruction` describes. Named once because both states
|
|
57
|
+
* carry the same rule for the same reason; typed {@link ToolChoice} because a
|
|
58
|
+
* standalone `"none"` would widen to `string` and stop being checked against
|
|
59
|
+
* the four the field admits.
|
|
60
|
+
*/
|
|
61
|
+
const SPEAK_ONLY: ToolChoice = "none";
|
|
62
|
+
|
|
63
|
+
const deskSpec = {
|
|
64
|
+
initial: "desk",
|
|
65
|
+
states: {
|
|
66
|
+
desk: {
|
|
67
|
+
instruction:
|
|
68
|
+
"You are the lead receptionist holding the whole call. Route each request to its tool; " +
|
|
69
|
+
"verification is something the booking tools do, not you. To book a room call " +
|
|
70
|
+
"start_room_booking the moment the caller wants one - do not collect name, email, phone " +
|
|
71
|
+
"or card before it is running. To change an existing booking, start_booking_modification.",
|
|
72
|
+
on: {
|
|
73
|
+
BOOKING_STARTED: "booking",
|
|
74
|
+
MODIFY_STARTED: "booking.editing",
|
|
75
|
+
"@session.timed-out": "hungUp",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
booking: {
|
|
79
|
+
initial: "stay",
|
|
80
|
+
on: {
|
|
81
|
+
NEED_STAY: ".stay",
|
|
82
|
+
OFFER: ".offering",
|
|
83
|
+
NEED_ROOM: ".room",
|
|
84
|
+
NEED_EXTRAS: ".extras",
|
|
85
|
+
NEED_DETAILS: ".details",
|
|
86
|
+
NEED_CARD: ".card",
|
|
87
|
+
READ_BACK: ".readBack",
|
|
88
|
+
BOOKED: "desk",
|
|
89
|
+
ABANDONED: "desk",
|
|
90
|
+
"@session.timed-out": "hungUp",
|
|
91
|
+
},
|
|
92
|
+
states: {
|
|
93
|
+
stay: {
|
|
94
|
+
instruction:
|
|
95
|
+
"A room booking is open. Scan the conversation: if dates and party size were already " +
|
|
96
|
+
"said, call set_stay with them now; otherwise ask for check-in, check-out and how " +
|
|
97
|
+
"many guests - one question per turn - then call set_stay. Its result lists the room " +
|
|
98
|
+
"options; OFFER them, never pick one.",
|
|
99
|
+
},
|
|
100
|
+
offering: {
|
|
101
|
+
toolChoice: SPEAK_ONLY,
|
|
102
|
+
instruction:
|
|
103
|
+
"The dates changed and the room the caller had picked is no longer available for them. " +
|
|
104
|
+
"Tell them, offer the room types set_stay just returned, and ask which they want. " +
|
|
105
|
+
"choose_room stays closed until they have answered.",
|
|
106
|
+
on: { "@user-transcript.committed": "room" },
|
|
107
|
+
},
|
|
108
|
+
room: {
|
|
109
|
+
instruction:
|
|
110
|
+
"The stay is recorded. Ask which room type (and view, if they care), then call " +
|
|
111
|
+
"choose_room with exactly what they chose. If they ask about extras or prices, the " +
|
|
112
|
+
"set_stay result is your reference - do not quote a total yet.",
|
|
113
|
+
},
|
|
114
|
+
extras: {
|
|
115
|
+
instruction:
|
|
116
|
+
"The room is recorded and there is no total yet. Offer the extras choose_room " +
|
|
117
|
+
"listed - breakfast, valet, late checkout, pets - and call set_extras with an " +
|
|
118
|
+
"explicit answer for each. The total only exists once this is answered.",
|
|
119
|
+
},
|
|
120
|
+
details: {
|
|
121
|
+
instruction:
|
|
122
|
+
"Room and extras are recorded. Collect the guest's name, email and phone, one at a " +
|
|
123
|
+
"time, reading spelled values back letter by letter, and call record_guest_details " +
|
|
124
|
+
"with what you have - it accepts any subset, so record each detail the moment it is " +
|
|
125
|
+
"given.",
|
|
126
|
+
},
|
|
127
|
+
card: {
|
|
128
|
+
instruction:
|
|
129
|
+
"Everything but the card is recorded. Take the card: number, expiry, security code " +
|
|
130
|
+
"and the name on it, then call record_card. Never read the full number or the code " +
|
|
131
|
+
"back - refer to the card by its last four only. If a value is rejected, ask for " +
|
|
132
|
+
"just that detail again.",
|
|
133
|
+
},
|
|
134
|
+
readBack: {
|
|
135
|
+
// Reading dates, a total and a card's last four back is transcription,
|
|
136
|
+
// and the failure it has is a model smoothing one number into another.
|
|
137
|
+
temperature: 0.2,
|
|
138
|
+
toolChoice: SPEAK_ONLY,
|
|
139
|
+
instruction:
|
|
140
|
+
"Every detail is captured. Read the booking back in ONE sentence - dates, guests, " +
|
|
141
|
+
"room and extras, the total the tool quoted, the card's last four - and ask if that " +
|
|
142
|
+
"is right. Then WAIT. confirm_booking is closed until the caller has answered.",
|
|
143
|
+
on: { "@user-transcript.committed": "agreeing" },
|
|
144
|
+
},
|
|
145
|
+
agreeing: {
|
|
146
|
+
temperature: 0.2,
|
|
147
|
+
instruction:
|
|
148
|
+
"The caller has heard the read-back. If they agreed, call confirm_booking now - the " +
|
|
149
|
+
"call IS your reply. If they corrected a detail, call the matching recording tool; " +
|
|
150
|
+
"the flow returns to the read-back. If they no longer want the room, abandon_booking.",
|
|
151
|
+
},
|
|
152
|
+
editing: {
|
|
153
|
+
instruction:
|
|
154
|
+
"You are modifying an existing booking, loaded and verified. Read it back briefly " +
|
|
155
|
+
"in one sentence - guest, dates, room type, extras - and ask what to change. Apply " +
|
|
156
|
+
"ONLY the changes the caller asks for with set_stay, choose_room and set_extras. " +
|
|
157
|
+
"Name, email, phone and card cannot change here (record_followup for identity, " +
|
|
158
|
+
"update_card for a card). To cancel instead, abandon_booking then cancel_room_booking.",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
hungUp: {
|
|
163
|
+
final: true,
|
|
164
|
+
instruction:
|
|
165
|
+
"The caller is gone. Do nothing further on this call - no booking, no lookup, no " +
|
|
166
|
+
"callback promise.",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
} as const;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The call's position, on its own slot key beside `hotelSlot`.
|
|
173
|
+
*
|
|
174
|
+
* `hungUp` is `final`: a booking abandoned mid-flow by a hang-up must not be
|
|
175
|
+
* confirmed by a model that keeps talking to a dead line. Their
|
|
176
|
+
* `abandoned_booking` followup is the human half of the same case, and it is
|
|
177
|
+
* written by `events.ts` on the SAME event — a transition decides what may
|
|
178
|
+
* still be done, a handler records what happened, and neither does the other's
|
|
179
|
+
* job.
|
|
180
|
+
*/
|
|
181
|
+
export const deskFlow = dialog("desk", deskSpec);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* What `agent({ dialogs })` is handed — the line that wires
|
|
185
|
+
* `@user-transcript.committed` and `@session.timed-out` to the dialog. Without
|
|
186
|
+
* it the two owed states could never be left.
|
|
187
|
+
*/
|
|
188
|
+
export const DIALOGS: readonly AnyDialog[] = [deskFlow];
|
|
189
|
+
|
|
190
|
+
/** Every state a recording tool may run in: the whole booking flow. */
|
|
191
|
+
export const IN_BOOKING = "booking";
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The booking steps in the order they are reached. Every gate below is a
|
|
195
|
+
* SUFFIX of this, so each is sliced from it rather than typed out: adding a
|
|
196
|
+
* step to the ladder used to mean editing up to four hand-kept lists, and a
|
|
197
|
+
* miss was silent — the tool simply refused at the new step.
|
|
198
|
+
*/
|
|
199
|
+
const LADDER = ["room", "extras", "details", "card", "readBack", "agreeing"] as const;
|
|
200
|
+
|
|
201
|
+
/** The ladder from `step` onward, as dialog positions. */
|
|
202
|
+
function from<S extends (typeof LADDER)[number]>(step: S) {
|
|
203
|
+
return LADDER.slice(LADDER.indexOf(step)).map((s) => `booking.${s}` as const);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Where `choose_room` may run: any step past the stay, and NOT `offering` —
|
|
208
|
+
* the options have to be spoken before a room can be picked, and the caller's
|
|
209
|
+
* next turn is what opens the step.
|
|
210
|
+
*
|
|
211
|
+
* `editing` is reachable from here and from {@link AFTER_ROOM} but NOT from the
|
|
212
|
+
* two below: the guest's name and card cannot be changed from that state, so
|
|
213
|
+
* the asymmetry is a decision rather than an omission.
|
|
214
|
+
*/
|
|
215
|
+
export const AFTER_STAY = [...from("room"), "booking.editing"] as const;
|
|
216
|
+
|
|
217
|
+
/** Where `set_extras` may run: once a room is on the draft. */
|
|
218
|
+
export const AFTER_ROOM = [...from("extras"), "booking.editing"] as const;
|
|
219
|
+
|
|
220
|
+
/** Where the guest's details may be recorded or corrected. */
|
|
221
|
+
export const AFTER_EXTRAS = from("details");
|
|
222
|
+
|
|
223
|
+
/** Where the card may be taken or corrected. */
|
|
224
|
+
export const AFTER_DETAILS = from("card");
|