@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
@@ -0,0 +1,334 @@
1
+ import type { DeepReadonly, SlotCaps } from "@alexkroman1/aai";
2
+ import { sessionSlot, spokenAlphanumeric } from "@alexkroman1/aai";
3
+ import { formatMoney } from "@alexkroman1/aai/utils";
4
+
5
+ /**
6
+ * The roadside desk's world: the rate cards, the fleet, the one session slot,
7
+ * and the pure functions that turn a coverage record into money and into the
8
+ * words the disclosure is read from.
9
+ *
10
+ * `call.ts` holds the other half — where the CONVERSATION is. The split is the
11
+ * one `retail` draws between `shared.ts` and `store.ts` and it is worth keeping
12
+ * here for a reason specific to this template: everything in this file is a
13
+ * fact about the caller's vehicle, policy and truck, and not one of those is a
14
+ * fact about the call. Per-entity facts live in the slot; the position lives in
15
+ * the dialog. Mixing them is the mistake `dispatch-center`'s guide entry is
16
+ * about, and a file boundary is a cheap way not to make it.
17
+ */
18
+
19
+ // ─── The rate cards ──────────────────────────────────────────────────────────
20
+
21
+ /**
22
+ * What a plan charges, per plan.
23
+ *
24
+ * `callOut` is the flat fee for putting a truck on the road, `freeTowMiles` is
25
+ * what the plan tows for nothing, and `perMile` is what every mile after that
26
+ * costs. Both member plans waive the call-out, which is the whole thing the
27
+ * caller is paying an annual membership for and therefore the sentence the
28
+ * disclosure has to get right.
29
+ */
30
+ export const PLANS = {
31
+ basic: { name: "Roadside Basic", callOut: 0, freeTowMiles: 5, perMile: 4 },
32
+ plus: { name: "Roadside Plus", callOut: 0, freeTowMiles: 25, perMile: 3 },
33
+ } as const;
34
+
35
+ export type PlanId = keyof typeof PLANS;
36
+
37
+ /** One plan's numbers, or {@link NON_MEMBER}'s — what {@link quoteFee} prices. */
38
+ export type RateCard = (typeof PLANS)[PlanId] | typeof NON_MEMBER;
39
+
40
+ /**
41
+ * What a caller with no plan we could verify pays.
42
+ *
43
+ * Reached three ways — no policy on file, a lapsed one, and the
44
+ * `onCall.verifying` deadline giving up — and deliberately ONE rate card for
45
+ * all three. The desk does not know which of the three it is looking at by the
46
+ * time it quotes, and a caller quoted a different number depending on why we
47
+ * could not confirm them is the kind of thing a regulator reads out loud.
48
+ */
49
+ export const NON_MEMBER = {
50
+ name: "no verified plan",
51
+ callOut: 129,
52
+ freeTowMiles: 0,
53
+ perMile: 7,
54
+ } as const;
55
+
56
+ /**
57
+ * The rate card in force for a coverage record — or for the absence of one.
58
+ *
59
+ * Takes the FROZEN shape, because everything that calls it reads the slot: the
60
+ * template aliases `DeepReadonly` once ({@link FrozenRoadsideState}) and every
61
+ * pure helper over slot state is typed through it. A mutable `Coverage` still
62
+ * satisfies it, so an `update` draft passes unchanged.
63
+ */
64
+ export function rateFor(coverage: FrozenRoadsideState["coverage"]): RateCard {
65
+ if (coverage === null || coverage.status === "lapsed") return NON_MEMBER;
66
+ return PLANS[coverage.plan];
67
+ }
68
+
69
+ /**
70
+ * What this call costs the caller, in whole dollars.
71
+ *
72
+ * A PURE function of the rate card and the distance, called from two places
73
+ * that must never disagree: the disclosure the caller hears before the truck
74
+ * moves, and the invoice `dispatch_truck` writes after it does. When those two
75
+ * disagree the second one is a chargeback, so there is exactly one of them.
76
+ */
77
+ export function quoteFee(rate: RateCard, towMiles: number): Quote {
78
+ const billableMiles = Math.max(0, Math.ceil(towMiles) - rate.freeTowMiles);
79
+ const mileage = billableMiles * rate.perMile;
80
+ return { callOut: rate.callOut, billableMiles, mileage, total: rate.callOut + mileage };
81
+ }
82
+
83
+ export interface Quote {
84
+ /** The flat fee for rolling a truck at all. */
85
+ callOut: number;
86
+ /** Miles past what the plan covers — what `mileage` is charged for. */
87
+ billableMiles: number;
88
+ /** `billableMiles` at the plan's per-mile rate. */
89
+ mileage: number;
90
+ /** What the caller owes: `callOut + mileage`. */
91
+ total: number;
92
+ }
93
+
94
+ /**
95
+ * The mandatory service-fee disclosure, word for word.
96
+ *
97
+ * This is the text `onCall.disclosure` exists to get said, and it is built here
98
+ * rather than written into the state's `instruction` for two reasons. It varies
99
+ * with the plan, and an instruction is a fixed string. And an instruction is
100
+ * GUIDANCE — the model is supposed to act on it in its own words — where this
101
+ * is a script the model is supposed to read verbatim, which is a different kind
102
+ * of thing and reaches the model a different way: as a tool result
103
+ * (`service_disclosure`) that hands over the exact sentences.
104
+ */
105
+ export function disclosureFor(coverage: FrozenRoadsideState["coverage"]): string {
106
+ const rate = rateFor(coverage);
107
+ const cover =
108
+ rate === NON_MEMBER
109
+ ? "We could not confirm an active plan on this vehicle, so this call is billed at our " +
110
+ `non-member rate: a ${money(rate.callOut)} call-out fee, plus ${money(rate.perMile)} ` +
111
+ "for every mile the vehicle is towed."
112
+ : `You are on ${rate.name}. There is no call-out fee, the first ${rate.freeTowMiles} ` +
113
+ `miles of towing are covered, and it is ${money(rate.perMile)} a mile after that.`;
114
+ return (
115
+ `${cover} The fee is charged once the truck is dispatched, whether or not the vehicle ` +
116
+ "starts when the driver arrives, and it is not refunded if you cancel after that point. " +
117
+ "Any repair the driver makes at the roadside is billed separately by the shop."
118
+ );
119
+ }
120
+
121
+ /**
122
+ * A rate as the driver hears it.
123
+ *
124
+ * `formatMoney`'s, which is what the rest of the repo prints: this rendered
125
+ * `$150` where every other desk renders `$150.00`, so one caller quoted a
126
+ * call-out fee in a different format from the tow it was billed with.
127
+ */
128
+ export const money = formatMoney;
129
+
130
+ // ─── The fleet ───────────────────────────────────────────────────────────────
131
+
132
+ export type TruckKind = "service_van" | "flatbed" | "heavy_duty";
133
+
134
+ /** What can go wrong at the roadside, as the caller's own tool argument. */
135
+ export const SITUATIONS = [
136
+ "flat_tire",
137
+ "battery",
138
+ "lockout",
139
+ "out_of_fuel",
140
+ "wont_start",
141
+ "collision",
142
+ ] as const;
143
+
144
+ export type Situation = (typeof SITUATIONS)[number];
145
+
146
+ /**
147
+ * What each situation needs on scene.
148
+ *
149
+ * A jump start or a lockout is a van with a driver; a car that will not start
150
+ * goes on a flatbed, and anything that has been hit goes on the heavy. Sending
151
+ * the wrong one is a second call-out an hour later, which is why the caller is
152
+ * never asked to choose — they are asked what happened, and this decides.
153
+ */
154
+ export const TRUCK_FOR: Record<Situation, TruckKind> = {
155
+ flat_tire: "service_van",
156
+ battery: "service_van",
157
+ lockout: "service_van",
158
+ out_of_fuel: "service_van",
159
+ wont_start: "flatbed",
160
+ collision: "heavy_duty",
161
+ };
162
+
163
+ export interface Truck {
164
+ callsign: string;
165
+ kind: TruckKind;
166
+ /** Minutes out from the desk's own yard, before any priority bump. */
167
+ minutesOut: number;
168
+ }
169
+
170
+ /**
171
+ * A small fixed fleet, nearest first. A real desk queries a dispatch API here.
172
+ *
173
+ * Which of these is FREE is not a fact about this call, so it is not in this
174
+ * file: `yard.ts` owns the board, because two callers who both need a van are
175
+ * competing for the same two vehicles and nothing in a `sessionSlot` can see
176
+ * the other call.
177
+ */
178
+ export const FLEET: readonly Truck[] = [
179
+ { callsign: "Van-3", kind: "service_van", minutesOut: 18 },
180
+ { callsign: "Van-7", kind: "service_van", minutesOut: 31 },
181
+ { callsign: "Flat-2", kind: "flatbed", minutesOut: 26 },
182
+ { callsign: "Flat-9", kind: "flatbed", minutesOut: 44 },
183
+ { callsign: "Heavy-1", kind: "heavy_duty", minutesOut: 39 },
184
+ ];
185
+
186
+ /** Minutes a caller who is NOT in a safe place is moved up the queue by. */
187
+ export const PRIORITY_MINUTES = 8;
188
+ /** No promise is ever shorter than this, however the arithmetic comes out. */
189
+ export const MIN_ETA_MINUTES = 6;
190
+
191
+ /** What the caller is told, in minutes — the one number they will hold us to. */
192
+ export function etaMinutes(truck: Truck, safeToWait: boolean): number {
193
+ const bumped = safeToWait ? truck.minutesOut : truck.minutesOut - PRIORITY_MINUTES;
194
+ return Math.max(MIN_ETA_MINUTES, bumped);
195
+ }
196
+
197
+ // ─── The policy book ─────────────────────────────────────────────────────────
198
+
199
+ export interface Coverage {
200
+ policyNumber: string;
201
+ holder: string;
202
+ plan: PlanId;
203
+ status: "active" | "lapsed";
204
+ }
205
+
206
+ /**
207
+ * The policies this demo knows about. A real desk calls a membership service.
208
+ *
209
+ * A lapsed policy is in here on purpose: "we found you and you are not covered"
210
+ * and "we could not find you" are the same PRICE and a different SENTENCE, and
211
+ * a caller who thinks they are covered and is not is the single worst outcome
212
+ * this call has.
213
+ */
214
+ const POLICY_BOOK: readonly Coverage[] = [
215
+ { policyNumber: "RS-4417", holder: "Dana Whitfield", plan: "plus", status: "active" },
216
+ { policyNumber: "RS-8802", holder: "Marcus Oyelaran", plan: "basic", status: "active" },
217
+ { policyNumber: "RS-1290", holder: "Priya Raghavan", plan: "plus", status: "lapsed" },
218
+ ];
219
+
220
+ /** Look a policy number up, however the caller spelled it out loud. */
221
+ export function findPolicy(policyNumber: string): Coverage | undefined {
222
+ const wanted = normalizePolicy(policyNumber);
223
+ return POLICY_BOOK.find((policy) => normalizePolicy(policy.policyNumber) === wanted);
224
+ }
225
+
226
+ /**
227
+ * A policy number as the desk compares them.
228
+ *
229
+ * Callers read these off a card down a phone line, so the hyphen, the spaces
230
+ * and the case are all noise — "r s four four one seven" comes through STT as
231
+ * anything from `RS4417` to `rs 4417`. Comparing the raw string is the version
232
+ * that tells a covered member they have no plan.
233
+ */
234
+ function normalizePolicy(policyNumber: string): string {
235
+ return spokenAlphanumeric(policyNumber);
236
+ }
237
+
238
+ // ─── The session's own state ─────────────────────────────────────────────────
239
+
240
+ export interface Vehicle {
241
+ year: number | null;
242
+ make: string;
243
+ model: string;
244
+ color: string | null;
245
+ }
246
+
247
+ export interface Whereabouts {
248
+ /** Where the caller says they are, in their own words. */
249
+ described: string;
250
+ /** Anything a driver can steer by — a mile marker, an exit, a storefront. */
251
+ landmark: string | null;
252
+ /** Whether they are somewhere they can wait. Decides the priority bump. */
253
+ safeToWait: boolean;
254
+ }
255
+
256
+ export interface TowJob {
257
+ callsign: string;
258
+ kind: TruckKind;
259
+ destination: string;
260
+ towMiles: number;
261
+ etaMinutes: number;
262
+ quote: Quote;
263
+ }
264
+
265
+ export interface RoadsideState {
266
+ vehicle: Vehicle | null;
267
+ where: Whereabouts | null;
268
+ situation: Situation | null;
269
+ /** The plan the lookup found. `null` means unverified, which is a PRICE. */
270
+ coverage: Coverage | null;
271
+ /** When the caller said they understood the disclosure, epoch ms. */
272
+ disclosureAcceptedAt: number | null;
273
+ /** The one truck this call ever assigns. See `dispatch_truck`. */
274
+ job: TowJob | null;
275
+ log: string[];
276
+ }
277
+
278
+ export function emptyRoadsideState(): RoadsideState {
279
+ return {
280
+ vehicle: null,
281
+ where: null,
282
+ situation: null,
283
+ coverage: null,
284
+ disclosureAcceptedAt: null,
285
+ job: null,
286
+ log: [],
287
+ };
288
+ }
289
+
290
+ /**
291
+ * How much of the call the log keeps, as the slot's own bound.
292
+ *
293
+ * Named and typed rather than written inline for the two reasons a `MAX_*`
294
+ * constant survives at all: a spec reads it (`agent.test.ts` proves the oldest
295
+ * lines really are evicted rather than trusting the declaration), and
296
+ * {@link SlotCaps} is what says WHICH keys may carry a bound — it maps only the
297
+ * array-valued fields of {@link RoadsideState}, so a cap on `coverage` or a
298
+ * typo like `logs` is a compile error here rather than a number the slot
299
+ * silently ignores.
300
+ *
301
+ * Twenty-four lines is enough to read a whole call back: a located caller, a
302
+ * coverage line, a disclosure, a dispatch, and room for whatever went wrong.
303
+ */
304
+ export const LOG_CAP: SlotCaps<RoadsideState> = { log: 24 };
305
+
306
+ /**
307
+ * Everything this call has established, as one typed slot.
308
+ *
309
+ * **No `after` hook, and that is a claim rather than an omission.** Nothing
310
+ * stored here is derived from anything else stored here: the money is
311
+ * {@link quoteFee} of the coverage and the distance, computed where it is
312
+ * quoted, and the log is bounded by `caps` — twenty-four lines is enough to
313
+ * read back a whole call. The moment a field IS derived — a running total, a
314
+ * flag some tool reads — it belongs in an `after` hook rather than in whichever
315
+ * tool happened to write last; see `dispatch-center` for the worked version of
316
+ * that.
317
+ */
318
+ export const roadsideSlot = sessionSlot("roadside", emptyRoadsideState, { caps: LOG_CAP });
319
+
320
+ /**
321
+ * The slot as a READ hands it out: deep-frozen, and typed to say so.
322
+ *
323
+ * Every template that reads its slot from a pure helper aliases this once —
324
+ * `slot.get` and a gated read both answer {@link DeepReadonly}, and TypeScript
325
+ * does not ignore `readonly` on arrays, so `readonly string[]` stops satisfying
326
+ * `string[]`. A mutable value still satisfies the alias, so an `update` draft
327
+ * passes unchanged while a helper that WOULD have mutated stops compiling.
328
+ */
329
+ export type FrozenRoadsideState = DeepReadonly<RoadsideState>;
330
+
331
+ /** The vehicle as a driver would be told to look for it. */
332
+ export function describeVehicle(vehicle: Vehicle): string {
333
+ return [vehicle.year, vehicle.color, vehicle.make, vehicle.model].filter(Boolean).join(" ");
334
+ }
@@ -0,0 +1,37 @@
1
+ You are the dispatch desk on a roadside-assistance line. The person calling you
2
+ is standing next to a vehicle that will not move, often on a shoulder, often in
3
+ the dark, sometimes in the rain. Everything below serves one goal: get a truck
4
+ to them, at a price they were told about before it moved.
5
+
6
+ Speak like a dispatcher who has done this for years. Short sentences. One
7
+ question at a time. Confirm what you heard before you act on it. Never fill
8
+ silence with reassurance you cannot back up — no "someone should be there
9
+ shortly" without a callsign and a number of minutes from `dispatch_truck`.
10
+
11
+ SAFETY COMES BEFORE THE CALL. If the caller is in a live traffic lane, if
12
+ anyone is hurt, or if there is smoke or fuel on the ground, tell them to get
13
+ clear and call emergency services first. That instruction outranks everything
14
+ else here, and it is worth losing the call over.
15
+
16
+ WHERE THE CALL IS. Every tool answers with the step this call is on and what
17
+ that step expects next, and the instruction for that step reaches you on every
18
+ turn. Read it. You do not have to remember the order of this call, and you must
19
+ not invent a step that is not in front of you: a tool that refuses is telling
20
+ you what to do first.
21
+
22
+ WHAT YOU MUST NOT DO:
23
+
24
+ - Do not tell a caller they are covered because it sounds likely. `lookup_coverage`
25
+ is the only thing that knows. A caller who believes they are covered and is not
26
+ will find out from an invoice, and that is the worst outcome this call has.
27
+ - Do not summarise the fee disclosure. Read what `service_disclosure` gives you,
28
+ in those words, all of it. If the caller talks over you, finish it anyway and
29
+ then answer them.
30
+ - Do not promise a truck you have not sent. A callsign and an ETA come from
31
+ `dispatch_truck` and from nowhere else.
32
+ - Do not read a policy number back as anything other than what you heard. If you
33
+ are not sure of a digit, ask.
34
+
35
+ NUMBERS OUT LOUD. Policy numbers go digit by digit — "R S, four four one
36
+ seven". Money is dollars, said plainly. An ETA is minutes, not a clock time: the
37
+ caller has no idea what time you think it is.
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ import { roadsideCall } from "../call.ts";
3
+ import { roadsideSlot } from "../shared.ts";
4
+
5
+ /**
6
+ * What the caller said about the fee, and the only way out of
7
+ * `onCall.disclosure`.
8
+ *
9
+ * `sendFrom` rather than `send`, because the outcome picks the transition: a
10
+ * caller who agrees moves the call to dispatch, and one who does not stays
11
+ * exactly where they are. Returning `undefined` from `sendFrom` is how a tool
12
+ * says "that worked, and it did not move the conversation" — which is a
13
+ * different thing from a `ToolFailure`, since declining a fee is not an error.
14
+ *
15
+ * **`sendFrom` is declared BELOW `execute`, and that is a rule rather than a
16
+ * habit.** `execute` here is an inline arrow whose parameters are contextually
17
+ * typed, so its return type is inferred in a later pass than this signature is
18
+ * checked: written above, `result` lands as `unknown` and `result.accepted` is
19
+ * a `TS18046`. The failure arm is already subtracted for us — a body that
20
+ * answered a `ToolFailure` never reaches `sendFrom` at all.
21
+ */
22
+ export default roadsideCall.tool({
23
+ description:
24
+ "Record the caller's answer to the fee disclosure, after you have read it to them in full. " +
25
+ "Set accepted to true only if they said yes to the charge. If they said no, or want to " +
26
+ "think, set it to false — the call stays where it is and you can read it again.",
27
+ when: "onCall.disclosure",
28
+ inputSchema: z.object({
29
+ accepted: z.boolean().describe("Whether the caller agreed to the fee"),
30
+ inTheirWords: z
31
+ .string()
32
+ .max(200)
33
+ .optional()
34
+ .describe("What they actually said, for the call log"),
35
+ }),
36
+ execute: (args, ctx) =>
37
+ roadsideSlot.update(ctx, (state) => {
38
+ state.disclosureAcceptedAt = args.accepted ? Date.now() : null;
39
+ state.log.push(args.accepted ? "Fee disclosure accepted" : "Fee disclosure declined");
40
+ return {
41
+ accepted: args.accepted,
42
+ saidAt: state.disclosureAcceptedAt,
43
+ heard: args.inTheirWords ?? null,
44
+ };
45
+ }),
46
+ sendFrom: (result) => (result.accepted ? { type: "DISCLOSED" } : undefined),
47
+ });
@@ -0,0 +1,148 @@
1
+ import { failable, isToolFailure, orFail, type ToolFailure, toolFailure } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+ import { roadsideCall } from "../call.ts";
4
+ import {
5
+ describeVehicle,
6
+ etaMinutes,
7
+ type FrozenRoadsideState,
8
+ type Quote,
9
+ quoteFee,
10
+ rateFor,
11
+ roadsideSlot,
12
+ type Situation,
13
+ type Truck,
14
+ } from "../shared.ts";
15
+ import { reserveTruck } from "../yard.ts";
16
+
17
+ /**
18
+ * Everything the desk needs off the slot before a truck can move — or the
19
+ * sentence saying what is missing.
20
+ *
21
+ * Unreachable while the gate holds: `onCall.dispatching` is four states
22
+ * downstream of `report_location`. Reported rather than thrown for the reason
23
+ * every guard in this template is — this runs mid-call, and a sentence the
24
+ * model can act on beats an exception down a phone line.
25
+ */
26
+ function dispatchBasis(state: FrozenRoadsideState): DispatchBasis | ToolFailure {
27
+ if (state.situation === null || state.where === null || state.vehicle === null) {
28
+ return toolFailure(
29
+ "Nothing is on file for this call yet — no location, vehicle or situation. Take those " +
30
+ "first with report_location.",
31
+ );
32
+ }
33
+ return { situation: state.situation, where: state.where, vehicle: state.vehicle };
34
+ }
35
+
36
+ interface DispatchBasis {
37
+ readonly situation: Situation;
38
+ readonly where: NonNullable<FrozenRoadsideState["where"]>;
39
+ readonly vehicle: NonNullable<FrozenRoadsideState["vehicle"]>;
40
+ }
41
+
42
+ interface DispatchPlan {
43
+ readonly truck: Truck;
44
+ readonly etaMinutes: number;
45
+ readonly quote: Quote;
46
+ readonly lookFor: string;
47
+ readonly at: string;
48
+ }
49
+
50
+ /**
51
+ * The whole decision, off the slot and against the yard, before anything is
52
+ * written.
53
+ *
54
+ * **`failable` pays here and would not have paid inside the `update` body it
55
+ * came out of.** The SDK's own rule is that the wrapper earns its three lines
56
+ * on a NAMED helper returning `T | ToolFailure` and not on an inline mutator
57
+ * with one or two guards; this is the named helper, it forwards two failures
58
+ * ({@link dispatchBasis} and a yard that has nothing free or does not answer),
59
+ * and each `orFail` replaces an `if (isToolFailure(x)) return x;` that said
60
+ * nothing about roadside assistance.
61
+ *
62
+ * It is also deliberately OUTSIDE the mutation window. `reserveTruck` awaits
63
+ * the yard, and a `slot.update` body is synchronous — so the shape is claim,
64
+ * await, then write, which is the same order `plan-and-execute`'s
65
+ * `work_next_step` uses for a body that has to call out mid-tool.
66
+ */
67
+ const planDispatch = failable(
68
+ async (state: FrozenRoadsideState, callKey: string, towMiles: number): Promise<DispatchPlan> => {
69
+ const basis = orFail(dispatchBasis(state));
70
+ const truck = orFail(await reserveTruck(basis.situation, callKey));
71
+ return {
72
+ truck,
73
+ etaMinutes: etaMinutes(truck, basis.where.safeToWait),
74
+ quote: quoteFee(rateFor(state.coverage), towMiles),
75
+ lookFor: describeVehicle(basis.vehicle),
76
+ at: basis.where.described,
77
+ };
78
+ },
79
+ );
80
+
81
+ /**
82
+ * Send the truck.
83
+ *
84
+ * **Idempotent on purpose, and that is what makes the state's `toolChoice` pin
85
+ * safe.** `onCall.dispatching` pins the model to this tool, so it is called on
86
+ * every step of every turn for the rest of the call — which is exactly the
87
+ * guarantee wanted ("do not tell a stranded caller a truck is coming without
88
+ * sending one") and would be a fleet of trucks if a second call rolled a second
89
+ * one. So the job is written once and every later call answers with the job
90
+ * that already exists, refreshed ETA and all.
91
+ *
92
+ * The idempotency is stated TWICE, and both are load-bearing because the body
93
+ * awaits. The slot check below catches the ordinary repeat; the yard's own
94
+ * `callKey` hold catches two pinned calls in the SAME step, which the LLM loop
95
+ * runs concurrently and which would otherwise both read `job === null` and both
96
+ * take a truck. `yard.ts` has the argument.
97
+ *
98
+ * It also means the tool must need nothing the caller has not already said: a
99
+ * pinned step cannot ask a question. Everything here comes off the slot, except
100
+ * the destination and the distance, which the caller gives once and which
101
+ * default to the nearest approved shop when they have no preference.
102
+ */
103
+ export default roadsideCall.tool({
104
+ description:
105
+ "Dispatch the truck and price the tow. Call this once the caller has accepted the fee. " +
106
+ "Calling it again on the same call reports the SAME job — it never sends a second truck.",
107
+ when: "onCall.dispatching",
108
+ inputSchema: z.object({
109
+ destination: z
110
+ .string()
111
+ .max(200)
112
+ .describe("Where the vehicle is going — a shop, a dealer, or 'nearest approved shop'"),
113
+ towMiles: z
114
+ .number()
115
+ .min(0)
116
+ .max(500)
117
+ .describe("Road miles from the vehicle to that destination. Use 0 for a roadside fix."),
118
+ }),
119
+ execute: async (args, ctx) => {
120
+ // A COPY rather than the stored object: what a read hands out is frozen,
121
+ // and spreading it is what makes the result a plain value again.
122
+ const dispatched = roadsideSlot.get(ctx).job;
123
+ if (dispatched !== null) return { ...dispatched, alreadyDispatched: true };
124
+
125
+ const plan = await planDispatch(roadsideSlot.get(ctx), ctx.sessionId, args.towMiles);
126
+ if (isToolFailure(plan)) return plan;
127
+
128
+ return roadsideSlot.update(ctx, (state) => {
129
+ // Read again inside the window: the yard round trip above is an await, so
130
+ // a concurrent pinned call may have landed here first. It holds the same
131
+ // truck — that is the yard's `callKey` contract — and the job it wrote is
132
+ // the one this call keeps.
133
+ if (state.job !== null) return { ...state.job, alreadyDispatched: true };
134
+ state.job = {
135
+ callsign: plan.truck.callsign,
136
+ kind: plan.truck.kind,
137
+ destination: args.destination,
138
+ towMiles: args.towMiles,
139
+ etaMinutes: plan.etaMinutes,
140
+ quote: plan.quote,
141
+ };
142
+ state.log.push(
143
+ `Dispatched ${plan.truck.callsign}, ETA ${plan.etaMinutes} min, total ${plan.quote.total}`,
144
+ );
145
+ return { ...state.job, alreadyDispatched: false, lookFor: plan.lookFor, at: plan.at };
146
+ });
147
+ },
148
+ });
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { ON_THE_LINE, roadsideCall } from "../call.ts";
3
+ import { describeVehicle, rateFor, roadsideSlot } from "../shared.ts";
4
+
5
+ /**
6
+ * Everything this call has established so far — for the caller who asks "what
7
+ * did you say my fee was?" three turns later.
8
+ *
9
+ * Gated on the PARENT: `"onCall"` matches all five phases, so this is legal
10
+ * throughout the call and refused the moment `abandoned` is reached. That is
11
+ * not the same as ungated, and the difference is the point — a read that still
12
+ * answered after the caller hung up would be a desk reporting on a call that no
13
+ * longer exists.
14
+ *
15
+ * The result carries `state`, `done` and the active `instruction` because
16
+ * `roadsideCall.tool` writes them, which is also how the model re-reads its own
17
+ * position after a turn that called nothing.
18
+ */
19
+ export default roadsideCall.tool({
20
+ description:
21
+ "What this call has established so far: location, vehicle, plan, and the truck if one has " +
22
+ "been sent. Use it to answer a caller repeating a question rather than asking them again.",
23
+ when: ON_THE_LINE,
24
+ inputSchema: z.object({}),
25
+ execute: (_args, ctx) => {
26
+ const state = roadsideSlot.get(ctx);
27
+ return {
28
+ where: state.where?.described ?? null,
29
+ safeToWait: state.where?.safeToWait ?? null,
30
+ vehicle: state.vehicle === null ? null : describeVehicle(state.vehicle),
31
+ situation: state.situation,
32
+ plan: rateFor(state.coverage).name,
33
+ feeDisclosureAccepted: state.disclosureAcceptedAt !== null,
34
+ job: state.job,
35
+ log: state.log,
36
+ };
37
+ },
38
+ });
@@ -0,0 +1,72 @@
1
+ import { toolFailure } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+ import { roadsideCall } from "../call.ts";
4
+ import { findPolicy, quoteFee, rateFor, roadsideSlot } from "../shared.ts";
5
+
6
+ /**
7
+ * What this caller is covered for — the one thing on this call that must never
8
+ * be guessed.
9
+ *
10
+ * Three outcomes, and the difference between them is the reason this is a tool
11
+ * rather than a prompt rule:
12
+ *
13
+ * - a policy that matches → the plan is latched and the call moves on;
14
+ * - **no policy number at all** (`policyNumber` omitted) → the caller has told
15
+ * us they have no plan or cannot find it, which is an ANSWER: coverage stays
16
+ * `null`, the call still moves on, and the non-member rate is what the
17
+ * disclosure will quote;
18
+ * - a number that matches NOTHING → a `ToolFailure`. The call does not move,
19
+ * because "I misheard four digits" and "you have no plan" are the same price
20
+ * and very much not the same sentence.
21
+ *
22
+ * The third case is where the `send` contract earns its keep: a gated tool
23
+ * sends nothing when its body answers a failure, so a mistyped policy number
24
+ * cannot leave the caller quoted at a rate nobody looked up.
25
+ */
26
+ export default roadsideCall.tool({
27
+ description:
28
+ "Look up the caller's roadside plan by the policy number on their card. Omit policyNumber " +
29
+ "only if they have told you they have no plan or cannot find the number — that is an " +
30
+ "answer, and it is priced as a non-member. Never tell a caller they are covered without " +
31
+ "calling this.",
32
+ when: "onCall.verifying",
33
+ send: { type: "VERIFIED" },
34
+ inputSchema: z.object({
35
+ policyNumber: z
36
+ .string()
37
+ .max(40)
38
+ .optional()
39
+ .describe("The policy number as they read it out, e.g. 'RS-4417'. Omit if they have none."),
40
+ }),
41
+ execute: (args, ctx) =>
42
+ roadsideSlot.update(ctx, (state) => {
43
+ if (args.policyNumber !== undefined) {
44
+ const found = findPolicy(args.policyNumber);
45
+ if (!found) {
46
+ return toolFailure(
47
+ `No plan is on file under ${args.policyNumber}. Read it back to them digit by ` +
48
+ "digit and try once more. If they cannot find the card, call this again with no " +
49
+ "policy number and we will price it as a non-member.",
50
+ );
51
+ }
52
+ state.coverage = { ...found };
53
+ } else {
54
+ state.coverage = null;
55
+ }
56
+ const rate = rateFor(state.coverage);
57
+ state.log.push(`Coverage: ${rate.name}`);
58
+ // The zero-mile quote, which is what the caller owes if the driver fixes
59
+ // it at the roadside. `quoteFee` is the same function `dispatch_truck`
60
+ // prices the tow with — there is one of it precisely so the number the
61
+ // caller hears now and the number on the invoice cannot drift.
62
+ return {
63
+ plan: rate.name,
64
+ holder: state.coverage?.holder ?? null,
65
+ status: state.coverage?.status ?? "unverified",
66
+ callOut: rate.callOut,
67
+ freeTowMiles: rate.freeTowMiles,
68
+ perMile: rate.perMile,
69
+ ifNoTowNeeded: quoteFee(rate, 0).total,
70
+ };
71
+ }),
72
+ });