@alexkroman1/aai-cli 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-B4ZiXbZj.mjs → _dev-server-C_zidzWj.mjs} +17 -12
- 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-Bp1kSqz_.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-CxZsZsOL.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 +46 -33
- 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/custom-pipeline-agent/stages.test.ts +4 -8
- 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 -125
- 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 +50 -18
- 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 -1073
- 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 +94 -63
- 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 +133 -471
- 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 +21 -32
- 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 -74
- 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
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - **The API** — auth, validation, and that a call is one run keyed by its
|
|
8
8
|
* id, against a stubbed `ctx.workflows`.
|
|
9
|
-
* - **The brief** — that a
|
|
10
|
-
*
|
|
11
|
-
* - **The session** —
|
|
12
|
-
*
|
|
9
|
+
* - **The brief** — that a session whose parameters this app did not sign is
|
|
10
|
+
* refused before it starts, and a signed one gets its task.
|
|
11
|
+
* - **The session** — `press_keys`, `end_call`, and the hand-over of the
|
|
12
|
+
* transcript to the run as the session ends.
|
|
13
13
|
* - **The run, durably** — `callFlow` on the real replay engine
|
|
14
14
|
* (`runWorkflow`) against a stubbed Twilio and model: it suspends while the
|
|
15
15
|
* phone rings and while the call is talked, resumes on the session's signal
|
|
@@ -17,9 +17,17 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import agentDef from "virtual:aai/agent";
|
|
20
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
type RouteRequest,
|
|
22
|
+
readCallBrief,
|
|
23
|
+
type SessionCall,
|
|
24
|
+
type SessionEndContext,
|
|
25
|
+
sessionCall,
|
|
26
|
+
signCallBrief,
|
|
27
|
+
} from "@alexkroman1/aai";
|
|
21
28
|
import { sentDtmfCalls } from "@alexkroman1/aai/experimental";
|
|
22
29
|
import {
|
|
30
|
+
createRouteContext,
|
|
23
31
|
createRunSnapshot,
|
|
24
32
|
createToolContext,
|
|
25
33
|
endSessionCalls,
|
|
@@ -27,30 +35,27 @@ import {
|
|
|
27
35
|
runWorkflow,
|
|
28
36
|
stubGatewayRoute,
|
|
29
37
|
stubPlaceCall,
|
|
30
|
-
|
|
38
|
+
type TestToolContext,
|
|
31
39
|
} from "@alexkroman1/aai-runtime/testing";
|
|
32
|
-
import { installStubWorkflows } from "@alexkroman1/aai-runtime/testing/vitest";
|
|
33
|
-
import {
|
|
40
|
+
import { describeAgent, installStubWorkflows } from "@alexkroman1/aai-runtime/testing/vitest";
|
|
41
|
+
import { beforeEach, describe, expect, onTestFinished, test, vi } from "vitest";
|
|
34
42
|
import { createCall, getCall, listCalls, newCallId } from "./api.ts";
|
|
35
43
|
import type { CallRecord } from "./api-types.ts";
|
|
36
|
-
import {
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import {
|
|
44
|
+
import { voicemailSlot } from "./shared.ts";
|
|
45
|
+
import endCall from "./tools/end_call.ts";
|
|
46
|
+
import pressKeys from "./tools/press_keys.ts";
|
|
47
|
+
import call, {
|
|
40
48
|
type CallEnded,
|
|
41
49
|
type CallInput,
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
RING_BUDGET_MS,
|
|
51
|
+
RING_POLL_MS,
|
|
44
52
|
} from "./workflows/call.ts";
|
|
45
|
-
import { callEndedToken } from "./workflows/tokens.ts";
|
|
46
53
|
|
|
47
54
|
const SECRET = "test-calls-key";
|
|
48
55
|
const PROMPT =
|
|
49
56
|
"Call Maria for Mission Dental to confirm her cleaning tomorrow at 2:30pm. " +
|
|
50
57
|
"If she needs to reschedule, offer Thursday at 10am or Friday at 4pm.";
|
|
51
58
|
|
|
52
|
-
const run = toolRunner(agentDef);
|
|
53
|
-
|
|
54
59
|
/** A request to one of the routes, authorized unless the case says otherwise. */
|
|
55
60
|
function request(over: Partial<RouteRequest> = {}): RouteRequest {
|
|
56
61
|
return {
|
|
@@ -66,16 +71,10 @@ function request(over: Partial<RouteRequest> = {}): RouteRequest {
|
|
|
66
71
|
|
|
67
72
|
/** A route context over a stubbed workflow client. */
|
|
68
73
|
function routeContext(
|
|
69
|
-
workflows = installStubWorkflows({
|
|
74
|
+
workflows = installStubWorkflows({ agent: agentDef }),
|
|
70
75
|
env: Record<string, string> = { CALLS_API_KEY: SECRET },
|
|
71
|
-
)
|
|
72
|
-
return {
|
|
73
|
-
env,
|
|
74
|
-
workflows,
|
|
75
|
-
clientTranscript: vi.fn(),
|
|
76
|
-
speech: () => undefined,
|
|
77
|
-
signal: new AbortController().signal,
|
|
78
|
-
};
|
|
76
|
+
) {
|
|
77
|
+
return createRouteContext({ env, workflows });
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
/** What a thrown `routeError` carries, without naming its class. */
|
|
@@ -88,7 +87,42 @@ async function refusal(promise: unknown): Promise<{ status: number; message: str
|
|
|
88
87
|
throw new Error("expected the route to refuse");
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
/** The call a session is on, as the phone bridge hands it in: this app's signed brief. */
|
|
91
|
+
async function placedCall(id: string, prompt = PROMPT, secret = SECRET): Promise<SessionCall> {
|
|
92
|
+
const ctx = createToolContext({
|
|
93
|
+
call: {
|
|
94
|
+
carrier: "twilio",
|
|
95
|
+
callId: "CA1",
|
|
96
|
+
parameters: await signCallBrief({ id, prompt }, secret),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
const placed = sessionCall(ctx);
|
|
100
|
+
if (placed === undefined) throw new Error("the context was given a call");
|
|
101
|
+
return placed;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* What `onSessionEnd` is handed when the session `ctx` was on ends: the
|
|
106
|
+
* session's own id and slots (so a fact a tool wrote during the call is
|
|
107
|
+
* readable), the stubbed workflow client, and the lines said. Built over a
|
|
108
|
+
* tool context rather than as a literal, so the next field the runtime adds to
|
|
109
|
+
* `SessionEndContext` lands here once.
|
|
110
|
+
*/
|
|
111
|
+
function sessionEnd(
|
|
112
|
+
ctx: TestToolContext,
|
|
113
|
+
over: Partial<SessionEndContext> & Pick<SessionEndContext, "workflows">,
|
|
114
|
+
): SessionEndContext {
|
|
115
|
+
return {
|
|
116
|
+
sessionId: ctx.sessionId,
|
|
117
|
+
env: { CALLS_API_KEY: SECRET },
|
|
118
|
+
slots: ctx.slots,
|
|
119
|
+
transcript: [],
|
|
120
|
+
lastEventIndex: -1,
|
|
121
|
+
...over,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
describeAgent(agentDef, (run) => {
|
|
92
126
|
test("answers Twilio calls and declares the call workflow and its routes", () => {
|
|
93
127
|
expect(agentDef.telephony).toEqual(["twilio"]);
|
|
94
128
|
expect(Object.keys(agentDef.workflows ?? {})).toContain("call");
|
|
@@ -98,485 +132,417 @@ describe("the agent", () => {
|
|
|
98
132
|
// An outbound call: the person who answers speaks first.
|
|
99
133
|
expect(agentDef.greeting).toBe("");
|
|
100
134
|
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("POST /v1/calls", () => {
|
|
104
|
-
const body = {
|
|
105
|
-
phone_number: "+14155550132",
|
|
106
|
-
prompt: PROMPT,
|
|
107
|
-
webhook_url: "https://example.com/hooks/calls",
|
|
108
|
-
};
|
|
109
135
|
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)) as {
|
|
116
|
-
status: number;
|
|
117
|
-
body: CallRecord;
|
|
136
|
+
describe("POST /v1/calls", () => {
|
|
137
|
+
const body = {
|
|
138
|
+
phone_number: "+14155550132",
|
|
139
|
+
prompt: PROMPT,
|
|
140
|
+
webhook_url: "https://example.com/hooks/calls",
|
|
118
141
|
};
|
|
119
142
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
test("starts one run, keyed by the call id it answers with", async () => {
|
|
144
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
145
|
+
const answer = (await createCall(
|
|
146
|
+
request({ method: "POST", body }),
|
|
147
|
+
routeContext(workflows),
|
|
148
|
+
)) as { status: number; body: CallRecord };
|
|
149
|
+
|
|
150
|
+
expect(answer.status).toBe(201);
|
|
151
|
+
expect(answer.body).toMatchObject({
|
|
152
|
+
status: "queued",
|
|
153
|
+
phone_number: body.phone_number,
|
|
154
|
+
transcript: [],
|
|
155
|
+
});
|
|
156
|
+
expect(answer.body.id).toMatch(/^call_[0-9a-f]{16}$/);
|
|
157
|
+
expect(workflows.start).toHaveBeenCalledWith(
|
|
158
|
+
call,
|
|
159
|
+
expect.objectContaining({ ...body, id: answer.body.id }),
|
|
160
|
+
{ key: answer.body.id, label: body.phone_number },
|
|
161
|
+
);
|
|
125
162
|
});
|
|
126
|
-
expect(answer.body.id).toMatch(/^call_[0-9a-f]{16}$/);
|
|
127
|
-
expect(workflows.start).toHaveBeenCalledWith(
|
|
128
|
-
call,
|
|
129
|
-
expect.objectContaining({ ...body, id: answer.body.id }),
|
|
130
|
-
{ key: answer.body.id, label: body.phone_number },
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
163
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
164
|
+
test("accepts `Bearer <key>` as well as the bare key", async () => {
|
|
165
|
+
const ctx = routeContext();
|
|
166
|
+
await createCall(
|
|
167
|
+
request({ method: "POST", body, headers: { authorization: `Bearer ${SECRET}` } }),
|
|
168
|
+
ctx,
|
|
169
|
+
);
|
|
170
|
+
expect(ctx.workflows.start).toHaveBeenCalledOnce();
|
|
171
|
+
});
|
|
142
172
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
173
|
+
test("refuses a wrong key, and is off entirely without CALLS_API_KEY", async () => {
|
|
174
|
+
const ctx = routeContext();
|
|
175
|
+
expect(
|
|
176
|
+
await createCall(
|
|
177
|
+
request({ method: "POST", body, headers: { authorization: "nope" } }),
|
|
178
|
+
ctx,
|
|
179
|
+
),
|
|
180
|
+
).toMatchObject({ status: 401 });
|
|
181
|
+
expect(
|
|
182
|
+
await createCall(request({ method: "POST", body }), routeContext(undefined, {})),
|
|
183
|
+
).toMatchObject({ status: 503, body: { error: expect.stringMatching(/CALLS_API_KEY/) } });
|
|
184
|
+
expect(ctx.workflows.start).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
155
186
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
createCall(
|
|
187
|
+
test("refuses a number that is not E.164 and a missing prompt, saying which", async () => {
|
|
188
|
+
const ctx = routeContext();
|
|
189
|
+
const refused = (await createCall(
|
|
160
190
|
request({ method: "POST", body: { phone_number: "415-555-0132", prompt: " " } }),
|
|
161
191
|
ctx,
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
expect(ctx.workflows.start).not.toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test("mints a distinct id per call", () => {
|
|
171
|
-
expect(new Set(Array.from({ length: 50 }, newCallId)).size).toBe(50);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("GET /v1/calls/:id and GET /v1/calls", () => {
|
|
176
|
-
afterEach(() => {
|
|
177
|
-
closeCall("s_live");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("a finished call is the run's output", async () => {
|
|
181
|
-
const record: CallRecord = {
|
|
182
|
-
id: "call_done",
|
|
183
|
-
status: "completed",
|
|
184
|
-
outcome: "answered",
|
|
185
|
-
phone_number: "+14155550132",
|
|
186
|
-
created_at: 1,
|
|
187
|
-
duration_seconds: 74,
|
|
188
|
-
summary: "Maria rebooked for Thursday at 10am.",
|
|
189
|
-
transcript: [{ role: "agent", text: "Hi, is this Maria?" }],
|
|
190
|
-
};
|
|
191
|
-
const workflows = installStubWorkflows({
|
|
192
|
-
runs: [
|
|
193
|
-
createRunSnapshot({
|
|
194
|
-
workflow: "call",
|
|
195
|
-
key: "call_done",
|
|
196
|
-
status: "completed",
|
|
197
|
-
output: record,
|
|
198
|
-
}),
|
|
199
|
-
],
|
|
192
|
+
)) as { status: number; body: { error: string } };
|
|
193
|
+
expect(refused.status).toBe(400);
|
|
194
|
+
expect(refused.body.error).toMatch(/E\.164/);
|
|
195
|
+
expect(refused.body.error).toMatch(/prompt is required/);
|
|
196
|
+
expect(ctx.workflows.start).not.toHaveBeenCalled();
|
|
200
197
|
});
|
|
201
|
-
const ctx = routeContext(workflows);
|
|
202
|
-
expect(await getCall(request({ params: { id: "call_done" } }), ctx)).toEqual(record);
|
|
203
|
-
expect(workflows.find).toHaveBeenCalledWith(call, "call_done", { limit: 1 });
|
|
204
|
-
expect(await listCalls(request(), ctx)).toEqual({ calls: [record] });
|
|
205
|
-
});
|
|
206
198
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
runs: [createRunSnapshot({ workflow: "call", key: "call_live", status: "running" })],
|
|
210
|
-
});
|
|
211
|
-
openCall("s_live", "call_live", 0);
|
|
212
|
-
recordTurn("s_live", "callee", "Hello?");
|
|
213
|
-
recordTurn("s_live", "agent", "Hi, is this Maria?");
|
|
214
|
-
|
|
215
|
-
expect(
|
|
216
|
-
await getCall(request({ params: { id: "call_live" } }), routeContext(workflows)),
|
|
217
|
-
).toMatchObject({
|
|
218
|
-
id: "call_live",
|
|
219
|
-
status: "in-progress",
|
|
220
|
-
transcript: [
|
|
221
|
-
{ role: "callee", text: "Hello?" },
|
|
222
|
-
{ role: "agent", text: "Hi, is this Maria?" },
|
|
223
|
-
],
|
|
199
|
+
test("mints a distinct id per call", () => {
|
|
200
|
+
expect(new Set(Array.from({ length: 50 }, newCallId)).size).toBe(50);
|
|
224
201
|
});
|
|
225
202
|
});
|
|
226
203
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
204
|
+
describe("GET /v1/calls/:id and GET /v1/calls", () => {
|
|
205
|
+
test("a finished call is the run's output", async () => {
|
|
206
|
+
const record: CallRecord = {
|
|
207
|
+
id: "call_done",
|
|
208
|
+
status: "completed",
|
|
209
|
+
outcome: "answered",
|
|
210
|
+
phone_number: "+14155550132",
|
|
211
|
+
created_at: 1,
|
|
212
|
+
duration_seconds: 74,
|
|
213
|
+
summary: "Maria rebooked for Thursday at 10am.",
|
|
214
|
+
transcript: [{ role: "agent", text: "Hi, is this Maria?" }],
|
|
215
|
+
};
|
|
216
|
+
const workflows = installStubWorkflows({
|
|
217
|
+
agent: agentDef,
|
|
218
|
+
runs: [createRunSnapshot(call, { key: "call_done", status: "completed", output: record })],
|
|
219
|
+
});
|
|
220
|
+
const ctx = routeContext(workflows);
|
|
221
|
+
expect(await getCall(request({ params: { id: "call_done" } }), ctx)).toEqual(record);
|
|
222
|
+
expect(workflows.find).toHaveBeenCalledWith(call, "call_done", { limit: 1 });
|
|
223
|
+
expect(await listCalls(request(), ctx)).toEqual({ calls: [record] });
|
|
238
224
|
});
|
|
239
|
-
expect(
|
|
240
|
-
await refusal(getCall(request({ params: { id: "call_none" } }), routeContext())),
|
|
241
|
-
).toMatchObject({
|
|
242
|
-
status: 404,
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
225
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
226
|
+
test("a call still going says where it is, in the run's own words", async () => {
|
|
227
|
+
const workflows = installStubWorkflows({
|
|
228
|
+
agent: agentDef,
|
|
229
|
+
runs: [
|
|
230
|
+
createRunSnapshot(call, {
|
|
231
|
+
key: "call_live",
|
|
232
|
+
status: "running",
|
|
233
|
+
createdAt: 5,
|
|
234
|
+
label: "+14155550132",
|
|
235
|
+
}),
|
|
236
|
+
],
|
|
237
|
+
});
|
|
238
|
+
expect(
|
|
239
|
+
await getCall(request({ params: { id: "call_live" } }), routeContext(workflows)),
|
|
240
|
+
).toEqual({
|
|
241
|
+
id: "call_live",
|
|
242
|
+
status: "queued",
|
|
243
|
+
phone_number: "+14155550132",
|
|
244
|
+
created_at: 5,
|
|
245
|
+
transcript: [],
|
|
246
|
+
summary: "+14155550132: dialled, waiting for the call to end.",
|
|
247
|
+
});
|
|
248
|
+
});
|
|
257
249
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
250
|
+
test("a run that failed says why; an unknown id is a 404", async () => {
|
|
251
|
+
const failed = installStubWorkflows({
|
|
252
|
+
agent: agentDef,
|
|
253
|
+
runs: [createRunSnapshot(call, { key: "call_bad", status: "failed", error: "boom" })],
|
|
254
|
+
});
|
|
255
|
+
expect(
|
|
256
|
+
await getCall(request({ params: { id: "call_bad" } }), routeContext(failed)),
|
|
257
|
+
).toMatchObject({ status: "failed", error: "boom" });
|
|
258
|
+
expect(
|
|
259
|
+
await refusal(getCall(request({ params: { id: "call_none" } }), routeContext())),
|
|
260
|
+
).toMatchObject({ status: 404 });
|
|
261
|
+
});
|
|
266
262
|
});
|
|
267
263
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
264
|
+
describe("the call brief", () => {
|
|
265
|
+
test("sessionContext refuses an unsigned stream and briefs a signed one", async () => {
|
|
266
|
+
const sessionContext = agentDef.sessionContext;
|
|
267
|
+
if (sessionContext === undefined) throw new Error("the agent declares a sessionContext");
|
|
268
|
+
const args = { env: { CALLS_API_KEY: SECRET }, signal: new AbortController().signal };
|
|
269
|
+
|
|
270
|
+
expect(await sessionContext({ ...args, sessionId: "s_web" })).toMatchObject({
|
|
271
|
+
refuse: expect.any(String),
|
|
272
|
+
});
|
|
273
|
+
expect(
|
|
274
|
+
await sessionContext({
|
|
275
|
+
...args,
|
|
276
|
+
sessionId: "s_stranger",
|
|
277
|
+
call: await placedCall("call_1", PROMPT, "another-key"),
|
|
278
|
+
}),
|
|
279
|
+
).toMatchObject({ refuse: expect.any(String) });
|
|
272
280
|
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
expect(
|
|
282
|
+
await sessionContext({ ...args, sessionId: "s_signed", call: await placedCall("call_1") }),
|
|
283
|
+
).toMatchObject({ greeting: "", instructions: expect.stringContaining(PROMPT) });
|
|
275
284
|
});
|
|
276
|
-
expect(
|
|
277
|
-
await sessionContext({
|
|
278
|
-
...args,
|
|
279
|
-
sessionId: "s_stranger",
|
|
280
|
-
call: { carrier: "twilio", parameters: { call: "call_1", sig: "00", p0: PROMPT } },
|
|
281
|
-
}),
|
|
282
|
-
).toMatchObject({ refuse: expect.any(String) });
|
|
283
|
-
|
|
284
|
-
const parameters = await signCall({ id: "call_1", prompt: PROMPT }, SECRET);
|
|
285
|
-
const briefed = await sessionContext({
|
|
286
|
-
...args,
|
|
287
|
-
sessionId: "s_signed",
|
|
288
|
-
call: { carrier: "twilio", callId: "CA1", parameters },
|
|
289
|
-
});
|
|
290
|
-
expect(briefed).toMatchObject({ greeting: "", instructions: expect.stringContaining(PROMPT) });
|
|
291
|
-
expect(liveCall("call_1")).toBeDefined();
|
|
292
|
-
closeCall("s_signed");
|
|
293
285
|
});
|
|
294
|
-
});
|
|
295
286
|
|
|
296
|
-
describe("the session", () => {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
287
|
+
describe("the session", () => {
|
|
288
|
+
test("end_call hangs up", async () => {
|
|
289
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
290
|
+
const result = await run(endCall, {}, ctx);
|
|
300
291
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
292
|
+
expect(result).toMatchObject({ ended: expect.any(Boolean) });
|
|
293
|
+
expect(endSessionCalls(ctx)).toHaveLength(1);
|
|
294
|
+
expect(voicemailSlot.get(ctx)).toBe(false);
|
|
295
|
+
});
|
|
305
296
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
297
|
+
test("end_call after a voicemail message records the fact for the session's end", async () => {
|
|
298
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
299
|
+
await run(endCall, { voicemail: true }, ctx);
|
|
310
300
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const result = await run("press_keys", { keys: "2#" }, ctx);
|
|
301
|
+
expect(endSessionCalls(ctx)).toHaveLength(1);
|
|
302
|
+
expect(voicemailSlot.get(ctx)).toBe(true);
|
|
303
|
+
});
|
|
315
304
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
});
|
|
305
|
+
test("press_keys plays the keys into the call", async () => {
|
|
306
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
307
|
+
const result = await run(pressKeys, { keys: "2#" }, ctx);
|
|
320
308
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
expect(sentDtmfCalls(ctx)).toEqual([]);
|
|
325
|
-
});
|
|
309
|
+
expect(result).toMatchObject({ pressed: "2#" });
|
|
310
|
+
expect(sentDtmfCalls(ctx)).toEqual(["2#"]);
|
|
311
|
+
});
|
|
326
312
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
recordTurn("s_1", "callee", "Enter your party's extension, then pound.");
|
|
333
|
-
await run("press_keys", { keys: "204#" }, ctx);
|
|
334
|
-
recordTurn("s_1", "callee", "Front desk, this is Dana.");
|
|
335
|
-
|
|
336
|
-
expect(sentDtmfCalls(ctx)).toEqual(["2", "204#"]);
|
|
337
|
-
const transcript = liveCall("call_tree")?.transcript ?? [];
|
|
338
|
-
expect(transcriptText(transcript)).toBe(
|
|
339
|
-
[
|
|
340
|
-
"Callee: For appointments, press 2. For billing, press 3.",
|
|
341
|
-
"Agent: [pressed 2]",
|
|
342
|
-
"Callee: Enter your party's extension, then pound.",
|
|
343
|
-
"Agent: [pressed 204#]",
|
|
344
|
-
"Callee: Front desk, this is Dana.",
|
|
345
|
-
].join("\n"),
|
|
346
|
-
);
|
|
347
|
-
});
|
|
313
|
+
test("press_keys refuses a key no phone has, so the model can retry", async () => {
|
|
314
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
315
|
+
await expect(run(pressKeys, { keys: "one" }, ctx)).rejects.toThrow(/not a phone key/);
|
|
316
|
+
expect(sentDtmfCalls(ctx)).toEqual([]);
|
|
317
|
+
});
|
|
348
318
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
319
|
+
test("press_keys sends the keys a model spells with spaces, commas or pauses", async () => {
|
|
320
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
321
|
+
await run(pressKeys, { keys: "2 0 4 #" }, ctx);
|
|
322
|
+
await run(pressKeys, { keys: "0w2" }, ctx);
|
|
323
|
+
expect(sentDtmfCalls(ctx)).toEqual(["204#", "0w2"]);
|
|
324
|
+
});
|
|
355
325
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
326
|
+
test("press_keys on a call that has ended says so", async () => {
|
|
327
|
+
// A context whose session has no audio to play into — what `sendDtmf`
|
|
328
|
+
// sees once the line has dropped.
|
|
329
|
+
const ctx = { ...createToolContext({ sessionId: "s_1" }), sessionId: "s_gone" };
|
|
330
|
+
expect(await run(pressKeys, { keys: "1" }, ctx)).toEqual({
|
|
331
|
+
pressed: null,
|
|
332
|
+
error: "The call has ended.",
|
|
333
|
+
});
|
|
334
|
+
});
|
|
362
335
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
336
|
+
test("hands the transcript to the call's run as the session ends, by the call's key", async () => {
|
|
337
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
338
|
+
const ctx = createToolContext({ sessionId: "s_1" });
|
|
339
|
+
|
|
340
|
+
await agentDef.onSessionEnd?.(
|
|
341
|
+
sessionEnd(ctx, {
|
|
342
|
+
call: await placedCall("call_42"),
|
|
343
|
+
workflows,
|
|
344
|
+
transcript: [
|
|
345
|
+
{ role: "user", text: "Hello?", at: 1000 },
|
|
346
|
+
{ role: "assistant", text: "Hi, is this Maria?", at: 75_000 },
|
|
347
|
+
],
|
|
348
|
+
lastEventIndex: 1,
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
// `signalRun` holds the payload for the run by default, so a call shorter
|
|
353
|
+
// than one ring poll still reaches a run not yet parked on it.
|
|
354
|
+
expect(workflows.signalRun).toHaveBeenCalledWith(call, "call_42", "callEnded", {
|
|
355
|
+
transcript: [
|
|
356
|
+
{ role: "callee", text: "Hello?" },
|
|
357
|
+
{ role: "agent", text: "Hi, is this Maria?" },
|
|
358
|
+
],
|
|
359
|
+
duration_seconds: 74,
|
|
360
|
+
voicemail: false,
|
|
361
|
+
});
|
|
362
|
+
});
|
|
367
363
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
364
|
+
test("the voicemail fact end_call wrote rides on the signal", async () => {
|
|
365
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
366
|
+
const ctx = createToolContext({ sessionId: "s_vm" });
|
|
367
|
+
await run(endCall, { voicemail: true }, ctx);
|
|
368
|
+
|
|
369
|
+
await agentDef.onSessionEnd?.(
|
|
370
|
+
sessionEnd(ctx, {
|
|
371
|
+
call: await placedCall("call_43"),
|
|
372
|
+
workflows,
|
|
373
|
+
transcript: [{ role: "assistant", text: "Hi Maria, please call us back.", at: 1000 }],
|
|
374
|
+
lastEventIndex: 0,
|
|
375
|
+
}),
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
expect(workflows.signalRun).toHaveBeenCalledWith(
|
|
379
|
+
call,
|
|
380
|
+
"call_43",
|
|
381
|
+
"callEnded",
|
|
382
|
+
expect.objectContaining({ voicemail: true }),
|
|
383
|
+
);
|
|
384
|
+
});
|
|
389
385
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
386
|
+
test("a session that was never a placed call hands nothing over", async () => {
|
|
387
|
+
const workflows = installStubWorkflows({ agent: agentDef });
|
|
388
|
+
await agentDef.onSessionEnd?.(
|
|
389
|
+
sessionEnd(createToolContext({ sessionId: "s_none" }), { workflows }),
|
|
390
|
+
);
|
|
391
|
+
expect(workflows.signalRun).not.toHaveBeenCalled();
|
|
392
|
+
});
|
|
394
393
|
});
|
|
395
394
|
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
expect(signal).toHaveBeenCalledWith(callEndedToken("call_42"), {
|
|
395
|
+
describe("the run is DURABLE", () => {
|
|
396
|
+
const INPUT: CallInput = {
|
|
397
|
+
id: "call_7Hq2xK9mPz",
|
|
398
|
+
phone_number: "+14155550132",
|
|
399
|
+
prompt: PROMPT,
|
|
400
|
+
webhook_url: "https://example.com/hooks/calls",
|
|
401
|
+
created_at: 1_700_000_000_000,
|
|
402
|
+
};
|
|
403
|
+
const ENDED: CallEnded = {
|
|
406
404
|
transcript: [
|
|
407
|
-
{ role: "
|
|
408
|
-
{ role: "
|
|
405
|
+
{ role: "agent", text: "Hi, is this Maria? I'm calling from Mission Dental." },
|
|
406
|
+
{ role: "callee", text: "Something came up at work. Anything later this week?" },
|
|
407
|
+
{ role: "agent", text: "I have Thursday at 10am or Friday at 4pm." },
|
|
408
|
+
{ role: "callee", text: "Thursday at 10 works." },
|
|
409
409
|
],
|
|
410
|
-
voicemail: false,
|
|
411
410
|
duration_seconds: 74,
|
|
411
|
+
voicemail: false,
|
|
412
|
+
};
|
|
413
|
+
const SUMMARY = "Maria rebooked for Thursday at 10am.";
|
|
414
|
+
|
|
415
|
+
beforeEach(() => {
|
|
416
|
+
vi.stubEnv("TWILIO_ACCOUNT_SID", "AC123");
|
|
417
|
+
vi.stubEnv("TWILIO_AUTH_TOKEN", "token");
|
|
418
|
+
vi.stubEnv("TWILIO_FROM_NUMBER", "+14155550100");
|
|
419
|
+
vi.stubEnv("CALLS_API_KEY", SECRET);
|
|
420
|
+
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
412
421
|
});
|
|
413
|
-
// Handed over once, and then forgotten.
|
|
414
|
-
expect(liveCall("call_42")).toBeUndefined();
|
|
415
|
-
});
|
|
416
422
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
423
|
+
/** Twilio, the model and the webhook behind the one published `stepFetch`. */
|
|
424
|
+
function stubWorld(options: Parameters<typeof stubPlaceCall>[0] = {}, summary = SUMMARY) {
|
|
425
|
+
const model = stubGatewayRoute(JSON.stringify({ summary }));
|
|
426
|
+
const webhook = vi.fn((_body: unknown) => ({ status: 204, body: "" }));
|
|
427
|
+
const twilio = stubPlaceCall({
|
|
428
|
+
status: (placed) => (placed.polls === 1 ? "ringing" : "in-progress"),
|
|
429
|
+
publicUrl: "https://caller.example.com",
|
|
430
|
+
...options,
|
|
431
|
+
otherwise: (req) =>
|
|
432
|
+
model.route(req) ??
|
|
433
|
+
webhook(
|
|
434
|
+
JSON.parse(
|
|
435
|
+
typeof req.body === "string" ? req.body : new TextDecoder().decode(req.body),
|
|
436
|
+
),
|
|
437
|
+
),
|
|
438
|
+
});
|
|
439
|
+
onTestFinished(() => twilio.restore());
|
|
440
|
+
return { twilio, model: model.calls, webhook };
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Keyed by the call id, as `POST /v1/calls` starts it: the key is what the
|
|
444
|
+
// body's `waitForSignal` and the session's `signalRun` derive the token from.
|
|
445
|
+
function start(options?: RunWorkflowOptions) {
|
|
446
|
+
return runWorkflow(agentDef, "call", INPUT, { key: INPUT.id, ...options });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
test("rings, parks on the call, and resumes on the session's signal into the finished record", async () => {
|
|
450
|
+
const world = stubWorld();
|
|
451
|
+
const handle = await start();
|
|
452
|
+
|
|
453
|
+
// Suspended between ring polls, with the dial already journaled.
|
|
454
|
+
expect(handle.status).toBe("running");
|
|
455
|
+
expect(world.twilio.calls).toHaveLength(1);
|
|
456
|
+
const placed = world.twilio.calls[0];
|
|
457
|
+
expect(placed?.to).toBe(INPUT.phone_number);
|
|
458
|
+
expect(placed?.webhookUrl).toBe("https://caller.example.com/phone?carrier=twilio");
|
|
459
|
+
// The answering session can verify the brief it was handed.
|
|
460
|
+
expect(await readCallBrief({ parameters: placed?.parameters ?? {} }, SECRET)).toEqual({
|
|
461
|
+
id: INPUT.id,
|
|
462
|
+
prompt: PROMPT,
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
await handle.advanceSleep(); // answered — now parked on the call
|
|
466
|
+
expect(handle.status).toBe("running");
|
|
467
|
+
|
|
468
|
+
await handle.signalRun("callEnded", ENDED);
|
|
469
|
+
expect(handle.signalled).toBe(true);
|
|
470
|
+
expect(handle.status).toBe("completed");
|
|
471
|
+
|
|
472
|
+
const expected: CallRecord = {
|
|
473
|
+
id: INPUT.id,
|
|
474
|
+
status: "completed",
|
|
475
|
+
phone_number: INPUT.phone_number,
|
|
476
|
+
created_at: INPUT.created_at,
|
|
477
|
+
outcome: "answered",
|
|
478
|
+
duration_seconds: 74,
|
|
479
|
+
summary: SUMMARY,
|
|
480
|
+
transcript: ENDED.transcript,
|
|
481
|
+
};
|
|
482
|
+
expect(handle.output).toEqual(expected);
|
|
483
|
+
expect(world.webhook).toHaveBeenCalledWith(expected);
|
|
484
|
+
// One dial, one model call, across every suspension.
|
|
485
|
+
expect(world.twilio.calls).toHaveLength(1);
|
|
486
|
+
expect(world.model).toHaveLength(1);
|
|
424
487
|
});
|
|
425
|
-
expect(signal).not.toHaveBeenCalled();
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
488
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
created_at: 1_700_000_000_000,
|
|
436
|
-
};
|
|
437
|
-
const ENDED: CallEnded = {
|
|
438
|
-
transcript: [
|
|
439
|
-
{ role: "agent", text: "Hi, is this Maria? I'm calling from Mission Dental." },
|
|
440
|
-
{ role: "callee", text: "Something came up at work. Anything later this week?" },
|
|
441
|
-
{ role: "agent", text: "I have Thursday at 10am or Friday at 4pm." },
|
|
442
|
-
{ role: "callee", text: "Thursday at 10 works." },
|
|
443
|
-
],
|
|
444
|
-
voicemail: false,
|
|
445
|
-
duration_seconds: 74,
|
|
446
|
-
};
|
|
447
|
-
const SUMMARY = "Maria rebooked for Thursday at 10am.";
|
|
448
|
-
|
|
449
|
-
beforeEach(() => {
|
|
450
|
-
vi.stubEnv("TWILIO_ACCOUNT_SID", "AC123");
|
|
451
|
-
vi.stubEnv("TWILIO_AUTH_TOKEN", "token");
|
|
452
|
-
vi.stubEnv("TWILIO_FROM_NUMBER", "+14155550100");
|
|
453
|
-
vi.stubEnv("CALLS_API_KEY", SECRET);
|
|
454
|
-
vi.stubEnv("ASSEMBLYAI_API_KEY", "sk-test");
|
|
455
|
-
});
|
|
489
|
+
test("a worker that dies after dialling resumes without ringing the phone again", async () => {
|
|
490
|
+
const world = stubWorld();
|
|
491
|
+
const handle = await start({ crashAt: "ring" }); // dies in the first ring poll
|
|
492
|
+
await handle.restart(); // a new worker: the dial is journaled, the poll runs again
|
|
493
|
+
await handle.advanceSleep();
|
|
494
|
+
await handle.signalRun("callEnded", ENDED);
|
|
456
495
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const model = stubGatewayRoute(JSON.stringify({ summary: SUMMARY }));
|
|
460
|
-
const webhook = vi.fn((_body: unknown) => ({ status: 204, body: "" }));
|
|
461
|
-
const twilio = stubPlaceCall({
|
|
462
|
-
status: (placed) => (placed.polls === 1 ? "ringing" : "in-progress"),
|
|
463
|
-
publicUrl: "https://caller.example.com",
|
|
464
|
-
...options,
|
|
465
|
-
otherwise: (req) =>
|
|
466
|
-
model.route(req) ??
|
|
467
|
-
webhook(
|
|
468
|
-
JSON.parse(typeof req.body === "string" ? req.body : new TextDecoder().decode(req.body)),
|
|
469
|
-
),
|
|
496
|
+
expect(handle.status).toBe("completed");
|
|
497
|
+
expect(world.twilio.calls).toHaveLength(1);
|
|
470
498
|
});
|
|
471
|
-
onTestFinished(() => twilio.restore());
|
|
472
|
-
return { twilio, model: model.calls, webhook };
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function start(options?: RunWorkflowOptions) {
|
|
476
|
-
return runWorkflow(call, INPUT, { name: "call", ...options });
|
|
477
|
-
}
|
|
478
499
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
expect(world.twilio.calls).toHaveLength(1);
|
|
486
|
-
const placed = world.twilio.calls[0];
|
|
487
|
-
expect(placed?.to).toBe(INPUT.phone_number);
|
|
488
|
-
expect(placed?.webhookUrl).toBe("https://caller.example.com/phone?carrier=twilio");
|
|
489
|
-
// The answering session can verify the brief it was handed.
|
|
490
|
-
expect(await readCall(placed?.parameters ?? {}, SECRET)).toEqual({
|
|
491
|
-
id: INPUT.id,
|
|
492
|
-
prompt: PROMPT,
|
|
500
|
+
test("voicemail is the outcome when the session said it reached a machine", async () => {
|
|
501
|
+
stubWorld({}, "Left a message asking Maria to call back.");
|
|
502
|
+
const handle = await start();
|
|
503
|
+
await handle.advanceSleep();
|
|
504
|
+
await handle.signalRun("callEnded", { ...ENDED, voicemail: true });
|
|
505
|
+
expect(handle.output).toMatchObject({ outcome: "voicemail" });
|
|
493
506
|
});
|
|
494
507
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
await handle.signal(callEndedToken(INPUT.id), ENDED);
|
|
500
|
-
expect(handle.signalled).toBe(true);
|
|
501
|
-
expect(handle.status).toBe("completed");
|
|
502
|
-
|
|
503
|
-
const expected: CallRecord = {
|
|
504
|
-
id: INPUT.id,
|
|
505
|
-
status: "completed",
|
|
506
|
-
phone_number: INPUT.phone_number,
|
|
507
|
-
created_at: INPUT.created_at,
|
|
508
|
-
outcome: "answered",
|
|
509
|
-
duration_seconds: 74,
|
|
510
|
-
summary: SUMMARY,
|
|
511
|
-
transcript: ENDED.transcript,
|
|
512
|
-
};
|
|
513
|
-
expect(handle.output).toEqual(expected);
|
|
514
|
-
expect(world.webhook).toHaveBeenCalledWith(expected);
|
|
515
|
-
// One dial, one model call, across every suspension.
|
|
516
|
-
expect(world.twilio.calls).toHaveLength(1);
|
|
517
|
-
expect(world.model).toHaveLength(1);
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
test("a worker that dies after dialling resumes without ringing the phone again", async () => {
|
|
521
|
-
const world = stubWorld();
|
|
522
|
-
const handle = await start({ crashAt: "ring-status" });
|
|
523
|
-
await handle.advanceSleep(); // the first ring poll is delivered, and the worker dies in it
|
|
524
|
-
await handle.restart(); // a new worker: the dial is journaled, the poll runs again
|
|
525
|
-
await handle.advanceSleep();
|
|
526
|
-
await handle.signal(callEndedToken(INPUT.id), ENDED);
|
|
527
|
-
|
|
528
|
-
expect(handle.status).toBe("completed");
|
|
529
|
-
expect(world.twilio.calls).toHaveLength(1);
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
test("voicemail is the outcome when the agent said so", async () => {
|
|
533
|
-
stubWorld();
|
|
534
|
-
const handle = await start();
|
|
535
|
-
await handle.advanceSleep();
|
|
536
|
-
await handle.advanceSleep();
|
|
537
|
-
await handle.signal(callEndedToken(INPUT.id), { ...ENDED, voicemail: true });
|
|
538
|
-
expect(handle.output).toMatchObject({ outcome: "voicemail" });
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
test("nobody answering completes as no-answer, with no model call", async () => {
|
|
542
|
-
const world = stubWorld({ status: "no-answer" });
|
|
543
|
-
const handle = await start();
|
|
544
|
-
await handle.advanceSleep();
|
|
508
|
+
test("nobody answering completes as no-answer, with no model call", async () => {
|
|
509
|
+
const world = stubWorld({ status: "no-answer" });
|
|
510
|
+
const handle = await start();
|
|
545
511
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
512
|
+
expect(handle.status).toBe("completed");
|
|
513
|
+
expect(handle.output).toMatchObject({ outcome: "no-answer", transcript: [] });
|
|
514
|
+
expect(world.model).toHaveLength(0);
|
|
515
|
+
expect(world.webhook).toHaveBeenCalledOnce();
|
|
516
|
+
});
|
|
551
517
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
518
|
+
test("a phone that only ever rings gives up once the ring budget is spent", async () => {
|
|
519
|
+
stubWorld({ status: "ringing" });
|
|
520
|
+
const handle = await start();
|
|
521
|
+
for (let i = 0; i < RING_BUDGET_MS / RING_POLL_MS; i++) await handle.advanceSleep();
|
|
522
|
+
expect(handle.output).toMatchObject({ outcome: "no-answer" });
|
|
523
|
+
});
|
|
558
524
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
525
|
+
test("a dial Twilio refuses completes as failed, with Twilio's reason", async () => {
|
|
526
|
+
const world = stubWorld({ dial: { status: 400, code: 21_219, message: "unverified" } });
|
|
527
|
+
const handle = await start();
|
|
562
528
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
529
|
+
expect(handle.status).toBe("completed");
|
|
530
|
+
expect(handle.output).toMatchObject({ outcome: "failed", error: expect.any(String) });
|
|
531
|
+
// Not retried: a refusal asks the same way next time.
|
|
532
|
+
expect(world.twilio.calls).toHaveLength(1);
|
|
533
|
+
});
|
|
568
534
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
535
|
+
test("a transcript that never arrives closes the window instead of hanging", async () => {
|
|
536
|
+
stubWorld();
|
|
537
|
+
const handle = await start();
|
|
538
|
+
await handle.advanceSleep();
|
|
539
|
+
await handle.expireWaits();
|
|
540
|
+
|
|
541
|
+
expect(handle.status).toBe("completed");
|
|
542
|
+
expect(handle.output).toMatchObject({
|
|
543
|
+
outcome: "answered",
|
|
544
|
+
error: expect.stringMatching(/transcript/),
|
|
545
|
+
});
|
|
580
546
|
});
|
|
581
547
|
});
|
|
582
548
|
});
|