@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
@@ -2,56 +2,38 @@
2
2
  /// <reference types="vite/client" />
3
3
 
4
4
  /**
5
- * Specs for the research desk's four tools.
5
+ * Specs for the research desk.
6
6
  *
7
- * All are exercised against a STUBBED `ctx.workflows`, which is the honest way
8
- * to unit-test a TOOL: what a tool owns is the call it makes, not what the run
9
- * does afterwards.
10
- * What these assert is the agent's half of the contract — that the handoff tool
11
- * passes the correlation key, that the status tool narrows a snapshot correctly
12
- * before reading it aloud, and that the two tools reaching PAST a status (the
13
- * progress stream, the early wake) ask for what a voice reply can use.
14
- *
15
- * The WORKFLOW half is `workflows.test.ts` beside this file: the steps driven
16
- * directly, the body on the real replay engine, and what a finished pass files.
17
- * The split is where the subject changes rather than where the line count did —
18
- * a tool's subject is the call it makes with a `ToolContext`, and a step's is
19
- * what it does with none.
7
+ * Three tiers: the two tools against a stubbed `ctx.workflows` (what a tool owns
8
+ * is the call it makes), the desk's configuration and delivery through
9
+ * `createWorkflowContext`, and the whole run on the real replay engine
10
+ * (`runWorkflow`). The pass itself — the brief's fallback, the planner's width
11
+ * cap, the researcher's cite-else-opened sources — is asserted in the SDK's own
12
+ * `sdk/deep-research.test.ts`; what is asserted here is this desk's half.
20
13
  */
21
14
 
22
- /** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
23
15
  import agentDef from "virtual:aai/agent";
24
- import { DEFAULT_STEP_MAX_ATTEMPTS, type WorkflowClient } from "@alexkroman1/aai";
16
+ import { describeRun } from "@alexkroman1/aai";
25
17
  import { renderSlackPlainText } from "@alexkroman1/aai/channels";
26
18
  import {
27
19
  DEFAULT_DEEP_RESEARCH_BUDGET,
28
20
  DEFAULT_DEEP_RESEARCH_PROMPTS,
29
21
  } from "@alexkroman1/aai/experimental";
30
22
  import { FatalError, RetryableError } from "@alexkroman1/aai/step-errors";
31
- import type { WorkflowRunSnapshot } from "@alexkroman1/aai/workflow-api";
32
- import type {
33
- JournalStore,
34
- ResumableRun,
35
- RunWorkflowOptions,
36
- SleepRecord,
37
- StepEntry,
38
- WorkflowTestHandle,
39
- WorkflowTestRun,
40
- } from "@alexkroman1/aai-runtime/testing";
23
+ import type { WorkflowTestRun, WorkflowTestWait } from "@alexkroman1/aai-runtime/testing";
41
24
  import {
42
25
  createRunSnapshot,
43
26
  createToolContext,
44
27
  createWorkflowContext,
45
28
  parseSchemaInput,
46
- runTool,
47
29
  runWorkflow,
48
30
  type StubStepAnswer,
49
31
  type StubStepFetch,
50
32
  type StubStepRequest,
51
33
  schemaInputIssues,
52
- toolRunner,
53
34
  } from "@alexkroman1/aai-runtime/testing";
54
35
  import {
36
+ describeAgent,
55
37
  installStubGateway,
56
38
  installStubReporter,
57
39
  installStubStepDelegate,
@@ -59,8 +41,8 @@ import {
59
41
  installStubWorkflows,
60
42
  } from "@alexkroman1/aai-runtime/testing/vitest";
61
43
  import { beforeEach, describe, expect, test, vi } from "vitest";
62
- import { research } from "./shared.ts";
63
- import researchStatus from "./tools/research_status.ts";
44
+ import fileItNow from "./tools/file_it_now.ts";
45
+ import requestResearch from "./tools/request_research.ts";
64
46
  import {
65
47
  FILING_TEXT_PARAM_ENV,
66
48
  FILING_WEBHOOK_ENV,
@@ -70,312 +52,110 @@ import {
70
52
  renderFiling,
71
53
  } from "./workflows/filing.ts";
72
54
  import { BRIEF_SUMMARY_SYSTEM, BRIEF_SYSTEM } from "./workflows/prompts.ts";
73
- import { deliverResearch } from "./workflows/research.ts";
74
- import { REVIEW_DELAY_MS, REVIEW_SLEEP_ID } from "./workflows/review.ts";
75
-
76
- /**
77
- * Every tool here is driven through the agent's own table, by the name the model
78
- * calls.
79
- *
80
- * The second parameter is args-or-context, which is `runTool`'s own shape: three
81
- * of this desk's four tools take no arguments, and the `{}` those calls were
82
- * obliged to pass sat between the two values a reader cares about.
83
- */
84
- const run = toolRunner(agentDef);
85
-
86
- /**
87
- * A `ctx.workflows` that records `start` and answers `find` from a fixture.
88
- *
89
- * Returned WITHOUT a cast, which is the property worth keeping: a cast would
90
- * also stop reporting the day `WorkflowClient` grows a method, and this stub is
91
- * how the template's tools reach the client at all. `installStubWorkflows`
92
- * (`@alexkroman1/aai-runtime/testing/vitest`) is what keeps that affordable — a `vi.fn`
93
- * per method over one `runs` list, filling in what this desk does not drive, so
94
- * the day the client does grow a method only the tests using it change.
95
- * `stream`/`streamTail` are left rejecting on purpose: `research_progress` reads
96
- * progress through `lastLine`, and composing those two by hand is the hazard
97
- * `lastLine` exists to remove.
98
- */
99
- function stubWorkflows(runs: WorkflowRunSnapshot[] = []): WorkflowClient {
100
- // Name only: `WorkflowSummary.description` is optional, so passing this
101
- // desk's through would mean handing `description: undefined` to a field that
102
- // does not accept it. Nothing here reads the description anyway.
103
- return installStubWorkflows({ runs, names: ["research"] });
55
+ import research, { deliverResearch, REVIEW_DELAY_MS } from "./workflows/research.ts";
56
+
57
+ /** A finished pass, as the status line reads it. */
58
+ function findings(over: { summary?: string; sources?: number } = {}) {
59
+ return {
60
+ topic: "otters",
61
+ summary: "Otters use tools.",
62
+ report: "# Otters",
63
+ sources: 3,
64
+ angles: ["Tool use"],
65
+ filedAt: "2026-01-01T00:00:00.000Z",
66
+ ...over,
67
+ };
104
68
  }
105
69
 
106
- describe("the agent declares its workflow", () => {
107
- test("under the name ctx.workflows.start resolves it by", () => {
108
- // `toContain` rather than an exact key list: a second workflow is an
109
- // invited edit and must not redden a test the author did not write. The
110
- // NAME is still pinned, deliberately — this key is a STRING to everything
111
- // outside this file (the REST route, `ctx.workflows.get`, a schedule), so
112
- // renaming it is a runtime 404 rather than a compile error, and nothing
113
- // else says so.
114
- expect(Object.keys(agentDef.workflows ?? {})).toContain("research");
70
+ describeAgent(agentDef, (run) => {
71
+ test("declares its workflow by its file name, with an input schema", async () => {
72
+ // `workflows/research.ts` is discovered the way `tools/` is, so the name the
73
+ // run API and the builtins use is the file's.
115
74
  expect(agentDef.workflows?.research).toBe(research);
116
- });
117
-
118
- test("with an input schema, so a bad topic fails at the call site", async () => {
119
- // `parseSchemaInput` / `schemaInputIssues` rather than a reach through
120
- // `["~standard"].validate`: that is the vendor WIRE contract, and whether it
121
- // answers synchronously or with a promise is the vendor's business — a
122
- // missing `await` there leaves `.issues` undefined and the refusing half
123
- // passes for the wrong reason.
124
75
  const parsed = await parseSchemaInput(research.input, { topic: "otters", requestedBy: "s" });
125
76
  expect(parsed).toMatchObject({ topic: "otters" });
126
77
  expect(
127
78
  await schemaInputIssues(research.input, { topic: "no", requestedBy: "s" }),
128
79
  ).toBeDefined();
129
80
  });
130
- });
131
-
132
- /**
133
- * The options `request_research` starts its run with.
134
- *
135
- * AWAITED rather than `void`-ed. Reading a mock's call list off a floating
136
- * promise worked only because the tool body happens to reach `start` before its
137
- * first `await`; anything async landing ahead of that would have made this
138
- * return `undefined` and the reader throw a `TypeError` instead of failing on
139
- * the option it is about — and the dropped promise is an unhandled rejection
140
- * either way.
141
- *
142
- * The return type is inferred from the mock, so `notify` arrives typed and the
143
- * caller needs no cast.
144
- */
145
- async function workflowsStartOptions() {
146
- const workflows = stubWorkflows();
147
- const ctx = createToolContext({ workflows });
148
- await run("request_research", { topic: "otters" }, ctx);
149
- return vi.mocked(workflows.start).mock.calls[0]?.[2];
150
- }
151
-
152
- describe("request_research", () => {
153
- test("starts a run keyed by the session, so a later turn can find it", async () => {
154
- const workflows = stubWorkflows();
155
- const ctx = createToolContext({ workflows });
156
- const result = await run("request_research", { topic: "otters" }, ctx);
157
-
158
- expect(workflows.start).toHaveBeenCalledWith(
159
- research,
160
- { topic: "otters", requestedBy: ctx.sessionId },
161
- // `key` is the DURABLE handle — a later call finds the run by it — and
162
- // `notify` is the live one: this session is told when the run lands, which
163
- // is what makes the agent's "I'll let you know" true.
164
- { key: ctx.sessionId, notify: expect.stringContaining("read the summary") },
165
- );
166
- expect(result).toMatchObject({ started: true, runId: "wrun_stub", topic: "otters" });
167
- });
168
-
169
- test("asks to be TOLD when the run lands, rather than waiting to be asked", async () => {
170
- // The gap this closes: the agent promised an update, the run finished, and
171
- // nothing made it speak — so the caller had to think to ask again. A voice
172
- // agent that starts durable work and never announces it is the shape to
173
- // avoid, and one option is the whole fix.
174
- const options = await workflowsStartOptions();
175
- expect(options, "request_research started no run").toBeDefined();
176
- expect(typeof options?.notify).toBe("string");
177
- });
178
-
179
- test("passes the definition rather than its name", async () => {
180
- const workflows = stubWorkflows();
181
- await run("request_research", { topic: "otters" }, createToolContext({ workflows }));
182
- // The def overload is what types the input and turns a rename into a compile
183
- // error; a string would still work at runtime and lose both.
184
- expect(vi.mocked(workflows.start).mock.calls[0]?.[0]).toBe(research);
185
- });
186
- });
187
-
188
- describe("research_status", () => {
189
- test("says nothing was started when the key has no runs", async () => {
190
- const ctx = createToolContext({ workflows: stubWorkflows([]) });
191
- const result = await run("research_status", ctx);
192
- expect(result).toMatchObject({ runs: [], note: "Nothing started yet." });
193
- });
194
-
195
- test("reads a completed run's summary and source count back", async () => {
196
- const runs = [
197
- createRunSnapshot({
198
- workflow: "research",
199
- status: "completed",
200
- output: { topic: "otters", summary: "Otters use tools.", sources: 3, filedAt: "now" },
201
- }),
202
- ];
203
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
204
- const result = await runTool(researchStatus, ctx);
205
- expect(result.runs[0]).toContain("Otters use tools.");
206
- expect(result.runs[0]).toContain("3 sources");
207
- });
208
-
209
- test("says WHEN it was asked for, so two requests can be told apart", async () => {
210
- // What a caller ringing back needs. It replaces the workflow NAME, which
211
- // was the same word on every line and read aloud as noise.
212
- const runs = [
213
- createRunSnapshot({
214
- workflow: "research",
215
- status: "running",
216
- createdAt: Date.now() - 12 * 60_000,
217
- }),
218
- ];
219
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
220
- const result = await runTool(researchStatus, ctx);
221
- expect(result.runs[0]).toContain("12 minutes ago");
222
- expect(result.runs[0]).not.toContain("research:");
223
- });
224
81
 
225
- test("a run started moments ago is not reported as zero minutes old", async () => {
226
- const ctx = createToolContext({
227
- workflows: stubWorkflows([
228
- createRunSnapshot({ workflow: "research", status: "running", createdAt: Date.now() }),
229
- ]),
82
+ describe("request_research", () => {
83
+ test("starts a run on the session's key, and asks to be TOLD when it lands", async () => {
84
+ const workflows = installStubWorkflows({ agent: agentDef });
85
+ const ctx = createToolContext({ workflows });
86
+ const result = await run(requestResearch, { topic: "otters" }, ctx);
87
+
88
+ // The def, not its name, so the input is typed; no `key`, because a
89
+ // tool's start is keyed by the session by default; and `notify` is what
90
+ // makes the agent's "I'll let you know" true.
91
+ expect(workflows.start).toHaveBeenCalledWith(
92
+ research,
93
+ { topic: "otters", requestedBy: ctx.sessionId },
94
+ { notify: expect.stringContaining("read the summary") },
95
+ );
96
+ expect(result).toEqual({ started: true, runId: "wrun_stub", topic: "otters" });
230
97
  });
231
- const result = await runTool(researchStatus, ctx);
232
- expect(result.runs[0]).toContain("Just now");
233
98
  });
234
99
 
235
- test("reports a live run as still working rather than as empty", async () => {
236
- const ctx = createToolContext({
237
- workflows: stubWorkflows([createRunSnapshot({ workflow: "research", status: "running" })]),
100
+ describe("file_it_now", () => {
101
+ test("wakes the REVIEW wait by its label, not whatever the run happens to hold", async () => {
102
+ const workflows = installStubWorkflows({
103
+ agent: agentDef,
104
+ runs: [createRunSnapshot(research, { status: "running" })],
105
+ });
106
+ vi.mocked(workflows.wakeUp).mockResolvedValue(1);
107
+ const result = await run(fileItNow, createToolContext({ workflows }));
108
+ expect(workflows.wakeUp).toHaveBeenCalledWith("wrun_1", {
109
+ correlationIds: ["reviewWindow"],
110
+ });
111
+ expect(result).toMatchObject({ filed: true });
238
112
  });
239
- const result = await runTool(researchStatus, ctx);
240
- expect(result.runs[0]).toContain("Still working on it.");
241
- });
242
113
 
243
- test("surfaces a failed run's message instead of swallowing it", async () => {
244
- const runs = [
245
- createRunSnapshot({ workflow: "research", status: "failed", error: "model unavailable" }),
246
- ];
247
- const ctx = createToolContext({ workflows: stubWorkflows(runs) });
248
- const result = await runTool(researchStatus, ctx);
249
- expect(result.runs[0]).toContain("model unavailable");
250
- });
114
+ test("a run that was not waiting is reported honestly, not as a failure", async () => {
115
+ const workflows = installStubWorkflows({
116
+ agent: agentDef,
117
+ runs: [createRunSnapshot(research, { status: "running" })],
118
+ });
119
+ const result = await run(fileItNow, createToolContext({ workflows }));
120
+ expect(result).toMatchObject({ filed: false, note: expect.stringContaining("moved on") });
121
+ });
251
122
 
252
- test("bounds how many past runs it reads aloud", async () => {
253
- const workflows = stubWorkflows([]);
254
- const ctx = createToolContext({ workflows });
255
- await run("research_status", ctx);
256
- // A voice reply cannot be a list of twenty runs.
257
- expect(workflows.find).toHaveBeenCalledWith(research, ctx.sessionId, { limit: 3 });
123
+ test("says nothing is in flight when the session's runs have all finished", async () => {
124
+ const workflows = installStubWorkflows({
125
+ agent: agentDef,
126
+ runs: [createRunSnapshot(research, { status: "completed", output: findings() })],
127
+ });
128
+ const result = await run(fileItNow, createToolContext({ workflows }));
129
+ expect(result).toMatchObject({ filed: false, note: expect.stringContaining("in flight") });
130
+ expect(workflows.wakeUp).not.toHaveBeenCalled();
131
+ });
258
132
  });
259
133
  });
260
134
 
261
- describe("research_progress", () => {
262
- test("reads the run's own progress line rather than its status", async () => {
263
- const workflows = stubWorkflows([
264
- createRunSnapshot({ workflow: "research", status: "running" }),
265
- ]);
266
- vi.mocked(workflows.lastLine).mockResolvedValue("Found 3 sources.");
267
- const result = await run("research_progress", createToolContext({ workflows }));
268
- expect(result).toMatchObject({ progress: "Found 3 sources." });
269
- });
270
-
271
- test("asks for the LAST line, not the whole log", async () => {
272
- // A voice reply cannot recite every line the run has written. `lastLine` is
273
- // the whole request — the bound that keeps an empty channel from hanging
274
- // belongs to the method, so nothing here composes `streamTail` and `stream`.
275
- const workflows = stubWorkflows([
276
- createRunSnapshot({ workflow: "research", status: "running" }),
277
- ]);
278
- vi.mocked(workflows.lastLine).mockResolvedValue("a");
279
- await run("research_progress", createToolContext({ workflows }));
280
- expect(workflows.lastLine).toHaveBeenCalledWith("wrun_1");
281
- });
282
-
283
- test("a run that has written nothing yet says so", async () => {
284
- // `lastLine` resolves `undefined` for an empty channel, and this is the arm
285
- // the tool branches on. That an empty channel does not HANG — it is never
286
- // closed, so a stream opened on one waits for a line that may never come —
287
- // is `lastLine`'s own guarantee now, and `aai`'s to test.
288
- const workflows = stubWorkflows([
289
- createRunSnapshot({ workflow: "research", status: "running" }),
290
- ]);
291
- const result = await run("research_progress", createToolContext({ workflows }));
292
- expect(result).toMatchObject({ note: "Started, nothing to report yet." });
293
- });
294
-
295
- test("says nothing was started when the key has no runs", async () => {
296
- const workflows = stubWorkflows([]);
297
- const result = await run("research_progress", createToolContext({ workflows }));
298
- expect(result).toMatchObject({ note: "Nothing started yet." });
299
- expect(workflows.lastLine).not.toHaveBeenCalled();
135
+ describe("what the status builtin says per run", () => {
136
+ test("reads a completed run's summary and source count back", () => {
137
+ const run = createRunSnapshot(research, { status: "completed", output: findings() });
138
+ expect(describeRun(research, run)).toContain("Otters use tools.");
139
+ expect(describeRun(research, run)).toContain("3 sources");
300
140
  });
301
- });
302
141
 
303
- describe("file_it_now", () => {
304
- test("wakes the sleeping run so the review wait ends early", async () => {
305
- const workflows = stubWorkflows([
306
- createRunSnapshot({ workflow: "research", status: "running" }),
307
- ]);
308
- vi.mocked(workflows.wakeUp).mockResolvedValue(1);
309
- const result = await run("file_it_now", createToolContext({ workflows }));
310
- expect(workflows.wakeUp).toHaveBeenCalledWith("wrun_1", {
311
- correlationIds: [REVIEW_SLEEP_ID],
142
+ test("says WHEN it was asked for, so two requests can be told apart", () => {
143
+ const twelveMinutesAgo = createRunSnapshot(research, {
144
+ status: "running",
145
+ createdAt: Date.now() - 12 * 60_000,
312
146
  });
313
- expect(result).toMatchObject({ filed: true });
314
- });
315
-
316
- test("wakes the REVIEW wait by name, not whatever the run happens to hold", async () => {
317
- // The tool's description is "skip the review wait", and an un-named
318
- // `wakeUp(runId)` ends every suspension the run has — including an approval
319
- // waitpoint a later body might open, which would file a report that was
320
- // still waiting on a person. `review.ts` is where both sides read the id.
321
- const workflows = stubWorkflows([
322
- createRunSnapshot({ workflow: "research", status: "running" }),
323
- ]);
324
- vi.mocked(workflows.wakeUp).mockResolvedValue(1);
325
- await run("file_it_now", createToolContext({ workflows }));
326
- expect(vi.mocked(workflows.wakeUp).mock.calls[0]?.[1]?.correlationIds).toEqual([
327
- REVIEW_SLEEP_ID,
328
- ]);
329
- });
330
-
331
- test("a run that was not waiting is reported honestly, not as a failure", async () => {
332
- // `wakeUp` answering 0 means the run had already moved past its sleep — the
333
- // same shape as `cancel` answering false.
334
- const workflows = stubWorkflows([
335
- createRunSnapshot({ workflow: "research", status: "running" }),
336
- ]);
337
- vi.mocked(workflows.wakeUp).mockResolvedValue(0);
338
- const result = await run("file_it_now", createToolContext({ workflows }));
339
- expect(result).toMatchObject({ filed: false });
147
+ expect(describeRun(research, twelveMinutesAgo)).toMatch(/^12 minutes ago: still working/);
148
+ const justNow = createRunSnapshot(research, { status: "running", createdAt: Date.now() });
149
+ expect(describeRun(research, justNow)).toMatch(/^Just now/);
340
150
  });
341
151
 
342
- test("says nothing was started when the key has no runs", async () => {
343
- const workflows = stubWorkflows([]);
344
- const result = await run("file_it_now", createToolContext({ workflows }));
345
- expect(result).toMatchObject({ note: "Nothing started yet." });
346
- expect(workflows.wakeUp).not.toHaveBeenCalled();
152
+ test("surfaces a failed run's message instead of swallowing it", () => {
153
+ const run = createRunSnapshot(research, { status: "failed", error: "model unavailable" });
154
+ expect(describeRun(research, run)).toContain("model unavailable");
347
155
  });
348
156
  });
349
157
 
350
- /**
351
- * The WORKFLOW half of the research desk: what it configures, what it files,
352
- * and the run itself.
353
- *
354
- * The pass is `deepResearchWorkflow()`'s, and its stages — the brief's
355
- * fallback, the planner's width cap, the researcher's cite-else-opened
356
- * sources, the report's one numbering, the gateway's retry classification —
357
- * are asserted in the SDK's own spec (`sdk/deep-research.test.ts`), where they
358
- * live. What is asserted HERE is this desk's half: the prompts it overrides,
359
- * the researcher and budget it keeps, the review wait and filing its `deliver`
360
- * adds, and — on the REAL replay engine — that the whole run keeps the desk's
361
- * promise: **answer the caller now, finish the work later**.
362
- *
363
- * The body is driven twice, once through `createWorkflowContext`, which records
364
- * what it asked for and replays nothing, and once through `runWorkflow`
365
- * (`@alexkroman1/aai-runtime/testing`), which reads the journal directly for
366
- * the three things the run's own snapshot cannot show (which sleep is open and
367
- * under what name, what an `investigate` left behind for a resume to reuse, and
368
- * whether a boot sweep would still find a run whose worker died).
369
- * `aai-cli`'s `dev-workflow.scenario.test.ts` is the tier above both, with a
370
- * built project and a real queue.
371
- */
372
158
  describe("the desk's research configuration", () => {
373
- beforeEach(() => {
374
- // `stepEnv` falls back to the process env when no host has published one,
375
- // which is exactly the case a spec is. `unstubEnvs` clears it per test.
376
- vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
377
- });
378
-
379
159
  const INPUT = { topic: "Tool use", requestedBy: "Ada" };
380
160
  const brief = { brief: "How otters use tools", criteria: ["Which species"] };
381
161
 
@@ -421,37 +201,7 @@ describe("the desk's research configuration", () => {
421
201
  expect(desk.calls[0]?.options.context).toContain("How otters use tools");
422
202
  });
423
203
 
424
- test("both investigate waves are called with more attempts than the default", async () => {
425
- // With `runSteps: false` nothing runs, so this is the skeleton of a run: no
426
- // page, no model and no search, in exchange for spelling the shape out.
427
- const ctx = createWorkflowContext({
428
- runSteps: false,
429
- results: {
430
- writeBrief: brief,
431
- planAngles: ["Adoption", "Tooling"],
432
- findGaps: ["Cost"],
433
- investigate: { angle: "Adoption", findings: "f", sources: [] },
434
- investigateGap: { angle: "Cost", findings: "f", sources: [] },
435
- writeReport: { summary: "s", report: "r" },
436
- },
437
- });
438
- await research.run(INPUT, ctx);
439
-
440
- const investigations = ctx.steps.filter((step) => step.name.startsWith("investigate"));
441
- expect(investigations.map((step) => step.name)).toEqual([
442
- "investigate",
443
- "investigate",
444
- "investigateGap",
445
- ]);
446
- for (const step of investigations) {
447
- expect(step.maxAttempts).toBeGreaterThan(DEFAULT_STEP_MAX_ATTEMPTS);
448
- }
449
- });
450
-
451
- test("the review wait is opened under the name file_it_now wakes", async () => {
452
- // The two halves of one agreement, and the only place a spec can see both:
453
- // the delivery's `correlationId` here, and the tool's `correlationIds` in
454
- // the `file_it_now` block. `review.ts` is the module that keeps them equal.
204
+ test("the review wait comes after the report and before filing, under the label file_it_now wakes", async () => {
455
205
  const ctx = createWorkflowContext({
456
206
  runSteps: false,
457
207
  results: {
@@ -464,13 +214,11 @@ describe("the desk's research configuration", () => {
464
214
  });
465
215
  await research.run(INPUT, ctx);
466
216
 
467
- expect(ctx.slept).toHaveLength(1);
468
- expect(ctx.slept[0]?.correlationId).toBe(REVIEW_SLEEP_ID);
469
- // The wait comes AFTER the report, and filing after the wait.
217
+ expect(ctx.slept).toMatchObject([{ label: "reviewWindow", until: REVIEW_DELAY_MS }]);
470
218
  expect(ctx.steps.map((step) => step.name).slice(-2)).toEqual(["writeReport", "file"]);
471
219
  });
472
220
 
473
- test("deliverResearch answers with what research_status reads back", async () => {
221
+ test("deliverResearch answers with what the status line reads back", async () => {
474
222
  const ctx = createWorkflowContext({ results: { file: "2026-01-01T00:00:00.000Z" } });
475
223
  const source = { title: "Otters", url: "https://otters.example" };
476
224
  const out = await deliverResearch(
@@ -497,7 +245,7 @@ describe("the desk's research configuration", () => {
497
245
 
498
246
  test("a missing key is FATAL, naming the key, and fails the run rather than filing", async () => {
499
247
  vi.stubEnv("ASSEMBLYAI_API_KEY", "");
500
- installStubGateway(["anything"]);
248
+ installStubGateway(["anything"], { apiKey: false });
501
249
  const ctx = createWorkflowContext();
502
250
  const err = await Promise.resolve(research.run(INPUT, ctx)).catch((thrown: unknown) => thrown);
503
251
  expect(FatalError.is(err)).toBe(true);
@@ -515,13 +263,9 @@ describe("the desk's research configuration", () => {
515
263
  });
516
264
 
517
265
  /**
518
- * The last step, which used to be a promise.
519
- *
520
- * What is asserted here is this template's half — what a filed report SAYS, and
521
- * that the channel is resolved from the env rather than assumed. The 4xx/5xx
522
- * split, the Block Kit assembly and the mrkdwn escaping are
523
- * `@alexkroman1/aai/channels`' and have their own specs; a template asserting
524
- * them again would pin the SDK's rendering from the outside.
266
+ * The last step. What is asserted here is this template's half — what a filed
267
+ * report SAYS, and that the channel is resolved from the env rather than
268
+ * assumed; the 4xx/5xx split and the rendering are `@alexkroman1/aai/channels`'.
525
269
  */
526
270
  describe("filing the findings", () => {
527
271
  const WEBHOOK = "https://hooks.slack.com/services/T000/B000/abc";
@@ -539,15 +283,7 @@ describe("filing the findings", () => {
539
283
  ],
540
284
  };
541
285
 
542
- /**
543
- * The webhook, answered without a network.
544
- *
545
- * `installStubStepFetch` rather than a `fetch` global stub: a channel post
546
- * goes out through the published `stepFetch` slot like every other step
547
- * request, and stubbing the global would test a path production does not
548
- * take. Anything that is not the webhook is a finding rather than a 200 —
549
- * an unexpected request answered emptily reads to the run as a refusal.
550
- */
286
+ /** The webhook, answered without a network; anything else is a finding. */
551
287
  function stubPost(answer: StubStepAnswer): StubStepFetch {
552
288
  return installStubStepFetch((request: StubStepRequest): StubStepAnswer => {
553
289
  if (!request.url.startsWith("https://hooks.slack.com/")) {
@@ -566,15 +302,12 @@ describe("filing the findings", () => {
566
302
  expect(posted.calls[0]?.method).toBe("POST");
567
303
  expect(posted.calls[0]?.url).toBe(WEBHOOK);
568
304
  expect(String(posted.calls[0]?.body)).toContain("crack shellfish");
569
- // `filedAt` is a TIME now. It was the literal string "filed" under a field
570
- // named for a timestamp, which was two claims and neither was true.
571
305
  expect(Number.isNaN(Date.parse(filedAt))).toBe(false);
572
306
  });
573
307
 
574
308
  test("with no webhook it files nowhere, says so, and does not fail the run", async () => {
575
309
  // The last step of a five-minute pass is the worst place to discover a
576
- // missing credential, so the channel is optional by construction — this is
577
- // the arm that keeps `aai dev` runnable before anything is configured.
310
+ // missing credential, so the channel is optional by construction.
578
311
  const reported = installStubReporter();
579
312
  const posted = stubPost({ body: "ok" });
580
313
 
@@ -591,8 +324,7 @@ describe("filing the findings", () => {
591
324
 
592
325
  test("a text param is carried only where it means something", () => {
593
326
  // It names a Slack WORKFLOW variable, so it does something on a trigger URL
594
- // and quietly nothing on an incoming webhook — and a setting that looks
595
- // configured and is ignored is the worse of the two.
327
+ // and quietly nothing on an incoming webhook.
596
328
  vi.stubEnv(FILING_TEXT_PARAM_ENV, "report");
597
329
  vi.stubEnv(FILING_WEBHOOK_ENV, WEBHOOK);
598
330
  expect(filingChannel()?.options.textParam).toBeUndefined();
@@ -607,7 +339,6 @@ describe("filing the findings", () => {
607
339
  expect(message.heading).toBe("Research: how otters use tools");
608
340
  expect(message.subtitle).toContain("Requested by sess_1");
609
341
  expect(message.subtitle).toContain("1 source across 1 angle");
610
- // The answer first, then one section per angle.
611
342
  expect(message.sections?.[0]).toMatchObject({ title: "In short" });
612
343
  expect(message.sections?.[1]).toMatchObject({
613
344
  title: "Tool use",
@@ -617,9 +348,7 @@ describe("filing the findings", () => {
617
348
 
618
349
  test("the message still answers where a destination renders no sections", () => {
619
350
  // A Slack workflow trigger takes ONE string, so the SDK folds the whole
620
- // message down to text — `renderSlackPlainText` is that folding. What has to
621
- // survive it is the answer and the sources, which is what a reader who never
622
- // opens the run gets.
351
+ // message down to text; the answer and the sources must survive it.
623
352
  const flat = renderSlackPlainText(renderFiling(FILING));
624
353
 
625
354
  expect(flat).toContain("crack shellfish");
@@ -628,27 +357,12 @@ describe("filing the findings", () => {
628
357
  });
629
358
 
630
359
  /**
631
- * The whole run — `deepResearchWorkflow`'s pass plus this desk's delivery — on
632
- * the real replay engine.
360
+ * The whole run on the real replay engine, which is the only tier that can
361
+ * reach the desk's promise: **answer the caller now, finish the work later**.
633
362
  *
634
- * The block above drives this body through `createWorkflowContext`, which records
635
- * what it ASKED for and replays nothing — right for the retry policy and the
636
- * step order, and silent about the desk's actual promise: **answer the caller
637
- * now, finish the work later**. `runWorkflow`
638
- * (`@alexkroman1/aai-runtime/testing`) is the engine `aai dev` runs, over an
639
- * in-memory journal, so the review wait really suspends and the resume really
640
- * comes off the journal.
641
- *
642
- * The model is scripted POSITIONALLY, which is only safe because the run is made
643
- * sequential: one angle, and a researcher that stops on its first turn, so the
644
- * `mapConcurrent` fan-out has a single item and nothing races. A case that wants
645
- * two angles at once wants a router keyed on the system prompt instead — the
646
- * shape `link-digest-workflow` uses — because the order two concurrent step bodies reach
647
- * the gateway in is the scheduler's business.
648
- *
649
- * Five calls make a whole run: the brief, the angles, the researcher's first
650
- * action, the gap pass, and the report — plus its summary, which is a second
651
- * call on the same step.
363
+ * The model is scripted POSITIONALLY, which is only safe because the run is
364
+ * made sequential: one angle, and a researcher that stops on its first turn,
365
+ * so the `mapConcurrent` fan-out has a single item and nothing races.
652
366
  */
653
367
  describe("the run is DURABLE", () => {
654
368
  const SCRIPT = [
@@ -656,9 +370,8 @@ describe("the run is DURABLE", () => {
656
370
  JSON.stringify({ brief: "How otters use tools", criteria: ["Which species"] }),
657
371
  // planAngles — ONE, so the fan-out is sequential and the script positional.
658
372
  JSON.stringify({ angles: ["Tool use"] }),
659
- // `investigate` is NOT in this script any more: it delegates, so its model
660
- // calls are the subagent's and are answered by `installStubStepDelegate`
661
- // below rather than by the gateway.
373
+ // `investigate` delegates: its model calls are the subagent's, answered by
374
+ // `installStubStepDelegate` below rather than by the gateway.
662
375
  // findGaps — none, so there is no second wave.
663
376
  JSON.stringify({ angles: [] }),
664
377
  // writeReport, then its summary.
@@ -667,20 +380,7 @@ describe("the run is DURABLE", () => {
667
380
  ];
668
381
  const INPUT = { topic: "otters", requestedBy: "sess_1" };
669
382
 
670
- /**
671
- * How every case here starts the run.
672
- *
673
- * `name` is the key the engine registers the run under and has to match the
674
- * one `agent.ts` declares — a string five call sites repeated, which is the
675
- * kind that drifts in four of them. The annotation is what says what else
676
- * belongs in this bag (`crashAt` below, and a `journal` of your own).
677
- */
678
- const RUN = { name: "research" } satisfies RunWorkflowOptions;
679
-
680
383
  beforeEach(() => {
681
- // `unstubEnvs` (set by `defineAgentTestConfig`) undoes the webhook an
682
- // earlier case stubbed, so these cases start with none configured.
683
- vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
684
384
  // No `RESEARCH_SLACK_WEBHOOK_URL`, so the filing step posts nothing — which
685
385
  // is why the gateway counts below are the run's model calls and only those.
686
386
  installStubStepDelegate({ routes: { researcher: "Nothing was found on this angle." } });
@@ -691,34 +391,15 @@ describe("the run is DURABLE", () => {
691
391
  return run.steps.map((step) => step.key);
692
392
  }
693
393
 
694
- /**
695
- * The one suspension a research run takes, read off the journal itself.
696
- *
697
- * The run's snapshot carries `wakeAt` and nothing about WHICH wait it is, so
698
- * the correlation id `file_it_now` names is only visible here.
699
- */
700
- async function reviewSleep(run: WorkflowTestHandle<unknown>): Promise<SleepRecord | undefined> {
701
- const sleeps = await run.journal.readSleeps(run.runId);
702
- return sleeps.find((sleep) => sleep.correlationId === REVIEW_SLEEP_ID);
703
- }
704
-
705
- /** What an `investigate` left in the journal for a resume to reuse. */
706
- async function journaledResearch(
707
- journal: JournalStore,
708
- runId: string,
709
- ): Promise<StepEntry | undefined> {
710
- return (await journal.readSteps(runId)).find((step) => step.name === "investigate");
711
- }
712
-
713
- /** What a boot sweep would still owe — the query a stranded run is found by. */
714
- async function resumable(journal: JournalStore): Promise<ResumableRun[]> {
715
- return (await journal.resumableRuns?.(10)) ?? [];
394
+ /** The one suspension a research run takes, read off the journal itself. */
395
+ function reviewSleep(run: WorkflowTestRun<unknown>): WorkflowTestWait | undefined {
396
+ return run.waits.find((wait) => wait.correlationId === "reviewWindow");
716
397
  }
717
398
 
718
399
  test("suspends on the review wait with the whole report already journaled", async () => {
719
400
  const started = Date.now();
720
401
  const model = installStubGateway(SCRIPT);
721
- const run = await runWorkflow(research, INPUT, RUN);
402
+ const run = await runWorkflow(agentDef, "research", INPUT);
722
403
 
723
404
  // Not blocked — suspended. The sandbox is free here, which is the whole
724
405
  // reason a caller can hang up.
@@ -732,41 +413,29 @@ describe("the run is DURABLE", () => {
732
413
  "writeBrief#0",
733
414
  "writeReport#0",
734
415
  ]);
735
- // FIVE gateway calls for six steps, and the missing one is `investigate`:
736
- // its model turns belong to the subagent now and go through the delegate
737
- // slot instead. The STEP is still journaled — it is in the list above.
416
+ // FIVE gateway calls for six steps: `investigate`'s turns went to the
417
+ // subagent through the delegate slot.
738
418
  expect(model).toHaveLength(5);
739
- });
740
-
741
- test("the open wait is the REVIEW wait, by the name the tool wakes", async () => {
742
- installStubGateway(SCRIPT);
743
- const run = await runWorkflow(research, INPUT, RUN);
744
-
745
- const sleep = await reviewSleep(run);
746
- expect(sleep, "the run holds no sleep under the review correlation id").toBeDefined();
747
- expect(sleep?.woken).toBe(false);
748
- expect(sleep?.kind).toBe("sleep");
419
+ // The open wait is the REVIEW wait, by the label `file_it_now` wakes.
420
+ expect(reviewSleep(run)).toMatchObject({ kind: "sleep", woken: false });
749
421
  });
750
422
 
751
423
  test("makes no decision a replay could not reproduce", async () => {
752
424
  // `reads` records every `ctx.now`/`ctx.random`/`ctx.uuid` the body took, and
753
425
  // this body takes none: the fan-out's width comes from a journaled step, and
754
- // the filing timestamp is a step RESULT. An empty list is the determinism
755
- // rule this template's doc states, asserted rather than described.
426
+ // the filing timestamp is a step RESULT.
756
427
  installStubGateway(SCRIPT);
757
- const run = await runWorkflow(research, INPUT, RUN);
428
+ const run = await runWorkflow(agentDef, "research", INPUT);
758
429
 
759
430
  expect(run.reads).toEqual([]);
760
431
  });
761
432
 
762
433
  test("resumes past the review wait and files, without researching again", async () => {
763
434
  const model = installStubGateway(SCRIPT);
764
- const run = await runWorkflow(research, INPUT, RUN);
765
- // `advanceSleep` is `ctx.workflows.wakeUp`'s own mechanism, which is what
766
- // the `file_it_now` tool calls to cut the review short — and it is given the
767
- // SAME correlation id that tool passes, so what this drives is that tool's
768
- // effect rather than a blanket wake nothing in the desk performs.
769
- await run.advanceSleep([REVIEW_SLEEP_ID]);
435
+ const run = await runWorkflow(agentDef, "research", INPUT);
436
+ // `advanceSleep` is `ctx.workflows.wakeUp`'s own mechanism, given the same
437
+ // label `file_it_now` passes.
438
+ await run.advanceSleep(["reviewWindow"]);
770
439
 
771
440
  expect(run.status).toBe("completed");
772
441
  expect(run.output).toMatchObject({
@@ -774,9 +443,9 @@ describe("the run is DURABLE", () => {
774
443
  summary: "Otters use tools.",
775
444
  report: "The report about otters.",
776
445
  angles: ["Tool use"],
446
+ // A real timestamp: the filing step really ran.
447
+ filedAt: expect.stringMatching(/^\d{4}-\d{2}-\d{2}T/),
777
448
  });
778
- // A real timestamp, and the filing step really ran.
779
- expect(Number.isNaN(Date.parse(run.output?.filedAt ?? ""))).toBe(false);
780
449
  expect(run.deliveries).toBe(2);
781
450
  // The second walk re-entered the body from the top and paid the model
782
451
  // NOTHING: every step above the wait came back out of the journal.
@@ -787,32 +456,25 @@ describe("the run is DURABLE", () => {
787
456
  // The expensive claim. A deep-research pass is five to twelve model calls
788
457
  // and as many searches; a resume that redid them would cost the run twice.
789
458
  const model = installStubGateway(SCRIPT);
790
- const run = await runWorkflow(research, INPUT, { ...RUN, crashAt: "writeReport" });
459
+ const run = await runWorkflow(agentDef, "research", INPUT, { crashAt: "writeReport" });
791
460
 
792
461
  expect(run.crashed).toBe(true);
793
462
  expect(stepKeys(run)).toEqual(["findGaps#0", "investigate#0", "planAngles#0", "writeBrief#0"]);
794
- // THREE, not four: `investigate` is one of the four steps above and paid
795
- // the gateway nothing — its turns went to the subagent.
796
- const spentBeforeTheCrash = model.length;
797
- expect(spentBeforeTheCrash).toBe(3);
798
-
799
- // WHY the resume is free, read off the store rather than inferred from a
800
- // call count: the finished angle's own result is sitting in the journal,
801
- // which is what the second walk answers `investigate#0` from.
802
- const done = await journaledResearch(run.journal, run.runId);
463
+ // THREE, not four: `investigate` paid the gateway nothing.
464
+ expect(model).toHaveLength(3);
465
+ // The finished angle's own result is sitting in the journal, which is what
466
+ // the second walk answers `investigate#0` from; and the run is still
467
+ // FINDABLE, so a boot sweep resumes it.
468
+ const done = run.steps.find((step) => step.name === "investigate");
803
469
  expect(done?.status).toBe("ok");
804
470
  expect(done?.output).toMatchObject({ angle: "Tool use" });
805
- // And the run is still FINDABLE: a dead worker leaves it for a boot sweep,
806
- // which is what makes "resume" a platform behaviour rather than a promise
807
- // this handle keeps.
808
- expect((await resumable(run.journal)).map((one) => one.runId)).toContain(run.runId);
471
+ expect(run.resumable).toBe(true);
809
472
 
810
473
  await run.restart();
811
- await run.advanceSleep([REVIEW_SLEEP_ID]);
474
+ await run.advanceSleep(["reviewWindow"]);
812
475
  expect(run.status).toBe("completed");
813
- // Five in total: the three the crash already paid for came back out of the
814
- // journal, and only the report and its summary were re-issued.
476
+ // Five in total: only the report and its summary were re-issued.
815
477
  expect(model).toHaveLength(5);
816
- expect(run.output?.report).toBe("The report about otters.");
478
+ expect(run.output).toMatchObject({ report: "The report about otters." });
817
479
  });
818
480
  });