@alexkroman1/aai-cli 0.17.0 → 0.18.0

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.
Files changed (438) hide show
  1. package/dist/{_agent-BopNO5Bq.mjs → _agent-BN21AHsJ.mjs} +4 -4
  2. package/dist/_api-client-Uljj0CQi.mjs +312 -0
  3. package/dist/_api-client.d.ts +69 -1
  4. package/dist/{_bundler-DCuNHjDF.mjs → _bundler-DvZDEu2p.mjs} +67 -7
  5. package/dist/_bundler.d.ts +15 -0
  6. package/dist/_cli-common.d.ts +42 -0
  7. package/dist/{client-bundler-DE-AGdm7.mjs → _client-plugins-kR43nZnb.mjs} +30 -132
  8. package/dist/_client-plugins.d.ts +16 -0
  9. package/dist/{_config-mq1I5Cva.mjs → _config-Dlh8PRRp.mjs} +2 -20
  10. package/dist/_config.d.ts +0 -8
  11. package/dist/{_dev-server-D6VSQbYW.mjs → _dev-server-C_zidzWj.mjs} +15 -10
  12. package/dist/_dev-session-ticket.d.ts +3 -0
  13. package/dist/_dev-tunnel.d.ts +20 -2
  14. package/dist/_dotenv-file.d.ts +6 -0
  15. package/dist/_init.d.ts +2 -11
  16. package/dist/_output.d.ts +47 -20
  17. package/dist/_safe-write.d.ts +38 -0
  18. package/dist/{_server-common-CVXIeWrY.mjs → _server-common-C6j67AcZ.mjs} +37 -2
  19. package/dist/_server-common.d.ts +16 -0
  20. package/dist/{_slug-api-BnmTHtjd.mjs → _slug-api-B9cptz7Q.mjs} +3 -2
  21. package/dist/_start-affinity.d.ts +70 -0
  22. package/dist/_start-log.d.ts +39 -0
  23. package/dist/_start-router.d.ts +85 -0
  24. package/dist/_start-run.d.ts +101 -0
  25. package/dist/_start-worker.d.ts +61 -0
  26. package/dist/_start-workers-BNdOnTal.mjs +529 -0
  27. package/dist/_start-workers.d.ts +262 -0
  28. package/dist/_studio-zympBLlD.mjs +140 -0
  29. package/dist/_studio.d.ts +14 -0
  30. package/dist/_target-bundle.d.ts +4 -0
  31. package/dist/{_templates-BVMVsQh0.mjs → _templates-ChZuhW66.mjs} +110 -8
  32. package/dist/_templates.d.ts +20 -1
  33. package/dist/{_typecheck-gate-CcX2gLJZ.mjs → _typecheck-gate-BNF5cboL.mjs} +2 -2
  34. package/dist/_ui-C0RufoYZ.mjs +147 -0
  35. package/dist/_ui.d.ts +14 -3
  36. package/dist/_utils-ChU85MEg.mjs +486 -0
  37. package/dist/_utils.d.ts +28 -0
  38. package/dist/_vendor-openers.d.ts +87 -0
  39. package/dist/{_vitest-runner-CKI8_K1b.mjs → _vitest-runner-tzyto9IU.mjs} +7 -3
  40. package/dist/_vitest-runner.d.ts +8 -1
  41. package/dist/{build-BnXLgfk-.mjs → build-BHgd-QYb.mjs} +13 -10
  42. package/dist/build.d.ts +21 -0
  43. package/dist/cli-workflow.d.ts +7 -0
  44. package/dist/cli.d.ts +16 -0
  45. package/dist/cli.mjs +243 -70
  46. package/dist/client-bundler-CImhqcp2.mjs +133 -0
  47. package/dist/client-bundler.mjs +1 -1
  48. package/dist/{console-tVBjfKyR.mjs → console-DwycgRkC.mjs} +4 -5
  49. package/dist/delete-ZcA3J_3o.mjs +75 -0
  50. package/dist/delete.d.ts +10 -1
  51. package/dist/{deploy-eWDoiwvn.mjs → deploy-CkfkiZE3.mjs} +9 -9
  52. package/dist/{dev-CT_QHHZL.mjs → dev-BX9g6qcf.mjs} +81 -18
  53. package/dist/{eval-Dl8o91yC.mjs → eval-CUKvfxRq.mjs} +4 -4
  54. package/dist/{init-CidslZZz.mjs → init-B9Uw76-_.mjs} +62 -32
  55. package/dist/{login-oJdBWu2B.mjs → login-Ct73CqU1.mjs} +30 -6
  56. package/dist/login.d.ts +2 -0
  57. package/dist/{logs-CkmFdSbr.mjs → logs-BBsUy96d.mjs} +59 -14
  58. package/dist/logs.d.ts +4 -1
  59. package/dist/project-config.mjs +1 -1
  60. package/dist/scaffold/CLAUDE.md +72 -55
  61. package/dist/scaffold/agent-guide/AGENT-API.md +44 -34
  62. package/dist/scaffold/agent-guide/HOSTING.md +11 -0
  63. package/dist/scaffold/agent-guide/TESTING-EVALS.md +105 -36
  64. package/dist/scaffold/agent-guide/TOOLS.md +189 -33
  65. package/dist/scaffold/agent-guide/UI.md +111 -39
  66. package/dist/scaffold/agent-guide/WORKFLOWS.md +234 -160
  67. package/dist/scaffold/package.json +4 -4
  68. package/dist/{secret-DPdPEet2.mjs → secret-CKjHRrVX.mjs} +112 -35
  69. package/dist/start.d.ts +14 -14
  70. package/dist/start.mjs +840 -40
  71. package/dist/{studio-COjK25Rl.mjs → studio-U6DvBNAx.mjs} +123 -35
  72. package/dist/studio.d.ts +1 -0
  73. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +23 -52
  74. package/dist/templates/applicant-screening-agent/agent.test.ts +821 -826
  75. package/dist/templates/applicant-screening-agent/agent.ts +1 -6
  76. package/dist/templates/applicant-screening-agent/client.tsx +1 -19
  77. package/dist/templates/applicant-screening-agent/shared.ts +8 -18
  78. package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +24 -27
  79. package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +75 -82
  80. package/dist/templates/applicant-screening-agent/tools/read_email.ts +24 -24
  81. package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +92 -99
  82. package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +72 -83
  83. package/dist/templates/applicant-screening-agent/tools/screening_status.ts +21 -29
  84. package/dist/templates/call-audit-workflow/agent.eval.test.ts +14 -19
  85. package/dist/templates/call-audit-workflow/agent.test.ts +275 -169
  86. package/dist/templates/call-audit-workflow/agent.ts +12 -30
  87. package/dist/templates/call-audit-workflow/client.tsx +9 -27
  88. package/dist/templates/call-audit-workflow/guards.test.ts +24 -71
  89. package/dist/templates/call-audit-workflow/workflows/audit.ts +24 -52
  90. package/dist/templates/call-audit-workflow/workflows/ingest.ts +32 -59
  91. package/dist/templates/call-audit-workflow/workflows/media.ts +4 -44
  92. package/dist/templates/call-audit-workflow/workflows/summarize.ts +72 -107
  93. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  94. package/dist/templates/code-interpreter-agent/agent.test.ts +4 -17
  95. package/dist/templates/code-interpreter-agent/agent.ts +1 -1
  96. package/dist/templates/coding-agent/agent.test.ts +17 -12
  97. package/dist/templates/coding-agent/agent.ts +1 -1
  98. package/dist/templates/custom-pipeline-agent/agent.test.ts +6 -14
  99. package/dist/templates/custom-pipeline-agent/agent.ts +1 -1
  100. package/dist/templates/custom-pipeline-agent/modes.test.ts +0 -1
  101. package/dist/templates/document-redline-workflow/agent.test.ts +88 -221
  102. package/dist/templates/document-redline-workflow/agent.ts +22 -32
  103. package/dist/templates/document-redline-workflow/client.tsx +46 -88
  104. package/dist/templates/document-redline-workflow/workflows/prompts.ts +0 -3
  105. package/dist/templates/document-redline-workflow/workflows/redline.ts +33 -50
  106. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +22 -71
  107. package/dist/templates/emergency-dispatch-agent/agent.test.ts +466 -495
  108. package/dist/templates/emergency-dispatch-agent/agent.ts +27 -43
  109. package/dist/templates/emergency-dispatch-agent/client.tsx +85 -119
  110. package/dist/templates/emergency-dispatch-agent/shared.ts +51 -88
  111. package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +11 -17
  112. package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +21 -30
  113. package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +60 -63
  114. package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +6 -15
  115. package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +40 -53
  116. package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +41 -47
  117. package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +2 -2
  118. package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +1 -1
  119. package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +13 -10
  120. package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +42 -51
  121. package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +40 -41
  122. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +14 -42
  123. package/dist/templates/entertainment-picks-agent/agent.test.ts +174 -221
  124. package/dist/templates/entertainment-picks-agent/agent.ts +1 -6
  125. package/dist/templates/entertainment-picks-agent/client.tsx +1 -12
  126. package/dist/templates/entertainment-picks-agent/shared.ts +12 -6
  127. package/dist/templates/entertainment-picks-agent/tools/recommend.ts +2 -2
  128. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +1 -0
  129. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +15 -22
  130. package/dist/templates/executive-inbox-agent/agent.test.ts +515 -527
  131. package/dist/templates/executive-inbox-agent/agent.ts +4 -8
  132. package/dist/templates/executive-inbox-agent/calendar.test.ts +23 -22
  133. package/dist/templates/executive-inbox-agent/client.tsx +1 -23
  134. package/dist/templates/executive-inbox-agent/review.ts +125 -113
  135. package/dist/templates/executive-inbox-agent/shared.ts +3 -0
  136. package/dist/templates/executive-inbox-agent/tools/ask_question.ts +6 -6
  137. package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +16 -18
  138. package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +1 -0
  139. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +20 -20
  140. package/dist/templates/executive-inbox-agent/tools/new_email.ts +17 -21
  141. package/dist/templates/executive-inbox-agent/tools/open_email.ts +72 -74
  142. package/dist/templates/executive-inbox-agent/tools/review_memory.ts +1 -0
  143. package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +19 -20
  144. package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +53 -50
  145. package/dist/templates/front-desk-agent/agent.eval.test.ts +22 -14
  146. package/dist/templates/front-desk-agent/agent.test.ts +139 -123
  147. package/dist/templates/front-desk-agent/agent.ts +4 -7
  148. package/dist/templates/front-desk-agent/shared.ts +88 -74
  149. package/dist/templates/front-door-agent/agent.eval.test.ts +61 -0
  150. package/dist/templates/front-door-agent/agent.test.ts +393 -0
  151. package/dist/templates/front-door-agent/agent.ts +35 -0
  152. package/dist/templates/front-door-agent/client.tsx +250 -0
  153. package/dist/templates/front-door-agent/routes.ts +91 -0
  154. package/dist/templates/front-door-agent/shared.ts +35 -0
  155. package/dist/templates/front-door-agent/system-prompt.md +12 -0
  156. package/dist/templates/front-door-agent/tools/leave_message.ts +39 -0
  157. package/dist/templates/front-door-agent/tools/link_phone.ts +49 -0
  158. package/dist/templates/front-door-agent/workflows/announce.ts +38 -0
  159. package/dist/templates/front-door-agent/workflows/digest.ts +53 -0
  160. package/dist/templates/front-door-agent/workflows/pair.ts +28 -0
  161. package/dist/templates/home-assistant-agent/agent.eval.test.ts +5 -9
  162. package/dist/templates/home-assistant-agent/agent.test.ts +513 -399
  163. package/dist/templates/home-assistant-agent/agent.ts +8 -5
  164. package/dist/templates/home-assistant-agent/client.tsx +48 -9
  165. package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +1 -0
  166. package/dist/templates/home-assistant-agent/tools/remind_me.ts +2 -1
  167. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +27 -52
  168. package/dist/templates/hotel-reception-agent/agent.test.ts +980 -964
  169. package/dist/templates/hotel-reception-agent/agent.ts +8 -21
  170. package/dist/templates/hotel-reception-agent/booking.ts +2 -2
  171. package/dist/templates/hotel-reception-agent/client.tsx +5 -20
  172. package/dist/templates/hotel-reception-agent/concierge.ts +2 -0
  173. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +285 -275
  174. package/dist/templates/hotel-reception-agent/desk.ts +45 -12
  175. package/dist/templates/hotel-reception-agent/hotel.ts +6 -6
  176. package/dist/templates/hotel-reception-agent/restaurant.ts +3 -4
  177. package/dist/templates/hotel-reception-agent/session.ts +14 -30
  178. package/dist/templates/hotel-reception-agent/shared.ts +33 -46
  179. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +14 -15
  180. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +1 -0
  181. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +1 -0
  182. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -2
  183. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +13 -10
  184. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  185. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +6 -7
  186. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +1 -0
  187. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +5 -4
  188. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +6 -5
  189. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +3 -4
  190. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +4 -4
  191. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -0
  192. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  193. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +1 -0
  194. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +1 -0
  195. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  196. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -0
  197. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +1 -0
  198. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +4 -4
  199. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -0
  200. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +4 -3
  201. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +1 -0
  202. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +1 -0
  203. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  204. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +1 -1
  205. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +30 -32
  206. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +22 -25
  207. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +1 -0
  208. package/dist/templates/hotel-reception-agent/tools/update_card.ts +5 -4
  209. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +23 -13
  210. package/dist/templates/kitchen-coach-agent/agent.eval.test.ts +38 -0
  211. package/dist/templates/kitchen-coach-agent/agent.test.ts +204 -0
  212. package/dist/templates/kitchen-coach-agent/agent.ts +22 -0
  213. package/dist/templates/kitchen-coach-agent/client.tsx +232 -0
  214. package/dist/templates/kitchen-coach-agent/history.ts +37 -0
  215. package/dist/templates/kitchen-coach-agent/shared.ts +131 -0
  216. package/dist/templates/kitchen-coach-agent/system-prompt.md +17 -0
  217. package/dist/templates/kitchen-coach-agent/tools/get_kitchen.ts +17 -0
  218. package/dist/templates/kitchen-coach-agent/tools/scale_amount.ts +31 -0
  219. package/dist/templates/kitchen-coach-agent/tools/start_timer.ts +24 -0
  220. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -40
  221. package/dist/templates/link-digest-workflow/agent.test.ts +84 -164
  222. package/dist/templates/link-digest-workflow/agent.ts +27 -42
  223. package/dist/templates/link-digest-workflow/api-client.ts +3 -2
  224. package/dist/templates/link-digest-workflow/client.tsx +5 -5
  225. package/dist/templates/link-digest-workflow/workflows/digest.ts +53 -95
  226. package/dist/templates/medication-safety-agent/agent.eval.test.ts +10 -30
  227. package/dist/templates/medication-safety-agent/agent.test.ts +16 -46
  228. package/dist/templates/medication-safety-agent/agent.ts +1 -4
  229. package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +13 -10
  230. package/dist/templates/meeting-recap-agent/agent.eval.test.ts +238 -396
  231. package/dist/templates/meeting-recap-agent/agent.test.ts +414 -1070
  232. package/dist/templates/meeting-recap-agent/agent.ts +26 -67
  233. package/dist/templates/meeting-recap-agent/system-prompt.md +1 -0
  234. package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +10 -12
  235. package/dist/templates/meeting-recap-agent/tools/request_recap.ts +9 -20
  236. package/dist/templates/meeting-recap-agent/workflows/recap.ts +224 -547
  237. package/dist/templates/outbound-call-agent/agent.eval.test.ts +10 -12
  238. package/dist/templates/outbound-call-agent/agent.test.ts +419 -453
  239. package/dist/templates/outbound-call-agent/agent.ts +57 -62
  240. package/dist/templates/outbound-call-agent/api.ts +53 -68
  241. package/dist/templates/outbound-call-agent/client.tsx +105 -176
  242. package/dist/templates/outbound-call-agent/shared.ts +10 -39
  243. package/dist/templates/outbound-call-agent/system-prompt.md +3 -4
  244. package/dist/templates/outbound-call-agent/tools/end_call.ts +15 -12
  245. package/dist/templates/outbound-call-agent/tools/press_keys.ts +8 -13
  246. package/dist/templates/outbound-call-agent/workflows/call.ts +89 -62
  247. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +18 -54
  248. package/dist/templates/pizza-ordering-agent/agent.test.ts +205 -244
  249. package/dist/templates/pizza-ordering-agent/agent.ts +5 -12
  250. package/dist/templates/pizza-ordering-agent/client.tsx +3 -14
  251. package/dist/templates/pizza-ordering-agent/shared.ts +31 -36
  252. package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +1 -0
  253. package/dist/templates/pizza-ordering-agent/tools/place_order.ts +5 -2
  254. package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +1 -0
  255. package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +2 -3
  256. package/dist/templates/pizza-ordering-agent/tools/view_order.ts +7 -3
  257. package/dist/templates/podcast-digest-workflow/agent.test.ts +53 -102
  258. package/dist/templates/podcast-digest-workflow/agent.ts +11 -17
  259. package/dist/templates/podcast-digest-workflow/client.tsx +29 -51
  260. package/dist/templates/podcast-digest-workflow/workflows/digest.ts +24 -26
  261. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +13 -14
  262. package/dist/templates/push-to-talk-agent/agent.test.ts +30 -23
  263. package/dist/templates/push-to-talk-agent/agent.ts +1 -5
  264. package/dist/templates/push-to-talk-agent/client.tsx +1 -11
  265. package/dist/templates/push-to-talk-agent/shared.ts +12 -6
  266. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +1 -0
  267. package/dist/templates/push-to-talk-agent/tools/save_note.ts +1 -0
  268. package/dist/templates/quickstart-agent/agent.eval.test.ts +0 -10
  269. package/dist/templates/quickstart-agent/agent.test.ts +18 -30
  270. package/dist/templates/quickstart-agent/agent.ts +3 -4
  271. package/dist/templates/research-handoff-agent/agent.eval.test.ts +161 -290
  272. package/dist/templates/research-handoff-agent/agent.test.ts +131 -457
  273. package/dist/templates/research-handoff-agent/agent.ts +26 -86
  274. package/dist/templates/research-handoff-agent/system-prompt.md +1 -0
  275. package/dist/templates/research-handoff-agent/tools/file_it_now.ts +8 -21
  276. package/dist/templates/research-handoff-agent/tools/request_research.ts +7 -16
  277. package/dist/templates/research-handoff-agent/workflows/research.ts +88 -40
  278. package/dist/templates/research-planner-agent/agent.eval.test.ts +15 -40
  279. package/dist/templates/research-planner-agent/agent.test.ts +415 -464
  280. package/dist/templates/research-planner-agent/agent.ts +3 -8
  281. package/dist/templates/research-planner-agent/client.tsx +1 -14
  282. package/dist/templates/research-planner-agent/procedure.ts +9 -3
  283. package/dist/templates/research-planner-agent/shared.ts +30 -33
  284. package/dist/templates/research-planner-agent/tools/plan_status.ts +7 -15
  285. package/dist/templates/research-planner-agent/tools/revise_plan.ts +29 -36
  286. package/dist/templates/research-planner-agent/tools/start_plan.ts +25 -39
  287. package/dist/templates/research-planner-agent/tools/work_next_step.ts +25 -42
  288. package/dist/templates/retail-orders-agent/agent.eval.test.ts +14 -34
  289. package/dist/templates/retail-orders-agent/agent.test.ts +1079 -1073
  290. package/dist/templates/retail-orders-agent/agent.ts +25 -78
  291. package/dist/templates/retail-orders-agent/client.tsx +120 -168
  292. package/dist/templates/retail-orders-agent/pending.test.ts +7 -14
  293. package/dist/templates/retail-orders-agent/registry.test.ts +93 -192
  294. package/dist/templates/retail-orders-agent/shared.test.ts +1 -1
  295. package/dist/templates/retail-orders-agent/shared.ts +10 -20
  296. package/dist/templates/retail-orders-agent/store.test.ts +46 -128
  297. package/dist/templates/retail-orders-agent/store.ts +42 -175
  298. package/dist/templates/retail-orders-agent/tools/cancel_change.ts +3 -6
  299. package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +3 -4
  300. package/dist/templates/retail-orders-agent/tools/confirm_change.ts +4 -6
  301. package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +3 -4
  302. package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +3 -4
  303. package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +3 -4
  304. package/dist/templates/retail-orders-agent/tools/get_item_details.ts +3 -4
  305. package/dist/templates/retail-orders-agent/tools/get_order_details.ts +3 -4
  306. package/dist/templates/retail-orders-agent/tools/get_product_details.ts +3 -4
  307. package/dist/templates/retail-orders-agent/tools/get_user_details.ts +3 -4
  308. package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +3 -8
  309. package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +3 -4
  310. package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +3 -4
  311. package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +3 -4
  312. package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +3 -4
  313. package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +3 -4
  314. package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +3 -4
  315. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +22 -25
  316. package/dist/templates/roadside-assistance-agent/agent.test.ts +453 -490
  317. package/dist/templates/roadside-assistance-agent/agent.ts +28 -60
  318. package/dist/templates/roadside-assistance-agent/call.ts +16 -22
  319. package/dist/templates/roadside-assistance-agent/shared.ts +24 -54
  320. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +29 -37
  321. package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +44 -70
  322. package/dist/templates/roadside-assistance-agent/tools/job_status.ts +16 -24
  323. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +39 -51
  324. package/dist/templates/roadside-assistance-agent/tools/report_location.ts +34 -33
  325. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +18 -39
  326. package/dist/templates/roadside-assistance-agent/yard.test.ts +22 -19
  327. package/dist/templates/roadside-assistance-agent/yard.ts +3 -3
  328. package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +38 -40
  329. package/dist/templates/spoken-summary-workflow/agent.test.ts +129 -279
  330. package/dist/templates/spoken-summary-workflow/agent.ts +15 -40
  331. package/dist/templates/spoken-summary-workflow/client.tsx +13 -25
  332. package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +52 -92
  333. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +31 -74
  334. package/dist/templates/tabletop-rpg-agent/agent.test.ts +756 -774
  335. package/dist/templates/tabletop-rpg-agent/agent.ts +9 -46
  336. package/dist/templates/tabletop-rpg-agent/client.tsx +13 -21
  337. package/dist/templates/tabletop-rpg-agent/shared.ts +40 -99
  338. package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +67 -83
  339. package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +65 -88
  340. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +8 -27
  341. package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +18 -36
  342. package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +101 -111
  343. package/dist/templates/technical-support-agent/agent.eval.test.ts +31 -72
  344. package/dist/templates/technical-support-agent/agent.test.ts +231 -260
  345. package/dist/templates/technical-support-agent/agent.ts +4 -10
  346. package/dist/templates/technical-support-agent/client.tsx +4 -18
  347. package/dist/templates/technical-support-agent/shared.ts +15 -25
  348. package/dist/templates/technical-support-agent/tools/answer_question.ts +46 -56
  349. package/dist/templates/technical-support-agent/tools/list_topics.ts +1 -0
  350. package/dist/templates/technical-support-agent/tools/log_ticket.ts +8 -5
  351. package/dist/templates/text-adventure-agent/agent.eval.test.ts +37 -126
  352. package/dist/templates/text-adventure-agent/agent.test.ts +197 -368
  353. package/dist/templates/text-adventure-agent/agent.ts +15 -65
  354. package/dist/templates/text-adventure-agent/client.tsx +38 -98
  355. package/dist/templates/text-adventure-agent/shared.ts +31 -143
  356. package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +6 -12
  357. package/dist/templates/text-adventure-agent/tools/game_state_get.ts +4 -11
  358. package/dist/templates/text-adventure-agent/tools/game_state_move.ts +0 -2
  359. package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +1 -3
  360. package/dist/templates/text-adventure-agent/tools/game_state_score.ts +5 -7
  361. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +12 -50
  362. package/dist/templates/topic-briefing-agent/agent.test.ts +478 -476
  363. package/dist/templates/topic-briefing-agent/agent.ts +3 -3
  364. package/dist/templates/topic-briefing-agent/shared.ts +11 -16
  365. package/dist/templates/topic-briefing-agent/slack.ts +12 -4
  366. package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +10 -17
  367. package/dist/templates/topic-briefing-agent/tools/research_topic.ts +21 -24
  368. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +13 -14
  369. package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +16 -13
  370. package/dist/templates/transcription-workflow/agent.test.ts +114 -259
  371. package/dist/templates/transcription-workflow/agent.ts +6 -9
  372. package/dist/templates/transcription-workflow/client.tsx +100 -258
  373. package/dist/templates/transcription-workflow/recover.test.ts +6 -136
  374. package/dist/templates/transcription-workflow/recover.ts +14 -97
  375. package/dist/templates/transcription-workflow/run-panel.tsx +71 -8
  376. package/dist/templates/transcription-workflow/workflows/batch.ts +28 -159
  377. package/dist/templates/transcription-workflow/workflows/normalize.ts +50 -86
  378. package/dist/templates/transcription-workflow/workflows/stream.ts +2 -2
  379. package/dist/templates/transcription-workflow/workflows/transcribe.ts +16 -23
  380. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +7 -25
  381. package/dist/templates/travel-concierge-agent/agent.test.ts +505 -517
  382. package/dist/templates/travel-concierge-agent/agent.ts +22 -46
  383. package/dist/templates/travel-concierge-agent/client.tsx +1 -22
  384. package/dist/templates/travel-concierge-agent/routing.ts +29 -31
  385. package/dist/templates/travel-concierge-agent/shared.ts +63 -152
  386. package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +8 -9
  387. package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +8 -8
  388. package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +9 -6
  389. package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +10 -10
  390. package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +3 -2
  391. package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +3 -2
  392. package/dist/templates/travel-concierge-agent/tools/search_flights.ts +4 -3
  393. package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +3 -2
  394. package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +13 -8
  395. package/dist/templates/web-research-agent/agent.test.ts +19 -30
  396. package/dist/templates/web-research-agent/agent.ts +3 -4
  397. package/dist/templates/word-game-agent/agent.eval.test.ts +47 -67
  398. package/dist/templates/word-game-agent/agent.test.ts +369 -382
  399. package/dist/templates/word-game-agent/agent.ts +2 -5
  400. package/dist/templates/word-game-agent/client.tsx +1 -8
  401. package/dist/templates/word-game-agent/game.ts +15 -27
  402. package/dist/templates/word-game-agent/shared.ts +36 -20
  403. package/dist/templates/word-game-agent/tools/final_score.ts +14 -13
  404. package/dist/templates/word-game-agent/tools/relay_description.ts +90 -66
  405. package/dist/templates/word-game-agent/tools/repeat_word.ts +11 -10
  406. package/dist/templates/word-game-agent/tools/skip_word.ts +17 -21
  407. package/dist/templates/word-game-agent/tools/start_game.ts +26 -30
  408. package/dist/{test-XufelYGW.mjs → test-CW5cw5fy.mjs} +3 -4
  409. package/dist/typecheck.mjs +1 -1
  410. package/dist/worker-bundler-D8uCzpYP.mjs +335 -0
  411. package/dist/worker-bundler.d.ts +39 -0
  412. package/dist/worker-bundler.mjs +2 -155
  413. package/dist/{workflow-CDUlTD5B.mjs → workflow-5gOZMB2M.mjs} +66 -19
  414. package/package.json +4 -4
  415. package/dist/_output-DBP9Op_d.mjs +0 -120
  416. package/dist/_studio-B5m4jBTD.mjs +0 -256
  417. package/dist/_ui-Coe0zwmm.mjs +0 -102
  418. package/dist/_utils-BVLdBvdT.mjs +0 -186
  419. package/dist/delete-DwXCHzTl.mjs +0 -55
  420. package/dist/templates/document-redline-workflow/form.ts +0 -73
  421. package/dist/templates/emergency-dispatch-agent/events.ts +0 -48
  422. package/dist/templates/hotel-reception-agent/events.ts +0 -80
  423. package/dist/templates/meeting-recap-agent/shared.ts +0 -44
  424. package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +0 -25
  425. package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +0 -24
  426. package/dist/templates/meeting-recap-agent/tools/recap_status.ts +0 -45
  427. package/dist/templates/meeting-recap-agent/workflows/tokens.ts +0 -47
  428. package/dist/templates/outbound-call-agent/call-params.ts +0 -109
  429. package/dist/templates/outbound-call-agent/live-calls.ts +0 -80
  430. package/dist/templates/outbound-call-agent/workflows/tokens.ts +0 -16
  431. package/dist/templates/research-handoff-agent/shared.ts +0 -41
  432. package/dist/templates/research-handoff-agent/tools/research_progress.ts +0 -23
  433. package/dist/templates/research-handoff-agent/tools/research_status.ts +0 -73
  434. package/dist/templates/research-handoff-agent/workflows/review.ts +0 -43
  435. package/dist/templates/roadside-assistance-agent/events.ts +0 -92
  436. package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +0 -137
  437. package/dist/templates/transcription-workflow/total-latency.tsx +0 -170
  438. package/dist/templates/travel-concierge-agent/call-events.ts +0 -80
@@ -1,16 +1,19 @@
1
1
  /** The def a DEPLOYED agent runs: authored, plus what `tools/` and the prompt add. */
2
2
  import agentDef from "virtual:aai/agent";
3
- import type { SessionEvent, ToolContext } from "@alexkroman1/aai";
3
+ import type { ToolContext, ToolDef } from "@alexkroman1/aai";
4
4
  import { isToolFailure } from "@alexkroman1/aai";
5
5
  import {
6
6
  createToolContext,
7
7
  expectDialogOk,
8
8
  expectDialogRefused,
9
+ expectSlotContract,
9
10
  expectToolOk,
10
- runTool,
11
+ fireEvent,
12
+ sessionEvent,
11
13
  toolInputIssues,
12
- toolRunner,
14
+ toolNameOf,
13
15
  } from "@alexkroman1/aai-runtime/testing";
16
+ import { describeAgent } from "@alexkroman1/aai-runtime/testing/vitest";
14
17
  import { describe, expect, test } from "vitest";
15
18
  import { luhnOk, validateCard } from "./card.ts";
16
19
  import { deskFlow } from "./desk.ts";
@@ -31,1091 +34,1104 @@ import {
31
34
  TODAY,
32
35
  } from "./records.ts";
33
36
  import { hotelSlot } from "./session.ts";
34
- import { deskView } from "./shared.ts";
37
+ import { deskView, emptyHotelState } from "./shared.ts";
38
+ import abandonBooking from "./tools/abandon_booking.ts";
35
39
  import bookAirportCar from "./tools/book_airport_car.ts";
36
40
  import bookBusinessCenter from "./tools/book_business_center.ts";
37
41
  import bookSpaAppointment from "./tools/book_spa_appointment.ts";
38
42
  import bookTour from "./tools/book_tour.ts";
43
+ import cancelRestaurantReservation from "./tools/cancel_restaurant_reservation.ts";
39
44
  import cancelRoomBooking from "./tools/cancel_room_booking.ts";
40
45
  import checkRestaurantAvailability from "./tools/check_restaurant_availability.ts";
41
46
  import checkRoomAvailability from "./tools/check_room_availability.ts";
47
+ import chooseRoom from "./tools/choose_room.ts";
48
+ import confirmBooking from "./tools/confirm_booking.ts";
42
49
  import dispatchEmergency from "./tools/dispatch_emergency.ts";
43
50
  import disputeCharge from "./tools/dispute_charge.ts";
51
+ import flagLateArrival from "./tools/flag_late_arrival.ts";
44
52
  import lookupBooking from "./tools/lookup_booking.ts";
45
53
  import lookupInvoice from "./tools/lookup_invoice.ts";
46
54
  import lookupPolicy from "./tools/lookup_policy.ts";
55
+ import lookupRestaurantReservation from "./tools/lookup_restaurant_reservation.ts";
47
56
  import modifyRestaurantReservation from "./tools/modify_restaurant_reservation.ts";
57
+ import orderFlowers from "./tools/order_flowers.ts";
58
+ import recordCard from "./tools/record_card.ts";
48
59
  import recordFollowup from "./tools/record_followup.ts";
60
+ import recordGroupInquiry from "./tools/record_group_inquiry.ts";
61
+ import recordGuestDetails from "./tools/record_guest_details.ts";
49
62
  import reinstateBooking from "./tools/reinstate_booking.ts";
63
+ import requestFlightReconfirmation from "./tools/request_flight_reconfirmation.ts";
50
64
  import resendConfirmation from "./tools/resend_confirmation.ts";
51
65
  import reserveTable from "./tools/reserve_table.ts";
52
66
  import resolveRoomConflict from "./tools/resolve_room_conflict.ts";
53
67
  import scheduleWakeupCall from "./tools/schedule_wakeup_call.ts";
68
+ import setExtras from "./tools/set_extras.ts";
69
+ import setStay from "./tools/set_stay.ts";
70
+ import startBookingModification from "./tools/start_booking_modification.ts";
71
+ import startRoomBooking from "./tools/start_room_booking.ts";
54
72
  import takeGuestMessage from "./tools/take_guest_message.ts";
55
73
  import transferCall from "./tools/transfer_call.ts";
56
74
  import updateCard from "./tools/update_card.ts";
57
75
  import verifyBooking from "./tools/verify_booking.ts";
58
76
 
59
- // ─── Harness ─────────────────────────────────────────────────────────────────
77
+ describeAgent(agentDef, (run) => {
78
+ // ─── Harness ─────────────────────────────────────────────────────────────────
60
79
 
61
- /** A tool by the name the model calls it by, bound to this agent. */
62
- const run = toolRunner(agentDef);
80
+ /** What the runtime offers the desk dialog when the caller says something. */
81
+ const HEARD_SOMETHING = sessionEvent("userTranscript.committed", { text: "yes, that's right" });
63
82
 
64
- /** What the runtime offers the desk dialog when the caller says something. */
65
- const HEARD_SOMETHING: SessionEvent = {
66
- type: "userTranscript.committed",
67
- text: "yes, that's right",
68
- meta: { id: "evt_1", at: 0 },
69
- };
83
+ /** And when they hang up. */
84
+ const CALLER_GONE = sessionEvent("session.timedOut");
70
85
 
71
- /** And when they hang up. */
72
- const CALLER_GONE: SessionEvent = { type: "session.timedOut", meta: { id: "evt_2", at: 0 } };
86
+ /** Where the call is, without going through a tool. */
87
+ const at = (ctx: ToolContext) => deskFlow.position(ctx).state;
73
88
 
74
- /** Where the call is, without going through a tool. */
75
- const at = (ctx: ToolContext) => deskFlow.position(ctx).state;
89
+ /** The caller answers — their next committed turn is what discharges an owed read-back. */
90
+ const callerAnswers = (ctx: ToolContext) => deskFlow.receive(ctx, HEARD_SOMETHING).state;
76
91
 
77
- /** The caller answers — their next committed turn is what discharges an owed read-back. */
78
- const callerAnswers = (ctx: ToolContext) => deskFlow.receive(ctx, HEARD_SOMETHING).state;
92
+ /** A context `n` caller turns in — what the idempotency guards read. */
93
+ const withCallerTurns = (n: number) => createToolContext({ turn: n });
79
94
 
80
- /** A context whose history holds `n` caller turns — what the idempotency guards read. */
81
- const withCallerTurns = (n: number) =>
82
- createToolContext({
83
- messages: Array.from({ length: n }, (_, i) => ({
84
- role: "user" as const,
85
- content: `turn ${i}`,
86
- })),
87
- });
88
-
89
- /** Verify as a seeded guest, the way the model has to. */
90
- async function verify(ctx: ToolContext, lastName: string, confirmationCode: string) {
91
- return expectToolOk(await runTool(verifyBooking, { lastName, confirmationCode }, ctx));
92
- }
93
-
94
- const A_CARD = {
95
- cardNumber: "4532 0000 0001 4471",
96
- expiryMonth: 12,
97
- expiryYear: 29,
98
- securityCode: "321",
99
- cardholderName: "Maria Whitfield",
100
- };
101
-
102
- /** Walk a fresh call through a whole new booking up to the read-back. */
103
- async function bookUpToReadBack(ctx: ToolContext) {
104
- expectDialogOk(await run("start_room_booking", ctx));
105
- expectDialogOk(
106
- await run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
107
- );
108
- expectDialogOk(await run("choose_room", { roomType: "queen_2beds", view: "garden" }, ctx));
109
- expectDialogOk(
110
- await run(
111
- "set_extras",
112
- { breakfast: false, valet: false, lateCheckout: false, pets: false },
113
- ctx,
114
- ),
115
- );
116
- expectDialogOk(
117
- await run(
118
- "record_guest_details",
119
- {
120
- firstName: "Maria",
121
- lastName: "Whitfield",
122
- email: "Maria.Whitfield@gmail.com",
123
- phone: "123-555-0170",
124
- },
125
- ctx,
126
- ),
127
- );
128
- expectDialogOk(await run("record_card", A_CARD, ctx));
129
- }
130
-
131
- // ─── 1. Records: money, dates, codes ─────────────────────────────────────────
132
-
133
- describe("records.ts", () => {
134
- test("a stay is priced once, with tax, and the line items add up to the total", () => {
135
- const priced = computeInvoice(24_000, 2, ["breakfast"]);
136
- expect(priced).toMatchObject({ subtotal: 53_000, taxes: 6360, total: 59_360 });
137
- expect(priced.lineItems.reduce((sum, li) => sum + li.amount, 0)).toBe(priced.total);
138
- expect(priced.lineItems.map((li) => li.label)).toEqual([
139
- "Room (2 nights)",
140
- "Breakfast (2 nights)",
141
- `Tax (${PRICING.taxRatePct}%)`,
142
- ]);
143
- });
144
-
145
- test("money and codes are spoken the way a phone needs them", () => {
146
- expect(speakUsd(24_000)).toBe("240 dollars");
147
- expect(speakUsd(24_050)).toBe("240 dollars and 50 cents");
148
- // The dash is the WORD "dash", not four more letters.
149
- expect(speakCode("HTL-AB12")).toBe("H, T, L, dash, A, B, 1, 2");
150
- });
95
+ /** Verify as a seeded guest, the way the model has to. */
96
+ async function verify(ctx: ToolContext, lastName: string, confirmationCode: string) {
97
+ return expectToolOk(await run(verifyBooking, { lastName, confirmationCode }, ctx));
98
+ }
151
99
 
152
- test("dates: TODAY is the simulation pin, and the helpers agree with the calendar", () => {
153
- expect(TODAY).toBe("2026-06-08");
154
- expect(spokenDate(TODAY)).toBe("Monday, June 8");
155
- expect(addDays(TODAY, 25)).toBe("2026-07-03");
156
- expect(daysBetween("2026-07-14", "2026-07-17")).toBe(3);
157
- expect(spokenTime("19:30")).toBe("7:30 PM");
158
- expect(spokenTime("21:00")).toBe("9 PM");
159
- expect(isIsoDate("2026-02-30")).toBe(false);
160
- expect(isIsoDate("2026-06-08")).toBe(true);
161
- });
162
-
163
- test("every date a tool takes is refused by its SCHEMA, before the body runs", async () => {
164
- // The rule used to be ten hand-written `if (!isIsoDate(...)) return
165
- // toolFailure(...)` lines, so it reached the model only by failing and each
166
- // tool worded it differently. `isoDate` declares it on the field, which is
167
- // what `executeToolCall` validates against before it calls `execute` —
168
- // asserted through `toolInputIssues`, which is the SDK's reader for exactly
169
- // this: `toolRunner` deliberately passes arguments straight through, so a
170
- // tool driven through it never meets its own schema.
171
- const dated: [string, Record<string, unknown>][] = [
172
- ["check_restaurant_availability", { partySize: 2 }],
173
- ["check_room_availability", { checkIn: "2026-06-09", guests: 2 }],
174
- ["schedule_wakeup_call", { room: "412", time: "07:00" }],
175
- ];
176
- for (const [name, rest] of dated) {
177
- const field = name === "check_room_availability" ? "checkOut" : "date";
178
- for (const value of ["2026-02-30", "next tuesday"]) {
179
- const issues = await toolInputIssues(agentDef, name, { ...rest, [field]: value });
180
- expect(JSON.stringify(issues), `${name} accepted ${value}`).toMatch(/YYYY-MM-DD/);
181
- }
182
- }
183
- });
100
+ const A_CARD = {
101
+ cardNumber: "4532 0000 0001 4471",
102
+ expiryMonth: 12,
103
+ expiryYear: 29,
104
+ securityCode: "321",
105
+ cardholderName: "Maria Whitfield",
106
+ };
184
107
 
185
- test("a minted code carries no character a caller could mishear as another", () => {
186
- for (let i = 0; i < 50; i++)
187
- expect(mintCode("HTL")).toMatch(/^HTL-[ABCDEFGHJKMNPQRSTUVWXYZ2-9]{4}$/);
188
- expect(mintCode("X", new Set())).not.toBe(mintCode("X", new Set()));
189
- });
190
-
191
- test("the card check is Luhn, and every refusal names one field", () => {
192
- expect(luhnOk("4532000000014471")).toBe(true);
193
- expect(luhnOk("4532000000014472")).toBe(false);
194
- const ok = validateCard(A_CARD);
195
- expect(ok).toMatchObject({ last4: "4471", issuer: "Visa", expiry: "12/29" });
196
- expect(validateCard({ ...A_CARD, cardNumber: "4532 0000 0001 4472" })).toMatchObject({
197
- error: expect.stringContaining("one digit is likely off"),
198
- });
199
- expect(validateCard({ ...A_CARD, expiryYear: 2025 })).toMatchObject({
200
- error: expect.stringContaining("expired"),
108
+ /** Walk a fresh call through a whole new booking up to the read-back. */
109
+ async function bookUpToReadBack(ctx: ToolContext) {
110
+ expectDialogOk(await run(startRoomBooking, ctx));
111
+ expectDialogOk(
112
+ await run(setStay, { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
113
+ );
114
+ expectDialogOk(await run(chooseRoom, { roomType: "queen_2beds", view: "garden" }, ctx));
115
+ expectDialogOk(
116
+ await run(
117
+ setExtras,
118
+ { breakfast: false, valet: false, lateCheckout: false, pets: false },
119
+ ctx,
120
+ ),
121
+ );
122
+ expectDialogOk(
123
+ await run(
124
+ recordGuestDetails,
125
+ {
126
+ firstName: "Maria",
127
+ lastName: "Whitfield",
128
+ email: "Maria.Whitfield@gmail.com",
129
+ phone: "123-555-0170",
130
+ },
131
+ ctx,
132
+ ),
133
+ );
134
+ expectDialogOk(await run(recordCard, A_CARD, ctx));
135
+ }
136
+
137
+ // ─── 1. Records: money, dates, codes ─────────────────────────────────────────
138
+
139
+ describe("records.ts", () => {
140
+ test("a stay is priced once, with tax, and the line items add up to the total", () => {
141
+ const priced = computeInvoice(24_000, 2, ["breakfast"]);
142
+ expect(priced).toMatchObject({ subtotal: 53_000, taxes: 6360, total: 59_360 });
143
+ expect(priced.lineItems.reduce((sum, li) => sum + li.amount, 0)).toBe(priced.total);
144
+ expect(priced.lineItems.map((li) => li.label)).toEqual([
145
+ "Room (2 nights)",
146
+ "Breakfast (2 nights)",
147
+ `Tax (${PRICING.taxRatePct}%)`,
148
+ ]);
201
149
  });
202
- expect(validateCard({ ...A_CARD, securityCode: "12" })).toMatchObject({
203
- error: expect.stringContaining("3 or 4 digits"),
150
+
151
+ test("money and codes are spoken the way a phone needs them", () => {
152
+ expect(speakUsd(24_000)).toBe("240 dollars");
153
+ expect(speakUsd(24_050)).toBe("240 dollars and 50 cents");
154
+ // The dash is the WORD "dash", not four more letters.
155
+ expect(speakCode("HTL-AB12")).toBe("H, T, L, dash, A, B, 1, 2");
204
156
  });
205
- });
206
- });
207
157
 
208
- // ─── 2. The seed's scenarios are the spec's ──────────────────────────────────
158
+ test("dates: TODAY is the simulation pin, and the helpers agree with the calendar", () => {
159
+ expect(TODAY).toBe("2026-06-08");
160
+ expect(spokenDate(TODAY)).toBe("Monday, June 8");
161
+ expect(addDays(TODAY, 25)).toBe("2026-07-03");
162
+ expect(daysBetween("2026-07-14", "2026-07-17")).toBe(3);
163
+ expect(spokenTime("19:30")).toBe("7:30 PM");
164
+ expect(spokenTime("21:00")).toBe("9 PM");
165
+ expect(isIsoDate("2026-02-30")).toBe(false);
166
+ expect(isIsoDate("2026-06-08")).toBe(true);
167
+ });
209
168
 
210
- describe("the seeded hotel", () => {
211
- test("tonight, the only free room is the garden queen the seed keeps for Robert Klein", () => {
212
- const ctx = createToolContext();
213
- const tonight = listRoomOptions(hotelSlot.get(ctx), {
214
- checkIn: TODAY,
215
- checkOut: addDays(TODAY, 1),
216
- guests: 2,
169
+ test("every date a tool takes is refused by its SCHEMA, before the body runs", async () => {
170
+ // The rule used to be ten hand-written `if (!isIsoDate(...)) return
171
+ // toolFailure(...)` lines, so it reached the model only by failing and each
172
+ // tool worded it differently. `isoDate` declares it on the field, which is
173
+ // what `executeToolCall` validates against before it calls `execute` —
174
+ // asserted through `toolInputIssues`, which is the SDK's reader for exactly
175
+ // this: `toolRunner` deliberately passes arguments straight through, so a
176
+ // tool driven through it never meets its own schema.
177
+ const dated: [ToolDef, string, Record<string, unknown>][] = [
178
+ [checkRestaurantAvailability, "date", { partySize: 2 }],
179
+ [checkRoomAvailability, "checkOut", { checkIn: "2026-06-09", guests: 2 }],
180
+ [scheduleWakeupCall, "date", { room: "412", time: "07:00" }],
181
+ ];
182
+ for (const [def, field, rest] of dated) {
183
+ for (const value of ["2026-02-30", "next tuesday"]) {
184
+ const issues = await toolInputIssues(def, { ...rest, [field]: value });
185
+ expect(JSON.stringify(issues), `${toolNameOf(def)} accepted ${value}`).toMatch(
186
+ /YYYY-MM-DD/,
187
+ );
188
+ }
189
+ }
217
190
  });
218
- expect(tonight).toEqual([{ type: "queen_2beds", view: "garden", nightlyRate: 22_000 }]);
219
- });
220
191
 
221
- test("Friday July 3 is sold out, and the desk says so rather than inventing a room", async () => {
222
- const empty = expectToolOk(
223
- await runTool(checkRoomAvailability, {
224
- checkIn: "2026-07-03",
225
- checkOut: "2026-07-04",
226
- guests: 2,
227
- }),
228
- );
229
- expect(empty.available).toBe(false);
230
- expect(empty.message).toMatch(/add_to_waitlist/);
231
- const open = expectToolOk(
232
- await runTool(checkRoomAvailability, {
233
- checkIn: "2026-07-14",
234
- checkOut: "2026-07-17",
235
- guests: 2,
236
- }),
237
- );
238
- expect(open.available).toBe(true);
239
- expect(open.options).toContain("queen 2beds, garden view: 220 dollars/night");
240
- });
192
+ test("a minted code carries no character a caller could mishear as another", () => {
193
+ for (let i = 0; i < 50; i++)
194
+ expect(mintCode("HTL")).toMatch(/^HTL-[ABCDEFGHJKMNPQRSTUVWXYZ2-9]{4}$/);
195
+ expect(mintCode("X", new Set())).not.toBe(mintCode("X", new Set()));
196
+ });
241
197
 
242
- test("the projection counts the house from the same records the tools read", () => {
243
- const view = deskView(hotelSlot.get(createToolContext()));
244
- expect(view).toMatchObject({
245
- verified: null,
246
- draft: null,
247
- ledger: [],
248
- inHouse: 13,
249
- arrivingToday: 5,
198
+ test("the card check is Luhn, and every refusal names one field", () => {
199
+ expect(luhnOk("4532000000014471")).toBe(true);
200
+ expect(luhnOk("4532000000014472")).toBe(false);
201
+ const ok = validateCard(A_CARD);
202
+ expect(ok).toMatchObject({ last4: "4471", issuer: "Visa", expiry: "12/29" });
203
+ expect(validateCard({ ...A_CARD, cardNumber: "4532 0000 0001 4472" })).toMatchObject({
204
+ error: expect.stringContaining("one digit is likely off"),
205
+ });
206
+ expect(validateCard({ ...A_CARD, expiryYear: 2025 })).toMatchObject({
207
+ error: expect.stringContaining("expired"),
208
+ });
209
+ expect(validateCard({ ...A_CARD, securityCode: "12" })).toMatchObject({
210
+ error: expect.stringContaining("3 or 4 digits"),
211
+ });
250
212
  });
251
- // The pre-first-tool-call frame the client renders is the same function.
252
- expect(hotelSlot.projected()).toEqual(view);
253
213
  });
254
- });
255
214
 
256
- // ─── 3. Verification is the tools' job ───────────────────────────────────────
257
-
258
- describe("verification", () => {
259
- test("every booking tool refuses until verify_booking has run, naming it", async () => {
260
- const ctx = createToolContext();
261
- for (const name of [
262
- "lookup_booking",
263
- "lookup_invoice",
264
- "cancel_room_booking",
265
- "resolve_room_conflict",
266
- ]) {
267
- const refused = await run(name, ctx);
268
- expect(isToolFailure(refused) && refused.error).toMatch(/verify_booking/);
269
- }
270
- expect(isToolFailure(await run("flag_late_arrival", { note: "around 1 AM" }, ctx))).toBe(true);
271
- });
215
+ // ─── 2. The seed's scenarios are the spec's ──────────────────────────────────
272
216
 
273
- test("last name plus code, or last name plus the card's last four — and nothing else", async () => {
274
- const byCode = createToolContext();
275
- expect((await verify(byCode, "Smith", "h t l dash a b 1 2")).code).toBe("HTL-AB12");
276
- expect(hotelSlot.get(byCode).verifiedCode).toBe("HTL-AB12");
217
+ describe("the seeded hotel", () => {
218
+ test("tonight, the only free room is the garden queen the seed keeps for Robert Klein", () => {
219
+ const ctx = createToolContext();
220
+ const tonight = listRoomOptions(hotelSlot.get(ctx), {
221
+ checkIn: TODAY,
222
+ checkOut: addDays(TODAY, 1),
223
+ guests: 2,
224
+ });
225
+ expect(tonight).toEqual([{ type: "queen_2beds", view: "garden", nightlyRate: 22_000 }]);
226
+ });
277
227
 
278
- const byCard = createToolContext();
279
- expectToolOk(await run("verify_booking", { lastName: "smith", cardLast4: "4242" }, byCard));
280
- expect(hotelSlot.get(byCard).verifiedCode).toBe("HTL-AB12");
228
+ test("Friday July 3 is sold out, and the desk says so rather than inventing a room", async () => {
229
+ const empty = expectToolOk(
230
+ await run(checkRoomAvailability, {
231
+ checkIn: "2026-07-03",
232
+ checkOut: "2026-07-04",
233
+ guests: 2,
234
+ }),
235
+ );
236
+ expect(empty.available).toBe(false);
237
+ expect(empty.message).toMatch(/add_to_waitlist/);
238
+ const open = expectToolOk(
239
+ await run(checkRoomAvailability, {
240
+ checkIn: "2026-07-14",
241
+ checkOut: "2026-07-17",
242
+ guests: 2,
243
+ }),
244
+ );
245
+ expect(open.available).toBe(true);
246
+ expect(open.options).toContain("queen 2beds, garden view: 220 dollars/night");
247
+ });
281
248
 
282
- const nothing = await run("verify_booking", { lastName: "Smith" });
283
- expect(isToolFailure(nothing) && nothing.error).toMatch(/PLUS/);
249
+ test("the projection counts the house from the same records the tools read", () => {
250
+ const view = deskView(hotelSlot.get(createToolContext()));
251
+ expect(view).toMatchObject({
252
+ verified: null,
253
+ draft: null,
254
+ ledger: [],
255
+ inHouse: 13,
256
+ arrivingToday: 5,
257
+ });
258
+ // What the slot projects before a tool has run is the EMPTY frame — the
259
+ // one `client.tsx` builds for itself — never the seed.
260
+ expect(hotelSlot.projected()).toEqual(deskView(emptyHotelState()));
261
+ expect(hotelSlot.projected()).toMatchObject({ inHouse: 0, arrivingToday: 0 });
262
+ // The same claim as the slot's contract, with the other two invariants:
263
+ // the frame is the view of `empty()`, a session's writes stay its own, and
264
+ // the log cap keeps the newest forty lines.
265
+ expectSlotContract(hotelSlot, {
266
+ write: (draft) => {
267
+ draft.log.push("probe");
268
+ },
269
+ });
270
+ });
284
271
  });
285
272
 
286
- test("three strikes, and the refusal routes to a verification_help followup", async () => {
287
- const ctx = createToolContext();
288
- const first = await run(
289
- "verify_booking",
290
- { lastName: "Smith", confirmationCode: "HTL-0000" },
291
- ctx,
292
- );
293
- expect(isToolFailure(first) && first.error).toMatch(/Attempt 1 of 3/);
294
- await run("verify_booking", { lastName: "Smith", confirmationCode: "HTL-0000" }, ctx);
295
- const third = await run(
296
- "verify_booking",
297
- { lastName: "Smith", confirmationCode: "HTL-0000" },
298
- ctx,
299
- );
300
- expect(isToolFailure(third) && third.error).toMatch(/verification_help/);
301
- expect(hotelSlot.get(ctx).verifiedCode).toBeNull();
302
- });
273
+ // ─── 3. Verification is the tools' job ───────────────────────────────────────
303
274
 
304
- test("a cancelled booking does not verify, and the refusal names the one flow that takes it", async () => {
305
- const refused = await run("verify_booking", {
306
- lastName: "Wagner",
307
- confirmationCode: "HTL-FW77",
275
+ describe("verification", () => {
276
+ test("every booking tool refuses until verify_booking has run, naming it", async () => {
277
+ const ctx = createToolContext();
278
+ for (const tool of [lookupBooking, lookupInvoice, cancelRoomBooking, resolveRoomConflict]) {
279
+ const refused = await run(tool, ctx);
280
+ expect(isToolFailure(refused) && refused.error).toMatch(/verify_booking/);
281
+ }
282
+ expect(isToolFailure(await run(flagLateArrival, { note: "around 1 AM" }, ctx))).toBe(true);
308
283
  });
309
- expect(isToolFailure(refused) && refused.error).toMatch(/reinstate_booking/);
310
- });
311
- });
312
-
313
- // ─── 4. The booking flow ─────────────────────────────────────────────────────
314
-
315
- describe("the booking dialog", () => {
316
- test("a fresh call is at the desk, and every booking tool refuses there", async () => {
317
- const ctx = createToolContext();
318
- expect(at(ctx)).toBe("desk");
319
- for (const call of [
320
- run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
321
- run("choose_room", { roomType: "king" }, ctx),
322
- run("confirm_booking", ctx),
323
- ]) {
324
- const refused = expectDialogRefused(await call, "desk");
325
- expect(refused.error).toMatch(/start_room_booking/);
326
- }
327
- expect(hotelSlot.get(ctx).draft).toBeNull();
328
- });
329
284
 
330
- test("each recording tool lands the flow on the step the draft says is next", async () => {
331
- const ctx = createToolContext();
332
- expectDialogOk(await run("start_room_booking", ctx));
333
- expect(at(ctx)).toBe("booking.stay");
334
- // The options have not been offered, so a room cannot be picked yet.
335
- expectDialogRefused(await run("choose_room", { roomType: "queen_2beds" }, ctx), "booking.stay");
285
+ test("last name plus code, or last name plus the card's last four — and nothing else", async () => {
286
+ const byCode = createToolContext();
287
+ expect((await verify(byCode, "Smith", "h t l dash a b 1 2")).code).toBe("HTL-AB12");
288
+ expect(hotelSlot.get(byCode).verifiedCode).toBe("HTL-AB12");
336
289
 
337
- const stay = expectDialogOk<{ options: string; next: string }>(
338
- await run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
339
- );
340
- expect(stay.state).toBe("booking.room");
341
- expect(stay.result.options).toContain("garden view");
290
+ const byCard = createToolContext();
291
+ expectToolOk(await run(verifyBooking, { lastName: "smith", cardLast4: "4242" }, byCard));
292
+ expect(hotelSlot.get(byCard).verifiedCode).toBe("HTL-AB12");
342
293
 
343
- const room = expectDialogOk<{ extrasToOffer: string }>(
344
- await run("choose_room", { roomType: "queen_2beds", view: "garden" }, ctx),
345
- );
346
- expect(room.state).toBe("booking.extras");
347
- expect(room.result.extrasToOffer).toContain("breakfast: adds 75 dollars");
348
- // No total exists before the extras are answered.
349
- expect(hotelSlot.get(ctx).draft?.quotedTotal).toBeNull();
350
- expectDialogRefused(await run("confirm_booking", ctx), "booking.extras");
294
+ const nothing = await run(verifyBooking, { lastName: "Smith" });
295
+ expect(isToolFailure(nothing) && nothing.error).toMatch(/PLUS/);
296
+ });
351
297
 
352
- const extras = expectDialogOk<{ total: string }>(
353
- await run(
354
- "set_extras",
355
- { breakfast: false, valet: false, lateCheckout: false, pets: false },
298
+ test("three strikes, and the refusal routes to a verification_help followup", async () => {
299
+ const ctx = createToolContext();
300
+ const first = await run(
301
+ verifyBooking,
302
+ { lastName: "Smith", confirmationCode: "HTL-0000" },
356
303
  ctx,
357
- ),
358
- );
359
- expect(extras.state).toBe("booking.details");
360
- expect(extras.result.total).toBe("739 dollars and 20 cents including tax");
361
-
362
- // A partial detail is stored the moment it is given, and the flow stays put.
363
- const named = expectDialogOk(
364
- await run("record_guest_details", { firstName: "Maria", lastName: "Whitfield" }, ctx),
365
- );
366
- expect(named.state).toBe("booking.details");
367
- const contact = expectDialogOk(
368
- await run(
369
- "record_guest_details",
370
- { email: "Maria.Whitfield@gmail.com", phone: "123-555-0170" },
304
+ );
305
+ expect(isToolFailure(first) && first.error).toMatch(/Attempt 1 of 3/);
306
+ await run(verifyBooking, { lastName: "Smith", confirmationCode: "HTL-0000" }, ctx);
307
+ const third = await run(
308
+ verifyBooking,
309
+ { lastName: "Smith", confirmationCode: "HTL-0000" },
371
310
  ctx,
372
- ),
373
- );
374
- expect(contact.state).toBe("booking.card");
375
- expect(hotelSlot.get(ctx).draft).toMatchObject({
376
- email: "maria.whitfield@gmail.com",
377
- phone: "1235550170",
311
+ );
312
+ expect(isToolFailure(third) && third.error).toMatch(/verification_help/);
313
+ expect(hotelSlot.get(ctx).verifiedCode).toBeNull();
378
314
  });
379
315
 
380
- const card = expectDialogOk(await run("record_card", A_CARD, ctx));
381
- expect(card.state).toBe("booking.readBack");
382
- // Only the last four ever reached the slot.
383
- expect(JSON.stringify(hotelSlot.get(ctx))).not.toContain("4532");
316
+ test("a cancelled booking does not verify, and the refusal names the one flow that takes it", async () => {
317
+ const refused = await run(verifyBooking, {
318
+ lastName: "Wagner",
319
+ confirmationCode: "HTL-FW77",
320
+ });
321
+ expect(isToolFailure(refused) && refused.error).toMatch(/reinstate_booking/);
322
+ });
384
323
  });
385
324
 
386
- test("the read-back is OWED: confirm refuses until the caller has answered it", async () => {
387
- const ctx = createToolContext();
388
- await bookUpToReadBack(ctx);
389
- expect(at(ctx)).toBe("booking.readBack");
390
- const early = expectDialogRefused(await run("confirm_booking", ctx), "booking.readBack");
391
- expect(early.error).toMatch(/WAIT|answered/);
392
- expect(hotelSlot.get(ctx).bookings.some((b) => b.lastName === "Whitfield")).toBe(false);
393
-
394
- expect(callerAnswers(ctx)).toBe("booking.agreeing");
395
- const done = expectDialogOk<{ outcome: string; room: string; total: string; code: string }>(
396
- await run("confirm_booking", ctx),
397
- );
398
- expect(done.state).toBe("desk");
399
- expect(done.result).toMatchObject({
400
- outcome: "booked",
401
- room: "205",
402
- total: "739 dollars and 20 cents",
325
+ // ─── 4. The booking flow ─────────────────────────────────────────────────────
326
+
327
+ describe("the booking dialog", () => {
328
+ test("a fresh call is at the desk, and every booking tool refuses there", async () => {
329
+ const ctx = createToolContext();
330
+ expect(at(ctx)).toBe("desk");
331
+ for (const call of [
332
+ run(setStay, { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
333
+ run(chooseRoom, { roomType: "king" }, ctx),
334
+ run(confirmBooking, ctx),
335
+ ]) {
336
+ const refused = expectDialogRefused(await call, "desk");
337
+ expect(refused.error).toMatch(/start_room_booking/);
338
+ }
339
+ expect(hotelSlot.get(ctx).draft).toBeNull();
403
340
  });
404
341
 
405
- const hotel = hotelSlot.get(ctx);
406
- const booking = hotel.bookings.find((b) => b.code === done.result.code);
407
- expect(booking).toMatchObject({
408
- roomId: "205",
409
- total: 73_920,
410
- cardLast4: "4471",
411
- status: "confirmed",
342
+ test("each recording tool lands the flow on the step the draft says is next", async () => {
343
+ const ctx = createToolContext();
344
+ expectDialogOk(await run(startRoomBooking, ctx));
345
+ expect(at(ctx)).toBe("booking.stay");
346
+ // The options have not been offered, so a room cannot be picked yet.
347
+ expectDialogRefused(await run(chooseRoom, { roomType: "queen_2beds" }, ctx), "booking.stay");
348
+
349
+ const stay = expectDialogOk(
350
+ await run(setStay, { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
351
+ );
352
+ expect(stay.state).toBe("booking.room");
353
+ expect(stay.result.options).toContain("garden view");
354
+
355
+ const room = expectDialogOk(
356
+ await run(chooseRoom, { roomType: "queen_2beds", view: "garden" }, ctx),
357
+ );
358
+ expect(room.state).toBe("booking.extras");
359
+ expect(room.result.extrasToOffer).toContain("breakfast: adds 75 dollars");
360
+ // No total exists before the extras are answered.
361
+ expect(hotelSlot.get(ctx).draft?.quotedTotal).toBeNull();
362
+ expectDialogRefused(await run(confirmBooking, ctx), "booking.extras");
363
+
364
+ const extras = expectDialogOk(
365
+ await run(
366
+ setExtras,
367
+ { breakfast: false, valet: false, lateCheckout: false, pets: false },
368
+ ctx,
369
+ ),
370
+ );
371
+ expect(extras.state).toBe("booking.details");
372
+ expect(extras.result.total).toBe("739 dollars and 20 cents including tax");
373
+
374
+ // A partial detail is stored the moment it is given, and the flow stays put.
375
+ const named = expectDialogOk(
376
+ await run(recordGuestDetails, { firstName: "Maria", lastName: "Whitfield" }, ctx),
377
+ );
378
+ expect(named.state).toBe("booking.details");
379
+ const contact = expectDialogOk(
380
+ await run(
381
+ recordGuestDetails,
382
+ { email: "Maria.Whitfield@gmail.com", phone: "123-555-0170" },
383
+ ctx,
384
+ ),
385
+ );
386
+ expect(contact.state).toBe("booking.card");
387
+ expect(hotelSlot.get(ctx).draft).toMatchObject({
388
+ email: "maria.whitfield@gmail.com",
389
+ phone: "1235550170",
390
+ });
391
+
392
+ const card = expectDialogOk(await run(recordCard, A_CARD, ctx));
393
+ expect(card.state).toBe("booking.readBack");
394
+ // Only the last four ever reached the slot.
395
+ expect(JSON.stringify(hotelSlot.get(ctx))).not.toContain("4532");
412
396
  });
413
- expect(hotel.invoices.find((i) => i.bookingCode === done.result.code)?.total).toBe(73_920);
414
- expect(hotel.draft).toBeNull();
415
- });
416
-
417
- test("a correction after the read-back re-arms it", async () => {
418
- const ctx = createToolContext();
419
- await bookUpToReadBack(ctx);
420
- callerAnswers(ctx);
421
- // One more night: the garden queen is still free, so the pick survives and
422
- // the flow goes back to the read-back rather than to the offer.
423
- const redated = expectDialogOk(
424
- await run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-18", guests: 2 }, ctx),
425
- );
426
- expect(redated.state).toBe("booking.readBack");
427
- expect(hotelSlot.get(ctx).draft?.roomType).toBe("queen_2beds");
428
- expectDialogRefused(await run("confirm_booking", ctx), "booking.readBack");
429
- });
430
397
 
431
- test("a re-dated pick that dies re-opens the OFFER, and the caller's turn closes it", async () => {
432
- const ctx = createToolContext();
433
- expectDialogOk(await run("start_room_booking", ctx));
434
- expectDialogOk(
435
- await run("set_stay", { checkIn: "2026-06-15", checkOut: "2026-06-16", guests: 2 }, ctx),
436
- );
437
- expectDialogOk(await run("choose_room", { roomType: "penthouse" }, ctx));
438
- // The penthouse is occupied through June 12.
439
- const moved = expectDialogOk<{ next: string }>(
440
- await run("set_stay", { checkIn: "2026-06-10", checkOut: "2026-06-11", guests: 2 }, ctx),
441
- );
442
- expect(moved.result.next).toBe("OFFER");
443
- expect(moved.state).toBe("booking.offering");
444
- expect(hotelSlot.get(ctx).draft?.roomType).toBeNull();
445
- // Closed until the options have been spoken and the caller has answered.
446
- expectDialogRefused(await run("choose_room", { roomType: "king" }, ctx), "booking.offering");
447
- expect(callerAnswers(ctx)).toBe("booking.room");
448
- expectDialogOk(await run("choose_room", { roomType: "king" }, ctx));
449
- });
450
-
451
- test("sold-out dates are refused and NOT recorded", async () => {
452
- const ctx = createToolContext();
453
- expectDialogOk(await run("start_room_booking", ctx));
454
- const refused = await run(
455
- "set_stay",
456
- { checkIn: "2026-07-03", checkOut: "2026-07-04", guests: 2 },
457
- ctx,
458
- );
459
- expect(isToolFailure(refused) && refused.error).toMatch(/sold out/);
460
- expect(hotelSlot.get(ctx).draft?.checkIn).toBeNull();
461
- expect(at(ctx)).toBe("booking.stay");
462
- });
463
-
464
- test("a room in a view the type does not have is refused with where the view IS", async () => {
465
- const ctx = createToolContext();
466
- expectDialogOk(await run("start_room_booking", ctx));
467
- expectDialogOk(
468
- await run("set_stay", { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
469
- );
470
- const refused = await run("choose_room", { roomType: "king", view: "garden" }, ctx);
471
- expect(isToolFailure(refused) && refused.error).toMatch(/garden view IS open as a queen 2beds/);
472
- });
398
+ test("the read-back is OWED: confirm refuses until the caller has answered it", async () => {
399
+ const ctx = createToolContext();
400
+ await bookUpToReadBack(ctx);
401
+ expect(at(ctx)).toBe("booking.readBack");
402
+ const early = expectDialogRefused(await run(confirmBooking, ctx), "booking.readBack");
403
+ expect(early.error).toMatch(/WAIT|answered/);
404
+ expect(hotelSlot.get(ctx).bookings.some((b) => b.lastName === "Whitfield")).toBe(false);
405
+
406
+ expect(callerAnswers(ctx)).toBe("booking.agreeing");
407
+ const done = expectDialogOk(await run(confirmBooking, ctx));
408
+ expect(done.state).toBe("desk");
409
+ expect(done.result).toMatchObject({
410
+ outcome: "booked",
411
+ room: "205",
412
+ total: "739 dollars and 20 cents",
413
+ });
414
+
415
+ const hotel = hotelSlot.get(ctx);
416
+ const booking = hotel.bookings.find((b) => b.code === done.result.code);
417
+ expect(booking).toMatchObject({
418
+ roomId: "205",
419
+ total: 73_920,
420
+ cardLast4: "4471",
421
+ status: "confirmed",
422
+ });
423
+ expect(hotel.invoices.find((i) => i.bookingCode === done.result.code)?.total).toBe(73_920);
424
+ expect(hotel.draft).toBeNull();
425
+ });
473
426
 
474
- test("a bad card bounces one field and leaves the flow where it was", async () => {
475
- const ctx = createToolContext();
476
- await bookUpToReadBack(ctx);
477
- // Re-record with a misheard digit: refused, and the recorded card stays.
478
- const refused = await run("record_card", { ...A_CARD, cardNumber: "4532 0000 0001 4472" }, ctx);
479
- expect(isToolFailure(refused) && refused.error).toMatch(/one digit is likely off/);
480
- expect(hotelSlot.get(ctx).draft?.cardLast4).toBe("4471");
481
- expect(at(ctx)).toBe("booking.readBack");
482
- });
427
+ test("a correction after the read-back re-arms it", async () => {
428
+ const ctx = createToolContext();
429
+ await bookUpToReadBack(ctx);
430
+ callerAnswers(ctx);
431
+ // One more night: the garden queen is still free, so the pick survives and
432
+ // the flow goes back to the read-back rather than to the offer.
433
+ const redated = expectDialogOk(
434
+ await run(setStay, { checkIn: "2026-07-14", checkOut: "2026-07-18", guests: 2 }, ctx),
435
+ );
436
+ expect(redated.state).toBe("booking.readBack");
437
+ expect(hotelSlot.get(ctx).draft?.roomType).toBe("queen_2beds");
438
+ expectDialogRefused(await run(confirmBooking, ctx), "booking.readBack");
439
+ });
483
440
 
484
- test("abandoning writes nothing and returns to the desk", async () => {
485
- const ctx = createToolContext();
486
- await bookUpToReadBack(ctx);
487
- const gone = expectDialogOk(
488
- await run("abandon_booking", { reason: "changed their mind" }, ctx),
489
- );
490
- expect(gone.state).toBe("desk");
491
- expect(hotelSlot.get(ctx).draft).toBeNull();
492
- expect(hotelSlot.get(ctx).bookings.some((b) => b.lastName === "Whitfield")).toBe(false);
493
- });
441
+ test("a re-dated pick that dies re-opens the OFFER, and the caller's turn closes it", async () => {
442
+ const ctx = createToolContext();
443
+ expectDialogOk(await run(startRoomBooking, ctx));
444
+ expectDialogOk(
445
+ await run(setStay, { checkIn: "2026-06-15", checkOut: "2026-06-16", guests: 2 }, ctx),
446
+ );
447
+ expectDialogOk(await run(chooseRoom, { roomType: "penthouse" }, ctx));
448
+ // The penthouse is occupied through June 12.
449
+ const moved = expectDialogOk(
450
+ await run(setStay, { checkIn: "2026-06-10", checkOut: "2026-06-11", guests: 2 }, ctx),
451
+ );
452
+ expect(moved.result.next).toBe("OFFER");
453
+ expect(moved.state).toBe("booking.offering");
454
+ expect(hotelSlot.get(ctx).draft?.roomType).toBeNull();
455
+ // Closed until the options have been spoken and the caller has answered.
456
+ expectDialogRefused(await run(chooseRoom, { roomType: "king" }, ctx), "booking.offering");
457
+ expect(callerAnswers(ctx)).toBe("booking.room");
458
+ expectDialogOk(await run(chooseRoom, { roomType: "king" }, ctx));
459
+ });
494
460
 
495
- test("the double-booking guard: no second flow until the caller has spoken again", async () => {
496
- const ctx = withCallerTurns(4);
497
- await bookUpToReadBack(ctx);
498
- callerAnswers(ctx);
499
- expectDialogOk(await run("confirm_booking", ctx));
500
- // Same history, so the model — not the caller — is asking for a second room.
501
- const again = await run("start_room_booking", ctx);
502
- expect(isToolFailure(again) && again.error).toMatch(/already complete/);
503
- expect(at(ctx)).toBe("desk");
504
- // One more caller turn and a real second room is legal.
505
- const later = withCallerTurns(5);
506
- hotelSlot.set(later, hotelSlot.snapshot(ctx));
507
- expectDialogOk(await run("start_room_booking", later));
508
- });
461
+ test("sold-out dates are refused and NOT recorded", async () => {
462
+ const ctx = createToolContext();
463
+ expectDialogOk(await run(startRoomBooking, ctx));
464
+ const refused = await run(
465
+ setStay,
466
+ { checkIn: "2026-07-03", checkOut: "2026-07-04", guests: 2 },
467
+ ctx,
468
+ );
469
+ expect(isToolFailure(refused) && refused.error).toMatch(/sold out/);
470
+ expect(hotelSlot.get(ctx).draft?.checkIn).toBeNull();
471
+ expect(at(ctx)).toBe("booking.stay");
472
+ });
509
473
 
510
- test("a hang-up ends the call, and nothing books after it", async () => {
511
- const ctx = createToolContext();
512
- await bookUpToReadBack(ctx);
513
- expect(deskFlow.receive(ctx, CALLER_GONE).state).toBe("hungUp");
514
- expect(isToolFailure(await run("confirm_booking", ctx))).toBe(true);
515
- expect(isToolFailure(await run("start_room_booking", ctx))).toBe(true);
516
- });
517
- });
474
+ test("a room in a view the type does not have is refused with where the view IS", async () => {
475
+ const ctx = createToolContext();
476
+ expectDialogOk(await run(startRoomBooking, ctx));
477
+ expectDialogOk(
478
+ await run(setStay, { checkIn: "2026-07-14", checkOut: "2026-07-17", guests: 2 }, ctx),
479
+ );
480
+ const refused = await run(chooseRoom, { roomType: "king", view: "garden" }, ctx);
481
+ expect(isToolFailure(refused) && refused.error).toMatch(
482
+ /garden view IS open as a queen 2beds/,
483
+ );
484
+ });
518
485
 
519
- // ─── 5. Modifying a booking ──────────────────────────────────────────────────
486
+ test("a bad card bounces one field and leaves the flow where it was", async () => {
487
+ const ctx = createToolContext();
488
+ await bookUpToReadBack(ctx);
489
+ // Re-record with a misheard digit: refused, and the recorded card stays.
490
+ const refused = await run(recordCard, { ...A_CARD, cardNumber: "4532 0000 0001 4472" }, ctx);
491
+ expect(isToolFailure(refused) && refused.error).toMatch(/one digit is likely off/);
492
+ expect(hotelSlot.get(ctx).draft?.cardLast4).toBe("4471");
493
+ expect(at(ctx)).toBe("booking.readBack");
494
+ });
520
495
 
521
- describe("modifying a booking", () => {
522
- test("Robert Klein's garden view is a room MOVE, and the refusal is the fix", async () => {
523
- const ctx = createToolContext();
524
- await verify(ctx, "Klein", "HTL-RK20");
525
- const loaded = expectDialogOk<{ loaded: { room: string; total: string } }>(
526
- await run("start_booking_modification", ctx),
527
- );
528
- expect(loaded.state).toBe("booking.editing");
529
- expect(loaded.result.loaded.room).toBe("king, city view, room 201");
530
- expect(loaded.result.loaded.total).toBe("537 dollars and 60 cents");
496
+ test("abandoning writes nothing and returns to the desk", async () => {
497
+ const ctx = createToolContext();
498
+ await bookUpToReadBack(ctx);
499
+ const gone = expectDialogOk(await run(abandonBooking, { reason: "changed their mind" }, ctx));
500
+ expect(gone.state).toBe("desk");
501
+ expect(hotelSlot.get(ctx).draft).toBeNull();
502
+ expect(hotelSlot.get(ctx).bookings.some((b) => b.lastName === "Whitfield")).toBe(false);
503
+ });
531
504
 
532
- // A garden king has never existed; the garden view IS open as a queen.
533
- const refused = await run("choose_room", { roomType: "king", view: "garden" }, ctx);
534
- expect(isToolFailure(refused) && refused.error).toMatch(/garden view IS open as a queen 2beds/);
505
+ test("the double-booking guard: no second flow until the caller has spoken again", async () => {
506
+ const ctx = withCallerTurns(4);
507
+ await bookUpToReadBack(ctx);
508
+ callerAnswers(ctx);
509
+ expectDialogOk(await run(confirmBooking, ctx));
510
+ // Same history, so the model — not the caller — is asking for a second room.
511
+ const again = await run(startRoomBooking, ctx);
512
+ expect(isToolFailure(again) && again.error).toMatch(/already complete/);
513
+ expect(at(ctx)).toBe("desk");
514
+ // One more caller turn and a real second room is legal.
515
+ const later = withCallerTurns(5);
516
+ hotelSlot.set(later, hotelSlot.snapshot(ctx));
517
+ expectDialogOk(await run(startRoomBooking, later));
518
+ });
535
519
 
536
- const picked = expectDialogOk(
537
- await run("choose_room", { roomType: "queen_2beds", view: "garden" }, ctx),
538
- );
539
- expect(picked.state).toBe("booking.readBack");
540
- expect(callerAnswers(ctx)).toBe("booking.agreeing");
541
- const done = expectDialogOk<{
542
- outcome: string;
543
- changed: string[];
544
- room: string;
545
- message: string;
546
- }>(await run("confirm_booking", ctx));
547
- expect(done.result).toMatchObject({ outcome: "updated", changed: ["room"], room: "205" });
548
- // 537.60 → 492.80, the difference refunded, and the model is handed the number.
549
- expect(done.result.message).toContain("44 dollars and 80 cents refunded");
550
- const booking = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-RK20");
551
- expect(booking).toMatchObject({ roomId: "205", total: 49_280 });
552
- // Still verified as the same guest, on the post-modify booking.
553
- expect(hotelSlot.get(ctx).verifiedCode).toBe("HTL-RK20");
520
+ test("a hang-up ends the call, and nothing books after it", async () => {
521
+ const ctx = createToolContext();
522
+ await bookUpToReadBack(ctx);
523
+ await fireEvent(agentDef, CALLER_GONE, ctx);
524
+ expect(deskFlow.position(ctx).state).toBe("hungUp");
525
+ expect(isToolFailure(await run(confirmBooking, ctx))).toBe(true);
526
+ expect(isToolFailure(await run(startRoomBooking, ctx))).toBe(true);
527
+ // And the lead is on the ledger: `hungUp`'s `onEnter` (desk-seams.test.ts).
528
+ expect(hotelSlot.get(ctx).tickets.at(-1)?.details.kind).toBe("abandoned_booking");
529
+ });
554
530
  });
555
531
 
556
- test("a date-only change keeps the room the guest already has", async () => {
557
- const ctx = createToolContext();
558
- await verify(ctx, "Smith", "HTL-AB12");
559
- expectDialogOk(await run("start_booking_modification", ctx));
560
- const stay = expectDialogOk(
561
- await run("set_stay", { checkIn: "2026-06-13", checkOut: "2026-06-16", guests: 2 }, ctx),
562
- );
563
- expect(stay.state).toBe("booking.readBack");
564
- callerAnswers(ctx);
565
- const done = expectDialogOk<{ changed: string[]; room: string }>(
566
- await run("confirm_booking", ctx),
567
- );
568
- expect(done.result.changed).toEqual(["stay"]);
569
- expect(done.result.room).toBe("203");
570
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")).toMatchObject({
571
- checkOut: "2026-06-16",
572
- total: 89_040,
532
+ // ─── 5. Modifying a booking ──────────────────────────────────────────────────
533
+
534
+ describe("modifying a booking", () => {
535
+ test("Robert Klein's garden view is a room MOVE, and the refusal is the fix", async () => {
536
+ const ctx = createToolContext();
537
+ await verify(ctx, "Klein", "HTL-RK20");
538
+ const loaded = expectDialogOk(await run(startBookingModification, ctx));
539
+ expect(loaded.state).toBe("booking.editing");
540
+ expect(loaded.result.loaded.room).toBe("king, city view, room 201");
541
+ expect(loaded.result.loaded.total).toBe("537 dollars and 60 cents");
542
+
543
+ // A garden king has never existed; the garden view IS open as a queen.
544
+ const refused = await run(chooseRoom, { roomType: "king", view: "garden" }, ctx);
545
+ expect(isToolFailure(refused) && refused.error).toMatch(
546
+ /garden view IS open as a queen 2beds/,
547
+ );
548
+
549
+ const picked = expectDialogOk(
550
+ await run(chooseRoom, { roomType: "queen_2beds", view: "garden" }, ctx),
551
+ );
552
+ expect(picked.state).toBe("booking.readBack");
553
+ expect(callerAnswers(ctx)).toBe("booking.agreeing");
554
+ const done = expectDialogOk(await run(confirmBooking, ctx));
555
+ expect(done.result).toMatchObject({ outcome: "updated", changed: ["room"], room: "205" });
556
+ // 537.60 → 492.80, the difference refunded, and the model is handed the number.
557
+ expect(done.result.message).toContain("44 dollars and 80 cents refunded");
558
+ const booking = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-RK20");
559
+ expect(booking).toMatchObject({ roomId: "205", total: 49_280 });
560
+ // Still verified as the same guest, on the post-modify booking.
561
+ expect(hotelSlot.get(ctx).verifiedCode).toBe("HTL-RK20");
573
562
  });
574
- });
575
563
 
576
- test("a modification that changes nothing is closed as unchanged, and a cancellation is refused mid-flow", async () => {
577
- const ctx = createToolContext();
578
- await verify(ctx, "Smith", "HTL-AB12");
579
- expectDialogOk(await run("start_booking_modification", ctx));
580
- // The caller pivots to cancelling: the desk's tools are still legal, but
581
- // the model is told to close the flow first — which abandon_booking does.
582
- expectDialogOk(await run("abandon_booking", { reason: "wants to cancel instead" }, ctx));
583
- expect(at(ctx)).toBe("desk");
584
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.status).toBe(
585
- "confirmed",
586
- );
587
- });
564
+ test("a date-only change keeps the room the guest already has", async () => {
565
+ const ctx = createToolContext();
566
+ await verify(ctx, "Smith", "HTL-AB12");
567
+ expectDialogOk(await run(startBookingModification, ctx));
568
+ const stay = expectDialogOk(
569
+ await run(setStay, { checkIn: "2026-06-13", checkOut: "2026-06-16", guests: 2 }, ctx),
570
+ );
571
+ expect(stay.state).toBe("booking.readBack");
572
+ callerAnswers(ctx);
573
+ const done = expectDialogOk(await run(confirmBooking, ctx));
574
+ expect(done.result.changed).toEqual(["stay"]);
575
+ expect(done.result.room).toBe("203");
576
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")).toMatchObject({
577
+ checkOut: "2026-06-16",
578
+ total: 89_040,
579
+ });
580
+ });
581
+
582
+ test("a modification that changes nothing is closed as unchanged, and a cancellation is refused mid-flow", async () => {
583
+ const ctx = createToolContext();
584
+ await verify(ctx, "Smith", "HTL-AB12");
585
+ expectDialogOk(await run(startBookingModification, ctx));
586
+ // The caller pivots to cancelling: the desk's tools are still legal, but
587
+ // the model is told to close the flow first — which abandon_booking does.
588
+ expectDialogOk(await run(abandonBooking, { reason: "wants to cancel instead" }, ctx));
589
+ expect(at(ctx)).toBe("desk");
590
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.status).toBe(
591
+ "confirmed",
592
+ );
593
+ });
588
594
 
589
- test("the unmodifiable: a cancelled or past booking", async () => {
590
- const ctx = createToolContext();
591
- await verify(ctx, "Lee", "HTL-GH78");
592
- const past = await run("start_booking_modification", ctx);
593
- expect(isToolFailure(past) && past.error).toMatch(/already ended/);
595
+ test("the unmodifiable: a cancelled or past booking", async () => {
596
+ const ctx = createToolContext();
597
+ await verify(ctx, "Lee", "HTL-GH78");
598
+ const past = await run(startBookingModification, ctx);
599
+ expect(isToolFailure(past) && past.error).toMatch(/already ended/);
600
+ });
594
601
  });
595
- });
596
602
 
597
- // ─── 6. Cancelling and reinstating ───────────────────────────────────────────
603
+ // ─── 6. Cancelling and reinstating ───────────────────────────────────────────
604
+
605
+ describe("cancelling", () => {
606
+ test("outside the window the whole total comes back; inside it one night is kept", async () => {
607
+ const outside = createToolContext();
608
+ await verify(outside, "Smith", "HTL-AB12");
609
+ const full = expectToolOk(await run(cancelRoomBooking, outside));
610
+ expect(full).toMatchObject({ withinWindow: false, forfeit: 0, refund: 59_360 });
611
+ expect(hotelSlot.get(outside).bookings.find((b) => b.code === "HTL-AB12")?.status).toBe(
612
+ "cancelled",
613
+ );
614
+ expect(hotelSlot.get(outside).verifiedCode).toBeNull();
615
+
616
+ const inside = createToolContext();
617
+ await verify(inside, "Sato", "HTL-BN23");
618
+ const partial = expectToolOk(await run(cancelRoomBooking, inside));
619
+ // Room 204 is 220 a night; the forfeit is that rate, never a model's arithmetic.
620
+ expect(partial).toMatchObject({
621
+ withinWindow: true,
622
+ forfeit: 22_000,
623
+ refund: 54_880 - 22_000,
624
+ });
625
+ expect(partial.message).toContain("one room-night (220 dollars) is forfeited");
626
+ });
598
627
 
599
- describe("cancelling", () => {
600
- test("outside the window the whole total comes back; inside it one night is kept", async () => {
601
- const outside = createToolContext();
602
- await verify(outside, "Smith", "HTL-AB12");
603
- const full = expectToolOk(await runTool(cancelRoomBooking, outside));
604
- expect(full).toMatchObject({ withinWindow: false, forfeit: 0, refund: 59_360 });
605
- expect(hotelSlot.get(outside).bookings.find((b) => b.code === "HTL-AB12")?.status).toBe(
606
- "cancelled",
607
- );
608
- expect(hotelSlot.get(outside).verifiedCode).toBeNull();
609
-
610
- const inside = createToolContext();
611
- await verify(inside, "Sato", "HTL-BN23");
612
- const partial = expectToolOk(await runTool(cancelRoomBooking, inside));
613
- // Room 204 is 220 a night; the forfeit is that rate, never a model's arithmetic.
614
- expect(partial).toMatchObject({ withinWindow: true, forfeit: 22_000, refund: 54_880 - 22_000 });
615
- expect(partial.message).toContain("one room-night (220 dollars) is forfeited");
616
- });
628
+ test("a cancel re-invoked with no caller turn since re-surfaces the outcome", async () => {
629
+ const ctx = withCallerTurns(2);
630
+ await verify(ctx, "Smith", "HTL-AB12");
631
+ expectToolOk(await run(cancelRoomBooking, ctx));
632
+ const again = expectToolOk(await run(cancelRoomBooking, ctx));
633
+ expect(again.alreadyCancelled).toBe(true);
634
+ expect(again.message).toContain("refund the full 593 dollars and 60 cents");
635
+ });
617
636
 
618
- test("a cancel re-invoked with no caller turn since re-surfaces the outcome", async () => {
619
- const ctx = withCallerTurns(2);
620
- await verify(ctx, "Smith", "HTL-AB12");
621
- expectToolOk(await run("cancel_room_booking", ctx));
622
- const again = expectToolOk(await runTool(cancelRoomBooking, ctx));
623
- expect(again.alreadyCancelled).toBe(true);
624
- expect(again.message).toContain("refund the full 593 dollars and 60 cents");
637
+ test("reinstating brings a cancelled booking back only while its room is free", async () => {
638
+ const ctx = createToolContext();
639
+ const back = expectToolOk(
640
+ await run(reinstateBooking, { lastName: "Wagner", confirmationCode: "htl fw77" }, ctx),
641
+ );
642
+ expect(back).toMatchObject({ reinstated: true, code: "HTL-FW77" });
643
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-FW77")?.status).toBe(
644
+ "confirmed",
645
+ );
646
+ expect(hotelSlot.get(ctx).verifiedCode).toBe("HTL-FW77");
647
+ // Already active: a no-op that says so.
648
+ const noop = expectToolOk(
649
+ await run(reinstateBooking, { lastName: "Wagner", confirmationCode: "HTL-FW77" }, ctx),
650
+ );
651
+ expect(noop.reinstated).toBe(false);
652
+ });
625
653
  });
626
654
 
627
- test("reinstating brings a cancelled booking back only while its room is free", async () => {
628
- const ctx = createToolContext();
629
- const back = expectToolOk(
630
- await runTool(reinstateBooking, { lastName: "Wagner", confirmationCode: "htl fw77" }, ctx),
631
- );
632
- expect(back).toMatchObject({ reinstated: true, code: "HTL-FW77" });
633
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-FW77")?.status).toBe(
634
- "confirmed",
635
- );
636
- expect(hotelSlot.get(ctx).verifiedCode).toBe("HTL-FW77");
637
- // Already active: a no-op that says so.
638
- const noop = expectToolOk(
639
- await runTool(reinstateBooking, { lastName: "Wagner", confirmationCode: "HTL-FW77" }, ctx),
640
- );
641
- expect(noop.reinstated).toBe(false);
642
- });
643
- });
655
+ // ─── 7. Disputes ─────────────────────────────────────────────────────────────
644
656
 
645
- // ─── 7. Disputes ─────────────────────────────────────────────────────────────
657
+ describe("disputes", () => {
658
+ test("the policy table decides the refund, and the refund moves the invoice", async () => {
659
+ const ctx = createToolContext();
660
+ await verify(ctx, "Lee", "HTL-GH78");
661
+ const invoice = expectToolOk(await run(lookupInvoice, ctx));
662
+ expect(invoice.lineItems.map((li) => li.label)).toContain("Late checkout");
646
663
 
647
- describe("disputes", () => {
648
- test("the policy table decides the refund, and the refund moves the invoice", async () => {
649
- const ctx = createToolContext();
650
- await verify(ctx, "Lee", "HTL-GH78");
651
- const invoice = expectToolOk(await runTool(lookupInvoice, ctx));
652
- expect(invoice.lineItems.map((li) => li.label)).toContain("Late checkout");
664
+ const filed = expectToolOk(
665
+ await run(
666
+ disputeCharge,
667
+ {
668
+ category: "late_checkout_fee",
669
+ lineItemLabel: "late checkout",
670
+ callerNote: "Front desk said a 1 PM checkout would be fine.",
671
+ acceptsOfferedResolution: true,
672
+ },
673
+ ctx,
674
+ ),
675
+ );
676
+ expect(filed).toMatchObject({ outcome: "goodwill_waived", refund: PRICING.lateCheckout });
677
+ expect(filed.say).toContain("Waived as a one-time courtesy - 40 dollars back");
678
+ const live = hotelSlot.get(ctx).invoices.find((i) => i.bookingCode === "HTL-GH78");
679
+ // 672.00 less the 40.00 already waived in the seed, less this one.
680
+ expect(live?.total).toBe(67_200 - PRICING.lateCheckout - PRICING.lateCheckout);
681
+ });
653
682
 
654
- const filed = expectToolOk(
655
- await runTool(
656
- disputeCharge,
657
- {
658
- category: "late_checkout_fee",
659
- lineItemLabel: "late checkout",
660
- callerNote: "Front desk said a 1 PM checkout would be fine.",
661
- acceptsOfferedResolution: true,
662
- },
663
- ctx,
664
- ),
665
- );
666
- expect(filed).toMatchObject({ outcome: "goodwill_waived", refund: PRICING.lateCheckout });
667
- expect(filed.say).toContain("Waived as a one-time courtesy - 40 dollars back");
668
- const live = hotelSlot.get(ctx).invoices.find((i) => i.bookingCode === "HTL-GH78");
669
- // 672.00 less the 40.00 already waived in the seed, less this one.
670
- expect(live?.total).toBe(67_200 - PRICING.lateCheckout - PRICING.lateCheckout);
671
- });
683
+ test("a no-show is explained, never refunded, and escalates only when the caller pushes", async () => {
684
+ const ctx = createToolContext();
685
+ await verify(ctx, "Richardson", "HTL-NS44");
686
+ const pushed = expectToolOk(
687
+ await run(
688
+ disputeCharge,
689
+ {
690
+ category: "no_show",
691
+ lineItemLabel: "Room (2 nights)",
692
+ callerNote: "Never showed up.",
693
+ acceptsOfferedResolution: false,
694
+ },
695
+ ctx,
696
+ ),
697
+ );
698
+ expect(pushed).toMatchObject({ outcome: "escalated_to_manager", refund: 0 });
699
+ });
672
700
 
673
- test("a no-show is explained, never refunded, and escalates only when the caller pushes", async () => {
674
- const ctx = createToolContext();
675
- await verify(ctx, "Richardson", "HTL-NS44");
676
- const pushed = expectToolOk(
677
- await runTool(
701
+ test("a line item that is not on the invoice is refused with the lines that are", async () => {
702
+ const ctx = createToolContext();
703
+ await verify(ctx, "Lee", "HTL-GH78");
704
+ const refused = await run(
678
705
  disputeCharge,
679
706
  {
680
- category: "no_show",
681
- lineItemLabel: "Room (2 nights)",
682
- callerNote: "Never showed up.",
707
+ category: "minibar",
708
+ lineItemLabel: "Minibar",
709
+ callerNote: "?",
683
710
  acceptsOfferedResolution: false,
684
711
  },
685
712
  ctx,
686
- ),
687
- );
688
- expect(pushed).toMatchObject({ outcome: "escalated_to_manager", refund: 0 });
689
- });
690
-
691
- test("a line item that is not on the invoice is refused with the lines that are", async () => {
692
- const ctx = createToolContext();
693
- await verify(ctx, "Lee", "HTL-GH78");
694
- const refused = await run(
695
- "dispute_charge",
696
- {
697
- category: "minibar",
698
- lineItemLabel: "Minibar",
699
- callerNote: "?",
700
- acceptsOfferedResolution: false,
701
- },
702
- ctx,
703
- );
704
- // `resolveOne`'s refusal, and it carries the AMOUNTS as well as the labels —
705
- // which is what the desk has to read back for the caller to pick one.
706
- expect(isToolFailure(refused) && refused.error).toMatch(
707
- /Room \(2 nights\) \(560 dollars\); Late checkout \(40 dollars\)/,
708
- );
709
- });
713
+ );
714
+ // `resolveOne`'s refusal, and it carries the AMOUNTS as well as the labels —
715
+ // which is what the desk has to read back for the caller to pick one.
716
+ expect(isToolFailure(refused) && refused.error).toMatch(
717
+ /Room \(2 nights\) \(560 dollars\); Late checkout \(40 dollars\)/,
718
+ );
719
+ });
710
720
 
711
- test("the outcome table, branch by branch", () => {
712
- const lines = [{ label: "Minibar", amount: 1800 }];
713
- expect(resolveDisputeOutcome(DISPUTE_POLICIES.minibar, 1800, "Minibar", lines, false)).toEqual({
714
- outcome: "auto_refunded",
715
- refund: 1800,
721
+ test("the outcome table, branch by branch", () => {
722
+ const lines = [{ label: "Minibar", amount: 1800 }];
723
+ expect(
724
+ resolveDisputeOutcome(DISPUTE_POLICIES.minibar, 1800, "Minibar", lines, false),
725
+ ).toEqual({
726
+ outcome: "auto_refunded",
727
+ refund: 1800,
728
+ });
729
+ expect(
730
+ resolveDisputeOutcome(DISPUTE_POLICIES.minibar, 9000, "Minibar", lines, false).outcome,
731
+ ).toBe("escalated_to_manager");
732
+ expect(
733
+ resolveDisputeOutcome(DISPUTE_POLICIES.damage_cleaning, 5000, "Pet fee", lines, true)
734
+ .outcome,
735
+ ).toBe("explained_no_action");
736
+ const doubled = [
737
+ { label: "Room (3 nights)", amount: 66_000 },
738
+ { label: "Room (3 nights)", amount: 66_000 },
739
+ ];
740
+ expect(
741
+ resolveDisputeOutcome(
742
+ DISPUTE_POLICIES.double_charge_billing_error,
743
+ 66_000,
744
+ "Room (3 nights)",
745
+ doubled,
746
+ false,
747
+ ),
748
+ ).toEqual({ outcome: "auto_refunded", refund: 66_000 });
749
+ expect(
750
+ resolveDisputeOutcome(
751
+ DISPUTE_POLICIES.double_charge_billing_error,
752
+ 66_000,
753
+ "Room (3 nights)",
754
+ lines,
755
+ false,
756
+ ).outcome,
757
+ ).toBe("accounting_ticket_opened");
716
758
  });
717
- expect(
718
- resolveDisputeOutcome(DISPUTE_POLICIES.minibar, 9000, "Minibar", lines, false).outcome,
719
- ).toBe("escalated_to_manager");
720
- expect(
721
- resolveDisputeOutcome(DISPUTE_POLICIES.damage_cleaning, 5000, "Pet fee", lines, true).outcome,
722
- ).toBe("explained_no_action");
723
- const doubled = [
724
- { label: "Room (3 nights)", amount: 66_000 },
725
- { label: "Room (3 nights)", amount: 66_000 },
726
- ];
727
- expect(
728
- resolveDisputeOutcome(
729
- DISPUTE_POLICIES.double_charge_billing_error,
730
- 66_000,
731
- "Room (3 nights)",
732
- doubled,
733
- false,
734
- ),
735
- ).toEqual({ outcome: "auto_refunded", refund: 66_000 });
736
- expect(
737
- resolveDisputeOutcome(
738
- DISPUTE_POLICIES.double_charge_billing_error,
739
- 66_000,
740
- "Room (3 nights)",
741
- lines,
742
- false,
743
- ).outcome,
744
- ).toBe("accounting_ticket_opened");
745
759
  });
746
- });
747
760
 
748
- // ─── 8. Room conflicts: the two seeded double-bookings ───────────────────────
749
-
750
- describe("room conflicts", () => {
751
- test("Kenji Tanaka is WALKED: the house is full tonight, and 301 is his again tomorrow", async () => {
752
- const ctx = createToolContext();
753
- await verify(ctx, "Tanaka", "HTL-RT88");
754
- const looked = expectToolOk(await runTool(lookupBooking, ctx));
755
- expect(looked.WARNING).toMatch(/double-booked/);
756
- const resolved = expectToolOk(await runTool(resolveRoomConflict, ctx));
757
- expect(resolved).toMatchObject({
758
- resolved: "walked",
759
- partnerHotel: "the Harbor House",
760
- returnDate: "Tuesday, June 9",
761
+ // ─── 8. Room conflicts: the two seeded double-bookings ───────────────────────
762
+
763
+ describe("room conflicts", () => {
764
+ test("Kenji Tanaka is WALKED: the house is full tonight, and 301 is his again tomorrow", async () => {
765
+ const ctx = createToolContext();
766
+ await verify(ctx, "Tanaka", "HTL-RT88");
767
+ const looked = expectToolOk(await run(lookupBooking, ctx));
768
+ expect(looked.WARNING).toMatch(/double-booked/);
769
+ const resolved = expectToolOk(await run(resolveRoomConflict, ctx));
770
+ expect(resolved).toMatchObject({
771
+ resolved: "walked",
772
+ partnerHotel: "the Harbor House",
773
+ returnDate: "Tuesday, June 9",
774
+ });
775
+ expect(hotelSlot.get(ctx).tickets.some((t) => t.kind === "walk")).toBe(true);
776
+ // The booking itself is untouched: same room, same total.
777
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-RT88")?.roomId).toBe("301");
761
778
  });
762
- expect(hotelSlot.get(ctx).tickets.some((t) => t.kind === "walk")).toBe(true);
763
- // The booking itself is untouched: same room, same total.
764
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-RT88")?.roomId).toBe("301");
765
- });
766
779
 
767
- test("Tom Whelan is UPGRADED: the only room at or above his rate is a suite, at his total", async () => {
768
- const ctx = createToolContext();
769
- await verify(ctx, "Whelan", "HTL-TW55");
770
- const before = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-TW55")?.total;
771
- const resolved = expectToolOk(await runTool(resolveRoomConflict, ctx));
772
- expect(resolved).toMatchObject({ resolved: "moved", roomType: "suite", upgraded: true });
773
- const after = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-TW55");
774
- expect(after?.roomId).toBe(resolved.room);
775
- expect(after?.total).toBe(before);
776
- // And the lookup no longer warns.
777
- expect(expectToolOk(await runTool(lookupBooking, ctx)).WARNING).toBeUndefined();
778
- });
780
+ test("Tom Whelan is UPGRADED: the only room at or above his rate is a suite, at his total", async () => {
781
+ const ctx = createToolContext();
782
+ await verify(ctx, "Whelan", "HTL-TW55");
783
+ const before = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-TW55")?.total;
784
+ const resolved = expectToolOk(await run(resolveRoomConflict, ctx));
785
+ expect(resolved).toMatchObject({ resolved: "moved", roomType: "suite", upgraded: true });
786
+ const after = hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-TW55");
787
+ expect(after?.roomId).toBe(resolved.room);
788
+ expect(after?.total).toBe(before);
789
+ // And the lookup no longer warns.
790
+ expect(expectToolOk(await run(lookupBooking, ctx)).WARNING).toBeUndefined();
791
+ });
779
792
 
780
- test("a booking with no conflict has nothing to resolve", async () => {
781
- const ctx = createToolContext();
782
- await verify(ctx, "Klein", "HTL-RK20");
783
- const refused = await run("resolve_room_conflict", ctx);
784
- expect(isToolFailure(refused) && refused.error).toMatch(/no room conflict/);
793
+ test("a booking with no conflict has nothing to resolve", async () => {
794
+ const ctx = createToolContext();
795
+ await verify(ctx, "Klein", "HTL-RK20");
796
+ const refused = await run(resolveRoomConflict, ctx);
797
+ expect(isToolFailure(refused) && refused.error).toMatch(/no room conflict/);
798
+ });
785
799
  });
786
- });
787
800
 
788
- // ─── 9. Guest privacy ────────────────────────────────────────────────────────
789
-
790
- describe("taking a message", () => {
791
- test("the result for an in-house guest and for a stranger are indistinguishable", async () => {
792
- const ctx = createToolContext();
793
- const args = {
794
- callerName: "Mark Ellis",
795
- callerPhone: "415 555 0100",
796
- message: "Dinner is at eight.",
797
- };
798
- const guest = expectToolOk(
799
- await runTool(takeGuestMessage, { ...args, recipient: "Jonathan Pierce" }, ctx),
800
- );
801
- const stranger = expectToolOk(
802
- await runTool(takeGuestMessage, { ...args, recipient: "Nobody Here" }, ctx),
803
- );
804
- const shape = (r: Record<string, unknown>) => Object.keys(r).sort();
805
- expect(shape(guest)).toEqual(shape(stranger));
806
- for (const result of [guest, stranger]) {
807
- // Neither the verdict nor the room number the ledger knows reaches the model.
808
- expect(JSON.stringify(result)).not.toMatch(/delivered|undeliverable|303/);
809
- }
810
- // The desk's ledger knows; the model never did.
811
- const statuses = hotelSlot
812
- .get(ctx)
813
- .tickets.filter((t) => t.kind === "guest_message")
814
- .map((t) => t.details.status);
815
- expect(statuses).toEqual(["delivered", "undeliverable"]);
816
- });
801
+ // ─── 9. Guest privacy ────────────────────────────────────────────────────────
802
+
803
+ describe("taking a message", () => {
804
+ test("the result for an in-house guest and for a stranger are indistinguishable", async () => {
805
+ const ctx = createToolContext();
806
+ const args = {
807
+ callerName: "Mark Ellis",
808
+ callerPhone: "415 555 0100",
809
+ message: "Dinner is at eight.",
810
+ };
811
+ const guest = expectToolOk(
812
+ await run(takeGuestMessage, { ...args, recipient: "Jonathan Pierce" }, ctx),
813
+ );
814
+ const stranger = expectToolOk(
815
+ await run(takeGuestMessage, { ...args, recipient: "Nobody Here" }, ctx),
816
+ );
817
+ const shape = (r: Record<string, unknown>) => Object.keys(r).sort();
818
+ expect(shape(guest)).toEqual(shape(stranger));
819
+ for (const result of [guest, stranger]) {
820
+ // Neither the verdict nor the room number the ledger knows reaches the model.
821
+ expect(JSON.stringify(result)).not.toMatch(/delivered|undeliverable|303/);
822
+ }
823
+ // The desk's ledger knows; the model never did.
824
+ const statuses = hotelSlot
825
+ .get(ctx)
826
+ .tickets.filter((t) => t.kind === "guest_message")
827
+ .map((t) => t.details.status);
828
+ expect(statuses).toEqual(["delivered", "undeliverable"]);
829
+ });
817
830
 
818
- test("a first name alone is refused — a message needs the full name to reach anyone", async () => {
819
- const refused = await run("take_guest_message", {
820
- recipient: "Jonathan",
821
- callerName: "Mark",
822
- callerPhone: "415 555 0100",
823
- message: "hi",
831
+ test("a first name alone is refused — a message needs the full name to reach anyone", async () => {
832
+ const refused = await run(takeGuestMessage, {
833
+ recipient: "Jonathan",
834
+ callerName: "Mark",
835
+ callerPhone: "415 555 0100",
836
+ message: "hi",
837
+ });
838
+ expect(isToolFailure(refused) && refused.error).toMatch(/last name/);
824
839
  });
825
- expect(isToolFailure(refused) && refused.error).toMatch(/last name/);
826
840
  });
827
- });
828
841
 
829
- // ─── 10. The restaurant ──────────────────────────────────────────────────────
830
-
831
- describe("the restaurant", () => {
832
- test("open slots come from the tables that seat the party and are not already taken", async () => {
833
- const open = expectToolOk(
834
- await runTool(checkRestaurantAvailability, { date: TODAY, partySize: 4 }),
835
- );
836
- expect(open.open).toContain("7 PM");
837
- const six = expectToolOk(
838
- await runTool(checkRestaurantAvailability, { date: TODAY, partySize: 6 }),
839
- );
840
- // The one six-top is García's at 7:30 tonight.
841
- expect(six.open).not.toContain("7:30 PM");
842
- expect(six.open).toContain("7 PM");
843
- });
842
+ // ─── 10. The restaurant ──────────────────────────────────────────────────────
843
+
844
+ describe("the restaurant", () => {
845
+ test("open slots come from the tables that seat the party and are not already taken", async () => {
846
+ const open = expectToolOk(
847
+ await run(checkRestaurantAvailability, { date: TODAY, partySize: 4 }),
848
+ );
849
+ expect(open.open).toContain("7 PM");
850
+ const six = expectToolOk(
851
+ await run(checkRestaurantAvailability, { date: TODAY, partySize: 6 }),
852
+ );
853
+ // The one six-top is García's at 7:30 tonight.
854
+ expect(six.open).not.toContain("7:30 PM");
855
+ expect(six.open).toContain("7 PM");
856
+ });
844
857
 
845
- test("a table is booked in one call, and the refusals carry the open times or the transfer", async () => {
846
- const ctx = createToolContext();
847
- const args = {
848
- date: TODAY,
849
- time: "19:00",
850
- partySize: 4,
851
- firstName: "Ana",
852
- lastName: "Reyes",
853
- phone: "415 555 0199",
854
- };
855
- const booked = expectToolOk(await runTool(reserveTable, args, ctx));
856
- expect(booked.code).toMatch(/^RES-/);
857
- expect(booked.time).toBe("7 PM");
858
-
859
- const odd = await run("reserve_table", { ...args, time: "19:15" }, ctx);
860
- expect(isToolFailure(odd) && odd.error).toMatch(/5:30 PM/);
861
- const big = await run("reserve_table", { ...args, partySize: 8 }, ctx);
862
- expect(isToolFailure(big) && big.error).toMatch(/transfer_call/);
863
- const past = await run("reserve_table", { ...args, date: "2026-06-01" }, ctx);
864
- expect(isToolFailure(past)).toBe(true);
865
- });
858
+ test("a table is booked in one call, and the refusals carry the open times or the transfer", async () => {
859
+ const ctx = createToolContext();
860
+ const args = {
861
+ date: TODAY,
862
+ time: "19:00",
863
+ partySize: 4,
864
+ firstName: "Ana",
865
+ lastName: "Reyes",
866
+ phone: "415 555 0199",
867
+ };
868
+ const booked = expectToolOk(await run(reserveTable, args, ctx));
869
+ expect(booked.code).toMatch(/^RES-/);
870
+ expect(booked.time).toBe("7 PM");
871
+
872
+ const odd = await run(reserveTable, { ...args, time: "19:15" }, ctx);
873
+ expect(isToolFailure(odd) && odd.error).toMatch(/5:30 PM/);
874
+ const big = await run(reserveTable, { ...args, partySize: 8 }, ctx);
875
+ expect(isToolFailure(big) && big.error).toMatch(/transfer_call/);
876
+ const past = await run(reserveTable, { ...args, date: "2026-06-01" }, ctx);
877
+ expect(isToolFailure(past)).toBe(true);
878
+ });
866
879
 
867
- test("moving a reservation keeps its table when that table is still free", async () => {
868
- const ctx = createToolContext();
869
- const moved = expectToolOk(
870
- await runTool(
871
- modifyRestaurantReservation,
872
- { lastName: "Bennett", confirmationCode: "RES-JK90", newDate: TODAY, newTime: "19:30" },
873
- ctx,
874
- ),
875
- );
876
- expect(moved).toMatchObject({ code: "RES-JK90", time: "7:30 PM", partySize: 4 });
877
- const reservation = hotelSlot.get(ctx).reservations.find((r) => r.code === "RES-JK90");
878
- expect(reservation).toMatchObject({ tableId: 3, time: "19:30" });
880
+ test("moving a reservation keeps its table when that table is still free", async () => {
881
+ const ctx = createToolContext();
882
+ const moved = expectToolOk(
883
+ await run(
884
+ modifyRestaurantReservation,
885
+ { lastName: "Bennett", confirmationCode: "RES-JK90", newDate: TODAY, newTime: "19:30" },
886
+ ctx,
887
+ ),
888
+ );
889
+ expect(moved).toMatchObject({ code: "RES-JK90", time: "7:30 PM", partySize: 4 });
890
+ const reservation = hotelSlot.get(ctx).reservations.find((r) => r.code === "RES-JK90");
891
+ expect(reservation).toMatchObject({ tableId: 3, time: "19:30" });
879
892
 
880
- const cancelled = expectToolOk(
881
- await run(
882
- "cancel_restaurant_reservation",
883
- { lastName: "Bennett", confirmationCode: "res jk90" },
884
- ctx,
885
- ),
886
- );
887
- expect(cancelled).toMatchObject({ cancelled: true });
888
- expect(
889
- isToolFailure(
893
+ const cancelled = expectToolOk(
890
894
  await run(
891
- "lookup_restaurant_reservation",
892
- { lastName: "Bennett", confirmationCode: "RES-JK90" },
895
+ cancelRestaurantReservation,
896
+ { lastName: "Bennett", confirmationCode: "res jk90" },
893
897
  ctx,
894
898
  ),
895
- ),
896
- ).toBe(true);
899
+ );
900
+ expect(cancelled).toMatchObject({ cancelled: true });
901
+ expect(
902
+ isToolFailure(
903
+ await run(
904
+ lookupRestaurantReservation,
905
+ { lastName: "Bennett", confirmationCode: "RES-JK90" },
906
+ ctx,
907
+ ),
908
+ ),
909
+ ).toBe(true);
910
+ });
897
911
  });
898
- });
899
912
 
900
- // ─── 11. Services and the ledger ─────────────────────────────────────────────
913
+ // ─── 11. Services and the ledger ─────────────────────────────────────────────
901
914
 
902
- describe("services", () => {
903
- test("an emergency is dispatched with no verification, and the direction matches the kind", async () => {
904
- const ctx = createToolContext();
905
- const sent = expectToolOk(
906
- await runTool(
915
+ describe("services", () => {
916
+ test("an emergency is dispatched with no verification, and the direction matches the kind", async () => {
917
+ const ctx = createToolContext();
918
+ const sent = expectToolOk(
919
+ await run(
920
+ dispatchEmergency,
921
+ { room: "room 401", kind: "medical", situation: "guest collapsed" },
922
+ ctx,
923
+ ),
924
+ );
925
+ expect(sent).toMatchObject({ dispatched: true, room: "401" });
926
+ expect(sent.next).toMatch(/9-1-1/);
927
+ expect(hotelSlot.get(ctx).tickets[0]?.kind).toBe("emergency");
928
+ const badRoom = await run(
907
929
  dispatchEmergency,
908
- { room: "room 401", kind: "medical", situation: "guest collapsed" },
909
- ctx,
910
- ),
911
- );
912
- expect(sent).toMatchObject({ dispatched: true, room: "401" });
913
- expect(sent.next).toMatch(/9-1-1/);
914
- expect(hotelSlot.get(ctx).tickets[0]?.kind).toBe("emergency");
915
- const badRoom = await run(
916
- "dispatch_emergency",
917
- { room: "999", kind: "fire", situation: "smoke" },
918
- ctx,
919
- );
920
- expect(isToolFailure(badRoom) && badRoom.error).toMatch(/no such room/);
921
- });
922
-
923
- test("a wake-up call is set, a followup is recorded, and each is a ledger line with a reference", async () => {
924
- const ctx = createToolContext();
925
- const wake = expectToolOk(
926
- await runTool(
927
- scheduleWakeupCall,
928
- { room: "304", guestName: "Frank Adler", date: addDays(TODAY, 1), time: "04:45" },
929
- ctx,
930
- ),
931
- );
932
- expect(wake.reference).toMatch(/^WUC-/);
933
- expect(wake.when).toBe("Tuesday, June 9 at 4:45 AM");
934
- const followup = expectToolOk(
935
- await runTool(
936
- recordFollowup,
937
- {
938
- kind: "housekeeping",
939
- callerName: "Priya Nair",
940
- callerPhone: "202",
941
- summary: "Two more towels to room 202.",
942
- },
930
+ { room: "999", kind: "fire", situation: "smoke" },
943
931
  ctx,
944
- ),
945
- );
946
- expect(followup.reference).toMatch(/^FUP-/);
947
- expect(followup.next).toContain("Two more towels");
948
- expect(deskView(hotelSlot.get(ctx)).ledger.map((t) => t.kind)).toEqual([
949
- "followup",
950
- "wakeup_call",
951
- ]);
952
- });
932
+ );
933
+ expect(isToolFailure(badRoom) && badRoom.error).toMatch(/no such room/);
934
+ });
953
935
 
954
- test("a transfer happens exactly once per department", async () => {
955
- const ctx = createToolContext();
956
- const first = expectToolOk(
957
- await runTool(
958
- transferCall,
959
- { destination: "restaurant", summary: "party of ten, private room" },
960
- ctx,
961
- ),
962
- );
963
- const second = expectToolOk(
964
- await runTool(transferCall, { destination: "restaurant", summary: "again" }, ctx),
965
- );
966
- expect(first.alreadyTransferred).toBe(false);
967
- expect(second.alreadyTransferred).toBe(true);
968
- expect(hotelSlot.get(ctx).tickets.filter((t) => t.kind === "transfer")).toHaveLength(1);
969
- });
936
+ test("a wake-up call is set, a followup is recorded, and each is a ledger line with a reference", async () => {
937
+ const ctx = createToolContext();
938
+ const wake = expectToolOk(
939
+ await run(
940
+ scheduleWakeupCall,
941
+ { room: "304", guestName: "Frank Adler", date: addDays(TODAY, 1), time: "04:45" },
942
+ ctx,
943
+ ),
944
+ );
945
+ expect(wake.reference).toMatch(/^WUC-/);
946
+ expect(wake.when).toBe("Tuesday, June 9 at 4:45 AM");
947
+ const followup = expectToolOk(
948
+ await run(
949
+ recordFollowup,
950
+ {
951
+ kind: "housekeeping",
952
+ callerName: "Priya Nair",
953
+ callerPhone: "202",
954
+ summary: "Two more towels to room 202.",
955
+ },
956
+ ctx,
957
+ ),
958
+ );
959
+ expect(followup.reference).toMatch(/^FUP-/);
960
+ expect(followup.next).toContain("Two more towels");
961
+ expect(deskView(hotelSlot.get(ctx)).ledger.map((t) => t.kind)).toEqual([
962
+ "followup",
963
+ "wakeup_call",
964
+ ]);
965
+ });
970
966
 
971
- test("the catalogs price a booking and refuse past its caps", async () => {
972
- const ctx = createToolContext();
973
- const tour = expectToolOk(
974
- await runTool(
975
- bookTour,
976
- {
977
- tour: "full_day_city",
978
- date: addDays(TODAY, 2),
979
- partySize: 2,
980
- guestName: "Sofía García",
981
- guestPhone: "415 555 0107",
982
- },
983
- ctx,
984
- ),
985
- );
986
- expect(tour.total).toBe("220 dollars");
987
- expect(tour.reference).toMatch(/^TUR-/);
988
- const tooMany = await run("book_tour", {
989
- tour: "private_city",
990
- date: addDays(TODAY, 2),
991
- partySize: 5,
992
- guestName: "x",
993
- guestPhone: "1",
967
+ test("a transfer happens exactly once per department", async () => {
968
+ const ctx = createToolContext();
969
+ const first = expectToolOk(
970
+ await run(
971
+ transferCall,
972
+ { destination: "restaurant", summary: "party of ten, private room" },
973
+ ctx,
974
+ ),
975
+ );
976
+ const second = expectToolOk(
977
+ await run(transferCall, { destination: "restaurant", summary: "again" }, ctx),
978
+ );
979
+ expect(first.alreadyTransferred).toBe(false);
980
+ expect(second.alreadyTransferred).toBe(true);
981
+ expect(hotelSlot.get(ctx).tickets.filter((t) => t.kind === "transfer")).toHaveLength(1);
994
982
  });
995
- expect(isToolFailure(tooMany) && tooMany.error).toMatch(/at most 4/);
996
- const past = await run("order_flowers", {
997
- arrangement: "roses",
998
- date: "2026-06-01",
999
- deliverTo: "401",
1000
- cardMessage: "Happy anniversary",
1001
- guestName: "x",
1002
- guestPhone: "1",
983
+
984
+ test("the catalogs price a booking and refuse past its caps", async () => {
985
+ const ctx = createToolContext();
986
+ const tour = expectToolOk(
987
+ await run(
988
+ bookTour,
989
+ {
990
+ tour: "full_day_city",
991
+ date: addDays(TODAY, 2),
992
+ partySize: 2,
993
+ guestName: "Sofía García",
994
+ guestPhone: "415 555 0107",
995
+ },
996
+ ctx,
997
+ ),
998
+ );
999
+ expect(tour.total).toBe("220 dollars");
1000
+ expect(tour.reference).toMatch(/^TUR-/);
1001
+ const tooMany = await run(bookTour, {
1002
+ tour: "private_city",
1003
+ date: addDays(TODAY, 2),
1004
+ partySize: 5,
1005
+ guestName: "x",
1006
+ guestPhone: "1",
1007
+ });
1008
+ expect(isToolFailure(tooMany) && tooMany.error).toMatch(/at most 4/);
1009
+ const past = await run(orderFlowers, {
1010
+ arrangement: "roses",
1011
+ date: "2026-06-01",
1012
+ deliverTo: "401",
1013
+ cardMessage: "Happy anniversary",
1014
+ guestName: "x",
1015
+ guestPhone: "1",
1016
+ });
1017
+ expect(isToolFailure(past) && past.error).toMatch(/in the past/);
1018
+ const spa = expectToolOk(
1019
+ await run(
1020
+ bookSpaAppointment,
1021
+ {
1022
+ service: "deep_tissue_massage",
1023
+ date: addDays(TODAY, 1),
1024
+ time: "10:00",
1025
+ partySize: 2,
1026
+ guestName: "x",
1027
+ guestPhone: "1",
1028
+ },
1029
+ ctx,
1030
+ ),
1031
+ );
1032
+ expect(spa.total).toBe("280 dollars");
1033
+ const biz = expectToolOk(
1034
+ await run(
1035
+ bookBusinessCenter,
1036
+ {
1037
+ service: "meeting_room",
1038
+ date: addDays(TODAY, 1),
1039
+ time: "09:00",
1040
+ durationHours: 3,
1041
+ guestName: "x",
1042
+ guestPhone: "1",
1043
+ },
1044
+ ctx,
1045
+ ),
1046
+ );
1047
+ expect(biz.total).toBe("120 dollars");
1003
1048
  });
1004
- expect(isToolFailure(past) && past.error).toMatch(/in the past/);
1005
- const spa = expectToolOk(
1006
- await runTool(
1007
- bookSpaAppointment,
1008
- {
1009
- service: "deep_tissue_massage",
1010
- date: addDays(TODAY, 1),
1011
- time: "10:00",
1012
- partySize: 2,
1013
- guestName: "x",
1014
- guestPhone: "1",
1015
- },
1016
- ctx,
1017
- ),
1018
- );
1019
- expect(spa.total).toBe("280 dollars");
1020
- const biz = expectToolOk(
1021
- await runTool(
1022
- bookBusinessCenter,
1023
- {
1024
- service: "meeting_room",
1025
- date: addDays(TODAY, 1),
1026
- time: "09:00",
1027
- durationHours: 3,
1028
- guestName: "x",
1029
- guestPhone: "1",
1030
- },
1031
- ctx,
1032
- ),
1033
- );
1034
- expect(biz.total).toBe("120 dollars");
1035
- });
1036
1049
 
1037
- test("the policy book renders the catalogs, so a price lives in one place", async () => {
1038
- const tours = expectToolOk(await runTool(lookupPolicy, { topic: "tours" }));
1039
- expect(tours.policy).toContain("Half-day city highlights");
1040
- expect(tours.policy).toContain("65 dollars per person");
1041
- expect(POLICIES.spa.body).toContain("140 dollars per person");
1042
- expect(
1043
- await toolInputIssues(agentDef, "lookup_policy", { topic: "not_a_topic" }),
1044
- ).toBeDefined();
1045
- });
1050
+ test("the policy book renders the catalogs, so a price lives in one place", async () => {
1051
+ const tours = expectToolOk(await run(lookupPolicy, { topic: "tours" }));
1052
+ expect(tours.policy).toContain("Half-day city highlights");
1053
+ expect(tours.policy).toContain("65 dollars per person");
1054
+ expect(POLICIES.spa.body).toContain("140 dollars per person");
1055
+ expect(await toolInputIssues(lookupPolicy, { topic: "not_a_topic" })).toBeDefined();
1056
+ });
1046
1057
 
1047
- test("a group under fifteen is not a group, and a car with five is not the hotel car", async () => {
1048
- expect(
1049
- await toolInputIssues(agentDef, "record_group_inquiry", {
1050
- company: "Acme",
1051
- contactName: "A",
1052
- contactPhone: "1",
1053
- partySize: 10,
1054
- shareType: "twin",
1055
- checkIn: addDays(TODAY, 30),
1056
- nights: 2,
1057
- }),
1058
- ).toBeDefined();
1059
- expect(
1060
- await toolInputIssues(agentDef, "book_airport_car", {
1061
- room: "401",
1062
- pickupDate: addDays(TODAY, 1),
1063
- pickupTime: "06:00",
1064
- passengers: 5,
1065
- }),
1066
- ).toBeDefined();
1067
- const car = expectToolOk(
1068
- await runTool(bookAirportCar, {
1069
- room: "401",
1070
- pickupDate: addDays(TODAY, 1),
1071
- pickupTime: "06:00",
1072
- passengers: 3,
1073
- }),
1074
- );
1075
- expect(car.total).toBe("85 dollars");
1076
- });
1058
+ test("a group under fifteen is not a group, and a car with five is not the hotel car", async () => {
1059
+ expect(
1060
+ await toolInputIssues(recordGroupInquiry, {
1061
+ company: "Acme",
1062
+ contactName: "A",
1063
+ contactPhone: "1",
1064
+ partySize: 10,
1065
+ shareType: "twin",
1066
+ checkIn: addDays(TODAY, 30),
1067
+ nights: 2,
1068
+ }),
1069
+ ).toBeDefined();
1070
+ expect(
1071
+ await toolInputIssues(bookAirportCar, {
1072
+ room: "401",
1073
+ pickupDate: addDays(TODAY, 1),
1074
+ pickupTime: "06:00",
1075
+ passengers: 5,
1076
+ }),
1077
+ ).toBeDefined();
1078
+ const car = expectToolOk(
1079
+ await run(bookAirportCar, {
1080
+ room: "401",
1081
+ pickupDate: addDays(TODAY, 1),
1082
+ pickupTime: "06:00",
1083
+ passengers: 3,
1084
+ }),
1085
+ );
1086
+ expect(car.total).toBe("85 dollars");
1087
+ });
1077
1088
 
1078
- test("a flight reference is normalized the way a caller spells one", async () => {
1079
- const ctx = createToolContext();
1080
- expectToolOk(
1081
- await run(
1082
- "request_flight_reconfirmation",
1083
- {
1084
- room: "304",
1085
- airline: "Iberia",
1086
- flightNumber: "ib 6174",
1087
- flightDate: addDays(TODAY, 3),
1088
- bookingReference: "x 7 q - 9 2 k",
1089
- seatCheck: true,
1090
- },
1091
- ctx,
1092
- ),
1093
- );
1094
- expect(hotelSlot.get(ctx).tickets[0]?.details).toMatchObject({
1095
- flightNumber: "IB6174",
1096
- bookingReference: "X7Q92K",
1089
+ test("a flight reference is normalized the way a caller spells one", async () => {
1090
+ const ctx = createToolContext();
1091
+ expectToolOk(
1092
+ await run(
1093
+ requestFlightReconfirmation,
1094
+ {
1095
+ room: "304",
1096
+ airline: "Iberia",
1097
+ flightNumber: "ib 6174",
1098
+ flightDate: addDays(TODAY, 3),
1099
+ bookingReference: "x 7 q - 9 2 k",
1100
+ seatCheck: true,
1101
+ },
1102
+ ctx,
1103
+ ),
1104
+ );
1105
+ expect(hotelSlot.get(ctx).tickets[0]?.details).toMatchObject({
1106
+ flightNumber: "IB6174",
1107
+ bookingReference: "X7Q92K",
1108
+ });
1097
1109
  });
1098
- });
1099
1110
 
1100
- test("the verified guest's extras: a late arrival, a re-sent folio, a new card", async () => {
1101
- const ctx = createToolContext();
1102
- await verify(ctx, "Smith", "HTL-AB12");
1103
- expectToolOk(await run("flag_late_arrival", { note: "around 1 AM" }, ctx));
1104
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.lateArrivalNote).toBe(
1105
- "around 1 AM",
1106
- );
1107
- const sent = expectToolOk(await runTool(resendConfirmation, { kind: "folio" }, ctx));
1108
- expect(sent.to).toBe("eleanor.smith@gmail.com");
1109
- const card = expectToolOk(await runTool(updateCard, A_CARD, ctx));
1110
- expect(card.cardLast4).toBe("4471");
1111
- expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.cardLast4).toBe("4471");
1112
- });
1111
+ test("the verified guest's extras: a late arrival, a re-sent folio, a new card", async () => {
1112
+ const ctx = createToolContext();
1113
+ await verify(ctx, "Smith", "HTL-AB12");
1114
+ expectToolOk(await run(flagLateArrival, { note: "around 1 AM" }, ctx));
1115
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.lateArrivalNote).toBe(
1116
+ "around 1 AM",
1117
+ );
1118
+ const sent = expectToolOk(await run(resendConfirmation, { kind: "folio" }, ctx));
1119
+ expect(sent.to).toBe("eleanor.smith@gmail.com");
1120
+ const card = expectToolOk(await run(updateCard, A_CARD, ctx));
1121
+ expect(card.cardLast4).toBe("4471");
1122
+ expect(hotelSlot.get(ctx).bookings.find((b) => b.code === "HTL-AB12")?.cardLast4).toBe(
1123
+ "4471",
1124
+ );
1125
+ });
1113
1126
 
1114
- test("two contexts never share a hotel", async () => {
1115
- const a = createToolContext();
1116
- const b = createToolContext();
1117
- await verify(a, "Smith", "HTL-AB12");
1118
- expectToolOk(await run("cancel_room_booking", a));
1119
- expect(hotelSlot.get(b).bookings.find((x) => x.code === "HTL-AB12")?.status).toBe("confirmed");
1127
+ test("two contexts never share a hotel", async () => {
1128
+ const a = createToolContext();
1129
+ const b = createToolContext();
1130
+ await verify(a, "Smith", "HTL-AB12");
1131
+ expectToolOk(await run(cancelRoomBooking, a));
1132
+ expect(hotelSlot.get(b).bookings.find((x) => x.code === "HTL-AB12")?.status).toBe(
1133
+ "confirmed",
1134
+ );
1135
+ });
1120
1136
  });
1121
1137
  });