@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
@@ -0,0 +1,77 @@
1
+ import { errorMessage, isToolFailure, requireEnv, toolFailure } from "@alexkroman1/aai";
2
+ import { ChannelDeliveryError, sendToChannel } from "@alexkroman1/aai/channels";
3
+ import { z } from "zod";
4
+ import { briefingSlot } from "../shared.ts";
5
+ import { briefingChannel, briefingMessage, DESTINATION_ENV } from "../slack.ts";
6
+
7
+ /**
8
+ * Post the board to the desk's Slack channel, so the briefing outlives the
9
+ * call.
10
+ *
11
+ * **Read as a subagent template, this is the tool that does NOT delegate**, and
12
+ * that is why it is here. Everything the desk knows came back from a subagent
13
+ * with its own context window; what crossed into the conversation is one
14
+ * paragraph per angle, and those paragraphs are already on the slot. Sending
15
+ * them costs no model, no researcher and no second look at the web — the same
16
+ * argument `briefing_so_far` makes, one step further.
17
+ *
18
+ * **`slot.tool`, because it READS the board and writes nothing.** A `tool()`
19
+ * opening with `briefingSlot.get(ctx)` would say the same thing in code and
20
+ * nothing in the declaration; what a read is handed is deep-frozen, so a body
21
+ * that meant to mutate stops compiling here rather than failing at a caller.
22
+ *
23
+ * **The credential is `ctx.env`, through `requireEnv`, and it THROWS.** That is
24
+ * the one deliberate throw in this template. A missing key is not a refusal the
25
+ * desk can talk its way around and not something the caller did — it is a
26
+ * deploy nobody finished — so the SDK's own message names the variable and how
27
+ * to set it, and the runtime hands that to the model rather than letting the
28
+ * first property access surface as a `TypeError` the caller hears as an
29
+ * unexplained apology. Everything a call CAN recover from is a `ToolFailure`
30
+ * below.
31
+ */
32
+ export default briefingSlot.tool({
33
+ description:
34
+ "Send the briefing so far to the team's Slack channel. Use it when the caller " +
35
+ "asks for it in writing, or to have it passed on to someone who was not on the " +
36
+ "call. Tell them you are sending it before you call this.",
37
+ inputSchema: z.object({}),
38
+ async execute(_args, board, ctx) {
39
+ if (board.findings.length === 0) {
40
+ return toolFailure(
41
+ "There is nothing to send yet — research something first, then offer to send it.",
42
+ );
43
+ }
44
+
45
+ const destination = briefingChannel(requireEnv(ctx, DESTINATION_ENV));
46
+ if (isToolFailure(destination)) return destination;
47
+
48
+ try {
49
+ await sendToChannel(destination, briefingMessage(board));
50
+ } catch (err: unknown) {
51
+ // The channel has already classified the refusal, which is the whole
52
+ // reason this is not a `fetch` and an `if (!res.ok)`: `retryable` is the
53
+ // 4xx/5xx split, and its message carries Slack's own advice for the half
54
+ // that will answer the same way forever. What is left for the desk is
55
+ // what to SAY, and the two are opposite — offering to try again after a
56
+ // revoked webhook is a promise it cannot keep.
57
+ if (err instanceof ChannelDeliveryError) {
58
+ return toolFailure(
59
+ err.retryable
60
+ ? `Slack did not take the briefing: ${err.message} Tell the caller it has not ` +
61
+ "sent yet and offer to try again in a moment."
62
+ : `Slack refused the briefing: ${err.message} Tell the caller it has not sent ` +
63
+ "and that trying again will not help — someone has to fix the destination.",
64
+ );
65
+ }
66
+ return toolFailure(`The briefing did not send: ${errorMessage(err)}`);
67
+ }
68
+
69
+ return {
70
+ topic: board.topic,
71
+ sent: board.findings.length,
72
+ message:
73
+ "Say it has gone to the channel and how many angles went with it. Do not read " +
74
+ "the briefing back out — they have it in writing now.",
75
+ };
76
+ },
77
+ });
@@ -1,6 +1,20 @@
1
- import { errorMessage, omitUndefined, tool, toolFailure } from "@alexkroman1/aai";
1
+ import {
2
+ type DeepReadonly,
3
+ errorMessage,
4
+ isToolFailure,
5
+ omitUndefined,
6
+ type TypedDelegateResult,
7
+ toolFailure,
8
+ } from "@alexkroman1/aai";
2
9
  import { z } from "zod";
3
- import { briefingSlot, countWork, factChecker, findByAngle } from "../shared.ts";
10
+ import {
11
+ briefingSlot,
12
+ countWork,
13
+ type Finding,
14
+ factChecker,
15
+ findByAngle,
16
+ type Verdict,
17
+ } from "../shared.ts";
4
18
 
5
19
  /**
6
20
  * Check one sentence against the web, on the narrower of the desk's two
@@ -17,9 +31,11 @@ import { briefingSlot, countWork, factChecker, findByAngle } from "../shared.ts"
17
31
  * **The claim may be quoted from the board.** The caller says "check the second
18
32
  * thing you told me", so `about` names an angle and the claim is read out of
19
33
  * the slot — a subagent has not heard the call, and handing it "the second
20
- * thing" as its task would get a confident answer about nothing.
34
+ * thing" as its task would get a confident answer about nothing. The board
35
+ * arrives through `briefingSlot.tool` rather than a `get` inside the body,
36
+ * which is what declares that this tool reads it and never writes.
21
37
  */
22
- export default tool({
38
+ export default briefingSlot.tool({
23
39
  description:
24
40
  "Check one specific factual claim against the web. Use it when the caller " +
25
41
  "pushes back on something, or asks whether a finding is right. Pass the " +
@@ -38,15 +54,26 @@ export default tool({
38
54
  "something already on the board",
39
55
  ),
40
56
  }),
41
- async execute(args, ctx) {
57
+ async execute(args, board, ctx) {
42
58
  const claim = args.claim.trim();
43
59
  if (claim === "") return toolFailure("Nothing to check — say the claim in a full sentence.");
44
60
 
45
- const board = briefingSlot.get(ctx);
46
- const source = args.about ? findByAngle(board, args.about) : undefined;
61
+ // The caller pointed at something on the board, so an AMBIGUOUS pointer is
62
+ // returned to the model rather than resolved by board order. Checking the
63
+ // claim against the wrong finding is worse than spending a turn asking
64
+ // which — the verdict would come back about a different conversation. A
65
+ // caller who named no angle is the `undefined` case and is fine.
66
+ let source: DeepReadonly<Finding> | undefined;
67
+ if (args.about !== undefined) {
68
+ const found = findByAngle(board, args.about);
69
+ if (isToolFailure(found)) return found;
70
+ source = found;
71
+ }
47
72
 
48
- let verdict: string;
73
+ let verdict: Verdict | undefined;
74
+ let detail: string;
49
75
  let searches: number;
76
+ let unusable: string | undefined;
50
77
  try {
51
78
  // What the checker gets of the conversation, and no more: the finding the
52
79
  // claim came out of, so it can tell a misquote from a disagreement.
@@ -54,24 +81,43 @@ export default tool({
54
81
  // repo's one spelling for an optional field, and the shape its own
55
82
  // `guard-invariants` rule 22 counts as debt.
56
83
  const context = source ? `The desk told the caller: ${source.summary}` : undefined;
57
- const result = await ctx.delegate(factChecker, {
84
+ // ANNOTATED, as `researchAngle`'s plain `DelegateResult` is, and the pair
85
+ // is the lesson: `factChecker` declares a `schema`, so `ctx.delegate`
86
+ // takes its typed overload and the reply carries a parsed `object`. A
87
+ // schema removed upstream lands here as a type error rather than as an
88
+ // `.object` that quietly went `unknown`.
89
+ const result: TypedDelegateResult<Verdict> = await ctx.delegate(factChecker, {
58
90
  task: claim,
59
91
  ...omitUndefined({ context }),
60
92
  });
61
- verdict = result.text;
62
93
  searches = countWork(result.toolCalls).searches;
94
+ // `object` is the parsed verdict, present exactly when the run was
95
+ // accepted. The checker's schema sends a mis-shaped answer back; exhausting
96
+ // that budget is not a failure — there IS an answer, and on a live call the
97
+ // desk is better off reading a hedged one and saying it is hedged than
98
+ // apologizing for the tooling. What it must not do is treat it as a verdict
99
+ // it can correct itself from, which is what `unusable` says.
100
+ unusable = result.accepted ? undefined : result.complaint;
101
+ verdict = result.accepted ? result.object : undefined;
102
+ detail = verdict?.detail ?? result.text;
63
103
  } catch (err: unknown) {
64
104
  return toolFailure(`The check did not come back: ${errorMessage(err)}`);
65
105
  }
66
106
 
67
107
  return {
68
108
  claim,
69
- verdict,
109
+ // The word the desk BRANCHES on, as a word — not a sentence it has to
110
+ // read a word out of.
111
+ verdict: verdict?.verdict ?? null,
112
+ detail,
70
113
  searches,
71
114
  checkedAgainst: source?.angle ?? null,
72
- message:
73
- "Say the verdict plainly, in the caller's words. If it is contradicted, " +
74
- "correct what you told them earlier rather than defending it.",
115
+ ...omitUndefined({ unusable }),
116
+ message: unusable
117
+ ? "The checker never gave a clear verdict. Tell the caller it is unresolved " +
118
+ "and offer to research it properly — do not present this as confirmation."
119
+ : "Say the verdict plainly, in the caller's words. If it is contradicted, " +
120
+ "correct what you told them earlier rather than defending it.",
75
121
  };
76
122
  },
77
123
  });
@@ -417,6 +417,11 @@ describeWorkflowEvalWithFfmpeg(
417
417
  // The RUN's own clock, from two journaled steps rather than a body-level
418
418
  // `Date.now()` a replay would re-read.
419
419
  expect(output.elapsedMs).toBeGreaterThanOrEqual(0);
420
+ // And the DECODER's share of it. Only a case that really spawns ffmpeg can
421
+ // claim this is a measurement rather than a zero: `runFfmpeg` times each
422
+ // invocation, and three of them ran here.
423
+ expect(output.ffmpegMs).toBeGreaterThan(0);
424
+ expect(output.ffmpegMs).toBeLessThanOrEqual(output.elapsedMs);
420
425
  });
421
426
 
422
427
  test(
@@ -884,10 +884,11 @@ describe("the body's step policy", () => {
884
884
  bytes: 60 * BYTES_PER_SECOND,
885
885
  silences: pauses(10, 20, 30),
886
886
  loudness: MEASURED,
887
+ ffmpegMs: 1200,
887
888
  },
888
889
  transcribeSegment: { index: 0, text: "hello" },
889
890
  summarize: { headline: "H", risks: [], actions: [], spoken: "S." },
890
- narrate: { audio: "upl_wav", durationMs: 500, bytes: 32 },
891
+ narrate: { audio: "upl_wav", durationMs: 500, bytes: 32, ffmpegMs: 300 },
891
892
  },
892
893
  });
893
894
 
@@ -928,6 +929,10 @@ describe("the body's step policy", () => {
928
929
  const output = await auditFlow({ recording: UPLOAD_ID }, ctx);
929
930
 
930
931
  expect(output.elapsedMs).toBe(3000);
932
+ // And the ffmpeg time is SUMMED from the two journaled step results rather
933
+ // than measured again — which is what makes a replay report what the passes
934
+ // really cost instead of zero for work it did not redo.
935
+ expect(output.ffmpegMs).toBe(1500);
931
936
  // And the clock is no longer a step, which is the other half of the claim: a
932
937
  // name here would mean the migration left one behind.
933
938
  expect(ctx.steps.map((step) => step.name)).not.toContain("clockStart");
@@ -86,33 +86,23 @@
86
86
  */
87
87
 
88
88
  import { workflow, workflowApp } from "@alexkroman1/aai";
89
- import { ASSEMBLYAI_TTS_DEFAULT_VOICE, ASSEMBLYAI_TTS_VOICES } from "@alexkroman1/aai/tts";
89
+ import { ttsVoiceIds } from "@alexkroman1/aai/tts";
90
90
  import type { WorkflowDef } from "@alexkroman1/aai/workflow-api";
91
91
  import { z } from "zod";
92
92
  import { auditFlow, type CallAudit } from "./workflows/audit.ts";
93
93
 
94
94
  /**
95
- * The voices the form offers.
95
+ * The voices the form offers, as the tuple `z.enum` takes.
96
96
  *
97
97
  * READ from the SDK's catalog rather than listed, because a wrong voice id is a
98
- * SILENT failure — it is a free-form string the service rejects in band after the
99
- * socket is open, so the synthesis simply produces nothing. Narrowed to the English
100
- * ones because the audit is written in the transcript's language and the prompt does
101
- * not translate; every voice in the catalog speaks exactly one.
98
+ * SILENT failure — it is a free-form string the service rejects in band after
99
+ * the socket is open, so the synthesis simply produces nothing. Narrowed to the
100
+ * English ones because the audit is written in the transcript's language and
101
+ * the prompt does not translate; every voice in the catalog speaks exactly one.
102
+ * `ttsVoiceIds` owns the derivation, including the fallback to the SDK's own
103
+ * default voice should the filter ever match nothing.
102
104
  */
103
- const VOICES = Object.entries(ASSEMBLYAI_TTS_VOICES)
104
- .filter(([, spec]) => spec.language === "en")
105
- .map(([id]) => id);
106
-
107
- /**
108
- * The same list as a TUPLE, which is what `z.enum` takes.
109
- *
110
- * Destructured rather than cast: a `.map` produces an array, and
111
- * `as [string, ...string[]]` would be a template teaching a cast. The default covers
112
- * the empty case honestly — a catalog with no English voice falls back to the SDK's
113
- * own default rather than rendering a picker with no options.
114
- */
115
- const [FIRST_VOICE = ASSEMBLYAI_TTS_DEFAULT_VOICE, ...OTHER_VOICES] = VOICES;
105
+ const VOICES = ttsVoiceIds("en");
116
106
 
117
107
  /**
118
108
  * The run input, as its own const.
@@ -134,10 +124,7 @@ const auditInput = z.object({
134
124
  // An enum, so the form renders a SELECT rather than a text box — which is the
135
125
  // whole reason the list is derived above rather than left free-form. Optional,
136
126
  // so the SDK's own default voice applies when nobody chooses.
137
- voice: z
138
- .enum([FIRST_VOICE, ...OTHER_VOICES])
139
- .optional()
140
- .describe("Voice to read the audit in"),
127
+ voice: z.enum(VOICES).optional().describe("Voice to read the audit in"),
141
128
  });
142
129
 
143
130
  /**
@@ -76,6 +76,7 @@ import "@alexkroman1/aai-ui/styles.css";
76
76
  // already declares.
77
77
  import { formatBytes, formatDuration } from "@alexkroman1/aai/utils";
78
78
  import {
79
+ AudioResult,
79
80
  BulletList,
80
81
  createWorkflowApi,
81
82
  Facts,
@@ -86,7 +87,9 @@ import {
86
87
  useDownloadUrl,
87
88
  useWorkflowSubmit,
88
89
  WorkflowFields,
90
+ WorkflowPendingNote,
89
91
  WorkflowProgress,
92
+ WorkflowRunError,
90
93
  } from "@alexkroman1/aai-ui";
91
94
  import type { audit } from "./agent.ts";
92
95
 
@@ -107,20 +110,6 @@ const WORKFLOW = "audit";
107
110
  */
108
111
  const api = createWorkflowApi();
109
112
 
110
- /**
111
- * What the desk says while a run is in flight — three situations, one line
112
- * each.
113
- *
114
- * The reload case gets its own words deliberately: somebody who did not press
115
- * the button is owed an explanation for an audit appearing in front of them,
116
- * and it is the line that keeps them from uploading the call again.
117
- */
118
- function pendingNote(startedHere: boolean, found: boolean): string {
119
- if (startedHere) return "Reloading is safe — this page will find the audit again.";
120
- if (!found) return "Looking for an audit this tab started earlier…";
121
- return "Still auditing a call this tab uploaded earlier — no need to send it again.";
122
- }
123
-
124
113
  /** One labelled number in the pipeline panel. */
125
114
  function Stat({ label, value }: { label: string; value: string }) {
126
115
  return (
@@ -136,8 +125,8 @@ export function App() {
136
125
  // `run.output` instead of `unknown`. The reload — both halves of it — is the
137
126
  // hook's own doing; see the module doc for why the key it mints is the one
138
127
  // this desk wants.
139
- const { submitForm, run, pending, upload, pauseUpload, resumeUpload, error, startedHere } =
140
- useWorkflowSubmit<typeof audit>(WORKFLOW, { api });
128
+ const submission = useWorkflowSubmit<typeof audit>(WORKFLOW, { api });
129
+ const { submitForm, run, pending, upload, pauseUpload, resumeUpload, error } = submission;
141
130
  const output = run?.status === "completed" ? run.output : undefined;
142
131
  // `useDownloadUrl` is the SDK's: the byte route takes the agent's bearer, so the
143
132
  // bytes have to be FETCHED and handed to the element as an object URL — and the
@@ -165,9 +154,7 @@ export function App() {
165
154
  {/* `pending` covers the RUN rather than the request, and on a reload it is
166
155
  also true while the run is being looked up by key — the stretch where
167
156
  an empty form would invite a second 700 MB upload of the same call. */}
168
- {pending && (
169
- <p className="text-sm opacity-70">{pendingNote(startedHere, run !== undefined)}</p>
170
- )}
157
+ <WorkflowPendingNote submission={submission} subject="audit" />
171
158
 
172
159
  {/* The upload is its own wait, and the one nothing else can describe: the run
173
160
  does not EXIST until the bytes are in, so there is no run id and nothing
@@ -179,13 +166,9 @@ export function App() {
179
166
  measured, how many pauses were found. */}
180
167
  <WorkflowProgress runId={run?.runId} api={api} />
181
168
 
182
- {/* `role="alert"`, the same contract `<Form>` gives the submit error: this
183
- is the outcome the reader waited minutes for. */}
184
- {run?.status === "failed" && (
185
- <p role="alert" className="text-red-600">
186
- That one failed: {run.error}
187
- </p>
188
- )}
169
+ {/* Announced, the same contract `<Form>` gives the submit error: this is
170
+ the outcome the reader waited minutes for. */}
171
+ <WorkflowRunError run={run} />
189
172
 
190
173
  {output !== undefined && (
191
174
  <article className="flex flex-col gap-6">
@@ -209,6 +192,11 @@ export function App() {
209
192
  value={output.blindCuts === 0 ? "none" : String(output.blindCuts)}
210
193
  />
211
194
  <Stat label="Run time" value={formatDuration(output.elapsedMs)} />
195
+ {/* Beside the run time rather than inside it: the run is mostly the
196
+ fan-out waiting on a provider, and this is what the DECODER cost.
197
+ It is the one number that says whether normalizing first paid for
198
+ itself, which is this template's whole argument. */}
199
+ <Stat label="ffmpeg time" value={formatDuration(output.ffmpegMs)} />
212
200
  </dl>
213
201
 
214
202
  {/* Either list can come back empty — see `risks` in the schema — and
@@ -217,36 +205,23 @@ export function App() {
217
205
  <BulletList title="Risks" items={output.risks} />
218
206
  <BulletList title="Actions" items={output.actions} />
219
207
 
220
- <section className="flex flex-col gap-2">
221
- <h3 className="text-sm font-medium opacity-70">
222
- Read aloud · {formatDuration(output.audioDurationMs)} ·{" "}
223
- {formatBytes(output.audioBytes)}
224
- </h3>
225
- {audio.pending && <p className="text-sm opacity-70">Fetching the audio…</p>}
226
- {audio.error !== undefined && (
227
- <p role="alert" className="text-red-600">
228
- Could not load the audio: {audio.error}
229
- </p>
230
- )}
231
- {audio.url !== undefined && (
232
- <>
233
- {/* No `<track>`, and that is a judgement rather than an
234
- oversight: the spoken text is rendered in full immediately
235
- below this player, which is the same information a caption
236
- track would carry. `spoken-summary` serves a one-cue WebVTT
237
- data URL instead — worth reading for how, if a real track is
238
- what a page needs. */}
239
- <audio aria-label="Audit read aloud" controls src={audio.url} className="w-full" />
240
- {/* `download` works on an object URL because the bytes are already in
241
- the tab; it is the href that could not carry the agent's bearer,
242
- not the attribute. */}
243
- <a href={audio.url} download="audit.mp3" className="text-sm underline">
244
- Download audit.mp3
245
- </a>
246
- </>
247
- )}
208
+ {/* The SDK's player over the hook's result: the pending line, the
209
+ announced error, the `<audio>` and the download link (which works on
210
+ an object URL because the bytes are already in the tab; it was the
211
+ href that could not carry the agent's bearer, not the attribute).
212
+ No `captions`, and that is a judgement rather than an oversight:
213
+ the spoken text is rendered in full immediately below the player,
214
+ which is the same information a caption track would carry.
215
+ `spoken-summary` passes one instead — worth reading, if a real
216
+ track is what a page needs. */}
217
+ <AudioResult
218
+ download={audio}
219
+ filename="audit.mp3"
220
+ label="Audit read aloud"
221
+ heading={`Read aloud · ${formatDuration(output.audioDurationMs)} · ${formatBytes(output.audioBytes)}`}
222
+ >
248
223
  <p className="text-sm opacity-70">{output.spoken}</p>
249
- </section>
224
+ </AudioResult>
250
225
 
251
226
  <details className="text-sm">
252
227
  <summary className="cursor-pointer opacity-70">Transcript</summary>
@@ -0,0 +1,233 @@
1
+ // Copyright 2026 the AAI authors. MIT license.
2
+ /**
3
+ * The three things this desk REFUSES, and what it reports while it works.
4
+ *
5
+ * `agent.test.ts` covers what the desk decides — every ffmpeg argv, both
6
+ * analysis parsers, and where `planSegments` cuts. This file covers the checks
7
+ * standing in front of those decisions, and they are together because they share
8
+ * one property: **each one turns a plausible wrong ANSWER into a loud failure.**
9
+ * That is the failure shape this template's own module docs keep returning to —
10
+ * a truncated upload levelled as though it were the whole call, a plan
11
+ * describing audio past the end of a file, a video with no soundtrack decoded at
12
+ * length before ffmpeg complains about a filter graph. None of them throws on
13
+ * its own; every one of them produces a transcript that reads as complete.
14
+ *
15
+ * They are also the seam where a template is at its most tempting to hand-roll,
16
+ * so what each spec really pins is that the SDK's own verdict is READ rather
17
+ * than re-derived: `stepRequireCompleteUpload` already decided that a
18
+ * still-arriving upload is terminal, and `throwStepError` is the line that makes
19
+ * the engine act on it.
20
+ *
21
+ * Its own file rather than more of `agent.test.ts`, which is already the longest
22
+ * spec in `templates/` — the split is by subject, and `health-assistant` and
23
+ * `pipeline-simple` each carry a second spec for the same reason. It sits
24
+ * beside `agent.ts` rather than under `workflows/` because the package's vitest
25
+ * `include` reaches one level into `templates/`, so a spec any deeper would
26
+ * never run.
27
+ */
28
+
29
+ import type { MediaInfo } from "@alexkroman1/aai/ffmpeg";
30
+ import type { StepInfo, UploadSlice } from "@alexkroman1/aai/step";
31
+ import { FatalError } from "@alexkroman1/aai/step-errors";
32
+ import { installStubReporter, installStubUploads } from "@alexkroman1/aai/testing/vitest";
33
+ import { omitUndefined } from "@alexkroman1/aai/utils";
34
+ import { beforeEach, describe, expect, test, vi } from "vitest";
35
+ import {
36
+ attemptSuffix,
37
+ segmentShortfall,
38
+ segmentWindow,
39
+ transcribeSegment,
40
+ } from "./workflows/audit.ts";
41
+ import { ingestRecording } from "./workflows/ingest.ts";
42
+ import {
43
+ BYTES_PER_SECOND,
44
+ MediaAnalysisError,
45
+ requireAudioStream,
46
+ TEMP_DIR,
47
+ totalFfmpegMs,
48
+ } from "./workflows/media.ts";
49
+
50
+ /** The id every spec below uploads under. */
51
+ const UPLOAD_ID = "upl_test";
52
+
53
+ /** One segment of the plan: the first second of the stored PCM. */
54
+ const SEGMENT = {
55
+ index: 0,
56
+ startByte: 0,
57
+ endByte: BYTES_PER_SECOND,
58
+ startMs: 0,
59
+ endMs: 1000,
60
+ cutInSpeech: false,
61
+ };
62
+
63
+ /** What `stepReadUpload` answers, with only the field the check reads. */
64
+ function slice(byteLength: number): Pick<UploadSlice, "bytes"> {
65
+ return { bytes: new Uint8Array(byteLength) };
66
+ }
67
+
68
+ /** What ffprobe made of a file, as `probeMedia` reports it. */
69
+ function probed(...kinds: string[]): MediaInfo {
70
+ const streams = kinds.map((kind, index) => ({ index, kind, codec: `${kind}-codec` }));
71
+ const audio = streams.find((stream) => stream.kind === "audio");
72
+ // Spread rather than `audio: …`: the repo compiles with
73
+ // `exactOptionalPropertyTypes`, so an OPTIONAL property may be absent but may
74
+ // not be present-and-undefined — which is exactly the shape `probeMedia`
75
+ // returns for a file with no audio track.
76
+ return { format: "mov,mp4,m4a", streams, ...omitUndefined({ audio }), raw: {} };
77
+ }
78
+
79
+ beforeEach(() => {
80
+ vi.stubEnv("ASSEMBLYAI_API_KEY", "test-key");
81
+ });
82
+
83
+ describe("an upload that is still arriving", () => {
84
+ test("fails the run TERMINALLY rather than re-asking six times", async () => {
85
+ // `UploadInfo.size` is the readable PREFIX, so a run started before the bytes
86
+ // are in would level part of a call and report success. The SDK already
87
+ // refuses that and already carries the verdict (`retryable: false`) — but a
88
+ // carried verdict is only read where a caller asks, and this call site sets
89
+ // `maxAttempts: 6`. Without `.catch(throwStepError)` in `ingest.ts` the engine
90
+ // would spend all six inside a millisecond on bytes that arrive on their own
91
+ // schedule.
92
+ installStubUploads({
93
+ [UPLOAD_ID]: { bytes: new Uint8Array(2048), name: "call.m4a", complete: false },
94
+ });
95
+ installStubReporter();
96
+
97
+ await expect(ingestRecording(UPLOAD_ID)).rejects.toBeInstanceOf(FatalError);
98
+ });
99
+
100
+ test("keeps the SDK's own sentence, which is the one naming the remedy", async () => {
101
+ // `throwStepError` replaces no message, deliberately: what the caller has
102
+ // otherwise is "the step failed", where the SDK's refusal says how many bytes
103
+ // landed and what to do about it.
104
+ installStubUploads({
105
+ [UPLOAD_ID]: { bytes: new Uint8Array(2048), name: "call.m4a", complete: false },
106
+ });
107
+ installStubReporter();
108
+
109
+ await expect(ingestRecording(UPLOAD_ID)).rejects.toThrow(/still arriving/);
110
+ });
111
+ });
112
+
113
+ describe("a file with no audio track", () => {
114
+ test("is refused, and the complaint names what ffprobe DID find", () => {
115
+ // The one file the form's "anything ffmpeg can read" honestly admits and this
116
+ // desk cannot use. Naming the streams is what tells somebody they uploaded
117
+ // the silent screen recording rather than the meeting.
118
+ expect(() => requireAudioStream(probed("video"))).toThrow(MediaAnalysisError);
119
+ expect(() => requireAudioStream(probed("video"))).toThrow(/no audio track/);
120
+ expect(() => requireAudioStream(probed("video", "subtitle"))).toThrow(/video, subtitle/);
121
+ });
122
+
123
+ test("a file ffprobe found nothing in at all still gets a sentence", () => {
124
+ // `streams: []` is what a PDF dragged into the picker looks like, and
125
+ // `found.join(", ")` on an empty list would have produced "ffprobe found .".
126
+ expect(() => requireAudioStream(probed())).toThrow(/no streams at all/);
127
+ });
128
+
129
+ test("a recording WITH sound passes the track through, codec and all", () => {
130
+ // The happy path is the other half of the claim: the codec now comes off the
131
+ // track rather than off an optional chain, so `unknown` means "ffprobe named
132
+ // no codec" and no longer doubles as "there was nothing to name".
133
+ expect(requireAudioStream(probed("video", "audio")).codec).toBe("audio-codec");
134
+ });
135
+ });
136
+
137
+ describe("a stored file smaller than the plan", () => {
138
+ test("a whole window is no shortfall", () => {
139
+ expect(segmentShortfall(SEGMENT, slice(BYTES_PER_SECOND))).toBe(0);
140
+ });
141
+
142
+ test("a CLAMPED read is counted, because nothing else would notice it", () => {
143
+ // The twelve-byte bug `durationSeconds` documents, as a number: the store
144
+ // clamps a window to what it holds, so a plan describing audio past the end of
145
+ // the file produced a short slice, a shorter WAV, and a transcript missing its
146
+ // tail with nothing anywhere saying so.
147
+ expect(segmentShortfall(SEGMENT, slice(BYTES_PER_SECOND - 12))).toBe(12);
148
+ });
149
+
150
+ test("a read LONGER than asked for is not a negative shortfall", () => {
151
+ // Cannot happen through the store, and clamping at zero is what keeps the
152
+ // caller's `> 0` test honest if it ever did.
153
+ expect(segmentShortfall(SEGMENT, slice(BYTES_PER_SECOND + 12))).toBe(0);
154
+ });
155
+
156
+ test("the STEP refuses rather than transcribing a hole", async () => {
157
+ // The check driven where it lives: the store holds one second of PCM and the
158
+ // plan asks for one second and twelve bytes, exactly as the rounding bug
159
+ // produced. `stepReadUpload` clamps, so nothing throws on its own — the run
160
+ // used to transcribe the short slice and report success.
161
+ installStubUploads({
162
+ [UPLOAD_ID]: {
163
+ bytes: new Uint8Array(BYTES_PER_SECOND),
164
+ name: "call.pcm",
165
+ type: "application/octet-stream",
166
+ },
167
+ });
168
+ installStubReporter();
169
+ // No transcription stub, which is the other half of the claim: the step must
170
+ // fail BEFORE it spends a request on audio it knows is incomplete.
171
+ const overrun = { ...SEGMENT, endByte: BYTES_PER_SECOND + 12 };
172
+
173
+ await expect(transcribeSegment(UPLOAD_ID, overrun)).rejects.toBeInstanceOf(FatalError);
174
+ await expect(transcribeSegment(UPLOAD_ID, overrun)).rejects.toThrow(/12 byte\(s\) short/);
175
+ });
176
+
177
+ test("the window is the plan's own half-open pair, unmodified", () => {
178
+ // A rename rather than arithmetic: the store owns the conversion to HTTP's
179
+ // inclusive range, so a `- 1` here would silently drop the last sample frame
180
+ // of every segment.
181
+ expect(segmentWindow(SEGMENT)).toEqual({ start: 0, end: BYTES_PER_SECOND });
182
+ });
183
+ });
184
+
185
+ describe("what the run reports about ffmpeg itself", () => {
186
+ test("sums the passes and rounds, because a page renders it", () => {
187
+ // `runFfmpeg` measures with `performance.now()`, so each duration is a float
188
+ // and a page would otherwise print 1502.3999999999999 ms.
189
+ expect(totalFfmpegMs({ durationMs: 1200.4 }, { durationMs: 301.9 })).toBe(1502);
190
+ });
191
+
192
+ test("no passes is zero rather than NaN", () => {
193
+ expect(totalFfmpegMs()).toBe(0);
194
+ });
195
+
196
+ test("both steps materialize under ONE prefix, which is what the leak spec matches", () => {
197
+ // Two files write temp directories — the ingest and the narration — and each
198
+ // used to name the prefix itself. The spec proving nothing leaks matches
199
+ // directories by this string, so a rename in one file would have left the
200
+ // other's leaks unwatched while the test still passed.
201
+ expect(TEMP_DIR.prefix).toBe("aai-call-audit-");
202
+ });
203
+ });
204
+
205
+ describe("the progress line while a fan-out is retrying", () => {
206
+ /** `stepInfo()`'s answer, as the engine publishes it mid-attempt. */
207
+ const attempt = (n: number): StepInfo => ({
208
+ name: "transcribeSegment",
209
+ key: `transcribeSegment!${n}`,
210
+ attempt: n,
211
+ maxAttempts: 6,
212
+ isLastAttempt: n === 6,
213
+ });
214
+
215
+ test("says nothing on a first attempt, so an ordinary run reads as it did", () => {
216
+ // The eval pins the whole line — `Transcribing 0:00–1:01.` — so a suffix that
217
+ // appeared on attempt one would be a change to the desk's narration rather
218
+ // than an addition to it.
219
+ expect(attemptSuffix(attempt(1))).toBe("");
220
+ });
221
+
222
+ test("names the attempt and the budget once it is really retrying", () => {
223
+ // A thirty-segment fan-out riding out a 429 otherwise re-prints the line it
224
+ // already printed, which looks exactly like a run that has stalled.
225
+ expect(attemptSuffix(attempt(3))).toBe(" (attempt 3 of 6)");
226
+ });
227
+
228
+ test("outside a step is ORDINARY and reads as `not retrying`", () => {
229
+ // `stepInfo()` answers `undefined` in a body, in a tool, and in a spec driving
230
+ // the step directly — which is what the first attempt would have said anyway.
231
+ expect(attemptSuffix(undefined)).toBe("");
232
+ });
233
+ });