@alexkroman1/aai-cli 15.1.0 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,35 +1,36 @@
1
1
  import { plural } from "@alexkroman1/aai/utils";
2
2
  import "@alexkroman1/aai-ui/styles.css";
3
- import type { AgentState, ConversationItem } from "@alexkroman1/aai-ui";
3
+ import type {
4
+ AgentState,
5
+ ChatMessage,
6
+ SessionControlButton,
7
+ ToolCallInfo,
8
+ } from "@alexkroman1/aai-ui";
4
9
  import {
5
- AGENT_STATE_LABELS,
6
- AutoScroll,
10
+ ConversationView,
7
11
  mountClient,
12
+ SessionControls,
8
13
  SessionErrorBanner,
14
+ SessionStateDot,
15
+ ToolCallRow,
9
16
  useAgentState,
10
- useConversation,
11
- useSessionActions,
12
- useSessionSelector,
13
- useSessionStatus,
14
17
  } from "@alexkroman1/aai-ui";
15
18
  import type { DispatchState, IncidentSummary, Severity, Status } from "./shared.ts";
16
19
  import { dashboardProjection } from "./shared.ts";
17
20
 
21
+ /*
22
+ * The board's own motion: the slide a new card and a new bubble make. The pulse
23
+ * it used to declare beside this was the SDK's `aai-pulse` under another name,
24
+ * and every dot here runs on that one now. The scrollbars are `.aai-scroll`
25
+ * from the same stylesheet; the one thing the board says about them is the
26
+ * thumb colour, as a custom property the utility reads.
27
+ */
18
28
  const CSS = `
19
- @keyframes dc-pulse {
20
- 0%, 100% { opacity: 1; }
21
- 50% { opacity: 0.5; }
22
- }
23
29
  @keyframes dc-slide-in {
24
30
  from { transform: translateY(10px); opacity: 0; }
25
31
  to { transform: translateY(0); opacity: 1; }
26
32
  }
27
- .dc-messages::-webkit-scrollbar { width: 6px; }
28
- .dc-messages::-webkit-scrollbar-track { background: transparent; }
29
- .dc-messages::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
30
- .dc-sidebar::-webkit-scrollbar { width: 6px; }
31
- .dc-sidebar::-webkit-scrollbar-track { background: transparent; }
32
- .dc-sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
33
+ .dc-main { --aai-scrollbar-thumb: #334155; }
33
34
  @media (max-width: 900px) {
34
35
  .dc-main { grid-template-columns: 1fr !important; grid-template-rows: auto 1fr !important; }
35
36
  }
@@ -66,11 +67,11 @@ const statusColors: Record<string, string> = {
66
67
  // if-chain with a grey default.
67
68
  //
68
69
  // The palette is this template's own — every client here paints the same six
69
- // states in its own colours, so the SDK has nothing to share but the union. What
70
- // the SDK does own is `AgentState`, and `satisfies Record<AgentState, string>`
71
- // is what borrows it: a state added there stops compiling here, where the
72
- // `state === "…"` chain this replaced answered a new state with a silent grey
73
- // badge in three separate files and no way to notice.
70
+ // states in its own colours, so it is the one prop `<SessionStateDot>` cannot
71
+ // default. What the SDK does own is `AgentState`, and `satisfies
72
+ // Record<AgentState, string>` is what borrows it: a state added there stops
73
+ // compiling here, where the `state === "…"` chain this replaced answered a new
74
+ // state with a silent grey badge in three separate files and no way to notice.
74
75
  const STATE_COLORS = {
75
76
  disconnected: "#6b7280",
76
77
  connecting: "#6b7280",
@@ -82,14 +83,12 @@ const STATE_COLORS = {
82
83
  } satisfies Record<AgentState, string>;
83
84
 
84
85
  /*
85
- * The board's own vocabulary, spread over the package's record rather than
86
- * written as a ternary chain. Only three of the seven states get a dispatch
87
- * word; the rest come from `AGENT_STATE_LABELS`, so a state added upstream
88
- * reads as something rather than falling through to whichever arm the chain
89
- * ended on.
86
+ * The board's own vocabulary — only three of the seven states get a dispatch
87
+ * word. The rest are `<SessionStateDot>`'s defaults (`AGENT_STATE_LABELS`), so a
88
+ * state added upstream reads as something rather than falling through to
89
+ * whichever arm a ternary chain ended on.
90
90
  */
91
- const STATE_LABELS: Record<AgentState, string> = {
92
- ...AGENT_STATE_LABELS,
91
+ const STATE_LABELS: Partial<Record<AgentState, string>> = {
93
92
  listening: "LISTENING",
94
93
  thinking: "PROCESSING",
95
94
  speaking: "TRANSMITTING",
@@ -158,31 +157,34 @@ function IncidentCard({ inc }: { inc: IncidentSummary }) {
158
157
  );
159
158
  }
160
159
 
161
- /** One radio line: a message bubble, or the tool call that came after it. */
162
- function Row({ item }: { item: ConversationItem }) {
163
- if (item.kind === "tool") {
164
- const { name, status } = item.toolCall;
165
- return (
166
- <div
167
- className="self-start rounded-md px-2.5 py-1.5 text-[11px] font-mono flex items-center gap-2"
168
- style={{
169
- background: "#111827",
170
- border: "1px solid #1e293b",
171
- color: status === "pending" ? "#eab308" : "#64748b",
172
- }}
173
- >
160
+ /**
161
+ * The tool the desk ran: the SDK's compact row, with the board's own dot in
162
+ * its icon slot. `ToolCallRow` owns the shimmer while the call is pending and
163
+ * the row's shape; the dot's colours are this board's.
164
+ */
165
+ function ToolChip({ toolCall }: { toolCall: ToolCallInfo }) {
166
+ const pending = toolCall.status === "pending";
167
+ return (
168
+ <ToolCallRow
169
+ variant="compact"
170
+ className="self-start"
171
+ title={toolCall.name}
172
+ pending={pending}
173
+ icon={
174
174
  <span
175
- className="w-1.5 h-1.5 rounded-full inline-block"
175
+ className="w-1.5 h-1.5 rounded-full inline-block align-middle"
176
176
  style={{
177
- background: status === "pending" ? "#eab308" : "#22c55e",
178
- animation: status === "pending" ? "dc-pulse 1s ease-in-out infinite" : "none",
177
+ background: pending ? "#eab308" : "#22c55e",
178
+ animation: pending ? "aai-pulse 1s ease-in-out infinite" : "none",
179
179
  }}
180
180
  />
181
- {name}
182
- </div>
183
- );
184
- }
185
- const { role, content } = item.message;
181
+ }
182
+ />
183
+ );
184
+ }
185
+
186
+ /** One radio line — the markup this template exists to show. */
187
+ function Bubble({ role, content }: ChatMessage) {
186
188
  return (
187
189
  <div
188
190
  className="rounded-lg text-[13px] max-w-[85%] px-3.5 py-2.5"
@@ -206,191 +208,111 @@ function Row({ item }: { item: ConversationItem }) {
206
208
  /**
207
209
  * The radio log.
208
210
  *
209
- * `useConversation()` rather than a `session.messages.map(...)`: the messages
211
+ * `<ConversationView>` rather than a `session.messages.map(...)`: the messages
210
212
  * were only half of it. This board runs eight tools and rendered NONE of them,
211
213
  * because tool calls live in a second array this page never read — and it also
212
- * dropped the streaming reply and the thinking indicator. The hook owns the
214
+ * dropped the streaming reply and the thinking indicator. The view owns the
213
215
  * interleave (a tool row follows its anchor message), the `null`-vs-`""`
214
- * transcript distinction and the thinking-suppression rule; what stays here is
215
- * the markup, which is the part this template exists to show.
216
+ * transcript distinction, the thinking-suppression rule and the announced
217
+ * thinking row; what stays here is the markup in each slot, which is the part
218
+ * this template exists to show. The live transcript is pinned BELOW the scroll
219
+ * as its own strip, which is what `transcriptPosition="below"` is for.
216
220
  *
217
221
  * It also subscribes per FIELD, so the conversation re-renders at the
218
222
  * conversation's rate. The whole-page `useSession()` this replaced re-rendered
219
223
  * the incident board on every STT partial.
220
224
  */
221
225
  function Conversation() {
222
- const { items, streaming, transcript, thinking } = useConversation();
223
226
  return (
224
- <>
225
- <AutoScroll
226
- scrollClassName="dc-messages overflow-y-auto"
227
- contentClassName="p-4 flex flex-col gap-2"
228
- >
229
- {items.length === 0 && !streaming && (
230
- <div className="text-center p-10 text-[13px]" style={{ color: "#475569" }}>
231
- Dispatch Command Center standing by. Click START to begin operations.
232
- </div>
233
- )}
234
- {items.map((item) => (
235
- <Row
236
- key={item.kind === "message" ? `m${item.message.id}` : item.toolCall.callId}
237
- item={item}
238
- />
239
- ))}
240
- {streaming !== null && (
241
- <div
242
- className="rounded-lg text-[13px] max-w-[85%] px-3.5 py-2.5 self-start"
243
- style={{ lineHeight: 1.6, background: "#1e293b", borderLeft: "3px solid #3b82f6" }}
244
- >
245
- <div className="text-[10px] uppercase tracking-wider mb-1" style={{ color: "#64748b" }}>
246
- DISPATCH
247
- </div>
248
- {streaming}
249
- </div>
250
- )}
251
- {/* Same contract as the shipped `MessageList`'s indicator: three pulsing
252
- dots are the only sign the desk is working, and to a screen reader
253
- they are punctuation. */}
254
- {thinking && (
255
- <div
256
- role="status"
257
- aria-label="Dispatch is thinking"
258
- className="self-start text-[11px] px-3.5"
259
- style={{ color: "#64748b" }}
260
- >
261
- <span style={{ animation: "dc-pulse 1.2s ease-in-out infinite" }}>· · ·</span>
262
- </div>
263
- )}
264
- </AutoScroll>
265
-
266
- {transcript.speaking && (
227
+ <ConversationView
228
+ scrollClassName="aai-scroll overflow-y-auto"
229
+ contentClassName="p-4 flex flex-col gap-2"
230
+ empty={
231
+ <div className="text-center p-10 text-[13px]" style={{ color: "#475569" }}>
232
+ Dispatch Command Center standing by. Click START to begin operations.
233
+ </div>
234
+ }
235
+ renderMessage={(message) => <Bubble {...message} />}
236
+ renderTool={(toolCall) => <ToolChip toolCall={toolCall} />}
237
+ renderTranscript={({ text }) => (
267
238
  <div
268
239
  className="flex items-center px-4 py-2 text-xs italic min-h-8"
269
240
  style={{ background: "#111827", borderTop: "1px solid #1e293b", color: "#64748b" }}
270
241
  >
271
242
  <span
272
243
  className="w-2.5 h-2.5 rounded-full inline-block mr-2"
273
- style={{ background: "#22c55e", animation: "dc-pulse 1.5s ease-in-out infinite" }}
244
+ style={{ background: "#22c55e", animation: "aai-pulse 1.5s ease-in-out infinite" }}
274
245
  />
275
- {transcript.text}
246
+ {text}
276
247
  </div>
277
248
  )}
278
- </>
249
+ transcriptPosition="below"
250
+ thinkingLabel="Dispatch is thinking"
251
+ thinkingClassName="self-start text-[11px] px-3.5 text-[#64748b]"
252
+ />
279
253
  );
280
254
  }
281
255
 
282
256
  /**
283
- * The live status readout, on its own subscription.
284
- *
285
- * `useSessionSelector` rather than a field off a whole-page `useSession()`: the
286
- * header is the only thing here that cares about the session state, and reading
287
- * it one level up dragged the incident board through every snapshot change.
257
+ * The live status readout: the SDK's dot in the board's colours, on its own
258
+ * subscription — the header is the only thing here that cares about the session
259
+ * state, and reading it one level up dragged the incident board through every
260
+ * snapshot change.
288
261
  */
289
262
  function StatusReadout() {
290
- const state = useSessionStatus();
291
263
  return (
292
- <>
293
- <span
294
- className="w-2.5 h-2.5 rounded-full inline-block"
295
- style={{
296
- background: STATE_COLORS[state],
297
- animation:
298
- state === "listening"
299
- ? "dc-pulse 1.5s ease-in-out infinite"
300
- : state === "thinking"
301
- ? "dc-pulse 0.8s ease-in-out infinite"
302
- : "none",
303
- }}
304
- title={state}
305
- />
306
- <span className="text-[11px] font-normal normal-case" style={{ color: "#64748b" }}>
307
- {STATE_LABELS[state]}
308
- </span>
309
- </>
264
+ <SessionStateDot
265
+ colors={STATE_COLORS}
266
+ labels={STATE_LABELS}
267
+ dotClassName="w-2.5 h-2.5"
268
+ labelClassName="text-[11px] font-normal normal-case text-[#64748b]"
269
+ />
310
270
  );
311
271
  }
312
272
 
313
- /*
314
- * The shift controls.
315
- *
316
- * `useSessionActions()` for the methods and two one-field selectors for the
317
- * flags, rather than the whole-snapshot `useSession()` this used to hold. The
318
- * methods are what the row is really after, and `useSession()` re-renders on
319
- * every snapshot change — so four buttons re-rendered at STT-partial rate to
320
- * read two booleans that flip once a shift.
273
+ const SHIFT_BUTTON =
274
+ "px-4 py-2 border-none rounded-md font-mono text-xs font-semibold uppercase tracking-wider cursor-pointer";
275
+
276
+ /**
277
+ * One shift button in the board's colours. `<SessionControls>` decides WHICH
278
+ * buttons exist and what each presses — including that "New Conversation" is
279
+ * `end()` then `start()` and never `reset()`, which is argued once on that
280
+ * component rather than in a comment here; this decides only how they look.
281
+ */
282
+ function shiftButton({ action, label, onClick, running }: SessionControlButton) {
283
+ const look =
284
+ action === "end"
285
+ ? { background: "#dc2626", color: "white" }
286
+ : action === "restart"
287
+ ? { background: "#1e293b", color: "#e2e8f0" }
288
+ : action === "toggle" && running
289
+ ? { background: "#334155", color: "#e2e8f0" }
290
+ : { background: "#2563eb", color: "white" };
291
+ return (
292
+ <button type="button" className={SHIFT_BUTTON} style={look} onClick={onClick}>
293
+ {label}
294
+ </button>
295
+ );
296
+ }
297
+
298
+ /**
299
+ * The shift controls: Start Dispatch before the shift, then Pause/Resume, New
300
+ * Conversation and End Shift. The row reads two one-field subscriptions through
301
+ * `useSessionControls`, so it re-renders when a flag flips and not at
302
+ * STT-partial rate the way the whole-snapshot `useSession()` it once held did.
321
303
  */
322
304
  function ShiftControls({ logged }: { logged: number }) {
323
- const { start, toggle, restart, end } = useSessionActions();
324
- const started = useSessionSelector((s) => s.started);
325
- const running = useSessionSelector((s) => s.running);
326
305
  return (
327
- <div
328
- className="flex items-center gap-2.5 px-4 py-3"
329
- style={{ background: "#111827", borderTop: "1px solid #1e293b" }}
306
+ <SessionControls
307
+ className="px-4 py-3 bg-[#111827] border-t border-[#1e293b]"
308
+ labels={{ start: "Start Dispatch", end: "End Shift" }}
309
+ renderButton={shiftButton}
330
310
  >
331
- {!started ? (
332
- <button
333
- type="button"
334
- className="px-4 py-2 border-none rounded-md font-mono text-xs font-semibold uppercase tracking-wider cursor-pointer text-white"
335
- style={{ background: "#2563eb" }}
336
- onClick={() => start()}
337
- >
338
- Start Dispatch
339
- </button>
340
- ) : (
341
- <>
342
- <button
343
- type="button"
344
- className="px-4 py-2 border-none rounded-md font-mono text-xs font-semibold uppercase tracking-wider cursor-pointer"
345
- style={{
346
- background: running ? "#334155" : "#2563eb",
347
- color: running ? "#e2e8f0" : "white",
348
- }}
349
- onClick={() => toggle()}
350
- >
351
- {running ? "Pause" : "Resume"}
352
- </button>
353
- {/* The one-click new conversation the default shell's
354
- `<Controls>` gives every other template — a custom
355
- `component:` renders no `<Controls>`, so a console like
356
- this one has to say it itself.
357
-
358
- end() then start(), NOT reset(): reset() clears the
359
- conversation and leaves the agent's own session-scoped
360
- state behind, so the next tool call would repopulate the
361
- shift that was just abandoned. end() drops the resume
362
- identity, so the redial is a brand-new session (fresh
363
- incident board, greeting included), and start() puts the
364
- console straight back on the call rather than at the
365
- "Start Dispatch" screen. */}
366
- <button
367
- type="button"
368
- className="px-4 py-2 border-none rounded-md font-mono text-xs font-semibold uppercase tracking-wider cursor-pointer"
369
- style={{ background: "#1e293b", color: "#e2e8f0" }}
370
- onClick={restart}
371
- >
372
- New Conversation
373
- </button>
374
- {/* end() hangs up and flips `started` back, so the UI
375
- returns to "Start Dispatch" and the next start is a
376
- brand-new shift (fresh incident board, greeting
377
- included). reset() would keep the call live — the
378
- buttons never toggle back. */}
379
- <button
380
- type="button"
381
- className="px-4 py-2 border-none rounded-md font-mono text-xs font-semibold uppercase tracking-wider cursor-pointer text-white"
382
- style={{ background: "#dc2626" }}
383
- onClick={() => end()}
384
- >
385
- End Shift
386
- </button>
387
- </>
388
- )}
389
311
  <div className="flex-1" />
390
312
  <span className="text-[10px]" style={{ color: "#475569" }}>
391
313
  {logged} {plural(logged, "incident")} logged
392
314
  </span>
393
- </div>
315
+ </SessionControls>
394
316
  );
395
317
  }
396
318
 
@@ -440,12 +362,15 @@ function App() {
440
362
  SYSTEM ALERT:
441
363
  </span>
442
364
  <span
443
- className="px-3 py-1 rounded text-[11px] font-bold uppercase tracking-wider"
444
365
  style={{
445
366
  background: alertBg,
446
367
  color: alertTextColor,
447
- animation: alertLevel === "red" ? "dc-pulse 1s ease-in-out infinite" : "none",
448
368
  }}
369
+ // Tailwind's own opacity pulse rather than `aai-pulse`, which also
370
+ // SCALES — right for a dot, wrong for a badge carrying a word.
371
+ className={`px-3 py-1 rounded text-[11px] font-bold uppercase tracking-wider${
372
+ alertLevel === "red" ? " animate-pulse" : ""
373
+ }`}
449
374
  >
450
375
  {alertLevel.toUpperCase()}
451
376
  </span>
@@ -469,7 +394,7 @@ function App() {
469
394
 
470
395
  {/* Right: sidebar dashboard */}
471
396
  <div
472
- className="dc-sidebar overflow-y-auto p-4 flex flex-col gap-4"
397
+ className="aai-scroll overflow-y-auto p-4 flex flex-col gap-4"
473
398
  style={{ background: "#111827" }}
474
399
  >
475
400
  <Panel title="Operations Summary">
@@ -0,0 +1,48 @@
1
+ import type { SessionEventHandlers } from "@alexkroman1/aai";
2
+ import { callInHand, dispatchSlot, logEvent } from "./shared.ts";
3
+
4
+ /**
5
+ * The one thing that happens on a 911 call which no tool can write down: the
6
+ * caller stops being there.
7
+ *
8
+ * Every line on an incident's timeline so far was written by a tool, so the
9
+ * board has nothing to say about the outcome that involves no tool at all — the
10
+ * line going dead. It arrives as a SESSION EVENT, and `agent({ events })` is
11
+ * how an agent observes its own stream.
12
+ *
13
+ * **The dialog deliberately does NOT move on it, and that is the difference
14
+ * between this desk and a phone desk.** `retail` and `roadside-assist` both
15
+ * carry `"@session.timed-out"` into a `final` state, because there the caller
16
+ * IS the conversation and a hang-up ends it. Here the caller is one input to a
17
+ * shift: units are rolling, the board is live, and the dispatcher goes on
18
+ * working every incident on it. So a hang-up is a FACT ABOUT ONE INCIDENT,
19
+ * recorded where the rest of that incident's history is, and `callFlow` stays
20
+ * exactly where it was.
21
+ *
22
+ * Which incident is {@link callInHand}'s question, and it is the same question
23
+ * the flow's position answers — see its doc. On a shift with nothing open there
24
+ * is nothing to write and nothing is written; a dropped call before the first
25
+ * `incident_create` left no record to annotate.
26
+ *
27
+ * Three properties of a handler this file depends on, all the SDK's: a handler
28
+ * is OBSERVE-ONLY (nothing here can make the desk say anything — a dispatcher
29
+ * finding out is the timeline's job), a throw in one is non-fatal, and delivery
30
+ * is at-least-once. The last one is why the line is worth checking against:
31
+ * a duplicated timeline entry is a cosmetic repeat, not a duplicated truck.
32
+ */
33
+ export const DISPATCH_EVENTS: SessionEventHandlers = {
34
+ "session.timed-out": (_event, ctx) => {
35
+ // A `SessionEventContext` is a `SlotHolder`, which is all a slot write
36
+ // needs — and all it is: there is no `generate`, no `send`, and no way for
37
+ // this to reach the caller who has just gone.
38
+ dispatchSlot.update(ctx, (state) => {
39
+ const incident = callInHand(state);
40
+ if (incident === undefined) return;
41
+ logEvent(
42
+ incident,
43
+ "CALLER LOST — line dropped or went silent. Units stay committed; " +
44
+ "attempt callback on the number on file.",
45
+ );
46
+ });
47
+ },
48
+ };
@@ -263,7 +263,7 @@ export const dashboardProjection = dispatchSlot.projection(dashboardView);
263
263
  * `as const` is what keeps the `on` keys literal, so `DialogEvent` synthesizes
264
264
  * the event union from them and a misspelled `send` is a compile error.
265
265
  */
266
- const callSpec = {
266
+ export const callSpec = {
267
267
  initial: "standby",
268
268
  states: {
269
269
  standby: {
@@ -310,6 +310,13 @@ const callSpec = {
310
310
  * about the conversation and the board is many facts about the world. One tool
311
311
  * call moves both — every converted tool opens `dispatchSlot.update` inside its
312
312
  * `execute` and lets the flow's own `send` follow it.
313
+ *
314
+ * **It is DECLARED on the agent** (`dialogs: [callFlow]`), which is what puts
315
+ * the active state's `instruction` in front of the model on every turn rather
316
+ * than only on the turns that happen to call a gated tool. Every sentence in
317
+ * the states below is written to be read that way; without the declaration the
318
+ * gate still holds and the instruction reaches nobody on a turn the dispatcher
319
+ * spends talking.
313
320
  */
314
321
  export const callFlow = dialog("call", callSpec);
315
322
 
@@ -370,6 +377,40 @@ export function findIncident<I extends DeepReadonly<Incident>>(
370
377
  return state.incidents[incidentId] ?? { error: `Incident ${incidentId} not found` };
371
378
  }
372
379
 
380
+ /**
381
+ * The incident the dispatcher is working, or `undefined` on a shift with
382
+ * nothing open.
383
+ *
384
+ * This is {@link callFlow}'s own reading of the board, expressed over the data:
385
+ * `working.monitoring` means "the incident this dispatcher LAST TOUCHED has
386
+ * units on it", and every write goes through {@link logEvent}, which touches
387
+ * `updatedAt`. So the most recently updated OPEN incident is the one the
388
+ * position is about. A resolved incident is never it — its caller is off the
389
+ * line and its units have been released.
390
+ *
391
+ * Why a function rather than an `Incident.id` field on the board: a stored
392
+ * "current" pointer is a second copy of a fact `updatedAt` already carries, and
393
+ * the two disagree the first time a tool forgets to update it.
394
+ *
395
+ * Generic for the same reason {@link findIncident} is — one lookup serves a
396
+ * mutable draft and a frozen read alike.
397
+ *
398
+ * `updatedAt` is `Date.now()`, so two incidents touched inside one millisecond
399
+ * tie; `>=` breaks that toward the one enumerated LAST, which for an insertion-
400
+ * ordered record is the most recently logged. Real calls are seconds apart and
401
+ * the tie only shows up in a test that logs two incidents in a row.
402
+ */
403
+ export function callInHand<I extends DeepReadonly<Incident>>(state: {
404
+ readonly incidents: { readonly [id: string]: I };
405
+ }): I | undefined {
406
+ let latest: I | undefined;
407
+ for (const inc of Object.values(state.incidents)) {
408
+ if (inc.status === "resolved") continue;
409
+ if (latest === undefined || inc.updatedAt >= latest.updatedAt) latest = inc;
410
+ }
411
+ return latest;
412
+ }
413
+
373
414
  /** Append a timeline entry and touch `updatedAt`, holding
374
415
  * {@link MAX_TIMELINE_ENTRIES}. Capped on APPEND rather than swept later, so
375
416
  * a single long-running incident cannot outgrow the payload between sweeps. */
@@ -1,3 +1,4 @@
1
+ import { plural } from "@alexkroman1/aai/utils";
1
2
  import { z } from "zod";
2
3
  import {
3
4
  calculateTriageScore,
@@ -87,8 +88,8 @@ export default dispatchSlot.updateTool({
87
88
  recommendedResources: recommended.map(resourceBrief),
88
89
  message:
89
90
  recSeverity === "critical"
90
- ? `PRIORITY ONE — ${id} created. Immediate dispatch recommended. ${protocols.length} protocol(s) applicable.`
91
- : `${id} created. Triage score ${triageScore}. ${recommended.length} resource(s) recommended.`,
91
+ ? `PRIORITY ONE — ${id} created. Immediate dispatch recommended. ${protocols.length} ${plural(protocols.length, "protocol")} applicable.`
92
+ : `${id} created. Triage score ${triageScore}. ${recommended.length} ${plural(recommended.length, "resource")} recommended.`,
92
93
  };
93
94
  },
94
95
  });
@@ -1,4 +1,5 @@
1
1
  import { isToolFailure } from "@alexkroman1/aai";
2
+ import { plural } from "@alexkroman1/aai/utils";
2
3
  import { z } from "zod";
3
4
  import {
4
5
  assertNotResolved,
@@ -89,7 +90,7 @@ export default callFlow.tool({
89
90
  callsign: r.callsign,
90
91
  type: r.type,
91
92
  })),
92
- message: `ESCALATION CONFIRMED — ${args.incidentId} now Level ${inc.escalationLevel}. ${additionalResources.length} additional resource(s) available for dispatch.`,
93
+ message: `ESCALATION CONFIRMED — ${args.incidentId} now Level ${inc.escalationLevel}. ${additionalResources.length} additional ${plural(additionalResources.length, "resource")} available for dispatch.`,
93
94
  };
94
95
  }),
95
96
  });
@@ -1,26 +1,48 @@
1
1
  import { dispatchSlot, incidentAgeMinutes, resourceBrief, resourceUtilization } from "../shared.ts";
2
2
 
3
+ /** Which `resourceSummary` counter a status belongs to — the two spellings differ. */
4
+ const COUNT_KEY = {
5
+ available: "available",
6
+ dispatched: "dispatched",
7
+ en_route: "enRoute",
8
+ on_scene: "onScene",
9
+ returning: "returning",
10
+ } as const;
11
+
3
12
  export default dispatchSlot.tool({
4
13
  description:
5
14
  "Get the full operational dashboard: alert level, resource utilization, active incidents, and available resources.",
6
15
  execute(_args, state) {
7
- const activeIncidents = Object.values(state.incidents)
8
- .filter((i) => i.status !== "resolved")
9
- .sort((a, b) => b.triageScore - a.triageScore);
10
-
11
- const resolvedCount = Object.values(state.incidents).filter(
12
- (i) => i.status === "resolved",
13
- ).length;
16
+ // The incidents, split in one pass rather than filtered twice over the same
17
+ // record: every incident is either active or resolved.
18
+ type Incident = (typeof state.incidents)[string];
19
+ const activeIncidents: Incident[] = [];
20
+ let resolvedCount = 0;
21
+ for (const incident of Object.values(state.incidents)) {
22
+ if (incident.status === "resolved") resolvedCount += 1;
23
+ else activeIncidents.push(incident);
24
+ }
25
+ activeIncidents.sort((a, b) => b.triageScore - a.triageScore);
14
26
 
27
+ // Likewise the resource breakdown: five `.filter().length` scans and a sixth
28
+ // for the briefs, all over the one list, become one walk of it.
15
29
  const resourceSummary = {
16
30
  total: state.resources.length,
17
- available: state.resources.filter((r) => r.status === "available").length,
18
- dispatched: state.resources.filter((r) => r.status === "dispatched").length,
19
- enRoute: state.resources.filter((r) => r.status === "en_route").length,
20
- onScene: state.resources.filter((r) => r.status === "on_scene").length,
21
- returning: state.resources.filter((r) => r.status === "returning").length,
31
+ available: 0,
32
+ dispatched: 0,
33
+ enRoute: 0,
34
+ onScene: 0,
35
+ returning: 0,
22
36
  };
37
+ const availableResources: ReturnType<typeof resourceBrief>[] = [];
38
+ for (const resource of state.resources) {
39
+ resourceSummary[COUNT_KEY[resource.status]] += 1;
40
+ if (resource.status === "available") availableResources.push(resourceBrief(resource));
41
+ }
23
42
 
43
+ // Still `resourceUtilization`, not a ratio derived from the counts above:
44
+ // that function is deliberately the ONE definition of the word, shared with
45
+ // the alert level, and a second one here is how the two come to disagree.
24
46
  const utilization = Math.round(resourceUtilization(state) * 100);
25
47
 
26
48
  return {
@@ -44,9 +66,7 @@ export default dispatchSlot.tool({
44
66
  ageMinutes: incidentAgeMinutes(i),
45
67
  casualties: i.casualties,
46
68
  })),
47
- availableResources: state.resources
48
- .filter((r) => r.status === "available")
49
- .map(resourceBrief),
69
+ availableResources,
50
70
  };
51
71
  },
52
72
  });