@alexkroman1/aai-cli 0.17.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.
- package/dist/{_agent-BopNO5Bq.mjs → _agent-BN21AHsJ.mjs} +4 -4
- package/dist/_api-client-Uljj0CQi.mjs +312 -0
- package/dist/_api-client.d.ts +69 -1
- package/dist/{_bundler-DCuNHjDF.mjs → _bundler-DvZDEu2p.mjs} +67 -7
- package/dist/_bundler.d.ts +15 -0
- package/dist/_cli-common.d.ts +42 -0
- package/dist/{client-bundler-DE-AGdm7.mjs → _client-plugins-kR43nZnb.mjs} +30 -132
- package/dist/_client-plugins.d.ts +16 -0
- package/dist/{_config-mq1I5Cva.mjs → _config-Dlh8PRRp.mjs} +2 -20
- package/dist/_config.d.ts +0 -8
- package/dist/{_dev-server-D6VSQbYW.mjs → _dev-server-C_zidzWj.mjs} +15 -10
- package/dist/_dev-session-ticket.d.ts +3 -0
- package/dist/_dev-tunnel.d.ts +20 -2
- package/dist/_dotenv-file.d.ts +6 -0
- package/dist/_init.d.ts +2 -11
- package/dist/_output.d.ts +47 -20
- package/dist/_safe-write.d.ts +38 -0
- package/dist/{_server-common-CVXIeWrY.mjs → _server-common-C6j67AcZ.mjs} +37 -2
- package/dist/_server-common.d.ts +16 -0
- package/dist/{_slug-api-BnmTHtjd.mjs → _slug-api-B9cptz7Q.mjs} +3 -2
- package/dist/_start-affinity.d.ts +70 -0
- package/dist/_start-log.d.ts +39 -0
- package/dist/_start-router.d.ts +85 -0
- package/dist/_start-run.d.ts +101 -0
- package/dist/_start-worker.d.ts +61 -0
- package/dist/_start-workers-BNdOnTal.mjs +529 -0
- package/dist/_start-workers.d.ts +262 -0
- package/dist/_studio-zympBLlD.mjs +140 -0
- package/dist/_studio.d.ts +14 -0
- package/dist/_target-bundle.d.ts +4 -0
- package/dist/{_templates-BVMVsQh0.mjs → _templates-ChZuhW66.mjs} +110 -8
- package/dist/_templates.d.ts +20 -1
- package/dist/{_typecheck-gate-CcX2gLJZ.mjs → _typecheck-gate-BNF5cboL.mjs} +2 -2
- package/dist/_ui-C0RufoYZ.mjs +147 -0
- package/dist/_ui.d.ts +14 -3
- package/dist/_utils-ChU85MEg.mjs +486 -0
- package/dist/_utils.d.ts +28 -0
- package/dist/_vendor-openers.d.ts +87 -0
- package/dist/{_vitest-runner-CKI8_K1b.mjs → _vitest-runner-tzyto9IU.mjs} +7 -3
- package/dist/_vitest-runner.d.ts +8 -1
- package/dist/{build-BnXLgfk-.mjs → build-BHgd-QYb.mjs} +13 -10
- package/dist/build.d.ts +21 -0
- package/dist/cli-workflow.d.ts +7 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.mjs +243 -70
- package/dist/client-bundler-CImhqcp2.mjs +133 -0
- package/dist/client-bundler.mjs +1 -1
- package/dist/{console-tVBjfKyR.mjs → console-DwycgRkC.mjs} +4 -5
- package/dist/delete-ZcA3J_3o.mjs +75 -0
- package/dist/delete.d.ts +10 -1
- package/dist/{deploy-eWDoiwvn.mjs → deploy-CkfkiZE3.mjs} +9 -9
- package/dist/{dev-CT_QHHZL.mjs → dev-BX9g6qcf.mjs} +81 -18
- package/dist/{eval-Dl8o91yC.mjs → eval-CUKvfxRq.mjs} +4 -4
- package/dist/{init-CidslZZz.mjs → init-B9Uw76-_.mjs} +62 -32
- package/dist/{login-oJdBWu2B.mjs → login-Ct73CqU1.mjs} +30 -6
- package/dist/login.d.ts +2 -0
- package/dist/{logs-CkmFdSbr.mjs → logs-BBsUy96d.mjs} +59 -14
- package/dist/logs.d.ts +4 -1
- package/dist/project-config.mjs +1 -1
- package/dist/scaffold/CLAUDE.md +72 -55
- package/dist/scaffold/agent-guide/AGENT-API.md +44 -34
- package/dist/scaffold/agent-guide/HOSTING.md +11 -0
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +105 -36
- package/dist/scaffold/agent-guide/TOOLS.md +189 -33
- package/dist/scaffold/agent-guide/UI.md +111 -39
- package/dist/scaffold/agent-guide/WORKFLOWS.md +234 -160
- package/dist/scaffold/package.json +4 -4
- package/dist/{secret-DPdPEet2.mjs → secret-CKjHRrVX.mjs} +112 -35
- package/dist/start.d.ts +14 -14
- package/dist/start.mjs +840 -40
- package/dist/{studio-COjK25Rl.mjs → studio-U6DvBNAx.mjs} +123 -35
- package/dist/studio.d.ts +1 -0
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +23 -52
- package/dist/templates/applicant-screening-agent/agent.test.ts +821 -826
- package/dist/templates/applicant-screening-agent/agent.ts +1 -6
- package/dist/templates/applicant-screening-agent/client.tsx +1 -19
- package/dist/templates/applicant-screening-agent/shared.ts +8 -18
- package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +24 -27
- package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +75 -82
- package/dist/templates/applicant-screening-agent/tools/read_email.ts +24 -24
- package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +92 -99
- package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +72 -83
- package/dist/templates/applicant-screening-agent/tools/screening_status.ts +21 -29
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +14 -19
- package/dist/templates/call-audit-workflow/agent.test.ts +275 -169
- package/dist/templates/call-audit-workflow/agent.ts +12 -30
- package/dist/templates/call-audit-workflow/client.tsx +9 -27
- package/dist/templates/call-audit-workflow/guards.test.ts +24 -71
- package/dist/templates/call-audit-workflow/workflows/audit.ts +24 -52
- package/dist/templates/call-audit-workflow/workflows/ingest.ts +32 -59
- package/dist/templates/call-audit-workflow/workflows/media.ts +4 -44
- package/dist/templates/call-audit-workflow/workflows/summarize.ts +72 -107
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +3 -2
- package/dist/templates/code-interpreter-agent/agent.test.ts +4 -17
- package/dist/templates/code-interpreter-agent/agent.ts +1 -1
- package/dist/templates/coding-agent/agent.test.ts +17 -12
- package/dist/templates/coding-agent/agent.ts +1 -1
- package/dist/templates/custom-pipeline-agent/agent.test.ts +6 -14
- package/dist/templates/custom-pipeline-agent/agent.ts +1 -1
- package/dist/templates/custom-pipeline-agent/modes.test.ts +0 -1
- package/dist/templates/document-redline-workflow/agent.test.ts +88 -221
- package/dist/templates/document-redline-workflow/agent.ts +22 -32
- package/dist/templates/document-redline-workflow/client.tsx +46 -88
- package/dist/templates/document-redline-workflow/workflows/prompts.ts +0 -3
- package/dist/templates/document-redline-workflow/workflows/redline.ts +33 -50
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +22 -71
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +466 -495
- package/dist/templates/emergency-dispatch-agent/agent.ts +27 -43
- package/dist/templates/emergency-dispatch-agent/client.tsx +85 -119
- package/dist/templates/emergency-dispatch-agent/shared.ts +51 -88
- package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +11 -17
- package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +21 -30
- package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +60 -63
- package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +6 -15
- package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +40 -53
- package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +41 -47
- package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +2 -2
- package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +1 -1
- package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +13 -10
- package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +42 -51
- package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +40 -41
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +14 -42
- package/dist/templates/entertainment-picks-agent/agent.test.ts +174 -221
- package/dist/templates/entertainment-picks-agent/agent.ts +1 -6
- package/dist/templates/entertainment-picks-agent/client.tsx +1 -12
- package/dist/templates/entertainment-picks-agent/shared.ts +12 -6
- package/dist/templates/entertainment-picks-agent/tools/recommend.ts +2 -2
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +1 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +15 -22
- package/dist/templates/executive-inbox-agent/agent.test.ts +515 -527
- package/dist/templates/executive-inbox-agent/agent.ts +4 -8
- package/dist/templates/executive-inbox-agent/calendar.test.ts +23 -22
- package/dist/templates/executive-inbox-agent/client.tsx +1 -23
- package/dist/templates/executive-inbox-agent/review.ts +125 -113
- package/dist/templates/executive-inbox-agent/shared.ts +3 -0
- package/dist/templates/executive-inbox-agent/tools/ask_question.ts +6 -6
- package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +16 -18
- package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +1 -0
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +20 -20
- package/dist/templates/executive-inbox-agent/tools/new_email.ts +17 -21
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +72 -74
- package/dist/templates/executive-inbox-agent/tools/review_memory.ts +1 -0
- package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +19 -20
- package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +53 -50
- package/dist/templates/front-desk-agent/agent.eval.test.ts +22 -14
- package/dist/templates/front-desk-agent/agent.test.ts +139 -123
- package/dist/templates/front-desk-agent/agent.ts +4 -7
- package/dist/templates/front-desk-agent/shared.ts +88 -74
- package/dist/templates/front-door-agent/agent.eval.test.ts +61 -0
- package/dist/templates/front-door-agent/agent.test.ts +393 -0
- package/dist/templates/front-door-agent/agent.ts +35 -0
- package/dist/templates/front-door-agent/client.tsx +250 -0
- package/dist/templates/front-door-agent/routes.ts +91 -0
- package/dist/templates/front-door-agent/shared.ts +35 -0
- package/dist/templates/front-door-agent/system-prompt.md +12 -0
- package/dist/templates/front-door-agent/tools/leave_message.ts +39 -0
- package/dist/templates/front-door-agent/tools/link_phone.ts +49 -0
- package/dist/templates/front-door-agent/workflows/announce.ts +38 -0
- package/dist/templates/front-door-agent/workflows/digest.ts +53 -0
- package/dist/templates/front-door-agent/workflows/pair.ts +28 -0
- package/dist/templates/home-assistant-agent/agent.eval.test.ts +5 -9
- package/dist/templates/home-assistant-agent/agent.test.ts +513 -399
- package/dist/templates/home-assistant-agent/agent.ts +8 -5
- package/dist/templates/home-assistant-agent/client.tsx +48 -9
- package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +1 -0
- package/dist/templates/home-assistant-agent/tools/remind_me.ts +2 -1
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +27 -52
- package/dist/templates/hotel-reception-agent/agent.test.ts +980 -964
- package/dist/templates/hotel-reception-agent/agent.ts +8 -21
- package/dist/templates/hotel-reception-agent/booking.ts +2 -2
- package/dist/templates/hotel-reception-agent/client.tsx +5 -20
- package/dist/templates/hotel-reception-agent/concierge.ts +2 -0
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +285 -275
- package/dist/templates/hotel-reception-agent/desk.ts +45 -12
- package/dist/templates/hotel-reception-agent/hotel.ts +6 -6
- package/dist/templates/hotel-reception-agent/restaurant.ts +3 -4
- package/dist/templates/hotel-reception-agent/session.ts +14 -30
- package/dist/templates/hotel-reception-agent/shared.ts +33 -46
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +14 -15
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +2 -2
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +13 -10
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +6 -7
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +5 -4
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +6 -5
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +3 -4
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +4 -4
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +4 -4
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +4 -3
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +1 -1
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +30 -32
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +22 -25
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +1 -0
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +5 -4
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +23 -13
- package/dist/templates/kitchen-coach-agent/agent.eval.test.ts +38 -0
- package/dist/templates/kitchen-coach-agent/agent.test.ts +204 -0
- package/dist/templates/kitchen-coach-agent/agent.ts +22 -0
- package/dist/templates/kitchen-coach-agent/client.tsx +232 -0
- package/dist/templates/kitchen-coach-agent/history.ts +37 -0
- package/dist/templates/kitchen-coach-agent/shared.ts +131 -0
- package/dist/templates/kitchen-coach-agent/system-prompt.md +17 -0
- package/dist/templates/kitchen-coach-agent/tools/get_kitchen.ts +17 -0
- package/dist/templates/kitchen-coach-agent/tools/scale_amount.ts +31 -0
- package/dist/templates/kitchen-coach-agent/tools/start_timer.ts +24 -0
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +16 -40
- package/dist/templates/link-digest-workflow/agent.test.ts +84 -164
- package/dist/templates/link-digest-workflow/agent.ts +27 -42
- package/dist/templates/link-digest-workflow/api-client.ts +3 -2
- package/dist/templates/link-digest-workflow/client.tsx +5 -5
- package/dist/templates/link-digest-workflow/workflows/digest.ts +53 -95
- package/dist/templates/medication-safety-agent/agent.eval.test.ts +10 -30
- package/dist/templates/medication-safety-agent/agent.test.ts +16 -46
- package/dist/templates/medication-safety-agent/agent.ts +1 -4
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +13 -10
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +238 -396
- package/dist/templates/meeting-recap-agent/agent.test.ts +414 -1070
- package/dist/templates/meeting-recap-agent/agent.ts +26 -67
- package/dist/templates/meeting-recap-agent/system-prompt.md +1 -0
- package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +10 -12
- package/dist/templates/meeting-recap-agent/tools/request_recap.ts +9 -20
- package/dist/templates/meeting-recap-agent/workflows/recap.ts +224 -547
- package/dist/templates/outbound-call-agent/agent.eval.test.ts +10 -12
- package/dist/templates/outbound-call-agent/agent.test.ts +419 -453
- package/dist/templates/outbound-call-agent/agent.ts +57 -62
- package/dist/templates/outbound-call-agent/api.ts +53 -68
- package/dist/templates/outbound-call-agent/client.tsx +105 -176
- package/dist/templates/outbound-call-agent/shared.ts +10 -39
- package/dist/templates/outbound-call-agent/system-prompt.md +3 -4
- package/dist/templates/outbound-call-agent/tools/end_call.ts +15 -12
- package/dist/templates/outbound-call-agent/tools/press_keys.ts +8 -13
- package/dist/templates/outbound-call-agent/workflows/call.ts +89 -62
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +18 -54
- package/dist/templates/pizza-ordering-agent/agent.test.ts +205 -244
- package/dist/templates/pizza-ordering-agent/agent.ts +5 -12
- package/dist/templates/pizza-ordering-agent/client.tsx +3 -14
- package/dist/templates/pizza-ordering-agent/shared.ts +31 -36
- package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +1 -0
- package/dist/templates/pizza-ordering-agent/tools/place_order.ts +5 -2
- package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +1 -0
- package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +2 -3
- package/dist/templates/pizza-ordering-agent/tools/view_order.ts +7 -3
- package/dist/templates/podcast-digest-workflow/agent.test.ts +53 -102
- package/dist/templates/podcast-digest-workflow/agent.ts +11 -17
- package/dist/templates/podcast-digest-workflow/client.tsx +29 -51
- package/dist/templates/podcast-digest-workflow/workflows/digest.ts +24 -26
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +13 -14
- package/dist/templates/push-to-talk-agent/agent.test.ts +30 -23
- package/dist/templates/push-to-talk-agent/agent.ts +1 -5
- package/dist/templates/push-to-talk-agent/client.tsx +1 -11
- package/dist/templates/push-to-talk-agent/shared.ts +12 -6
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +1 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +1 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +0 -10
- package/dist/templates/quickstart-agent/agent.test.ts +18 -30
- package/dist/templates/quickstart-agent/agent.ts +3 -4
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +161 -290
- package/dist/templates/research-handoff-agent/agent.test.ts +131 -457
- package/dist/templates/research-handoff-agent/agent.ts +26 -86
- package/dist/templates/research-handoff-agent/system-prompt.md +1 -0
- package/dist/templates/research-handoff-agent/tools/file_it_now.ts +8 -21
- package/dist/templates/research-handoff-agent/tools/request_research.ts +7 -16
- package/dist/templates/research-handoff-agent/workflows/research.ts +88 -40
- package/dist/templates/research-planner-agent/agent.eval.test.ts +15 -40
- package/dist/templates/research-planner-agent/agent.test.ts +415 -464
- package/dist/templates/research-planner-agent/agent.ts +3 -8
- package/dist/templates/research-planner-agent/client.tsx +1 -14
- package/dist/templates/research-planner-agent/procedure.ts +9 -3
- package/dist/templates/research-planner-agent/shared.ts +30 -33
- package/dist/templates/research-planner-agent/tools/plan_status.ts +7 -15
- package/dist/templates/research-planner-agent/tools/revise_plan.ts +29 -36
- package/dist/templates/research-planner-agent/tools/start_plan.ts +25 -39
- package/dist/templates/research-planner-agent/tools/work_next_step.ts +25 -42
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +14 -34
- package/dist/templates/retail-orders-agent/agent.test.ts +1079 -1073
- package/dist/templates/retail-orders-agent/agent.ts +25 -78
- package/dist/templates/retail-orders-agent/client.tsx +120 -168
- package/dist/templates/retail-orders-agent/pending.test.ts +7 -14
- package/dist/templates/retail-orders-agent/registry.test.ts +93 -192
- package/dist/templates/retail-orders-agent/shared.test.ts +1 -1
- package/dist/templates/retail-orders-agent/shared.ts +10 -20
- package/dist/templates/retail-orders-agent/store.test.ts +46 -128
- package/dist/templates/retail-orders-agent/store.ts +42 -175
- package/dist/templates/retail-orders-agent/tools/cancel_change.ts +3 -6
- package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/confirm_change.ts +4 -6
- package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_item_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_product_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/get_user_details.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +3 -8
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +3 -4
- package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +3 -4
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +22 -25
- package/dist/templates/roadside-assistance-agent/agent.test.ts +453 -490
- package/dist/templates/roadside-assistance-agent/agent.ts +28 -60
- package/dist/templates/roadside-assistance-agent/call.ts +16 -22
- package/dist/templates/roadside-assistance-agent/shared.ts +24 -54
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +29 -37
- package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +44 -70
- package/dist/templates/roadside-assistance-agent/tools/job_status.ts +16 -24
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +39 -51
- package/dist/templates/roadside-assistance-agent/tools/report_location.ts +34 -33
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +18 -39
- package/dist/templates/roadside-assistance-agent/yard.test.ts +22 -19
- package/dist/templates/roadside-assistance-agent/yard.ts +3 -3
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +38 -40
- package/dist/templates/spoken-summary-workflow/agent.test.ts +129 -279
- package/dist/templates/spoken-summary-workflow/agent.ts +15 -40
- package/dist/templates/spoken-summary-workflow/client.tsx +13 -25
- package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +52 -92
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +31 -74
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +756 -774
- package/dist/templates/tabletop-rpg-agent/agent.ts +9 -46
- package/dist/templates/tabletop-rpg-agent/client.tsx +13 -21
- package/dist/templates/tabletop-rpg-agent/shared.ts +40 -99
- package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +67 -83
- package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +65 -88
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +8 -27
- package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +18 -36
- package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +101 -111
- package/dist/templates/technical-support-agent/agent.eval.test.ts +31 -72
- package/dist/templates/technical-support-agent/agent.test.ts +231 -260
- package/dist/templates/technical-support-agent/agent.ts +4 -10
- package/dist/templates/technical-support-agent/client.tsx +4 -18
- package/dist/templates/technical-support-agent/shared.ts +15 -25
- package/dist/templates/technical-support-agent/tools/answer_question.ts +46 -56
- package/dist/templates/technical-support-agent/tools/list_topics.ts +1 -0
- package/dist/templates/technical-support-agent/tools/log_ticket.ts +8 -5
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +37 -126
- package/dist/templates/text-adventure-agent/agent.test.ts +197 -368
- package/dist/templates/text-adventure-agent/agent.ts +15 -65
- package/dist/templates/text-adventure-agent/client.tsx +38 -98
- package/dist/templates/text-adventure-agent/shared.ts +31 -143
- package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +6 -12
- package/dist/templates/text-adventure-agent/tools/game_state_get.ts +4 -11
- package/dist/templates/text-adventure-agent/tools/game_state_move.ts +0 -2
- package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +1 -3
- package/dist/templates/text-adventure-agent/tools/game_state_score.ts +5 -7
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +12 -50
- package/dist/templates/topic-briefing-agent/agent.test.ts +478 -476
- package/dist/templates/topic-briefing-agent/agent.ts +3 -3
- package/dist/templates/topic-briefing-agent/shared.ts +11 -16
- package/dist/templates/topic-briefing-agent/slack.ts +12 -4
- package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +10 -17
- package/dist/templates/topic-briefing-agent/tools/research_topic.ts +21 -24
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +13 -14
- package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +16 -13
- package/dist/templates/transcription-workflow/agent.test.ts +114 -259
- package/dist/templates/transcription-workflow/agent.ts +6 -9
- package/dist/templates/transcription-workflow/client.tsx +100 -258
- package/dist/templates/transcription-workflow/recover.test.ts +6 -136
- package/dist/templates/transcription-workflow/recover.ts +14 -97
- package/dist/templates/transcription-workflow/run-panel.tsx +71 -8
- package/dist/templates/transcription-workflow/workflows/batch.ts +28 -159
- package/dist/templates/transcription-workflow/workflows/normalize.ts +50 -86
- package/dist/templates/transcription-workflow/workflows/stream.ts +2 -2
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +16 -23
- package/dist/templates/travel-concierge-agent/agent.eval.test.ts +7 -25
- package/dist/templates/travel-concierge-agent/agent.test.ts +505 -517
- package/dist/templates/travel-concierge-agent/agent.ts +22 -46
- package/dist/templates/travel-concierge-agent/client.tsx +1 -22
- package/dist/templates/travel-concierge-agent/routing.ts +29 -31
- package/dist/templates/travel-concierge-agent/shared.ts +63 -152
- package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +8 -9
- package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +8 -8
- package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +9 -6
- package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +10 -10
- package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/search_flights.ts +4 -3
- package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +3 -2
- package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +13 -8
- package/dist/templates/web-research-agent/agent.test.ts +19 -30
- package/dist/templates/web-research-agent/agent.ts +3 -4
- package/dist/templates/word-game-agent/agent.eval.test.ts +47 -67
- package/dist/templates/word-game-agent/agent.test.ts +369 -382
- package/dist/templates/word-game-agent/agent.ts +2 -5
- package/dist/templates/word-game-agent/client.tsx +1 -8
- package/dist/templates/word-game-agent/game.ts +15 -27
- package/dist/templates/word-game-agent/shared.ts +36 -20
- package/dist/templates/word-game-agent/tools/final_score.ts +14 -13
- package/dist/templates/word-game-agent/tools/relay_description.ts +90 -66
- package/dist/templates/word-game-agent/tools/repeat_word.ts +11 -10
- package/dist/templates/word-game-agent/tools/skip_word.ts +17 -21
- package/dist/templates/word-game-agent/tools/start_game.ts +26 -30
- package/dist/{test-XufelYGW.mjs → test-CW5cw5fy.mjs} +3 -4
- package/dist/typecheck.mjs +1 -1
- package/dist/worker-bundler-D8uCzpYP.mjs +335 -0
- package/dist/worker-bundler.d.ts +39 -0
- package/dist/worker-bundler.mjs +2 -155
- package/dist/{workflow-CDUlTD5B.mjs → workflow-5gOZMB2M.mjs} +66 -19
- package/package.json +4 -4
- package/dist/_output-DBP9Op_d.mjs +0 -120
- package/dist/_studio-B5m4jBTD.mjs +0 -256
- package/dist/_ui-Coe0zwmm.mjs +0 -102
- package/dist/_utils-BVLdBvdT.mjs +0 -186
- package/dist/delete-DwXCHzTl.mjs +0 -55
- package/dist/templates/document-redline-workflow/form.ts +0 -73
- package/dist/templates/emergency-dispatch-agent/events.ts +0 -48
- package/dist/templates/hotel-reception-agent/events.ts +0 -80
- package/dist/templates/meeting-recap-agent/shared.ts +0 -44
- package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +0 -25
- package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +0 -24
- package/dist/templates/meeting-recap-agent/tools/recap_status.ts +0 -45
- package/dist/templates/meeting-recap-agent/workflows/tokens.ts +0 -47
- package/dist/templates/outbound-call-agent/call-params.ts +0 -109
- package/dist/templates/outbound-call-agent/live-calls.ts +0 -80
- package/dist/templates/outbound-call-agent/workflows/tokens.ts +0 -16
- package/dist/templates/research-handoff-agent/shared.ts +0 -41
- package/dist/templates/research-handoff-agent/tools/research_progress.ts +0 -23
- package/dist/templates/research-handoff-agent/tools/research_status.ts +0 -73
- package/dist/templates/research-handoff-agent/workflows/review.ts +0 -43
- package/dist/templates/roadside-assistance-agent/events.ts +0 -92
- package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +0 -137
- package/dist/templates/transcription-workflow/total-latency.tsx +0 -170
- package/dist/templates/travel-concierge-agent/call-events.ts +0 -80
|
@@ -5,129 +5,58 @@
|
|
|
5
5
|
* Specs for the recap desk — the template that ports the Temporal workflow
|
|
6
6
|
* patterns onto a voice call.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* for a second transcription, and that a cancel says out loud what cancelling
|
|
16
|
-
* does not do.
|
|
17
|
-
* - **The steps**, directly. Imported through vitest with no bundler in the
|
|
18
|
-
* path a step is an ordinary async function, so its HTTP
|
|
19
|
-
* handling, its retryable/fatal split and its JSON contract with the model are
|
|
20
|
-
* all testable.
|
|
21
|
-
* - **The body's two helpers** — the poll loop and the compensation unwind —
|
|
22
|
-
* with `sleep` stubbed. What that asserts is ORDERING and BRANCHING, which is
|
|
23
|
-
* ordinary logic and worth pinning; it asserts nothing about durability,
|
|
24
|
-
* replay or suspension, and could not.
|
|
25
|
-
* - **`recapFlow` itself, durably.** The last block runs it on the real replay
|
|
26
|
-
* engine over an in-memory journal (`runWorkflow`,
|
|
27
|
-
* `@alexkroman1/aai-runtime/testing`), which this file used to say needed a
|
|
28
|
-
* built world. It is the tier that reaches this desk's two most expensive
|
|
29
|
-
* claims: that a resume does not re-transcribe, and that the RETENTION GATE's
|
|
30
|
-
* unanswered window deletes. `aai-cli`'s `dev-workflow.scenario.test.ts` is
|
|
31
|
-
* still the tier above it, with a project and a real queue.
|
|
32
|
-
*
|
|
33
|
-
* **The branch this file used to name as its biggest gap no longer exists.** It
|
|
34
|
-
* was `recapFlow`'s `if (isWorkflowSuspend(err)) throw err;` — the guard whose
|
|
35
|
-
* absence had once deleted the transcript the run was waiting for — and it was
|
|
36
|
-
* unpinnable here by construction, since `createWorkflowContext`'s `sleep` is
|
|
37
|
-
* RECORDED and its `waitFor` answers out of `hooks`, so no wait it serves ever
|
|
38
|
-
* suspended. A wait now hands the body a promise that never settles, so a
|
|
39
|
-
* suspension cannot reach a `catch` at all and there is no branch left to test:
|
|
40
|
-
* `aai-runtime`'s `workflow/replay/suspend.ts` carries the mechanism and
|
|
41
|
-
* `workflow/replay.test.ts` the engine-level proof, for every template at once.
|
|
8
|
+
* Four tiers: the two tools against a stubbed `ctx.workflows`; the steps,
|
|
9
|
+
* directly, against a stubbed provider; the body's helpers (the poll and the
|
|
10
|
+
* gate) through `createWorkflowContext`, which records ORDERING and BRANCHING
|
|
11
|
+
* and claims nothing about durability; and `recapFlow` itself on the real
|
|
12
|
+
* replay engine (`runWorkflow`), which is the tier that reaches this desk's two
|
|
13
|
+
* most expensive claims — a resume does not re-transcribe, and the RETENTION
|
|
14
|
+
* GATE's unanswered window deletes.
|
|
42
15
|
*/
|
|
43
16
|
|
|
44
|
-
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
45
17
|
import agentDef from "virtual:aai/agent";
|
|
46
|
-
import {
|
|
47
|
-
import type {
|
|
18
|
+
import { describeRun } from "@alexkroman1/aai";
|
|
19
|
+
import type {
|
|
20
|
+
WorkflowTestRun,
|
|
21
|
+
WorkflowTestStep,
|
|
22
|
+
WorkflowTestWait,
|
|
23
|
+
} from "@alexkroman1/aai-runtime/testing";
|
|
48
24
|
import {
|
|
49
25
|
createRunSnapshot,
|
|
50
26
|
createStubWorkflows,
|
|
51
27
|
createToolContext,
|
|
52
28
|
createWorkflowContext,
|
|
53
29
|
parseSchemaInput,
|
|
54
|
-
type RecordedStep,
|
|
55
|
-
type RunWorkflowOptions,
|
|
56
|
-
runTool,
|
|
57
30
|
runWorkflow,
|
|
58
31
|
schemaInputIssues,
|
|
59
32
|
stubGatewayRoute,
|
|
60
|
-
toolRunner,
|
|
61
33
|
type WorkflowContextRecorder,
|
|
62
|
-
type WorkflowTestHandle,
|
|
63
|
-
type WorkflowTestRun,
|
|
64
|
-
type WorkflowTestStep,
|
|
65
|
-
type WorkflowTestWait,
|
|
66
34
|
} from "@alexkroman1/aai-runtime/testing";
|
|
67
35
|
import {
|
|
36
|
+
describeAgent,
|
|
68
37
|
installStubGateway,
|
|
69
38
|
installStubStepFetch,
|
|
70
39
|
installStubWorkflows,
|
|
71
40
|
} from "@alexkroman1/aai-runtime/testing/vitest";
|
|
72
41
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
73
|
-
import
|
|
74
|
-
import
|
|
75
|
-
import
|
|
76
|
-
import {
|
|
42
|
+
import keepTranscript from "./tools/keep_transcript.ts";
|
|
43
|
+
import requestRecap from "./tools/request_recap.ts";
|
|
44
|
+
import recap, {
|
|
77
45
|
askWhetherToKeep,
|
|
78
46
|
awaitTranscript,
|
|
79
|
-
callbackUrl,
|
|
80
47
|
checkTranscript,
|
|
81
48
|
compensate,
|
|
82
49
|
discardTranscript,
|
|
83
|
-
|
|
50
|
+
SAMPLE_RECORDING,
|
|
84
51
|
submitRecording,
|
|
85
52
|
summarize,
|
|
86
53
|
type TranscriptState,
|
|
87
54
|
} from "./workflows/recap.ts";
|
|
88
|
-
import { retentionToken, transcriptToken } from "./workflows/tokens.ts";
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Every tool here is driven through the agent's own table, by the name the model
|
|
92
|
-
* calls.
|
|
93
|
-
*
|
|
94
|
-
* The second parameter is args-or-context, which is `runTool`'s own shape: four
|
|
95
|
-
* of this desk's five tools take no arguments, and the `{}` those calls were
|
|
96
|
-
* obliged to pass sat between the two values a reader cares about.
|
|
97
|
-
*/
|
|
98
|
-
const run = toolRunner(agentDef);
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* A `ctx.workflows` that records `start` and answers the lookups from a fixture.
|
|
102
|
-
*
|
|
103
|
-
* `installStubWorkflows` (`@alexkroman1/aai-runtime/testing/vitest`) is the whole thing — a
|
|
104
|
-
* `vi.fn` per method over one `runs` list, with `stream`/`streamTail` left
|
|
105
|
-
* rejecting because `recap_progress` reads progress through `lastLine` and
|
|
106
|
-
* composing those two by hand is the hazard `lastLine` exists to remove. What
|
|
107
|
-
* is local is only which workflow this desk declares.
|
|
108
|
-
*/
|
|
109
|
-
function stubWorkflows(runs: WorkflowRunSnapshot[] = []): WorkflowClient {
|
|
110
|
-
return installStubWorkflows({ runs, names: ["recap"] });
|
|
111
|
-
}
|
|
112
55
|
|
|
113
|
-
/**
|
|
114
|
-
* Every step of one name the body issued, in order.
|
|
115
|
-
*
|
|
116
|
-
* Five assertions in this file ask that question — four about `noteSlow`, which
|
|
117
|
-
* must be said once and only once, and one about what `summarize` was allowed
|
|
118
|
-
* to spend — and each had re-written the predicate. `RecordedStep` is what
|
|
119
|
-
* `createWorkflowContext` records per `ctx.step` call, and it carries the
|
|
120
|
-
* OPTIONS as well as the name, which is why the retry-policy assertion can be
|
|
121
|
-
* made here at all.
|
|
122
|
-
*/
|
|
123
|
-
function recordedSteps(ctx: WorkflowContextRecorder, name: string): RecordedStep[] {
|
|
124
|
-
return ctx.steps.filter((step) => step.name === name);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** A finished recap, as the workflow's output reaches the tools. */
|
|
56
|
+
/** A finished recap, as the workflow's output reaches the status line. */
|
|
128
57
|
function finishedOutput(over: { kept?: boolean; answered?: boolean } = {}) {
|
|
129
58
|
return {
|
|
130
|
-
url:
|
|
59
|
+
url: SAMPLE_RECORDING,
|
|
131
60
|
headline: "Smoke reaches the east coast",
|
|
132
61
|
points: ["a", "b", "c"],
|
|
133
62
|
spoken: "Wildfire smoke drifted east and pushed air quality into the unhealthy range.",
|
|
@@ -139,24 +68,9 @@ function finishedOutput(over: { kept?: boolean; answered?: boolean } = {}) {
|
|
|
139
68
|
};
|
|
140
69
|
}
|
|
141
70
|
|
|
142
|
-
|
|
143
|
-
test("
|
|
144
|
-
// `toContain` rather than an exact key list: a second workflow is an
|
|
145
|
-
// invited edit and must not redden a test the author did not write. The
|
|
146
|
-
// NAME is still pinned, deliberately — this key is a STRING to everything
|
|
147
|
-
// outside this file (the REST route, `ctx.workflows.get`, a schedule), so
|
|
148
|
-
// renaming it is a runtime 404 rather than a compile error, and nothing
|
|
149
|
-
// else says so.
|
|
150
|
-
expect(Object.keys(agentDef.workflows ?? {})).toContain("recap");
|
|
71
|
+
describeAgent(agentDef, (run) => {
|
|
72
|
+
test("declares its workflow by its file name, with a schema and the key its steps read", async () => {
|
|
151
73
|
expect(agentDef.workflows?.recap).toBe(recap);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("with an input schema, so a bad URL fails at the call site", async () => {
|
|
155
|
-
// `parseSchemaInput` / `schemaInputIssues` rather than a reach through
|
|
156
|
-
// `["~standard"].validate`: that is the vendor WIRE contract, and whether it
|
|
157
|
-
// answers synchronously or with a promise is the vendor's business — a
|
|
158
|
-
// missing `await` there leaves `.issues` undefined and the refusing half
|
|
159
|
-
// passes for the wrong reason.
|
|
160
74
|
const parsed = await parseSchemaInput(recap.input, {
|
|
161
75
|
url: "https://example.com/a.mp3",
|
|
162
76
|
requestedBy: "s",
|
|
@@ -165,810 +79,400 @@ describe("the agent declares its workflow", () => {
|
|
|
165
79
|
expect(
|
|
166
80
|
await schemaInputIssues(recap.input, { url: "not a url", requestedBy: "s" }),
|
|
167
81
|
).toBeDefined();
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
test("and names the credential its steps read, so a deploy checks for it", () => {
|
|
171
|
-
// The steps reach the key with `requireStepEnv`, which no part of the agent
|
|
172
|
-
// config would otherwise mention.
|
|
82
|
+
// The steps reach the key with `requireStepEnv`, which nothing else in the
|
|
83
|
+
// agent config would mention.
|
|
173
84
|
expect(agentDef.requiredEnv).toContain("ASSEMBLYAI_API_KEY");
|
|
174
85
|
});
|
|
175
86
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// going MISSING — which is what a broken discovery looks like, and it looks
|
|
182
|
-
// identical to a template that never had tools.
|
|
183
|
-
expect(Object.keys(agentDef.tools)).toEqual(
|
|
184
|
-
expect.arrayContaining([
|
|
185
|
-
"cancel_recap",
|
|
186
|
-
"keep_transcript",
|
|
187
|
-
"recap_progress",
|
|
188
|
-
"recap_status",
|
|
189
|
-
"request_recap",
|
|
190
|
-
]),
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
87
|
+
describe("request_recap", () => {
|
|
88
|
+
test("starts a run on the session's key, and asks to be TOLD when it lands", async () => {
|
|
89
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
90
|
+
const ctx = createToolContext({ workflows });
|
|
91
|
+
const result = await run(requestRecap, ctx);
|
|
194
92
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
recap,
|
|
203
|
-
{ url: expect.stringContaining("http"), requestedBy: ctx.sessionId },
|
|
204
|
-
// `key` is the DURABLE handle — a later call finds the run by it — and
|
|
205
|
-
// `notify` is the live one: this session is told when the run lands.
|
|
206
|
-
{ key: ctx.sessionId, notify: expect.stringContaining("one-sentence") },
|
|
207
|
-
);
|
|
208
|
-
expect(result).toMatchObject({ started: true, runId: "wrun_stub" });
|
|
209
|
-
});
|
|
93
|
+
expect(workflows.start).toHaveBeenCalledWith(
|
|
94
|
+
recap,
|
|
95
|
+
{ url: SAMPLE_RECORDING, requestedBy: ctx.sessionId },
|
|
96
|
+
{ notify: expect.stringContaining("one-sentence") },
|
|
97
|
+
);
|
|
98
|
+
expect(result).toMatchObject({ started: true, runId: "wrun_stub" });
|
|
99
|
+
});
|
|
210
100
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
101
|
+
test("uses the caller's recording when they named one", async () => {
|
|
102
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
103
|
+
await run(
|
|
104
|
+
requestRecap,
|
|
105
|
+
{ url: "https://example.com/board.mp3" },
|
|
106
|
+
createToolContext({ workflows }),
|
|
107
|
+
);
|
|
108
|
+
expect(vi.mocked(workflows.start).mock.calls[0]?.[1]).toMatchObject({
|
|
109
|
+
url: "https://example.com/board.mp3",
|
|
110
|
+
});
|
|
111
|
+
});
|
|
218
112
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
113
|
+
test("REFUSES a second run while one is live, and hands back the one that exists", async () => {
|
|
114
|
+
// Temporal's workflow-id reuse policy: a caller who asks twice would
|
|
115
|
+
// otherwise pay for the same recording being transcribed twice.
|
|
116
|
+
const workflows = installStubWorkflows({
|
|
117
|
+
agent: agentDef,
|
|
118
|
+
runs: [createRunSnapshot(recap, { status: "running" })],
|
|
119
|
+
});
|
|
120
|
+
const result = await run(requestRecap, createToolContext({ workflows }));
|
|
121
|
+
expect(result).toMatchObject({ started: false, runId: "wrun_1" });
|
|
122
|
+
expect(workflows.start).not.toHaveBeenCalled();
|
|
228
123
|
});
|
|
229
|
-
});
|
|
230
124
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
125
|
+
test("starts a fresh run once the previous one is terminal", async () => {
|
|
126
|
+
const workflows = installStubWorkflows({
|
|
127
|
+
agent: agentDef,
|
|
128
|
+
runs: [createRunSnapshot(recap, { status: "completed", output: finishedOutput() })],
|
|
129
|
+
});
|
|
130
|
+
const result = await run(requestRecap, createToolContext({ workflows }));
|
|
131
|
+
expect(result).toMatchObject({ started: true });
|
|
132
|
+
});
|
|
239
133
|
});
|
|
240
134
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
135
|
+
describe("keep_transcript — the signal", () => {
|
|
136
|
+
// A `ctx.workflows` where `signalRun` is the ONLY method that answers, so
|
|
137
|
+
// these fail if the tool ever reaches for a run: the hook is addressed by
|
|
138
|
+
// the def, the session's key and the label, which is the whole claim of
|
|
139
|
+
// the tool — neither side spells a token.
|
|
140
|
+
const signalOnly = (answer: boolean) => {
|
|
141
|
+
const signalRun = vi.fn(async () => answer);
|
|
142
|
+
return {
|
|
143
|
+
signalRun,
|
|
144
|
+
ctx: createToolContext({ workflows: createStubWorkflows({ signalRun }) }),
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
test("signals the run's retention hook by the session's key and the label", async () => {
|
|
149
|
+
const { signalRun, ctx } = signalOnly(true);
|
|
150
|
+
const result = await run(keepTranscript, { keep: true }, ctx);
|
|
151
|
+
expect(signalRun).toHaveBeenCalledWith(recap, "session", "retention", { keep: true });
|
|
152
|
+
expect(result).toMatchObject({ answered: true, keep: true });
|
|
153
|
+
});
|
|
250
154
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
155
|
+
test("carries a DECLINE, not just an approval", async () => {
|
|
156
|
+
// "Delete it" has to reach the run before the window closes, or the
|
|
157
|
+
// caller waits two minutes for something they already said.
|
|
158
|
+
const { signalRun, ctx } = signalOnly(true);
|
|
159
|
+
await run(keepTranscript, { keep: false }, ctx);
|
|
160
|
+
expect(signalRun).toHaveBeenCalledWith(recap, "session", "retention", { keep: false });
|
|
161
|
+
});
|
|
257
162
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
]);
|
|
264
|
-
const result = await runTool(recapStatus, createToolContext({ workflows }));
|
|
265
|
-
expect(result.runs[0]).toContain("air quality");
|
|
163
|
+
test("a token nobody holds is reported as SETTLED, not as a failure", async () => {
|
|
164
|
+
const { ctx } = signalOnly(false);
|
|
165
|
+
const result = await run(keepTranscript, { keep: true }, ctx);
|
|
166
|
+
expect(result).toMatchObject({ answered: false, note: expect.stringContaining("settled") });
|
|
167
|
+
});
|
|
266
168
|
});
|
|
169
|
+
});
|
|
267
170
|
|
|
268
|
-
|
|
171
|
+
describe("what the status builtin says per run — the QUERY port", () => {
|
|
172
|
+
test("reads back the ONE-SENTENCE version of a finished recap, and the transcript's fate", () => {
|
|
173
|
+
const kept = createRunSnapshot(recap, { status: "completed", output: finishedOutput() });
|
|
174
|
+
expect(describeRun(recap, kept)).toContain("air quality");
|
|
175
|
+
expect(describeRun(recap, kept)).toContain("transcript kept");
|
|
269
176
|
// The caller who never got round to answering should hear that the
|
|
270
177
|
// transcript is gone, not just the recap.
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
status: "completed",
|
|
275
|
-
output: finishedOutput({ kept: false, answered: false }),
|
|
276
|
-
}),
|
|
277
|
-
];
|
|
278
|
-
const result = await runTool(
|
|
279
|
-
recapStatus,
|
|
280
|
-
createToolContext({ workflows: stubWorkflows(runs) }),
|
|
281
|
-
);
|
|
282
|
-
expect(result.runs[0]).toContain("transcript deleted");
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test("reports a live run as still working rather than as empty", async () => {
|
|
286
|
-
const ctx = createToolContext({
|
|
287
|
-
workflows: stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]),
|
|
178
|
+
const deleted = createRunSnapshot(recap, {
|
|
179
|
+
status: "completed",
|
|
180
|
+
output: finishedOutput({ kept: false, answered: false }),
|
|
288
181
|
});
|
|
289
|
-
|
|
290
|
-
expect(result.runs[0]).toContain("Still working");
|
|
182
|
+
expect(describeRun(recap, deleted)).toContain("transcript deleted");
|
|
291
183
|
});
|
|
292
184
|
|
|
293
|
-
test("
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
// to chase.
|
|
297
|
-
const runs = [
|
|
298
|
-
createRunSnapshot({ workflow: "recap", status: "failed", error: "provider unavailable" }),
|
|
299
|
-
];
|
|
300
|
-
const result = await runTool(
|
|
301
|
-
recapStatus,
|
|
302
|
-
createToolContext({ workflows: stubWorkflows(runs) }),
|
|
185
|
+
test("reports a live run as still working, and a failed one as ROLLED BACK", () => {
|
|
186
|
+
expect(describeRun(recap, createRunSnapshot(recap, { status: "running" }))).toContain(
|
|
187
|
+
"Still working",
|
|
303
188
|
);
|
|
304
|
-
|
|
305
|
-
expect(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
test("bounds how many past runs it reads aloud", async () => {
|
|
309
|
-
const workflows = stubWorkflows([]);
|
|
310
|
-
const ctx = createToolContext({ workflows });
|
|
311
|
-
await run("recap_status", ctx);
|
|
312
|
-
// A voice reply cannot be a list of twenty runs.
|
|
313
|
-
expect(workflows.find).toHaveBeenCalledWith(recap, ctx.sessionId, { limit: 3 });
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
describe("recap_progress", () => {
|
|
318
|
-
test("reads the run's own progress line rather than its status", async () => {
|
|
319
|
-
const workflows = stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]);
|
|
320
|
-
vi.mocked(workflows.lastLine).mockResolvedValue("Transcript processing.");
|
|
321
|
-
const result = await run("recap_progress", createToolContext({ workflows }));
|
|
322
|
-
expect(result).toMatchObject({ progress: "Transcript processing." });
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
test("asks for the LAST line, not the whole log", async () => {
|
|
326
|
-
// Every poll narrates, so a twenty-minute run's whole log is eighty lines.
|
|
327
|
-
// `lastLine` is the whole request — the bound that keeps an empty channel
|
|
328
|
-
// from hanging belongs to the method, so nothing here composes
|
|
329
|
-
// `streamTail` and `stream`.
|
|
330
|
-
const workflows = stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]);
|
|
331
|
-
vi.mocked(workflows.lastLine).mockResolvedValue("a");
|
|
332
|
-
await run("recap_progress", createToolContext({ workflows }));
|
|
333
|
-
expect(workflows.lastLine).toHaveBeenCalledWith("wrun_1");
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
test("a run that has written nothing yet says so", async () => {
|
|
337
|
-
// `lastLine` resolves `undefined` for an empty channel, and this is the arm
|
|
338
|
-
// the tool branches on. That an empty channel does not HANG — it is never
|
|
339
|
-
// closed, so a stream opened on one waits for a line that may never come —
|
|
340
|
-
// is `lastLine`'s own guarantee now, and `aai`'s to test.
|
|
341
|
-
const workflows = stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]);
|
|
342
|
-
const result = await run("recap_progress", createToolContext({ workflows }));
|
|
343
|
-
expect(result).toMatchObject({ note: expect.stringContaining("nothing to report") });
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
describe("keep_transcript — the signal", () => {
|
|
348
|
-
/**
|
|
349
|
-
* A `ctx.workflows` where `signal` is the ONLY method that answers.
|
|
350
|
-
*
|
|
351
|
-
* `createStubWorkflows` (`@alexkroman1/aai-runtime/testing`) rather than the
|
|
352
|
-
* `installStubWorkflows` the rest of this file uses, and the difference is the
|
|
353
|
-
* assertion: every method it is not given REJECTS, so these three tests fail
|
|
354
|
-
* if `keep_transcript` ever reaches for a run — a `find` to locate one, a
|
|
355
|
-
* `get` to check it is still open. It needs neither, because a hook is
|
|
356
|
-
* addressed by a token both sides derive from the session, and that is the
|
|
357
|
-
* whole claim of this tool. Spread over the general stub, a stray lookup would
|
|
358
|
-
* have been answered and nothing would have said so.
|
|
359
|
-
*/
|
|
360
|
-
const signalOnly = (signal: WorkflowClient["signal"]) => createStubWorkflows({ signal });
|
|
361
|
-
|
|
362
|
-
test("signals the run's retention hook on the token BOTH sides derive", async () => {
|
|
363
|
-
// The token is the contract. `workflows/tokens.ts` is the one place it is
|
|
364
|
-
// spelled, which is what stops the body waiting on a string the tool never
|
|
365
|
-
// sends — a drift whose only symptom is `signal` answering false.
|
|
366
|
-
const signal = vi.fn(async () => true);
|
|
367
|
-
const ctx = createToolContext({ workflows: signalOnly(signal) });
|
|
368
|
-
const result = await run("keep_transcript", { keep: true }, ctx);
|
|
369
|
-
|
|
370
|
-
expect(signal).toHaveBeenCalledWith(retentionToken(ctx.sessionId), { keep: true });
|
|
371
|
-
expect(result).toMatchObject({ answered: true, keep: true });
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
test("carries a DECLINE, not just an approval", async () => {
|
|
375
|
-
// Three outcomes, and this is the one a boolean gate loses if the tool only
|
|
376
|
-
// ever signals on yes: "delete it" has to reach the run before the window
|
|
377
|
-
// closes, or the caller waits two minutes for something they already said.
|
|
378
|
-
const signal = vi.fn(async () => true);
|
|
379
|
-
const ctx = createToolContext({ workflows: signalOnly(signal) });
|
|
380
|
-
await run("keep_transcript", { keep: false }, ctx);
|
|
381
|
-
expect(signal).toHaveBeenCalledWith(expect.any(String), { keep: false });
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
test("a token nobody holds is reported as SETTLED, not as a failure", async () => {
|
|
385
|
-
// The ordinary case: the window closed, or the caller answered a question
|
|
386
|
-
// nobody asked.
|
|
387
|
-
const signal = vi.fn(async () => false);
|
|
388
|
-
const ctx = createToolContext({ workflows: signalOnly(signal) });
|
|
389
|
-
const result = await run("keep_transcript", { keep: true }, ctx);
|
|
390
|
-
expect(result).toMatchObject({ answered: false, note: expect.stringContaining("settled") });
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
describe("cancel_recap", () => {
|
|
395
|
-
test("cancels the live run", async () => {
|
|
396
|
-
const workflows = stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]);
|
|
397
|
-
const result = await run("cancel_recap", createToolContext({ workflows }));
|
|
398
|
-
expect(workflows.cancel).toHaveBeenCalledWith("wrun_1");
|
|
399
|
-
expect(result).toMatchObject({ cancelled: true });
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
test("says the transcript is LEFT BEHIND, because cancellation is not cooperative here", async () => {
|
|
403
|
-
// The one Temporal behaviour that did not port. Temporal delivers
|
|
404
|
-
// cancellation into the workflow, so the saga's catch runs; `cancel` here
|
|
405
|
-
// stops replaying the run, so the compensations never fire. A template that
|
|
406
|
-
// implied otherwise would be teaching the wrong thing.
|
|
407
|
-
const workflows = stubWorkflows([createRunSnapshot({ workflow: "recap", status: "running" })]);
|
|
408
|
-
const result = await runTool(cancelRecap, createToolContext({ workflows }));
|
|
409
|
-
expect(result.note).toContain("left behind");
|
|
189
|
+
const failed = createRunSnapshot(recap, { status: "failed", error: "provider unavailable" });
|
|
190
|
+
expect(describeRun(recap, failed)).toContain("rolled back");
|
|
191
|
+
expect(describeRun(recap, failed)).toContain("provider unavailable");
|
|
410
192
|
});
|
|
411
193
|
|
|
412
|
-
test("
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
expect(result).toMatchObject({ cancelled: false, note: "That one had already finished." });
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
test("says nothing was started when the key has no runs", async () => {
|
|
422
|
-
const workflows = stubWorkflows([]);
|
|
423
|
-
const result = await run("cancel_recap", createToolContext({ workflows }));
|
|
424
|
-
expect(result).toMatchObject({ cancelled: false, note: "Nothing started yet." });
|
|
425
|
-
expect(workflows.cancel).not.toHaveBeenCalled();
|
|
194
|
+
test("the cancel note says what cancelling does NOT roll back", () => {
|
|
195
|
+
// The one Temporal behaviour that did not port: `cancel` stops replaying
|
|
196
|
+
// the run, so the compensations never fire. A template that implied
|
|
197
|
+
// otherwise would be teaching the wrong thing.
|
|
198
|
+
expect(recap.cancelNote).toMatch(/left behind/);
|
|
199
|
+
expect(recap.cancelNote).toMatch(/does not roll back/);
|
|
426
200
|
});
|
|
427
201
|
});
|
|
428
202
|
|
|
429
203
|
// ---- The steps --------------------------------------------------------------
|
|
430
204
|
|
|
431
|
-
/**
|
|
432
|
-
* A provider answering `body` with `status`, recording what it was asked.
|
|
433
|
-
*
|
|
434
|
-
* Published into `stepFetch`'s OWN slot, not over `globalThis.fetch`. Every
|
|
435
|
-
* request in this file goes through `stepFetch` — `request()` and
|
|
436
|
-
* `discardTranscript` reach it directly, `orFail(stepTranscribeSubmit)`
|
|
437
|
-
* through the SDK — and `step-fetch.ts` falls back to `globalThis.fetch` only
|
|
438
|
-
* when nothing is published. A global stub therefore passed while exercising a
|
|
439
|
-
* path production never takes; every sibling template already stubs the slot,
|
|
440
|
-
* and `link-digest-workflow/agent.test.ts` states the rule this one used to break.
|
|
441
|
-
*
|
|
442
|
-
* `installStubStepFetch` unpublishes on `onTestFinished`, so there is no restore
|
|
443
|
-
* registry here and a stub cannot reach the next file.
|
|
444
|
-
*/
|
|
205
|
+
/** A provider answering `body` with `status`, into `stepFetch`'s own slot. */
|
|
445
206
|
function stubProvider(body: unknown, status = 200) {
|
|
446
207
|
return installStubStepFetch(() => ({ status, body })).calls;
|
|
447
208
|
}
|
|
448
209
|
|
|
449
|
-
describe("
|
|
210
|
+
describe("the steps", () => {
|
|
450
211
|
beforeEach(() => {
|
|
451
|
-
// `stepEnv` falls back to the process env when no host has published one
|
|
452
|
-
// which is exactly the case a spec is. `unstubEnvs` clears it per test.
|
|
212
|
+
// `stepEnv` falls back to the process env when no host has published one.
|
|
453
213
|
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
454
214
|
});
|
|
455
215
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
216
|
+
describe("submitRecording", () => {
|
|
217
|
+
test("posts the recording with the desk's own request, on the raw key", async () => {
|
|
218
|
+
const calls = stubProvider({ id: "t_1", status: "queued" });
|
|
219
|
+
expect(await submitRecording("https://example.com/a.mp3")).toBe("t_1");
|
|
220
|
+
|
|
221
|
+
const call = calls[0];
|
|
222
|
+
expect(call?.method).toBe("POST");
|
|
223
|
+
expect(JSON.parse(String(call?.body))).toMatchObject({
|
|
224
|
+
audio_url: "https://example.com/a.mp3",
|
|
225
|
+
speaker_labels: true,
|
|
226
|
+
});
|
|
227
|
+
// AssemblyAI takes the key RAW — no `Bearer` prefix.
|
|
228
|
+
const auth = Object.entries(call?.headers ?? {}).find(
|
|
229
|
+
([name]) => name.toLowerCase() === "authorization",
|
|
230
|
+
);
|
|
231
|
+
expect(auth?.[1]).toBe("sk-test");
|
|
464
232
|
});
|
|
465
233
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
audio_url: "https://example.com/a.mp3",
|
|
472
|
-
speaker_labels: true,
|
|
234
|
+
test("fails FATALLY on a bad key and plainly on a rate limit", async () => {
|
|
235
|
+
stubProvider({ error: "nope" }, 401);
|
|
236
|
+
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/HTTP 401/);
|
|
237
|
+
stubProvider({ error: "slow down" }, 429);
|
|
238
|
+
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/HTTP 429/);
|
|
473
239
|
});
|
|
474
|
-
// AssemblyAI takes the key RAW — no `Bearer` prefix, unlike the
|
|
475
|
-
// OpenAI-compatible LLM gateway `summarize` calls. The SDK spells the
|
|
476
|
-
// header `Authorization`; HTTP header names are case-insensitive, so the
|
|
477
|
-
// lookup is too rather than pinning one casing.
|
|
478
|
-
const auth = Object.entries(call?.headers ?? {}).find(
|
|
479
|
-
([name]) => name.toLowerCase() === "authorization",
|
|
480
|
-
);
|
|
481
|
-
expect(auth?.[1]).toBe("sk-test");
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
test("fails FATALLY on a bad key and plainly on a rate limit", async () => {
|
|
485
|
-
// The retry policy in one assertion: a 401 answers the same way on the
|
|
486
|
-
// fourth attempt, a 429 is what retries are for.
|
|
487
|
-
stubProvider({ error: "nope" }, 401);
|
|
488
|
-
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/HTTP 401/);
|
|
489
|
-
stubProvider({ error: "slow down" }, 429);
|
|
490
|
-
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/HTTP 429/);
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
test("refuses a response that names no transcript id", async () => {
|
|
494
|
-
// Nothing downstream can poll without one, and a run that discovers that at
|
|
495
|
-
// the first poll has already lost the id it needed to compensate with.
|
|
496
|
-
stubProvider({ status: "queued" });
|
|
497
|
-
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/transcript id/);
|
|
498
|
-
});
|
|
499
240
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
// This one field is the whole difference between the two arms of
|
|
506
|
-
// `awaitTranscript`.
|
|
507
|
-
expect(JSON.parse(String(calls[0]?.body))).toMatchObject({
|
|
508
|
-
webhook_url: "https://desk.example/hook/transcript:s_1",
|
|
509
|
-
speaker_labels: true,
|
|
241
|
+
test("refuses a response that names no transcript id", async () => {
|
|
242
|
+
// A run that discovers that at the first poll has already lost the id it
|
|
243
|
+
// needed to compensate with.
|
|
244
|
+
stubProvider({ status: "queued" });
|
|
245
|
+
await expect(submitRecording("https://example.com/a.mp3")).rejects.toThrow(/transcript id/);
|
|
510
246
|
});
|
|
511
|
-
});
|
|
512
247
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
test("OMITS the key rather than sending a null when there is no callback URL", async () => {
|
|
527
|
-
// `JSON.stringify` drops an `undefined` property, so the key is absent on
|
|
528
|
-
// the wire for free — and what this pins is that nobody "makes it explicit"
|
|
529
|
-
// with a `?? null` or a `?? ""`, either of which puts it back. A provider
|
|
530
|
-
// handed a null for a URL is entitled to refuse the whole submission. The
|
|
531
|
-
// assertion is about the KEY, which `toMatchObject` cannot express.
|
|
532
|
-
const calls = stubProvider({ id: "t_1", status: "queued" });
|
|
533
|
-
await submitRecording("https://example.com/a.mp3");
|
|
534
|
-
|
|
535
|
-
expect(Object.keys(JSON.parse(String(calls[0]?.body)))).not.toContain("webhook_url");
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
describe("callbackUrl", () => {
|
|
540
|
-
test("degrades to NO callback when the deployment cannot mint one", async () => {
|
|
541
|
-
// `stepWebhookUrl` THROWS on an unpublished slot rather than answering
|
|
542
|
-
// `undefined` — a callback URL has no legitimate default, so the SDK refuses
|
|
543
|
-
// to invent one. A spec publishes no minter, which is the same position as
|
|
544
|
-
// `aai dev` on a laptop and a self-hosted server started without
|
|
545
|
-
// `publicUrl`. What must NOT happen is that throw reaching the step: a recap
|
|
546
|
-
// may not fail over a missing optimization.
|
|
547
|
-
expect(callbackUrl(transcriptToken("s_1"))).toBeUndefined();
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
test("does not swallow an EMPTY token, which would compose the route's own prefix", async () => {
|
|
551
|
-
// The one input `stepWebhookUrl` refuses that is a caller bug rather than a
|
|
552
|
-
// deployment fact — and this pins that `callbackUrl`'s catch does not hide
|
|
553
|
-
// it as "no callback available". A URL that is the bare prefix is refused by
|
|
554
|
-
// the route's own parser, so the failure would otherwise arrive at the far
|
|
555
|
-
// end as a 404 on a URL nobody can re-issue.
|
|
556
|
-
//
|
|
557
|
-
// It currently reads `undefined` because the unpublished slot is checked
|
|
558
|
-
// FIRST, so both arms of `stepWebhookUrl` are indistinguishable here. That is
|
|
559
|
-
// a real limit of this tier rather than a claim about the SDK: a spec with a
|
|
560
|
-
// published minter would tell them apart, and publishing one needs
|
|
561
|
-
// `publishStepWebhookUrl` off `@alexkroman1/aai/host-internal` — a host
|
|
562
|
-
// surface a template has no business importing. Recorded so the next reader
|
|
563
|
-
// does not mistake the assertion for a stronger one than it is.
|
|
564
|
-
expect(callbackUrl("")).toBeUndefined();
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
describe("checkTranscript", () => {
|
|
569
|
-
beforeEach(() => {
|
|
570
|
-
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
test("reports a completed job with its text and duration", async () => {
|
|
574
|
-
stubProvider({ status: "completed", text: "Hello there.", audio_duration: 254 });
|
|
575
|
-
expect(await checkTranscript("t_1")).toEqual({
|
|
576
|
-
status: "completed",
|
|
577
|
-
text: "Hello there.",
|
|
578
|
-
audioDuration: 254,
|
|
248
|
+
test("asks the provider to CALL BACK when handed a URL, and OMITS the key otherwise", async () => {
|
|
249
|
+
const calls = stubProvider({ id: "t_1", status: "queued" });
|
|
250
|
+
await submitRecording(
|
|
251
|
+
"https://example.com/a.mp3",
|
|
252
|
+
"https://desk.example/hook/transcript:s_1",
|
|
253
|
+
);
|
|
254
|
+
expect(JSON.parse(String(calls[0]?.body))).toMatchObject({
|
|
255
|
+
webhook_url: "https://desk.example/hook/transcript:s_1",
|
|
256
|
+
});
|
|
257
|
+
// Absent on the wire, never a null: a provider handed a null for a URL is
|
|
258
|
+
// entitled to refuse the whole submission.
|
|
259
|
+
await submitRecording("https://example.com/a.mp3");
|
|
260
|
+
expect(Object.keys(JSON.parse(String(calls[1]?.body)))).not.toContain("webhook_url");
|
|
579
261
|
});
|
|
580
262
|
});
|
|
581
263
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
expect(calls[0]?.headers).toMatchObject({
|
|
591
|
-
authorization: "sk-test",
|
|
592
|
-
"content-type": "application/json",
|
|
264
|
+
describe("checkTranscript", () => {
|
|
265
|
+
test("reports a completed job with its text and duration", async () => {
|
|
266
|
+
stubProvider({ status: "completed", text: "Hello there.", audio_duration: 254 });
|
|
267
|
+
expect(await checkTranscript("t_1")).toEqual({
|
|
268
|
+
status: "completed",
|
|
269
|
+
text: "Hello there.",
|
|
270
|
+
audioDuration: 254,
|
|
271
|
+
});
|
|
593
272
|
});
|
|
594
|
-
});
|
|
595
273
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
274
|
+
test("carries the credential and asks for JSON", async () => {
|
|
275
|
+
const calls = stubProvider({ status: "processing" });
|
|
276
|
+
await checkTranscript("t_1");
|
|
277
|
+
expect(calls[0]?.headers).toMatchObject({
|
|
278
|
+
authorization: "sk-test",
|
|
279
|
+
"content-type": "application/json",
|
|
280
|
+
});
|
|
601
281
|
});
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
test("omits absent fields rather than setting them to undefined", async () => {
|
|
605
|
-
// `exactOptionalPropertyTypes` makes those different types, and the result
|
|
606
|
-
// crosses a queue — a key set to `undefined` does not survive the trip.
|
|
607
|
-
stubProvider({ status: "processing" });
|
|
608
|
-
expect(Object.keys(await checkTranscript("t_1"))).toEqual(["status"]);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
test("refuses a status it does not recognise instead of polling forever", async () => {
|
|
612
|
-
// The loop's exit conditions are `completed` and `error`; an unknown status
|
|
613
|
-
// is neither, so it would poll to the bound and then fail with the wrong
|
|
614
|
-
// reason.
|
|
615
|
-
stubProvider({ status: "transcribing" });
|
|
616
|
-
await expect(checkTranscript("t_1")).rejects.toThrow(/unknown transcript status/);
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
test("drops a field of the wrong type rather than failing the poll", async () => {
|
|
620
|
-
// THE degradation rule, and the test that fails against a schema parsed
|
|
621
|
-
// with a throwing `parse`: the job is running and `status` says so, so a
|
|
622
|
-
// `text` the provider sent as a number is one unusable field — not a reason
|
|
623
|
-
// to end a run that has already paid for the transcription. Each optional
|
|
624
|
-
// field carries its own `.catch(undefined)` for exactly this.
|
|
625
|
-
stubProvider({ status: "processing", text: 42, error: [], audio_duration: "254" });
|
|
626
|
-
expect(await checkTranscript("t_1")).toEqual({ status: "processing" });
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
test("drops a non-finite duration, which `Math.round(x / 60)` cannot use", async () => {
|
|
630
|
-
// JSON cannot spell `Infinity`, so this arrives as a string or a null and
|
|
631
|
-
// has to be refused the same way — `z.number()` refuses both, which is the
|
|
632
|
-
// `Number.isFinite` test the hand-written reader carried.
|
|
633
|
-
stubProvider({ status: "completed", text: "Hello.", audio_duration: null });
|
|
634
|
-
expect(await checkTranscript("t_1")).toEqual({ status: "completed", text: "Hello." });
|
|
635
|
-
});
|
|
636
282
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
describe("discardTranscript — the compensation", () => {
|
|
648
|
-
beforeEach(() => {
|
|
649
|
-
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
test("deletes the transcript this run created", async () => {
|
|
653
|
-
const calls = stubProvider({ id: "t_1" });
|
|
654
|
-
await expect(discardTranscript("t_1")).resolves.toBeUndefined();
|
|
655
|
-
expect(calls[0]?.method).toBe("DELETE");
|
|
656
|
-
expect(calls[0]?.url).toContain("/t_1");
|
|
657
|
-
// The other half of `apiInit`: the method is this call site's own addition
|
|
658
|
-
// and the credential is still the shared one underneath it.
|
|
659
|
-
expect(calls[0]?.headers).toMatchObject({ authorization: "sk-test" });
|
|
660
|
-
});
|
|
283
|
+
test("carries the provider's own failure message, and omits absent fields", async () => {
|
|
284
|
+
stubProvider({ status: "error", error: "Transcoding failed" });
|
|
285
|
+
expect(await checkTranscript("t_1")).toEqual({
|
|
286
|
+
status: "error",
|
|
287
|
+
error: "Transcoding failed",
|
|
288
|
+
});
|
|
289
|
+
// A key set to `undefined` does not survive the queue.
|
|
290
|
+
stubProvider({ status: "processing" });
|
|
291
|
+
expect(Object.keys(await checkTranscript("t_1"))).toEqual(["status"]);
|
|
292
|
+
});
|
|
661
293
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
294
|
+
test("refuses a status it does not recognise instead of polling forever", async () => {
|
|
295
|
+
stubProvider({ status: "transcribing" });
|
|
296
|
+
await expect(checkTranscript("t_1")).rejects.toThrow(/unknown transcript status/);
|
|
297
|
+
// Valid JSON that is not this endpoint's object: no status to report, so
|
|
298
|
+
// the sentence says exactly that rather than throwing a second time.
|
|
299
|
+
stubProvider([{ status: "completed" }]);
|
|
300
|
+
await expect(checkTranscript("t_1")).rejects.toThrow(/unknown transcript status: undefined/);
|
|
301
|
+
});
|
|
669
302
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
303
|
+
test("drops a field of the wrong type rather than failing the poll", async () => {
|
|
304
|
+
// The job is running and `status` says so; a `text` the provider sent as
|
|
305
|
+
// a number is one unusable field, not a reason to end a run that has
|
|
306
|
+
// already paid for the transcription.
|
|
307
|
+
stubProvider({ status: "processing", text: 42, error: [], audio_duration: "254" });
|
|
308
|
+
expect(await checkTranscript("t_1")).toEqual({ status: "processing" });
|
|
309
|
+
stubProvider({ status: "completed", text: "Hello.", audio_duration: null });
|
|
310
|
+
expect(await checkTranscript("t_1")).toEqual({ status: "completed", text: "Hello." });
|
|
311
|
+
});
|
|
673
312
|
});
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
describe("summarize", () => {
|
|
677
|
-
/** A finished transcript, typed rather than cast — the shape a step really gets. */
|
|
678
|
-
function transcript(over: Partial<TranscriptState> = {}): TranscriptState {
|
|
679
|
-
return { status: "completed", text: "We talked about smoke.", audioDuration: 254, ...over };
|
|
680
|
-
}
|
|
681
313
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
314
|
+
describe("discardTranscript — the compensation", () => {
|
|
315
|
+
test("deletes the transcript this run created", async () => {
|
|
316
|
+
const calls = stubProvider({ id: "t_1" });
|
|
317
|
+
await expect(discardTranscript("t_1")).resolves.toBeUndefined();
|
|
318
|
+
expect(calls[0]?.method).toBe("DELETE");
|
|
319
|
+
expect(calls[0]?.url).toContain("/t_1");
|
|
320
|
+
expect(calls[0]?.headers).toMatchObject({ authorization: "sk-test" });
|
|
321
|
+
});
|
|
685
322
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
);
|
|
690
|
-
expect(await summarize("https://example.com/a.mp3", transcript())).toEqual({
|
|
691
|
-
url: "https://example.com/a.mp3",
|
|
692
|
-
headline: "Smoke",
|
|
693
|
-
points: ["a", "b", "c"],
|
|
694
|
-
spoken: "Smoke drifted east.",
|
|
695
|
-
// Rounded from the provider's seconds — a voice reply says "four minutes",
|
|
696
|
-
// never "254 seconds".
|
|
697
|
-
minutes: 4,
|
|
323
|
+
test("treats a 404 as success, because an undo must be safe to run twice", async () => {
|
|
324
|
+
stubProvider("", 404);
|
|
325
|
+
await expect(discardTranscript("t_1")).resolves.toBeUndefined();
|
|
698
326
|
});
|
|
699
|
-
});
|
|
700
327
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
328
|
+
test("still fails on a real error, so the engine retries it", async () => {
|
|
329
|
+
stubProvider("", 503);
|
|
330
|
+
await expect(discardTranscript("t_1")).rejects.toThrow(/HTTP 503/);
|
|
331
|
+
});
|
|
704
332
|
});
|
|
705
333
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
334
|
+
describe("summarize", () => {
|
|
335
|
+
function transcript(over: Partial<TranscriptState> = {}): TranscriptState {
|
|
336
|
+
return { status: "completed", text: "We talked about smoke.", audioDuration: 254, ...over };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
test("returns the recap the model produced, with the recording's length in minutes", async () => {
|
|
340
|
+
installStubGateway(
|
|
341
|
+
'{"headline":"Smoke","points":["a","b","c","d"],"spoken":"Smoke drifted east."}',
|
|
342
|
+
);
|
|
343
|
+
expect(await summarize("https://example.com/a.mp3", transcript())).toEqual({
|
|
344
|
+
url: "https://example.com/a.mp3",
|
|
345
|
+
headline: "Smoke",
|
|
346
|
+
// Capped by the schema: a fourth point is dropped, not refused.
|
|
347
|
+
points: ["a", "b", "c"],
|
|
348
|
+
spoken: "Smoke drifted east.",
|
|
349
|
+
minutes: 4,
|
|
350
|
+
});
|
|
351
|
+
});
|
|
715
352
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
353
|
+
test("throws PLAINLY when the model answered with prose, so the step retries", async () => {
|
|
354
|
+
// A model that ignored the format may well obey on the next attempt,
|
|
355
|
+
// where a 401 will not.
|
|
356
|
+
installStubGateway("Here is a recap of the recording.");
|
|
357
|
+
await expect(summarize("https://x/a.mp3", transcript())).rejects.toThrow(/Expected JSON/);
|
|
358
|
+
});
|
|
722
359
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
await expect(summarize("https://x/a.mp3", transcript({ text: " " }))).rejects.toThrow(
|
|
728
|
-
/no speech/,
|
|
729
|
-
);
|
|
730
|
-
});
|
|
360
|
+
test("rejects a reply missing the spoken sentence as firmly as no JSON at all", async () => {
|
|
361
|
+
installStubGateway('{"headline":"H","points":["a"]}');
|
|
362
|
+
await expect(summarize("https://x/a.mp3", transcript())).rejects.toThrow(/did not match/);
|
|
363
|
+
});
|
|
731
364
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
365
|
+
test("fails FATALLY on a transcript with no speech in it", async () => {
|
|
366
|
+
installStubGateway('{"headline":"H","points":["a"],"spoken":"S."}');
|
|
367
|
+
await expect(summarize("https://x/a.mp3", transcript({ text: " " }))).rejects.toThrow(
|
|
368
|
+
/no speech/,
|
|
369
|
+
);
|
|
370
|
+
});
|
|
737
371
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
results: {
|
|
745
|
-
submitRecording: { id: "t_1" },
|
|
746
|
-
checkTranscript: { status: "completed", text: "Done.", durationMs: 1 },
|
|
747
|
-
summarize: { headline: "H", points: [], spoken: "S." },
|
|
748
|
-
},
|
|
749
|
-
hooks: { [retentionToken("Ada")]: { keep: true } },
|
|
372
|
+
test("fails FATALLY with no API key rather than retrying", async () => {
|
|
373
|
+
vi.stubEnv("ASSEMBLYAI_API_KEY", "");
|
|
374
|
+
installStubGateway('{"headline":"H","points":["a"],"spoken":"S."}', { apiKey: false });
|
|
375
|
+
await expect(summarize("https://x/a.mp3", transcript())).rejects.toThrow(
|
|
376
|
+
/ASSEMBLYAI_API_KEY/,
|
|
377
|
+
);
|
|
750
378
|
});
|
|
751
|
-
await recapFlow({ url: "https://x/a.mp3", requestedBy: "Ada" }, ctx);
|
|
752
|
-
|
|
753
|
-
// Against the SDK's own default rather than the literal 3 this restated:
|
|
754
|
-
// what the assertion means is "more patience than an ordinary step gets",
|
|
755
|
-
// and a repo that ever retunes the default should not have to find this
|
|
756
|
-
// line to keep the sentence true.
|
|
757
|
-
const [step] = recordedSteps(ctx, "summarize");
|
|
758
|
-
expect(step?.maxAttempts).toBeGreaterThan(DEFAULT_STEP_MAX_ATTEMPTS);
|
|
759
379
|
});
|
|
760
380
|
});
|
|
761
381
|
|
|
762
382
|
// ---- The body's helpers -----------------------------------------------------
|
|
763
383
|
|
|
384
|
+
/** Every step of one name the body issued, in order. */
|
|
385
|
+
function recordedSteps(ctx: WorkflowContextRecorder, name: string) {
|
|
386
|
+
return ctx.steps.filter((step) => step.name === name);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** The run as `request_recap` starts it: keyed by the session, so the body can derive its tokens. */
|
|
390
|
+
const recapCtx = (options: Parameters<typeof createWorkflowContext>[0] = {}) =>
|
|
391
|
+
createWorkflowContext({ workflow: "recap", key: "s_1", ...options });
|
|
392
|
+
|
|
764
393
|
describe("awaitTranscript — the polling port, and the callback over it", () => {
|
|
765
394
|
beforeEach(() => {
|
|
766
395
|
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
767
396
|
});
|
|
768
397
|
|
|
769
|
-
/** A provider whose status endpoint answers `statuses` in order. */
|
|
398
|
+
/** A provider whose status endpoint answers `statuses` in order, the last repeating. */
|
|
770
399
|
function stubStatuses(statuses: readonly Record<string, unknown>[]) {
|
|
771
|
-
// Into `stepFetch`'s slot, for the reason `stubProvider` above gives.
|
|
772
400
|
const stub = installStubStepFetch(() => ({
|
|
773
401
|
body: statuses[Math.min(stub.calls.length - 1, statuses.length - 1)],
|
|
774
402
|
}));
|
|
775
403
|
return () => stub.calls.length;
|
|
776
404
|
}
|
|
777
405
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
{ status: "processing" },
|
|
782
|
-
{ status: "completed", text: "Done.", audio_duration: 60 },
|
|
783
|
-
]);
|
|
784
|
-
const state = await awaitTranscript("t_1", createWorkflowContext());
|
|
785
|
-
expect(state).toMatchObject({ status: "completed", text: "Done." });
|
|
786
|
-
expect(polls()).toBe(3);
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
test("stops on the provider's own terminal failure instead of waiting it out", async () => {
|
|
790
|
-
// `error` is terminal: polling a failed job to the bound would spend twenty
|
|
791
|
-
// minutes learning what the first answer already said.
|
|
792
|
-
const polls = stubStatuses([{ status: "error", error: "Transcoding failed" }]);
|
|
793
|
-
await expect(awaitTranscript("t_1", createWorkflowContext())).rejects.toThrow(
|
|
794
|
-
/Transcoding failed/,
|
|
795
|
-
);
|
|
796
|
-
expect(polls()).toBe(1);
|
|
797
|
-
});
|
|
798
|
-
|
|
799
|
-
test("gives up at the bound rather than polling a stuck job forever", async () => {
|
|
800
|
-
stubStatuses([{ status: "processing" }]);
|
|
801
|
-
await expect(awaitTranscript("t_1", createWorkflowContext())).rejects.toThrow(/Gave up/);
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
/** A job still `processing` for `polls` turns, then completed. */
|
|
805
|
-
function stubSlowJob(polls: number) {
|
|
806
|
-
return stubStatuses([
|
|
406
|
+
/** A job still `processing` for `polls` reads, then completed. */
|
|
407
|
+
const slowJob = (polls: number) =>
|
|
408
|
+
stubStatuses([
|
|
807
409
|
...Array.from({ length: polls }, () => ({ status: "processing" })),
|
|
808
410
|
{ status: "completed", text: "Done.", audio_duration: 60 },
|
|
809
411
|
]);
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
test("says nothing about a long one until it really has waited two minutes", async () => {
|
|
813
|
-
// The boundary this case and the next one hold together, and it is where
|
|
814
|
-
// `PATIENCE_POLLS` disagreed with its own doc. The note goes out at the TOP
|
|
815
|
-
// of a poll, so the wait it follows is the sleeps BEHIND it — attempt N is
|
|
816
|
-
// reached after N-1 of them. At a fifteen-second interval the two minutes
|
|
817
|
-
// the constant promises is eight sleeps, so the earliest honest turn to say
|
|
818
|
-
// it is the ninth. Here the job finishes on that ninth poll, two minutes in
|
|
819
|
-
// and not a second over, so the caller is told nothing.
|
|
820
|
-
const ctx = createWorkflowContext();
|
|
821
|
-
stubSlowJob(8);
|
|
822
|
-
|
|
823
|
-
await awaitTranscript("t_1", ctx);
|
|
824
412
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
expect(ctx.slept.map((one) => one.until)).toEqual(Array.from({ length: 8 }, () => 15_000));
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
test("says it ONCE past two minutes, not on every poll after", async () => {
|
|
831
|
-
// The ninth poll finds the job still going, which is the first turn that has
|
|
832
|
-
// two minutes of waiting behind it — so the note goes out, and the eleven
|
|
833
|
-
// polls after it say nothing more. A note per poll would be a caller told
|
|
834
|
-
// the same sentence every fifteen seconds.
|
|
835
|
-
const ctx = createWorkflowContext();
|
|
836
|
-
stubSlowJob(20);
|
|
413
|
+
/** The callback token the body derives for that run — read off the context, never spelled. */
|
|
414
|
+
const NUDGE = recapCtx().signalToken("transcript");
|
|
837
415
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
//
|
|
845
|
-
// Everything above drives `awaitTranscript` with no callback token, which is
|
|
846
|
-
// what a deployment that does not know its own public URL gets — and those
|
|
847
|
-
// cases are the REGRESSION guard for this section: the poll-only arm has to
|
|
848
|
-
// keep behaving exactly as it did before there was a callback at all.
|
|
849
|
-
//
|
|
850
|
-
// `createWorkflowContext` is the only tier that can drive the answered branch:
|
|
851
|
-
// its `waitFor` reads `hooks` by token, so supplying a payload IS the delivery
|
|
852
|
-
// landing and omitting one IS the window closing. The eval tier cannot —
|
|
853
|
-
// nothing there can signal — so it only ever sees the fallback, which is
|
|
854
|
-
// stated in `agent.eval.test.ts`.
|
|
855
|
-
|
|
856
|
-
/** The token both `request_recap` and the body derive for one session. */
|
|
857
|
-
const NUDGE = transcriptToken("s_1");
|
|
858
|
-
|
|
859
|
-
test("the delivery ends the wait, so a finished job costs no sleeping at all", async () => {
|
|
860
|
-
// The whole point of the conversion, in one assertion. Read once, park on
|
|
861
|
-
// the callback, read again when it lands: two requests to the provider
|
|
862
|
-
// where the poll-only arm would have made nine before it even said
|
|
863
|
-
// anything, and not one durable sleep.
|
|
864
|
-
const polls = stubStatuses([
|
|
865
|
-
{ status: "processing" },
|
|
866
|
-
{ status: "completed", text: "Done.", audio_duration: 60 },
|
|
867
|
-
]);
|
|
868
|
-
const ctx = createWorkflowContext({
|
|
869
|
-
hooks: { [NUDGE]: { transcript_id: "t_1", status: "completed" } },
|
|
870
|
-
});
|
|
416
|
+
test("parks on the callback ONCE, then polls on the cadence until the job settles", async () => {
|
|
417
|
+
// No `hooks` entry, so the timed wait resolves `undefined` — the window
|
|
418
|
+
// closing. A dropped delivery is the ordinary case a webhook has no answer
|
|
419
|
+
// for, and the run must finish anyway.
|
|
420
|
+
const polls = slowJob(2);
|
|
421
|
+
const ctx = recapCtx();
|
|
871
422
|
|
|
872
|
-
const state = await awaitTranscript("t_1",
|
|
423
|
+
const state = await awaitTranscript("t_1", NUDGE, ctx);
|
|
873
424
|
|
|
874
425
|
expect(state).toMatchObject({ status: "completed", text: "Done." });
|
|
875
|
-
expect(polls()).toBe(
|
|
876
|
-
expect(ctx.slept).toEqual([]);
|
|
877
|
-
// On the token the tool derives for the same session — the one string this
|
|
878
|
-
// template and a third party on the public internet have to agree about.
|
|
426
|
+
expect(polls()).toBe(3);
|
|
879
427
|
expect(ctx.waited).toEqual([NUDGE]);
|
|
428
|
+
expect(ctx.slept.map((one) => one.until)).toEqual([15_000, 15_000]);
|
|
880
429
|
});
|
|
881
430
|
|
|
882
431
|
test("a delivery is a NUDGE, not an answer: the run still READS the status", async () => {
|
|
883
|
-
// The security property
|
|
884
|
-
//
|
|
885
|
-
//
|
|
886
|
-
// forged delivery on a guessed token costs exactly one extra read and
|
|
887
|
-
// changes no outcome. Nothing the payload carries is ever read.
|
|
432
|
+
// The security property, and the reason an unauthenticated callback route
|
|
433
|
+
// is safe here: the payload SAYS the job completed, the provider's own
|
|
434
|
+
// endpoint says otherwise, and the provider wins.
|
|
888
435
|
const polls = stubStatuses([
|
|
889
|
-
{ status: "processing" },
|
|
890
436
|
{ status: "processing" },
|
|
891
437
|
{ status: "completed", text: "The real transcript.", audio_duration: 60 },
|
|
892
438
|
]);
|
|
893
|
-
const ctx =
|
|
439
|
+
const ctx = recapCtx({
|
|
894
440
|
hooks: { [NUDGE]: { transcript_id: "t_1", status: "completed", text: "A LIE." } },
|
|
895
441
|
});
|
|
896
442
|
|
|
897
|
-
const state = await awaitTranscript("t_1",
|
|
443
|
+
const state = await awaitTranscript("t_1", NUDGE, ctx);
|
|
898
444
|
|
|
899
445
|
expect(state).toMatchObject({ status: "completed", text: "The real transcript." });
|
|
900
|
-
|
|
901
|
-
// one after the ordinary fifteen-second wait that followed it.
|
|
902
|
-
expect(polls()).toBe(3);
|
|
903
|
-
expect(ctx.slept).toEqual([{ label: "poll", until: 15_000, correlationId: undefined }]);
|
|
904
|
-
});
|
|
905
|
-
|
|
906
|
-
test("parks ONCE and then polls, because a token cannot be claimed twice", async () => {
|
|
907
|
-
// `claimHook` refuses a second claim on a token its run still holds, and a
|
|
908
|
-
// refusal is a throw rather than a suspend — which `recapFlow`'s catch would
|
|
909
|
-
// read as a failed run and answer by deleting the transcript. So the wait
|
|
910
|
-
// may not be inside the loop, and this is what pins that: twenty turns, ONE
|
|
911
|
-
// `waitFor`, and every other wait a plain sleep.
|
|
912
|
-
const ctx = createWorkflowContext({ hooks: { [NUDGE]: {} } });
|
|
913
|
-
stubSlowJob(20);
|
|
914
|
-
|
|
915
|
-
await awaitTranscript("t_1", ctx, NUDGE);
|
|
916
|
-
|
|
917
|
-
expect(ctx.waited).toHaveLength(1);
|
|
918
|
-
expect(ctx.slept).toHaveLength(19);
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
test("an unanswered window falls back to the poll rather than hanging", async () => {
|
|
922
|
-
// No `hooks` entry, so the timed wait resolves `undefined` — which IS the
|
|
923
|
-
// window closing. The run must finish anyway: a dropped delivery is the
|
|
924
|
-
// ordinary case a webhook has no answer for, and a template that waited
|
|
925
|
-
// forever on one would be strictly worse than the loop it replaced.
|
|
926
|
-
const polls = stubStatuses([
|
|
927
|
-
{ status: "processing" },
|
|
928
|
-
{ status: "processing" },
|
|
929
|
-
{ status: "completed", text: "Done.", audio_duration: 60 },
|
|
930
|
-
]);
|
|
931
|
-
const ctx = createWorkflowContext();
|
|
932
|
-
|
|
933
|
-
const state = await awaitTranscript("t_1", ctx, NUDGE);
|
|
934
|
-
|
|
935
|
-
expect(state).toMatchObject({ status: "completed", text: "Done." });
|
|
936
|
-
expect(polls()).toBe(3);
|
|
937
|
-
// It asked, and then it stopped counting on the answer.
|
|
446
|
+
expect(polls()).toBe(2);
|
|
938
447
|
expect(ctx.waited).toEqual([NUDGE]);
|
|
939
|
-
expect(ctx.slept).toEqual([{ label: "poll", until: 15_000, correlationId: undefined }]);
|
|
940
448
|
});
|
|
941
449
|
|
|
942
|
-
test("
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
stubSlowJob(20);
|
|
949
|
-
|
|
950
|
-
await awaitTranscript("t_1", ctx, NUDGE);
|
|
951
|
-
|
|
952
|
-
const notes = recordedSteps(ctx, "noteSlow");
|
|
953
|
-
expect(notes).toHaveLength(1);
|
|
954
|
-
// Attempt 2, which is one `checkTranscript` and one closed window in.
|
|
955
|
-
expect(ctx.steps.slice(0, 3).map((entry) => entry.name)).toEqual([
|
|
956
|
-
"checkTranscript",
|
|
957
|
-
"checkTranscript",
|
|
958
|
-
"noteSlow",
|
|
959
|
-
]);
|
|
450
|
+
test("stops on the provider's own terminal failure instead of waiting it out", async () => {
|
|
451
|
+
const polls = stubStatuses([{ status: "error", error: "Transcoding failed" }]);
|
|
452
|
+
await expect(awaitTranscript("t_1", NUDGE, createWorkflowContext())).rejects.toThrow(
|
|
453
|
+
/Transcoding failed/,
|
|
454
|
+
);
|
|
455
|
+
expect(polls()).toBe(1);
|
|
960
456
|
});
|
|
961
457
|
|
|
962
|
-
test("
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
const ctx = createWorkflowContext({ hooks: { [NUDGE]: {} } });
|
|
967
|
-
stubSlowJob(1);
|
|
458
|
+
test("gives up at the bound rather than polling a stuck job forever", async () => {
|
|
459
|
+
stubStatuses([{ status: "processing" }]);
|
|
460
|
+
await expect(awaitTranscript("t_1", NUDGE, createWorkflowContext())).rejects.toThrow(/Gave up/);
|
|
461
|
+
});
|
|
968
462
|
|
|
969
|
-
|
|
463
|
+
test("says 'still transcribing' ONCE past two minutes, and not for a job that finishes sooner", async () => {
|
|
464
|
+
// A note per poll would be a caller told the same sentence every fifteen
|
|
465
|
+
// seconds; a note for every job would be a desk calling a four-minute
|
|
466
|
+
// recording a long one.
|
|
467
|
+
const slow = createWorkflowContext();
|
|
468
|
+
slowJob(20);
|
|
469
|
+
await awaitTranscript("t_1", NUDGE, slow);
|
|
470
|
+
expect(recordedSteps(slow, "checkTranscript:slow")).toHaveLength(1);
|
|
970
471
|
|
|
971
|
-
|
|
472
|
+
const quick = createWorkflowContext();
|
|
473
|
+
slowJob(3);
|
|
474
|
+
await awaitTranscript("t_1", NUDGE, quick);
|
|
475
|
+
expect(recordedSteps(quick, "checkTranscript:slow")).toEqual([]);
|
|
972
476
|
});
|
|
973
477
|
});
|
|
974
478
|
|
|
@@ -977,27 +481,16 @@ describe("askWhetherToKeep — the expense port", () => {
|
|
|
977
481
|
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
978
482
|
});
|
|
979
483
|
|
|
980
|
-
/**
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
* This block used to be forty lines of DevKit scaffolding: `vi.mock("workflow")`
|
|
984
|
-
* over `createHook` and `sleep`, plus a hand-built `Hook` assembled by hanging
|
|
985
|
-
* members on a real promise, plus a never-resolving `sleep` so the two sides of
|
|
986
|
-
* a `Promise.race` could not settle in an order that decided the test instead
|
|
987
|
-
* of the branch. The gate is ONE call now — `ctx.waitFor(token, { timeoutMs })`
|
|
988
|
-
* — so an answer is a `hooks` entry and the no-answer branch is its absence.
|
|
989
|
-
* What is pinned is unchanged: the three outcomes and the safe default.
|
|
990
|
-
*/
|
|
484
|
+
/** The run's own retention token, derived the way the body derives it. */
|
|
485
|
+
const RETENTION = recapCtx().signalToken("retention");
|
|
486
|
+
/** The gate, driven with or without an answer: a `hooks` entry, or its absence. */
|
|
991
487
|
const gateCtx = (answer?: { keep: boolean }) =>
|
|
992
|
-
|
|
993
|
-
answer === undefined ? {} : { hooks: { [retentionToken("s_1")]: answer } },
|
|
994
|
-
);
|
|
488
|
+
recapCtx(answer === undefined ? {} : { hooks: { [RETENTION]: answer } });
|
|
995
489
|
|
|
996
490
|
test("keeps the transcript when the caller says to, and deletes nothing", async () => {
|
|
997
491
|
const provider = installStubStepFetch();
|
|
998
|
-
|
|
999
492
|
const compensations = [{ label: "transcript t_1", undo: async () => undefined }];
|
|
1000
|
-
expect(await askWhetherToKeep("
|
|
493
|
+
expect(await askWhetherToKeep("t_1", compensations, gateCtx({ keep: true }))).toEqual({
|
|
1001
494
|
kept: true,
|
|
1002
495
|
answered: true,
|
|
1003
496
|
});
|
|
@@ -1008,26 +501,18 @@ describe("askWhetherToKeep — the expense port", () => {
|
|
|
1008
501
|
|
|
1009
502
|
test("deletes on a DECLINE, and drops the undo it just performed", async () => {
|
|
1010
503
|
const calls = stubProvider({ id: "t_1" });
|
|
1011
|
-
|
|
1012
504
|
const compensations = [{ label: "transcript t_1", undo: async () => undefined }];
|
|
1013
|
-
expect(await askWhetherToKeep("
|
|
505
|
+
expect(await askWhetherToKeep("t_1", compensations, gateCtx({ keep: false }))).toEqual({
|
|
1014
506
|
kept: false,
|
|
1015
507
|
answered: true,
|
|
1016
508
|
});
|
|
1017
509
|
expect(calls[0]?.method).toBe("DELETE");
|
|
1018
|
-
// Leaving it would be harmless — the undo tolerates a 404 — and would still
|
|
1019
|
-
// narrate an unwind that reverses something already gone.
|
|
1020
510
|
expect(compensations).toHaveLength(0);
|
|
1021
511
|
});
|
|
1022
512
|
|
|
1023
513
|
test("DELETES when nobody answers, which is what makes the window mean anything", async () => {
|
|
1024
|
-
// The safe default, and the whole reason the gate is a gate: a no-answer
|
|
1025
|
-
// branch that kept the data would be a prompt with a grace period. No
|
|
1026
|
-
// `hooks` entry is exactly the closed-window case, because the wait carries a
|
|
1027
|
-
// `timeoutMs` and so has an unanswered branch to take.
|
|
1028
514
|
const calls = stubProvider({ id: "t_1" });
|
|
1029
|
-
|
|
1030
|
-
expect(await askWhetherToKeep("s_1", "t_1", [], gateCtx())).toEqual({
|
|
515
|
+
expect(await askWhetherToKeep("t_1", [], gateCtx())).toEqual({
|
|
1031
516
|
kept: false,
|
|
1032
517
|
answered: false,
|
|
1033
518
|
});
|
|
@@ -1035,27 +520,16 @@ describe("askWhetherToKeep — the expense port", () => {
|
|
|
1035
520
|
});
|
|
1036
521
|
|
|
1037
522
|
test("asks BEFORE it waits, so the caller knows what they are answering", async () => {
|
|
1038
|
-
// The ordering that replaced `createHook`'s claim-then-ask dance. Under the
|
|
1039
|
-
// DevKit the hook registered nothing until the workflow suspended, so an
|
|
1040
|
-
// answer sent before the claim landed was told "nobody is listening" —
|
|
1041
|
-
// indistinguishable from being late — and the body had to call
|
|
1042
|
-
// `getConflict()` first to force it. `ctx.waitFor` registers the token as
|
|
1043
|
-
// part of waiting, by construction, so what is left to assert is the thing
|
|
1044
|
-
// that still matters to a person: the note goes out first.
|
|
1045
523
|
const ctx = gateCtx({ keep: true });
|
|
1046
524
|
installStubStepFetch();
|
|
1047
|
-
|
|
1048
|
-
await askWhetherToKeep("s_1", "t_1", [], ctx);
|
|
1049
|
-
|
|
525
|
+
await askWhetherToKeep("t_1", [], ctx);
|
|
1050
526
|
expect(ctx.steps[0]?.name).toBe("noteGate");
|
|
1051
|
-
expect(ctx.waited).toEqual([
|
|
527
|
+
expect(ctx.waited).toEqual([RETENTION]);
|
|
1052
528
|
});
|
|
1053
529
|
});
|
|
1054
530
|
|
|
1055
531
|
describe("compensate — the saga port", () => {
|
|
1056
532
|
test("unwinds newest-first, which is the order acquisitions were stacked in", async () => {
|
|
1057
|
-
// `recapFlow` pushes with `unshift`, so the list is already newest-first and
|
|
1058
|
-
// this walks it forwards. A dependency acquired later has to come off first.
|
|
1059
533
|
const order: string[] = [];
|
|
1060
534
|
await compensate(
|
|
1061
535
|
[
|
|
@@ -1070,82 +544,58 @@ describe("compensate — the saga port", () => {
|
|
|
1070
544
|
|
|
1071
545
|
test("a failing undo does not stop the ones behind it", async () => {
|
|
1072
546
|
// Ported deliberately from Temporal's `compensate`, which swallows: the run
|
|
1073
|
-
// already failed for a reason the caller needs
|
|
1074
|
-
// failure must not replace it or strand the rest of the stack.
|
|
547
|
+
// already failed for a reason the caller needs.
|
|
1075
548
|
const order: string[] = [];
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
},
|
|
549
|
+
const ctx = createWorkflowContext();
|
|
550
|
+
await compensate(
|
|
551
|
+
[
|
|
552
|
+
{
|
|
553
|
+
label: "broken",
|
|
554
|
+
undo: async () => {
|
|
555
|
+
throw new Error("the provider declined the delete");
|
|
1084
556
|
},
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
)
|
|
557
|
+
},
|
|
558
|
+
{ label: "fine", undo: async () => void order.push("fine") },
|
|
559
|
+
],
|
|
560
|
+
"because",
|
|
561
|
+
ctx,
|
|
562
|
+
);
|
|
1091
563
|
expect(order).toEqual(["fine"]);
|
|
564
|
+
expect(ctx.steps.map((step) => step.name)).toEqual(["noteUnwind", "noteUndoFailed"]);
|
|
1092
565
|
});
|
|
1093
566
|
|
|
1094
567
|
test("does nothing at all when nothing was acquired", async () => {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
await expect(
|
|
1099
|
-
compensate([], "nothing was acquired", createWorkflowContext()),
|
|
1100
|
-
).resolves.toBeUndefined();
|
|
568
|
+
const ctx = createWorkflowContext();
|
|
569
|
+
await compensate([], "nothing was acquired", ctx);
|
|
570
|
+
expect(ctx.steps).toEqual([]);
|
|
1101
571
|
});
|
|
1102
572
|
});
|
|
1103
573
|
|
|
1104
574
|
/**
|
|
1105
|
-
* `recapFlow` itself, on the real replay engine
|
|
1106
|
-
*
|
|
1107
|
-
* `runWorkflow` starts the declared workflow on `createInProcessWorkflowEngine`
|
|
1108
|
-
* over an in-memory journal and drives one delivery at a time, with a suspension
|
|
1109
|
-
* RECORDED rather than waited out. So the poll cadence a deployed run spends
|
|
1110
|
-
* fifteen seconds a turn on costs this file nothing, and the run really parks,
|
|
1111
|
-
* really resumes off its journal, and really closes its window.
|
|
1112
|
-
*
|
|
1113
|
-
* Two of this desk's claims are only reachable here, and both are expensive when
|
|
1114
|
-
* wrong:
|
|
1115
|
-
*
|
|
1116
|
-
* - **A resume does not re-transcribe.** Twenty minutes of provider time is
|
|
1117
|
-
* already paid for, which is why `summarize` is its own step; nothing below
|
|
1118
|
-
* this tier can show that a second walk did not submit the recording again.
|
|
1119
|
-
* - **The retention gate's unanswered window DELETES.** "A gate whose no-answer
|
|
1120
|
-
* branch keeps the data is not a gate", and for a desk holding transcripts of
|
|
1121
|
-
* other people's meetings the default is what the whole pattern is about.
|
|
1122
|
-
* `ctx.workflows.wakeUp` deliberately cannot end an approval window — that is
|
|
1123
|
-
* `SleepRecord.kind`'s entire reason — so `expireWaits()` is the only thing
|
|
1124
|
-
* that reaches the branch.
|
|
575
|
+
* `recapFlow` itself, on the real replay engine: the run really parks, really
|
|
576
|
+
* resumes off its journal, and really closes its windows.
|
|
1125
577
|
*
|
|
1126
|
-
*
|
|
1127
|
-
*
|
|
1128
|
-
*
|
|
1129
|
-
*
|
|
578
|
+
* A spec publishes no webhook minter, so the submit carries no `webhook_url` —
|
|
579
|
+
* and the poll still parks on the callback window FIRST, which is the arm a
|
|
580
|
+
* deployment with no public URL takes. Here the window is ended the way the
|
|
581
|
+
* provider ends it, with a delivery on the callback label (`run.signalRun`);
|
|
582
|
+
* `expireWaits()` is kept for the retention gate's unanswered branch, which
|
|
583
|
+
* nothing public can reach — that is `SleepRecord.kind`'s entire reason.
|
|
1130
584
|
*/
|
|
1131
585
|
describe("the run is DURABLE", () => {
|
|
1132
|
-
const
|
|
1133
|
-
const INPUT = { url: URL, requestedBy: "sess_1" };
|
|
586
|
+
const INPUT = { url: "https://example.com/standup.mp3", requestedBy: "sess_1" };
|
|
1134
587
|
const RECAP = '{"headline":"Standup","points":["a","b"],"spoken":"They shipped it."}';
|
|
588
|
+
const PROCESSING = { id: "t_1", status: "processing" };
|
|
589
|
+
const DONE = { id: "t_1", status: "completed", text: "We shipped it.", audio_duration: 600 };
|
|
590
|
+
/** What AssemblyAI posts to the callback URL: an edge, never an answer. */
|
|
591
|
+
const NUDGE = { transcript_id: "t_1", status: "completed" };
|
|
1135
592
|
|
|
1136
593
|
/**
|
|
1137
|
-
* The provider and the model, behind ONE published `stepFetch`.
|
|
1138
|
-
*
|
|
1139
|
-
* Every step's HTTP goes through the slot, the model call included, so a
|
|
1140
|
-
* gateway stub installed over `globalThis.fetch` beside a provider stub would
|
|
1141
|
-
* be bypassed — `link-digest-workflow/agent.test.ts` carries the same note.
|
|
1142
|
-
* `stubGatewayRoute` is the composition for it.
|
|
1143
|
-
*
|
|
1144
|
-
* `transcript` is a list of successive `GET` answers, so a spec says how many
|
|
1145
|
-
* polls the job takes by how many entries it gives.
|
|
594
|
+
* The provider and the model, behind ONE published `stepFetch`. `transcript`
|
|
595
|
+
* is a list of successive `GET` answers, the last repeating.
|
|
1146
596
|
*/
|
|
1147
|
-
function stubWorld(transcript: readonly Record<string, unknown>[]) {
|
|
1148
|
-
const model = stubGatewayRoute(
|
|
597
|
+
function stubWorld(transcript: readonly Record<string, unknown>[], recapReply = RECAP) {
|
|
598
|
+
const model = stubGatewayRoute(recapReply);
|
|
1149
599
|
const deletes: string[] = [];
|
|
1150
600
|
let polls = 0;
|
|
1151
601
|
const provider = installStubStepFetch((request) => {
|
|
@@ -1156,245 +606,139 @@ describe("the run is DURABLE", () => {
|
|
|
1156
606
|
return { status: 200, body: {} };
|
|
1157
607
|
}
|
|
1158
608
|
if (request.method === "POST") return { status: 200, body: { id: "t_1", status: "queued" } };
|
|
1159
|
-
// The last answer repeats, so a spec that wants one more poll than it
|
|
1160
|
-
// scripted gets the terminal state rather than an index error.
|
|
1161
609
|
const at = Math.min(polls++, transcript.length - 1);
|
|
1162
610
|
return { status: 200, body: transcript[at] ?? {} };
|
|
1163
611
|
});
|
|
1164
|
-
return { model, deletes, provider
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
const PROCESSING = { id: "t_1", status: "processing" };
|
|
1168
|
-
const DONE = {
|
|
1169
|
-
id: "t_1",
|
|
1170
|
-
status: "completed",
|
|
1171
|
-
text: "We shipped it.",
|
|
1172
|
-
audio_duration: 600,
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* One run of this desk's declaration, on the real engine, under the name the
|
|
1177
|
-
* agent registers it by.
|
|
1178
|
-
*
|
|
1179
|
-
* Six tests started it with the same three arguments, and the `name` is the
|
|
1180
|
-
* one that has to be right: it is what `ctx.workflow` reads and what a run
|
|
1181
|
-
* record carries, so a spec that let it default would be driving a workflow
|
|
1182
|
-
* called `workflow`. `WorkflowTestHandle` is what comes back — the run PLUS
|
|
1183
|
-
* the four things only a test may do to it (advance a sleep, signal, expire a
|
|
1184
|
-
* window, restart a dead worker) — and naming it is what lets the crash case
|
|
1185
|
-
* below hand one to a helper.
|
|
1186
|
-
*/
|
|
1187
|
-
function startRecap(
|
|
1188
|
-
options: RunWorkflowOptions = {},
|
|
1189
|
-
): Promise<WorkflowTestHandle<WorkflowOutputOf<typeof recap>>> {
|
|
1190
|
-
return runWorkflow(recap, INPUT, { name: "recap", ...options });
|
|
612
|
+
return { model, deletes, provider };
|
|
1191
613
|
}
|
|
1192
614
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
* reached it.
|
|
1196
|
-
*
|
|
1197
|
-
* `WorkflowTestRun` rather than the handle, deliberately: what these
|
|
1198
|
-
* assertions read is the RUN's journaled shape, and taking the narrower type
|
|
1199
|
-
* says a reader cannot restart anything from in here. `WorkflowTestStep`
|
|
1200
|
-
* carries `attempts`, which is the field the crash case is about.
|
|
1201
|
-
*/
|
|
1202
|
-
function journaledStep(
|
|
615
|
+
const stepKeys = (run: WorkflowTestRun<unknown>) => run.steps.map((step) => step.key);
|
|
616
|
+
const journaledStep = (
|
|
1203
617
|
run: WorkflowTestRun<unknown>,
|
|
1204
618
|
name: string,
|
|
1205
|
-
): WorkflowTestStep | undefined
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
619
|
+
): WorkflowTestStep | undefined => run.steps.find((step) => step.name === name);
|
|
620
|
+
const parkKinds = (waits: readonly WorkflowTestWait[]) => waits.map((wait) => wait.kind);
|
|
621
|
+
|
|
622
|
+
/** The run as the tool starts it: keyed by the session, which its tokens derive from. */
|
|
623
|
+
const KEY = "sess_1";
|
|
624
|
+
|
|
625
|
+
/** Through the callback and the one poll, to the gate. */
|
|
626
|
+
async function toTheGate() {
|
|
627
|
+
const run = await runWorkflow(agentDef, "recap", INPUT, { key: KEY });
|
|
628
|
+
await run.signalRun("transcript", NUDGE); // the provider calls back
|
|
629
|
+
await run.advanceSleep(); // the poll cadence
|
|
630
|
+
return run;
|
|
1212
631
|
}
|
|
1213
632
|
|
|
1214
633
|
beforeEach(() => {
|
|
1215
634
|
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
1216
635
|
});
|
|
1217
636
|
|
|
1218
|
-
test("submits once, then parks on the
|
|
637
|
+
test("submits once, then parks on the callback window before any read", async () => {
|
|
1219
638
|
stubWorld([PROCESSING, DONE]);
|
|
1220
|
-
const
|
|
1221
|
-
const run = await startRecap();
|
|
639
|
+
const run = await runWorkflow(agentDef, "recap", INPUT, { key: KEY });
|
|
1222
640
|
|
|
1223
641
|
expect(run.status).toBe("running");
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
expect(run.wakeAt).toBeGreaterThan(started);
|
|
1227
|
-
expect(run.steps.map((step) => step.key)).toEqual(["checkTranscript#0", "submitRecording#0"]);
|
|
642
|
+
expect(stepKeys(run)).toEqual(["submitRecording#0"]);
|
|
643
|
+
expect(parkKinds(run.waits)).toEqual(["hookTimeout"]);
|
|
1228
644
|
});
|
|
1229
645
|
|
|
1230
|
-
test("resumes past the poll WITHOUT re-submitting the recording", async () => {
|
|
1231
|
-
//
|
|
1232
|
-
//
|
|
646
|
+
test("resumes past the callback and the poll WITHOUT re-submitting the recording", async () => {
|
|
647
|
+
// Twenty minutes of provider time is already paid for, and a resume must
|
|
648
|
+
// not spend it again.
|
|
1233
649
|
const world = stubWorld([PROCESSING, DONE]);
|
|
1234
|
-
const run = await
|
|
1235
|
-
await run.advanceSleep();
|
|
650
|
+
const run = await toTheGate();
|
|
1236
651
|
|
|
1237
652
|
// Parked again, now on the retention gate — a hook with a deadline.
|
|
1238
653
|
expect(run.status).toBe("running");
|
|
1239
|
-
expect(run
|
|
654
|
+
expect(stepKeys(run)).toEqual([
|
|
1240
655
|
"checkTranscript#0",
|
|
1241
656
|
"checkTranscript#1",
|
|
1242
657
|
"noteGate#0",
|
|
1243
658
|
"submitRecording#0",
|
|
1244
659
|
"summarize#0",
|
|
1245
660
|
]);
|
|
1246
|
-
expect(run.deliveries).toBe(
|
|
1247
|
-
// ONE submit across
|
|
1248
|
-
// journal on the second — and one model call.
|
|
661
|
+
expect(run.deliveries).toBe(3);
|
|
662
|
+
// ONE submit across three walks, and one model call.
|
|
1249
663
|
expect(
|
|
1250
664
|
world.provider.calls.filter((call) => call.method === "POST" && !call.url.includes("chat")),
|
|
1251
665
|
).toHaveLength(1);
|
|
1252
666
|
expect(world.model.calls).toHaveLength(1);
|
|
667
|
+
// Two windows and a sleep, read off the journal the run really lives in:
|
|
668
|
+
// `wakeUp` reaches only the sleep, which is why "send it now" can never
|
|
669
|
+
// answer an approval window.
|
|
670
|
+
expect(parkKinds(run.waits).toSorted()).toEqual(["hookTimeout", "hookTimeout", "sleep"]);
|
|
1253
671
|
});
|
|
1254
672
|
|
|
1255
673
|
test("an answer of KEEP leaves the transcript on the account", async () => {
|
|
1256
|
-
const world = stubWorld([DONE]);
|
|
1257
|
-
const run = await
|
|
1258
|
-
await run.
|
|
674
|
+
const world = stubWorld([PROCESSING, DONE]);
|
|
675
|
+
const run = await toTheGate();
|
|
676
|
+
await run.signalRun("retention", { keep: true });
|
|
1259
677
|
|
|
1260
678
|
expect(run.status).toBe("completed");
|
|
1261
679
|
expect(run.output).toMatchObject({ kept: true, answered: true, requestedBy: "sess_1" });
|
|
1262
|
-
// No discard step reached at all, and nothing deleted.
|
|
1263
680
|
expect(journaledStep(run, "discardOnDecline")).toBeUndefined();
|
|
1264
681
|
expect(world.deletes).toEqual([]);
|
|
1265
682
|
});
|
|
1266
683
|
|
|
1267
684
|
test("an UNANSWERED window deletes, which is the safe default the gate exists for", async () => {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
// only public route to this outcome is to wait out two real minutes.
|
|
1271
|
-
const world = stubWorld([DONE]);
|
|
1272
|
-
const run = await startRecap();
|
|
1273
|
-
expect(run.status).toBe("running");
|
|
1274
|
-
|
|
685
|
+
const world = stubWorld([PROCESSING, DONE]);
|
|
686
|
+
const run = await toTheGate();
|
|
1275
687
|
await run.expireWaits();
|
|
688
|
+
|
|
1276
689
|
expect(run.status).toBe("completed");
|
|
1277
690
|
// `answered: false` is the distinction the type carries: the caller did not
|
|
1278
691
|
// decline, they said nothing, and the desk deleted anyway.
|
|
1279
692
|
expect(run.output).toMatchObject({ kept: false, answered: false });
|
|
1280
693
|
expect(journaledStep(run, "discardOnDecline")).toBeDefined();
|
|
1281
|
-
expect(world.deletes).
|
|
1282
|
-
expect(world.deletes[0]).toContain("t_1");
|
|
1283
|
-
});
|
|
1284
|
-
|
|
1285
|
-
test("journals the gate as a hook DEADLINE and the poll as a sleep", async () => {
|
|
1286
|
-
// The distinction the whole retention pattern rests on, read off the
|
|
1287
|
-
// journal rather than inferred from behaviour. A run parks twice for two
|
|
1288
|
-
// different reasons, and `WorkflowTestWait.kind` is what keeps them apart:
|
|
1289
|
-
// `wakeUp` (with no correlation ids) reaches only `sleep`, which is why
|
|
1290
|
-
// `expireWaits` exists at all and why "send it now" cannot be made to
|
|
1291
|
-
// answer an approval window it was never told the answer to.
|
|
1292
|
-
stubWorld([PROCESSING, DONE]);
|
|
1293
|
-
const run = await startRecap();
|
|
1294
|
-
await run.advanceSleep();
|
|
1295
|
-
|
|
1296
|
-
// `waits` is read off the journal the run really lives in, so this is the
|
|
1297
|
-
// durable record and not the driver's view of it. One of each, without a
|
|
1298
|
-
// claim about the order: the list is by KEY rather than by when the run
|
|
1299
|
-
// reached each park.
|
|
1300
|
-
const kinds = parkKinds(run.waits);
|
|
1301
|
-
expect(kinds).toHaveLength(2);
|
|
1302
|
-
expect(kinds).toContain("sleep");
|
|
1303
|
-
expect(kinds).toContain("hookTimeout");
|
|
1304
|
-
|
|
1305
|
-
// And the proof it matters: another `wakeUp` finds nothing to wake, so the
|
|
1306
|
-
// gate is still open and the run is still waiting on a person.
|
|
1307
|
-
await run.advanceSleep();
|
|
1308
|
-
expect(run.status).toBe("running");
|
|
1309
|
-
});
|
|
1310
|
-
|
|
1311
|
-
test("a signal that arrives after the window closed cannot reopen it", async () => {
|
|
1312
|
-
// `closeHook` is a compare-and-set, so the walk that timed out and every
|
|
1313
|
-
// later replay read the same branch — the divergence `HookRecord.closed`
|
|
1314
|
-
// exists to prevent.
|
|
1315
|
-
stubWorld([DONE]);
|
|
1316
|
-
const run = await startRecap();
|
|
1317
|
-
await run.expireWaits();
|
|
1318
|
-
expect(run.output).toMatchObject({ kept: false });
|
|
694
|
+
expect(world.deletes).toEqual(["https://api.assemblyai.com/v2/transcript/t_1"]);
|
|
1319
695
|
|
|
1320
|
-
|
|
696
|
+
// And a signal that arrives after the window closed cannot reopen it.
|
|
697
|
+
await run.signalRun("retention", { keep: true });
|
|
1321
698
|
expect(run.signalled).toBe(false);
|
|
1322
699
|
expect(run.output).toMatchObject({ kept: false });
|
|
1323
700
|
});
|
|
1324
701
|
|
|
1325
|
-
/**
|
|
1326
|
-
* A world where the model never produces JSON, so `summarize` exhausts its
|
|
1327
|
-
* attempts and the body's `catch` unwinds the compensation stack.
|
|
1328
|
-
*
|
|
1329
|
-
* The `deletes` list is what the unwind is measured by — every `DELETE` the
|
|
1330
|
-
* provider was really sent.
|
|
1331
|
-
*/
|
|
1332
|
-
function stubDoomedWorld(): { deletes: string[] } {
|
|
1333
|
-
const model = stubGatewayRoute("Here is a recap, in prose, as you did not ask.");
|
|
1334
|
-
const deletes: string[] = [];
|
|
1335
|
-
installStubStepFetch((request) => {
|
|
1336
|
-
const routed = model.route(request);
|
|
1337
|
-
if (routed) return routed;
|
|
1338
|
-
if (request.method === "DELETE") {
|
|
1339
|
-
deletes.push(request.url);
|
|
1340
|
-
return { status: 200, body: {} };
|
|
1341
|
-
}
|
|
1342
|
-
if (request.method === "POST") return { status: 200, body: { id: "t_1", status: "queued" } };
|
|
1343
|
-
return { status: 200, body: DONE };
|
|
1344
|
-
});
|
|
1345
|
-
return { deletes };
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
702
|
test("a failure after the transcript exists UNWINDS it, and the run still fails", async () => {
|
|
1349
703
|
// The saga. `summarize` is given prose instead of JSON on every attempt, so
|
|
1350
704
|
// the step exhausts its patience and the body's catch runs the compensation
|
|
1351
705
|
// stack — which must delete the transcript the run acquired.
|
|
1352
|
-
const
|
|
706
|
+
const world = stubWorld([DONE], "Here is a recap, in prose, as you did not ask.");
|
|
707
|
+
const run = await runWorkflow(agentDef, "recap", INPUT, { key: KEY });
|
|
708
|
+
await run.signalRun("transcript", NUDGE);
|
|
1353
709
|
|
|
1354
|
-
const run = await startRecap();
|
|
1355
710
|
expect(run.status).toBe("failed");
|
|
1356
711
|
expect(run.error).toMatch(/JSON/i);
|
|
1357
|
-
// The undo ran, as a STEP — which is what makes a crash during the unwind
|
|
1358
|
-
// resume with the finished ones replayed rather than run twice.
|
|
1359
712
|
expect(journaledStep(run, "discardTranscript")).toBeDefined();
|
|
1360
|
-
expect(deletes).toHaveLength(1);
|
|
713
|
+
expect(world.deletes).toHaveLength(1);
|
|
1361
714
|
});
|
|
1362
715
|
|
|
1363
716
|
test("a worker that dies MID-UNWIND resumes it rather than starting it over", async () => {
|
|
1364
|
-
// The saga's headline claim
|
|
1365
|
-
//
|
|
1366
|
-
//
|
|
1367
|
-
//
|
|
1368
|
-
//
|
|
1369
|
-
//
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
const { deletes } = stubDoomedWorld();
|
|
1377
|
-
const run = await startRecap({ crashAt: "discardTranscript" });
|
|
717
|
+
// The saga's headline claim: a crash part-way through the unwind resumes
|
|
718
|
+
// with the already-run compensations replayed from the journal and
|
|
719
|
+
// re-issues only what is left — the property a `finally` cannot have.
|
|
720
|
+
// `crashAt` kills the delivery that reaches `discardTranscript` AFTER the
|
|
721
|
+
// attempt has been charged and before the body runs, which is where a real
|
|
722
|
+
// death lands.
|
|
723
|
+
const world = stubWorld([DONE], "Here is a recap, in prose, as you did not ask.");
|
|
724
|
+
const run = await runWorkflow(agentDef, "recap", INPUT, {
|
|
725
|
+
key: KEY,
|
|
726
|
+
crashAt: "discardTranscript",
|
|
727
|
+
});
|
|
728
|
+
await run.signalRun("transcript", NUDGE);
|
|
1378
729
|
|
|
1379
730
|
expect(run.crashed).toBe(true);
|
|
1380
|
-
// The transcript is still on the account:
|
|
1381
|
-
|
|
1382
|
-
expect(deletes).toEqual([]);
|
|
731
|
+
// The transcript is still on the account: announced and never performed.
|
|
732
|
+
expect(world.deletes).toEqual([]);
|
|
1383
733
|
|
|
1384
734
|
await run.restart();
|
|
1385
735
|
|
|
1386
736
|
expect(run.status).toBe("failed");
|
|
1387
|
-
// Deleted ONCE, by the resumed unwind rather than by a second one
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
// reading progress is not told the desk is undoing two steps.
|
|
737
|
+
// Deleted ONCE, by the resumed unwind rather than by a second one, with
|
|
738
|
+
// the narration out of the journal on the second walk.
|
|
739
|
+
expect(world.deletes).toHaveLength(1);
|
|
1391
740
|
expect(journaledStep(run, "noteUnwind")?.attempts).toBe(1);
|
|
1392
|
-
|
|
1393
|
-
// resume tells an abandoned attempt from one that never started.
|
|
1394
|
-
// ONE of each: no second `noteUnwind#1` and no second `discardTranscript#1`
|
|
1395
|
-
// from an unwind that started over. That is the whole difference between a
|
|
1396
|
-
// compensation stack of STEPS and a `finally`.
|
|
1397
|
-
expect(run.steps.map((step) => step.key)).toEqual([
|
|
741
|
+
expect(stepKeys(run)).toEqual([
|
|
1398
742
|
"checkTranscript#0",
|
|
1399
743
|
"discardTranscript#0",
|
|
1400
744
|
"noteUnwind#0",
|