@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,15 +1,16 @@
1
1
  /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
2
2
  import agentDef from "virtual:aai/agent";
3
- import type { SessionEvent, SessionEventHandler, ToolContext } from "@alexkroman1/aai";
3
+ import type { ToolContext } from "@alexkroman1/aai";
4
4
  import { isToolFailure } from "@alexkroman1/aai/utils";
5
5
  import {
6
6
  createToolContext,
7
- expectDialogOk,
8
7
  expectDialogRefused,
8
+ expectSlotContract,
9
9
  expectToolOk,
10
- runTool,
11
- toolRunner,
10
+ fireEvent,
11
+ sessionEvent,
12
12
  } from "@alexkroman1/aai-runtime/testing";
13
+ import { describeAgent } from "@alexkroman1/aai-runtime/testing/vitest";
13
14
  import { describe, expect, test } from "vitest";
14
15
  import {
15
16
  activeAssistant,
@@ -22,580 +23,567 @@ import {
22
23
  tripSlot,
23
24
  tripView,
24
25
  } from "./shared.ts";
26
+ import bookCarRental from "./tools/book_car_rental.ts";
25
27
  import bookExcursion from "./tools/book_excursion.ts";
26
28
  import bookHotel from "./tools/book_hotel.ts";
29
+ import cancelAction from "./tools/cancel_action.ts";
27
30
  import cancelTicket from "./tools/cancel_ticket.ts";
28
31
  import completeOrEscalate from "./tools/complete_or_escalate.ts";
32
+ import confirmAction from "./tools/confirm_action.ts";
29
33
  import lookupBooking from "./tools/lookup_booking.ts";
34
+ import searchCarRentals from "./tools/search_car_rentals.ts";
30
35
  import searchExcursions from "./tools/search_excursions.ts";
31
36
  import searchFlights from "./tools/search_flights.ts";
32
37
  import searchHotels from "./tools/search_hotels.ts";
38
+ import toCarRentalAssistant from "./tools/to_car_rental_assistant.ts";
39
+ import toExcursionAssistant from "./tools/to_excursion_assistant.ts";
40
+ import toFlightAssistant from "./tools/to_flight_assistant.ts";
33
41
  import toHotelAssistant from "./tools/to_hotel_assistant.ts";
34
42
  import updateTicket from "./tools/update_ticket.ts";
35
43
 
36
- // ─── Harness ─────────────────────────────────────────────────────────────────
37
-
38
- /** A tool by the name the model calls it by, bound to this agent. The lookup,
39
- * its "no such tool" message and the args-or-context shape are all
40
- * `toolRunner`'s (`@alexkroman1/aai-runtime/testing`); what is local is only which
41
- * agent it runs against. */
42
- const run = toolRunner(agentDef);
43
-
44
- /** The state a tool just mutated, read back the way `syncState` reads it. */
45
- function stateOf(ctx: ToolContext) {
46
- return tripSlot.get(ctx);
47
- }
48
-
49
- /**
50
- * Put the call at a desk the way the model has to: through that desk's own
51
- * delegation tool.
52
- *
53
- * Every desk tool checks the stack first (`requireDesk`) and refuses from
54
- * anywhere else, so a spec driving one has to stand where the model would. It is
55
- * one line per test rather than a shared `beforeEach` deliberately — which desk
56
- * a tool belongs to is what the block below is about, so it stays visible at the
57
- * call site.
58
- */
59
- const atDesk = async (id: SpecialistId, ctx: ToolContext): Promise<void> => {
60
- await run(`to_${id}_assistant`, { request: "what the caller asked for" }, ctx);
61
- };
62
-
63
- // ─── 1. The dialog stack ─────────────────────────────────────────────────────
64
-
65
- describe("dialog stack (routing.ts)", () => {
66
- test("delegating pushes a desk and hands back its brief", async () => {
67
- const ctx = createToolContext();
68
- expect(activeAssistant(stateOf(ctx))).toBe("primary");
69
-
70
- const handoff = await runTool(toHotelAssistant, { request: "somewhere near the water" }, ctx);
71
- expect(handoff.desk).toBe("hotel desk");
72
- // The brief IS the tool result — that is the whole port of their
73
- // per-assistant prompt onto a session whose prompt is fixed at connect.
74
- expect(handoff.instructions).toContain("hotel desk");
75
- expect(activeAssistant(stateOf(ctx))).toBe("hotel");
76
- });
44
+ describeAgent(agentDef, (run) => {
45
+ // ─── Harness ─────────────────────────────────────────────────────────────────
77
46
 
78
- test("re-delegating to the desk already holding the call does not grow the stack", async () => {
79
- const ctx = createToolContext();
80
- await run("to_flight_assistant", { request: "move my flight" }, ctx);
81
- await run("to_flight_assistant", { request: "actually a later one" }, ctx);
82
- expect(stateOf(ctx).dialogState).toEqual(["primary", "flight"]);
83
- });
47
+ /** The state a tool just mutated, read back the way `syncState` reads it. */
48
+ function stateOf(ctx: ToolContext) {
49
+ return tripSlot.get(ctx);
50
+ }
84
51
 
85
- test("complete_or_escalate pops, and never past the concierge", async () => {
86
- const ctx = createToolContext();
87
- await run("to_excursion_assistant", { request: "something to do" }, ctx);
52
+ /**
53
+ * Put the call at a desk the way the model has to: through that desk's own
54
+ * delegation tool.
55
+ *
56
+ * Every desk tool checks the stack first (`requireDesk`) and refuses from
57
+ * anywhere else, so a spec driving one has to stand where the model would. It is
58
+ * one line per test rather than a shared `beforeEach` deliberately — which desk
59
+ * a tool belongs to is what the block below is about, so it stays visible at the
60
+ * call site.
61
+ */
62
+ const DESK_ENTRY = {
63
+ flight: toFlightAssistant,
64
+ hotel: toHotelAssistant,
65
+ car_rental: toCarRentalAssistant,
66
+ excursion: toExcursionAssistant,
67
+ } as const satisfies Record<SpecialistId, unknown>;
68
+ const atDesk = async (id: SpecialistId, ctx: ToolContext): Promise<void> => {
69
+ await run(DESK_ENTRY[id], { request: "what the caller asked for" }, ctx);
70
+ };
88
71
 
89
- const back = await runTool(completeOrEscalate, { reason: "booked it" }, ctx);
90
- expect(back.returnedFrom).toBe("excursions desk");
91
- expect(back.nowHandling).toBe("concierge");
92
- expect(activeAssistant(stateOf(ctx))).toBe("primary");
72
+ // ─── 1. The dialog stack ─────────────────────────────────────────────────────
93
73
 
94
- // Popping again at the bottom is a no-op rather than an empty stack: the
95
- // slot's `after` hook is what guarantees there is always an assistant.
96
- await run("complete_or_escalate", { reason: "nothing else" }, ctx);
97
- expect(stateOf(ctx).dialogState).toEqual(["primary"]);
98
- });
99
- });
74
+ describe("dialog stack (routing.ts)", () => {
75
+ test("delegating pushes a desk and hands back its brief", async () => {
76
+ const ctx = createToolContext();
77
+ expect(activeAssistant(stateOf(ctx))).toBe("primary");
100
78
 
101
- // ─── 1b. The desk gate ───────────────────────────────────────────────────────
102
- //
103
- // What their graph gets from binding a tool set per node, and what this port
104
- // used to only ask the prompt for. The eval (`agent.eval.test.ts`) is what
105
- // measured the asking losing — 0 of 5 live runs, the model searching hotels
106
- // while the stack said `primary` — so these are the tests that make the stack
107
- // binding rather than descriptive.
108
-
109
- describe("the desk gate (requireDesk)", () => {
110
- const DESK_TOOLS = [
111
- ["search_flights", { route: "Boston" }, "flight"],
112
- ["update_ticket", { flightId: "LX52" }, "flight"],
113
- ["cancel_ticket", {}, "flight"],
114
- ["search_hotels", { city: "Boston" }, "hotel"],
115
- ["book_hotel", { hotelId: "H1", nights: 2 }, "hotel"],
116
- ["search_car_rentals", { city: "Boston" }, "car_rental"],
117
- ["book_car_rental", { carId: "C2", days: 3 }, "car_rental"],
118
- ["search_excursions", { city: "Boston" }, "excursion"],
119
- ["book_excursion", { excursionId: "E2" }, "excursion"],
120
- ] as const;
121
-
122
- test.each(DESK_TOOLS)("%s refuses at the concierge desk", async (name, args, desk) => {
123
- const ctx = createToolContext();
124
- const refused = (await run(name, args, ctx)) as { error?: string };
125
- // The refusal NAMES the way in, which is what the model recovers from
126
- // inside the same turn — a bare "not allowed" would leave it guessing.
127
- expect(refused.error).toContain(`to_${desk}_assistant`);
128
- // And nothing happened: no search result, no staging, no stack movement.
129
- expect(stateOf(ctx).pending).toBeNull();
130
- expect(activeAssistant(stateOf(ctx))).toBe("primary");
131
- expect(gateFlow.position(ctx).state).toBe("browsing");
132
- });
79
+ const handoff = await run(toHotelAssistant, { request: "somewhere near the water" }, ctx);
80
+ expect(handoff.desk).toBe("hotel desk");
81
+ // The brief IS the tool result — that is the whole port of their
82
+ // per-assistant prompt onto a session whose prompt is fixed at connect.
83
+ expect(handoff.instructions).toContain("hotel desk");
84
+ expect(activeAssistant(stateOf(ctx))).toBe("hotel");
85
+ });
133
86
 
134
- test.each(DESK_TOOLS)("%s refuses from ANOTHER desk", async (name, args, desk) => {
135
- const ctx = createToolContext();
136
- // The excursions desk for anything that is not its own, and the flight desk
137
- // for the excursion tools — so every case really is a wrong desk rather
138
- // than a coincidence of ordering.
139
- const wrong = desk === "excursion" ? "flight" : "excursion";
140
- await atDesk(wrong, ctx);
141
- const refused = (await run(name, args, ctx)) as { error?: string };
142
- expect(refused.error).toContain(`to_${desk}_assistant`);
143
- expect(refused.error).toContain(desk === "excursion" ? "flight desk" : "excursions desk");
144
- expect(stateOf(ctx).pending).toBeNull();
145
- });
87
+ test("re-delegating to the desk already holding the call does not grow the stack", async () => {
88
+ const ctx = createToolContext();
89
+ await run(toFlightAssistant, { request: "move my flight" }, ctx);
90
+ await run(toFlightAssistant, { request: "actually a later one" }, ctx);
91
+ expect(stateOf(ctx).dialogState).toEqual(["primary", "flight"]);
92
+ });
93
+
94
+ test("complete_or_escalate pops, and never past the concierge", async () => {
95
+ const ctx = createToolContext();
96
+ await run(toExcursionAssistant, { request: "something to do" }, ctx);
146
97
 
147
- test.each(DESK_TOOLS)("%s works once its own desk holds the call", async (name, args, desk) => {
148
- // The other half, and the one that makes the block above non-vacuous: a
149
- // gate that refused everywhere would pass every assertion up to here.
150
- const ctx = createToolContext();
151
- await atDesk(desk, ctx);
152
- expect(await run(name, args, ctx)).not.toMatchObject({
153
- error: expect.stringContaining("belongs to the"),
98
+ const back = await run(completeOrEscalate, { reason: "booked it" }, ctx);
99
+ expect(back.returnedFrom).toBe("excursions desk");
100
+ expect(back.nowHandling).toBe("concierge");
101
+ expect(activeAssistant(stateOf(ctx))).toBe("primary");
102
+
103
+ // Popping again at the bottom is a no-op rather than an empty stack: the
104
+ // slot's `after` hook is what guarantees there is always an assistant.
105
+ await run(completeOrEscalate, { reason: "nothing else" }, ctx);
106
+ expect(stateOf(ctx).dialogState).toEqual(["primary"]);
154
107
  });
155
108
  });
156
109
 
157
- test("the concierge's own tools are NOT gated", async () => {
158
- // `lookup_booking` is the concierge's, and the gate must not make the desk
159
- // unable to answer "what am I holding?" from wherever the call is.
160
- const ctx = createToolContext();
161
- await atDesk("hotel", ctx);
162
- const booking = await runTool(lookupBooking, ctx);
163
- expect(booking.passenger).toBe("Nadia Rossi");
164
- });
165
- });
110
+ // ─── 1b. The desk gate ───────────────────────────────────────────────────────
111
+ //
112
+ // What their graph gets from binding a tool set per node, and what this port
113
+ // used to only ask the prompt for. The eval (`agent.eval.test.ts`) is what
114
+ // measured the asking losing — 0 of 5 live runs, the model searching hotels
115
+ // while the stack said `primary` — so these are the tests that make the stack
116
+ // binding rather than descriptive.
117
+
118
+ describe("the desk gate (requireDesk)", () => {
119
+ const DESK_TOOLS = [
120
+ ["search_flights", searchFlights, { route: "Boston" }, "flight"],
121
+ ["update_ticket", updateTicket, { flightId: "LX52" }, "flight"],
122
+ ["cancel_ticket", cancelTicket, {}, "flight"],
123
+ ["search_hotels", searchHotels, { city: "Boston" }, "hotel"],
124
+ ["book_hotel", bookHotel, { hotelId: "H1", nights: 2 }, "hotel"],
125
+ ["search_car_rentals", searchCarRentals, { city: "Boston" }, "car_rental"],
126
+ ["book_car_rental", bookCarRental, { carId: "C2", days: 3 }, "car_rental"],
127
+ ["search_excursions", searchExcursions, { city: "Boston" }, "excursion"],
128
+ ["book_excursion", bookExcursion, { excursionId: "E2" }, "excursion"],
129
+ ] as const;
130
+
131
+ test.each(DESK_TOOLS)("%s refuses at the concierge desk", async (_name, tool, args, desk) => {
132
+ const ctx = createToolContext();
133
+ const refused = await run(tool, args, ctx);
134
+ // The refusal NAMES the way in, which is what the model recovers from
135
+ // inside the same turn — a bare "not allowed" would leave it guessing.
136
+ expect(isToolFailure(refused) && refused.error).toContain(`to_${desk}_assistant`);
137
+ // And nothing happened: no search result, no staging, no stack movement.
138
+ expect(stateOf(ctx).pending).toBeNull();
139
+ expect(activeAssistant(stateOf(ctx))).toBe("primary");
140
+ expect(gateFlow.position(ctx).state).toBe("browsing");
141
+ });
166
142
 
167
- // ─── 2. The confirmation gate ────────────────────────────────────────────────
168
- //
169
- // Their graph halts before a sensitive tool (`interrupt_before`) and resumes on
170
- // approval. Here every sensitive tool stages and applies nothing, so the
171
- // approval has somewhere to arrive. These are the tests that matter: a
172
- // regression makes the agent able to rebook a flight BY MISTAKE.
173
-
174
- describe("sensitive tools stage rather than act", () => {
175
- test.each([
176
- ["update_ticket", { flightId: "LX52" }, "flight"],
177
- ["cancel_ticket", {}, "flight"],
178
- ["book_hotel", { hotelId: "H1", nights: 2 }, "hotel"],
179
- ["book_car_rental", { carId: "C2", days: 3 }, "car_rental"],
180
- ["book_excursion", { excursionId: "E2" }, "excursion"],
181
- ] as const)("%s changes nothing on its own", async (name, args, desk) => {
182
- const ctx = createToolContext();
183
- await atDesk(desk, ctx);
184
- const before = structuredClone(stateOf(ctx));
185
-
186
- const staged = (await run(name, args, ctx)) as { awaitingConfirmation: boolean };
187
- expect(staged.awaitingConfirmation).toBe(true);
188
-
189
- const after = stateOf(ctx);
190
- expect(after.ticket).toEqual(before.ticket);
191
- expect(after.bookings).toEqual([]);
192
- expect(after.pending).not.toBeNull();
193
- });
143
+ test.each(DESK_TOOLS)("%s refuses from ANOTHER desk", async (_name, tool, args, desk) => {
144
+ const ctx = createToolContext();
145
+ // The excursions desk for anything that is not its own, and the flight desk
146
+ // for the excursion tools — so every case really is a wrong desk rather
147
+ // than a coincidence of ordering.
148
+ const wrong = desk === "excursion" ? "flight" : "excursion";
149
+ await atDesk(wrong, ctx);
150
+ const refused = await run(tool, args, ctx);
151
+ const error = isToolFailure(refused) && refused.error;
152
+ expect(error).toContain(`to_${desk}_assistant`);
153
+ expect(error).toContain(desk === "excursion" ? "flight desk" : "excursions desk");
154
+ expect(stateOf(ctx).pending).toBeNull();
155
+ });
194
156
 
195
- test("confirm_action applies the staged change, and only then", async () => {
196
- const ctx = createToolContext();
197
- await atDesk("hotel", ctx);
198
- await run("book_hotel", { hotelId: "H1", nights: 3 }, ctx);
199
-
200
- // Staging moved the gate, in the same window it wrote `pending`.
201
- expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
202
-
203
- // A gated tool answers the flow's POSITION wrapped around the body's own
204
- // return value, so the applied sentence is under `result`. `expectDialogOk`
205
- // keeps the position and THROWS on a refusal, quoting it — where the cast
206
- // it replaces read `undefined` off the failure and died three assertions
207
- // later on a property of undefined.
208
- const confirmed = expectDialogOk<{ applied: string; reference: string }>(
209
- await run("confirm_action", ctx),
157
+ test.each(DESK_TOOLS)(
158
+ "%s works once its own desk holds the call",
159
+ async (_name, tool, args, desk) => {
160
+ // The other half, and the one that makes the block above non-vacuous: a
161
+ // gate that refused everywhere would pass every assertion up to here.
162
+ const ctx = createToolContext();
163
+ await atDesk(desk, ctx);
164
+ expect(await run(tool, args, ctx)).not.toMatchObject({
165
+ error: expect.stringContaining("belongs to the"),
166
+ });
167
+ },
210
168
  );
211
- expect(confirmed.result.applied).toContain("Harborview Suites");
212
- // 3 nights at $265.
213
- expect(confirmed.result.applied).toContain("$795");
214
- // SETTLED: the gate re-armed as part of the same call.
215
- expect(confirmed.state).toBe("browsing");
216
-
217
- const state = stateOf(ctx);
218
- expect(state.pending).toBeNull();
219
- expect(state.bookings).toHaveLength(1);
220
- expect(state.bookings[0]?.reference).toBe(confirmed.result.reference);
221
-
222
- // The gate re-arms, and now REFUSES rather than reporting an empty apply —
223
- // `when: "awaitingConfirmation"` is what a second confirm meets.
224
- //
225
- // `expectDialogRefused` rather than a regex for the sentence: the refusal is
226
- // the SDK's, written in one place and matched from another, and it throws on
227
- // a call that SUCCEEDED — where a `toMatchObject` on a success reads
228
- // `undefined` for `error` and passes nothing worth reading. The state is
229
- // pinned too, because "refused" and "refused where the spec thinks the
230
- // conversation is" are two claims.
231
- expectDialogRefused(await run("confirm_action", ctx), "browsing");
232
- });
233
-
234
- test("cancel_action drops the staged change and leaves the booking alone", async () => {
235
- const ctx = createToolContext();
236
- await atDesk("flight", ctx);
237
- await run("update_ticket", { flightId: "LX54" }, ctx);
238
- const dropped = expectDialogOk<{ discarded: string }>(await run("cancel_action", ctx));
239
- expect(dropped.result.discarded).toContain("LX54");
240
- expect(dropped.state).toBe("browsing");
241
-
242
- const state = stateOf(ctx);
243
- expect(state.pending).toBeNull();
244
- expect(state.ticket?.flightId).toBe("LX40");
245
- expectDialogRefused(await run("cancel_action", ctx), "browsing");
246
- });
247
169
 
248
- test("a staged action naming something that does not exist is refused at staging time", async () => {
249
- // Refused where the model can still recover — before the caller is asked to
250
- // confirm a flight the airline does not fly.
251
- const ctx = createToolContext();
252
- await atDesk("flight", ctx);
253
- expect(await run("update_ticket", { flightId: "ZZ99" }, ctx)).toEqual({
254
- error: "No flight ZZ99 in the schedule.",
170
+ test("the concierge's own tools are NOT gated", async () => {
171
+ // `lookup_booking` is the concierge's, and the gate must not make the desk
172
+ // unable to answer "what am I holding?" from wherever the call is.
173
+ const ctx = createToolContext();
174
+ await atDesk("hotel", ctx);
175
+ const booking = await run(lookupBooking, ctx);
176
+ expect(booking.passenger).toBe("Nadia Rossi");
255
177
  });
256
- expect(stateOf(ctx).pending).toBeNull();
257
178
  });
258
179
 
259
- test("cancelling the ticket makes a later ticket change impossible", async () => {
260
- const ctx = createToolContext();
261
- await atDesk("flight", ctx);
262
- await run("cancel_ticket", ctx);
263
- await run("confirm_action", ctx);
264
- expect(stateOf(ctx).ticket).toBeNull();
180
+ // ─── 2. The confirmation gate ────────────────────────────────────────────────
181
+ //
182
+ // Their graph halts before a sensitive tool (`interrupt_before`) and resumes on
183
+ // approval. Here every sensitive tool stages and applies nothing, so the
184
+ // approval has somewhere to arrive. These are the tests that matter: a
185
+ // regression makes the agent able to rebook a flight BY MISTAKE.
186
+
187
+ describe("sensitive tools stage rather than act", () => {
188
+ test.each([
189
+ ["update_ticket", updateTicket, { flightId: "LX52" }, "flight"],
190
+ ["cancel_ticket", cancelTicket, {}, "flight"],
191
+ ["book_hotel", bookHotel, { hotelId: "H1", nights: 2 }, "hotel"],
192
+ ["book_car_rental", bookCarRental, { carId: "C2", days: 3 }, "car_rental"],
193
+ ["book_excursion", bookExcursion, { excursionId: "E2" }, "excursion"],
194
+ ] as const)("%s changes nothing on its own", async (_name, tool, args, desk) => {
195
+ const ctx = createToolContext();
196
+ await atDesk(desk, ctx);
197
+ const before = structuredClone(stateOf(ctx));
198
+
199
+ const staged = expectToolOk(await run(tool, args, ctx));
200
+ expect(staged.awaitingConfirmation).toBe(true);
201
+
202
+ const after = stateOf(ctx);
203
+ expect(after.ticket).toEqual(before.ticket);
204
+ expect(after.bookings).toEqual([]);
205
+ expect(after.pending).not.toBeNull();
206
+ });
265
207
 
266
- expect(await run("update_ticket", { flightId: "LX52" }, ctx)).toEqual({
267
- error: "This caller has no ticket to move — it was cancelled on this call.",
208
+ test("confirm_action applies the staged change, and only then", async () => {
209
+ const ctx = createToolContext();
210
+ await atDesk("hotel", ctx);
211
+ await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
212
+
213
+ // Staging moved the gate, in the same window it wrote `pending`.
214
+ expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
215
+
216
+ // A gated tool answers the flow's POSITION wrapped around the body's own
217
+ // return value, so the applied sentence is under `result`.
218
+ const confirmed = await run(confirmAction, ctx);
219
+ if (isToolFailure(confirmed)) throw new Error(confirmed.error);
220
+ expect(confirmed.result.applied).toContain("Harborview Suites");
221
+ // 3 nights at $265.
222
+ expect(confirmed.result.applied).toContain("$795");
223
+ // SETTLED: the gate re-armed as part of the same call.
224
+ expect(confirmed.state).toBe("browsing");
225
+
226
+ const state = stateOf(ctx);
227
+ expect(state.pending).toBeNull();
228
+ expect(state.bookings).toHaveLength(1);
229
+ expect(state.bookings[0]?.reference).toBe(confirmed.result.reference);
230
+
231
+ // The gate re-arms, and now REFUSES rather than reporting an empty apply —
232
+ // `when: "awaitingConfirmation"` is what a second confirm meets.
233
+ //
234
+ // `expectDialogRefused` rather than a regex for the sentence: the refusal is
235
+ // the SDK's, written in one place and matched from another, and it throws on
236
+ // a call that SUCCEEDED — where a `toMatchObject` on a success reads
237
+ // `undefined` for `error` and passes nothing worth reading. The state is
238
+ // pinned too, because "refused" and "refused where the spec thinks the
239
+ // conversation is" are two claims.
240
+ expectDialogRefused(await run(confirmAction, ctx), "browsing");
268
241
  });
269
- expect(await run("cancel_ticket", ctx)).toEqual({ error: "There is no ticket to cancel." });
270
- });
271
242
 
272
- test("a second staging is REFUSED rather than overwriting the first", async () => {
273
- // The LLM loop runs a step's tool calls concurrently, so two sensitive
274
- // tools in one step is ordinary: the model hears "move my flight and cancel
275
- // the old one" and emits both. Assigning `pending` unconditionally made the
276
- // second win — both answered `awaitingConfirmation`, the caller said yes
277
- // once, and one of the two changes was silently dropped forever.
278
- const ctx = createToolContext();
279
- await atDesk("flight", ctx);
280
- const first = expectToolOk(await runTool(updateTicket, { flightId: "LX52" }, ctx));
281
- expect(first.awaitingConfirmation).toBe(true);
282
-
283
- // Both from ONE desk, which is what a concurrent pair looks like now that
284
- // `requireDesk` is enforced. Another desk's tool would be refused by the
285
- // DESK gate first, which is a different refusal and would leave this one
286
- // unexercised.
287
- const second = await runTool(cancelTicket, ctx);
288
- if (!isToolFailure(second)) throw new Error("expected the second staging to be refused");
289
- // The refusal NAMES what is already waiting, which is what lets the model
290
- // settle that one and come back rather than guess.
291
- expect(second.error).toContain("LX52");
292
- expect(second.error).toMatch(/confirm_action or cancel_action/);
293
-
294
- // The first staging is untouched, and it is what a yes applies.
295
- expect(stateOf(ctx).pending).toEqual({ kind: "update_ticket", flightId: "LX52" });
296
- // A refused SECOND staging must not have moved the gate either — it was
297
- // already `awaitingConfirmation` and the refusal changed nothing.
298
- expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
299
- // `expectToolOk` is `expectDialogOk` with `.result` taken off: this assertion is about
300
- // what the apply DID, not about where the gate landed.
301
- const applied = expectToolOk<{ applied: string }>(await run("confirm_action", ctx));
302
- expect(applied.applied).toContain("LX52");
303
- expect(stateOf(ctx).bookings).toEqual([]);
304
-
305
- // Once the queue is clear, the next desk's booking can be staged after all.
306
- await atDesk("hotel", ctx);
307
- const retried = expectToolOk(await runTool(bookHotel, { hotelId: "H1", nights: 2 }, ctx));
308
- expect(retried.awaitingConfirmation).toBe(true);
309
- });
243
+ test("cancel_action drops the staged change and leaves the booking alone", async () => {
244
+ const ctx = createToolContext();
245
+ await atDesk("flight", ctx);
246
+ await run(updateTicket, { flightId: "LX54" }, ctx);
247
+ const dropped = await run(cancelAction, ctx);
248
+ if (isToolFailure(dropped)) throw new Error(dropped.error);
249
+ expect(dropped.result.discarded).toContain("LX54");
250
+ expect(dropped.state).toBe("browsing");
251
+
252
+ const state = stateOf(ctx);
253
+ expect(state.pending).toBeNull();
254
+ expect(state.ticket?.flightId).toBe("LX40");
255
+ expectDialogRefused(await run(cancelAction, ctx), "browsing");
256
+ });
310
257
 
311
- test("cancel_action clears the block, so a declined change does not wedge the desk", async () => {
312
- const ctx = createToolContext();
313
- await atDesk("car_rental", ctx);
314
- await run("book_car_rental", { carId: "C2", days: 3 }, ctx);
315
- await run("cancel_action", ctx);
316
- await atDesk("excursion", ctx);
317
- const staged = expectToolOk(await runTool(bookExcursion, { excursionId: "E2" }, ctx));
318
- expect(staged.awaitingConfirmation).toBe(true);
319
- });
258
+ test("a staged action naming something that does not exist is refused at staging time", async () => {
259
+ // Refused where the model can still recover — before the caller is asked to
260
+ // confirm a flight the airline does not fly.
261
+ const ctx = createToolContext();
262
+ await atDesk("flight", ctx);
263
+ expect(await run(updateTicket, { flightId: "ZZ99" }, ctx)).toEqual({
264
+ error: "No flight ZZ99 in the schedule.",
265
+ });
266
+ expect(stateOf(ctx).pending).toBeNull();
267
+ });
320
268
 
321
- test("two independent contexts never share a stack, a ticket or an itinerary", async () => {
322
- // What this really checks: the state lives in the SLOT and not in a
323
- // module-level variable. `createToolContext()` hands each call its own
324
- // detached slot store, so the isolation is per CONTEXT — two distinct
325
- // session ids would prove nothing extra, and `sessionSlot` could stop
326
- // keying by session with this still passing.
327
- const first = createToolContext();
328
- const second = createToolContext();
329
-
330
- await run("to_hotel_assistant", { request: "a room" }, first);
331
- await run("book_hotel", { hotelId: "H3", nights: 1 }, first);
332
- await run("confirm_action", first);
333
-
334
- expect(activeAssistant(stateOf(second))).toBe("primary");
335
- expect(stateOf(second).bookings).toEqual([]);
336
- // The GATE is per-session too, not just the trip.
337
- expect(gateFlow.position(second).state).toBe("browsing");
338
- expectDialogRefused(await run("confirm_action", second), "browsing");
339
- expect(stateOf(first).bookings).toHaveLength(1);
340
- });
341
- });
269
+ test("cancelling the ticket makes a later ticket change impossible", async () => {
270
+ const ctx = createToolContext();
271
+ await atDesk("flight", ctx);
272
+ await run(cancelTicket, ctx);
273
+ await run(confirmAction, ctx);
274
+ expect(stateOf(ctx).ticket).toBeNull();
275
+
276
+ expect(await run(updateTicket, { flightId: "LX52" }, ctx)).toEqual({
277
+ error: "This caller has no ticket to move — it was cancelled on this call.",
278
+ });
279
+ expect(await run(cancelTicket, ctx)).toEqual({ error: "There is no ticket to cancel." });
280
+ });
342
281
 
343
- // ─── 3. Search ───────────────────────────────────────────────────────────────
282
+ test("a second staging is REFUSED rather than overwriting the first", async () => {
283
+ // The LLM loop runs a step's tool calls concurrently, so two sensitive
284
+ // tools in one step is ordinary: the model hears "move my flight and cancel
285
+ // the old one" and emits both. Assigning `pending` unconditionally made the
286
+ // second win — both answered `awaitingConfirmation`, the caller said yes
287
+ // once, and one of the two changes was silently dropped forever.
288
+ const ctx = createToolContext();
289
+ await atDesk("flight", ctx);
290
+ const first = expectToolOk(await run(updateTicket, { flightId: "LX52" }, ctx));
291
+ expect(first.awaitingConfirmation).toBe(true);
292
+
293
+ // Both from ONE desk, which is what a concurrent pair looks like now that
294
+ // `requireDesk` is enforced. Another desk's tool would be refused by the
295
+ // DESK gate first, which is a different refusal and would leave this one
296
+ // unexercised.
297
+ const second = await run(cancelTicket, ctx);
298
+ if (!isToolFailure(second)) throw new Error("expected the second staging to be refused");
299
+ // The refusal NAMES what is already waiting, which is what lets the model
300
+ // settle that one and come back rather than guess.
301
+ expect(second.error).toContain("LX52");
302
+ expect(second.error).toMatch(/confirm_action or cancel_action/);
303
+
304
+ // The first staging is untouched, and it is what a yes applies.
305
+ expect(stateOf(ctx).pending).toEqual({ kind: "update_ticket", flightId: "LX52" });
306
+ // A refused SECOND staging must not have moved the gate either — it was
307
+ // already `awaitingConfirmation` and the refusal changed nothing.
308
+ expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
309
+ // `expectToolOk` takes the envelope off: this assertion is about what the
310
+ // apply DID, not about where the gate landed.
311
+ const applied = expectToolOk(await run(confirmAction, ctx));
312
+ expect(applied.applied).toContain("LX52");
313
+ expect(stateOf(ctx).bookings).toEqual([]);
314
+
315
+ // Once the queue is clear, the next desk's booking can be staged after all.
316
+ await atDesk("hotel", ctx);
317
+ const retried = expectToolOk(await run(bookHotel, { hotelId: "H1", nights: 2 }, ctx));
318
+ expect(retried.awaitingConfirmation).toBe(true);
319
+ });
344
320
 
345
- describe("search tools", () => {
346
- test("an unmatched route widens to the whole schedule rather than answering nothing", async () => {
347
- const ctx = createToolContext();
348
- await atDesk("flight", ctx);
349
- const hit = expectToolOk(await runTool(searchFlights, { route: "Zurich to Boston" }, ctx));
350
- expect(hit.widened).toBe(false);
351
- expect(hit.flights).toHaveLength(3);
321
+ test("cancel_action clears the block, so a declined change does not wedge the desk", async () => {
322
+ const ctx = createToolContext();
323
+ await atDesk("car_rental", ctx);
324
+ await run(bookCarRental, { carId: "C2", days: 3 }, ctx);
325
+ await run(cancelAction, ctx);
326
+ await atDesk("excursion", ctx);
327
+ const staged = expectToolOk(await run(bookExcursion, { excursionId: "E2" }, ctx));
328
+ expect(staged.awaitingConfirmation).toBe(true);
329
+ });
352
330
 
353
- const miss = expectToolOk(await runTool(searchFlights, { route: "Osaka" }, ctx));
354
- expect(miss.widened).toBe(true);
355
- expect(miss.flights).toHaveLength(FLIGHTS.length);
331
+ test("two independent contexts never share a stack, a ticket or an itinerary", async () => {
332
+ // What this really checks: the state lives in the SLOT and not in a
333
+ // module-level variable. `createToolContext()` hands each call its own
334
+ // detached slot store, so the isolation is per CONTEXT — two distinct
335
+ // session ids would prove nothing extra, and `sessionSlot` could stop
336
+ // keying by session with this still passing.
337
+ const first = createToolContext();
338
+ const second = createToolContext();
339
+
340
+ await run(toHotelAssistant, { request: "a room" }, first);
341
+ await run(bookHotel, { hotelId: "H3", nights: 1 }, first);
342
+ await run(confirmAction, first);
343
+
344
+ expect(activeAssistant(stateOf(second))).toBe("primary");
345
+ expect(stateOf(second).bookings).toEqual([]);
346
+ // The GATE is per-session too, not just the trip.
347
+ expect(gateFlow.position(second).state).toBe("browsing");
348
+ expectDialogRefused(await run(confirmAction, second), "browsing");
349
+ expect(stateOf(first).bookings).toHaveLength(1);
350
+ });
356
351
  });
357
352
 
358
- test("a departure-time floor filters the schedule, and a bad clock is left out", async () => {
359
- const ctx = createToolContext();
360
- await atDesk("flight", ctx);
361
- // 17:40 and 21:15 and 19:55 are at or after 17:00; the two morning
362
- // departures are not. Compared as STRINGS, which is only legal because
363
- // every reading is zero-padded — the property `isClockTime` is asked for.
364
- const evening = expectToolOk(await runTool(searchFlights, { departsAfter: "17:00" }, ctx));
365
- expect(evening.widened).toBe(false);
366
- expect(evening.flights.map((f) => f.flight)).toEqual(["LX54", "LX15", "LX17"]);
367
-
368
- // Nothing that late, so the desk widens to the whole schedule rather than
369
- // telling the caller there is nothing — the same "be generous" arm the
370
- // route filter has.
371
- const midnight = expectToolOk(await runTool(searchFlights, { departsAfter: "23:30" }, ctx));
372
- expect(midnight.widened).toBe(true);
373
- expect(midnight.flights).toHaveLength(FLIGHTS.length);
374
-
375
- // The schedule's own half of the same rule: a row whose departure is not a
376
- // clock reading has nothing to compare, and `departureClock` says so rather
377
- // than ordering the caller's request against "Tue".
378
- expect(departureClock(FLIGHTS[0] as Flight)).toBe("13:05");
379
- expect(departureClock({ ...(FLIGHTS[0] as Flight), departs: "Tuesday" })).toBeUndefined();
380
- });
353
+ // ─── 3. Search ───────────────────────────────────────────────────────────────
381
354
 
382
- test("hotels come back cheapest first, and a ceiling filters them", async () => {
383
- const ctx = createToolContext();
384
- await atDesk("hotel", ctx);
385
- const all = expectToolOk(await runTool(searchHotels, { city: "Boston" }, ctx));
386
- // Always to the cent: `formatMoney` is one shape at every desk, where
387
- // this template's own `toLocaleString` copy dropped `.00` on a round
388
- // number and kept it on a price with change.
389
- expect(all.hotels.map((h) => h.perNight)).toEqual(["$179.95", "$265.00", "$340.00"]);
390
-
391
- const cheap = expectToolOk(
392
- await runTool(searchHotels, { city: "Boston", maxPerNight: 200 }, ctx),
393
- );
394
- expect(cheap.hotels).toHaveLength(1);
395
- expect(cheap.hotels[0]?.name).toBe("Cambridge Rooms");
396
- });
355
+ describe("search tools", () => {
356
+ test("an unmatched route widens to the whole schedule rather than answering nothing", async () => {
357
+ const ctx = createToolContext();
358
+ await atDesk("flight", ctx);
359
+ const hit = expectToolOk(await run(searchFlights, { route: "Zurich to Boston" }, ctx));
360
+ expect(hit.widened).toBe(false);
361
+ expect(hit.flights).toHaveLength(3);
397
362
 
398
- test("an excursion keyword that matches nothing falls back to the city", async () => {
399
- const ctx = createToolContext();
400
- await atDesk("excursion", ctx);
401
- const result = expectToolOk(
402
- await runTool(searchExcursions, { city: "Boston", keyword: "skiing" }, ctx),
403
- );
404
- expect(result.widened).toBe(true);
405
- expect(result.excursions).toHaveLength(3);
406
- });
363
+ const miss = expectToolOk(await run(searchFlights, { route: "Osaka" }, ctx));
364
+ expect(miss.widened).toBe(true);
365
+ expect(miss.flights).toHaveLength(FLIGHTS.length);
366
+ });
407
367
 
408
- test("lookup_booking reports the ticket the caller is actually holding", async () => {
409
- const ctx = createToolContext();
410
- await atDesk("flight", ctx);
411
- await run("update_ticket", { flightId: "LX52" }, ctx);
412
- await run("confirm_action", ctx);
413
- const booking = await runTool(lookupBooking, ctx);
414
- expect(booking.passenger).toBe("Nadia Rossi");
415
- expect(booking.ticket?.flight).toBe("LX52");
416
- expect(booking.ticket?.departs).toBe("Wed 09:20");
417
- });
418
- });
368
+ test("a departure-time floor filters the schedule, and a bad clock is left out", async () => {
369
+ const ctx = createToolContext();
370
+ await atDesk("flight", ctx);
371
+ // 17:40 and 21:15 and 19:55 are at or after 17:00; the two morning
372
+ // departures are not. Compared as STRINGS, which is only legal because
373
+ // every reading is zero-padded — the property `isClockTime` is asked for.
374
+ const evening = expectToolOk(await run(searchFlights, { departsAfter: "17:00" }, ctx));
375
+ expect(evening.widened).toBe(false);
376
+ expect(evening.flights.map((f) => f.flight)).toEqual(["LX54", "LX15", "LX17"]);
377
+
378
+ // Nothing that late, so the desk widens to the whole schedule rather than
379
+ // telling the caller there is nothing — the same "be generous" arm the
380
+ // route filter has.
381
+ const midnight = expectToolOk(await run(searchFlights, { departsAfter: "23:30" }, ctx));
382
+ expect(midnight.widened).toBe(true);
383
+ expect(midnight.flights).toHaveLength(FLIGHTS.length);
384
+
385
+ // The schedule's own half of the same rule: a row whose departure is not a
386
+ // clock reading has nothing to compare, and `departureClock` says so rather
387
+ // than ordering the caller's request against "Tue".
388
+ expect(departureClock(FLIGHTS[0] as Flight)).toBe("13:05");
389
+ expect(departureClock({ ...(FLIGHTS[0] as Flight), departs: "Tuesday" })).toBeUndefined();
390
+ });
419
391
 
420
- // ─── 4. The projection contract with client.tsx ─────────────────────────────
421
-
422
- describe("tripView projection", () => {
423
- test("an untouched call projects the seeded booking at the concierge desk", () => {
424
- // Exactly the frame `client.tsx` renders before the first push — it passes
425
- // this same projection to `useAgentState`.
426
- const view = tripSlot.projected();
427
- expect(view).toMatchObject({
428
- assistant: "primary",
429
- assistantTitle: "concierge",
430
- bookings: [],
431
- total: 0,
432
- pending: null,
392
+ test("hotels come back cheapest first, and a ceiling filters them", async () => {
393
+ const ctx = createToolContext();
394
+ await atDesk("hotel", ctx);
395
+ const all = expectToolOk(await run(searchHotels, { city: "Boston" }, ctx));
396
+ // Always to the cent: `formatMoney` is one shape at every desk, where
397
+ // this template's own `toLocaleString` copy dropped `.00` on a round
398
+ // number and kept it on a price with change.
399
+ expect(all.hotels.map((h) => h.perNight)).toEqual(["$179.95", "$265.00", "$340.00"]);
400
+
401
+ const cheap = expectToolOk(
402
+ await run(searchHotels, { city: "Boston", maxPerNight: 200 }, ctx),
403
+ );
404
+ expect(cheap.hotels).toHaveLength(1);
405
+ expect(cheap.hotels[0]?.name).toBe("Cambridge Rooms");
433
406
  });
434
- expect(view.ticket?.flightId).toBe("LX40");
435
- });
436
407
 
437
- test("renders the staged action as the prose the concierge just spoke", async () => {
438
- const ctx = createToolContext();
439
- await run("to_car_rental_assistant", { request: "a car for the week" }, ctx);
440
- await run("book_car_rental", { carId: "C3", days: 4 }, ctx);
441
-
442
- const view = tripView(stateOf(ctx));
443
- expect(view.assistant).toBe("car_rental");
444
- expect(view.assistantTitle).toBe("car rental desk");
445
- // $95/day × 4 — the sidebar and the spoken read-back derive from one string.
446
- expect(view.pending).toContain("$380");
447
- expect(view.log.at(-1)).toContain("Awaiting confirmation");
448
- });
408
+ test("an excursion keyword that matches nothing falls back to the city", async () => {
409
+ const ctx = createToolContext();
410
+ await atDesk("excursion", ctx);
411
+ const result = expectToolOk(
412
+ await run(searchExcursions, { city: "Boston", keyword: "skiing" }, ctx),
413
+ );
414
+ expect(result.widened).toBe(true);
415
+ expect(result.excursions).toHaveLength(3);
416
+ });
449
417
 
450
- test("totals every confirmed booking, to the cent", async () => {
451
- const ctx = createToolContext();
452
- await atDesk("hotel", ctx);
453
- await run("book_hotel", { hotelId: "H3", nights: 3 }, ctx); // 3 × 179.95
454
- await run("confirm_action", ctx);
455
- await atDesk("excursion", ctx);
456
- await run("book_excursion", { excursionId: "E1" }, ctx); // 35
457
- await run("confirm_action", ctx);
458
-
459
- const view = tripView(stateOf(ctx));
460
- // `179.95 * 3` is `539.8499999999999`, so this is the assertion `roundMoney`
461
- // is there for: the price is what gets STORED and then summed, and a
462
- // booking that carries the dust makes every later comparison a coin toss.
463
- // It would print as $539.85 either way, which is what hides it.
464
- expect(view.bookings[0]?.price).toBe(539.85);
465
- expect(view.total).toBe(574.85);
466
- expect(view.bookings.map((b) => b.kind)).toEqual(["hotel", "excursion"]);
467
- expect(view.pending).toBeNull();
418
+ test("lookup_booking reports the ticket the caller is actually holding", async () => {
419
+ const ctx = createToolContext();
420
+ await atDesk("flight", ctx);
421
+ await run(updateTicket, { flightId: "LX52" }, ctx);
422
+ await run(confirmAction, ctx);
423
+ const booking = await run(lookupBooking, ctx);
424
+ expect(booking.passenger).toBe("Nadia Rossi");
425
+ expect(booking.ticket?.flight).toBe("LX52");
426
+ expect(booking.ticket?.departs).toBe("Wed 09:20");
427
+ });
468
428
  });
469
- });
470
429
 
471
- describe("the call log", () => {
472
- test("is capped by the slot, so a long call cannot grow the frame without bound", async () => {
473
- // The log rides in every `syncState` frame, and it now has writers that are
474
- // not tool calls at all (`call-events.ts` appends on a reported error), so
475
- // "how long can this get" is a question with no answer in the tools. The
476
- // slot's `caps` is the answer, and this is the assertion that it is real.
477
- const ctx = createToolContext();
478
- for (let i = 0; i < LOG_CAP + 5; i++) {
479
- await run("to_flight_assistant", { request: `ask ${i}` }, ctx);
480
- }
481
- const log = stateOf(ctx).log;
482
- expect(log).toHaveLength(LOG_CAP);
483
- // Capped at the FRONT: what a desk reading the sidebar wants is the end of
484
- // the call, so the oldest lines are the ones that go.
485
- expect(log[0]).toContain("ask 5");
486
- expect(log.at(-1)).toContain(`ask ${LOG_CAP + 4}`);
487
- });
488
- });
430
+ // ─── 4. The projection contract with client.tsx ─────────────────────────────
489
431
 
490
- describe("a caller who hangs up", () => {
491
- /** The frame the runtime offers a declared dialog when a session times out. */
492
- const CALLER_GONE = { type: "session.timedOut", meta: { id: "evt_1", at: 0 } } as const;
432
+ describe("tripView projection", () => {
433
+ test("the slot keeps its contract", () => {
434
+ expectSlotContract(tripSlot, {
435
+ write: (trip) => {
436
+ trip.log.push("a line");
437
+ },
438
+ });
439
+ });
493
440
 
494
- /**
495
- * The same event, delivered to the AGENT'S hooks the way the runtime delivers
496
- * it: the handler declared for the event's own type.
497
- *
498
- * The cast is the runtime's own (`aai-runtime/src/session/emitter.ts` makes it once, at the
499
- * lookup): `events` is typed per key, so a dispatch driven by an event reads
500
- * its handler back as the union's `SessionEventHandler`. A `ToolContext`
501
- * stands in for the hook context — a handler is handed `slots` and
502
- * `sessionId`, which is all `tripSlot.update` needs and deliberately much less
503
- * than a tool gets.
504
- */
505
- const deliver = (event: SessionEvent, ctx: ToolContext): void => {
506
- const handler = agentDef.events?.[event.type] as SessionEventHandler | undefined;
507
- // A throw rather than an `expect`: this runs from a helper, and the failure
508
- // it reports — the agent declares no hook for this event — is a fact about
509
- // the declaration rather than about the case that called it.
510
- if (!handler) throw new Error(`no handler is declared for ${event.type}`);
511
- handler(event, ctx);
512
- };
441
+ test("an untouched call projects the seeded booking at the concierge desk", () => {
442
+ // Exactly the frame `client.tsx` renders before the first push — it passes
443
+ // this same projection to `useAgentState`.
444
+ const view = tripSlot.projected();
445
+ expect(view).toMatchObject({
446
+ assistant: "primary",
447
+ assistantTitle: "concierge",
448
+ bookings: [],
449
+ total: 0,
450
+ pending: null,
451
+ });
452
+ expect(view.ticket?.flightId).toBe("LX40");
453
+ });
513
454
 
514
- test("ends the call, from a gate that is holding a staged booking", async () => {
515
- const ctx = createToolContext();
516
- await atDesk("hotel", ctx);
517
- await run("book_hotel", { hotelId: "H1", nights: 3 }, ctx);
518
- expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
455
+ test("renders the staged action as the prose the concierge just spoke", async () => {
456
+ const ctx = createToolContext();
457
+ await run(toCarRentalAssistant, { request: "a car for the week" }, ctx);
458
+ await run(bookCarRental, { carId: "C3", days: 4 }, ctx);
459
+
460
+ const view = tripView(stateOf(ctx));
461
+ expect(view.assistant).toBe("car_rental");
462
+ expect(view.assistantTitle).toBe("car rental desk");
463
+ // $95/day × 4 — the sidebar and the spoken read-back derive from one string.
464
+ expect(view.pending).toContain("$380");
465
+ expect(view.log.at(-1)).toContain("Awaiting confirmation");
466
+ });
519
467
 
520
- const at = gateFlow.receive(ctx, CALLER_GONE);
521
- expect(at.state).toBe("abandoned");
522
- expect(at.done).toBe(true);
468
+ test("totals every confirmed booking, to the cent", async () => {
469
+ const ctx = createToolContext();
470
+ await atDesk("hotel", ctx);
471
+ await run(bookHotel, { hotelId: "H3", nights: 3 }, ctx); // 3 × 179.95
472
+ await run(confirmAction, ctx);
473
+ await atDesk("excursion", ctx);
474
+ await run(bookExcursion, { excursionId: "E1" }, ctx); // 35
475
+ await run(confirmAction, ctx);
476
+
477
+ const view = tripView(stateOf(ctx));
478
+ // `179.95 * 3` is `539.8499999999999`, so this is the assertion `roundMoney`
479
+ // is there for: the price is what gets STORED and then summed, and a
480
+ // booking that carries the dust makes every later comparison a coin toss.
481
+ // It would print as $539.85 either way, which is what hides it.
482
+ expect(view.bookings[0]?.price).toBe(539.85);
483
+ expect(view.total).toBe(574.85);
484
+ expect(view.bookings.map((b) => b.kind)).toEqual(["hotel", "excursion"]);
485
+ expect(view.pending).toBeNull();
486
+ });
523
487
  });
524
488
 
525
- test("a sensitive tool cannot run afterwards", async () => {
526
- const ctx = createToolContext();
527
- await atDesk("hotel", ctx);
528
- await run("book_hotel", { hotelId: "H1", nights: 3 }, ctx);
529
- gateFlow.receive(ctx, CALLER_GONE);
530
-
531
- // The property the state exists for: `confirm_action` is what turns a
532
- // staged booking into a real one, and nobody is on the call to agree to it.
533
- //
534
- // The shape this replaces — `isToolFailure(…)` then a `toContain` guarded by
535
- // it — lets a SUCCESS through as an assertion that never runs.
536
- expectDialogRefused(await run("confirm_action", {}, ctx), "abandoned");
537
- // Still abandoned afterwards: refusing once and reopening would satisfy the
538
- // line above while losing the property the state exists for.
539
- expect(gateFlow.position(ctx).state).toBe("abandoned");
489
+ describe("the call log", () => {
490
+ test("is capped by the slot, so a long call cannot grow the frame without bound", async () => {
491
+ const ctx = createToolContext();
492
+ for (let i = 0; i < LOG_CAP + 5; i++) {
493
+ await run(toFlightAssistant, { request: `ask ${i}` }, ctx);
494
+ }
495
+ const log = stateOf(ctx).log;
496
+ expect(log).toHaveLength(LOG_CAP);
497
+ // Capped at the FRONT: what a desk reading the sidebar wants is the end of
498
+ // the call, so the oldest lines are the ones that go.
499
+ expect(log[0]).toContain("ask 5");
500
+ expect(log.at(-1)).toContain(`ask ${LOG_CAP + 4}`);
501
+ });
540
502
  });
541
503
 
542
- test("the staged action is still THERE — the state is final so nothing reads it", async () => {
543
- const ctx = createToolContext();
544
- await atDesk("hotel", ctx);
545
- await run("book_hotel", { hotelId: "H1", nights: 3 }, ctx);
546
- gateFlow.receive(ctx, CALLER_GONE);
547
-
548
- // Stated as a test because it is the feature's sharpest limit: a session
549
- // event SENDS AN EVENT and cannot run a tool, so `pending` is untouched.
550
- // That is safe here only because `abandoned` is final — the same shape as a
551
- // timeout returning to `browsing` would strand a staged change in a call
552
- // that carries on.
553
- expect(tripSlot.get(ctx).pending).not.toBeNull();
554
- });
504
+ describe("a caller who hangs up", () => {
505
+ /** The event the runtime hands a declared dialog when a session times out. */
506
+ const CALLER_GONE = sessionEvent("session.timedOut");
555
507
 
556
- test("the call log says the caller went, and names what was never applied", () => {
557
- // The other route the same event takes: the dialog moves the POSITION, and
558
- // `agent({ events })` writes the LINE. Neither covers the other — a
559
- // position is not something a desk can read afterwards, and a hook cannot
560
- // stop `confirm_action` running.
561
- const ctx = createToolContext();
562
- tripSlot.update(ctx, (trip) => {
563
- trip.pending = { kind: "book_hotel", hotelId: "H1", nights: 3 };
508
+ test("ends the call, from a gate that is holding a staged booking", async () => {
509
+ const ctx = createToolContext();
510
+ await atDesk("hotel", ctx);
511
+ await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
512
+ expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
513
+
514
+ await fireEvent(agentDef, CALLER_GONE, ctx);
515
+ const at = gateFlow.position(ctx);
516
+ expect(at.state).toBe("abandoned");
517
+ expect(at.done).toBe(true);
564
518
  });
565
519
 
566
- deliver(CALLER_GONE, ctx);
520
+ test("a sensitive tool cannot run afterwards", async () => {
521
+ const ctx = createToolContext();
522
+ await atDesk("hotel", ctx);
523
+ await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
524
+ await fireEvent(agentDef, CALLER_GONE, ctx);
525
+
526
+ // The property the state exists for: `confirm_action` is what turns a
527
+ // staged booking into a real one, and nobody is on the call to agree to it.
528
+ expectDialogRefused(await run(confirmAction, ctx), "abandoned");
529
+ // Still abandoned afterwards: refusing once and reopening would lose the
530
+ // property the state exists for.
531
+ expect(gateFlow.position(ctx).state).toBe("abandoned");
532
+ });
567
533
 
568
- expect(tripSlot.get(ctx).log.at(-1)).toContain("Caller gone");
569
- expect(tripSlot.get(ctx).log.at(-1)).toContain("Harborview Suites");
570
- // A hook records; it does not settle. The staged change is still there,
571
- // which is the whole reason the line names it.
572
- expect(tripSlot.get(ctx).pending).not.toBeNull();
573
- });
534
+ test("the staged action is still THERE — the state is final so nothing reads it", async () => {
535
+ const ctx = createToolContext();
536
+ await atDesk("hotel", ctx);
537
+ await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
538
+ await fireEvent(agentDef, CALLER_GONE, ctx);
574
539
 
575
- test("with nothing staged it says so, rather than naming an empty change", () => {
576
- const ctx = createToolContext();
577
- deliver(CALLER_GONE, ctx);
578
- expect(tripSlot.get(ctx).log).toEqual(["Caller gone — nothing was waiting."]);
579
- });
540
+ // A session event sends an event and cannot run a tool, so `pending` is
541
+ // untouched. Safe only because `abandoned` is final — a timeout returning
542
+ // to `browsing` would strand a staged change in a call that carries on.
543
+ expect(tripSlot.get(ctx).pending).not.toBeNull();
544
+ });
580
545
 
581
- test("an error on the call is recorded too, fatal or not", () => {
582
- const ctx = createToolContext();
583
- const meta = { id: "evt_2", at: 0 };
584
- // Declared under its own key, so the handler reads `code`, `message` and
585
- // `fatal` off the event with no narrowing — which is what the map's typed
586
- // half buys and the reason these are two handlers rather than one `"*"`.
587
- deliver(
588
- { type: "error.reported", meta, code: "tts", message: "voice down", fatal: false },
589
- ctx,
590
- );
591
- deliver(
592
- { type: "error.reported", meta, code: "llm", message: "gateway 503", fatal: true },
593
- ctx,
594
- );
546
+ test("the call log says the caller went, and names what was never applied", async () => {
547
+ // `abandoned`'s `onEnter` writes the line in the same window the move
548
+ // lands in — a position is not something a desk can read afterwards.
549
+ const ctx = createToolContext();
550
+ tripSlot.update(ctx, (trip) => {
551
+ trip.pending = { kind: "book_hotel", hotelId: "H1", nights: 3 };
552
+ });
595
553
 
596
- expect(tripSlot.get(ctx).log).toEqual([
597
- "Trouble on the call (tts): voice down",
598
- "Call failed (llm): gateway 503",
599
- ]);
554
+ await fireEvent(agentDef, CALLER_GONE, ctx);
555
+
556
+ expect(tripSlot.get(ctx).log.at(-1)).toContain("Caller gone");
557
+ expect(tripSlot.get(ctx).log.at(-1)).toContain("Harborview Suites");
558
+ // A hook records; it does not settle.
559
+ expect(tripSlot.get(ctx).pending).not.toBeNull();
560
+ });
561
+
562
+ test("with nothing staged it says so, rather than naming an empty change", async () => {
563
+ const ctx = createToolContext();
564
+ await fireEvent(agentDef, CALLER_GONE, ctx);
565
+ expect(tripSlot.get(ctx).log).toEqual(["Caller gone — nothing was waiting."]);
566
+ });
567
+
568
+ test("an error on the call is recorded too, fatal or not", async () => {
569
+ const ctx = createToolContext();
570
+ // Declared under its own key, so the handler reads `code`, `message` and
571
+ // `fatal` off the event with no narrowing.
572
+ await fireEvent(
573
+ agentDef,
574
+ sessionEvent("error.reported", { code: "tts", message: "voice down", fatal: false }),
575
+ ctx,
576
+ );
577
+ await fireEvent(
578
+ agentDef,
579
+ sessionEvent("error.reported", { code: "llm", message: "gateway 503", fatal: true }),
580
+ ctx,
581
+ );
582
+
583
+ expect(tripSlot.get(ctx).log).toEqual([
584
+ "Trouble on the call (tts): voice down",
585
+ "Call failed (llm): gateway 503",
586
+ ]);
587
+ });
600
588
  });
601
589
  });