@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
@@ -45,13 +45,22 @@
45
45
  * ingest result, once as the plan) and buy nothing.
46
46
  */
47
47
 
48
- import type { WorkflowContext } from "@alexkroman1/aai";
49
- import { encodeWav, mapConcurrent, stepReadUpload, stepReport } from "@alexkroman1/aai/step";
50
- import { countWords, formatDuration } from "@alexkroman1/aai/utils";
51
48
  // ERASED at build time, so the body can name the schema's own output type without
52
49
  // a runtime cycle back through `agent.ts` — the same mechanism `client.tsx` uses
53
50
  // for `WorkflowOutputOf`.
54
- import type { WorkflowInputOf } from "@alexkroman1/aai/workflow-api";
51
+ import type { WorkflowContext, WorkflowInputOf } from "@alexkroman1/aai";
52
+ import {
53
+ encodeWav,
54
+ mapConcurrent,
55
+ type ReadUploadOptions,
56
+ type StepInfo,
57
+ stepInfo,
58
+ stepReadUpload,
59
+ stepReport,
60
+ type UploadSlice,
61
+ } from "@alexkroman1/aai/step";
62
+ import { throwFatalStepError } from "@alexkroman1/aai/step-errors";
63
+ import { countWords, formatDuration } from "@alexkroman1/aai/utils";
55
64
  import type { audit } from "../agent.ts";
56
65
  import { ingestRecording } from "./ingest.ts";
57
66
  import {
@@ -111,6 +120,15 @@ export type CallAudit = {
111
120
  durationMs: number;
112
121
  /** How long the RUN took, wall clock. */
113
122
  elapsedMs: number;
123
+ /**
124
+ * How much of that was ffmpeg — the two levelling passes plus the mastering one.
125
+ *
126
+ * Rendered beside `elapsedMs` rather than folded into it, because the two
127
+ * answer different questions: the run is mostly the fan-out waiting on a
128
+ * provider, and this is what the DECODER cost. It is the number that says
129
+ * whether normalizing first paid for itself.
130
+ */
131
+ ffmpegMs: number;
114
132
  /** How many requests the transcript was assembled from. */
115
133
  segments: number;
116
134
  /**
@@ -218,6 +236,10 @@ export async function auditFlow(
218
236
  codec: ingested.codec,
219
237
  durationMs: ingested.durationMs,
220
238
  elapsedMs: finishedAt - startedAt,
239
+ // Both directions, summed in the body from two journaled step results — so a
240
+ // replay reports the time the passes really took rather than re-measuring
241
+ // work it did not redo.
242
+ ffmpegMs: ingested.ffmpegMs + spoken.ffmpegMs,
221
243
  segments: segments.length,
222
244
  blindCuts: segments.filter((segment) => segment.cutInSpeech).length,
223
245
  speechPercent: Math.round(
@@ -259,23 +281,80 @@ export async function transcribeSegment(audioId: string, segment: Segment): Prom
259
281
  // ORDER is not guaranteed here and does not need to be — the calls go out
260
282
  // together, so their lines interleave by completion, and `segment.index` is what
261
283
  // puts the TRANSCRIPT back in order.
262
- await stepReport(
263
- `Transcribing ${formatDuration(segment.startMs)}–${formatDuration(segment.endMs)}.`,
264
- );
284
+ //
285
+ // `stepInfo()` is read ONCE, at the top, which is what that function asks of a
286
+ // caller: its answer is a snapshot of the attempt in flight, so reading it again
287
+ // after an `await` asks a question whose answer cannot have changed.
288
+ const span = `${formatDuration(segment.startMs)}–${formatDuration(segment.endMs)}`;
289
+ await stepReport(`Transcribing ${span}.${attemptSuffix(stepInfo())}`);
265
290
 
266
- // `[start, end)`, the same half-open pair `planSegments` produced — the store
267
- // owns the conversion to HTTP's inclusive range, so there is no `- 1` here to get
268
- // wrong.
269
- const audio = await stepReadUpload(audioId, { start: segment.startByte, end: segment.endByte });
270
- const text = await transcribeSpan(
271
- encodeWav(audio.bytes, ANALYSIS_FORMAT),
272
- `segment-${segment.index}.wav`,
273
- `Segment ${segment.index} (${formatDuration(segment.startMs)})`,
274
- );
291
+ const audio = await stepReadUpload(audioId, segmentWindow(segment));
292
+
293
+ // The store CLAMPS a window to what it holds, which is the property that made
294
+ // the twelve-byte planning bug `durationSeconds` documents silent: a plan
295
+ // describing audio past the end of the file produced a short slice, a shorter
296
+ // WAV, and a transcript nobody could tell was missing its tail. So the read is
297
+ // checked against what was asked for. Fatal, because the same plan against the
298
+ // same stored file is short on every attempt.
299
+ const missing = segmentShortfall(segment, audio);
300
+ if (missing > 0) {
301
+ throwFatalStepError(
302
+ `Segment ${segment.index} (${span}) came back ${missing} byte(s) short of the ` +
303
+ `${segment.endByte - segment.startByte} the plan asked for. The stored PCM is ` +
304
+ "smaller than the plan was built against, so the transcript would be missing " +
305
+ "audio and say nothing about it.",
306
+ );
307
+ }
308
+
309
+ const text = await transcribeSpan(encodeWav(audio.bytes, ANALYSIS_FORMAT), {
310
+ filename: `segment-${segment.index}.wav`,
311
+ label: `Segment ${segment.index} (${formatDuration(segment.startMs)})`,
312
+ });
275
313
 
276
314
  return { index: segment.index, text };
277
315
  }
278
316
 
317
+ /**
318
+ * One segment's byte range, in the STORE's vocabulary.
319
+ *
320
+ * `[start, end)` — the same half-open pair `planSegments` produced, which is why
321
+ * this is a rename rather than arithmetic: the store owns the conversion to
322
+ * HTTP's inclusive range, so there is no `- 1` here to get wrong. The annotation
323
+ * is what says so, by naming the SDK's own {@link ReadUploadOptions} rather than
324
+ * an object literal that happens to have the right keys today.
325
+ */
326
+ export function segmentWindow(segment: Segment): ReadUploadOptions {
327
+ return { start: segment.startByte, end: segment.endByte };
328
+ }
329
+
330
+ /**
331
+ * Bytes the store came back SHORT of what the plan asked for. `0` when whole.
332
+ *
333
+ * Measured against the bytes actually returned rather than against the slice's
334
+ * own `start`/`end`, because those are what the store CLAMPED to and would
335
+ * therefore agree with themselves.
336
+ */
337
+ export function segmentShortfall(segment: Segment, slice: Pick<UploadSlice, "bytes">): number {
338
+ return Math.max(0, segment.endByte - segment.startByte - slice.bytes.byteLength);
339
+ }
340
+
341
+ /**
342
+ * ` (attempt 2 of 6)`, or nothing at all on a first attempt.
343
+ *
344
+ * The progress log is this desk's whole UI while a run is going, and a
345
+ * thirty-segment fan-out that meets a rate limit re-reports each retried segment
346
+ * under the line it already printed — so without this a run that is patiently
347
+ * riding out a 429 looks exactly like a run that has stalled.
348
+ *
349
+ * `undefined` is ORDINARY rather than an error and reads as "not retrying":
350
+ * {@link stepInfo} answers it outside a step, which is what a spec driving this
351
+ * function directly has and what the first attempt would have said anyway.
352
+ */
353
+ export function attemptSuffix(info: StepInfo | undefined): string {
354
+ if (info === undefined || info.attempt <= 1) return "";
355
+ return ` (attempt ${info.attempt} of ${info.maxAttempts})`;
356
+ }
357
+
279
358
  /**
280
359
  * Join the segment transcripts into one.
281
360
  *
@@ -62,9 +62,13 @@
62
62
 
63
63
  import { readFile, stat } from "node:fs/promises";
64
64
  import { join } from "node:path";
65
- import { probeMedia, runFfmpeg } from "@alexkroman1/aai/ffmpeg";
65
+ import { describeMedia, probeMedia, runFfmpeg } from "@alexkroman1/aai/ffmpeg";
66
66
  import { pcmDurationMs, stepReport, stepRequireCompleteUpload } from "@alexkroman1/aai/step";
67
- import { throwFatalStepError, throwFfmpegStepError } from "@alexkroman1/aai/step-errors";
67
+ import {
68
+ throwFatalStepError,
69
+ throwFfmpegStepError,
70
+ throwStepError,
71
+ } from "@alexkroman1/aai/step-errors";
68
72
  import { readUploadToFile, withTempDir, writeUploadFromFile } from "@alexkroman1/aai/step-files";
69
73
  import { formatBytes, formatDuration, plural } from "@alexkroman1/aai/utils";
70
74
  import {
@@ -75,8 +79,11 @@ import {
75
79
  normalizeArgs,
76
80
  parseLoudness,
77
81
  parseSilences,
82
+ requireAudioStream,
78
83
  type Silence,
79
84
  speechFraction,
85
+ TEMP_DIR,
86
+ totalFfmpegMs,
80
87
  } from "./media.ts";
81
88
 
82
89
  /**
@@ -108,6 +115,13 @@ export type Ingested = {
108
115
  bytes: number;
109
116
  /** What the recording measured before it was levelled. */
110
117
  loudness: Loudness;
118
+ /**
119
+ * Wall clock the two `loudnorm` passes spent, in milliseconds.
120
+ *
121
+ * The decoder's own cost, which is what makes the run's `elapsedMs` readable —
122
+ * see {@link totalFfmpegMs}.
123
+ */
124
+ ffmpegMs: number;
111
125
  /** Every pause long enough to cut in. The fan-out's cut points come from these. */
112
126
  silences: Silence[];
113
127
  };
@@ -134,96 +148,108 @@ export type Ingested = {
134
148
  export async function ingestRecording(uploadId: string): Promise<Ingested> {
135
149
  // `stepRequireCompleteUpload`, not `stepUploadInfo`: `size` is the readable PREFIX, so
136
150
  // an upload still arriving would be copied short and levelled as the whole call.
137
- const stored = await stepRequireCompleteUpload(uploadId);
151
+ // `.catch(throwStepError)` is not decoration: `stepRequireCompleteUpload`
152
+ // refuses a still-arriving upload with an `UploadIncompleteError` that already
153
+ // CARRIES `retryable: false`, and nothing reads a carried verdict unless a
154
+ // caller asks. Thrown raw it is a plain failure, so the engine's unclassified
155
+ // default applies and this call site's `maxAttempts: 6` re-asks the store six
156
+ // times inside a millisecond for bytes that arrive on their own schedule.
157
+ // `throwStepError` turns the carried verdict into the `FatalError` the SDK
158
+ // meant, with its own sentence — which names the remedy — intact.
159
+ const stored = await stepRequireCompleteUpload(uploadId).catch(throwStepError);
138
160
  await stepReport(`Reading ${stored.name || uploadId} (${formatBytes(stored.size)}).`);
139
161
 
140
- return await withTempDir(
141
- async (dir) => {
142
- const source = join(dir, "source");
143
- const normalized = join(dir, "audio.pcm");
144
- const silenceLog = join(dir, "silence.txt");
162
+ return await withTempDir(async (dir) => {
163
+ const source = join(dir, "source");
164
+ const normalized = join(dir, "audio.pcm");
165
+ const silenceLog = join(dir, "silence.txt");
145
166
 
146
- // NO `size`, though `stored.size` is right there — and that is the whole
147
- // difference between this copy being one window at a time and being
148
- // `STEP_FILE_READ_CONCURRENCY` of them. Passing `size` means "I am judging
149
- // completeness myself", which is what a body polling a still-arriving
150
- // upload needs and is the opposite of what happened above: this step has
151
- // already called `stepRequireCompleteUpload`, so the file IS whole and the
152
- // windows may land in any order. Omitting it lets `readUploadToFile`
153
- // establish that for itself and fan out. The cost is one metadata round
154
- // trip, against the dozens of window reads it overlaps.
155
- await readUploadToFile(uploadId, source);
167
+ // NO `size`, though `stored.size` is right there — and that is the whole
168
+ // difference between this copy being one window at a time and being
169
+ // `STEP_FILE_READ_CONCURRENCY` of them. Passing `size` means "I am judging
170
+ // completeness myself", which is what a body polling a still-arriving
171
+ // upload needs and is the opposite of what happened above: this step has
172
+ // already called `stepRequireCompleteUpload`, so the file IS whole and the
173
+ // windows may land in any order. Omitting it lets `readUploadToFile`
174
+ // establish that for itself and fan out. The cost is one metadata round
175
+ // trip, against the dozens of window reads it overlaps.
176
+ await readUploadToFile(uploadId, source);
156
177
 
157
- // What it WAS, for the progress log and the page. Worth one ffprobe: "41
158
- // minutes of aac" explains the shape of the run, where "the recording" leaves
159
- // a reader guessing what the desk decided. On a temp FILE rather than a pipe,
160
- // so a trailing index is readable.
161
- const probed = await probeMedia(source, { timeoutMs: FFMPEG_TIMEOUT_MS }).catch(
162
- throwFfmpegStepError,
163
- );
164
- const codec = probed.audio?.codec ?? "unknown";
165
- await stepReport(
166
- `Levelling ${describeSource(codec, probed.durationSec)} to ${ANALYSIS_FORMAT.sampleRate / 1000} kHz mono.`,
167
- );
178
+ // What it WAS, for the progress log and the page. Worth one ffprobe: "41
179
+ // minutes of aac" explains the shape of the run, where "the recording" leaves
180
+ // a reader guessing what the desk decided. On a temp FILE rather than a pipe,
181
+ // so a trailing index is readable.
182
+ const probed = await probeMedia(source, { timeoutMs: FFMPEG_TIMEOUT_MS }).catch(
183
+ throwFfmpegStepError,
184
+ );
185
+ // Terminal when the file carries no sound at all, BEFORE the measure pass
186
+ // decodes a gigabyte of it — see `requireAudioStream`. The codec then comes
187
+ // off the track itself rather than off an optional chain, so `unknown` here
188
+ // means "ffprobe named no codec" and no longer doubles as "there was
189
+ // nothing to name".
190
+ const track = analyse(() => requireAudioStream(probed));
191
+ const codec = track.codec ?? "unknown";
192
+ await stepReport(
193
+ `Levelling ${describeMedia(probed)} to ${ANALYSIS_FORMAT.sampleRate / 1000} kHz mono.`,
194
+ );
168
195
 
169
- // Pass one: measure. `-f null -` decodes every frame and writes no audio, so
170
- // this costs a decode and produces five numbers.
171
- const measured = await runFfmpeg(measureLoudnessArgs(source), {
172
- timeoutMs: FFMPEG_TIMEOUT_MS,
173
- }).catch(throwFfmpegStepError);
174
- const loudness = analyse(() => parseLoudness(measured.stderr));
196
+ // Pass one: measure. `-f null -` decodes every frame and writes no audio, so
197
+ // this costs a decode and produces five numbers.
198
+ const measured = await runFfmpeg(measureLoudnessArgs(source), {
199
+ timeoutMs: FFMPEG_TIMEOUT_MS,
200
+ }).catch(throwFfmpegStepError);
201
+ const loudness = analyse(() => parseLoudness(measured.stderr));
175
202
 
176
- // Pass two: apply the measurement, find the pauses, write the audio.
177
- await runFfmpeg(normalizeArgs(source, loudness, normalized, silenceLog), {
178
- timeoutMs: FFMPEG_TIMEOUT_MS,
179
- }).catch(throwFfmpegStepError);
203
+ // Pass two: apply the measurement, find the pauses, write the audio.
204
+ const levelled = await runFfmpeg(normalizeArgs(source, loudness, normalized, silenceLog), {
205
+ timeoutMs: FFMPEG_TIMEOUT_MS,
206
+ }).catch(throwFfmpegStepError);
180
207
 
181
- // The duration comes from the BYTE COUNT, not from the original's header or
182
- // from ffprobe. It is the only measurement that agrees with the byte offsets
183
- // the fan-out will use — a container's declared duration can disagree with
184
- // what was actually decoded (an AAC file's encoder padding puts this one ~16ms
185
- // over), and a segment planned against the wrong one runs off the end.
186
- const bytes = (await stat(normalized)).size;
187
- const durationMs = pcmDurationMs(bytes, ANALYSIS_FORMAT);
208
+ // The duration comes from the BYTE COUNT, not from the original's header or
209
+ // from ffprobe. It is the only measurement that agrees with the byte offsets
210
+ // the fan-out will use — a container's declared duration can disagree with
211
+ // what was actually decoded (an AAC file's encoder padding puts this one ~16ms
212
+ // over), and a segment planned against the wrong one runs off the end.
213
+ const bytes = (await stat(normalized)).size;
214
+ const durationMs = pcmDurationMs(bytes, ANALYSIS_FORMAT);
188
215
 
189
- // Verified on ffmpeg 6.1: `ametadata` creates the file at filter-init, so a
190
- // recording with no pause in it leaves an EMPTY log rather than no log. A
191
- // missing file here is therefore a real failure and not a case to tolerate.
192
- const log = await readFile(silenceLog, "utf-8");
193
- const silences = analyse(() => parseSilences(log, durationMs / 1000));
216
+ // Verified on ffmpeg 6.1: `ametadata` creates the file at filter-init, so a
217
+ // recording with no pause in it leaves an EMPTY log rather than no log. A
218
+ // missing file here is therefore a real failure and not a case to tolerate.
219
+ const log = await readFile(silenceLog, "utf-8");
220
+ const silences = analyse(() => parseSilences(log, durationMs / 1000));
194
221
 
195
- const written = await writeUploadFromFile(normalized, {
196
- // Named after the original, so a download reads as the recording it came
197
- // from. `.pcm` because that is what it is — raw samples with no header, and
198
- // a `.wav` name on a headerless file is one no player will open.
199
- name: `${baseName(stored.name || uploadId)}.pcm`,
200
- // Not `audio/wav`: the type is served back on the byte route, and claiming a
201
- // container this file does not have would be a lie a browser acts on. Not
202
- // `audio/L16` either, which looks right and is not — that type is defined as
203
- // BIG-endian 16-bit PCM, where this is `s16le`. Nothing plays this file; the
204
- // fan-out reads byte ranges out of it and puts a real header back on each one
205
- // with `encodeWav`.
206
- type: "application/octet-stream",
207
- });
222
+ const written = await writeUploadFromFile(normalized, {
223
+ // Named after the original, so a download reads as the recording it came
224
+ // from. `.pcm` because that is what it is — raw samples with no header, and
225
+ // a `.wav` name on a headerless file is one no player will open.
226
+ name: `${baseName(stored.name || uploadId)}.pcm`,
227
+ // Not `audio/wav`: the type is served back on the byte route, and claiming a
228
+ // container this file does not have would be a lie a browser acts on. Not
229
+ // `audio/L16` either, which looks right and is not — that type is defined as
230
+ // BIG-endian 16-bit PCM, where this is `s16le`. Nothing plays this file; the
231
+ // fan-out reads byte ranges out of it and puts a real header back on each one
232
+ // with `encodeWav`.
233
+ type: "application/octet-stream",
234
+ });
208
235
 
209
- await stepReport(
210
- `Levelled ${formatDuration(durationMs)} from ${loudness.inputLufs} LUFS, ` +
211
- `${Math.round(speechFraction(silences, durationMs / 1000) * 100)}% speech across ` +
212
- `${silences.length} ${plural(silences.length, "pause")}.`,
213
- );
236
+ await stepReport(
237
+ `Levelled ${formatDuration(durationMs)} from ${loudness.inputLufs} LUFS, ` +
238
+ `${Math.round(speechFraction(silences, durationMs / 1000) * 100)}% speech across ` +
239
+ `${silences.length} ${plural(silences.length, "pause")}.`,
240
+ );
214
241
 
215
- return {
216
- audio: written.id,
217
- source: stored.name || uploadId,
218
- codec,
219
- durationMs,
220
- bytes,
221
- loudness,
222
- silences,
223
- };
224
- },
225
- { prefix: "aai-call-audit-" },
226
- );
242
+ return {
243
+ audio: written.id,
244
+ source: stored.name || uploadId,
245
+ codec,
246
+ durationMs,
247
+ bytes,
248
+ loudness,
249
+ ffmpegMs: totalFfmpegMs(measured, levelled),
250
+ silences,
251
+ };
252
+ }, TEMP_DIR);
227
253
  }
228
254
 
229
255
  /**
@@ -246,13 +272,6 @@ export function analyse<T>(read: () => T): T {
246
272
  }
247
273
  }
248
274
 
249
- /** `41:20 of aac`, or as much of that as ffprobe would say. */
250
- function describeSource(codec: string, durationSec: number | undefined): string {
251
- const length =
252
- durationSec === undefined ? undefined : formatDuration(Math.round(durationSec * 1000));
253
- return length === undefined ? codec : `${length} of ${codec}`;
254
- }
255
-
256
275
  /** A filename without its extension, so a new one can be put on. */
257
276
  function baseName(name: string): string {
258
277
  const dot = name.lastIndexOf(".");
@@ -58,8 +58,14 @@
58
58
  * longer than the cap gets the blind cut, and says so.
59
59
  */
60
60
 
61
- import { ffmpegBaseArgs } from "@alexkroman1/aai/ffmpeg";
61
+ import {
62
+ type FfmpegRunResult,
63
+ ffmpegBaseArgs,
64
+ type MediaInfo,
65
+ type MediaStreamInfo,
66
+ } from "@alexkroman1/aai/ffmpeg";
62
67
  import type { PcmFormat } from "@alexkroman1/aai/step";
68
+ import type { WithTempDirOptions } from "@alexkroman1/aai/step-files";
63
69
  import { safeJsonParse } from "@alexkroman1/aai/utils";
64
70
  import { z } from "zod";
65
71
 
@@ -95,6 +101,21 @@ export const ANALYSIS_FORMAT = {
95
101
  export const BYTES_PER_SECOND =
96
102
  (ANALYSIS_FORMAT.sampleRate * ANALYSIS_FORMAT.channels * ANALYSIS_FORMAT.bitsPerSample) / 8;
97
103
 
104
+ /**
105
+ * Where every step of this desk materializes, as ONE value.
106
+ *
107
+ * Both steps that touch a file call `withTempDir` — the ingest to hold the
108
+ * recording and the levelled PCM, the narration to hold the WAV and the MP3 —
109
+ * and each had written the prefix itself. That is a string two files have to
110
+ * agree on and nothing checked: the spec that proves nothing is LEAKED matches
111
+ * directories by this prefix, so renaming it in one file would leave the other's
112
+ * leaks unwatched while the test still passed.
113
+ *
114
+ * Typed as the SDK's own options rather than inferred, because the annotation is
115
+ * what says the rest of the bag exists and is deliberately left at its default.
116
+ */
117
+ export const TEMP_DIR: WithTempDirOptions = { prefix: "aai-call-audit-" };
118
+
98
119
  /**
99
120
  * Integrated loudness everything is normalized to, in LUFS.
100
121
  *
@@ -197,7 +218,13 @@ export type Segment = {
197
218
  cutInSpeech: boolean;
198
219
  };
199
220
 
200
- /** Raised when an analysis pass produced something this module cannot read. Always terminal. */
221
+ /**
222
+ * Raised when a probe or an analysis pass produced something this module cannot
223
+ * USE — a `loudnorm` block with a renamed key, a silence log cut off mid-write,
224
+ * a file ffprobe found no audio track in. Always terminal: `analyse` in
225
+ * `ingest.ts` is what turns one into a `FatalError`, on the argument that every
226
+ * retry runs the same binary over the same file and reads the same answer.
227
+ */
201
228
  export class MediaAnalysisError extends Error {
202
229
  constructor(message: string) {
203
230
  super(message);
@@ -205,6 +232,53 @@ export class MediaAnalysisError extends Error {
205
232
  }
206
233
  }
207
234
 
235
+ /**
236
+ * The audio track ffprobe found, or a terminal complaint naming what it found
237
+ * instead.
238
+ *
239
+ * **The one thing about the uploaded file this desk checks before it spends a
240
+ * decode on it.** The form accepts "any recording — a video's audio track
241
+ * included", which is honest and admits exactly one file that cannot work: a
242
+ * video with no sound, a still image, a PDF somebody dragged into the picker.
243
+ * Without this the run pays a whole `loudnorm` measure pass over that file — the
244
+ * expensive part, on a recording that can be gigabytes — and then fails with
245
+ * ffmpeg's own complaint about a filter graph, which names the filter rather
246
+ * than the file.
247
+ *
248
+ * A {@link MediaAnalysisError}, so `analyse` in `ingest.ts` makes it TERMINAL:
249
+ * the same file has no audio track on every attempt.
250
+ *
251
+ * The stream KINDS are listed rather than counted, because "found video" is what
252
+ * tells somebody they uploaded the wrong export of the right meeting.
253
+ */
254
+ export function requireAudioStream(probed: MediaInfo): MediaStreamInfo {
255
+ if (probed.audio !== undefined) return probed.audio;
256
+ const found = probed.streams.map((stream) => stream.kind);
257
+ throw new MediaAnalysisError(
258
+ `That file has no audio track — ffprobe found ${found.length === 0 ? "no streams at all" : found.join(", ")}. ` +
259
+ "A video is fine, since the conversion drops the picture, but it has to carry sound.",
260
+ );
261
+ }
262
+
263
+ /**
264
+ * Wall clock the ffmpeg PASSES themselves spent, summed and rounded.
265
+ *
266
+ * `runFfmpeg` measures each invocation and hands the number back on its result;
267
+ * nothing else in a run can measure it, because the alternative is timing a
268
+ * promise that also covers the SDK's own spawn and drain. It is worth carrying
269
+ * out to the page for this template in particular: the run's `elapsedMs` is
270
+ * mostly the fan-out waiting on a provider, and this is the part the DECODER
271
+ * cost — which is the one number that says whether normalizing first was paid
272
+ * for.
273
+ *
274
+ * `ffprobe` is not one of these. It answers in milliseconds on any file, and
275
+ * `probeMedia` returns a {@link MediaInfo} rather than a run result, so there is
276
+ * no duration to add.
277
+ */
278
+ export function totalFfmpegMs(...runs: readonly Pick<FfmpegRunResult, "durationMs">[]): number {
279
+ return Math.round(runs.reduce((total, run) => total + run.durationMs, 0));
280
+ }
281
+
208
282
  /**
209
283
  * Pass one: measure the recording's loudness without writing any audio.
210
284
  *
@@ -507,14 +581,25 @@ export function planSegments(silences: readonly Silence[], totalBytes: number):
507
581
 
508
582
  const cuts: number[] = [];
509
583
  let at = 0;
584
+ // `candidates` is ascending — the `break` below already relies on it — and `at`
585
+ // only moves forward, so each pass resumes where the last one stopped instead of
586
+ // re-walking the prefix it has already consumed. That is O(candidates) over the
587
+ // whole plan rather than O(cuts x candidates), and the two are far apart: an hour
588
+ // of audio at MIN_SILENCE_SECONDS yields on the order of a thousand pauses
589
+ // against ~33 segments.
590
+ let from = 0;
510
591
  while (durationSec - at > MAX_SEGMENT_SECONDS) {
511
592
  const limit = at + MAX_SEGMENT_SECONDS;
512
- // The last candidate that still fits, and strictly after where we are — a
513
- // candidate at `at` would make a zero-length segment and never advance.
593
+ // Strictly after where we are: a candidate at `at` would make a zero-length
594
+ // segment and never advance. Skipping them here is what lets the scan below
595
+ // test only the upper bound.
596
+ while (from < candidates.length && (candidates[from] ?? 0) <= at) from += 1;
597
+ // The last candidate that still fits.
514
598
  let chosen: number | undefined;
515
- for (const candidate of candidates) {
516
- if (candidate > at && candidate <= limit) chosen = candidate;
599
+ for (let j = from; j < candidates.length; j += 1) {
600
+ const candidate = candidates[j] ?? 0;
517
601
  if (candidate > limit) break;
602
+ chosen = candidate;
518
603
  }
519
604
  cuts.push(chosen ?? limit);
520
605
  at = chosen ?? limit;
@@ -523,7 +608,13 @@ export function planSegments(silences: readonly Silence[], totalBytes: number):
523
608
  // Whether a boundary is a cut this planner INVENTED, rather than a pause it found
524
609
  // or the recording's own end. One expression, used by both branches below —
525
610
  // computing it twice is how they came to disagree in a first draft.
526
- const blind = (endSec: number): boolean => cuts.includes(endSec) && !candidates.includes(endSec);
611
+ // As sets: `blind` is called once per segment and both lists are scanned whole by
612
+ // `includes`, which on a long recording is a thousand-element walk per call. The
613
+ // membership test is identical — `Set` matches numbers by SameValueZero, exactly
614
+ // as `includes` does.
615
+ const cutSet = new Set(cuts);
616
+ const candidateSet = new Set(candidates);
617
+ const blind = (endSec: number): boolean => cutSet.has(endSec) && !candidateSet.has(endSec);
527
618
 
528
619
  const bounds = [0, ...cuts, durationSec];
529
620
  const segments: Segment[] = [];
@@ -40,7 +40,7 @@ import { stepGenerateJsonOrFail, throwFfmpegStepError } from "@alexkroman1/aai/s
40
40
  import { withTempDir, writeUploadFromFile } from "@alexkroman1/aai/step-files";
41
41
  import { formatBytes, formatDuration, omitUndefined, plural } from "@alexkroman1/aai/utils";
42
42
  import { z } from "zod";
43
- import { masterArgs } from "./media.ts";
43
+ import { masterArgs, TEMP_DIR, totalFfmpegMs } from "./media.ts";
44
44
 
45
45
  /** Risks the summary is reduced to. Enough to be useful, few enough to act on. */
46
46
  const MAX_RISKS = 4;
@@ -158,40 +158,44 @@ export async function summarize(
158
158
  export async function narrate(
159
159
  script: string,
160
160
  voice?: string,
161
- ): Promise<{ audio: string; durationMs: number; bytes: number }> {
161
+ ): Promise<{ audio: string; durationMs: number; bytes: number; ffmpegMs: number }> {
162
162
  const spoken = await stepSpeak(script, omitUndefined({ voice }));
163
163
 
164
- return await withTempDir(
165
- async (dir) => {
166
- const wav = join(dir, "spoken.wav");
167
- const mp3 = join(dir, "summary.mp3");
164
+ return await withTempDir(async (dir) => {
165
+ const wav = join(dir, "spoken.wav");
166
+ const mp3 = join(dir, "summary.mp3");
168
167
 
169
- // `writeFile` rather than a stream, and this is the one place in the template
170
- // where holding the whole thing in memory is right: `stepSpeak` already
171
- // returned it as a single `Uint8Array`, so streaming it to disk would be
172
- // copying from the heap to the heap on the way. It is bounded by the script,
173
- // which the schema keeps under 150 words.
174
- await writeFile(wav, spoken.audio);
168
+ // `writeFile` rather than a stream, and this is the one place in the template
169
+ // where holding the whole thing in memory is right: `stepSpeak` already
170
+ // returned it as a single `Uint8Array`, so streaming it to disk would be
171
+ // copying from the heap to the heap on the way. It is bounded by the script,
172
+ // which the schema keeps under 150 words.
173
+ await writeFile(wav, spoken.audio);
175
174
 
176
- await runFfmpeg(masterArgs(wav, mp3), { timeoutMs: MASTER_TIMEOUT_MS }).catch(
177
- throwFfmpegStepError,
178
- );
179
- const bytes = (await stat(mp3)).size;
175
+ const mastered = await runFfmpeg(masterArgs(wav, mp3), {
176
+ timeoutMs: MASTER_TIMEOUT_MS,
177
+ }).catch(throwFfmpegStepError);
178
+ const bytes = (await stat(mp3)).size;
180
179
 
181
- const stored = await writeUploadFromFile(mp3, {
182
- // Named, because this is what a person sees on the download link rather than
183
- // an opaque id — and typed, because the byte route serves the type it was
184
- // given and a browser will not play a file it was handed as bytes.
185
- name: "audit.mp3",
186
- type: "audio/mpeg",
187
- });
180
+ const stored = await writeUploadFromFile(mp3, {
181
+ // Named, because this is what a person sees on the download link rather than
182
+ // an opaque id — and typed, because the byte route serves the type it was
183
+ // given and a browser will not play a file it was handed as bytes.
184
+ name: "audit.mp3",
185
+ type: "audio/mpeg",
186
+ });
188
187
 
189
- await stepReport(
190
- `Recorded a ${Math.round(spoken.durationMs / 1000)}s audit in ${spoken.voice}'s voice — ` +
191
- `${formatBytes(bytes)} of MP3, from ${formatBytes(spoken.audio.byteLength)} of WAV.`,
192
- );
193
- return { audio: stored.id, durationMs: spoken.durationMs, bytes };
194
- },
195
- { prefix: "aai-call-audit-" },
196
- );
188
+ await stepReport(
189
+ `Recorded a ${Math.round(spoken.durationMs / 1000)}s audit in ${spoken.voice}'s voice — ` +
190
+ `${formatBytes(bytes)} of MP3, from ${formatBytes(spoken.audio.byteLength)} of WAV.`,
191
+ );
192
+ return {
193
+ audio: stored.id,
194
+ durationMs: spoken.durationMs,
195
+ bytes,
196
+ // The pass on the way OUT, so the page's one ffmpeg number covers both
197
+ // directions rather than only the one the ingest paid for.
198
+ ffmpegMs: totalFfmpegMs(mastered),
199
+ };
200
+ }, TEMP_DIR);
197
201
  }