@alexkroman1/aai-cli 15.0.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 (363) 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 +14 -20
  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-CFyusRbq.mjs → init-D363Ls5u.mjs} +13 -39
  26. package/dist/init.d.ts +5 -10
  27. package/dist/scaffold/CLAUDE.md +185 -35
  28. package/dist/scaffold/package.json +4 -4
  29. package/dist/start.mjs +3 -1
  30. package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
  31. package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
  32. package/dist/templates/briefing-desk/agent.test.ts +347 -55
  33. package/dist/templates/briefing-desk/agent.ts +12 -0
  34. package/dist/templates/briefing-desk/shared.ts +220 -31
  35. package/dist/templates/briefing-desk/slack.ts +108 -0
  36. package/dist/templates/briefing-desk/system-prompt.md +12 -2
  37. package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
  38. package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
  39. package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
  40. package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
  41. package/dist/templates/call-audit/agent.eval.test.ts +5 -0
  42. package/dist/templates/call-audit/agent.test.ts +6 -1
  43. package/dist/templates/call-audit/agent.ts +10 -23
  44. package/dist/templates/call-audit/client.tsx +30 -55
  45. package/dist/templates/call-audit/guards.test.ts +233 -0
  46. package/dist/templates/call-audit/workflows/audit.ts +95 -16
  47. package/dist/templates/call-audit/workflows/ingest.ts +107 -88
  48. package/dist/templates/call-audit/workflows/media.ts +98 -7
  49. package/dist/templates/call-audit/workflows/summarize.ts +35 -31
  50. package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
  51. package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
  52. package/dist/templates/code-interpreter/agent.test.ts +44 -56
  53. package/dist/templates/code-interpreter/system-prompt.md +1 -1
  54. package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
  55. package/dist/templates/dispatch-center/agent.test.ts +253 -48
  56. package/dist/templates/dispatch-center/agent.ts +28 -1
  57. package/dist/templates/dispatch-center/client.tsx +126 -201
  58. package/dist/templates/dispatch-center/events.ts +48 -0
  59. package/dist/templates/dispatch-center/shared.ts +42 -1
  60. package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
  61. package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
  62. package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
  63. package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
  64. package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
  65. package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
  66. package/dist/templates/executive-assistant/agent.test.ts +672 -0
  67. package/dist/templates/executive-assistant/agent.ts +50 -0
  68. package/dist/templates/executive-assistant/calendar.test.ts +198 -0
  69. package/dist/templates/executive-assistant/client.tsx +195 -0
  70. package/dist/templates/executive-assistant/inbox.ts +233 -0
  71. package/dist/templates/executive-assistant/meeting.ts +138 -0
  72. package/dist/templates/executive-assistant/nodes.ts +152 -0
  73. package/dist/templates/executive-assistant/prompts.ts +331 -0
  74. package/dist/templates/executive-assistant/review.ts +425 -0
  75. package/dist/templates/executive-assistant/shared.ts +490 -0
  76. package/dist/templates/executive-assistant/system-prompt.md +15 -0
  77. package/dist/templates/executive-assistant/tools/accept.ts +10 -0
  78. package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
  79. package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
  80. package/dist/templates/executive-assistant/tools/edit.ts +10 -0
  81. package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
  82. package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
  83. package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
  84. package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
  85. package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
  86. package/dist/templates/executive-assistant/tools/respond.ts +10 -0
  87. package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
  88. package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
  89. package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
  90. package/dist/templates/health-assistant/agent.test.ts +134 -15
  91. package/dist/templates/health-assistant/agent.ts +8 -1
  92. package/dist/templates/health-assistant/fda.test.ts +130 -0
  93. package/dist/templates/health-assistant/fda.ts +75 -16
  94. package/dist/templates/health-assistant/system-prompt.md +9 -0
  95. package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
  96. package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
  97. package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
  98. package/dist/templates/hiring-desk/agent.test.ts +1021 -0
  99. package/dist/templates/hiring-desk/agent.ts +38 -0
  100. package/dist/templates/hiring-desk/client.tsx +154 -0
  101. package/dist/templates/hiring-desk/crews.ts +432 -0
  102. package/dist/templates/hiring-desk/leads.json +86 -0
  103. package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
  104. package/dist/templates/hiring-desk/screening-lock.ts +51 -0
  105. package/dist/templates/hiring-desk/shared.ts +480 -0
  106. package/dist/templates/hiring-desk/system-prompt.md +21 -0
  107. package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
  108. package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
  109. package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
  110. package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
  111. package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
  112. package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
  113. package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
  114. package/dist/templates/hotel-desk/agent.test.ts +1128 -0
  115. package/dist/templates/hotel-desk/agent.ts +63 -0
  116. package/dist/templates/hotel-desk/booking.ts +159 -0
  117. package/dist/templates/hotel-desk/card.ts +92 -0
  118. package/dist/templates/hotel-desk/catalogs.ts +219 -0
  119. package/dist/templates/hotel-desk/client.tsx +137 -0
  120. package/dist/templates/hotel-desk/concierge.ts +99 -0
  121. package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
  122. package/dist/templates/hotel-desk/desk.ts +224 -0
  123. package/dist/templates/hotel-desk/disputes.ts +216 -0
  124. package/dist/templates/hotel-desk/events.ts +79 -0
  125. package/dist/templates/hotel-desk/hotel.ts +412 -0
  126. package/dist/templates/hotel-desk/policies.ts +209 -0
  127. package/dist/templates/hotel-desk/records.ts +384 -0
  128. package/dist/templates/hotel-desk/restaurant.ts +147 -0
  129. package/dist/templates/hotel-desk/seed.ts +955 -0
  130. package/dist/templates/hotel-desk/shared.ts +354 -0
  131. package/dist/templates/hotel-desk/system-prompt.md +76 -0
  132. package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
  133. package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
  134. package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
  135. package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
  136. package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
  137. package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
  138. package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
  139. package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
  140. package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
  141. package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
  142. package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
  143. package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
  144. package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
  145. package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
  146. package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
  147. package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
  148. package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
  149. package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
  150. package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
  151. package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
  152. package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
  153. package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
  154. package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
  155. package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
  156. package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
  157. package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
  158. package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
  159. package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
  160. package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
  161. package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
  162. package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
  163. package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
  164. package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
  165. package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
  166. package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
  167. package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
  168. package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
  169. package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
  170. package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
  171. package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
  172. package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
  173. package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
  174. package/dist/templates/infocom-adventure/agent.test.ts +207 -52
  175. package/dist/templates/infocom-adventure/agent.ts +14 -3
  176. package/dist/templates/infocom-adventure/client.tsx +138 -176
  177. package/dist/templates/infocom-adventure/shared.ts +126 -6
  178. package/dist/templates/infocom-adventure/system-prompt.md +4 -4
  179. package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
  180. package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
  181. package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
  182. package/dist/templates/link-digest/agent.eval.test.ts +8 -0
  183. package/dist/templates/link-digest/agent.test.ts +285 -29
  184. package/dist/templates/link-digest/agent.ts +9 -0
  185. package/dist/templates/link-digest/api-client.ts +144 -0
  186. package/dist/templates/link-digest/client.tsx +11 -30
  187. package/dist/templates/link-digest/workflows/digest.ts +72 -24
  188. package/dist/templates/night-owl/agent.eval.test.ts +55 -40
  189. package/dist/templates/night-owl/agent.test.ts +146 -12
  190. package/dist/templates/night-owl/client.tsx +50 -17
  191. package/dist/templates/night-owl/shared.ts +33 -2
  192. package/dist/templates/night-owl/system-prompt.md +3 -0
  193. package/dist/templates/night-owl/tools/recommend.ts +4 -1
  194. package/dist/templates/night-owl/tools/revisit.ts +49 -0
  195. package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
  196. package/dist/templates/pipeline-simple/agent.test.ts +48 -91
  197. package/dist/templates/pipeline-simple/modes.test.ts +151 -0
  198. package/dist/templates/pipeline-simple/stages.test.ts +332 -0
  199. package/dist/templates/pizza-ordering/agent.test.ts +94 -38
  200. package/dist/templates/pizza-ordering/client.tsx +10 -5
  201. package/dist/templates/pizza-ordering/shared.ts +65 -6
  202. package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
  203. package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
  204. package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
  205. package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
  206. package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
  207. package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
  208. package/dist/templates/plan-and-execute/agent.test.ts +300 -113
  209. package/dist/templates/plan-and-execute/client.tsx +18 -7
  210. package/dist/templates/plan-and-execute/procedure.ts +162 -64
  211. package/dist/templates/plan-and-execute/prompts.ts +51 -15
  212. package/dist/templates/plan-and-execute/shared.ts +151 -45
  213. package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
  214. package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
  215. package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
  216. package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
  217. package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
  218. package/dist/templates/podcast-digest/agent.test.ts +126 -51
  219. package/dist/templates/podcast-digest/client.tsx +104 -68
  220. package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
  221. package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
  222. package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
  223. package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
  224. package/dist/templates/recap-workflow/agent.test.ts +207 -26
  225. package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
  226. package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
  227. package/dist/templates/redline/agent.eval.test.ts +40 -3
  228. package/dist/templates/redline/agent.test.ts +216 -6
  229. package/dist/templates/redline/agent.ts +54 -34
  230. package/dist/templates/redline/client.tsx +82 -126
  231. package/dist/templates/redline/form.ts +74 -0
  232. package/dist/templates/redline/workflows/prompts.ts +3 -3
  233. package/dist/templates/redline/workflows/redline.ts +73 -4
  234. package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
  235. package/dist/templates/research-workflow/agent.test.ts +436 -126
  236. package/dist/templates/research-workflow/agent.ts +20 -5
  237. package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
  238. package/dist/templates/research-workflow/tools/research_status.ts +39 -4
  239. package/dist/templates/research-workflow/workflows/filing.ts +164 -0
  240. package/dist/templates/research-workflow/workflows/notes.ts +69 -0
  241. package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
  242. package/dist/templates/research-workflow/workflows/research.ts +227 -280
  243. package/dist/templates/research-workflow/workflows/review.ts +43 -0
  244. package/dist/templates/retail/address.ts +29 -35
  245. package/dist/templates/retail/agent.eval.test.ts +36 -16
  246. package/dist/templates/retail/agent.test.ts +104 -26
  247. package/dist/templates/retail/agent.ts +12 -0
  248. package/dist/templates/retail/cancel.ts +39 -42
  249. package/dist/templates/retail/client.tsx +111 -176
  250. package/dist/templates/retail/payment.ts +38 -43
  251. package/dist/templates/retail/pending.test.ts +16 -8
  252. package/dist/templates/retail/registry.test.ts +108 -49
  253. package/dist/templates/retail/resolve.test.ts +2 -63
  254. package/dist/templates/retail/resolve.ts +16 -56
  255. package/dist/templates/retail/returns.ts +53 -54
  256. package/dist/templates/retail/seed.test.ts +2 -1
  257. package/dist/templates/retail/shared.ts +58 -14
  258. package/dist/templates/retail/store.test.ts +40 -29
  259. package/dist/templates/retail/store.ts +60 -23
  260. package/dist/templates/retail/swap.ts +78 -81
  261. package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
  262. package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
  263. package/dist/templates/roadside-assist/agent.test.ts +617 -0
  264. package/dist/templates/roadside-assist/agent.ts +85 -0
  265. package/dist/templates/roadside-assist/call.ts +237 -0
  266. package/dist/templates/roadside-assist/events.ts +92 -0
  267. package/dist/templates/roadside-assist/shared.ts +334 -0
  268. package/dist/templates/roadside-assist/system-prompt.md +37 -0
  269. package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
  270. package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
  271. package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
  272. package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
  273. package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
  274. package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
  275. package/dist/templates/roadside-assist/yard.test.ts +158 -0
  276. package/dist/templates/roadside-assist/yard.ts +183 -0
  277. package/dist/templates/simple/agent.eval.test.ts +4 -1
  278. package/dist/templates/simple/agent.test.ts +54 -31
  279. package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
  280. package/dist/templates/solo-rpg/agent.test.ts +402 -175
  281. package/dist/templates/solo-rpg/agent.ts +14 -3
  282. package/dist/templates/solo-rpg/client.tsx +10 -10
  283. package/dist/templates/solo-rpg/shared.ts +198 -79
  284. package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
  285. package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
  286. package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
  287. package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
  288. package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
  289. package/dist/templates/spoken-summary/agent.test.ts +70 -15
  290. package/dist/templates/spoken-summary/agent.ts +25 -21
  291. package/dist/templates/spoken-summary/client.tsx +68 -88
  292. package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
  293. package/dist/templates/support-line/agent.test.ts +167 -36
  294. package/dist/templates/support-line/client.tsx +21 -9
  295. package/dist/templates/support-line/nodes.ts +74 -32
  296. package/dist/templates/support-line/procedure.ts +66 -21
  297. package/dist/templates/support-line/prompts.ts +9 -0
  298. package/dist/templates/support-line/shared.ts +55 -17
  299. package/dist/templates/support-line/tools/answer_question.ts +14 -14
  300. package/dist/templates/transcription-workflow/agent.test.ts +135 -13
  301. package/dist/templates/transcription-workflow/client.tsx +30 -23
  302. package/dist/templates/transcription-workflow/recover.test.ts +93 -12
  303. package/dist/templates/transcription-workflow/recover.ts +29 -5
  304. package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
  305. package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
  306. package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
  307. package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
  308. package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
  309. package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
  310. package/dist/templates/travel-concierge/agent.test.ts +209 -40
  311. package/dist/templates/travel-concierge/agent.ts +24 -4
  312. package/dist/templates/travel-concierge/call-events.ts +80 -0
  313. package/dist/templates/travel-concierge/client.tsx +3 -2
  314. package/dist/templates/travel-concierge/routing.ts +5 -7
  315. package/dist/templates/travel-concierge/shared.ts +202 -41
  316. package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
  317. package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
  318. package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
  319. package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
  320. package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
  321. package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
  322. package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
  323. package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
  324. package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
  325. package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
  326. package/dist/templates/web-researcher/agent.test.ts +102 -65
  327. package/dist/templates/web-researcher/agent.ts +93 -1
  328. package/dist/templates/web-researcher/system-prompt.md +7 -1
  329. package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
  330. package/dist/templates/word-wrangler/agent.test.ts +432 -0
  331. package/dist/templates/word-wrangler/agent.ts +35 -0
  332. package/dist/templates/word-wrangler/client.tsx +211 -0
  333. package/dist/templates/word-wrangler/game.ts +107 -0
  334. package/dist/templates/word-wrangler/guess.ts +63 -0
  335. package/dist/templates/word-wrangler/player.ts +68 -0
  336. package/dist/templates/word-wrangler/shared.ts +263 -0
  337. package/dist/templates/word-wrangler/system-prompt.md +15 -0
  338. package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
  339. package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
  340. package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
  341. package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
  342. package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
  343. package/dist/templates/word-wrangler/words.ts +278 -0
  344. package/dist/test-Cllnx81G.mjs +83 -0
  345. package/dist/test.d.ts +9 -114
  346. package/package.json +5 -5
  347. package/dist/build-BhEaxBPu.mjs +0 -481
  348. package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
  349. package/dist/templates/embedded-assets/agent.test.ts +0 -79
  350. package/dist/templates/embedded-assets/agent.ts +0 -7
  351. package/dist/templates/embedded-assets/knowledge.json +0 -20
  352. package/dist/templates/embedded-assets/shared.ts +0 -17
  353. package/dist/templates/embedded-assets/system-prompt.md +0 -13
  354. package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
  355. package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
  356. package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
  357. package/dist/templates/math-buddy/agent.test.ts +0 -126
  358. package/dist/templates/math-buddy/agent.ts +0 -15
  359. package/dist/templates/math-buddy/system-prompt.md +0 -12
  360. package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
  361. package/dist/templates/personal-finance/agent.test.ts +0 -127
  362. package/dist/templates/personal-finance/agent.ts +0 -8
  363. package/dist/templates/personal-finance/system-prompt.md +0 -21
@@ -0,0 +1,52 @@
1
+ import { toolFailure } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+ import { EXECUTIVE } from "../inbox.ts";
4
+ import { findMeetingTime } from "../meeting.ts";
5
+ import { threadText } from "../prompts.ts";
6
+ import { assistantSlot, DRAFTING, openEmail, reviewFlow } from "../shared.ts";
7
+
8
+ /**
9
+ * Their `MeetingAssistant` → `find_meeting_time`: a specialist reads the
10
+ * calendar and reports the free slots, and the report comes back as this
11
+ * tool's result — their `ToolMessage` back into `draft_response`. The
12
+ * specialist is a subagent (`../meeting.ts`), so the calendar lookups never
13
+ * reach this conversation; what does is one dense sentence.
14
+ *
15
+ * No `send`: the call stays in `drafting`, because knowing the free slots is
16
+ * not yet a proposal. `draft_reply` or `send_calendar_invite` comes next.
17
+ *
18
+ * A report the specialist's guardrail never accepted is handed on anyway, with
19
+ * `usable: false` and a different `next` — the desk is on a live call and there
20
+ * IS an answer, so a `ToolFailure` would throw away the one thing it learned.
21
+ */
22
+ export default reviewFlow.tool({
23
+ description:
24
+ `Ask the meeting assistant when ${EXECUTIVE.name} is free, for an email that is trying to ` +
25
+ "set up a meeting. It reads the calendar and answers with the open slots. Say you are " +
26
+ "checking the calendar before you call it — it takes a moment.",
27
+ when: DRAFTING,
28
+ inputSchema: z.object({
29
+ request: z
30
+ .string()
31
+ .min(1)
32
+ .max(300)
33
+ .describe("What the sender is asking for — which days, how long, any times they ruled out"),
34
+ }),
35
+ async execute(args, ctx) {
36
+ const email = openEmail(assistantSlot.get(ctx));
37
+ if (!email) return toolFailure("No email is open — call open_email first.");
38
+ const found = await findMeetingTime(ctx.delegate, threadText(email), args.request);
39
+ return assistantSlot.update(ctx, (state) => {
40
+ state.exchange.push(`Meeting assistant: ${found.availability}`);
41
+ state.log.push(`Checked the calendar (${found.lookups} lookups)`);
42
+ return {
43
+ ...found,
44
+ next: found.usable
45
+ ? "Offer these times in draft_reply, or send_calendar_invite if the meeting should be " +
46
+ "booked outright."
47
+ : `The assistant did not name a time, so there is nothing to offer. Ask ${EXECUTIVE.name} ` +
48
+ "what to do, or ask again with the days the sender suggested. Do not invent a slot.",
49
+ };
50
+ });
51
+ },
52
+ });
@@ -0,0 +1,50 @@
1
+ import { toolFailure } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+ import { EXECUTIVE } from "../inbox.ts";
4
+ import { rewriteDraft } from "../nodes.ts";
5
+ import { threadText } from "../prompts.ts";
6
+ import { propose } from "../review.ts";
7
+ import { assistantSlot, DRAFTING, openEmail, reviewFlow } from "../shared.ts";
8
+
9
+ /**
10
+ * Their `NewEmailDraft` — a fresh thread, such as the introduction the open
11
+ * email asked for. Declared in their drafting tool list; their `take_action`
12
+ * has no arm for it and routes it to `bad_tool_name`, so this is the arm the
13
+ * prompt describes — rewritten and staged like a reply, sent only by `accept`.
14
+ */
15
+ export default reviewFlow.tool({
16
+ description:
17
+ `Start a NEW email thread from ${EXECUTIVE.name} — for an introduction they agreed to make, ` +
18
+ "or a note the open email calls for to someone not on it. Full text, their voice. Staged " +
19
+ "for read-back, not sent.",
20
+ when: DRAFTING,
21
+ send: { type: "PROPOSED" },
22
+ inputSchema: z.object({
23
+ recipients: z
24
+ .array(z.string().max(120))
25
+ .min(1)
26
+ .max(5)
27
+ .describe("Who it goes to — real addresses you have, never invented"),
28
+ content: z.string().min(1).max(4000).describe("The complete email"),
29
+ }),
30
+ async execute(args, ctx) {
31
+ const state = assistantSlot.get(ctx);
32
+ const email = openEmail(state);
33
+ if (!email) return toolFailure("No email is open — call open_email first.");
34
+ const tone = await rewriteDraft(
35
+ ctx.generate,
36
+ EXECUTIVE,
37
+ state.memory.rewriteInstructions,
38
+ args.content,
39
+ threadText(email),
40
+ );
41
+ return assistantSlot.update(ctx, (draft) =>
42
+ propose(draft, {
43
+ kind: "new_email",
44
+ content: tone.rewrittenContent,
45
+ recipients: [...args.recipients],
46
+ toneLogic: tone.toneLogic,
47
+ }),
48
+ );
49
+ },
50
+ });
@@ -0,0 +1,165 @@
1
+ import {
2
+ type DeepReadonly,
3
+ isToolFailure,
4
+ type ResolveOneOptions,
5
+ resolveOne,
6
+ toolFailure,
7
+ } from "@alexkroman1/aai";
8
+ import { z } from "zod";
9
+ import { EXECUTIVE } from "../inbox.ts";
10
+ import { triageEmail } from "../nodes.ts";
11
+ import { draftingBrief, threadText } from "../prompts.ts";
12
+ import { readBackFor } from "../review.ts";
13
+ import {
14
+ ALLOWED,
15
+ AT_INBOX,
16
+ assistantSlot,
17
+ type FrozenAssistantState,
18
+ findEmail,
19
+ type InboxEmail,
20
+ nextToOpen,
21
+ reviewFlow,
22
+ similarExamples,
23
+ } from "../shared.ts";
24
+
25
+ /**
26
+ * Words too common in a subject line to be what the executive meant — "the
27
+ * Northwind one" is about Northwind. Six of them, kept short deliberately: a
28
+ * longer list starts deciding which real words do not count.
29
+ */
30
+ const FILLER = new Set(["the", "that", "one", "your", "with", "for"]);
31
+
32
+ const wordsIn = (text: string) =>
33
+ (text.toLowerCase().match(/[a-z0-9]{3,}/g) ?? []).filter((word) => !FILLER.has(word));
34
+
35
+ /**
36
+ * How the executive refers to an email when they are not reading an id: by who
37
+ * sent it and what it is about. The SENDER and SUBJECT only — a body match on
38
+ * "meeting" would tie half the inbox.
39
+ */
40
+ const BY_WHAT_IT_IS: ResolveOneOptions<DeepReadonly<InboxEmail>> = {
41
+ label: "email",
42
+ describe: (email) => `${email.id}: "${email.subject}" from ${email.from}`,
43
+ score: (email, spoken) => {
44
+ const said = new Set(wordsIn(spoken));
45
+ return wordsIn(`${email.from} ${email.subject}`).filter((word) => said.has(word)).length;
46
+ },
47
+ };
48
+
49
+ /**
50
+ * The email the executive named — and the two ways they name one are two
51
+ * different problems.
52
+ *
53
+ * An ID came off a list this desk read out, so an exact lookup is the whole
54
+ * answer and a miss means no such email. THEIR OWN WORDS — "the one from Dana",
55
+ * "the second one" — are a pick among eight rows that look alike, where taking
56
+ * the first overlap opens the wrong thread and drafts a reply in the
57
+ * executive's name against it. So the desk narrows by its own vocabulary (the
58
+ * scorer above) and `resolveOne` owns the half a template should not re-derive:
59
+ * a position is taken as read, nothing matching and several matching are
60
+ * DIFFERENT answers, and both come back naming what it could have meant so the
61
+ * assistant can ask on its own turn.
62
+ */
63
+ function pick(state: FrozenAssistantState, which: string) {
64
+ const byId = findEmail(state.emails, which);
65
+ if (byId) return byId;
66
+ const live = state.emails.filter((email) => email.status !== "closed");
67
+ return resolveOne(live, which, BY_WHAT_IT_IS);
68
+ }
69
+
70
+ /**
71
+ * Start one thread's run — their graph's entry, from `triage_input` to the
72
+ * first node that needs a model.
73
+ *
74
+ * **The result IS the brief.** Their `draft_response` node reads
75
+ * `EMAIL_WRITING_INSTRUCTIONS` with the four memory prompts interpolated; a
76
+ * voice session's prompt is fixed at connect and memory changes mid-call, so the
77
+ * same text comes back as this tool's result — the last thing the model reads
78
+ * before it chooses a drafting tool, with whatever memory says NOW.
79
+ *
80
+ * Their `route_after_triage` is `sendFrom`: a `notify` skips drafting and lands
81
+ * straight in `awaitingDecision` with a heads-up staged, as their `notify` node
82
+ * halts for the human without drafting anything; `email` and `question` go to
83
+ * `drafting`. A `no` the executive opens anyway is opened — their `--rerun` —
84
+ * with the verdict in the result so the model knows it was filed.
85
+ *
86
+ * An untriaged email is triaged on the way in, so "open the one from Dana" works
87
+ * before `triage_inbox` has run.
88
+ */
89
+ export default reviewFlow.tool({
90
+ description:
91
+ "Open the next email that needs the executive — or the one they named, by id or in their " +
92
+ "own words — and get the thread plus your brief for handling it. Replies come before " +
93
+ "heads-ups. One email is open at a time; settle it before opening another.",
94
+ when: AT_INBOX,
95
+ inputSchema: z.object({
96
+ which: z
97
+ .string()
98
+ .max(120)
99
+ .describe(
100
+ "An email id from triage_inbox or inbox_status, or how the executive referred to it " +
101
+ "in their own words — who sent it, what it is about, or which one in the list. " +
102
+ "Leave it out for the next one that needs them.",
103
+ )
104
+ .optional(),
105
+ }),
106
+ async execute(args, ctx) {
107
+ const state = assistantSlot.get(ctx);
108
+ const target = args.which ? pick(state, args.which) : nextToOpen(state);
109
+ if (isToolFailure(target)) return target;
110
+ if (!target) {
111
+ return toolFailure(
112
+ "Nothing is queued. Run triage_inbox if you have not; otherwise the inbox is done.",
113
+ );
114
+ }
115
+ const verdict =
116
+ target.triage ??
117
+ (await triageEmail(
118
+ ctx.generate,
119
+ EXECUTIVE,
120
+ target,
121
+ similarExamples(state.triageExamples, target),
122
+ ));
123
+ return assistantSlot.update(ctx, (draft) => {
124
+ const email = findEmail(draft.emails, target.id);
125
+ if (!email) return toolFailure(`Email ${target.id} disappeared.`);
126
+ const reopened = email.status === "closed";
127
+ email.triage = verdict;
128
+ email.status = "open";
129
+ draft.openId = email.id;
130
+ draft.exchange = [`Draft a response to this email:\n\n${threadText(email)}`];
131
+ draft.log.push(`Opened: ${email.subject} (${verdict.response})`);
132
+ const thread = {
133
+ id: email.id,
134
+ from: email.from,
135
+ to: email.to,
136
+ subject: email.subject,
137
+ sentAt: email.sentAt,
138
+ body: email.body,
139
+ };
140
+ if (verdict.response === "notify") {
141
+ const proposal = { kind: "notify" as const };
142
+ draft.proposal = proposal;
143
+ draft.exchange.push("Assistant proposed — Heads-up: no reply needed.");
144
+ return {
145
+ route: "notify" as const,
146
+ email: thread,
147
+ triage: verdict,
148
+ allowed: ALLOWED.notify,
149
+ instructions: readBackFor(proposal),
150
+ };
151
+ }
152
+ return {
153
+ route: "draft" as const,
154
+ email: thread,
155
+ triage: verdict,
156
+ reopened,
157
+ instructions:
158
+ (verdict.response === "no"
159
+ ? `Triage filed this one as not worth a reply; ${EXECUTIVE.name} opened it anyway, so only draft if they ask. `
160
+ : "") + draftingBrief(EXECUTIVE, draft.memory),
161
+ };
162
+ });
163
+ },
164
+ sendFrom: (result) => ({ type: result.route === "notify" ? "NOTIFY" : "OPENED" }),
165
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `respond` — one of the four answers to a proposal, their `HumanResponse`
3
+ * `"respond"`. The four live together in `../review.ts` because they share the one
4
+ * place anything is sent and the reflection scope table; this file is what
5
+ * gives this one its name.
6
+ */
7
+
8
+ import { respondTool } from "../review.ts";
9
+
10
+ export default respondTool();
@@ -0,0 +1,22 @@
1
+ import { EXECUTIVE } from "../inbox.ts";
2
+ import { assistantSlot } from "../shared.ts";
3
+
4
+ /**
5
+ * What the assistant has learned — the four memory prompts their store holds,
6
+ * and every rewrite this call made to them. A read, so ungated: "what have you
7
+ * picked up about how I write?" is answerable at any point.
8
+ */
9
+ export default assistantSlot.tool({
10
+ description:
11
+ `Read back what you currently believe about how ${EXECUTIVE.name} likes emails written, ` +
12
+ "what to include, how to schedule, and the background you are working from — plus what " +
13
+ "you learned on this call. For when they ask what you have picked up, or to check a rule.",
14
+ execute: (_args, state) => ({
15
+ tone: state.memory.rewriteInstructions,
16
+ content: state.memory.responsePreferences || "(nothing yet)",
17
+ scheduling: state.memory.schedulePreferences,
18
+ background: state.memory.backgroundPreferences,
19
+ learnedThisCall: state.reflections.map((r) => `${r.memory}: ${r.logic}`),
20
+ examplesRemembered: state.triageExamples.length,
21
+ }),
22
+ });
@@ -0,0 +1,68 @@
1
+ import { clockTime, isoDate, spokenDate, spokenTime, toolFailure } from "@alexkroman1/aai";
2
+ import { z } from "zod";
3
+ import { EXECUTIVE } from "../inbox.ts";
4
+ import { clashOn } from "../meeting.ts";
5
+ import { propose } from "../review.ts";
6
+ import { assistantSlot, DRAFTING, reviewFlow } from "../shared.ts";
7
+
8
+ /**
9
+ * Their `SendCalendarInvite` → `send_cal_invite`: staged, read back, and sent
10
+ * by `accept` alone. Their schema's own warning rides on the field: "Do NOT
11
+ * make any emails up!"
12
+ *
13
+ * **The day and the two times are three CIVIL fields**, not one ISO datetime.
14
+ * The pair of regexes that shape used to carry accepted `2026-02-30T99:99` —
15
+ * both halves are checked now, by the same predicates the SDK's date and clock
16
+ * fields put in front of the model as JSON Schema, so a bad value is refused
17
+ * before `execute` runs rather than by a sentence written here. It also makes
18
+ * the read-back speakable: `2026-03-17T14:00:00` is what a TTS engine spells
19
+ * out digit by digit.
20
+ *
21
+ * **And the calendar is CHECKED.** The description asks for `meeting_assistant`
22
+ * first, and a rule the model can skip is not a rule (see `retail`'s
23
+ * confirmation gate): a slot the calendar already holds is refused here, naming
24
+ * what is in it, so the one tool that books time in the executive's name cannot
25
+ * double-book them because a model went straight to it.
26
+ */
27
+ export default reviewFlow.tool({
28
+ description:
29
+ `Book a meeting on ${EXECUTIVE.name}'s calendar and invite the people on the thread. Only ` +
30
+ "once you are sure they want it and meeting_assistant has said the slot is free. Staged " +
31
+ "for read-back, not sent.",
32
+ when: DRAFTING,
33
+ send: { type: "PROPOSED" },
34
+ inputSchema: z.object({
35
+ emails: z
36
+ .array(z.string().max(120))
37
+ .min(1)
38
+ .max(10)
39
+ .describe("Who to invite. Do NOT make any emails up!"),
40
+ title: z.string().min(1).max(120).describe("Name of the meeting"),
41
+ date: isoDate("the day of the meeting"),
42
+ startTime: clockTime(`when it starts, 24-hour, local to ${EXECUTIVE.timezone}`),
43
+ endTime: clockTime("when it ends, same format"),
44
+ }),
45
+ execute: (args, ctx) => {
46
+ if (args.endTime <= args.startTime) {
47
+ return toolFailure("The meeting ends before it starts — check the times.");
48
+ }
49
+ const clash = clashOn(args.date, args.startTime, args.endTime);
50
+ if (clash) {
51
+ return toolFailure(
52
+ `${EXECUTIVE.name} already has "${clash.title}" on ${spokenDate(args.date)} from ` +
53
+ `${spokenTime(clash.start)} to ${spokenTime(clash.end)}. Ask meeting_assistant for a ` +
54
+ "free slot and offer that instead.",
55
+ );
56
+ }
57
+ return assistantSlot.update(ctx, (state) =>
58
+ propose(state, {
59
+ kind: "invite",
60
+ emails: [...args.emails],
61
+ title: args.title,
62
+ date: args.date,
63
+ startTime: args.startTime,
64
+ endTime: args.endTime,
65
+ }),
66
+ );
67
+ },
68
+ });
@@ -0,0 +1,75 @@
1
+ import { EXECUTIVE } from "../inbox.ts";
2
+ import { triageEmail } from "../nodes.ts";
3
+ import { assistantSlot, closeEmail, findEmail, reviewFlow, similarExamples } from "../shared.ts";
4
+
5
+ /**
6
+ * Their `triage_input`, over every email that has not been triaged yet.
7
+ *
8
+ * **All of them at once, and that is the voice adaptation.** Their cron runs the
9
+ * graph once per thread as mail arrives; a caller wants to hear the shape of the
10
+ * inbox before opening anything, so the verdicts are fetched concurrently and
11
+ * applied in one window. Their `route_after_triage` is applied here too: a `no`
12
+ * is marked read on the spot (`filed`), and only `email`, `question` and
13
+ * `notify` are queued for the executive.
14
+ *
15
+ * The few-shot examples are chosen per email from what THIS call has settled —
16
+ * their `get_few_shot_examples`, over the session's own store.
17
+ */
18
+ export default reviewFlow.tool({
19
+ description:
20
+ "Triage every new email: decide which need a reply, which are just worth knowing " +
21
+ "about, and which to file unread. Call this first on a call, and again if new mail is " +
22
+ "mentioned. Tell the executive the counts, then open_email.",
23
+ when: "onCall",
24
+ async execute(_args, ctx) {
25
+ const state = assistantSlot.get(ctx);
26
+ const pending = state.emails.filter((email) => email.status === "untriaged");
27
+ const verdicts = await Promise.all(
28
+ pending.map(async (email) => ({
29
+ id: email.id,
30
+ verdict: await triageEmail(
31
+ ctx.generate,
32
+ EXECUTIVE,
33
+ email,
34
+ similarExamples(state.triageExamples, email),
35
+ ),
36
+ })),
37
+ );
38
+ return assistantSlot.update(ctx, (draft) => {
39
+ const filed: string[] = [];
40
+ for (const { id, verdict } of verdicts) {
41
+ const email = findEmail(draft.emails, id);
42
+ if (!email) continue;
43
+ email.triage = verdict;
44
+ if (verdict.response === "no") {
45
+ closeEmail(draft, email.id, "filed");
46
+ filed.push(email.subject);
47
+ } else {
48
+ email.status = "queued";
49
+ }
50
+ }
51
+ if (verdicts.length > 0) {
52
+ draft.log.push(
53
+ `Triaged ${verdicts.length}: ${verdicts.length - filed.length} queued, ${filed.length} filed`,
54
+ );
55
+ }
56
+ const queued = draft.emails.filter((email) => email.status === "queued");
57
+ const brief = (email: (typeof queued)[number]) => ({
58
+ id: email.id,
59
+ from: email.from,
60
+ subject: email.subject,
61
+ why: email.triage?.logic ?? "",
62
+ });
63
+ return {
64
+ triaged: verdicts.length,
65
+ needReply: queued.filter((email) => email.triage?.response !== "notify").map(brief),
66
+ headsUp: queued.filter((email) => email.triage?.response === "notify").map(brief),
67
+ filed,
68
+ next:
69
+ queued.length > 0
70
+ ? `Say how many need ${EXECUTIVE.name}, then open_email to start with the first.`
71
+ : "The inbox is clear.",
72
+ };
73
+ });
74
+ },
75
+ });
@@ -1,7 +1,19 @@
1
- import { isToolFailure } from "@alexkroman1/aai";
2
- import { toolInputIssues, toolRunner } from "@alexkroman1/aai/testing";
1
+ import {
2
+ type InferToolInput,
3
+ type InferToolOutput,
4
+ isToolFailure,
5
+ type ToolFailure,
6
+ } from "@alexkroman1/aai";
7
+ import {
8
+ expectDeployable,
9
+ expectPromptBuiltinsDeclared,
10
+ toolInputIssues,
11
+ toolRunner,
12
+ } from "@alexkroman1/aai/testing";
3
13
  import { beforeEach, describe, expect, test, vi } from "vitest";
4
14
  import { excerptAround, type FdaLabel, toDrugInfo } from "./fda.ts";
15
+ import type CheckDrugInteraction from "./tools/check_drug_interaction.ts";
16
+ import type MedicationLookup from "./tools/medication_lookup.ts";
5
17
 
6
18
  /**
7
19
  * Only the NETWORK half of `fda.ts` is faked.
@@ -32,6 +44,37 @@ import agentDef from "virtual:aai/agent";
32
44
  */
33
45
  const run = toolRunner(agentDef);
34
46
 
47
+ /**
48
+ * The two tools, reached through their OWN input types.
49
+ *
50
+ * `run` takes `Record<string, unknown>`, so `run("medication_lookup", { drug:
51
+ * "advil" })` compiles and fails at run time as a schema rejection — in the one
52
+ * spec that is supposed to be the worked example of calling this tool.
53
+ * `InferToolInput` reads the argument type off the tool's `execute`, which is
54
+ * the zod schema the tool really declares, so a renamed or retyped field breaks
55
+ * the BUILD here and the two files cannot drift apart quietly.
56
+ *
57
+ * The imports are TYPE-only, deliberately: the defs under test still come from
58
+ * `agentDef`, which is what a deploy resolves, and nothing here re-registers a
59
+ * tool module by importing it.
60
+ */
61
+ const lookUp = (args: InferToolInput<typeof MedicationLookup>) => run("medication_lookup", args);
62
+ const check = (args: InferToolInput<typeof CheckDrugInteraction>) =>
63
+ run("check_drug_interaction", args);
64
+
65
+ /**
66
+ * What `check_drug_interaction` answers when it did NOT refuse.
67
+ *
68
+ * `run` is typed `unknown` — the registry lookup is by string — so reading a
69
+ * field off the answer needs an assertion either way. `InferToolOutput` makes
70
+ * it an assertion about the tool's OWN return type rather than a shape retyped
71
+ * beside it, so renaming `interactions_found` reddens here instead of quietly
72
+ * comparing `undefined`. The SDK's `expectToolOk` is deliberately not used: it
73
+ * unwraps a `dialog()` envelope and throws for a plain `tool()`, which both of
74
+ * these are.
75
+ */
76
+ type CheckResult = Exclude<InferToolOutput<typeof CheckDrugInteraction>, ToolFailure>;
77
+
35
78
  const IBUPROFEN: FdaLabel = {
36
79
  openfda: { generic_name: ["IBUPROFEN"], brand_name: ["Advil"], manufacturer_name: ["Acme"] },
37
80
  purpose: ["Pain reliever"],
@@ -66,31 +109,92 @@ describe("health-assistant template", () => {
66
109
  expect.arrayContaining(["check_drug_interaction", "medication_lookup"]),
67
110
  );
68
111
  });
112
+
113
+ test("is deployable: validates, is nameable, and every stage its mode needs is filled", () => {
114
+ // The same conversion `aai build`/`aai deploy` run, and the only thing that
115
+ // checks the three builtin NAMES against the SDK's own enum — so a typo in
116
+ // `builtinTools` fails here rather than shipping an agent whose prompt
117
+ // commands a tool the platform never resolved. This template declares no
118
+ // provider at all, so the default all-AssemblyAI cascade is what makes it
119
+ // run the moment it is deployed; `expectDeployable` asserts that per MODE,
120
+ // so it survives a swap. `not.toThrow()` because the helper's throw IS the
121
+ // finding: vitest quotes the message, which names the invariant that went.
122
+ expect(() => expectDeployable(agentDef)).not.toThrow();
123
+ });
124
+
125
+ test("all three builtins survive into the config a deploy carries", () => {
126
+ const builtins = expectDeployable(agentDef).builtinTools ?? [];
127
+
128
+ // Asserted on the CONFIG rather than the def because that is what a deploy
129
+ // ships, and because `DEFAULT_BUILTIN_TOOLS` is empty: a builtin is
130
+ // something an agent asks for, never something it has to notice and switch
131
+ // off. So a dropped entry is not a quieter Dr. Sage — it is the same one
132
+ // with a prompt rule addressed to nothing. Adding builtins beside these
133
+ // three is an ordinary edit; losing one is the regression.
134
+ //
135
+ // `run_code` is the arithmetic rule's only mechanism (a BMI or a
136
+ // weight-based dose worked out in the model's head reads exactly like a
137
+ // computed one), `web_search` the only route to current symptom
138
+ // information, and `fetch_json` the only route to the adverse-event
139
+ // dataset — which is a COUNTING query the two `tools/` files cannot
140
+ // answer, since they read the label endpoint and a label is what the
141
+ // manufacturer wrote.
142
+ expect(builtins).toEqual(expect.arrayContaining(["web_search", "run_code", "fetch_json"]));
143
+ });
144
+
145
+ test("every builtin the prompt tells Dr. Sage to use is one it declares", () => {
146
+ // The pairing this template's prose is built on: the prompt holds the
147
+ // formulas, the endpoint and the caveats, each list headed by the tool that
148
+ // consumes it, and `agent.ts` holds the array that makes those tools exist.
149
+ // The failure is silent in both directions and shows up in a diff of
150
+ // neither file — a prompt commanding `fetch_json` at an agent that never
151
+ // declared it produces a model apologizing for a tool it cannot see, and a
152
+ // builtin dropped from `agent.ts` alone leaves the endpoint addressed to
153
+ // nothing.
154
+ //
155
+ // Which snake_case tokens in the prose are tool NAMES is a question for the
156
+ // SDK's own schema rather than a catalog restated here: this prompt also
157
+ // names `weight_kg`, `dose_mg`, `medication_lookup` and
158
+ // `patient.reaction.reactionmeddrapt.exact`, so matching every underscored
159
+ // word would redden on a formula or a query field.
160
+ // `expectPromptBuiltinsDeclared` asks the schema, and it also FAILS on a
161
+ // prompt naming no builtin at all — the state this template lands in when
162
+ // `system-prompt.md` was not applied, since the framework default names
163
+ // none. The converse is deliberately not asserted: declaring a builtin the
164
+ // prompt never mentions is an ordinary edit.
165
+ expect(expectPromptBuiltinsDeclared(agentDef)).toEqual(
166
+ expect.arrayContaining(["web_search", "run_code", "fetch_json"]),
167
+ );
168
+ });
69
169
  });
70
170
 
71
171
  describe("medication_lookup", () => {
72
172
  test("folds the label's array fields into one flat answer", async () => {
73
173
  label.mockResolvedValue(IBUPROFEN);
74
- const result = await run("medication_lookup", { name: "advil" });
174
+ const result = await lookUp({ name: "advil" });
75
175
  expect(result).toMatchObject({
76
176
  name: "IBUPROFEN",
77
177
  brand_names: ["Advil"],
78
178
  purpose: "Pain reliever",
79
179
  manufacturer: "Acme",
80
180
  });
181
+ // And the lookup carried the caller's `ctx.signal` down to openFDA — the
182
+ // `CallOptions` half. A tool that forgets it leaves a request running past
183
+ // the turn that wanted it, which nothing else here would notice.
184
+ expect(label.mock.calls[0]?.[1]?.signal).toBeInstanceOf(AbortSignal);
81
185
  });
82
186
 
83
187
  test("an unknown drug is a tool FAILURE, not an empty answer", async () => {
84
188
  // The model has to be able to tell "no such drug" from "a drug with no
85
189
  // warnings", which is why this is a failure rather than a record of "N/A".
86
190
  label.mockResolvedValue(null);
87
- const result = await run("medication_lookup", { name: "sparkleforin" });
191
+ const result = await lookUp({ name: "sparkleforin" });
88
192
  expect(isToolFailure(result) && result.error).toContain("sparkleforin");
89
193
  });
90
194
 
91
195
  test("a missing section reads N/A rather than undefined", async () => {
92
196
  label.mockResolvedValue(WARFARIN);
93
- expect(await run("medication_lookup", { name: "warfarin" })).toMatchObject({
197
+ expect(await lookUp({ name: "warfarin" })).toMatchObject({
94
198
  warnings: "N/A",
95
199
  dosage: "N/A",
96
200
  side_effects: "N/A",
@@ -104,10 +208,9 @@ describe("check_drug_interaction", () => {
104
208
  label.mockImplementation(async (name: string) =>
105
209
  name.includes("ibuprofen") ? IBUPROFEN : WARFARIN,
106
210
  );
107
- const result = await run("check_drug_interaction", { drugs: ["ibuprofen", "warfarin"] });
108
- expect(result).toMatchObject({ interactions_found: 1 });
109
- const [first] = (result as { interactions: { drug: string; mentions: string }[] }).interactions;
110
- expect(first).toMatchObject({ drug: "ibuprofen", mentions: "warfarin" });
211
+ const result = (await check({ drugs: ["ibuprofen", "warfarin"] })) as CheckResult;
212
+ expect(result.interactions_found).toBe(1);
213
+ expect(result.interactions[0]).toMatchObject({ drug: "ibuprofen", mentions: "warfarin" });
111
214
  });
112
215
 
113
216
  test("matches on a BRAND alias, not only the name the caller used", async () => {
@@ -120,7 +223,7 @@ describe("check_drug_interaction", () => {
120
223
  label.mockImplementation(async (name: string) =>
121
224
  name.includes("ibuprofen") ? coumadinMention : WARFARIN,
122
225
  );
123
- const result = await run("check_drug_interaction", { drugs: ["ibuprofen", "warfarin"] });
226
+ const result = await check({ drugs: ["ibuprofen", "warfarin"] });
124
227
  expect(result).toMatchObject({ interactions_found: 1 });
125
228
  });
126
229
 
@@ -130,21 +233,37 @@ describe("check_drug_interaction", () => {
130
233
  label.mockImplementation(async (name: string) =>
131
234
  name.includes("ibuprofen") ? IBUPROFEN : null,
132
235
  );
133
- const result = await run("check_drug_interaction", { drugs: ["ibuprofen", "sparkleforin"] });
236
+ const result = await check({ drugs: ["ibuprofen", "sparkleforin"] });
134
237
  expect(isToolFailure(result) && result.error).toContain("sparkleforin");
135
238
  });
136
239
 
137
240
  test("two drugs with no cross-mention are reported as such, with the caveat", async () => {
138
241
  label.mockResolvedValue(WARFARIN);
139
- const result = await run("check_drug_interaction", { drugs: ["warfarin", "aspirin"] });
140
- expect(result).toMatchObject({ interactions_found: 0 });
141
- expect((result as { note: string }).note).toContain("does not guarantee");
242
+ const result = (await check({ drugs: ["warfarin", "aspirin"] })) as CheckResult;
243
+ expect(result.interactions_found).toBe(0);
244
+ // The caveat is the point of the zero case: "no cross-mention" is not
245
+ // "safe", and this tool must never be read as saying it was.
246
+ expect(result.note).toContain("does not guarantee");
247
+ });
248
+
249
+ test("every drug in the fan-out is looked up under the caller's signal", async () => {
250
+ // The reason `fetchFdaLabel` takes `CallOptions` at all: this tool fires one
251
+ // request per drug the caller named, so a hang-up mid-check has N of them
252
+ // to take down, not one.
253
+ label.mockResolvedValue(WARFARIN);
254
+
255
+ await check({ drugs: ["warfarin", "aspirin"] });
256
+
257
+ expect(label).toHaveBeenCalledTimes(2);
258
+ for (const [, options] of label.mock.calls) {
259
+ expect(options?.signal).toBeInstanceOf(AbortSignal);
260
+ }
142
261
  });
143
262
 
144
263
  test("whitespace-only names are refused before any lookup happens", async () => {
145
264
  // The schema's `min(2)` counts entries, not real names, so the body
146
265
  // re-checks after trimming — and must do so BEFORE touching the network.
147
- const result = await run("check_drug_interaction", { drugs: ["ibuprofen", " "] });
266
+ const result = await check({ drugs: ["ibuprofen", " "] });
148
267
  expect(isToolFailure(result) && result.error).toContain("at least two");
149
268
  expect(label).not.toHaveBeenCalled();
150
269
  });