@alexkroman1/aai-cli 15.1.0 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +8 -5
  2. package/bin.mjs +12 -3
  3. package/dist/_build-target-55dJisQ-.mjs +649 -0
  4. package/dist/_build-target.d.ts +105 -108
  5. package/dist/_deno-output.d.ts +23 -0
  6. package/dist/_deno-target.d.ts +73 -0
  7. package/dist/{_init-Bsi3DZNJ.mjs → _init-BzQbV8Zh.mjs} +3 -1
  8. package/dist/_modal-app.d.ts +77 -0
  9. package/dist/_modal-output.d.ts +31 -0
  10. package/dist/_modal-target.d.ts +64 -0
  11. package/dist/_target-bundle.d.ts +27 -0
  12. package/dist/_target-drain.d.ts +44 -0
  13. package/dist/_target-output.d.ts +63 -0
  14. package/dist/{_templates-CIlJ3Vay.mjs → _templates-CuP74F8D.mjs} +94 -4
  15. package/dist/_templates.d.ts +14 -1
  16. package/dist/_vercel-output.d.ts +4 -19
  17. package/dist/_vercel-target.d.ts +169 -0
  18. package/dist/{test-D032V2cA.mjs → _vitest-runner-AVR9VtXh.mjs} +28 -68
  19. package/dist/_vitest-runner.d.ts +154 -0
  20. package/dist/build-ButI2IKc.mjs +689 -0
  21. package/dist/build.d.ts +11 -0
  22. package/dist/cli.mjs +12 -11
  23. package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
  24. package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
  25. package/dist/{init-CQbj3ycf.mjs → init-D363Ls5u.mjs} +2 -2
  26. package/dist/scaffold/CLAUDE.md +185 -35
  27. package/dist/scaffold/package.json +4 -4
  28. package/dist/start.mjs +3 -1
  29. package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
  30. package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
  31. package/dist/templates/briefing-desk/agent.test.ts +347 -55
  32. package/dist/templates/briefing-desk/agent.ts +12 -0
  33. package/dist/templates/briefing-desk/shared.ts +220 -31
  34. package/dist/templates/briefing-desk/slack.ts +108 -0
  35. package/dist/templates/briefing-desk/system-prompt.md +12 -2
  36. package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
  37. package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
  38. package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
  39. package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
  40. package/dist/templates/call-audit/agent.eval.test.ts +5 -0
  41. package/dist/templates/call-audit/agent.test.ts +6 -1
  42. package/dist/templates/call-audit/agent.ts +10 -23
  43. package/dist/templates/call-audit/client.tsx +30 -55
  44. package/dist/templates/call-audit/guards.test.ts +233 -0
  45. package/dist/templates/call-audit/workflows/audit.ts +95 -16
  46. package/dist/templates/call-audit/workflows/ingest.ts +107 -88
  47. package/dist/templates/call-audit/workflows/media.ts +98 -7
  48. package/dist/templates/call-audit/workflows/summarize.ts +35 -31
  49. package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
  50. package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
  51. package/dist/templates/code-interpreter/agent.test.ts +44 -56
  52. package/dist/templates/code-interpreter/system-prompt.md +1 -1
  53. package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
  54. package/dist/templates/dispatch-center/agent.test.ts +253 -48
  55. package/dist/templates/dispatch-center/agent.ts +28 -1
  56. package/dist/templates/dispatch-center/client.tsx +126 -201
  57. package/dist/templates/dispatch-center/events.ts +48 -0
  58. package/dist/templates/dispatch-center/shared.ts +42 -1
  59. package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
  60. package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
  61. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
  62. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
  63. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
  64. package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
  65. package/dist/templates/executive-assistant/agent.test.ts +672 -0
  66. package/dist/templates/executive-assistant/agent.ts +50 -0
  67. package/dist/templates/executive-assistant/calendar.test.ts +198 -0
  68. package/dist/templates/executive-assistant/client.tsx +195 -0
  69. package/dist/templates/executive-assistant/inbox.ts +233 -0
  70. package/dist/templates/executive-assistant/meeting.ts +138 -0
  71. package/dist/templates/executive-assistant/nodes.ts +152 -0
  72. package/dist/templates/executive-assistant/prompts.ts +331 -0
  73. package/dist/templates/executive-assistant/review.ts +425 -0
  74. package/dist/templates/executive-assistant/shared.ts +490 -0
  75. package/dist/templates/executive-assistant/system-prompt.md +15 -0
  76. package/dist/templates/executive-assistant/tools/accept.ts +10 -0
  77. package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
  78. package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
  79. package/dist/templates/executive-assistant/tools/edit.ts +10 -0
  80. package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
  81. package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
  82. package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
  83. package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
  84. package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
  85. package/dist/templates/executive-assistant/tools/respond.ts +10 -0
  86. package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
  87. package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
  88. package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
  89. package/dist/templates/health-assistant/agent.test.ts +134 -15
  90. package/dist/templates/health-assistant/agent.ts +8 -1
  91. package/dist/templates/health-assistant/fda.test.ts +130 -0
  92. package/dist/templates/health-assistant/fda.ts +75 -16
  93. package/dist/templates/health-assistant/system-prompt.md +9 -0
  94. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
  95. package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
  96. package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
  97. package/dist/templates/hiring-desk/agent.test.ts +1021 -0
  98. package/dist/templates/hiring-desk/agent.ts +38 -0
  99. package/dist/templates/hiring-desk/client.tsx +154 -0
  100. package/dist/templates/hiring-desk/crews.ts +432 -0
  101. package/dist/templates/hiring-desk/leads.json +86 -0
  102. package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
  103. package/dist/templates/hiring-desk/screening-lock.ts +51 -0
  104. package/dist/templates/hiring-desk/shared.ts +480 -0
  105. package/dist/templates/hiring-desk/system-prompt.md +21 -0
  106. package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
  107. package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
  108. package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
  109. package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
  110. package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
  111. package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
  112. package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
  113. package/dist/templates/hotel-desk/agent.test.ts +1128 -0
  114. package/dist/templates/hotel-desk/agent.ts +63 -0
  115. package/dist/templates/hotel-desk/booking.ts +159 -0
  116. package/dist/templates/hotel-desk/card.ts +92 -0
  117. package/dist/templates/hotel-desk/catalogs.ts +219 -0
  118. package/dist/templates/hotel-desk/client.tsx +137 -0
  119. package/dist/templates/hotel-desk/concierge.ts +99 -0
  120. package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
  121. package/dist/templates/hotel-desk/desk.ts +224 -0
  122. package/dist/templates/hotel-desk/disputes.ts +216 -0
  123. package/dist/templates/hotel-desk/events.ts +79 -0
  124. package/dist/templates/hotel-desk/hotel.ts +412 -0
  125. package/dist/templates/hotel-desk/policies.ts +209 -0
  126. package/dist/templates/hotel-desk/records.ts +384 -0
  127. package/dist/templates/hotel-desk/restaurant.ts +147 -0
  128. package/dist/templates/hotel-desk/seed.ts +955 -0
  129. package/dist/templates/hotel-desk/shared.ts +354 -0
  130. package/dist/templates/hotel-desk/system-prompt.md +76 -0
  131. package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
  132. package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
  133. package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
  134. package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
  135. package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
  136. package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
  137. package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
  138. package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
  139. package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
  140. package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
  141. package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
  142. package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
  143. package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
  144. package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
  145. package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
  146. package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
  147. package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
  148. package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
  149. package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
  150. package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
  151. package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
  152. package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
  153. package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
  154. package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
  155. package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
  156. package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
  157. package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
  158. package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
  159. package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
  160. package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
  161. package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
  162. package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
  163. package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
  164. package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
  165. package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
  166. package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
  167. package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
  168. package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
  169. package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
  170. package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
  171. package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
  172. package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
  173. package/dist/templates/infocom-adventure/agent.test.ts +207 -52
  174. package/dist/templates/infocom-adventure/agent.ts +14 -3
  175. package/dist/templates/infocom-adventure/client.tsx +138 -176
  176. package/dist/templates/infocom-adventure/shared.ts +126 -6
  177. package/dist/templates/infocom-adventure/system-prompt.md +4 -4
  178. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
  179. package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
  180. package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
  181. package/dist/templates/link-digest/agent.eval.test.ts +8 -0
  182. package/dist/templates/link-digest/agent.test.ts +285 -29
  183. package/dist/templates/link-digest/agent.ts +9 -0
  184. package/dist/templates/link-digest/api-client.ts +144 -0
  185. package/dist/templates/link-digest/client.tsx +11 -30
  186. package/dist/templates/link-digest/workflows/digest.ts +72 -24
  187. package/dist/templates/night-owl/agent.eval.test.ts +55 -40
  188. package/dist/templates/night-owl/agent.test.ts +146 -12
  189. package/dist/templates/night-owl/client.tsx +50 -17
  190. package/dist/templates/night-owl/shared.ts +33 -2
  191. package/dist/templates/night-owl/system-prompt.md +3 -0
  192. package/dist/templates/night-owl/tools/recommend.ts +4 -1
  193. package/dist/templates/night-owl/tools/revisit.ts +49 -0
  194. package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
  195. package/dist/templates/pipeline-simple/agent.test.ts +48 -91
  196. package/dist/templates/pipeline-simple/modes.test.ts +151 -0
  197. package/dist/templates/pipeline-simple/stages.test.ts +332 -0
  198. package/dist/templates/pizza-ordering/agent.test.ts +94 -38
  199. package/dist/templates/pizza-ordering/client.tsx +10 -5
  200. package/dist/templates/pizza-ordering/shared.ts +65 -6
  201. package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
  202. package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
  203. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
  204. package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
  205. package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
  206. package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
  207. package/dist/templates/plan-and-execute/agent.test.ts +300 -113
  208. package/dist/templates/plan-and-execute/client.tsx +18 -7
  209. package/dist/templates/plan-and-execute/procedure.ts +162 -64
  210. package/dist/templates/plan-and-execute/prompts.ts +51 -15
  211. package/dist/templates/plan-and-execute/shared.ts +151 -45
  212. package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
  213. package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
  214. package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
  215. package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
  216. package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
  217. package/dist/templates/podcast-digest/agent.test.ts +126 -51
  218. package/dist/templates/podcast-digest/client.tsx +104 -68
  219. package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
  220. package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
  221. package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
  222. package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
  223. package/dist/templates/recap-workflow/agent.test.ts +207 -26
  224. package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
  225. package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
  226. package/dist/templates/redline/agent.eval.test.ts +40 -3
  227. package/dist/templates/redline/agent.test.ts +216 -6
  228. package/dist/templates/redline/agent.ts +54 -34
  229. package/dist/templates/redline/client.tsx +82 -126
  230. package/dist/templates/redline/form.ts +74 -0
  231. package/dist/templates/redline/workflows/prompts.ts +3 -3
  232. package/dist/templates/redline/workflows/redline.ts +73 -4
  233. package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
  234. package/dist/templates/research-workflow/agent.test.ts +436 -126
  235. package/dist/templates/research-workflow/agent.ts +20 -5
  236. package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
  237. package/dist/templates/research-workflow/tools/research_status.ts +39 -4
  238. package/dist/templates/research-workflow/workflows/filing.ts +164 -0
  239. package/dist/templates/research-workflow/workflows/notes.ts +69 -0
  240. package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
  241. package/dist/templates/research-workflow/workflows/research.ts +227 -280
  242. package/dist/templates/research-workflow/workflows/review.ts +43 -0
  243. package/dist/templates/retail/address.ts +29 -35
  244. package/dist/templates/retail/agent.eval.test.ts +36 -16
  245. package/dist/templates/retail/agent.test.ts +104 -26
  246. package/dist/templates/retail/agent.ts +12 -0
  247. package/dist/templates/retail/cancel.ts +39 -42
  248. package/dist/templates/retail/client.tsx +111 -176
  249. package/dist/templates/retail/payment.ts +38 -43
  250. package/dist/templates/retail/pending.test.ts +16 -8
  251. package/dist/templates/retail/registry.test.ts +108 -49
  252. package/dist/templates/retail/resolve.test.ts +2 -63
  253. package/dist/templates/retail/resolve.ts +16 -56
  254. package/dist/templates/retail/returns.ts +53 -54
  255. package/dist/templates/retail/seed.test.ts +2 -1
  256. package/dist/templates/retail/shared.ts +58 -14
  257. package/dist/templates/retail/store.test.ts +40 -29
  258. package/dist/templates/retail/store.ts +60 -23
  259. package/dist/templates/retail/swap.ts +78 -81
  260. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
  261. package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
  262. package/dist/templates/roadside-assist/agent.test.ts +617 -0
  263. package/dist/templates/roadside-assist/agent.ts +85 -0
  264. package/dist/templates/roadside-assist/call.ts +237 -0
  265. package/dist/templates/roadside-assist/events.ts +92 -0
  266. package/dist/templates/roadside-assist/shared.ts +334 -0
  267. package/dist/templates/roadside-assist/system-prompt.md +37 -0
  268. package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
  269. package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
  270. package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
  271. package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
  272. package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
  273. package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
  274. package/dist/templates/roadside-assist/yard.test.ts +158 -0
  275. package/dist/templates/roadside-assist/yard.ts +183 -0
  276. package/dist/templates/simple/agent.eval.test.ts +4 -1
  277. package/dist/templates/simple/agent.test.ts +54 -31
  278. package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
  279. package/dist/templates/solo-rpg/agent.test.ts +402 -175
  280. package/dist/templates/solo-rpg/agent.ts +14 -3
  281. package/dist/templates/solo-rpg/client.tsx +10 -10
  282. package/dist/templates/solo-rpg/shared.ts +198 -79
  283. package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
  284. package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
  285. package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
  286. package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
  287. package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
  288. package/dist/templates/spoken-summary/agent.test.ts +70 -15
  289. package/dist/templates/spoken-summary/agent.ts +25 -21
  290. package/dist/templates/spoken-summary/client.tsx +68 -88
  291. package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
  292. package/dist/templates/support-line/agent.test.ts +167 -36
  293. package/dist/templates/support-line/client.tsx +21 -9
  294. package/dist/templates/support-line/nodes.ts +74 -32
  295. package/dist/templates/support-line/procedure.ts +66 -21
  296. package/dist/templates/support-line/prompts.ts +9 -0
  297. package/dist/templates/support-line/shared.ts +55 -17
  298. package/dist/templates/support-line/tools/answer_question.ts +14 -14
  299. package/dist/templates/transcription-workflow/agent.test.ts +135 -13
  300. package/dist/templates/transcription-workflow/client.tsx +30 -23
  301. package/dist/templates/transcription-workflow/recover.test.ts +93 -12
  302. package/dist/templates/transcription-workflow/recover.ts +29 -5
  303. package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
  304. package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
  305. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
  306. package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
  307. package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
  308. package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
  309. package/dist/templates/travel-concierge/agent.test.ts +209 -40
  310. package/dist/templates/travel-concierge/agent.ts +24 -4
  311. package/dist/templates/travel-concierge/call-events.ts +80 -0
  312. package/dist/templates/travel-concierge/client.tsx +3 -2
  313. package/dist/templates/travel-concierge/routing.ts +5 -7
  314. package/dist/templates/travel-concierge/shared.ts +202 -41
  315. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
  316. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
  317. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
  318. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
  319. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
  320. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
  321. package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
  322. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
  323. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
  324. package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
  325. package/dist/templates/web-researcher/agent.test.ts +102 -65
  326. package/dist/templates/web-researcher/agent.ts +93 -1
  327. package/dist/templates/web-researcher/system-prompt.md +7 -1
  328. package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
  329. package/dist/templates/word-wrangler/agent.test.ts +432 -0
  330. package/dist/templates/word-wrangler/agent.ts +35 -0
  331. package/dist/templates/word-wrangler/client.tsx +211 -0
  332. package/dist/templates/word-wrangler/game.ts +107 -0
  333. package/dist/templates/word-wrangler/guess.ts +63 -0
  334. package/dist/templates/word-wrangler/player.ts +68 -0
  335. package/dist/templates/word-wrangler/shared.ts +263 -0
  336. package/dist/templates/word-wrangler/system-prompt.md +15 -0
  337. package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
  338. package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
  339. package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
  340. package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
  341. package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
  342. package/dist/templates/word-wrangler/words.ts +278 -0
  343. package/dist/test-Cllnx81G.mjs +83 -0
  344. package/dist/test.d.ts +9 -114
  345. package/package.json +5 -5
  346. package/dist/build-BhEaxBPu.mjs +0 -481
  347. package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
  348. package/dist/templates/embedded-assets/agent.test.ts +0 -79
  349. package/dist/templates/embedded-assets/agent.ts +0 -7
  350. package/dist/templates/embedded-assets/knowledge.json +0 -20
  351. package/dist/templates/embedded-assets/shared.ts +0 -17
  352. package/dist/templates/embedded-assets/system-prompt.md +0 -13
  353. package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
  354. package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
  355. package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
  356. package/dist/templates/math-buddy/agent.test.ts +0 -126
  357. package/dist/templates/math-buddy/agent.ts +0 -15
  358. package/dist/templates/math-buddy/system-prompt.md +0 -12
  359. package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
  360. package/dist/templates/personal-finance/agent.test.ts +0 -127
  361. package/dist/templates/personal-finance/agent.ts +0 -8
  362. package/dist/templates/personal-finance/system-prompt.md +0 -21
@@ -0,0 +1,689 @@
1
+ #!/usr/bin/env node
2
+ import { _ as DENO_ENTRY_FILE, a as VERCEL_ENTRY_SOURCE, c as VERCEL_STATIC_DIR, d as MODAL_ENTRY_FILE, f as MODAL_ENTRY_SOURCE, g as DENO_CONFIG_SOURCE, h as DENO_CONFIG_FILE, i as VERCEL_BUILD_CONFIG_SOURCE, l as vercelFunctionConfigSource, m as MODAL_PORT, n as TARGET_OUTPUTS, o as VERCEL_FUNCTION_DIR, p as MODAL_OUTPUT_DIR, r as resolveBuildTarget, s as VERCEL_OUTPUT_DIR, u as MODAL_APP_FILE, v as DENO_ENTRY_SOURCE, y as DENO_OUTPUT_DIR } from "./_build-target-55dJisQ-.mjs";
3
+ import { a as ok, t as CliError } from "./_output-DBP9Op_d.mjs";
4
+ import { n as log, r as notify } from "./_ui-DCt4qZrk.mjs";
5
+ import { n as withPreservedNodeEnv } from "./_vite-env-kejF0p2L.mjs";
6
+ import { n as WORKER_ARTIFACT_REL, t as CLIENT_ARTIFACT_REL } from "./_artifacts-BJOYGQPp.mjs";
7
+ import { r as evalWorkerBundle, t as buildAgentBundle } from "./_bundler-DM0d0M7m.mjs";
8
+ import { assertTypechecks } from "./_typecheck-gate-U3jcil8L.mjs";
9
+ import { n as classifyVitestError, r as runVitest } from "./_vitest-runner-AVR9VtXh.mjs";
10
+ import { n as scanWorkflowDeterminism, t as determinismWarnings } from "./_workflow-determinism-CvpqMpdh.mjs";
11
+ import { TEST_FILES } from "./test-Cllnx81G.mjs";
12
+ import path from "node:path";
13
+ import fs from "node:fs/promises";
14
+ import { invariant } from "@alexkroman1/aai/internal";
15
+ import { build } from "vite";
16
+ import { defaultClientDir } from "@alexkroman1/aai-ui/client-dir";
17
+ import { agentConfigWarnings } from "@alexkroman1/aai/manifest";
18
+ import { DEFAULT_SYSTEM_PROMPT } from "@alexkroman1/aai";
19
+ //#region src/_target-bundle.ts
20
+ /**
21
+ * Bundling a deployment target's ENTRY into one self-contained ESM file.
22
+ *
23
+ * Shared by every target that emits one, because the reason is the same at
24
+ * each: the entry imports `@alexkroman1/aai-cli/start`, and what a host does
25
+ * with the module graph behind that import differs in ways that are all bad.
26
+ *
27
+ * - **Vercel** traces it with `@vercel/nft`, which cannot follow the dynamic
28
+ * `import(pathToFileURL(...))` that loads the worker.
29
+ * - **Deno Deploy** caches the dependency graph of the PACKAGE rather than of
30
+ * the import, and `@alexkroman1/aai-cli`'s dependencies are a build
31
+ * toolchain — vite, rolldown and the rest. Measured: the build exceeded its
32
+ * 1024 MiB memory limit at "Caching dependencies for the entrypoint" before
33
+ * it reached any code of ours.
34
+ *
35
+ * A bundle removes the question. The host resolves nothing, installs nothing,
36
+ * and what runs is what the project's own lockfile pinned.
37
+ *
38
+ * The entry is written INTO the project rather than a temp directory, because
39
+ * that is what makes `@alexkroman1/aai-cli/start` resolve against the user's
40
+ * install. Removed in a `finally`: a build that throws must not leave a file
41
+ * that looks authored.
42
+ */
43
+ /** Bundle `source` as if it were a module in `cwd`, and answer the code. */
44
+ async function bundleTargetEntry(cwd, source, name) {
45
+ const entryPath = path.join(cwd, ".aai", `${name}-entry.mjs`);
46
+ await fs.mkdir(path.dirname(entryPath), { recursive: true });
47
+ await fs.writeFile(entryPath, source, "utf-8");
48
+ let result;
49
+ try {
50
+ result = await withPreservedNodeEnv(() => build({
51
+ root: cwd,
52
+ logLevel: "silent",
53
+ configFile: false,
54
+ ssr: { noExternal: true },
55
+ build: {
56
+ ssr: true,
57
+ lib: {
58
+ entry: entryPath,
59
+ formats: ["es"],
60
+ fileName: name
61
+ },
62
+ target: "node20",
63
+ minify: false,
64
+ write: false,
65
+ rollupOptions: { output: {
66
+ entryFileNames: "[name].mjs",
67
+ codeSplitting: false
68
+ } }
69
+ }
70
+ }));
71
+ } finally {
72
+ await fs.rm(entryPath, { force: true }).catch(() => void 0);
73
+ }
74
+ const output = Array.isArray(result) ? result[0] : result;
75
+ invariant(output !== void 0, "target.entry.output", () => ({ name }));
76
+ const chunk = output.output.find((o) => o.type === "chunk" && o.isEntry);
77
+ invariant(chunk !== void 0, "target.entry.chunk", () => ({
78
+ name,
79
+ kinds: output.output.map((o) => o.type)
80
+ }));
81
+ return chunk.code;
82
+ }
83
+ /** Whether a path exists — the check every emit makes of an optional file. */
84
+ async function targetPathExists(target) {
85
+ return await fs.stat(target).then(() => true, () => false);
86
+ }
87
+ //#endregion
88
+ //#region src/_target-output.ts
89
+ /**
90
+ * The SELF-CONTAINED deployment directory — the half two targets share.
91
+ *
92
+ * `deno deploy` uploads a directory and runs one entrypoint in it; `modal
93
+ * deploy` uploads a directory into an image layer and spawns node on one file
94
+ * in it. Neither performs an install, so both emits have the identical job:
95
+ * put beside the bundled entry every file the server opens at RUN time. Each
96
+ * of the three was found by a deployment failing without it, which is the
97
+ * reason this is one module and not a shape each target re-derives —
98
+ * a fourth target must not get to rediscover them.
99
+ *
100
+ * - **`.aai/worker.mjs`**, loaded through `import(pathToFileURL(...))`. Bundling
101
+ * cannot inline it and nothing else would carry it.
102
+ * - **The browser client.** `resolveClientDir` falls back to `defaultClientDir()`,
103
+ * which is `require.resolve("@alexkroman1/aai-ui/package.json")` — a lookup
104
+ * with no `node_modules` to answer it. A bundled deployment died at boot on
105
+ * exactly that until the prebuilt UI was copied in.
106
+ * - **`.env.example`**, which DECLARES which variables become `ctx.env`. Without
107
+ * it every tool sees an empty env while the platform has the values set.
108
+ *
109
+ * **`.env` is deliberately absent**, the same rule the Vercel emit follows:
110
+ * declarations ship, values come from the host (`deno deploy env`, a
111
+ * `modal.Secret`). Copying it would upload a developer's live credentials AND
112
+ * let them outrank what the host was configured with.
113
+ *
114
+ * The nesting is not an accident. `createProjectServer` resolves the worker at
115
+ * `<cwd>/.aai/worker.mjs` and each entry passes its own directory as `cwd`, so
116
+ * the output holds its own `.aai/` — the layout the server already knows,
117
+ * rather than a second one this module would have to teach it.
118
+ */
119
+ /** Files copied verbatim, each read at RUNTIME by a path no bundler can see. */
120
+ const RUNTIME_FILES$1 = [WORKER_ARTIFACT_REL, ".env.example"];
121
+ /**
122
+ * Write a target's self-contained directory and answer its absolute path.
123
+ *
124
+ * REMOVED first: the directory is uploaded wholesale, so anything an earlier
125
+ * build left in it would be deployed alongside this one.
126
+ *
127
+ * The path comes back so a target with MORE to write — Modal's `app.py` — adds
128
+ * it here rather than recomputing where "here" is.
129
+ */
130
+ async function emitSelfContainedOutput(cwd, target, options = {}) {
131
+ const outputDir = path.join(cwd, target.outputDir);
132
+ await fs.rm(outputDir, {
133
+ recursive: true,
134
+ force: true
135
+ });
136
+ await fs.mkdir(outputDir, { recursive: true });
137
+ const bundle = options.bundle ?? ((dir) => bundleTargetEntry(dir, target.entrySource, target.name));
138
+ await fs.writeFile(path.join(outputDir, target.entryFile), await bundle(cwd), "utf-8");
139
+ for (const rel of RUNTIME_FILES$1) {
140
+ const from = path.join(cwd, rel);
141
+ if (!await targetPathExists(from)) continue;
142
+ const to = path.join(outputDir, rel);
143
+ await fs.mkdir(path.dirname(to), { recursive: true });
144
+ await fs.copyFile(from, to);
145
+ }
146
+ const clientSource = await targetPathExists(path.join(cwd, CLIENT_ARTIFACT_REL, "index.html")) ? path.join(cwd, CLIENT_ARTIFACT_REL) : defaultClientDir();
147
+ await fs.cp(clientSource, path.join(outputDir, CLIENT_ARTIFACT_REL), { recursive: true });
148
+ return outputDir;
149
+ }
150
+ //#endregion
151
+ //#region src/_deno-output.ts
152
+ /**
153
+ * Assemble a self-contained Deno Deploy directory — `.aai/deno/`.
154
+ *
155
+ * The assembly is `_target-output.ts`, shared with the Modal emit: both hosts
156
+ * upload a directory and run one file in it with no install step, so the set of
157
+ * runtime files that have to travel is the same set, and that module's doc
158
+ * carries which three and the deployment failure that found each.
159
+ *
160
+ * Deno's own half is two files. The ENTRY it bundles — see `DENO_ENTRY_SOURCE`
161
+ * — and a **`deno.json`** beside it (see {@link DENO_CONFIG_SOURCE}), so the
162
+ * directory describes how to run itself and no command against it has to
163
+ * re-supply `--entrypoint`.
164
+ *
165
+ * That second file is also the answer to "why is this not just the shared
166
+ * emit": both self-contained targets need a way to say what to RUN, and the two
167
+ * hosts take it differently — Deno reads a config it already understands, while
168
+ * Modal has no descriptor at all and needs a generated Python module.
169
+ */
170
+ /** Write `.aai/deno/` for this project. */
171
+ async function emitDenoOutput(cwd, options = {}) {
172
+ const outputDir = await emitSelfContainedOutput(cwd, {
173
+ outputDir: DENO_OUTPUT_DIR,
174
+ entryFile: DENO_ENTRY_FILE,
175
+ entrySource: DENO_ENTRY_SOURCE,
176
+ name: "deno"
177
+ }, options);
178
+ await fs.writeFile(path.join(outputDir, DENO_CONFIG_FILE), DENO_CONFIG_SOURCE, "utf-8");
179
+ }
180
+ //#endregion
181
+ //#region src/_modal-app.ts
182
+ /**
183
+ * The Modal app definition `aai build --target modal` emits — `app.py`.
184
+ *
185
+ * ## Why this target is a generated PYTHON file
186
+ *
187
+ * Every other target emits the host's expected entry shape and lets the host
188
+ * hold the rest: Vercel reads a routing table it already understands, Deno
189
+ * Deploy takes a directory and an entrypoint. Modal has no such descriptor.
190
+ * Its deploy unit is a Python module — `modal.App`, an image recipe, and a
191
+ * decorated function — and `modal deploy` runs that module rather than reading
192
+ * a manifest out of it. So the "preset" for Modal is the module itself, which
193
+ * is why this is the one target whose emit generates code in another language.
194
+ *
195
+ * ## The knobs are DEPLOY-TIME ENV, not edits to this file
196
+ *
197
+ * The awkward consequence is that Modal's policy — how many containers, how
198
+ * much CPU, which secret — lives in Python arguments rather than in a platform
199
+ * dashboard. A generated file carrying policy is a file people edit, and this
200
+ * one is overwritten by the next `aai build`, so "do not edit" would be a lie
201
+ * the first time somebody wanted a warm container.
202
+ *
203
+ * Four knobs are therefore read from the environment at deploy time
204
+ * ({@link MODAL_ENV_KNOBS}), which keeps the project committing nothing
205
+ * host-specific — the property `_build-target.ts` opens by defending:
206
+ *
207
+ * ```sh
208
+ * AAI_MODAL_MIN_CONTAINERS=1 modal deploy .aai/modal/app.py
209
+ * ```
210
+ *
211
+ * The rest — cpu, memory, timeout, concurrency — stays a documented constant
212
+ * in the emitted file. Those are the numbers a reader needs to SEE to trust
213
+ * the deployment, and regenerating restates the default, which is the same
214
+ * contract every other generated artifact here has.
215
+ */
216
+ /**
217
+ * The Node major the emitted image may not go below — the SDK's own `engines`
218
+ * floor.
219
+ *
220
+ * The tag otherwise tracks the Node running the build, so the bundle runs on
221
+ * the runtime it was bundled for. Modal pulls any tag that exists on Docker
222
+ * Hub, so there is nothing to clamp from ABOVE — unlike `vercelNodeRuntime`,
223
+ * whose platform publishes a fixed list. The floor is the half that matters:
224
+ * npm does not enforce `engines` by default, so a build on Node 22 would
225
+ * otherwise emit a `node:22-slim` image in which the SDK genuinely does not
226
+ * run, and the failure would arrive as a crash-looping container.
227
+ */
228
+ const MODAL_NODE_MAJOR_FLOOR = 24;
229
+ /**
230
+ * The Python `add_python` layers beside Node.
231
+ *
232
+ * Matches `scripts/modal_image.py`, which is the same arrangement one layer up:
233
+ * the container entrypoint is Modal's own Python runtime, and it spawns node.
234
+ */
235
+ const MODAL_ADD_PYTHON = "3.13";
236
+ /** What a name sanitizes to when nothing usable survives — see {@link modalAppName}. */
237
+ const MODAL_FALLBACK_APP_NAME = "aai-agent";
238
+ /**
239
+ * Modal caps a resource name at 64 characters. Truncated rather than refused:
240
+ * the name is cosmetic (it appears in the app's URL), and failing a build over
241
+ * a long agent name would be the target's first impression.
242
+ */
243
+ const MODAL_NAME_MAX = 64;
244
+ /**
245
+ * An agent name as a Modal app name.
246
+ *
247
+ * Modal accepts a narrow character set here and the name reaches a hostname —
248
+ * a deployed function is served at `<workspace>--<app>-<function>.modal.run` —
249
+ * so anything outside `[a-z0-9-]` becomes a dash rather than being passed
250
+ * through and rejected by the platform. Agent names are free text
251
+ * (`define({ name: "Retail Support Bot" })`), which is why this is a mapping
252
+ * and not a validation.
253
+ *
254
+ * Collapsed and trimmed, because `--` is what a hostname reader sees as the
255
+ * workspace separator, and a leading or trailing dash is not a legal label.
256
+ */
257
+ function modalAppName(agentName) {
258
+ const slug = agentName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, MODAL_NAME_MAX).replace(/-+$/g, "");
259
+ return slug === "" ? MODAL_FALLBACK_APP_NAME : slug;
260
+ }
261
+ /**
262
+ * The Modal Secret the deployment reads its env from.
263
+ *
264
+ * `-env` rather than the app name alone: the secret holds exactly what
265
+ * `.env.example` declares, and a name that says so makes
266
+ * `modal secret create <name> …` self-explaining. Derived rather than
267
+ * configured, so the emitted file and the command in its docstring cannot name
268
+ * two different secrets.
269
+ */
270
+ function modalSecretName(appName) {
271
+ return `${appName}-env`.slice(0, MODAL_NAME_MAX);
272
+ }
273
+ /** `node:<major>-slim` for the Node running this build, floored at the SDK's minimum. */
274
+ function modalNodeImageTag(version = process.versions.node) {
275
+ const major = Number.parseInt(version.split(".")[0] ?? "", 10);
276
+ return `node:${Number.isNaN(major) || major < MODAL_NODE_MAJOR_FLOOR ? MODAL_NODE_MAJOR_FLOOR : major}-slim`;
277
+ }
278
+ /**
279
+ * Render `app.py` for this agent.
280
+ *
281
+ * Every number the platform needs appears ONCE and is interpolated, so the
282
+ * emitted file cannot disagree with itself or with the entry beside it — see
283
+ * {@link MODAL_PORT} for the failure that motivates it.
284
+ */
285
+ function modalAppSource(options) {
286
+ const app = modalAppName(options.name);
287
+ const secret = modalSecretName(app);
288
+ const image = options.nodeImage ?? modalNodeImageTag();
289
+ return `# Generated by \`aai build --target modal\` — do not edit, and do not commit.
290
+ """Deploys this agent to Modal.
291
+
292
+ modal secret create ${secret} ASSEMBLYAI_API_KEY=... # once
293
+ modal deploy .aai/modal/${MODAL_APP_FILE}
294
+
295
+ Everything this serves is in THIS directory. \`${MODAL_ENTRY_FILE}\` is a bundle
296
+ with no imports left to resolve, so the image installs nothing, carries no
297
+ lockfile and needs no node_modules.
298
+
299
+ Policy is read from the environment at DEPLOY time rather than edited here,
300
+ because \`aai build --target modal\` overwrites this file:
301
+
302
+ AAI_MODAL_APP app name (default: ${app})
303
+ AAI_MODAL_SECRET secret holding the agent env (default: ${secret})
304
+ AAI_MODAL_MIN_CONTAINERS warm floor (default: 0, i.e. scales to zero)
305
+ AAI_MODAL_MAX_CONTAINERS autoscaler ceiling (default: 10)
306
+ """
307
+
308
+ import atexit
309
+ import contextlib
310
+ import os
311
+ import signal
312
+ import subprocess
313
+ from pathlib import Path
314
+
315
+ import modal
316
+
317
+ # This file's OWN directory, never the shell's. \`modal deploy\` resolves a
318
+ # relative local path against the directory it was invoked FROM, so an
319
+ # \`add_local_dir(".")\` here would upload the project root or nothing at all,
320
+ # depending on where the deploy was run.
321
+ HERE = Path(__file__).parent
322
+
323
+ # Bound to \`@modal.web_server\` and baked into the image env from this one
324
+ # place. The proxy routes to the port it is told about, and a node process
325
+ # reading a different number listens where nothing is routed — a deployment
326
+ # that builds, starts, reports healthy and answers no request.
327
+ PORT = ${MODAL_PORT}
328
+
329
+ # The node server, spawned by \`server()\` below.
330
+ ENTRY = "${MODAL_ENTRY_FILE}"
331
+
332
+ APP_NAME = os.environ.get("AAI_MODAL_APP", "${app}")
333
+ SECRET_NAME = os.environ.get("AAI_MODAL_SECRET", "${secret}")
334
+ MIN_CONTAINERS = int(os.environ.get("AAI_MODAL_MIN_CONTAINERS", "0"))
335
+ MAX_CONTAINERS = int(os.environ.get("AAI_MODAL_MAX_CONTAINERS", "10"))
336
+
337
+ # How long a container stop waits for node to close its sessions before the
338
+ # force-kill. Modal's own SIGKILL backstop still bounds the real grace period,
339
+ # so this is headroom rather than a budget the shutdown spends.
340
+ NODE_STOP_TIMEOUT_SECS = 30
341
+
342
+ image = (
343
+ # \`add_python\` layers Modal's own Python beside Node: the container
344
+ # entrypoint is that Python runtime, and it spawns node. The Node major
345
+ # tracks the one this was BUILT with, so the bundle runs on the runtime it
346
+ # was bundled for.
347
+ modal.Image.from_registry("${image}", add_python="${MODAL_ADD_PYTHON}")
348
+ .env({"NODE_ENV": "production", "PORT": str(PORT)})
349
+ # \`copy=True\` puts these files in an image LAYER. The default mounts them
350
+ # at container start instead, which re-uploads the browser client on every
351
+ # cold start and makes the boot slower the larger the UI gets.
352
+ .add_local_dir(
353
+ HERE,
354
+ remote_path="/app",
355
+ copy=True,
356
+ ignore=["${MODAL_APP_FILE}", "__pycache__"],
357
+ )
358
+ )
359
+
360
+ app = modal.App(APP_NAME)
361
+
362
+
363
+ def _run_node(entry: str, env: dict[str, str]) -> subprocess.Popen:
364
+ """Spawn the node server and hand container stop signals to it.
365
+
366
+ Modal stops a container by signalling THIS Python process, and a child
367
+ spawned with a bare Popen receives nothing of its own — so the node
368
+ server's SIGTERM handler, the thing that closes live voice sessions, would
369
+ never run on a scale-in or a redeploy. Every call in progress would just
370
+ lose its socket.
371
+
372
+ Two hooks, because neither alone is reliable: \`signal.signal\` only works on
373
+ the main thread and Modal may call this off it, while the atexit fallback
374
+ catches the runtime handling the signal itself and exiting normally. Both
375
+ funnel into one memoized stop(), and the node handler is idempotent, so
376
+ double delivery is harmless.
377
+ """
378
+ proc = subprocess.Popen(["node", entry], cwd="/app", env=env)
379
+ stopped = False
380
+
381
+ def stop() -> None:
382
+ nonlocal stopped
383
+ if stopped or proc.poll() is not None:
384
+ return
385
+ stopped = True
386
+ with contextlib.suppress(ProcessLookupError):
387
+ proc.send_signal(signal.SIGTERM)
388
+ with contextlib.suppress(subprocess.TimeoutExpired):
389
+ proc.wait(timeout=NODE_STOP_TIMEOUT_SECS)
390
+ if proc.poll() is None:
391
+ proc.kill()
392
+
393
+ def forward(signum: int) -> None:
394
+ previous = signal.getsignal(signum)
395
+
396
+ def handler(sig: int, frame: object) -> None:
397
+ stop()
398
+ if callable(previous):
399
+ previous(sig, frame)
400
+ elif previous == signal.SIG_DFL:
401
+ # Re-deliver with the default disposition so this runtime still
402
+ # dies the way the platform expects.
403
+ signal.signal(sig, signal.SIG_DFL)
404
+ os.kill(os.getpid(), sig)
405
+
406
+ signal.signal(signum, handler)
407
+
408
+ for signum in (signal.SIGTERM, signal.SIGINT):
409
+ with contextlib.suppress(ValueError): # not the main thread
410
+ forward(signum)
411
+
412
+ atexit.register(stop)
413
+ return proc
414
+
415
+
416
+ @app.function(
417
+ image=image,
418
+ # Values live in a Modal Secret; the \`.env.example\` beside this file
419
+ # DECLARES which names reach \`ctx.env\`. Deploy FAILS when the secret does
420
+ # not exist, which is the right time to hear about it — the alternative is
421
+ # a container that starts and has no provider credential.
422
+ secrets=[modal.Secret.from_name(SECRET_NAME)],
423
+ # An audio pipeline is not a burstable workload: STT framing, the LLM turn
424
+ # and TTS playback all run in this process.
425
+ cpu=1,
426
+ memory=1024,
427
+ min_containers=MIN_CONTAINERS,
428
+ max_containers=MAX_CONTAINERS,
429
+ # Hold a container after the last call rather than paying a cold start on
430
+ # the next one.
431
+ scaledown_window=300,
432
+ # Bounds ONE input, and a WebSocket is one input for as long as the call
433
+ # lasts — so this is the longest single call this deployment will carry.
434
+ timeout=3600,
435
+ )
436
+ # Without this a container serves ONE input at a time, and a voice call holds
437
+ # its input until the caller hangs up: the second caller would wait out the
438
+ # first, and every asset request for the browser client would queue behind
439
+ # whichever call is in progress. \`target_inputs\` is the scale-out set point,
440
+ # under the cap, so a container is joined by another before it saturates.
441
+ @modal.concurrent(max_inputs=50, target_inputs=25)
442
+ @modal.web_server(port=PORT, startup_timeout=180)
443
+ def server() -> None:
444
+ env = os.environ.copy()
445
+ # Modal points this at an in-container Unix socket serving its own Python
446
+ # task runtime. The \`modal\` JS SDK prefers that variable over the public
447
+ # endpoint, so anything in node that talks to Modal would dial a socket
448
+ # that does not answer it.
449
+ env.pop("MODAL_SERVER_URL", None)
450
+ # _run_node, not a bare Popen, so the container's stop signal reaches node
451
+ # and live sessions are closed rather than dropped.
452
+ _run_node(ENTRY, env)
453
+ `;
454
+ }
455
+ //#endregion
456
+ //#region src/_modal-output.ts
457
+ /**
458
+ * Assemble a self-contained Modal deployment directory — `.aai/modal/`.
459
+ *
460
+ * The runtime files are `_target-output.ts`, shared with the Deno emit for the
461
+ * reason that module's doc gives: neither host installs anything, so both need
462
+ * the same three files carried in beside the bundled entry.
463
+ *
464
+ * Modal's own half is the fourth file, `app.py`. It is what makes this target
465
+ * different in kind from the other two — Vercel and Deno are each pointed at a
466
+ * directory and work out the rest, while `modal deploy` RUNS a Python module
467
+ * that declares the image, the app and the function. See `_modal-app.ts`.
468
+ *
469
+ * The `app.py` is written LAST, after the directory it describes exists. That
470
+ * ordering has no failure to point at yet; it is here because the file's
471
+ * `add_local_dir(HERE, …)` is a claim about this directory's contents, and a
472
+ * half-assembled directory is a worse thing to hand a user than a missing one.
473
+ */
474
+ /** Write `.aai/modal/` for this project. */
475
+ async function emitModalOutput(cwd, options) {
476
+ const { name, ...emitOptions } = options;
477
+ const outputDir = await emitSelfContainedOutput(cwd, {
478
+ outputDir: MODAL_OUTPUT_DIR,
479
+ entryFile: MODAL_ENTRY_FILE,
480
+ entrySource: MODAL_ENTRY_SOURCE,
481
+ name: "modal"
482
+ }, emitOptions);
483
+ await fs.writeFile(path.join(outputDir, MODAL_APP_FILE), modalAppSource({ name }), "utf-8");
484
+ }
485
+ //#endregion
486
+ //#region src/_vercel-output.ts
487
+ /**
488
+ * Assemble a PREBUILT Vercel deployment — `.vercel/output/` — from what
489
+ * `aai build` just produced.
490
+ *
491
+ * The argument for the Build Output API over an `api/` entry is in
492
+ * `_vercel-target.ts` at {@link VERCEL_OUTPUT_DIR}; what this module adds is the
493
+ * consequence of it. A `.func` directory is a directory WE fill, so every file
494
+ * the server reads at runtime is present because it was copied in, and nothing
495
+ * depends on a static tracer following a path it structurally cannot:
496
+ *
497
+ * - **`.aai/worker.mjs`** is loaded through `import(pathToFileURL(...))`
498
+ * (`start.ts`), which `@vercel/nft` cannot resolve. Under the `api/` shape
499
+ * the build was green and the function 500'd on its first request with
500
+ * "No built agent at .aai/worker.mjs".
501
+ * - **`.env.example`** is not documentation here. `resolveServerEnv` treats it
502
+ * as the DECLARATION of which variables become `ctx.env` (see
503
+ * `DEPLOY_ENV_FILES`), so a function without it hands every tool an empty
504
+ * env while the Vercel project has the values set — a failure that looks
505
+ * like a credential problem and is a packaging one.
506
+ * - **The client** is copied to `static/`, where the CDN serves it, and also
507
+ * beside the worker, so `resolveClientDir` finds a real directory rather
508
+ * than reaching into a `node_modules` that the bundle replaced.
509
+ *
510
+ * The entry is BUNDLED rather than shipped with a `node_modules` — see
511
+ * `_target-bundle.ts`, which every target that emits an entry shares.
512
+ */
513
+ /**
514
+ * Files copied verbatim into the function, each one read at RUNTIME by a path
515
+ * no bundler can see. A missing one is skipped rather than fatal.
516
+ *
517
+ * **`.env` is deliberately NOT here.** `resolveServerEnv` reads
518
+ * {@link DEPLOY_ENV_FILES} — `.env.example` then `.env` — but only the first is
519
+ * a DECLARATION; the second holds a developer's own keys, and copying it would
520
+ * bake them into a deployment artifact and let them silently win over the
521
+ * values set in the Vercel project. Declarations ship, values come from the
522
+ * platform environment. Verified by building the `simple` template: a local
523
+ * `.env` with live credentials landed in the function until this list dropped
524
+ * it.
525
+ */
526
+ const RUNTIME_FILES = [WORKER_ARTIFACT_REL, ".env.example"];
527
+ /**
528
+ * Write `.vercel/output/` for this project.
529
+ *
530
+ * The directory is REMOVED first. It is not addressed by content, so a
531
+ * function or a static asset left by an earlier build with a different shape
532
+ * would be deployed alongside this one — and `vercel deploy --prebuilt`
533
+ * uploads whatever is there.
534
+ */
535
+ async function emitVercelOutput(cwd, options = {}) {
536
+ const outputDir = path.join(cwd, VERCEL_OUTPUT_DIR);
537
+ const functionDir = path.join(cwd, VERCEL_FUNCTION_DIR);
538
+ const staticDir = path.join(cwd, VERCEL_STATIC_DIR);
539
+ await fs.rm(outputDir, {
540
+ recursive: true,
541
+ force: true
542
+ });
543
+ await fs.mkdir(functionDir, { recursive: true });
544
+ await fs.writeFile(path.join(outputDir, "config.json"), VERCEL_BUILD_CONFIG_SOURCE, "utf-8");
545
+ await fs.writeFile(path.join(functionDir, ".vc-config.json"), vercelFunctionConfigSource(), "utf-8");
546
+ const bundle = options.bundle ?? ((dir) => bundleTargetEntry(dir, VERCEL_ENTRY_SOURCE, "vercel"));
547
+ await fs.writeFile(path.join(functionDir, "index.mjs"), await bundle(cwd), "utf-8");
548
+ for (const rel of RUNTIME_FILES) {
549
+ const from = path.join(cwd, rel);
550
+ if (!await targetPathExists(from)) continue;
551
+ const to = path.join(functionDir, rel);
552
+ await fs.mkdir(path.dirname(to), { recursive: true });
553
+ await fs.copyFile(from, to);
554
+ }
555
+ const clientSource = await targetPathExists(path.join(cwd, CLIENT_ARTIFACT_REL, "index.html")) ? path.join(cwd, CLIENT_ARTIFACT_REL) : defaultClientDir();
556
+ await fs.cp(clientSource, staticDir, { recursive: true });
557
+ await fs.cp(clientSource, path.join(functionDir, CLIENT_ARTIFACT_REL), { recursive: true });
558
+ }
559
+ //#endregion
560
+ //#region src/build.ts
561
+ /**
562
+ * `aai build` — bundle the agent without deploying, behind the same gates
563
+ * deploy runs (tests, then typecheck), so the command previews the deploy
564
+ * artifact and its failures alike.
565
+ *
566
+ * It also LEAVES that artifact on disk, at {@link WORKER_ARTIFACT_REL}, which is
567
+ * what makes self-hosting work: `aai start` loads the built worker rather than
568
+ * `agent.ts`, because a tool is discovered by the bundler enumerating `tools/`
569
+ * and no un-bundled loader can see that directory. See `start.ts` and
570
+ * "Self-hosting is the scaffold's default" in `packages/aai-cli/CLAUDE.md`.
571
+ *
572
+ * `--target` decides what else it emits — see `_build-target.ts`.
573
+ */
574
+ /**
575
+ * The prose slot, named by convention. Mirrors `worker-bundler.ts`'s constant of
576
+ * the same name — the two cannot share one without an import cycle
577
+ * (`build.ts` → `_bundler.ts` → `worker-bundler.ts`), so `_build.test.ts` pins
578
+ * the pair end to end instead: a build whose prompt really came from the file
579
+ * has to report the file.
580
+ */
581
+ const SYSTEM_PROMPT_FILE = "system-prompt.md";
582
+ /** What {@link systemPromptSource} reports when nothing declared a prompt. */
583
+ const FRAMEWORK_DEFAULT_PROMPT_SOURCE = "the framework default (DEFAULT_SYSTEM_PROMPT)";
584
+ /**
585
+ * Which of the three possible authors of this agent's system prompt actually
586
+ * wrote the one in the bundle.
587
+ *
588
+ * `aai build` reported `name` and `workerBytes` and nothing about the prompt,
589
+ * and the prompt is the one field that can change COMPLETELY without any
590
+ * config changing: deleting `system-prompt.md` swaps in
591
+ * `DEFAULT_SYSTEM_PROMPT` — a total personality change — with exit 0 and no
592
+ * line anywhere. `withSystemPrompt` refuses the case where a file exists and
593
+ * nothing reads it; it cannot refuse a file that is simply GONE, because that
594
+ * is what an agent with no file legitimately looks like. So this is a report
595
+ * rather than a check.
596
+ *
597
+ * Decided by comparing VALUES against the built agent's resolved prompt, which
598
+ * is the same method `withSystemPrompt` uses and for the same reason — the
599
+ * alternative asks the bundler's module graph a question, and the author may
600
+ * have imported the file and composed it, which is neither "the file" nor
601
+ * "agent.ts" alone.
602
+ */
603
+ async function systemPromptSource(cwd, resolved) {
604
+ if (resolved === DEFAULT_SYSTEM_PROMPT) return FRAMEWORK_DEFAULT_PROMPT_SOURCE;
605
+ const trimmed = (await fs.readFile(path.join(cwd, SYSTEM_PROMPT_FILE), "utf-8").catch(() => void 0))?.trim();
606
+ if (trimmed === void 0 || trimmed === "" || !resolved.includes(trimmed)) return "agent.ts";
607
+ return resolved.trim() === trimmed ? SYSTEM_PROMPT_FILE : `agent.ts (composing ${SYSTEM_PROMPT_FILE})`;
608
+ }
609
+ /**
610
+ * Map a {@link runVitest} failure to a CliError — distinguishing a real test
611
+ * failure (test_failed) from the runner not spawning (spawn_failed) instead
612
+ * of a generic command_failed.
613
+ */
614
+ function testGateError(err) {
615
+ const { code, message } = classifyVitestError(err);
616
+ return new CliError(code, message, "Re-run with --skipTests to build without tests", { cause: err });
617
+ }
618
+ async function executeBuild(opts) {
619
+ const { cwd } = opts;
620
+ const target = resolveBuildTarget(opts.target);
621
+ if (!opts.skipTests) try {
622
+ runVitest(cwd, {
623
+ candidates: TEST_FILES,
624
+ all: true
625
+ });
626
+ } catch (err) {
627
+ throw testGateError(err);
628
+ }
629
+ await assertTypechecks(cwd, { skip: opts.skipTypecheck });
630
+ const bundle = await buildAgentBundle(cwd, { minify: true });
631
+ const agentDef = await evalWorkerBundle(bundle.worker);
632
+ for (const warning of agentConfigWarnings(agentDef)) notify("warn", warning);
633
+ for (const warning of determinismWarnings(await scanWorkflowDeterminism(cwd))) notify("warn", warning);
634
+ const worker = path.join(cwd, WORKER_ARTIFACT_REL);
635
+ await fs.mkdir(path.dirname(worker), { recursive: true });
636
+ await fs.writeFile(worker, bundle.worker, "utf-8");
637
+ await emitTargetFiles(cwd, target, { name: agentDef.name });
638
+ const output = TARGET_OUTPUTS[target];
639
+ if (output.dir !== void 0) log.info(`Target ${target}: wrote ${output.dir}`);
640
+ if (output.deploy !== void 0) log.info(`Deploy it with \`${output.deploy}\``);
641
+ const systemPrompt = await systemPromptSource(cwd, agentDef.systemPrompt);
642
+ log.info(`System prompt: ${systemPrompt}`);
643
+ log.success("Build complete");
644
+ return ok({
645
+ name: agentDef.name,
646
+ workerBytes: bundle.worker.length,
647
+ worker,
648
+ systemPrompt,
649
+ target,
650
+ outputDir: output.dir,
651
+ deploy: output.deploy
652
+ });
653
+ }
654
+ /**
655
+ * Write what a target needs, if it needs anything.
656
+ *
657
+ * `node` writes nothing: a long-lived process runs `aai start`, which needs no
658
+ * generated file. `vercel` writes a complete prebuilt deployment under
659
+ * `.vercel/output/` — see `_vercel-output.ts`, and `VERCEL_OUTPUT_DIR` in
660
+ * `_vercel-target.ts` for why that directory and not an `api/` entry beside a
661
+ * generated `vercel.json`. `deno` and `modal` write a self-contained directory
662
+ * each — `_target-output.ts` for the half they share.
663
+ *
664
+ * WHERE each lands and how it is deployed is `TARGET_OUTPUTS`, not this
665
+ * function, and the caller reports it. Those strings were a `log.info` per
666
+ * `case` and drifted the way a per-arm string does: `vercel` named its
667
+ * directory and no deploy command at all.
668
+ *
669
+ * The agent's `name` reaches only `modal`, which needs it for the app name a
670
+ * deployment is served under. It is threaded through rather than re-read
671
+ * because `executeBuild` has already evaluated the bundle to report it.
672
+ */
673
+ async function emitTargetFiles(cwd, target, agent) {
674
+ switch (target) {
675
+ case "node": return;
676
+ case "vercel":
677
+ await emitVercelOutput(cwd);
678
+ return;
679
+ case "deno":
680
+ await emitDenoOutput(cwd);
681
+ return;
682
+ case "modal":
683
+ await emitModalOutput(cwd, { name: agent.name });
684
+ return;
685
+ default: throw new Error(`Unhandled build target ${String(target)}`);
686
+ }
687
+ }
688
+ //#endregion
689
+ export { executeBuild };