@alexkroman1/aai-cli 0.16.0 → 0.18.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 (439) hide show
  1. package/dist/{_agent-BopNO5Bq.mjs → _agent-BN21AHsJ.mjs} +4 -4
  2. package/dist/_api-client-Uljj0CQi.mjs +312 -0
  3. package/dist/_api-client.d.ts +69 -1
  4. package/dist/{_bundler-DCuNHjDF.mjs → _bundler-DvZDEu2p.mjs} +67 -7
  5. package/dist/_bundler.d.ts +15 -0
  6. package/dist/_cli-common.d.ts +42 -0
  7. package/dist/{client-bundler-DE-AGdm7.mjs → _client-plugins-kR43nZnb.mjs} +30 -132
  8. package/dist/_client-plugins.d.ts +16 -0
  9. package/dist/{_config-mq1I5Cva.mjs → _config-Dlh8PRRp.mjs} +2 -20
  10. package/dist/_config.d.ts +0 -8
  11. package/dist/{_dev-server-B4ZiXbZj.mjs → _dev-server-C_zidzWj.mjs} +17 -12
  12. package/dist/_dev-session-ticket.d.ts +3 -0
  13. package/dist/_dev-tunnel.d.ts +20 -2
  14. package/dist/_dotenv-file.d.ts +6 -0
  15. package/dist/_init.d.ts +2 -11
  16. package/dist/_output.d.ts +47 -20
  17. package/dist/_safe-write.d.ts +38 -0
  18. package/dist/{_server-common-CVXIeWrY.mjs → _server-common-C6j67AcZ.mjs} +37 -2
  19. package/dist/_server-common.d.ts +16 -0
  20. package/dist/{_slug-api-BnmTHtjd.mjs → _slug-api-B9cptz7Q.mjs} +3 -2
  21. package/dist/_start-affinity.d.ts +70 -0
  22. package/dist/_start-log.d.ts +39 -0
  23. package/dist/_start-router.d.ts +85 -0
  24. package/dist/_start-run.d.ts +101 -0
  25. package/dist/_start-worker.d.ts +61 -0
  26. package/dist/_start-workers-BNdOnTal.mjs +529 -0
  27. package/dist/_start-workers.d.ts +262 -0
  28. package/dist/_studio-zympBLlD.mjs +140 -0
  29. package/dist/_studio.d.ts +14 -0
  30. package/dist/_target-bundle.d.ts +4 -0
  31. package/dist/{_templates-BVMVsQh0.mjs → _templates-ChZuhW66.mjs} +110 -8
  32. package/dist/_templates.d.ts +20 -1
  33. package/dist/{_typecheck-gate-CcX2gLJZ.mjs → _typecheck-gate-BNF5cboL.mjs} +2 -2
  34. package/dist/_ui-C0RufoYZ.mjs +147 -0
  35. package/dist/_ui.d.ts +14 -3
  36. package/dist/_utils-ChU85MEg.mjs +486 -0
  37. package/dist/_utils.d.ts +28 -0
  38. package/dist/_vendor-openers.d.ts +87 -0
  39. package/dist/{_vitest-runner-CKI8_K1b.mjs → _vitest-runner-tzyto9IU.mjs} +7 -3
  40. package/dist/_vitest-runner.d.ts +8 -1
  41. package/dist/{build-BnXLgfk-.mjs → build-BHgd-QYb.mjs} +13 -10
  42. package/dist/build.d.ts +21 -0
  43. package/dist/cli-workflow.d.ts +7 -0
  44. package/dist/cli.d.ts +16 -0
  45. package/dist/cli.mjs +243 -70
  46. package/dist/client-bundler-CImhqcp2.mjs +133 -0
  47. package/dist/client-bundler.mjs +1 -1
  48. package/dist/{console-Bp1kSqz_.mjs → console-DwycgRkC.mjs} +4 -5
  49. package/dist/delete-ZcA3J_3o.mjs +75 -0
  50. package/dist/delete.d.ts +10 -1
  51. package/dist/{deploy-eWDoiwvn.mjs → deploy-CkfkiZE3.mjs} +9 -9
  52. package/dist/{dev-CxZsZsOL.mjs → dev-BX9g6qcf.mjs} +81 -18
  53. package/dist/{eval-Dl8o91yC.mjs → eval-CUKvfxRq.mjs} +4 -4
  54. package/dist/{init-CidslZZz.mjs → init-B9Uw76-_.mjs} +62 -32
  55. package/dist/{login-oJdBWu2B.mjs → login-Ct73CqU1.mjs} +30 -6
  56. package/dist/login.d.ts +2 -0
  57. package/dist/{logs-CkmFdSbr.mjs → logs-BBsUy96d.mjs} +59 -14
  58. package/dist/logs.d.ts +4 -1
  59. package/dist/project-config.mjs +1 -1
  60. package/dist/scaffold/CLAUDE.md +72 -55
  61. package/dist/scaffold/agent-guide/AGENT-API.md +46 -33
  62. package/dist/scaffold/agent-guide/HOSTING.md +11 -0
  63. package/dist/scaffold/agent-guide/TESTING-EVALS.md +105 -36
  64. package/dist/scaffold/agent-guide/TOOLS.md +189 -33
  65. package/dist/scaffold/agent-guide/UI.md +111 -39
  66. package/dist/scaffold/agent-guide/WORKFLOWS.md +234 -160
  67. package/dist/scaffold/package.json +4 -4
  68. package/dist/{secret-DPdPEet2.mjs → secret-CKjHRrVX.mjs} +112 -35
  69. package/dist/start.d.ts +14 -14
  70. package/dist/start.mjs +840 -40
  71. package/dist/{studio-COjK25Rl.mjs → studio-U6DvBNAx.mjs} +123 -35
  72. package/dist/studio.d.ts +1 -0
  73. package/dist/templates/applicant-screening-agent/agent.eval.test.ts +23 -52
  74. package/dist/templates/applicant-screening-agent/agent.test.ts +821 -826
  75. package/dist/templates/applicant-screening-agent/agent.ts +1 -6
  76. package/dist/templates/applicant-screening-agent/client.tsx +1 -19
  77. package/dist/templates/applicant-screening-agent/shared.ts +8 -18
  78. package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +24 -27
  79. package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +75 -82
  80. package/dist/templates/applicant-screening-agent/tools/read_email.ts +24 -24
  81. package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +92 -99
  82. package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +72 -83
  83. package/dist/templates/applicant-screening-agent/tools/screening_status.ts +21 -29
  84. package/dist/templates/call-audit-workflow/agent.eval.test.ts +14 -19
  85. package/dist/templates/call-audit-workflow/agent.test.ts +275 -169
  86. package/dist/templates/call-audit-workflow/agent.ts +12 -30
  87. package/dist/templates/call-audit-workflow/client.tsx +9 -27
  88. package/dist/templates/call-audit-workflow/guards.test.ts +24 -71
  89. package/dist/templates/call-audit-workflow/workflows/audit.ts +24 -52
  90. package/dist/templates/call-audit-workflow/workflows/ingest.ts +32 -59
  91. package/dist/templates/call-audit-workflow/workflows/media.ts +4 -44
  92. package/dist/templates/call-audit-workflow/workflows/summarize.ts +72 -107
  93. package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
  94. package/dist/templates/code-interpreter-agent/agent.test.ts +4 -17
  95. package/dist/templates/code-interpreter-agent/agent.ts +1 -1
  96. package/dist/templates/coding-agent/agent.test.ts +17 -12
  97. package/dist/templates/coding-agent/agent.ts +1 -1
  98. package/dist/templates/custom-pipeline-agent/agent.test.ts +6 -14
  99. package/dist/templates/custom-pipeline-agent/agent.ts +1 -1
  100. package/dist/templates/custom-pipeline-agent/modes.test.ts +0 -1
  101. package/dist/templates/custom-pipeline-agent/stages.test.ts +4 -8
  102. package/dist/templates/document-redline-workflow/agent.test.ts +88 -221
  103. package/dist/templates/document-redline-workflow/agent.ts +22 -32
  104. package/dist/templates/document-redline-workflow/client.tsx +46 -88
  105. package/dist/templates/document-redline-workflow/workflows/prompts.ts +0 -3
  106. package/dist/templates/document-redline-workflow/workflows/redline.ts +33 -50
  107. package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +22 -71
  108. package/dist/templates/emergency-dispatch-agent/agent.test.ts +466 -495
  109. package/dist/templates/emergency-dispatch-agent/agent.ts +27 -43
  110. package/dist/templates/emergency-dispatch-agent/client.tsx +85 -119
  111. package/dist/templates/emergency-dispatch-agent/shared.ts +51 -88
  112. package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +11 -17
  113. package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +21 -30
  114. package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +60 -63
  115. package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +6 -15
  116. package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +40 -53
  117. package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +41 -47
  118. package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +2 -2
  119. package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +1 -1
  120. package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +13 -10
  121. package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +42 -51
  122. package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +40 -41
  123. package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +14 -42
  124. package/dist/templates/entertainment-picks-agent/agent.test.ts +174 -221
  125. package/dist/templates/entertainment-picks-agent/agent.ts +1 -6
  126. package/dist/templates/entertainment-picks-agent/client.tsx +1 -12
  127. package/dist/templates/entertainment-picks-agent/shared.ts +12 -6
  128. package/dist/templates/entertainment-picks-agent/tools/recommend.ts +2 -2
  129. package/dist/templates/entertainment-picks-agent/tools/revisit.ts +1 -0
  130. package/dist/templates/executive-inbox-agent/agent.eval.test.ts +15 -22
  131. package/dist/templates/executive-inbox-agent/agent.test.ts +515 -527
  132. package/dist/templates/executive-inbox-agent/agent.ts +4 -8
  133. package/dist/templates/executive-inbox-agent/calendar.test.ts +23 -22
  134. package/dist/templates/executive-inbox-agent/client.tsx +1 -23
  135. package/dist/templates/executive-inbox-agent/review.ts +125 -113
  136. package/dist/templates/executive-inbox-agent/shared.ts +3 -0
  137. package/dist/templates/executive-inbox-agent/tools/ask_question.ts +6 -6
  138. package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +16 -18
  139. package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +1 -0
  140. package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +20 -20
  141. package/dist/templates/executive-inbox-agent/tools/new_email.ts +17 -21
  142. package/dist/templates/executive-inbox-agent/tools/open_email.ts +72 -74
  143. package/dist/templates/executive-inbox-agent/tools/review_memory.ts +1 -0
  144. package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +19 -20
  145. package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +53 -50
  146. package/dist/templates/front-desk-agent/agent.eval.test.ts +22 -14
  147. package/dist/templates/front-desk-agent/agent.test.ts +139 -125
  148. package/dist/templates/front-desk-agent/agent.ts +4 -7
  149. package/dist/templates/front-desk-agent/shared.ts +88 -74
  150. package/dist/templates/front-door-agent/agent.eval.test.ts +61 -0
  151. package/dist/templates/front-door-agent/agent.test.ts +393 -0
  152. package/dist/templates/front-door-agent/agent.ts +35 -0
  153. package/dist/templates/front-door-agent/client.tsx +250 -0
  154. package/dist/templates/front-door-agent/routes.ts +91 -0
  155. package/dist/templates/front-door-agent/shared.ts +35 -0
  156. package/dist/templates/front-door-agent/system-prompt.md +12 -0
  157. package/dist/templates/front-door-agent/tools/leave_message.ts +39 -0
  158. package/dist/templates/front-door-agent/tools/link_phone.ts +49 -0
  159. package/dist/templates/front-door-agent/workflows/announce.ts +38 -0
  160. package/dist/templates/front-door-agent/workflows/digest.ts +53 -0
  161. package/dist/templates/front-door-agent/workflows/pair.ts +28 -0
  162. package/dist/templates/home-assistant-agent/agent.eval.test.ts +5 -9
  163. package/dist/templates/home-assistant-agent/agent.test.ts +513 -399
  164. package/dist/templates/home-assistant-agent/agent.ts +8 -5
  165. package/dist/templates/home-assistant-agent/client.tsx +50 -18
  166. package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +1 -0
  167. package/dist/templates/home-assistant-agent/tools/remind_me.ts +2 -1
  168. package/dist/templates/hotel-reception-agent/agent.eval.test.ts +27 -52
  169. package/dist/templates/hotel-reception-agent/agent.test.ts +980 -964
  170. package/dist/templates/hotel-reception-agent/agent.ts +8 -21
  171. package/dist/templates/hotel-reception-agent/booking.ts +2 -2
  172. package/dist/templates/hotel-reception-agent/client.tsx +5 -20
  173. package/dist/templates/hotel-reception-agent/concierge.ts +2 -0
  174. package/dist/templates/hotel-reception-agent/desk-seams.test.ts +285 -275
  175. package/dist/templates/hotel-reception-agent/desk.ts +45 -12
  176. package/dist/templates/hotel-reception-agent/hotel.ts +6 -6
  177. package/dist/templates/hotel-reception-agent/restaurant.ts +3 -4
  178. package/dist/templates/hotel-reception-agent/session.ts +14 -30
  179. package/dist/templates/hotel-reception-agent/shared.ts +33 -46
  180. package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +14 -15
  181. package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +1 -0
  182. package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +1 -0
  183. package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -2
  184. package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +13 -10
  185. package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
  186. package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +6 -7
  187. package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +1 -0
  188. package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +5 -4
  189. package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +6 -5
  190. package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +3 -4
  191. package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +4 -4
  192. package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -0
  193. package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
  194. package/dist/templates/hotel-reception-agent/tools/record_followup.ts +1 -0
  195. package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +1 -0
  196. package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
  197. package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -0
  198. package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +1 -0
  199. package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +4 -4
  200. package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -0
  201. package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +4 -3
  202. package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +1 -0
  203. package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +1 -0
  204. package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
  205. package/dist/templates/hotel-reception-agent/tools/set_stay.ts +1 -1
  206. package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +30 -32
  207. package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +22 -25
  208. package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +1 -0
  209. package/dist/templates/hotel-reception-agent/tools/update_card.ts +5 -4
  210. package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +23 -13
  211. package/dist/templates/kitchen-coach-agent/agent.eval.test.ts +38 -0
  212. package/dist/templates/kitchen-coach-agent/agent.test.ts +204 -0
  213. package/dist/templates/kitchen-coach-agent/agent.ts +22 -0
  214. package/dist/templates/kitchen-coach-agent/client.tsx +232 -0
  215. package/dist/templates/kitchen-coach-agent/history.ts +37 -0
  216. package/dist/templates/kitchen-coach-agent/shared.ts +131 -0
  217. package/dist/templates/kitchen-coach-agent/system-prompt.md +17 -0
  218. package/dist/templates/kitchen-coach-agent/tools/get_kitchen.ts +17 -0
  219. package/dist/templates/kitchen-coach-agent/tools/scale_amount.ts +31 -0
  220. package/dist/templates/kitchen-coach-agent/tools/start_timer.ts +24 -0
  221. package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -40
  222. package/dist/templates/link-digest-workflow/agent.test.ts +84 -164
  223. package/dist/templates/link-digest-workflow/agent.ts +27 -42
  224. package/dist/templates/link-digest-workflow/api-client.ts +3 -2
  225. package/dist/templates/link-digest-workflow/client.tsx +5 -5
  226. package/dist/templates/link-digest-workflow/workflows/digest.ts +53 -95
  227. package/dist/templates/medication-safety-agent/agent.eval.test.ts +10 -30
  228. package/dist/templates/medication-safety-agent/agent.test.ts +16 -46
  229. package/dist/templates/medication-safety-agent/agent.ts +1 -4
  230. package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +13 -10
  231. package/dist/templates/meeting-recap-agent/agent.eval.test.ts +238 -396
  232. package/dist/templates/meeting-recap-agent/agent.test.ts +414 -1073
  233. package/dist/templates/meeting-recap-agent/agent.ts +26 -67
  234. package/dist/templates/meeting-recap-agent/system-prompt.md +1 -0
  235. package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +10 -12
  236. package/dist/templates/meeting-recap-agent/tools/request_recap.ts +9 -20
  237. package/dist/templates/meeting-recap-agent/workflows/recap.ts +224 -547
  238. package/dist/templates/outbound-call-agent/agent.eval.test.ts +10 -12
  239. package/dist/templates/outbound-call-agent/agent.test.ts +419 -453
  240. package/dist/templates/outbound-call-agent/agent.ts +57 -62
  241. package/dist/templates/outbound-call-agent/api.ts +53 -68
  242. package/dist/templates/outbound-call-agent/client.tsx +105 -176
  243. package/dist/templates/outbound-call-agent/shared.ts +10 -39
  244. package/dist/templates/outbound-call-agent/system-prompt.md +3 -4
  245. package/dist/templates/outbound-call-agent/tools/end_call.ts +15 -12
  246. package/dist/templates/outbound-call-agent/tools/press_keys.ts +8 -13
  247. package/dist/templates/outbound-call-agent/workflows/call.ts +94 -63
  248. package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +18 -54
  249. package/dist/templates/pizza-ordering-agent/agent.test.ts +205 -244
  250. package/dist/templates/pizza-ordering-agent/agent.ts +5 -12
  251. package/dist/templates/pizza-ordering-agent/client.tsx +3 -14
  252. package/dist/templates/pizza-ordering-agent/shared.ts +31 -36
  253. package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +1 -0
  254. package/dist/templates/pizza-ordering-agent/tools/place_order.ts +5 -2
  255. package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +1 -0
  256. package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +2 -3
  257. package/dist/templates/pizza-ordering-agent/tools/view_order.ts +7 -3
  258. package/dist/templates/podcast-digest-workflow/agent.test.ts +53 -102
  259. package/dist/templates/podcast-digest-workflow/agent.ts +11 -17
  260. package/dist/templates/podcast-digest-workflow/client.tsx +29 -51
  261. package/dist/templates/podcast-digest-workflow/workflows/digest.ts +24 -26
  262. package/dist/templates/push-to-talk-agent/agent.eval.test.ts +13 -14
  263. package/dist/templates/push-to-talk-agent/agent.test.ts +30 -23
  264. package/dist/templates/push-to-talk-agent/agent.ts +1 -5
  265. package/dist/templates/push-to-talk-agent/client.tsx +1 -11
  266. package/dist/templates/push-to-talk-agent/shared.ts +12 -6
  267. package/dist/templates/push-to-talk-agent/tools/list_notes.ts +1 -0
  268. package/dist/templates/push-to-talk-agent/tools/save_note.ts +1 -0
  269. package/dist/templates/quickstart-agent/agent.eval.test.ts +0 -10
  270. package/dist/templates/quickstart-agent/agent.test.ts +18 -30
  271. package/dist/templates/quickstart-agent/agent.ts +3 -4
  272. package/dist/templates/research-handoff-agent/agent.eval.test.ts +161 -290
  273. package/dist/templates/research-handoff-agent/agent.test.ts +133 -471
  274. package/dist/templates/research-handoff-agent/agent.ts +26 -86
  275. package/dist/templates/research-handoff-agent/system-prompt.md +1 -0
  276. package/dist/templates/research-handoff-agent/tools/file_it_now.ts +8 -21
  277. package/dist/templates/research-handoff-agent/tools/request_research.ts +7 -16
  278. package/dist/templates/research-handoff-agent/workflows/research.ts +88 -40
  279. package/dist/templates/research-planner-agent/agent.eval.test.ts +15 -40
  280. package/dist/templates/research-planner-agent/agent.test.ts +415 -464
  281. package/dist/templates/research-planner-agent/agent.ts +3 -8
  282. package/dist/templates/research-planner-agent/client.tsx +1 -14
  283. package/dist/templates/research-planner-agent/procedure.ts +9 -3
  284. package/dist/templates/research-planner-agent/shared.ts +30 -33
  285. package/dist/templates/research-planner-agent/tools/plan_status.ts +7 -15
  286. package/dist/templates/research-planner-agent/tools/revise_plan.ts +29 -36
  287. package/dist/templates/research-planner-agent/tools/start_plan.ts +25 -39
  288. package/dist/templates/research-planner-agent/tools/work_next_step.ts +25 -42
  289. package/dist/templates/retail-orders-agent/agent.eval.test.ts +14 -34
  290. package/dist/templates/retail-orders-agent/agent.test.ts +1079 -1073
  291. package/dist/templates/retail-orders-agent/agent.ts +25 -78
  292. package/dist/templates/retail-orders-agent/client.tsx +120 -168
  293. package/dist/templates/retail-orders-agent/pending.test.ts +7 -14
  294. package/dist/templates/retail-orders-agent/registry.test.ts +93 -192
  295. package/dist/templates/retail-orders-agent/shared.test.ts +1 -1
  296. package/dist/templates/retail-orders-agent/shared.ts +10 -20
  297. package/dist/templates/retail-orders-agent/store.test.ts +46 -128
  298. package/dist/templates/retail-orders-agent/store.ts +42 -175
  299. package/dist/templates/retail-orders-agent/tools/cancel_change.ts +3 -6
  300. package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +3 -4
  301. package/dist/templates/retail-orders-agent/tools/confirm_change.ts +4 -6
  302. package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +3 -4
  303. package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +3 -4
  304. package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +3 -4
  305. package/dist/templates/retail-orders-agent/tools/get_item_details.ts +3 -4
  306. package/dist/templates/retail-orders-agent/tools/get_order_details.ts +3 -4
  307. package/dist/templates/retail-orders-agent/tools/get_product_details.ts +3 -4
  308. package/dist/templates/retail-orders-agent/tools/get_user_details.ts +3 -4
  309. package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +3 -8
  310. package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +3 -4
  311. package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +3 -4
  312. package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +3 -4
  313. package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +3 -4
  314. package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +3 -4
  315. package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +3 -4
  316. package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +22 -25
  317. package/dist/templates/roadside-assistance-agent/agent.test.ts +453 -490
  318. package/dist/templates/roadside-assistance-agent/agent.ts +28 -60
  319. package/dist/templates/roadside-assistance-agent/call.ts +16 -22
  320. package/dist/templates/roadside-assistance-agent/shared.ts +24 -54
  321. package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +29 -37
  322. package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +44 -70
  323. package/dist/templates/roadside-assistance-agent/tools/job_status.ts +16 -24
  324. package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +39 -51
  325. package/dist/templates/roadside-assistance-agent/tools/report_location.ts +34 -33
  326. package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +18 -39
  327. package/dist/templates/roadside-assistance-agent/yard.test.ts +22 -19
  328. package/dist/templates/roadside-assistance-agent/yard.ts +3 -3
  329. package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +38 -40
  330. package/dist/templates/spoken-summary-workflow/agent.test.ts +129 -279
  331. package/dist/templates/spoken-summary-workflow/agent.ts +15 -40
  332. package/dist/templates/spoken-summary-workflow/client.tsx +13 -25
  333. package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +52 -92
  334. package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +31 -74
  335. package/dist/templates/tabletop-rpg-agent/agent.test.ts +756 -774
  336. package/dist/templates/tabletop-rpg-agent/agent.ts +9 -46
  337. package/dist/templates/tabletop-rpg-agent/client.tsx +13 -21
  338. package/dist/templates/tabletop-rpg-agent/shared.ts +40 -99
  339. package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +67 -83
  340. package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +65 -88
  341. package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +8 -27
  342. package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +18 -36
  343. package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +101 -111
  344. package/dist/templates/technical-support-agent/agent.eval.test.ts +31 -72
  345. package/dist/templates/technical-support-agent/agent.test.ts +231 -260
  346. package/dist/templates/technical-support-agent/agent.ts +4 -10
  347. package/dist/templates/technical-support-agent/client.tsx +4 -18
  348. package/dist/templates/technical-support-agent/shared.ts +15 -25
  349. package/dist/templates/technical-support-agent/tools/answer_question.ts +46 -56
  350. package/dist/templates/technical-support-agent/tools/list_topics.ts +1 -0
  351. package/dist/templates/technical-support-agent/tools/log_ticket.ts +8 -5
  352. package/dist/templates/text-adventure-agent/agent.eval.test.ts +37 -126
  353. package/dist/templates/text-adventure-agent/agent.test.ts +197 -368
  354. package/dist/templates/text-adventure-agent/agent.ts +15 -65
  355. package/dist/templates/text-adventure-agent/client.tsx +38 -98
  356. package/dist/templates/text-adventure-agent/shared.ts +31 -143
  357. package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +6 -12
  358. package/dist/templates/text-adventure-agent/tools/game_state_get.ts +4 -11
  359. package/dist/templates/text-adventure-agent/tools/game_state_move.ts +0 -2
  360. package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +1 -3
  361. package/dist/templates/text-adventure-agent/tools/game_state_score.ts +5 -7
  362. package/dist/templates/topic-briefing-agent/agent.eval.test.ts +12 -50
  363. package/dist/templates/topic-briefing-agent/agent.test.ts +478 -476
  364. package/dist/templates/topic-briefing-agent/agent.ts +3 -3
  365. package/dist/templates/topic-briefing-agent/shared.ts +11 -16
  366. package/dist/templates/topic-briefing-agent/slack.ts +12 -4
  367. package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +10 -17
  368. package/dist/templates/topic-briefing-agent/tools/research_topic.ts +21 -24
  369. package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +13 -14
  370. package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +16 -13
  371. package/dist/templates/transcription-workflow/agent.test.ts +114 -259
  372. package/dist/templates/transcription-workflow/agent.ts +6 -9
  373. package/dist/templates/transcription-workflow/client.tsx +100 -258
  374. package/dist/templates/transcription-workflow/recover.test.ts +6 -136
  375. package/dist/templates/transcription-workflow/recover.ts +14 -97
  376. package/dist/templates/transcription-workflow/run-panel.tsx +71 -8
  377. package/dist/templates/transcription-workflow/workflows/batch.ts +28 -159
  378. package/dist/templates/transcription-workflow/workflows/normalize.ts +50 -86
  379. package/dist/templates/transcription-workflow/workflows/stream.ts +2 -2
  380. package/dist/templates/transcription-workflow/workflows/transcribe.ts +16 -23
  381. package/dist/templates/travel-concierge-agent/agent.eval.test.ts +7 -25
  382. package/dist/templates/travel-concierge-agent/agent.test.ts +505 -517
  383. package/dist/templates/travel-concierge-agent/agent.ts +22 -46
  384. package/dist/templates/travel-concierge-agent/client.tsx +1 -22
  385. package/dist/templates/travel-concierge-agent/routing.ts +29 -31
  386. package/dist/templates/travel-concierge-agent/shared.ts +63 -152
  387. package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +8 -9
  388. package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +8 -8
  389. package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +9 -6
  390. package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +10 -10
  391. package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +3 -2
  392. package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +3 -2
  393. package/dist/templates/travel-concierge-agent/tools/search_flights.ts +4 -3
  394. package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +3 -2
  395. package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +13 -8
  396. package/dist/templates/web-research-agent/agent.test.ts +21 -32
  397. package/dist/templates/web-research-agent/agent.ts +3 -4
  398. package/dist/templates/word-game-agent/agent.eval.test.ts +47 -67
  399. package/dist/templates/word-game-agent/agent.test.ts +369 -382
  400. package/dist/templates/word-game-agent/agent.ts +2 -5
  401. package/dist/templates/word-game-agent/client.tsx +1 -8
  402. package/dist/templates/word-game-agent/game.ts +15 -27
  403. package/dist/templates/word-game-agent/shared.ts +36 -20
  404. package/dist/templates/word-game-agent/tools/final_score.ts +14 -13
  405. package/dist/templates/word-game-agent/tools/relay_description.ts +90 -66
  406. package/dist/templates/word-game-agent/tools/repeat_word.ts +11 -10
  407. package/dist/templates/word-game-agent/tools/skip_word.ts +17 -21
  408. package/dist/templates/word-game-agent/tools/start_game.ts +26 -30
  409. package/dist/{test-XufelYGW.mjs → test-CW5cw5fy.mjs} +3 -4
  410. package/dist/typecheck.mjs +1 -1
  411. package/dist/worker-bundler-D8uCzpYP.mjs +335 -0
  412. package/dist/worker-bundler.d.ts +39 -0
  413. package/dist/worker-bundler.mjs +2 -155
  414. package/dist/{workflow-CDUlTD5B.mjs → workflow-5gOZMB2M.mjs} +66 -19
  415. package/package.json +4 -4
  416. package/dist/_output-DBP9Op_d.mjs +0 -120
  417. package/dist/_studio-B5m4jBTD.mjs +0 -256
  418. package/dist/_ui-Coe0zwmm.mjs +0 -102
  419. package/dist/_utils-BVLdBvdT.mjs +0 -186
  420. package/dist/delete-DwXCHzTl.mjs +0 -55
  421. package/dist/templates/document-redline-workflow/form.ts +0 -74
  422. package/dist/templates/emergency-dispatch-agent/events.ts +0 -48
  423. package/dist/templates/hotel-reception-agent/events.ts +0 -80
  424. package/dist/templates/meeting-recap-agent/shared.ts +0 -44
  425. package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +0 -25
  426. package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +0 -24
  427. package/dist/templates/meeting-recap-agent/tools/recap_status.ts +0 -45
  428. package/dist/templates/meeting-recap-agent/workflows/tokens.ts +0 -47
  429. package/dist/templates/outbound-call-agent/call-params.ts +0 -109
  430. package/dist/templates/outbound-call-agent/live-calls.ts +0 -80
  431. package/dist/templates/outbound-call-agent/workflows/tokens.ts +0 -16
  432. package/dist/templates/research-handoff-agent/shared.ts +0 -41
  433. package/dist/templates/research-handoff-agent/tools/research_progress.ts +0 -23
  434. package/dist/templates/research-handoff-agent/tools/research_status.ts +0 -73
  435. package/dist/templates/research-handoff-agent/workflows/review.ts +0 -43
  436. package/dist/templates/roadside-assistance-agent/events.ts +0 -92
  437. package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +0 -137
  438. package/dist/templates/transcription-workflow/total-latency.tsx +0 -170
  439. package/dist/templates/travel-concierge-agent/call-events.ts +0 -80
@@ -1,15 +1,15 @@
1
+ import agentDef from "virtual:aai/agent";
1
2
  import type { DelegateOptions, SpeakerDef } from "@alexkroman1/aai";
2
- import { DELEGATE_TOOL_NAME, isToolFailure } from "@alexkroman1/aai";
3
+ import { DELEGATE_TOOL_NAME, instructionOf, isToolFailure } from "@alexkroman1/aai";
3
4
  import {
4
5
  createToolContext,
6
+ expectSlotContract,
5
7
  expectToolOk,
6
- runTool,
7
8
  type StubDelegateCall,
8
9
  stubDelegate,
9
10
  toolOf,
10
- toolRunner,
11
11
  } from "@alexkroman1/aai-runtime/testing";
12
- import { installStubStepFetch } from "@alexkroman1/aai-runtime/testing/vitest";
12
+ import { describeAgent, installStubStepFetch } from "@alexkroman1/aai-runtime/testing/vitest";
13
13
  import { describe, expect, test } from "vitest";
14
14
  import authoredAgent from "./agent.ts";
15
15
  import type { AngleWork } from "./shared.ts";
@@ -23,25 +23,21 @@ import {
23
23
  factChecker,
24
24
  findByAngle,
25
25
  MAX_ANGLES,
26
- MAX_FINDINGS,
27
26
  MAX_RESEARCH_STEPS,
28
27
  researcher,
29
28
  VerdictSchema,
30
29
  } from "./shared.ts";
31
30
  import { briefingChannel, briefingMessage, DESTINATION_ENV } from "./slack.ts";
32
31
 
33
- /** A finding whose cost is irrelevant to the case at hand. */
34
- const NO_WORK: AngleWork = { searches: 0, reads: 0 };
35
-
36
- /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
37
- import agentDef from "virtual:aai/agent";
32
+ // The tool FILES: each default export is the object `agentDef` registers, so
33
+ // `run(researchTopic, …)` is typed by the def — arguments and result.
38
34
  import briefingSoFar from "./tools/briefing_so_far.ts";
39
35
  import researchTopic from "./tools/research_topic.ts";
40
36
  import sendBriefing from "./tools/send_briefing.ts";
41
37
  import verifyClaim from "./tools/verify_claim.ts";
42
38
 
43
- const run = toolRunner(agentDef);
44
- const deployed = agentDef;
39
+ /** A finding whose cost is irrelevant to the case at hand. */
40
+ const NO_WORK: AngleWork = { searches: 0, reads: 0 };
45
41
 
46
42
  /**
47
43
  * The desk's two subagents, faked.
@@ -82,570 +78,576 @@ function scriptedDesk(
82
78
  return { ctx, desk: ctx.desk };
83
79
  }
84
80
 
85
- describe("the desk itself", () => {
86
- test("has no web tools of its own — everything goes through a subagent", () => {
87
- // Stated as the claim the test's name makes, rather than as "no builtins at
88
- // all": giving the desk `run_code` is a reasonable edit, and it does not
89
- // put the web in front of the desk.
90
- expect(authoredAgent.builtinTools ?? []).not.toContain("web_search");
91
- expect(authoredAgent.builtinTools ?? []).not.toContain("visit_webpage");
92
- // And the subagents do, which is the split the template exists to show.
93
- expect(researcher.builtinTools).toContain("web_search");
94
- expect(factChecker.builtinTools).toContain("web_search");
95
- });
96
-
97
- test("gives the checker a tighter budget than the researcher", () => {
98
- expect(factChecker.maxSteps).toBeLessThan(MAX_RESEARCH_STEPS);
99
- });
81
+ describeAgent(agentDef, (run) => {
82
+ describe("the desk itself", () => {
83
+ test("has no web tools of its own — everything goes through a subagent", () => {
84
+ // Stated as the claim the test's name makes, rather than as "no builtins at
85
+ // all": giving the desk `run_code` is a reasonable edit, and it does not
86
+ // put the web in front of the desk.
87
+ expect(authoredAgent.builtinTools ?? []).not.toContain("web_search");
88
+ expect(authoredAgent.builtinTools ?? []).not.toContain("visit_webpage");
89
+ // And the subagents do, which is the split the template exists to show.
90
+ expect(researcher.builtinTools).toContain("web_search");
91
+ expect(factChecker.builtinTools).toContain("web_search");
92
+ });
100
93
 
101
- test("runs the three NARROW subagents somewhere cheaper, and the researcher on the default", () => {
102
- // The other half of the budget split, and the reason `CHEAP_MODEL` is one
103
- // constant: three subagents that were each meant to be cheap, one of
104
- // which quietly is not, is a bill nobody can read.
105
- for (const one of [factChecker, explainer, counterpoint]) {
106
- expect(one.llm, one.name).toMatchObject({ options: { model: CHEAP_MODEL } });
107
- }
108
- // The researcher reads whole pages and stays on the agent's own model.
109
- expect(researcher.llm).toBeUndefined();
110
- });
94
+ test("gives the checker a tighter budget than the researcher", () => {
95
+ expect(factChecker.maxSteps).toBeLessThan(MAX_RESEARCH_STEPS);
96
+ });
111
97
 
112
- test("declares what every subagent's final message has to be", () => {
113
- // The rule that decides whether delegation works at all, and it is a FIELD
114
- // rather than a paragraph somebody remembered to write: the desk reads the
115
- // final message and nothing else. A subagent added here without one is the
116
- // regression this catches.
117
- for (const one of [researcher, factChecker, explainer, counterpoint]) {
118
- expect(one.expectedOutput, one.name).toBeTruthy();
119
- }
120
- expect(researcher.expectedOutput).toMatch(/only this/);
121
- });
98
+ test("runs the three NARROW subagents somewhere cheaper, and the researcher on the default", () => {
99
+ // The other half of the budget split, and the reason `CHEAP_MODEL` is one
100
+ // constant: three subagents that were each meant to be cheap, one of
101
+ // which quietly is not, is a bill nobody can read.
102
+ for (const one of [factChecker, explainer, counterpoint]) {
103
+ expect(one.llm, one.name).toMatchObject({ options: { model: CHEAP_MODEL } });
104
+ }
105
+ // The researcher reads whole pages and stays on the agent's own model.
106
+ expect(researcher.llm).toBeUndefined();
107
+ });
122
108
 
123
- test("puts on the roster exactly the subagents chosen by what the caller ASKED", () => {
124
- // The two tools name their own subagent, so those two must NOT be on the
125
- // roster: a subagent reachable both ways gives the model a second, worse
126
- // route to a tool that does real work around the delegation.
127
- expect(authoredAgent.roster?.delegates.map((one) => one.name)).toEqual([
128
- "explainer",
129
- "counterpoint",
130
- ]);
131
- expect(authoredAgent.roster?.speaking).toEqual([]);
132
- for (const one of authoredAgent.roster?.list ?? []) {
133
- // The only thing the router reads. `agent()` refuses a roster without it;
134
- // asserted here too because the template is what an author copies.
135
- expect(one.description, one.name).toBeTruthy();
136
- }
137
- });
109
+ test("declares what every subagent's final message has to be", () => {
110
+ // The rule that decides whether delegation works at all, and it is a FIELD
111
+ // rather than a paragraph somebody remembered to write: the desk reads the
112
+ // final message and nothing else. A subagent added here without one is the
113
+ // regression this catches.
114
+ for (const one of [researcher, factChecker, explainer, counterpoint]) {
115
+ expect(one.expectedOutput, one.name).toBeTruthy();
116
+ }
117
+ expect(researcher.expectedOutput).toMatch(/only this/);
118
+ });
138
119
 
139
- test("publishes the roster as one delegate tool listing both subagents", () => {
140
- const delegate = toolOf(deployed, DELEGATE_TOOL_NAME);
141
- expect(delegate).toBeDefined();
142
- expect(delegate?.description).toContain("explainer:");
143
- expect(delegate?.description).toContain("counterpoint:");
144
- });
145
- });
120
+ test("puts on the roster exactly the subagents chosen by what the caller ASKED", () => {
121
+ // The two tools name their own subagent, so those two must NOT be on the
122
+ // roster: a subagent reachable both ways gives the model a second, worse
123
+ // route to a tool that does real work around the delegation.
124
+ expect(authoredAgent.roster?.delegates.map((one) => one.name)).toEqual([
125
+ "explainer",
126
+ "counterpoint",
127
+ ]);
128
+ expect(authoredAgent.roster?.speaking).toEqual([]);
129
+ for (const one of authoredAgent.roster?.list ?? []) {
130
+ // The only thing the router reads. `agent()` refuses a roster without it;
131
+ // asserted here too because the template is what an author copies.
132
+ expect(one.description, one.name).toBeTruthy();
133
+ }
134
+ });
146
135
 
147
- describe("the fact-checker's schema", () => {
148
- test("admits exactly the three verdicts the desk can act on", () => {
149
- for (const verdict of ["confirmed", "contradicted", "unclear"]) {
150
- expect(VerdictSchema.safeParse({ verdict, detail: "why" }).success).toBe(true);
151
- }
152
- // The failure this exists for: a hedge the desk cannot tell from a
153
- // confirmation, which `tools/verify_claim.ts` would then read out as one.
154
- // It is not a judgement call any more — it does not parse.
155
- expect(VerdictSchema.safeParse({ verdict: "probably", detail: "why" }).success).toBe(false);
156
- expect(VerdictSchema.safeParse({ verdict: "confirmed" }).success).toBe(false);
136
+ test("publishes the roster as one delegate tool listing both subagents", () => {
137
+ const delegate = toolOf(agentDef, DELEGATE_TOOL_NAME);
138
+ expect(delegate).toBeDefined();
139
+ expect(delegate?.description).toContain("explainer:");
140
+ expect(delegate?.description).toContain("counterpoint:");
141
+ });
157
142
  });
158
143
 
159
- test("the checker declares it, so the runtime is what enforces it", () => {
160
- expect(factChecker.schema).toBe(VerdictSchema);
161
- // And the guardrail it replaced is gone: a guardrail is for the judgement a
162
- // shape cannot express, and a three-word enum was never that.
163
- expect(factChecker.guardrail).toBeUndefined();
164
- });
165
- });
144
+ describe("the fact-checker's schema", () => {
145
+ test("admits exactly the three verdicts the desk can act on", () => {
146
+ for (const verdict of ["confirmed", "contradicted", "unclear"]) {
147
+ expect(VerdictSchema.safeParse({ verdict, detail: "why" }).success).toBe(true);
148
+ }
149
+ // The failure this exists for: a hedge the desk cannot tell from a
150
+ // confirmation, which `tools/verify_claim.ts` would then read out as one.
151
+ // It is not a judgement call any more — it does not parse.
152
+ expect(VerdictSchema.safeParse({ verdict: "probably", detail: "why" }).success).toBe(false);
153
+ expect(VerdictSchema.safeParse({ verdict: "confirmed" }).success).toBe(false);
154
+ });
166
155
 
167
- describe("research_topic", () => {
168
- test("fans every angle out as its own run, each with a self-contained task", async () => {
169
- const { ctx, desk: subagents } = scriptedDesk();
170
-
171
- await run(
172
- "research_topic",
173
- { topic: "home batteries", angles: ["price trend", "install lead times"] },
174
- ctx,
175
- );
176
-
177
- expect(subagents.calls).toHaveLength(2);
178
- expect(subagents.calls.map((call) => call.subagent.name)).toEqual(["researcher", "researcher"]);
179
- expect(subagents.calls.map((call) => call.task)).toEqual(["price trend", "install lead times"]);
180
- // The subagent has not heard the call, so the topic rides in `context`.
181
- expect(subagents.calls[0]?.options.context).toContain("home batteries");
156
+ test("the checker declares it, so the runtime is what enforces it", () => {
157
+ expect(factChecker.schema).toBe(VerdictSchema);
158
+ // And the guardrail it replaced is gone: a guardrail is for the judgement a
159
+ // shape cannot express, and a three-word enum was never that.
160
+ expect(factChecker.guardrail).toBeUndefined();
161
+ });
182
162
  });
183
163
 
184
- test("starts the runs concurrently rather than one after another", async () => {
185
- let inFlight = 0;
186
- let peak = 0;
187
- const model = stubDelegate({
188
- routes: {
189
- researcher: () => {
190
- inFlight += 1;
191
- peak = Math.max(peak, inFlight);
192
- return "found";
193
- },
194
- },
164
+ describe("research_topic", () => {
165
+ test("fans every angle out as its own run, each with a self-contained task", async () => {
166
+ const { ctx, desk: subagents } = scriptedDesk();
167
+
168
+ await run(
169
+ researchTopic,
170
+ { topic: "home batteries", angles: ["price trend", "install lead times"] },
171
+ ctx,
172
+ );
173
+
174
+ expect(subagents.calls).toHaveLength(2);
175
+ expect(subagents.calls.map((call) => call.subagent.name)).toEqual([
176
+ "researcher",
177
+ "researcher",
178
+ ]);
179
+ expect(subagents.calls.map((call) => call.task)).toEqual([
180
+ "price trend",
181
+ "install lead times",
182
+ ]);
183
+ // The subagent has not heard the call, so the topic rides in `context`.
184
+ expect(subagents.calls[0]?.options.context).toContain("home batteries");
195
185
  });
196
- // The fake answers synchronously, so `inFlight` is only ever 1 unless the
197
- // tool really did start every run before awaiting any — which is the claim.
198
- // Parameters ANNOTATED rather than inferred: `DelegateFn` is overloaded
199
- // (a subagent with a `schema` answers with a parsed `object`), and a bare
200
- // arrow has no single signature to contextually type itself against.
201
- const delegate = ((sub: SpeakerDef, options: DelegateOptions) =>
202
- model.delegate(sub, options).finally(() => {
203
- inFlight -= 1;
204
- })) as typeof model.delegate;
205
-
206
- await run(
207
- "research_topic",
208
- { topic: "t", angles: ["a", "b", "c"] },
209
- createToolContext({ delegate }),
210
- );
211
-
212
- expect(peak).toBe(3);
213
- });
214
186
 
215
- test("records what each angle concluded, and only that", async () => {
216
- const { ctx } = scriptedDesk({
217
- research: (call) => ({ text: `Answer to ${call.task}.`, searches: 3 }),
187
+ test("starts the runs concurrently rather than one after another", async () => {
188
+ let inFlight = 0;
189
+ let peak = 0;
190
+ const model = stubDelegate({
191
+ routes: {
192
+ researcher: () => {
193
+ inFlight += 1;
194
+ peak = Math.max(peak, inFlight);
195
+ return "found";
196
+ },
197
+ },
198
+ });
199
+ // The fake answers synchronously, so `inFlight` is only ever 1 unless the
200
+ // tool really did start every run before awaiting any — which is the claim.
201
+ // Parameters ANNOTATED rather than inferred: `DelegateFn` is overloaded
202
+ // (a subagent with a `schema` answers with a parsed `object`), and a bare
203
+ // arrow has no single signature to contextually type itself against.
204
+ const delegate = ((sub: SpeakerDef, options: DelegateOptions) =>
205
+ model.delegate(sub, options).finally(() => {
206
+ inFlight -= 1;
207
+ })) as typeof model.delegate;
208
+
209
+ await run(
210
+ researchTopic,
211
+ { topic: "t", angles: ["a", "b", "c"] },
212
+ createToolContext({ delegate }),
213
+ );
214
+
215
+ expect(peak).toBe(3);
218
216
  });
219
217
 
220
- const result = expectToolOk(await runTool(researchTopic, { topic: "t", angles: ["a"] }, ctx));
218
+ test("records what each angle concluded, and only that", async () => {
219
+ const { ctx } = scriptedDesk({
220
+ research: (call) => ({ text: `Answer to ${call.task}.`, searches: 3 }),
221
+ });
221
222
 
222
- expect(result.findings).toEqual([
223
- { angle: "a", summary: "Answer to a.", work: { searches: 3, reads: 0 } },
224
- ]);
225
- const board = briefingSlot.get(ctx);
226
- expect(board.topic).toBe("t");
227
- expect(board.findings).toEqual(result.findings);
228
- });
223
+ const result = expectToolOk(await run(researchTopic, { topic: "t", angles: ["a"] }, ctx));
229
224
 
230
- test("one failed angle does not sink the briefing", async () => {
231
- const model = stubDelegate({
232
- routes: {
233
- researcher: (call) => {
234
- if (call.task === "b") throw new Error("provider is having a day");
235
- return `Answer to ${call.task}.`;
236
- },
237
- },
225
+ expect(result.findings).toEqual([
226
+ { angle: "a", summary: "Answer to a.", work: { searches: 3, reads: 0 } },
227
+ ]);
228
+ const board = briefingSlot.get(ctx);
229
+ expect(board.topic).toBe("t");
230
+ expect(board.findings).toEqual(result.findings);
238
231
  });
239
- const ctx = createToolContext({ delegate: model.delegate });
240
232
 
241
- const result = expectToolOk(
242
- await runTool(researchTopic, { topic: "t", angles: ["a", "b", "c"] }, ctx),
243
- );
233
+ test("one failed angle does not sink the briefing", async () => {
234
+ const model = stubDelegate({
235
+ routes: {
236
+ researcher: (call) => {
237
+ if (call.task === "b") throw new Error("provider is having a day");
238
+ return `Answer to ${call.task}.`;
239
+ },
240
+ },
241
+ });
242
+ const ctx = createToolContext({ delegate: model.delegate });
244
243
 
245
- expect(result.findings.map((one) => one.angle)).toEqual(["a", "c"]);
246
- expect(result.failed).toEqual([{ angle: "b", error: "provider is having a day" }]);
247
- // And the desk is told to say so rather than quietly reporting two angles.
248
- expect(result.message).toMatch(/could not get to/);
249
- expect(briefingSlot.get(ctx).findings).toHaveLength(2);
250
- });
244
+ const result = expectToolOk(
245
+ await run(researchTopic, { topic: "t", angles: ["a", "b", "c"] }, ctx),
246
+ );
251
247
 
252
- test("fails as a tool when every angle fails, quoting the first reason", async () => {
253
- const model = stubDelegate({
254
- routes: {
255
- researcher: () => {
256
- throw new Error("gateway said no");
257
- },
258
- },
248
+ expect(result.findings.map((one) => one.angle)).toEqual(["a", "c"]);
249
+ expect(result.failed).toEqual([{ angle: "b", error: "provider is having a day" }]);
250
+ // And the desk is told to say so rather than quietly reporting two angles.
251
+ expect(instructionOf(result)).toMatch(/could not get to/);
252
+ expect(briefingSlot.get(ctx).findings).toHaveLength(2);
259
253
  });
260
254
 
261
- const result = await run(
262
- "research_topic",
263
- { topic: "t", angles: ["a", "b"] },
264
- createToolContext({ delegate: model.delegate }),
265
- );
266
-
267
- expect(result).toEqual({ error: expect.stringContaining("gateway said no") });
268
- });
255
+ test("fails as a tool when every angle fails, quoting the first reason", async () => {
256
+ const model = stubDelegate({
257
+ routes: {
258
+ researcher: () => {
259
+ throw new Error("gateway said no");
260
+ },
261
+ },
262
+ });
269
263
 
270
- test("refuses a call whose angles are all blank, without spending a subagent", async () => {
271
- const { ctx, desk: subagents } = scriptedDesk();
264
+ const result = await run(
265
+ researchTopic,
266
+ { topic: "t", angles: ["a", "b"] },
267
+ createToolContext({ delegate: model.delegate }),
268
+ );
272
269
 
273
- const result = await run("research_topic", { topic: "t", angles: [" "] }, ctx);
270
+ expect(result).toEqual({ error: expect.stringContaining("gateway said no") });
271
+ });
274
272
 
275
- expect(result).toEqual({ error: expect.stringContaining("No angles") });
276
- expect(subagents.calls).toEqual([]);
277
- });
273
+ test("refuses a call whose angles are all blank, without spending a subagent", async () => {
274
+ const { ctx, desk: subagents } = scriptedDesk();
278
275
 
279
- test("accepts at most MAX_ANGLES angles", () => {
280
- const schema = agentDef.tools.research_topic?.inputSchema;
281
- const tooMany = { topic: "t", angles: Array.from({ length: MAX_ANGLES + 1 }, () => "a") };
282
- expect(schema?.["~standard"].validate(tooMany)).toMatchObject({ issues: expect.anything() });
283
- });
284
- });
276
+ const result = await run(researchTopic, { topic: "t", angles: [" "] }, ctx);
285
277
 
286
- describe("verify_claim", () => {
287
- test("asks the fact-checker, not the researcher", async () => {
288
- const { ctx, desk: subagents } = scriptedDesk({
289
- check: '{"verdict": "contradicted", "detail": "The figure is 12%."}',
278
+ expect(result).toEqual({ error: expect.stringContaining("No angles") });
279
+ expect(subagents.calls).toEqual([]);
290
280
  });
291
281
 
292
- const result = expectToolOk(await runTool(verifyClaim, { claim: "The figure is 40%." }, ctx));
293
-
294
- expect(subagents.calls.map((call) => call.subagent.name)).toEqual(["fact-checker"]);
295
- // The WORD the desk branches on, parsed — not a sentence it must read one out of.
296
- expect(result.verdict).toBe("contradicted");
297
- expect(result.detail).toBe("The figure is 12%.");
298
- expect(result.checkedAgainst).toBeNull();
282
+ test("accepts at most MAX_ANGLES angles", () => {
283
+ const schema = agentDef.tools.research_topic?.inputSchema;
284
+ const tooMany = { topic: "t", angles: Array.from({ length: MAX_ANGLES + 1 }, () => "a") };
285
+ expect(schema?.["~standard"].validate(tooMany)).toMatchObject({ issues: expect.anything() });
286
+ });
299
287
  });
300
288
 
301
- test("quotes the finding a claim came from, so the checker can see the source", async () => {
302
- const { ctx, desk: subagents } = scriptedDesk();
303
- briefingSlot.update(ctx, (board) => {
304
- board.findings.push({
305
- angle: "install lead times",
306
- summary: "Installers quote eight weeks.",
307
- work: { searches: 2, reads: 1 },
289
+ describe("verify_claim", () => {
290
+ test("asks the fact-checker, not the researcher", async () => {
291
+ const { ctx, desk: subagents } = scriptedDesk({
292
+ check: '{"verdict": "contradicted", "detail": "The figure is 12%."}',
308
293
  });
294
+
295
+ const result = expectToolOk(await run(verifyClaim, { claim: "The figure is 40%." }, ctx));
296
+
297
+ expect(subagents.calls.map((call) => call.subagent.name)).toEqual(["fact-checker"]);
298
+ // The WORD the desk branches on, parsed — not a sentence it must read one out of.
299
+ expect(result.verdict).toBe("contradicted");
300
+ expect(result.detail).toBe("The figure is 12%.");
301
+ expect(result.checkedAgainst).toBeNull();
309
302
  });
310
303
 
311
- const result = expectToolOk(
312
- await runTool(verifyClaim, { claim: "Installs take eight weeks.", about: "lead times" }, ctx),
313
- );
304
+ test("quotes the finding a claim came from, so the checker can see the source", async () => {
305
+ const { ctx, desk: subagents } = scriptedDesk();
306
+ briefingSlot.update(ctx, (board) => {
307
+ board.findings.push({
308
+ angle: "install lead times",
309
+ summary: "Installers quote eight weeks.",
310
+ work: { searches: 2, reads: 1 },
311
+ });
312
+ });
314
313
 
315
- expect(subagents.calls[0]?.options.context).toContain("Installers quote eight weeks.");
316
- expect(result.checkedAgainst).toBe("install lead times");
317
- });
314
+ const result = expectToolOk(
315
+ await run(verifyClaim, { claim: "Installs take eight weeks.", about: "lead times" }, ctx),
316
+ );
318
317
 
319
- test("tells the desk not to act on a verdict the schema never accepted", async () => {
320
- // A run the runtime could not parse after its retries: `accepted` is false
321
- // and the complaint says why. The scripted text is well-formed here because
322
- // `stubDelegate` parses it — what makes this the UNACCEPTED case is the
323
- // staged `complaint`.
324
- const model = stubDelegate({
325
- routes: {
326
- "fact-checker": {
327
- text: '{"verdict": "unclear", "detail": "Nothing conclusive."}',
328
- complaint: "no verdict word",
329
- },
330
- },
318
+ expect(subagents.calls[0]?.options.context).toContain("Installers quote eight weeks.");
319
+ expect(result.checkedAgainst).toBe("install lead times");
331
320
  });
332
321
 
333
- const result = expectToolOk(
334
- await runTool(
335
- verifyClaim,
336
- { claim: "Prices fell." },
337
- createToolContext({ delegate: model.delegate }),
338
- ),
339
- );
340
-
341
- // Not a tool failure: there IS an answer, and the desk is on a live call.
342
- // What changes is the instruction — the desk must not round a hedge up to a
343
- // confirmation, which is exactly what it would have done before. `verdict`
344
- // is null rather than a word, so there is nothing to round.
345
- expect(result.verdict).toBeNull();
346
- expect(result.unusable).toBe("no verdict word");
347
- expect(result.message).toContain("unresolved");
348
- });
322
+ test("tells the desk not to act on a verdict the schema never accepted", async () => {
323
+ // A run the runtime could not parse after its retries: `accepted` is false
324
+ // and the complaint says why. The scripted text is well-formed here because
325
+ // `stubDelegate` parses it — what makes this the UNACCEPTED case is the
326
+ // staged `complaint`.
327
+ const model = stubDelegate({
328
+ routes: {
329
+ "fact-checker": {
330
+ text: '{"verdict": "unclear", "detail": "Nothing conclusive."}',
331
+ complaint: "no verdict word",
332
+ },
333
+ },
334
+ });
349
335
 
350
- test("carries no `unusable` when the verdict was accepted", async () => {
351
- const { ctx } = scriptedDesk({
352
- check: '{"verdict": "confirmed", "detail": "Two sources say so."}',
336
+ const result = expectToolOk(
337
+ await run(
338
+ verifyClaim,
339
+ { claim: "Prices fell." },
340
+ createToolContext({ delegate: model.delegate }),
341
+ ),
342
+ );
343
+
344
+ // Not a tool failure: there IS an answer, and the desk is on a live call.
345
+ // What changes is the instruction — the desk must not round a hedge up to a
346
+ // confirmation, which is exactly what it would have done before. `verdict`
347
+ // is null rather than a word, so there is nothing to round.
348
+ expect(result.verdict).toBeNull();
349
+ expect(result.unusable).toBe("no verdict word");
350
+ expect(instructionOf(result)).toContain("unresolved");
353
351
  });
354
352
 
355
- const result = expectToolOk(await runTool(verifyClaim, { claim: "Prices fell." }, ctx));
353
+ test("carries no `unusable` when the verdict was accepted", async () => {
354
+ const { ctx } = scriptedDesk({
355
+ check: '{"verdict": "confirmed", "detail": "Two sources say so."}',
356
+ });
356
357
 
357
- expect(result.unusable).toBeUndefined();
358
- expect(result.message).toContain("correct what you told them earlier");
359
- });
358
+ const result = expectToolOk(await run(verifyClaim, { claim: "Prices fell." }, ctx));
360
359
 
361
- test("reports a failed check as a tool failure the model can recover from", async () => {
362
- const model = stubDelegate({
363
- routes: {
364
- "fact-checker": () => {
365
- throw new Error("checker timed out");
366
- },
367
- },
360
+ expect(result.unusable).toBeUndefined();
361
+ expect(instructionOf(result)).toContain("correct what you told them earlier");
368
362
  });
369
363
 
370
- const result = await run(
371
- "verify_claim",
372
- { claim: "Something." },
373
- createToolContext({ delegate: model.delegate }),
374
- );
375
-
376
- expect(result).toEqual({ error: expect.stringContaining("checker timed out") });
377
- });
378
-
379
- test("refuses a blank claim without spending a subagent", async () => {
380
- const { ctx, desk: subagents } = scriptedDesk();
381
- const result = await run("verify_claim", { claim: " " }, ctx);
382
- expect(result).toEqual({ error: expect.stringContaining("Nothing to check") });
383
- expect(subagents.calls).toEqual([]);
384
- });
385
- });
364
+ test("reports a failed check as a tool failure the model can recover from", async () => {
365
+ const model = stubDelegate({
366
+ routes: {
367
+ "fact-checker": () => {
368
+ throw new Error("checker timed out");
369
+ },
370
+ },
371
+ });
386
372
 
387
- describe("briefing_so_far", () => {
388
- test("says so when there is nothing yet, and spends no subagent", async () => {
389
- const ctx = createToolContext();
390
- const result = await runTool(briefingSoFar, {}, ctx);
391
- expect(result.findings).toEqual([]);
392
- });
373
+ const result = await run(
374
+ verifyClaim,
375
+ { claim: "Something." },
376
+ createToolContext({ delegate: model.delegate }),
377
+ );
393
378
 
394
- test("adds the lookups up across every angle", async () => {
395
- const ctx = createToolContext();
396
- briefingSlot.update(ctx, (board) => {
397
- board.topic = "t";
398
- board.findings.push({ angle: "a", summary: "A.", work: { searches: 2, reads: 1 } });
399
- board.findings.push({ angle: "b", summary: "B.", work: { searches: 3, reads: 0 } });
379
+ expect(result).toEqual({ error: expect.stringContaining("checker timed out") });
400
380
  });
401
381
 
402
- const result = await runTool(briefingSoFar, {}, ctx);
403
- expect(result.totalSearches).toBe(5);
404
- expect(result.totalReads).toBe(1);
405
- });
406
- });
407
-
408
- describe("the brief a subagent is sent", () => {
409
- test("carries the topic, because the subagent has not heard the call", () => {
410
- expect(angleBrief("home batteries", "price trend")).toEqual({
411
- task: "price trend",
412
- context: expect.stringContaining("home batteries"),
382
+ test("refuses a blank claim without spending a subagent", async () => {
383
+ const { ctx, desk: subagents } = scriptedDesk();
384
+ const result = await run(verifyClaim, { claim: " " }, ctx);
385
+ expect(result).toEqual({ error: expect.stringContaining("Nothing to check") });
386
+ expect(subagents.calls).toEqual([]);
413
387
  });
414
388
  });
415
- });
416
389
 
417
- describe("countWork", () => {
418
- test("tells searches from page reads", () => {
419
- expect(
420
- countWork([
421
- { name: "web_search", input: {} },
422
- { name: "visit_webpage", input: {} },
423
- { name: "web_search", input: {} },
424
- ]),
425
- ).toEqual({ searches: 2, reads: 1 });
426
- });
390
+ describe("briefing_so_far", () => {
391
+ test("says so when there is nothing yet, and spends no subagent", async () => {
392
+ const ctx = createToolContext();
393
+ const result = await run(briefingSoFar, ctx);
394
+ expect(result.findings).toEqual([]);
395
+ expect(instructionOf(result)).toContain("ask what they want");
396
+ });
427
397
 
428
- test("counts a tool it does not recognise as neither", () => {
429
- // A researcher that gains a third tool must not silently inflate "searches".
430
- expect(countWork([{ name: "think", input: {} }])).toEqual({ searches: 0, reads: 0 });
431
- });
432
- });
398
+ test("adds the lookups up across every angle", async () => {
399
+ const ctx = createToolContext();
400
+ briefingSlot.update(ctx, (board) => {
401
+ board.topic = "t";
402
+ board.findings.push({ angle: "a", summary: "A.", work: { searches: 2, reads: 1 } });
403
+ board.findings.push({ angle: "b", summary: "B.", work: { searches: 3, reads: 0 } });
404
+ });
433
405
 
434
- describe("the board", () => {
435
- test("holds MAX_FINDINGS, dropping the oldest", () => {
436
- const ctx = createToolContext();
437
- briefingSlot.update(ctx, (board) => {
438
- for (let index = 0; index < MAX_FINDINGS + 3; index++) {
439
- board.findings.push({ angle: `angle ${index}`, summary: "s", work: NO_WORK });
440
- }
406
+ const result = await run(briefingSoFar, ctx);
407
+ if (!("totalSearches" in result)) throw new Error("expected a board with findings");
408
+ expect(result.totalSearches).toBe(5);
409
+ expect(result.totalReads).toBe(1);
441
410
  });
442
- const board = briefingSlot.get(ctx);
443
- expect(board.findings).toHaveLength(MAX_FINDINGS);
444
- expect(board.findings[0]?.angle).toBe("angle 3");
445
411
  });
446
412
 
447
- test("finds an angle from a loose mention, and nothing from a blank one", () => {
448
- const ctx = createToolContext();
449
- briefingSlot.update(ctx, (board) => {
450
- board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
413
+ describe("the brief a subagent is sent", () => {
414
+ test("carries the topic, because the subagent has not heard the call", () => {
415
+ expect(angleBrief("home batteries", "price trend")).toEqual({
416
+ task: "price trend",
417
+ context: expect.stringContaining("home batteries"),
418
+ });
451
419
  });
452
- const board = briefingSlot.get(ctx);
453
- const found = findByAngle(board, "lead times");
454
- expect(isToolFailure(found) ? found : found.angle).toBe("install lead times");
455
420
  });
456
421
 
457
- test("an angle the caller could mean two ways is ASKED about, not guessed", () => {
458
- // What the `.find()` this replaced did: it took the first angle whose text
459
- // overlapped in either direction, so board order decided which of these the
460
- // claim got checked against — and it answered `undefined` for "nothing
461
- // matches" and "several do" alike.
462
- const ctx = createToolContext();
463
- briefingSlot.update(ctx, (board) => {
464
- board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
465
- board.findings.push({ angle: "battery lead times", summary: "s", work: NO_WORK });
422
+ describe("countWork", () => {
423
+ test("tells searches from page reads", () => {
424
+ expect(
425
+ countWork([
426
+ { name: "web_search", input: {} },
427
+ { name: "visit_webpage", input: {} },
428
+ { name: "web_search", input: {} },
429
+ ]),
430
+ ).toEqual({ searches: 2, reads: 1 });
466
431
  });
467
- const found = findByAngle(briefingSlot.get(ctx), "lead times");
468
- expect(isToolFailure(found)).toBe(true);
469
- expect(isToolFailure(found) && found.error).toContain("install lead times");
470
- expect(isToolFailure(found) && found.error).toContain("battery lead times");
471
- });
472
432
 
473
- test("an angle on nothing, and a blank one, each say so", () => {
474
- const ctx = createToolContext();
475
- briefingSlot.update(ctx, (board) => {
476
- board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
433
+ test("counts a tool it does not recognise as neither", () => {
434
+ // A researcher that gains a third tool must not silently inflate "searches".
435
+ expect(countWork([{ name: "think", input: {} }])).toEqual({ searches: 0, reads: 0 });
477
436
  });
478
- const board = briefingSlot.get(ctx);
479
- const missing = findByAngle(board, "battery chemistry");
480
- expect(isToolFailure(missing) && missing.error).toContain("install lead times");
481
- const blank = findByAngle(board, " ");
482
- expect(isToolFailure(blank) && blank.error).toContain("which angle");
483
437
  });
484
- });
485
438
 
486
- // ---- Sending it on ----------------------------------------------------------
487
-
488
- /** A destination that really is Slack's, which is what the guard checks. */
489
- const WEBHOOK = "https://hooks.slack.com/services/T00/B00/xxxxxxxx";
439
+ describe("the board", () => {
440
+ test("is per session, and holds MAX_FINDINGS, dropping the oldest", () => {
441
+ expectSlotContract(briefingSlot, {
442
+ write: (board) => {
443
+ board.topic = "t";
444
+ },
445
+ });
446
+ });
490
447
 
491
- /** A context with a board on it and a channel configured. */
492
- function deskWithBoard(env: Record<string, string> = { [DESTINATION_ENV]: WEBHOOK }) {
493
- const ctx = createToolContext({ env });
494
- briefingSlot.update(ctx, (board) => {
495
- board.topic = "home batteries";
496
- board.findings.push({
497
- angle: "price trend",
498
- summary: "Pack prices fell 14% year on year.",
499
- work: { searches: 2, reads: 1 },
448
+ test("finds an angle from a loose mention, and nothing from a blank one", () => {
449
+ const ctx = createToolContext();
450
+ briefingSlot.update(ctx, (board) => {
451
+ board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
452
+ });
453
+ const board = briefingSlot.get(ctx);
454
+ const found = findByAngle(board, "lead times");
455
+ expect(isToolFailure(found) ? found : found.angle).toBe("install lead times");
500
456
  });
501
- board.findings.push({
502
- angle: "install lead times",
503
- summary: "Installers quote eight weeks.",
504
- work: { searches: 3, reads: 0 },
457
+
458
+ test("an angle the caller could mean two ways is ASKED about, not guessed", () => {
459
+ // What the `.find()` this replaced did: it took the first angle whose text
460
+ // overlapped in either direction, so board order decided which of these the
461
+ // claim got checked against — and it answered `undefined` for "nothing
462
+ // matches" and "several do" alike.
463
+ const ctx = createToolContext();
464
+ briefingSlot.update(ctx, (board) => {
465
+ board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
466
+ board.findings.push({ angle: "battery lead times", summary: "s", work: NO_WORK });
467
+ });
468
+ const found = findByAngle(briefingSlot.get(ctx), "lead times");
469
+ expect(isToolFailure(found)).toBe(true);
470
+ expect(isToolFailure(found) && found.error).toContain("install lead times");
471
+ expect(isToolFailure(found) && found.error).toContain("battery lead times");
505
472
  });
506
- });
507
- return ctx;
508
- }
509
473
 
510
- describe("the briefing as a channel message", () => {
511
- /**
512
- * What is left to assert here once the channel owns the wire: the MESSAGE,
513
- * not the payload. Slack's two webhook shapes, the Block Kit assembly and the
514
- * mrkdwn escaping are `@alexkroman1/aai/channels`' and are covered by its own
515
- * specs — a template asserting them again would pin the SDK's rendering from
516
- * the outside.
517
- */
518
- test("carries every angle as its own section, in the order they were researched", () => {
519
- const message = briefingMessage(briefingSlot.get(deskWithBoard()));
520
-
521
- expect(message.heading).toBe("Briefing: home batteries");
522
- expect(message.sections).toEqual([
523
- { title: "price trend", body: "Pack prices fell 14% year on year." },
524
- { title: "install lead times", body: "Installers quote eight weeks." },
525
- ]);
474
+ test("an angle on nothing, and a blank one, each say so", () => {
475
+ const ctx = createToolContext();
476
+ briefingSlot.update(ctx, (board) => {
477
+ board.findings.push({ angle: "install lead times", summary: "s", work: NO_WORK });
478
+ });
479
+ const board = briefingSlot.get(ctx);
480
+ const missing = findByAngle(board, "battery chemistry");
481
+ expect(isToolFailure(missing) && missing.error).toContain("install lead times");
482
+ const blank = findByAngle(board, " ");
483
+ expect(isToolFailure(blank) && blank.error).toContain("which angle");
484
+ });
526
485
  });
527
486
 
528
- test("says how many angles in the notification line and what they cost in the subtitle", () => {
529
- const message = briefingMessage(briefingSlot.get(deskWithBoard()));
487
+ // ---- Sending it on ----------------------------------------------------------
530
488
 
531
- // The notification line is the WHOLE message on a Slack workflow trigger,
532
- // so it has to stand on its own.
533
- expect(message.text).toBe("Briefing on home batteries: 2 angles");
534
- // The same two numbers `briefing_so_far` reads back, from the same helper.
535
- expect(message.subtitle).toBe("5 searches, 1 page read");
536
- });
489
+ /** A destination that really is Slack's, which is what the guard checks. */
490
+ const WEBHOOK = "https://hooks.slack.com/services/T00/B00/xxxxxxxx";
537
491
 
538
- test("still names something when the board carries findings and no topic", () => {
539
- // Reachable: a tool can push to the board without setting `topic`, and a
540
- // heading reading "Briefing: null" is the kind of thing a channel keeps
541
- // forever.
542
- const ctx = createToolContext();
492
+ /** A context with a board on it and a channel configured. */
493
+ function deskWithBoard(env: Record<string, string> = { [DESTINATION_ENV]: WEBHOOK }) {
494
+ const ctx = createToolContext({ env });
543
495
  briefingSlot.update(ctx, (board) => {
544
- board.findings.push({ angle: "a", summary: "A.", work: NO_WORK });
496
+ board.topic = "home batteries";
497
+ board.findings.push({
498
+ angle: "price trend",
499
+ summary: "Pack prices fell 14% year on year.",
500
+ work: { searches: 2, reads: 1 },
501
+ });
502
+ board.findings.push({
503
+ angle: "install lead times",
504
+ summary: "Installers quote eight weeks.",
505
+ work: { searches: 3, reads: 0 },
506
+ });
507
+ });
508
+ return ctx;
509
+ }
510
+
511
+ describe("the briefing as a channel message", () => {
512
+ /**
513
+ * What is left to assert here once the channel owns the wire: the MESSAGE,
514
+ * not the payload. Slack's two webhook shapes, the Block Kit assembly and the
515
+ * mrkdwn escaping are `@alexkroman1/aai/channels`' and are covered by its own
516
+ * specs — a template asserting them again would pin the SDK's rendering from
517
+ * the outside.
518
+ */
519
+ test("carries every angle as its own section, in the order they were researched", () => {
520
+ const message = briefingMessage(briefingSlot.get(deskWithBoard()));
521
+
522
+ expect(message.heading).toBe("Briefing: home batteries");
523
+ expect(message.sections).toEqual([
524
+ { title: "price trend", body: "Pack prices fell 14% year on year." },
525
+ { title: "install lead times", body: "Installers quote eight weeks." },
526
+ ]);
545
527
  });
546
528
 
547
- const message = briefingMessage(briefingSlot.get(ctx));
529
+ test("says how many angles in the notification line and what they cost in the subtitle", () => {
530
+ const message = briefingMessage(briefingSlot.get(deskWithBoard()));
548
531
 
549
- expect(message.heading).toBe("Briefing: an unnamed subject");
550
- expect(message.text).toBe("Briefing on an unnamed subject: 1 angle");
551
- expect(message.subtitle).toBe("0 searches, 0 pages read");
552
- });
532
+ // The notification line is the WHOLE message on a Slack workflow trigger,
533
+ // so it has to stand on its own.
534
+ expect(message.text).toBe("Briefing on home batteries: 2 angles");
535
+ // The same two numbers `briefing_so_far` reads back, from the same helper.
536
+ expect(message.subtitle).toBe("5 searches, 1 page read");
537
+ });
553
538
 
554
- test("refuses a destination that is not Slack, before anything is posted", () => {
555
- // A security boundary rather than a typo check: the value is the target of
556
- // a POST carrying everything the desk was told.
557
- const refused = briefingChannel("https://example.test/collect");
558
- expect(isToolFailure(refused) && refused.error).toContain(DESTINATION_ENV);
559
- expect(briefingChannel(WEBHOOK)).toMatchObject({ kind: "slack" });
560
- });
561
- });
539
+ test("still names something when the board carries findings and no topic", () => {
540
+ // Reachable: a tool can push to the board without setting `topic`, and a
541
+ // heading reading "Briefing: null" is the kind of thing a channel keeps
542
+ // forever.
543
+ const ctx = createToolContext();
544
+ briefingSlot.update(ctx, (board) => {
545
+ board.findings.push({ angle: "a", summary: "A.", work: NO_WORK });
546
+ });
562
547
 
563
- describe("send_briefing", () => {
564
- test("posts the board to the configured channel and reports what went", async () => {
565
- // `installStubStepFetch`, not a stubbed global: a channel posts through the
566
- // SDK's own `stepFetch` slot, and stubbing the global would test a path
567
- // production does not take.
568
- const posted = installStubStepFetch(() => ({ body: "ok" }));
548
+ const message = briefingMessage(briefingSlot.get(ctx));
569
549
 
570
- const result = expectToolOk(await runTool(sendBriefing, {}, deskWithBoard()));
550
+ expect(message.heading).toBe("Briefing: an unnamed subject");
551
+ expect(message.text).toBe("Briefing on an unnamed subject: 1 angle");
552
+ expect(message.subtitle).toBe("0 searches, 0 pages read");
553
+ });
571
554
 
572
- expect(posted.calls).toHaveLength(1);
573
- expect(posted.calls[0]?.url).toBe(WEBHOOK);
574
- expect(posted.calls[0]?.method).toBe("POST");
575
- expect(result).toMatchObject({ sent: 2, topic: "home batteries" });
576
- expect(result.message).toMatch(/in writing/);
555
+ test("refuses a destination that is not Slack, before anything is posted", () => {
556
+ // A security boundary rather than a typo check: the value is the target of
557
+ // a POST carrying everything the desk was told.
558
+ const refused = briefingChannel("https://example.test/collect");
559
+ expect(isToolFailure(refused) && refused.error).toContain(DESTINATION_ENV);
560
+ expect(briefingChannel(WEBHOOK)).toMatchObject({ kind: "slack" });
561
+ });
577
562
  });
578
563
 
579
- test("spends no request on an empty board", async () => {
580
- const posted = installStubStepFetch(() => ({ body: "ok" }));
581
- const ctx = createToolContext({ env: { [DESTINATION_ENV]: WEBHOOK } });
564
+ describe("send_briefing", () => {
565
+ test("posts the board to the configured channel and reports what went", async () => {
566
+ // `installStubStepFetch`, not a stubbed global: a channel posts through the
567
+ // SDK's own `stepFetch` slot, and stubbing the global would test a path
568
+ // production does not take.
569
+ const posted = installStubStepFetch(() => ({ body: "ok" }));
582
570
 
583
- const result = await run("send_briefing", {}, ctx);
571
+ const result = expectToolOk(await run(sendBriefing, deskWithBoard()));
584
572
 
585
- expect(result).toEqual({ error: expect.stringContaining("nothing to send") });
586
- expect(posted.calls).toEqual([]);
587
- });
573
+ expect(posted.calls).toHaveLength(1);
574
+ expect(posted.calls[0]?.url).toBe(WEBHOOK);
575
+ expect(posted.calls[0]?.method).toBe("POST");
576
+ expect(result).toMatchObject({ sent: 2, topic: "home batteries" });
577
+ expect(instructionOf(result)).toMatch(/in writing/);
578
+ });
588
579
 
589
- test("offers to try again when Slack is having a bad minute", async () => {
590
- installStubStepFetch(() => ({ status: 503, body: { error: "server_error" } }));
580
+ test("spends no request on an empty board", async () => {
581
+ const posted = installStubStepFetch(() => ({ body: "ok" }));
582
+ const ctx = createToolContext({ env: { [DESTINATION_ENV]: WEBHOOK } });
591
583
 
592
- const result = await run("send_briefing", {}, deskWithBoard());
584
+ const result = await run(sendBriefing, ctx);
593
585
 
594
- expect(isToolFailure(result) && result.error).toMatch(/try again/);
595
- });
586
+ expect(result).toEqual({ error: expect.stringContaining("nothing to send") });
587
+ expect(posted.calls).toEqual([]);
588
+ });
596
589
 
597
- test("does NOT offer a retry for a refusal that will answer the same way forever", async () => {
598
- // The 4xx/5xx split is the whole reason this goes through a channel: a
599
- // revoked webhook answers identically on every attempt, and promising the
600
- // caller another go is a promise the desk cannot keep.
601
- installStubStepFetch(() => ({ status: 403, body: { error: "invalid_token" } }));
590
+ test("offers to try again when Slack is having a bad minute", async () => {
591
+ installStubStepFetch(() => ({ status: 503, body: { error: "server_error" } }));
602
592
 
603
- const result = await run("send_briefing", {}, deskWithBoard());
593
+ const result = await run(sendBriefing, deskWithBoard());
604
594
 
605
- expect(isToolFailure(result) && result.error).toMatch(/will not help/);
606
- expect(isToolFailure(result) && result.error).not.toMatch(/try again/);
607
- });
595
+ expect(isToolFailure(result) && result.error).toMatch(/try again/);
596
+ });
597
+
598
+ test("does NOT offer a retry for a refusal that will answer the same way forever", async () => {
599
+ // The 4xx/5xx split is the whole reason this goes through a channel: a
600
+ // revoked webhook answers identically on every attempt, and promising the
601
+ // caller another go is a promise the desk cannot keep.
602
+ installStubStepFetch(() => ({ status: 403, body: { error: "invalid_token" } }));
603
+
604
+ const result = await run(sendBriefing, deskWithBoard());
608
605
 
609
- test("reports a connection that never got there as itself", async () => {
610
- // Not a `ChannelDeliveryError`: there was no response to classify. The
611
- // channel cannot say whether a retry would help, so neither does the desk.
612
- installStubStepFetch(() => {
613
- throw new Error("connection reset");
606
+ expect(isToolFailure(result) && result.error).toMatch(/will not help/);
607
+ expect(isToolFailure(result) && result.error).not.toMatch(/try again/);
614
608
  });
615
609
 
616
- const result = await run("send_briefing", {}, deskWithBoard());
610
+ test("reports a connection that never got there as itself", async () => {
611
+ // Not a `ChannelDeliveryError`: there was no response to classify. The
612
+ // channel cannot say whether a retry would help, so neither does the desk.
613
+ installStubStepFetch(() => {
614
+ throw new Error("connection reset");
615
+ });
617
616
 
618
- expect(isToolFailure(result) && result.error).toMatch(/did not send/);
619
- expect(isToolFailure(result) && result.error).toContain("connection reset");
620
- });
617
+ const result = await run(sendBriefing, deskWithBoard());
621
618
 
622
- test("names the missing variable when no channel is configured", async () => {
623
- // The one deliberate throw in this template: a missing credential is not
624
- // something the call can recover from, and the message is the fix.
625
- const posted = installStubStepFetch(() => ({ body: "ok" }));
619
+ expect(isToolFailure(result) && result.error).toMatch(/did not send/);
620
+ expect(isToolFailure(result) && result.error).toContain("connection reset");
621
+ });
626
622
 
627
- await expect(run("send_briefing", {}, deskWithBoard({}))).rejects.toThrow(DESTINATION_ENV);
628
- expect(posted.calls).toEqual([]);
629
- });
623
+ test("names the missing variable when no channel is configured", async () => {
624
+ // The one deliberate throw in this template: a missing credential is not
625
+ // something the call can recover from, and the message is the fix.
626
+ const posted = installStubStepFetch(() => ({ body: "ok" }));
630
627
 
631
- test("declares onError, so a missing webhook is FATAL rather than something to retry", () => {
632
- // Without it the runtime hands every throw to the model as this call's
633
- // result, and the desk re-calls `send_briefing` against a variable that is
634
- // still unset — burning the reply's step budget on a deploy fault. The
635
- // handler re-throws, which is how a tool says "stop, this cannot work".
636
- const sender = toolOf(deployed, "send_briefing");
637
- expect(sender.onError).toBeDefined();
638
- const cause = new Error(`Missing required environment variable: ${DESTINATION_ENV}`);
639
- expect(() => sender.onError?.(cause, createToolContext())).toThrow(cause);
640
- });
628
+ await expect(run(sendBriefing, deskWithBoard({}))).rejects.toThrow(DESTINATION_ENV);
629
+ expect(posted.calls).toEqual([]);
630
+ });
631
+
632
+ test("declares onError, so a missing webhook is FATAL rather than something to retry", () => {
633
+ // Without it the runtime hands every throw to the model as this call's
634
+ // result, and the desk re-calls `send_briefing` against a variable that is
635
+ // still unset — burning the reply's step budget on a deploy fault. The
636
+ // handler re-throws, which is how a tool says "stop, this cannot work".
637
+ const sender = toolOf(agentDef, "send_briefing");
638
+ expect(sender.onError).toBeDefined();
639
+ const cause = new Error(`Missing required environment variable: ${DESTINATION_ENV}`);
640
+ expect(() => sender.onError?.(cause, createToolContext())).toThrow(cause);
641
+ });
641
642
 
642
- test("refuses a configured destination that is not Slack, without posting", async () => {
643
- const posted = installStubStepFetch(() => ({ body: "ok" }));
644
- const ctx = deskWithBoard({ [DESTINATION_ENV]: "https://example.test/collect" });
643
+ test("refuses a configured destination that is not Slack, without posting", async () => {
644
+ const posted = installStubStepFetch(() => ({ body: "ok" }));
645
+ const ctx = deskWithBoard({ [DESTINATION_ENV]: "https://example.test/collect" });
645
646
 
646
- const result = await run("send_briefing", {}, ctx);
647
+ const result = await run(sendBriefing, ctx);
647
648
 
648
- expect(isToolFailure(result) && result.error).toContain(DESTINATION_ENV);
649
- expect(posted.calls).toEqual([]);
649
+ expect(isToolFailure(result) && result.error).toContain(DESTINATION_ENV);
650
+ expect(posted.calls).toEqual([]);
651
+ });
650
652
  });
651
653
  });