@alexkroman1/aai-cli 15.1.0 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +8 -5
  2. package/bin.mjs +12 -3
  3. package/dist/_build-target-55dJisQ-.mjs +649 -0
  4. package/dist/_build-target.d.ts +105 -108
  5. package/dist/_deno-output.d.ts +23 -0
  6. package/dist/_deno-target.d.ts +73 -0
  7. package/dist/{_init-Bsi3DZNJ.mjs → _init-BzQbV8Zh.mjs} +3 -1
  8. package/dist/_modal-app.d.ts +77 -0
  9. package/dist/_modal-output.d.ts +31 -0
  10. package/dist/_modal-target.d.ts +64 -0
  11. package/dist/_target-bundle.d.ts +27 -0
  12. package/dist/_target-drain.d.ts +44 -0
  13. package/dist/_target-output.d.ts +63 -0
  14. package/dist/{_templates-CIlJ3Vay.mjs → _templates-CuP74F8D.mjs} +94 -4
  15. package/dist/_templates.d.ts +14 -1
  16. package/dist/_vercel-output.d.ts +4 -19
  17. package/dist/_vercel-target.d.ts +169 -0
  18. package/dist/{test-D032V2cA.mjs → _vitest-runner-AVR9VtXh.mjs} +28 -68
  19. package/dist/_vitest-runner.d.ts +154 -0
  20. package/dist/build-ButI2IKc.mjs +689 -0
  21. package/dist/build.d.ts +11 -0
  22. package/dist/cli.mjs +12 -11
  23. package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
  24. package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
  25. package/dist/{init-CQbj3ycf.mjs → init-D363Ls5u.mjs} +2 -2
  26. package/dist/scaffold/CLAUDE.md +185 -35
  27. package/dist/scaffold/package.json +4 -4
  28. package/dist/start.mjs +3 -1
  29. package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
  30. package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
  31. package/dist/templates/briefing-desk/agent.test.ts +347 -55
  32. package/dist/templates/briefing-desk/agent.ts +12 -0
  33. package/dist/templates/briefing-desk/shared.ts +220 -31
  34. package/dist/templates/briefing-desk/slack.ts +108 -0
  35. package/dist/templates/briefing-desk/system-prompt.md +12 -2
  36. package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
  37. package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
  38. package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
  39. package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
  40. package/dist/templates/call-audit/agent.eval.test.ts +5 -0
  41. package/dist/templates/call-audit/agent.test.ts +6 -1
  42. package/dist/templates/call-audit/agent.ts +10 -23
  43. package/dist/templates/call-audit/client.tsx +30 -55
  44. package/dist/templates/call-audit/guards.test.ts +233 -0
  45. package/dist/templates/call-audit/workflows/audit.ts +95 -16
  46. package/dist/templates/call-audit/workflows/ingest.ts +107 -88
  47. package/dist/templates/call-audit/workflows/media.ts +98 -7
  48. package/dist/templates/call-audit/workflows/summarize.ts +35 -31
  49. package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
  50. package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
  51. package/dist/templates/code-interpreter/agent.test.ts +44 -56
  52. package/dist/templates/code-interpreter/system-prompt.md +1 -1
  53. package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
  54. package/dist/templates/dispatch-center/agent.test.ts +253 -48
  55. package/dist/templates/dispatch-center/agent.ts +28 -1
  56. package/dist/templates/dispatch-center/client.tsx +126 -201
  57. package/dist/templates/dispatch-center/events.ts +48 -0
  58. package/dist/templates/dispatch-center/shared.ts +42 -1
  59. package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
  60. package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
  61. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
  62. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
  63. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
  64. package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
  65. package/dist/templates/executive-assistant/agent.test.ts +672 -0
  66. package/dist/templates/executive-assistant/agent.ts +50 -0
  67. package/dist/templates/executive-assistant/calendar.test.ts +198 -0
  68. package/dist/templates/executive-assistant/client.tsx +195 -0
  69. package/dist/templates/executive-assistant/inbox.ts +233 -0
  70. package/dist/templates/executive-assistant/meeting.ts +138 -0
  71. package/dist/templates/executive-assistant/nodes.ts +152 -0
  72. package/dist/templates/executive-assistant/prompts.ts +331 -0
  73. package/dist/templates/executive-assistant/review.ts +425 -0
  74. package/dist/templates/executive-assistant/shared.ts +490 -0
  75. package/dist/templates/executive-assistant/system-prompt.md +15 -0
  76. package/dist/templates/executive-assistant/tools/accept.ts +10 -0
  77. package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
  78. package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
  79. package/dist/templates/executive-assistant/tools/edit.ts +10 -0
  80. package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
  81. package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
  82. package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
  83. package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
  84. package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
  85. package/dist/templates/executive-assistant/tools/respond.ts +10 -0
  86. package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
  87. package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
  88. package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
  89. package/dist/templates/health-assistant/agent.test.ts +134 -15
  90. package/dist/templates/health-assistant/agent.ts +8 -1
  91. package/dist/templates/health-assistant/fda.test.ts +130 -0
  92. package/dist/templates/health-assistant/fda.ts +75 -16
  93. package/dist/templates/health-assistant/system-prompt.md +9 -0
  94. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
  95. package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
  96. package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
  97. package/dist/templates/hiring-desk/agent.test.ts +1021 -0
  98. package/dist/templates/hiring-desk/agent.ts +38 -0
  99. package/dist/templates/hiring-desk/client.tsx +154 -0
  100. package/dist/templates/hiring-desk/crews.ts +432 -0
  101. package/dist/templates/hiring-desk/leads.json +86 -0
  102. package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
  103. package/dist/templates/hiring-desk/screening-lock.ts +51 -0
  104. package/dist/templates/hiring-desk/shared.ts +480 -0
  105. package/dist/templates/hiring-desk/system-prompt.md +21 -0
  106. package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
  107. package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
  108. package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
  109. package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
  110. package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
  111. package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
  112. package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
  113. package/dist/templates/hotel-desk/agent.test.ts +1128 -0
  114. package/dist/templates/hotel-desk/agent.ts +63 -0
  115. package/dist/templates/hotel-desk/booking.ts +159 -0
  116. package/dist/templates/hotel-desk/card.ts +92 -0
  117. package/dist/templates/hotel-desk/catalogs.ts +219 -0
  118. package/dist/templates/hotel-desk/client.tsx +137 -0
  119. package/dist/templates/hotel-desk/concierge.ts +99 -0
  120. package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
  121. package/dist/templates/hotel-desk/desk.ts +224 -0
  122. package/dist/templates/hotel-desk/disputes.ts +216 -0
  123. package/dist/templates/hotel-desk/events.ts +79 -0
  124. package/dist/templates/hotel-desk/hotel.ts +412 -0
  125. package/dist/templates/hotel-desk/policies.ts +209 -0
  126. package/dist/templates/hotel-desk/records.ts +384 -0
  127. package/dist/templates/hotel-desk/restaurant.ts +147 -0
  128. package/dist/templates/hotel-desk/seed.ts +955 -0
  129. package/dist/templates/hotel-desk/shared.ts +354 -0
  130. package/dist/templates/hotel-desk/system-prompt.md +76 -0
  131. package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
  132. package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
  133. package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
  134. package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
  135. package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
  136. package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
  137. package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
  138. package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
  139. package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
  140. package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
  141. package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
  142. package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
  143. package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
  144. package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
  145. package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
  146. package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
  147. package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
  148. package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
  149. package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
  150. package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
  151. package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
  152. package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
  153. package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
  154. package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
  155. package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
  156. package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
  157. package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
  158. package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
  159. package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
  160. package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
  161. package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
  162. package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
  163. package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
  164. package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
  165. package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
  166. package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
  167. package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
  168. package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
  169. package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
  170. package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
  171. package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
  172. package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
  173. package/dist/templates/infocom-adventure/agent.test.ts +207 -52
  174. package/dist/templates/infocom-adventure/agent.ts +14 -3
  175. package/dist/templates/infocom-adventure/client.tsx +138 -176
  176. package/dist/templates/infocom-adventure/shared.ts +126 -6
  177. package/dist/templates/infocom-adventure/system-prompt.md +4 -4
  178. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
  179. package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
  180. package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
  181. package/dist/templates/link-digest/agent.eval.test.ts +8 -0
  182. package/dist/templates/link-digest/agent.test.ts +285 -29
  183. package/dist/templates/link-digest/agent.ts +9 -0
  184. package/dist/templates/link-digest/api-client.ts +144 -0
  185. package/dist/templates/link-digest/client.tsx +11 -30
  186. package/dist/templates/link-digest/workflows/digest.ts +72 -24
  187. package/dist/templates/night-owl/agent.eval.test.ts +55 -40
  188. package/dist/templates/night-owl/agent.test.ts +146 -12
  189. package/dist/templates/night-owl/client.tsx +50 -17
  190. package/dist/templates/night-owl/shared.ts +33 -2
  191. package/dist/templates/night-owl/system-prompt.md +3 -0
  192. package/dist/templates/night-owl/tools/recommend.ts +4 -1
  193. package/dist/templates/night-owl/tools/revisit.ts +49 -0
  194. package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
  195. package/dist/templates/pipeline-simple/agent.test.ts +48 -91
  196. package/dist/templates/pipeline-simple/modes.test.ts +151 -0
  197. package/dist/templates/pipeline-simple/stages.test.ts +332 -0
  198. package/dist/templates/pizza-ordering/agent.test.ts +94 -38
  199. package/dist/templates/pizza-ordering/client.tsx +10 -5
  200. package/dist/templates/pizza-ordering/shared.ts +65 -6
  201. package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
  202. package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
  203. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
  204. package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
  205. package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
  206. package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
  207. package/dist/templates/plan-and-execute/agent.test.ts +300 -113
  208. package/dist/templates/plan-and-execute/client.tsx +18 -7
  209. package/dist/templates/plan-and-execute/procedure.ts +162 -64
  210. package/dist/templates/plan-and-execute/prompts.ts +51 -15
  211. package/dist/templates/plan-and-execute/shared.ts +151 -45
  212. package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
  213. package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
  214. package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
  215. package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
  216. package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
  217. package/dist/templates/podcast-digest/agent.test.ts +126 -51
  218. package/dist/templates/podcast-digest/client.tsx +104 -68
  219. package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
  220. package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
  221. package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
  222. package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
  223. package/dist/templates/recap-workflow/agent.test.ts +207 -26
  224. package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
  225. package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
  226. package/dist/templates/redline/agent.eval.test.ts +40 -3
  227. package/dist/templates/redline/agent.test.ts +216 -6
  228. package/dist/templates/redline/agent.ts +54 -34
  229. package/dist/templates/redline/client.tsx +82 -126
  230. package/dist/templates/redline/form.ts +74 -0
  231. package/dist/templates/redline/workflows/prompts.ts +3 -3
  232. package/dist/templates/redline/workflows/redline.ts +73 -4
  233. package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
  234. package/dist/templates/research-workflow/agent.test.ts +436 -126
  235. package/dist/templates/research-workflow/agent.ts +20 -5
  236. package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
  237. package/dist/templates/research-workflow/tools/research_status.ts +39 -4
  238. package/dist/templates/research-workflow/workflows/filing.ts +164 -0
  239. package/dist/templates/research-workflow/workflows/notes.ts +69 -0
  240. package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
  241. package/dist/templates/research-workflow/workflows/research.ts +227 -280
  242. package/dist/templates/research-workflow/workflows/review.ts +43 -0
  243. package/dist/templates/retail/address.ts +29 -35
  244. package/dist/templates/retail/agent.eval.test.ts +36 -16
  245. package/dist/templates/retail/agent.test.ts +104 -26
  246. package/dist/templates/retail/agent.ts +12 -0
  247. package/dist/templates/retail/cancel.ts +39 -42
  248. package/dist/templates/retail/client.tsx +111 -176
  249. package/dist/templates/retail/payment.ts +38 -43
  250. package/dist/templates/retail/pending.test.ts +16 -8
  251. package/dist/templates/retail/registry.test.ts +108 -49
  252. package/dist/templates/retail/resolve.test.ts +2 -63
  253. package/dist/templates/retail/resolve.ts +16 -56
  254. package/dist/templates/retail/returns.ts +53 -54
  255. package/dist/templates/retail/seed.test.ts +2 -1
  256. package/dist/templates/retail/shared.ts +58 -14
  257. package/dist/templates/retail/store.test.ts +40 -29
  258. package/dist/templates/retail/store.ts +60 -23
  259. package/dist/templates/retail/swap.ts +78 -81
  260. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
  261. package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
  262. package/dist/templates/roadside-assist/agent.test.ts +617 -0
  263. package/dist/templates/roadside-assist/agent.ts +85 -0
  264. package/dist/templates/roadside-assist/call.ts +237 -0
  265. package/dist/templates/roadside-assist/events.ts +92 -0
  266. package/dist/templates/roadside-assist/shared.ts +334 -0
  267. package/dist/templates/roadside-assist/system-prompt.md +37 -0
  268. package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
  269. package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
  270. package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
  271. package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
  272. package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
  273. package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
  274. package/dist/templates/roadside-assist/yard.test.ts +158 -0
  275. package/dist/templates/roadside-assist/yard.ts +183 -0
  276. package/dist/templates/simple/agent.eval.test.ts +4 -1
  277. package/dist/templates/simple/agent.test.ts +54 -31
  278. package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
  279. package/dist/templates/solo-rpg/agent.test.ts +402 -175
  280. package/dist/templates/solo-rpg/agent.ts +14 -3
  281. package/dist/templates/solo-rpg/client.tsx +10 -10
  282. package/dist/templates/solo-rpg/shared.ts +198 -79
  283. package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
  284. package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
  285. package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
  286. package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
  287. package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
  288. package/dist/templates/spoken-summary/agent.test.ts +70 -15
  289. package/dist/templates/spoken-summary/agent.ts +25 -21
  290. package/dist/templates/spoken-summary/client.tsx +68 -88
  291. package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
  292. package/dist/templates/support-line/agent.test.ts +167 -36
  293. package/dist/templates/support-line/client.tsx +21 -9
  294. package/dist/templates/support-line/nodes.ts +74 -32
  295. package/dist/templates/support-line/procedure.ts +66 -21
  296. package/dist/templates/support-line/prompts.ts +9 -0
  297. package/dist/templates/support-line/shared.ts +55 -17
  298. package/dist/templates/support-line/tools/answer_question.ts +14 -14
  299. package/dist/templates/transcription-workflow/agent.test.ts +135 -13
  300. package/dist/templates/transcription-workflow/client.tsx +30 -23
  301. package/dist/templates/transcription-workflow/recover.test.ts +93 -12
  302. package/dist/templates/transcription-workflow/recover.ts +29 -5
  303. package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
  304. package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
  305. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
  306. package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
  307. package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
  308. package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
  309. package/dist/templates/travel-concierge/agent.test.ts +209 -40
  310. package/dist/templates/travel-concierge/agent.ts +24 -4
  311. package/dist/templates/travel-concierge/call-events.ts +80 -0
  312. package/dist/templates/travel-concierge/client.tsx +3 -2
  313. package/dist/templates/travel-concierge/routing.ts +5 -7
  314. package/dist/templates/travel-concierge/shared.ts +202 -41
  315. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
  316. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
  317. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
  318. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
  319. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
  320. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
  321. package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
  322. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
  323. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
  324. package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
  325. package/dist/templates/web-researcher/agent.test.ts +102 -65
  326. package/dist/templates/web-researcher/agent.ts +93 -1
  327. package/dist/templates/web-researcher/system-prompt.md +7 -1
  328. package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
  329. package/dist/templates/word-wrangler/agent.test.ts +432 -0
  330. package/dist/templates/word-wrangler/agent.ts +35 -0
  331. package/dist/templates/word-wrangler/client.tsx +211 -0
  332. package/dist/templates/word-wrangler/game.ts +107 -0
  333. package/dist/templates/word-wrangler/guess.ts +63 -0
  334. package/dist/templates/word-wrangler/player.ts +68 -0
  335. package/dist/templates/word-wrangler/shared.ts +263 -0
  336. package/dist/templates/word-wrangler/system-prompt.md +15 -0
  337. package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
  338. package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
  339. package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
  340. package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
  341. package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
  342. package/dist/templates/word-wrangler/words.ts +278 -0
  343. package/dist/test-Cllnx81G.mjs +83 -0
  344. package/dist/test.d.ts +9 -114
  345. package/package.json +5 -5
  346. package/dist/build-BhEaxBPu.mjs +0 -481
  347. package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
  348. package/dist/templates/embedded-assets/agent.test.ts +0 -79
  349. package/dist/templates/embedded-assets/agent.ts +0 -7
  350. package/dist/templates/embedded-assets/knowledge.json +0 -20
  351. package/dist/templates/embedded-assets/shared.ts +0 -17
  352. package/dist/templates/embedded-assets/system-prompt.md +0 -13
  353. package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
  354. package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
  355. package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
  356. package/dist/templates/math-buddy/agent.test.ts +0 -126
  357. package/dist/templates/math-buddy/agent.ts +0 -15
  358. package/dist/templates/math-buddy/system-prompt.md +0 -12
  359. package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
  360. package/dist/templates/personal-finance/agent.test.ts +0 -127
  361. package/dist/templates/personal-finance/agent.ts +0 -8
  362. package/dist/templates/personal-finance/system-prompt.md +0 -21
@@ -14,18 +14,26 @@
14
14
  * | `ToFlightBookingAssistant` & friends (delegation tools) | the four tools {@link SPECIALISTS} generates in `routing.ts` |
15
15
  * | `CompleteOrEscalate` | `complete_or_escalate`, which pops the same stack |
16
16
  * | `interrupt_before=["…_sensitive_tools"]` | {@link stageAction} + `confirm_action` |
17
- * | a specialist node's BOUND tool set | {@link requireDesk}, checked by every desk tool |
17
+ * | a specialist node's BOUND tool set | {@link deskTool} / {@link deskUpdateTool}, which every desk tool is declared through |
18
18
  * | `fetch_user_flight_information` (sqlite) | `lookup_booking` over {@link seedTrip} |
19
19
  *
20
20
  * **The dialog stack is what keeps a long call on the rails.** Their insight is
21
21
  * that one prompt holding every tool degrades as the tool list grows, so the
22
22
  * primary assistant delegates to a specialist and the specialist works with a
23
- * narrow brief. A voice agent cannot swap its system prompt mid-session — the
24
- * session's prompt is fixed at connect — so the specialist's brief arrives as
25
- * the DELEGATION TOOL'S RESULT, which is the last thing the model reads before
26
- * it answers. The stack itself is real state either way, which is what
23
+ * narrow brief. The specialist's brief arrives as the DELEGATION TOOL'S RESULT,
24
+ * which is the last thing the model reads before it answers.
25
+ *
26
+ * That used to be stated here as a hard limit — "a voice agent cannot swap its
27
+ * system prompt mid-session" — and it is no longer true in general: a state's
28
+ * `instruction` reaches the model on EVERY turn now, on the pipeline and on
29
+ * OpenAI Realtime (AssemblyAI S2S still resolves once). It stays true for THIS
30
+ * template, for a different reason: the desks are a STACK in a session slot,
31
+ * not a dialog position, and a dialog holds one position per session where a
32
+ * stack holds several. Reaching for the new mechanism here would mean modelling
33
+ * the desks as states, which is the port's own design question rather than a
34
+ * fix. The stack itself is real state either way, which is what
27
35
  * `complete_or_escalate` pops and what the sidebar renders — and what
28
- * {@link requireDesk} makes binding, so the position is never merely a label on
36
+ * {@link deskTool} makes binding, so the position is never merely a label on
29
37
  * work that happened somewhere else.
30
38
  *
31
39
  * **`interrupt_before` becomes a spoken confirmation, and that is not a
@@ -42,12 +50,16 @@ import {
42
50
  type DeepReadonly,
43
51
  type DialogSpec,
44
52
  dialog,
45
- pushCapped,
53
+ isClockTime,
54
+ type SlotToolDef,
55
+ type StateProjection,
46
56
  sessionSlot,
47
57
  type ToolContext,
58
+ type ToolDef,
48
59
  type ToolFailure,
60
+ type ToolInputSchema,
49
61
  } from "@alexkroman1/aai";
50
- import { formatMoney, plural } from "@alexkroman1/aai/utils";
62
+ import { formatMoney, plural, roundMoney } from "@alexkroman1/aai/utils";
51
63
 
52
64
  // ─── The booking world ───────────────────────────────────────────────────────
53
65
  // Their notebook downloads a sqlite database of a real airline's schedule and
@@ -150,11 +162,15 @@ export const HOTELS: Hotel[] = [
150
162
  stars: 5,
151
163
  },
152
164
  {
165
+ // The one rate with cents in it, and it is deliberate: three nights here is
166
+ // `179.95 * 3 === 539.8499999999999`, so this row is what makes
167
+ // {@link roundMoney} load-bearing rather than decorative — see the totals in
168
+ // `applyPending` and {@link tripView}.
153
169
  id: "H3",
154
170
  name: "Cambridge Rooms",
155
171
  city: "Boston",
156
172
  area: "Cambridge",
157
- pricePerNight: 180,
173
+ pricePerNight: 179.95,
158
174
  stars: 3,
159
175
  },
160
176
  {
@@ -349,14 +365,11 @@ export interface TripState {
349
365
  * here. A concurrent step emitting two sensitive tools is ordinary. */
350
366
  pending: PendingAction | null;
351
367
  bookings: BookingRecord[];
352
- /** What has happened on this call, for the sidebar. Capped on append. */
368
+ /** What has happened on this call, for the sidebar. Capped by the slot. */
353
369
  log: string[];
354
370
  bookingCounter: number;
355
371
  }
356
372
 
357
- /** Growth cap on the call log — it rides in every `syncState` frame. */
358
- export const MAX_LOG_ENTRIES = 40;
359
-
360
373
  /** The caller as the airline already knows them — their
361
374
  * `fetch_user_flight_information`, minus the sqlite. */
362
375
  export function seedTrip(): TripState {
@@ -371,6 +384,9 @@ export function seedTrip(): TripState {
371
384
  };
372
385
  }
373
386
 
387
+ /** How many call-log lines survive in the projection the browser is pushed. */
388
+ export const LOG_CAP = 40;
389
+
374
390
  /**
375
391
  * The call's state, as one typed slot.
376
392
  *
@@ -382,6 +398,11 @@ export const tripSlot = sessionSlot("trip", seedTrip, {
382
398
  after: (state) => {
383
399
  if (state.dialogState.length === 0) state.dialogState.push("primary");
384
400
  },
401
+ // The call log rides in every `syncState` frame, and its writers are no longer
402
+ // only tools — `call-events.ts` appends on a hang-up and on a reported error.
403
+ // The bound is declared here rather than at each push, and `LOG_CAP` is
404
+ // exported because a spec reads it.
405
+ caps: { log: LOG_CAP },
385
406
  });
386
407
 
387
408
  /**
@@ -399,10 +420,6 @@ export function activeAssistant(state: FrozenTripState): DialogState {
399
420
  return state.dialogState.at(-1) ?? "primary";
400
421
  }
401
422
 
402
- export function note(state: TripState, entry: string): void {
403
- pushCapped(state.log, entry, MAX_LOG_ENTRIES);
404
- }
405
-
406
423
  // ─── The desk gate ───────────────────────────────────────────────────────────
407
424
 
408
425
  /**
@@ -430,8 +447,11 @@ export function note(state: TripState, entry: string): void {
430
447
  * It costs one wasted round trip the first time the model reaches past the
431
448
  * stack, which is the right price: the alternative is a desk whose position is
432
449
  * decoration.
450
+ *
451
+ * Not exported: {@link deskTool} and {@link deskUpdateTool} are the only callers,
452
+ * which is what makes a desk tool unable to skip it.
433
453
  */
434
- export function requireDesk(state: FrozenTripState, id: SpecialistId): ToolFailure | undefined {
454
+ function requireDesk(state: FrozenTripState, id: SpecialistId): ToolFailure | undefined {
435
455
  const at = activeAssistant(state);
436
456
  if (at === id) return undefined;
437
457
  const here = at === "primary" ? "the main concierge" : SPECIALISTS[at].title;
@@ -444,6 +464,83 @@ export function requireDesk(state: FrozenTripState, id: SpecialistId): ToolFailu
444
464
  };
445
465
  }
446
466
 
467
+ /**
468
+ * What a desk tool declares: the slot's own {@link SlotToolDef}, with the schema
469
+ * REQUIRED — `cancel_ticket` takes no arguments and passes `z.object({})`.
470
+ *
471
+ * One code path in the wrapper is worth more than a line saved at one call
472
+ * site: `exactOptionalPropertyTypes` is on, so an `inputSchema` forwarded
473
+ * through a spread arrives as `P | undefined`, which is not what "this tool
474
+ * takes no arguments" means to the slot.
475
+ */
476
+ type DeskToolDef<P extends ToolInputSchema, V, R> = Omit<SlotToolDef<P, V, R>, "inputSchema"> & {
477
+ inputSchema: P;
478
+ };
479
+
480
+ /**
481
+ * A desk's own tool: {@link requireDesk} first, then the body — declared once.
482
+ *
483
+ * Nine tools used to open with the same two lines, and a wrapper is what makes
484
+ * the narrowing STRUCTURAL rather than remembered: their graph binds a tool set
485
+ * per node, and the tenth desk tool written here cannot forget the gate the way
486
+ * a copied prologue can. It is the per-agent wrapper `retail` demonstrates, at
487
+ * its smallest — all this one adds is the gate, so what it takes is the SLOT's
488
+ * OWN {@link SlotToolDef} rather than a spec of its own, and a tool file reads
489
+ * exactly as it did minus the prologue.
490
+ *
491
+ * Two of them because the slot has two halves and choosing wrong is a compile
492
+ * error: a search READS the frozen state, a staging tool takes the mutable
493
+ * draft. `requireDesk` short-circuits before either body runs, so a refused call
494
+ * really searches, stages and books nothing.
495
+ */
496
+ export function deskTool<P extends ToolInputSchema, R>(
497
+ id: SpecialistId,
498
+ def: DeskToolDef<P, FrozenTripState, R>,
499
+ ): ToolDef<P, R | ToolFailure> {
500
+ return tripSlot.tool<P, R | ToolFailure>({
501
+ description: def.description,
502
+ inputSchema: def.inputSchema,
503
+ execute: (args, trip, ctx) => requireDesk(trip, id) ?? def.execute(args, trip, ctx),
504
+ });
505
+ }
506
+
507
+ /**
508
+ * {@link deskTool} for a tool that WRITES — the draft half of the slot.
509
+ *
510
+ * Its result type is FIXED at {@link StagedReadBack} rather than generic, and
511
+ * that is the template's central rule stated as a type: a desk tool that touches
512
+ * the draft may only STAGE. There is nothing else for one to answer — a body
513
+ * that applied a change itself would have to invent a receipt, and the compiler
514
+ * asks for the read-back instead.
515
+ */
516
+ export function deskUpdateTool<P extends ToolInputSchema>(
517
+ id: SpecialistId,
518
+ def: DeskToolDef<P, TripState, StagedReadBack | ToolFailure>,
519
+ ): ToolDef<P, StagedReadBack | ToolFailure> {
520
+ return tripSlot.updateTool<P, StagedReadBack | ToolFailure>({
521
+ description: def.description,
522
+ inputSchema: def.inputSchema,
523
+ execute: (args, trip, ctx) => requireDesk(trip, id) ?? def.execute(args, trip, ctx),
524
+ });
525
+ }
526
+
527
+ /**
528
+ * A flight's departure as a comparable `HH:MM`, or `undefined` for a row that
529
+ * does not carry one.
530
+ *
531
+ * The schedule writes a departure as `"Tue 13:05"` — a weekday a caller says
532
+ * and a clock reading a caller filters by — and `search_flights` compares the
533
+ * clock half as a STRING, which is legal for exactly the reason
534
+ * {@link isClockTime} exists: a zero-padded 24-hour reading sorts the way the
535
+ * clock runs, and `"9:05"` does not. So the predicate is what stands between a
536
+ * row and a comparison, rather than a regex written here: a row it refuses is
537
+ * left out of a time-filtered search instead of being ordered against `"Tue"`.
538
+ */
539
+ export function departureClock(flight: DeepReadonly<Flight>): string | undefined {
540
+ const clock = flight.departs.slice(-5);
541
+ return isClockTime(clock) ? clock : undefined;
542
+ }
543
+
447
544
  // ─── The confirmation gate ───────────────────────────────────────────────────
448
545
 
449
546
  /**
@@ -469,12 +566,34 @@ const gateSpec = {
469
566
  browsing: {
470
567
  instruction:
471
568
  "Nothing is waiting for the caller's yes. Stage a change with a booking tool first.",
472
- on: { STAGED: "awaitingConfirmation" },
569
+ on: { STAGED: "awaitingConfirmation", "@session.timed-out": "abandoned" },
473
570
  },
474
571
  awaitingConfirmation: {
475
572
  instruction:
476
573
  "Read the staged change back and hear a clear yes or no, then use confirm_action or cancel_action.",
477
- on: { SETTLED: "browsing" },
574
+ on: { SETTLED: "browsing", "@session.timed-out": "abandoned" },
575
+ },
576
+ /**
577
+ * The caller hung up, or the session timed out under them.
578
+ *
579
+ * Declared on both live states rather than on a parent, because wrapping
580
+ * them would rename `browsing` and `awaitingConfirmation` to
581
+ * `onCall.browsing` and `onCall.awaitingConfirmation` — the two names every
582
+ * `when` in `tools/` is written against, and the sidebar renders.
583
+ *
584
+ * What it does NOT do is settle the staged action: a deadline or a session
585
+ * event SENDS AN EVENT, it does not run a tool, so `pending` is still
586
+ * whatever `stageAction` left there. That is fine here and is the reason
587
+ * this state is `final` — nothing may act on this call again, so nothing
588
+ * reads `pending` again either. It would NOT be fine as a timeout that
589
+ * returned to `browsing`, which is the trap recorded in
590
+ * `aai-runtime`'s `DIALOG-CLAUDE.md`.
591
+ */
592
+ abandoned: {
593
+ final: true,
594
+ instruction:
595
+ "The caller is gone. Do nothing further — do not confirm the staged change, do not " +
596
+ "book anything, and do not promise a callback.",
478
597
  },
479
598
  },
480
599
  } as const satisfies DialogSpec;
@@ -527,6 +646,36 @@ export function describeAction(action: DeepReadonly<PendingAction>): string | To
527
646
  }
528
647
  }
529
648
 
649
+ /**
650
+ * The sentence for an action that has ALREADY been staged.
651
+ *
652
+ * `describeAction` answers `string | ToolFailure` because {@link stageAction} is
653
+ * the one caller that can be handed an id naming nothing, and its refusal names
654
+ * that id. Everything else describes something `stageAction` already accepted,
655
+ * so the failure arm is unreachable — and every such site had written
656
+ * `typeof described === "string" ? described : ...` to guard it, one of which
657
+ * read as if a `ToolFailure` might be spoken to the caller. The fallback is the
658
+ * action's own kind, so a catalog that somehow lost an entry mid-call degrades
659
+ * to a rough noun rather than to a stray `[object Object]`.
660
+ */
661
+ export function describeStaged(action: DeepReadonly<PendingAction>): string {
662
+ const described = describeAction(action);
663
+ return typeof described === "string" ? described : action.kind;
664
+ }
665
+
666
+ /**
667
+ * What a sensitive tool answers with: the sentence to read aloud, and the fact
668
+ * that nothing has happened yet.
669
+ *
670
+ * Named because {@link deskUpdateTool} pins every writing desk tool to it — see
671
+ * there for why that is the gate rather than a convenience.
672
+ */
673
+ export type StagedReadBack = {
674
+ awaitingConfirmation: true;
675
+ readBack: string;
676
+ expires: "on the caller's next answer";
677
+ };
678
+
530
679
  /**
531
680
  * Stage a sensitive action and return what a sensitive tool answers with.
532
681
  *
@@ -549,16 +698,13 @@ export function stageAction(
549
698
  ctx: ToolContext,
550
699
  state: TripState,
551
700
  action: PendingAction,
552
- ):
553
- | { awaitingConfirmation: true; readBack: string; expires: "on the caller's next answer" }
554
- | ToolFailure {
701
+ ): StagedReadBack | ToolFailure {
555
702
  const described = describeAction(action);
556
703
  if (typeof described !== "string") return described;
557
- const waiting = state.pending ? describeAction(state.pending) : null;
558
- if (waiting !== null) {
704
+ if (state.pending) {
559
705
  return {
560
706
  error:
561
- `Something is already waiting for the caller's yes: ${typeof waiting === "string" ? waiting : state.pending?.kind}. ` +
707
+ `Something is already waiting for the caller's yes: ${describeStaged(state.pending)}. ` +
562
708
  "Settle it with confirm_action or cancel_action, then ask for this one. " +
563
709
  "Only one change can be waiting at a time — nothing about this request has been staged.",
564
710
  };
@@ -569,7 +715,7 @@ export function stageAction(
569
715
  // a different slot from `tripSlot`, so this is not a nested write to the draft
570
716
  // being held — the open-draft guard is per slot.
571
717
  gateFlow.send(ctx, { type: "STAGED" });
572
- note(state, `Awaiting confirmation: ${described}`);
718
+ state.log.push(`Awaiting confirmation: ${described}`);
573
719
  return {
574
720
  awaitingConfirmation: true,
575
721
  readBack: `Ask the caller to confirm, out loud, that they want to ${described}. Nothing has changed yet.`,
@@ -593,8 +739,6 @@ export function applyPending(
593
739
  if (!action) {
594
740
  return { error: "Nothing is staged after all — ask the caller again what they want." };
595
741
  }
596
- const described = describeAction(action);
597
- if (typeof described !== "string") return described;
598
742
  state.pending = null;
599
743
  state.bookingCounter++;
600
744
  const reference = `BK${String(1000 + state.bookingCounter)}`;
@@ -606,40 +750,43 @@ export function applyPending(
606
750
  if (flight.seatsLeft <= 0) return { error: `${flight.id} has no seats left.` };
607
751
  if (!state.ticket) return { error: "There is no ticket to move — it was cancelled." };
608
752
  state.ticket = { reference: state.ticket.reference, flightId: flight.id };
609
- note(state, `Ticket ${state.ticket.reference} moved to ${flight.id}`);
753
+ state.log.push(`Ticket ${state.ticket.reference} moved to ${flight.id}`);
610
754
  return { applied: `Ticket moved to ${flight.id}, ${flight.departs}.` };
611
755
  }
612
756
  case "cancel_ticket": {
613
757
  if (!state.ticket) return { error: "There is no ticket to cancel." };
614
758
  const cancelled = state.ticket.reference;
615
759
  state.ticket = null;
616
- note(state, `Ticket ${cancelled} cancelled`);
760
+ state.log.push(`Ticket ${cancelled} cancelled`);
617
761
  return { applied: `Ticket ${cancelled} cancelled.` };
618
762
  }
619
763
  case "book_hotel": {
620
764
  const hotel = HOTELS.find((h) => h.id === action.hotelId);
621
765
  if (!hotel) return { error: `No hotel ${action.hotelId}.` };
622
- const price = hotel.pricePerNight * action.nights;
766
+ // `roundMoney` because this is STORED and then summed into the itinerary
767
+ // total: `179.95 * 3` is `539.8499999999999`, which prints as $539.85 and
768
+ // compares equal to nothing anyone would write down.
769
+ const price = roundMoney(hotel.pricePerNight * action.nights);
623
770
  state.bookings.push({
624
771
  kind: "hotel",
625
772
  reference,
626
773
  summary: `${hotel.name} (${hotel.area}), ${action.nights} ${plural(action.nights, "night")}`,
627
774
  price,
628
775
  });
629
- note(state, `Hotel booked: ${hotel.name} — ${reference}`);
776
+ state.log.push(`Hotel booked: ${hotel.name} — ${reference}`);
630
777
  return { applied: `${hotel.name} booked, ${formatMoney(price)}.`, reference };
631
778
  }
632
779
  case "book_car": {
633
780
  const car = CAR_RENTALS.find((c) => c.id === action.carId);
634
781
  if (!car) return { error: `No car ${action.carId}.` };
635
- const price = car.pricePerDay * action.days;
782
+ const price = roundMoney(car.pricePerDay * action.days);
636
783
  state.bookings.push({
637
784
  kind: "car",
638
785
  reference,
639
786
  summary: `${car.vendor} ${car.tier}, ${action.days} ${plural(action.days, "day")}`,
640
787
  price,
641
788
  });
642
- note(state, `Car reserved: ${car.vendor} ${car.tier} — ${reference}`);
789
+ state.log.push(`Car reserved: ${car.vendor} ${car.tier} — ${reference}`);
643
790
  return {
644
791
  applied: `${car.tier} from ${car.vendor} reserved, ${formatMoney(price)}.`,
645
792
  reference,
@@ -654,7 +801,7 @@ export function applyPending(
654
801
  summary: `${excursion.name} (${excursion.city})`,
655
802
  price: excursion.price,
656
803
  });
657
- note(state, `Excursion booked: ${excursion.name} — ${reference}`);
804
+ state.log.push(`Excursion booked: ${excursion.name} — ${reference}`);
658
805
  return { applied: `${excursion.name} booked, ${formatMoney(excursion.price)}.`, reference };
659
806
  }
660
807
  // Same as `describeAction`: unreachable today, and a refusal rather than a
@@ -689,7 +836,7 @@ export interface TripView {
689
836
  export function tripView(state: FrozenTripState): TripView {
690
837
  const assistant = activeAssistant(state);
691
838
  const flight = state.ticket ? FLIGHTS.find((f) => f.id === state.ticket?.flightId) : undefined;
692
- const described = state.pending ? describeAction(state.pending) : null;
839
+ const described = state.pending ? describeStaged(state.pending) : null;
693
840
  return {
694
841
  passenger: state.passenger,
695
842
  assistant,
@@ -704,11 +851,25 @@ export function tripView(state: FrozenTripState): TripView {
704
851
  }
705
852
  : null,
706
853
  bookings: state.bookings,
707
- total: state.bookings.reduce((sum, b) => sum + b.price, 0),
708
- pending: typeof described === "string" ? described : null,
854
+ // The running total the sidebar prints and a spec compares. Each booking's
855
+ // price was already rounded where it was STORED — which is where today's
856
+ // catalog actually produces dust — and the sum goes through the same rule
857
+ // rather than through a rate table that happens not to need it.
858
+ total: roundMoney(state.bookings.reduce((sum, b) => sum + b.price, 0)),
859
+ pending: described,
709
860
  log: state.log,
710
861
  };
711
862
  }
712
863
 
713
- /** The projection BOTH ends use: `syncState` on the agent, `useAgentState` in the client. */
714
- export const tripProjection = tripSlot.projection(tripView);
864
+ /**
865
+ * The projection BOTH ends use: `syncState` on the agent, `useAgentState` in the
866
+ * client.
867
+ *
868
+ * Annotated, because the annotation is the CONTRACT rather than a restatement:
869
+ * `agent({ syncState })` and `useAgentState()` are both declared against
870
+ * `StateProjection<V>`, so writing it here is what says the frame the server
871
+ * pushes and the frame the browser renders are the same {@link TripView} — and
872
+ * what fails at this line, rather than in `client.tsx`, if `tripView` stops
873
+ * producing one.
874
+ */
875
+ export const tripProjection: StateProjection<TripView> = tripSlot.projection(tripView);
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
- import { requireDesk, stageAction, tripSlot } from "../shared.ts";
2
+ import { deskUpdateTool, stageAction } from "../shared.ts";
3
3
 
4
4
  /** SENSITIVE — their `book_car_rental`, staged rather than applied. */
5
- export default tripSlot.updateTool({
5
+ export default deskUpdateTool("car_rental", {
6
6
  description:
7
7
  "The CAR RENTAL DESK's booking tool: reserve a rental car. Only usable while the call " +
8
8
  "is at that desk. This does NOT reserve anything yet — it stages the reservation so " +
@@ -12,8 +12,6 @@ export default tripSlot.updateTool({
12
12
  days: z.number().int().min(1).max(60).describe("How many days"),
13
13
  }),
14
14
  execute(args, trip, ctx) {
15
- const offDesk = requireDesk(trip, "car_rental");
16
- if (offDesk) return offDesk;
17
15
  return stageAction(ctx, trip, {
18
16
  kind: "book_car",
19
17
  carId: args.carId.toUpperCase(),
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
- import { requireDesk, stageAction, tripSlot } from "../shared.ts";
2
+ import { deskUpdateTool, stageAction } from "../shared.ts";
3
3
 
4
4
  /** SENSITIVE — their `book_excursion`, staged rather than applied. */
5
- export default tripSlot.updateTool({
5
+ export default deskUpdateTool("excursion", {
6
6
  description:
7
7
  "The EXCURSIONS DESK's booking tool: book an excursion. Only usable while the call is " +
8
8
  "at that desk. This does NOT book anything yet — it stages the booking so you can read " +
@@ -11,8 +11,6 @@ export default tripSlot.updateTool({
11
11
  excursionId: z.string().max(20).describe("The excursion id from search_excursions, e.g. 'E2'"),
12
12
  }),
13
13
  execute(args, trip, ctx) {
14
- const offDesk = requireDesk(trip, "excursion");
15
- if (offDesk) return offDesk;
16
14
  return stageAction(ctx, trip, {
17
15
  kind: "book_excursion",
18
16
  excursionId: args.excursionId.toUpperCase(),
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
- import { requireDesk, stageAction, tripSlot } from "../shared.ts";
2
+ import { deskUpdateTool, stageAction } from "../shared.ts";
3
3
 
4
4
  /** SENSITIVE — their `book_hotel`, staged rather than applied. */
5
- export default tripSlot.updateTool({
5
+ export default deskUpdateTool("hotel", {
6
6
  description:
7
7
  "The HOTEL DESK's booking tool: hold a hotel room. Only usable while the call is at " +
8
8
  "that desk. This does NOT book anything yet — it stages the booking so you can read " +
@@ -12,8 +12,6 @@ export default tripSlot.updateTool({
12
12
  nights: z.number().int().min(1).max(30).describe("How many nights"),
13
13
  }),
14
14
  execute(args, trip, ctx) {
15
- const offDesk = requireDesk(trip, "hotel");
16
- if (offDesk) return offDesk;
17
15
  return stageAction(ctx, trip, {
18
16
  kind: "book_hotel",
19
17
  hotelId: args.hotelId.toUpperCase(),
@@ -1,18 +1,20 @@
1
- import { requireDesk, stageAction, tripSlot } from "../shared.ts";
1
+ import { z } from "zod";
2
+ import { deskUpdateTool, stageAction } from "../shared.ts";
2
3
 
3
4
  /**
4
5
  * SENSITIVE — their `cancel_ticket`. The most destructive thing on the call and
5
6
  * the clearest argument for the gate: staged, read back, and only applied by
6
7
  * `confirm_action`.
7
8
  */
8
- export default tripSlot.updateTool({
9
+ export default deskUpdateTool("flight", {
9
10
  description:
10
11
  "The FLIGHT DESK's cancellation tool: cancel the caller's ticket outright. Only usable " +
11
12
  "while the call is at that desk. This does NOT cancel anything yet — it stages the " +
12
13
  "cancellation so you can read it back and hear a yes.",
14
+ // The desk's one tool that takes nothing: declared anyway, so `deskUpdateTool`
15
+ // has a single code path rather than a branch for the no-argument case.
16
+ inputSchema: z.object({}),
13
17
  execute(_args, trip, ctx) {
14
- const offDesk = requireDesk(trip, "flight");
15
- if (offDesk) return offDesk;
16
18
  if (!trip.ticket) return { error: "There is no ticket to cancel." };
17
19
  return stageAction(ctx, trip, { kind: "cancel_ticket" });
18
20
  },
@@ -1,9 +1,9 @@
1
1
  import { formatMoney } from "@alexkroman1/aai/utils";
2
2
  import { z } from "zod";
3
- import { CAR_RENTALS, requireDesk, tripSlot } from "../shared.ts";
3
+ import { CAR_RENTALS, deskTool } from "../shared.ts";
4
4
 
5
5
  /** Their `search_car_rentals`, by city and tier. */
6
- export default tripSlot.tool({
6
+ export default deskTool("car_rental", {
7
7
  description:
8
8
  "The CAR RENTAL DESK's search: cars by city, and optionally by tier (compact, midsize, " +
9
9
  "suv). Only usable while the call is at that desk — from anywhere else it refuses, so " +
@@ -12,9 +12,7 @@ export default tripSlot.tool({
12
12
  city: z.string().max(80).describe("City to search, e.g. 'Boston'"),
13
13
  tier: z.string().max(40).describe("compact, midsize or suv").optional(),
14
14
  }),
15
- execute(args, trip) {
16
- const offDesk = requireDesk(trip, "car_rental");
17
- if (offDesk) return offDesk;
15
+ execute(args) {
18
16
  const city = args.city.trim().toLowerCase();
19
17
  const tier = args.tier?.trim().toLowerCase();
20
18
  const cars = CAR_RENTALS.filter(
@@ -1,10 +1,10 @@
1
1
  import { formatMoney } from "@alexkroman1/aai/utils";
2
2
  import { z } from "zod";
3
- import { EXCURSIONS, requireDesk, tripSlot } from "../shared.ts";
3
+ import { deskTool, EXCURSIONS } from "../shared.ts";
4
4
 
5
5
  /** Their `search_trip_recommendations` — city plus a loose keyword, matched
6
6
  * against the name and the kind so "boat" and "sail" both land. */
7
- export default tripSlot.tool({
7
+ export default deskTool("excursion", {
8
8
  description:
9
9
  "The EXCURSIONS DESK's search: things to do in a city, with an optional keyword matched " +
10
10
  "loosely. Only usable while the call is at that desk — from anywhere else it refuses, so " +
@@ -17,9 +17,7 @@ export default tripSlot.tool({
17
17
  .describe("What they enjoy, e.g. 'food', 'boat', 'history'")
18
18
  .optional(),
19
19
  }),
20
- execute(args, trip) {
21
- const offDesk = requireDesk(trip, "excursion");
22
- if (offDesk) return offDesk;
20
+ execute(args) {
23
21
  const city = args.city.trim().toLowerCase();
24
22
  const keyword = args.keyword?.trim().toLowerCase();
25
23
  const inCity = EXCURSIONS.filter((e) => e.city.toLowerCase().includes(city));
@@ -1,19 +1,25 @@
1
+ import { clockTime } from "@alexkroman1/aai";
1
2
  import { formatMoney } from "@alexkroman1/aai/utils";
2
3
  import { z } from "zod";
3
- import { FLIGHTS, requireDesk, tripSlot } from "../shared.ts";
4
+ import { departureClock, deskTool, FLIGHTS } from "../shared.ts";
4
5
 
5
6
  /**
6
7
  * Their `search_flights`, with the same "be generous" behaviour their flight
7
8
  * prompt asks the model for: an unmatched route returns the whole schedule
8
9
  * rather than an empty list, so the desk can say what it DOES fly instead of
9
10
  * "nothing found" — which is what sends a caller to a human.
11
+ *
12
+ * `departsAfter` is declared with `clockTime()` rather than a bare string, so
13
+ * "the afternoon one" is refused as `9am` and accepted as `14:00` BEFORE the
14
+ * body runs — the padding is what makes the comparison against
15
+ * {@link departureClock} a string comparison at all.
10
16
  */
11
- export default tripSlot.tool({
17
+ export default deskTool("flight", {
12
18
  description:
13
19
  "The FLIGHT DESK's search: the schedule, matched on any part of the route, e.g. " +
14
- "'Boston' or 'Zurich to Boston'. Omit the route to hear everything. Only usable while " +
15
- "the call is at that desk — from anywhere else it refuses, so call to_flight_assistant " +
16
- "first.",
20
+ "'Boston' or 'Zurich to Boston', and optionally only what leaves at or after a time " +
21
+ "of day. Omit the route to hear everything. Only usable while the call is at that " +
22
+ "desk — from anywhere else it refuses, so call to_flight_assistant first.",
17
23
  inputSchema: z.object({
18
24
  route: z
19
25
  .string()
@@ -21,15 +27,20 @@ export default tripSlot.tool({
21
27
  .describe("Route or city to match, e.g. 'Zurich to Boston'")
22
28
  .optional(),
23
29
  maxFare: z.number().positive().describe("Only flights at or under this fare").optional(),
30
+ departsAfter: clockTime("Only flights departing at or after this time of day").optional(),
24
31
  }),
25
- execute(args, trip) {
26
- const offDesk = requireDesk(trip, "flight");
27
- if (offDesk) return offDesk;
32
+ // The state is not read at all any more: the desk gate was the only thing a
33
+ // search needed it for, and `deskTool` owns that now.
34
+ execute(args) {
28
35
  const needle = args.route?.trim().toLowerCase();
29
36
  const matched = FLIGHTS.filter(
30
37
  (f) =>
31
38
  (!needle || f.route.toLowerCase().includes(needle) || f.id.toLowerCase() === needle) &&
32
- (args.maxFare === undefined || f.fare <= args.maxFare),
39
+ (args.maxFare === undefined || f.fare <= args.maxFare) &&
40
+ // A row whose departure is not a clock reading is left out of a
41
+ // time-filtered search rather than compared against one — see
42
+ // `departureClock`. Unfiltered searches are untouched.
43
+ (args.departsAfter === undefined || (departureClock(f) ?? "") >= args.departsAfter),
33
44
  );
34
45
  const results = matched.length > 0 ? matched : FLIGHTS;
35
46
  return {
@@ -1,10 +1,10 @@
1
1
  import { formatMoney } from "@alexkroman1/aai/utils";
2
2
  import { z } from "zod";
3
- import { HOTELS, requireDesk, tripSlot } from "../shared.ts";
3
+ import { deskTool, HOTELS } from "../shared.ts";
4
4
 
5
5
  /** Their `search_hotels`, with `price_tier` collapsed to a nightly ceiling —
6
6
  * a caller says "under two hundred", not "midscale". */
7
- export default tripSlot.tool({
7
+ export default deskTool("hotel", {
8
8
  description:
9
9
  "The HOTEL DESK's search: hotels by city, and optionally by the most they want to pay " +
10
10
  "per night. Only usable while the call is at that desk — from anywhere else it refuses, " +
@@ -13,9 +13,7 @@ export default tripSlot.tool({
13
13
  city: z.string().max(80).describe("City to search, e.g. 'Boston'"),
14
14
  maxPerNight: z.number().positive().describe("Nightly ceiling in dollars").optional(),
15
15
  }),
16
- execute(args, trip) {
17
- const offDesk = requireDesk(trip, "hotel");
18
- if (offDesk) return offDesk;
16
+ execute(args) {
19
17
  const city = args.city.trim().toLowerCase();
20
18
  const hotels = HOTELS.filter(
21
19
  (h) =>
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
- import { requireDesk, stageAction, tripSlot } from "../shared.ts";
2
+ import { deskUpdateTool, stageAction } from "../shared.ts";
3
3
 
4
4
  /**
5
5
  * SENSITIVE — their `update_ticket_to_new_flight`, behind the confirmation
6
6
  * gate. It changes nothing: it stages the move and hands back the sentence to
7
7
  * read aloud. `confirm_action` is what applies it.
8
8
  */
9
- export default tripSlot.updateTool({
9
+ export default deskUpdateTool("flight", {
10
10
  description:
11
11
  "The FLIGHT DESK's rebooking tool: move the caller's ticket to a different flight. " +
12
12
  "Only usable while the call is at that desk. This does NOT change the ticket — it " +
@@ -15,8 +15,6 @@ export default tripSlot.updateTool({
15
15
  flightId: z.string().max(20).describe("The flight to move to, e.g. 'LX52'"),
16
16
  }),
17
17
  execute(args, trip, ctx) {
18
- const offDesk = requireDesk(trip, "flight");
19
- if (offDesk) return offDesk;
20
18
  if (!trip.ticket) {
21
19
  return { error: "This caller has no ticket to move — it was cancelled on this call." };
22
20
  }