@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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares. */
|
|
2
2
|
import agentDef from "virtual:aai/agent";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ToolContext } from "@alexkroman1/aai";
|
|
4
4
|
import { isToolFailure } from "@alexkroman1/aai/utils";
|
|
5
5
|
import {
|
|
6
6
|
createToolContext,
|
|
7
|
-
expectDialogOk,
|
|
8
7
|
expectDialogRefused,
|
|
8
|
+
expectSlotContract,
|
|
9
9
|
expectToolOk,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
fireEvent,
|
|
11
|
+
sessionEvent,
|
|
12
12
|
} from "@alexkroman1/aai-runtime/testing";
|
|
13
|
+
import { describeAgent } from "@alexkroman1/aai-runtime/testing/vitest";
|
|
13
14
|
import { describe, expect, test } from "vitest";
|
|
14
15
|
import {
|
|
15
16
|
activeAssistant,
|
|
@@ -22,580 +23,567 @@ import {
|
|
|
22
23
|
tripSlot,
|
|
23
24
|
tripView,
|
|
24
25
|
} from "./shared.ts";
|
|
26
|
+
import bookCarRental from "./tools/book_car_rental.ts";
|
|
25
27
|
import bookExcursion from "./tools/book_excursion.ts";
|
|
26
28
|
import bookHotel from "./tools/book_hotel.ts";
|
|
29
|
+
import cancelAction from "./tools/cancel_action.ts";
|
|
27
30
|
import cancelTicket from "./tools/cancel_ticket.ts";
|
|
28
31
|
import completeOrEscalate from "./tools/complete_or_escalate.ts";
|
|
32
|
+
import confirmAction from "./tools/confirm_action.ts";
|
|
29
33
|
import lookupBooking from "./tools/lookup_booking.ts";
|
|
34
|
+
import searchCarRentals from "./tools/search_car_rentals.ts";
|
|
30
35
|
import searchExcursions from "./tools/search_excursions.ts";
|
|
31
36
|
import searchFlights from "./tools/search_flights.ts";
|
|
32
37
|
import searchHotels from "./tools/search_hotels.ts";
|
|
38
|
+
import toCarRentalAssistant from "./tools/to_car_rental_assistant.ts";
|
|
39
|
+
import toExcursionAssistant from "./tools/to_excursion_assistant.ts";
|
|
40
|
+
import toFlightAssistant from "./tools/to_flight_assistant.ts";
|
|
33
41
|
import toHotelAssistant from "./tools/to_hotel_assistant.ts";
|
|
34
42
|
import updateTicket from "./tools/update_ticket.ts";
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/** A tool by the name the model calls it by, bound to this agent. The lookup,
|
|
39
|
-
* its "no such tool" message and the args-or-context shape are all
|
|
40
|
-
* `toolRunner`'s (`@alexkroman1/aai-runtime/testing`); what is local is only which
|
|
41
|
-
* agent it runs against. */
|
|
42
|
-
const run = toolRunner(agentDef);
|
|
43
|
-
|
|
44
|
-
/** The state a tool just mutated, read back the way `syncState` reads it. */
|
|
45
|
-
function stateOf(ctx: ToolContext) {
|
|
46
|
-
return tripSlot.get(ctx);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Put the call at a desk the way the model has to: through that desk's own
|
|
51
|
-
* delegation tool.
|
|
52
|
-
*
|
|
53
|
-
* Every desk tool checks the stack first (`requireDesk`) and refuses from
|
|
54
|
-
* anywhere else, so a spec driving one has to stand where the model would. It is
|
|
55
|
-
* one line per test rather than a shared `beforeEach` deliberately — which desk
|
|
56
|
-
* a tool belongs to is what the block below is about, so it stays visible at the
|
|
57
|
-
* call site.
|
|
58
|
-
*/
|
|
59
|
-
const atDesk = async (id: SpecialistId, ctx: ToolContext): Promise<void> => {
|
|
60
|
-
await run(`to_${id}_assistant`, { request: "what the caller asked for" }, ctx);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// ─── 1. The dialog stack ─────────────────────────────────────────────────────
|
|
64
|
-
|
|
65
|
-
describe("dialog stack (routing.ts)", () => {
|
|
66
|
-
test("delegating pushes a desk and hands back its brief", async () => {
|
|
67
|
-
const ctx = createToolContext();
|
|
68
|
-
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
69
|
-
|
|
70
|
-
const handoff = await runTool(toHotelAssistant, { request: "somewhere near the water" }, ctx);
|
|
71
|
-
expect(handoff.desk).toBe("hotel desk");
|
|
72
|
-
// The brief IS the tool result — that is the whole port of their
|
|
73
|
-
// per-assistant prompt onto a session whose prompt is fixed at connect.
|
|
74
|
-
expect(handoff.instructions).toContain("hotel desk");
|
|
75
|
-
expect(activeAssistant(stateOf(ctx))).toBe("hotel");
|
|
76
|
-
});
|
|
44
|
+
describeAgent(agentDef, (run) => {
|
|
45
|
+
// ─── Harness ─────────────────────────────────────────────────────────────────
|
|
77
46
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(stateOf(ctx).dialogState).toEqual(["primary", "flight"]);
|
|
83
|
-
});
|
|
47
|
+
/** The state a tool just mutated, read back the way `syncState` reads it. */
|
|
48
|
+
function stateOf(ctx: ToolContext) {
|
|
49
|
+
return tripSlot.get(ctx);
|
|
50
|
+
}
|
|
84
51
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Put the call at a desk the way the model has to: through that desk's own
|
|
54
|
+
* delegation tool.
|
|
55
|
+
*
|
|
56
|
+
* Every desk tool checks the stack first (`requireDesk`) and refuses from
|
|
57
|
+
* anywhere else, so a spec driving one has to stand where the model would. It is
|
|
58
|
+
* one line per test rather than a shared `beforeEach` deliberately — which desk
|
|
59
|
+
* a tool belongs to is what the block below is about, so it stays visible at the
|
|
60
|
+
* call site.
|
|
61
|
+
*/
|
|
62
|
+
const DESK_ENTRY = {
|
|
63
|
+
flight: toFlightAssistant,
|
|
64
|
+
hotel: toHotelAssistant,
|
|
65
|
+
car_rental: toCarRentalAssistant,
|
|
66
|
+
excursion: toExcursionAssistant,
|
|
67
|
+
} as const satisfies Record<SpecialistId, unknown>;
|
|
68
|
+
const atDesk = async (id: SpecialistId, ctx: ToolContext): Promise<void> => {
|
|
69
|
+
await run(DESK_ENTRY[id], { request: "what the caller asked for" }, ctx);
|
|
70
|
+
};
|
|
88
71
|
|
|
89
|
-
|
|
90
|
-
expect(back.returnedFrom).toBe("excursions desk");
|
|
91
|
-
expect(back.nowHandling).toBe("concierge");
|
|
92
|
-
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
72
|
+
// ─── 1. The dialog stack ─────────────────────────────────────────────────────
|
|
93
73
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
});
|
|
74
|
+
describe("dialog stack (routing.ts)", () => {
|
|
75
|
+
test("delegating pushes a desk and hands back its brief", async () => {
|
|
76
|
+
const ctx = createToolContext();
|
|
77
|
+
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
100
78
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
describe("the desk gate (requireDesk)", () => {
|
|
110
|
-
const DESK_TOOLS = [
|
|
111
|
-
["search_flights", { route: "Boston" }, "flight"],
|
|
112
|
-
["update_ticket", { flightId: "LX52" }, "flight"],
|
|
113
|
-
["cancel_ticket", {}, "flight"],
|
|
114
|
-
["search_hotels", { city: "Boston" }, "hotel"],
|
|
115
|
-
["book_hotel", { hotelId: "H1", nights: 2 }, "hotel"],
|
|
116
|
-
["search_car_rentals", { city: "Boston" }, "car_rental"],
|
|
117
|
-
["book_car_rental", { carId: "C2", days: 3 }, "car_rental"],
|
|
118
|
-
["search_excursions", { city: "Boston" }, "excursion"],
|
|
119
|
-
["book_excursion", { excursionId: "E2" }, "excursion"],
|
|
120
|
-
] as const;
|
|
121
|
-
|
|
122
|
-
test.each(DESK_TOOLS)("%s refuses at the concierge desk", async (name, args, desk) => {
|
|
123
|
-
const ctx = createToolContext();
|
|
124
|
-
const refused = (await run(name, args, ctx)) as { error?: string };
|
|
125
|
-
// The refusal NAMES the way in, which is what the model recovers from
|
|
126
|
-
// inside the same turn — a bare "not allowed" would leave it guessing.
|
|
127
|
-
expect(refused.error).toContain(`to_${desk}_assistant`);
|
|
128
|
-
// And nothing happened: no search result, no staging, no stack movement.
|
|
129
|
-
expect(stateOf(ctx).pending).toBeNull();
|
|
130
|
-
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
131
|
-
expect(gateFlow.position(ctx).state).toBe("browsing");
|
|
132
|
-
});
|
|
79
|
+
const handoff = await run(toHotelAssistant, { request: "somewhere near the water" }, ctx);
|
|
80
|
+
expect(handoff.desk).toBe("hotel desk");
|
|
81
|
+
// The brief IS the tool result — that is the whole port of their
|
|
82
|
+
// per-assistant prompt onto a session whose prompt is fixed at connect.
|
|
83
|
+
expect(handoff.instructions).toContain("hotel desk");
|
|
84
|
+
expect(activeAssistant(stateOf(ctx))).toBe("hotel");
|
|
85
|
+
});
|
|
133
86
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
expect(stateOf(ctx).pending).toBeNull();
|
|
145
|
-
});
|
|
87
|
+
test("re-delegating to the desk already holding the call does not grow the stack", async () => {
|
|
88
|
+
const ctx = createToolContext();
|
|
89
|
+
await run(toFlightAssistant, { request: "move my flight" }, ctx);
|
|
90
|
+
await run(toFlightAssistant, { request: "actually a later one" }, ctx);
|
|
91
|
+
expect(stateOf(ctx).dialogState).toEqual(["primary", "flight"]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("complete_or_escalate pops, and never past the concierge", async () => {
|
|
95
|
+
const ctx = createToolContext();
|
|
96
|
+
await run(toExcursionAssistant, { request: "something to do" }, ctx);
|
|
146
97
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
98
|
+
const back = await run(completeOrEscalate, { reason: "booked it" }, ctx);
|
|
99
|
+
expect(back.returnedFrom).toBe("excursions desk");
|
|
100
|
+
expect(back.nowHandling).toBe("concierge");
|
|
101
|
+
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
102
|
+
|
|
103
|
+
// Popping again at the bottom is a no-op rather than an empty stack: the
|
|
104
|
+
// slot's `after` hook is what guarantees there is always an assistant.
|
|
105
|
+
await run(completeOrEscalate, { reason: "nothing else" }, ctx);
|
|
106
|
+
expect(stateOf(ctx).dialogState).toEqual(["primary"]);
|
|
154
107
|
});
|
|
155
108
|
});
|
|
156
109
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
110
|
+
// ─── 1b. The desk gate ───────────────────────────────────────────────────────
|
|
111
|
+
//
|
|
112
|
+
// What their graph gets from binding a tool set per node, and what this port
|
|
113
|
+
// used to only ask the prompt for. The eval (`agent.eval.test.ts`) is what
|
|
114
|
+
// measured the asking losing — 0 of 5 live runs, the model searching hotels
|
|
115
|
+
// while the stack said `primary` — so these are the tests that make the stack
|
|
116
|
+
// binding rather than descriptive.
|
|
117
|
+
|
|
118
|
+
describe("the desk gate (requireDesk)", () => {
|
|
119
|
+
const DESK_TOOLS = [
|
|
120
|
+
["search_flights", searchFlights, { route: "Boston" }, "flight"],
|
|
121
|
+
["update_ticket", updateTicket, { flightId: "LX52" }, "flight"],
|
|
122
|
+
["cancel_ticket", cancelTicket, {}, "flight"],
|
|
123
|
+
["search_hotels", searchHotels, { city: "Boston" }, "hotel"],
|
|
124
|
+
["book_hotel", bookHotel, { hotelId: "H1", nights: 2 }, "hotel"],
|
|
125
|
+
["search_car_rentals", searchCarRentals, { city: "Boston" }, "car_rental"],
|
|
126
|
+
["book_car_rental", bookCarRental, { carId: "C2", days: 3 }, "car_rental"],
|
|
127
|
+
["search_excursions", searchExcursions, { city: "Boston" }, "excursion"],
|
|
128
|
+
["book_excursion", bookExcursion, { excursionId: "E2" }, "excursion"],
|
|
129
|
+
] as const;
|
|
130
|
+
|
|
131
|
+
test.each(DESK_TOOLS)("%s refuses at the concierge desk", async (_name, tool, args, desk) => {
|
|
132
|
+
const ctx = createToolContext();
|
|
133
|
+
const refused = await run(tool, args, ctx);
|
|
134
|
+
// The refusal NAMES the way in, which is what the model recovers from
|
|
135
|
+
// inside the same turn — a bare "not allowed" would leave it guessing.
|
|
136
|
+
expect(isToolFailure(refused) && refused.error).toContain(`to_${desk}_assistant`);
|
|
137
|
+
// And nothing happened: no search result, no staging, no stack movement.
|
|
138
|
+
expect(stateOf(ctx).pending).toBeNull();
|
|
139
|
+
expect(activeAssistant(stateOf(ctx))).toBe("primary");
|
|
140
|
+
expect(gateFlow.position(ctx).state).toBe("browsing");
|
|
141
|
+
});
|
|
166
142
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
["book_excursion", { excursionId: "E2" }, "excursion"],
|
|
181
|
-
] as const)("%s changes nothing on its own", async (name, args, desk) => {
|
|
182
|
-
const ctx = createToolContext();
|
|
183
|
-
await atDesk(desk, ctx);
|
|
184
|
-
const before = structuredClone(stateOf(ctx));
|
|
185
|
-
|
|
186
|
-
const staged = (await run(name, args, ctx)) as { awaitingConfirmation: boolean };
|
|
187
|
-
expect(staged.awaitingConfirmation).toBe(true);
|
|
188
|
-
|
|
189
|
-
const after = stateOf(ctx);
|
|
190
|
-
expect(after.ticket).toEqual(before.ticket);
|
|
191
|
-
expect(after.bookings).toEqual([]);
|
|
192
|
-
expect(after.pending).not.toBeNull();
|
|
193
|
-
});
|
|
143
|
+
test.each(DESK_TOOLS)("%s refuses from ANOTHER desk", async (_name, tool, args, desk) => {
|
|
144
|
+
const ctx = createToolContext();
|
|
145
|
+
// The excursions desk for anything that is not its own, and the flight desk
|
|
146
|
+
// for the excursion tools — so every case really is a wrong desk rather
|
|
147
|
+
// than a coincidence of ordering.
|
|
148
|
+
const wrong = desk === "excursion" ? "flight" : "excursion";
|
|
149
|
+
await atDesk(wrong, ctx);
|
|
150
|
+
const refused = await run(tool, args, ctx);
|
|
151
|
+
const error = isToolFailure(refused) && refused.error;
|
|
152
|
+
expect(error).toContain(`to_${desk}_assistant`);
|
|
153
|
+
expect(error).toContain(desk === "excursion" ? "flight desk" : "excursions desk");
|
|
154
|
+
expect(stateOf(ctx).pending).toBeNull();
|
|
155
|
+
});
|
|
194
156
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// it replaces read `undefined` off the failure and died three assertions
|
|
207
|
-
// later on a property of undefined.
|
|
208
|
-
const confirmed = expectDialogOk<{ applied: string; reference: string }>(
|
|
209
|
-
await run("confirm_action", ctx),
|
|
157
|
+
test.each(DESK_TOOLS)(
|
|
158
|
+
"%s works once its own desk holds the call",
|
|
159
|
+
async (_name, tool, args, desk) => {
|
|
160
|
+
// The other half, and the one that makes the block above non-vacuous: a
|
|
161
|
+
// gate that refused everywhere would pass every assertion up to here.
|
|
162
|
+
const ctx = createToolContext();
|
|
163
|
+
await atDesk(desk, ctx);
|
|
164
|
+
expect(await run(tool, args, ctx)).not.toMatchObject({
|
|
165
|
+
error: expect.stringContaining("belongs to the"),
|
|
166
|
+
});
|
|
167
|
+
},
|
|
210
168
|
);
|
|
211
|
-
expect(confirmed.result.applied).toContain("Harborview Suites");
|
|
212
|
-
// 3 nights at $265.
|
|
213
|
-
expect(confirmed.result.applied).toContain("$795");
|
|
214
|
-
// SETTLED: the gate re-armed as part of the same call.
|
|
215
|
-
expect(confirmed.state).toBe("browsing");
|
|
216
|
-
|
|
217
|
-
const state = stateOf(ctx);
|
|
218
|
-
expect(state.pending).toBeNull();
|
|
219
|
-
expect(state.bookings).toHaveLength(1);
|
|
220
|
-
expect(state.bookings[0]?.reference).toBe(confirmed.result.reference);
|
|
221
|
-
|
|
222
|
-
// The gate re-arms, and now REFUSES rather than reporting an empty apply —
|
|
223
|
-
// `when: "awaitingConfirmation"` is what a second confirm meets.
|
|
224
|
-
//
|
|
225
|
-
// `expectDialogRefused` rather than a regex for the sentence: the refusal is
|
|
226
|
-
// the SDK's, written in one place and matched from another, and it throws on
|
|
227
|
-
// a call that SUCCEEDED — where a `toMatchObject` on a success reads
|
|
228
|
-
// `undefined` for `error` and passes nothing worth reading. The state is
|
|
229
|
-
// pinned too, because "refused" and "refused where the spec thinks the
|
|
230
|
-
// conversation is" are two claims.
|
|
231
|
-
expectDialogRefused(await run("confirm_action", ctx), "browsing");
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test("cancel_action drops the staged change and leaves the booking alone", async () => {
|
|
235
|
-
const ctx = createToolContext();
|
|
236
|
-
await atDesk("flight", ctx);
|
|
237
|
-
await run("update_ticket", { flightId: "LX54" }, ctx);
|
|
238
|
-
const dropped = expectDialogOk<{ discarded: string }>(await run("cancel_action", ctx));
|
|
239
|
-
expect(dropped.result.discarded).toContain("LX54");
|
|
240
|
-
expect(dropped.state).toBe("browsing");
|
|
241
|
-
|
|
242
|
-
const state = stateOf(ctx);
|
|
243
|
-
expect(state.pending).toBeNull();
|
|
244
|
-
expect(state.ticket?.flightId).toBe("LX40");
|
|
245
|
-
expectDialogRefused(await run("cancel_action", ctx), "browsing");
|
|
246
|
-
});
|
|
247
169
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
170
|
+
test("the concierge's own tools are NOT gated", async () => {
|
|
171
|
+
// `lookup_booking` is the concierge's, and the gate must not make the desk
|
|
172
|
+
// unable to answer "what am I holding?" from wherever the call is.
|
|
173
|
+
const ctx = createToolContext();
|
|
174
|
+
await atDesk("hotel", ctx);
|
|
175
|
+
const booking = await run(lookupBooking, ctx);
|
|
176
|
+
expect(booking.passenger).toBe("Nadia Rossi");
|
|
255
177
|
});
|
|
256
|
-
expect(stateOf(ctx).pending).toBeNull();
|
|
257
178
|
});
|
|
258
179
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
180
|
+
// ─── 2. The confirmation gate ────────────────────────────────────────────────
|
|
181
|
+
//
|
|
182
|
+
// Their graph halts before a sensitive tool (`interrupt_before`) and resumes on
|
|
183
|
+
// approval. Here every sensitive tool stages and applies nothing, so the
|
|
184
|
+
// approval has somewhere to arrive. These are the tests that matter: a
|
|
185
|
+
// regression makes the agent able to rebook a flight BY MISTAKE.
|
|
186
|
+
|
|
187
|
+
describe("sensitive tools stage rather than act", () => {
|
|
188
|
+
test.each([
|
|
189
|
+
["update_ticket", updateTicket, { flightId: "LX52" }, "flight"],
|
|
190
|
+
["cancel_ticket", cancelTicket, {}, "flight"],
|
|
191
|
+
["book_hotel", bookHotel, { hotelId: "H1", nights: 2 }, "hotel"],
|
|
192
|
+
["book_car_rental", bookCarRental, { carId: "C2", days: 3 }, "car_rental"],
|
|
193
|
+
["book_excursion", bookExcursion, { excursionId: "E2" }, "excursion"],
|
|
194
|
+
] as const)("%s changes nothing on its own", async (_name, tool, args, desk) => {
|
|
195
|
+
const ctx = createToolContext();
|
|
196
|
+
await atDesk(desk, ctx);
|
|
197
|
+
const before = structuredClone(stateOf(ctx));
|
|
198
|
+
|
|
199
|
+
const staged = expectToolOk(await run(tool, args, ctx));
|
|
200
|
+
expect(staged.awaitingConfirmation).toBe(true);
|
|
201
|
+
|
|
202
|
+
const after = stateOf(ctx);
|
|
203
|
+
expect(after.ticket).toEqual(before.ticket);
|
|
204
|
+
expect(after.bookings).toEqual([]);
|
|
205
|
+
expect(after.pending).not.toBeNull();
|
|
206
|
+
});
|
|
265
207
|
|
|
266
|
-
|
|
267
|
-
|
|
208
|
+
test("confirm_action applies the staged change, and only then", async () => {
|
|
209
|
+
const ctx = createToolContext();
|
|
210
|
+
await atDesk("hotel", ctx);
|
|
211
|
+
await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
|
|
212
|
+
|
|
213
|
+
// Staging moved the gate, in the same window it wrote `pending`.
|
|
214
|
+
expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
|
|
215
|
+
|
|
216
|
+
// A gated tool answers the flow's POSITION wrapped around the body's own
|
|
217
|
+
// return value, so the applied sentence is under `result`.
|
|
218
|
+
const confirmed = await run(confirmAction, ctx);
|
|
219
|
+
if (isToolFailure(confirmed)) throw new Error(confirmed.error);
|
|
220
|
+
expect(confirmed.result.applied).toContain("Harborview Suites");
|
|
221
|
+
// 3 nights at $265.
|
|
222
|
+
expect(confirmed.result.applied).toContain("$795");
|
|
223
|
+
// SETTLED: the gate re-armed as part of the same call.
|
|
224
|
+
expect(confirmed.state).toBe("browsing");
|
|
225
|
+
|
|
226
|
+
const state = stateOf(ctx);
|
|
227
|
+
expect(state.pending).toBeNull();
|
|
228
|
+
expect(state.bookings).toHaveLength(1);
|
|
229
|
+
expect(state.bookings[0]?.reference).toBe(confirmed.result.reference);
|
|
230
|
+
|
|
231
|
+
// The gate re-arms, and now REFUSES rather than reporting an empty apply —
|
|
232
|
+
// `when: "awaitingConfirmation"` is what a second confirm meets.
|
|
233
|
+
//
|
|
234
|
+
// `expectDialogRefused` rather than a regex for the sentence: the refusal is
|
|
235
|
+
// the SDK's, written in one place and matched from another, and it throws on
|
|
236
|
+
// a call that SUCCEEDED — where a `toMatchObject` on a success reads
|
|
237
|
+
// `undefined` for `error` and passes nothing worth reading. The state is
|
|
238
|
+
// pinned too, because "refused" and "refused where the spec thinks the
|
|
239
|
+
// conversation is" are two claims.
|
|
240
|
+
expectDialogRefused(await run(confirmAction, ctx), "browsing");
|
|
268
241
|
});
|
|
269
|
-
expect(await run("cancel_ticket", ctx)).toEqual({ error: "There is no ticket to cancel." });
|
|
270
|
-
});
|
|
271
242
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// unexercised.
|
|
287
|
-
const second = await runTool(cancelTicket, ctx);
|
|
288
|
-
if (!isToolFailure(second)) throw new Error("expected the second staging to be refused");
|
|
289
|
-
// The refusal NAMES what is already waiting, which is what lets the model
|
|
290
|
-
// settle that one and come back rather than guess.
|
|
291
|
-
expect(second.error).toContain("LX52");
|
|
292
|
-
expect(second.error).toMatch(/confirm_action or cancel_action/);
|
|
293
|
-
|
|
294
|
-
// The first staging is untouched, and it is what a yes applies.
|
|
295
|
-
expect(stateOf(ctx).pending).toEqual({ kind: "update_ticket", flightId: "LX52" });
|
|
296
|
-
// A refused SECOND staging must not have moved the gate either — it was
|
|
297
|
-
// already `awaitingConfirmation` and the refusal changed nothing.
|
|
298
|
-
expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
|
|
299
|
-
// `expectToolOk` is `expectDialogOk` with `.result` taken off: this assertion is about
|
|
300
|
-
// what the apply DID, not about where the gate landed.
|
|
301
|
-
const applied = expectToolOk<{ applied: string }>(await run("confirm_action", ctx));
|
|
302
|
-
expect(applied.applied).toContain("LX52");
|
|
303
|
-
expect(stateOf(ctx).bookings).toEqual([]);
|
|
304
|
-
|
|
305
|
-
// Once the queue is clear, the next desk's booking can be staged after all.
|
|
306
|
-
await atDesk("hotel", ctx);
|
|
307
|
-
const retried = expectToolOk(await runTool(bookHotel, { hotelId: "H1", nights: 2 }, ctx));
|
|
308
|
-
expect(retried.awaitingConfirmation).toBe(true);
|
|
309
|
-
});
|
|
243
|
+
test("cancel_action drops the staged change and leaves the booking alone", async () => {
|
|
244
|
+
const ctx = createToolContext();
|
|
245
|
+
await atDesk("flight", ctx);
|
|
246
|
+
await run(updateTicket, { flightId: "LX54" }, ctx);
|
|
247
|
+
const dropped = await run(cancelAction, ctx);
|
|
248
|
+
if (isToolFailure(dropped)) throw new Error(dropped.error);
|
|
249
|
+
expect(dropped.result.discarded).toContain("LX54");
|
|
250
|
+
expect(dropped.state).toBe("browsing");
|
|
251
|
+
|
|
252
|
+
const state = stateOf(ctx);
|
|
253
|
+
expect(state.pending).toBeNull();
|
|
254
|
+
expect(state.ticket?.flightId).toBe("LX40");
|
|
255
|
+
expectDialogRefused(await run(cancelAction, ctx), "browsing");
|
|
256
|
+
});
|
|
310
257
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
258
|
+
test("a staged action naming something that does not exist is refused at staging time", async () => {
|
|
259
|
+
// Refused where the model can still recover — before the caller is asked to
|
|
260
|
+
// confirm a flight the airline does not fly.
|
|
261
|
+
const ctx = createToolContext();
|
|
262
|
+
await atDesk("flight", ctx);
|
|
263
|
+
expect(await run(updateTicket, { flightId: "ZZ99" }, ctx)).toEqual({
|
|
264
|
+
error: "No flight ZZ99 in the schedule.",
|
|
265
|
+
});
|
|
266
|
+
expect(stateOf(ctx).pending).toBeNull();
|
|
267
|
+
});
|
|
320
268
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
expect(activeAssistant(stateOf(second))).toBe("primary");
|
|
335
|
-
expect(stateOf(second).bookings).toEqual([]);
|
|
336
|
-
// The GATE is per-session too, not just the trip.
|
|
337
|
-
expect(gateFlow.position(second).state).toBe("browsing");
|
|
338
|
-
expectDialogRefused(await run("confirm_action", second), "browsing");
|
|
339
|
-
expect(stateOf(first).bookings).toHaveLength(1);
|
|
340
|
-
});
|
|
341
|
-
});
|
|
269
|
+
test("cancelling the ticket makes a later ticket change impossible", async () => {
|
|
270
|
+
const ctx = createToolContext();
|
|
271
|
+
await atDesk("flight", ctx);
|
|
272
|
+
await run(cancelTicket, ctx);
|
|
273
|
+
await run(confirmAction, ctx);
|
|
274
|
+
expect(stateOf(ctx).ticket).toBeNull();
|
|
275
|
+
|
|
276
|
+
expect(await run(updateTicket, { flightId: "LX52" }, ctx)).toEqual({
|
|
277
|
+
error: "This caller has no ticket to move — it was cancelled on this call.",
|
|
278
|
+
});
|
|
279
|
+
expect(await run(cancelTicket, ctx)).toEqual({ error: "There is no ticket to cancel." });
|
|
280
|
+
});
|
|
342
281
|
|
|
343
|
-
|
|
282
|
+
test("a second staging is REFUSED rather than overwriting the first", async () => {
|
|
283
|
+
// The LLM loop runs a step's tool calls concurrently, so two sensitive
|
|
284
|
+
// tools in one step is ordinary: the model hears "move my flight and cancel
|
|
285
|
+
// the old one" and emits both. Assigning `pending` unconditionally made the
|
|
286
|
+
// second win — both answered `awaitingConfirmation`, the caller said yes
|
|
287
|
+
// once, and one of the two changes was silently dropped forever.
|
|
288
|
+
const ctx = createToolContext();
|
|
289
|
+
await atDesk("flight", ctx);
|
|
290
|
+
const first = expectToolOk(await run(updateTicket, { flightId: "LX52" }, ctx));
|
|
291
|
+
expect(first.awaitingConfirmation).toBe(true);
|
|
292
|
+
|
|
293
|
+
// Both from ONE desk, which is what a concurrent pair looks like now that
|
|
294
|
+
// `requireDesk` is enforced. Another desk's tool would be refused by the
|
|
295
|
+
// DESK gate first, which is a different refusal and would leave this one
|
|
296
|
+
// unexercised.
|
|
297
|
+
const second = await run(cancelTicket, ctx);
|
|
298
|
+
if (!isToolFailure(second)) throw new Error("expected the second staging to be refused");
|
|
299
|
+
// The refusal NAMES what is already waiting, which is what lets the model
|
|
300
|
+
// settle that one and come back rather than guess.
|
|
301
|
+
expect(second.error).toContain("LX52");
|
|
302
|
+
expect(second.error).toMatch(/confirm_action or cancel_action/);
|
|
303
|
+
|
|
304
|
+
// The first staging is untouched, and it is what a yes applies.
|
|
305
|
+
expect(stateOf(ctx).pending).toEqual({ kind: "update_ticket", flightId: "LX52" });
|
|
306
|
+
// A refused SECOND staging must not have moved the gate either — it was
|
|
307
|
+
// already `awaitingConfirmation` and the refusal changed nothing.
|
|
308
|
+
expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
|
|
309
|
+
// `expectToolOk` takes the envelope off: this assertion is about what the
|
|
310
|
+
// apply DID, not about where the gate landed.
|
|
311
|
+
const applied = expectToolOk(await run(confirmAction, ctx));
|
|
312
|
+
expect(applied.applied).toContain("LX52");
|
|
313
|
+
expect(stateOf(ctx).bookings).toEqual([]);
|
|
314
|
+
|
|
315
|
+
// Once the queue is clear, the next desk's booking can be staged after all.
|
|
316
|
+
await atDesk("hotel", ctx);
|
|
317
|
+
const retried = expectToolOk(await run(bookHotel, { hotelId: "H1", nights: 2 }, ctx));
|
|
318
|
+
expect(retried.awaitingConfirmation).toBe(true);
|
|
319
|
+
});
|
|
344
320
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
321
|
+
test("cancel_action clears the block, so a declined change does not wedge the desk", async () => {
|
|
322
|
+
const ctx = createToolContext();
|
|
323
|
+
await atDesk("car_rental", ctx);
|
|
324
|
+
await run(bookCarRental, { carId: "C2", days: 3 }, ctx);
|
|
325
|
+
await run(cancelAction, ctx);
|
|
326
|
+
await atDesk("excursion", ctx);
|
|
327
|
+
const staged = expectToolOk(await run(bookExcursion, { excursionId: "E2" }, ctx));
|
|
328
|
+
expect(staged.awaitingConfirmation).toBe(true);
|
|
329
|
+
});
|
|
352
330
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
331
|
+
test("two independent contexts never share a stack, a ticket or an itinerary", async () => {
|
|
332
|
+
// What this really checks: the state lives in the SLOT and not in a
|
|
333
|
+
// module-level variable. `createToolContext()` hands each call its own
|
|
334
|
+
// detached slot store, so the isolation is per CONTEXT — two distinct
|
|
335
|
+
// session ids would prove nothing extra, and `sessionSlot` could stop
|
|
336
|
+
// keying by session with this still passing.
|
|
337
|
+
const first = createToolContext();
|
|
338
|
+
const second = createToolContext();
|
|
339
|
+
|
|
340
|
+
await run(toHotelAssistant, { request: "a room" }, first);
|
|
341
|
+
await run(bookHotel, { hotelId: "H3", nights: 1 }, first);
|
|
342
|
+
await run(confirmAction, first);
|
|
343
|
+
|
|
344
|
+
expect(activeAssistant(stateOf(second))).toBe("primary");
|
|
345
|
+
expect(stateOf(second).bookings).toEqual([]);
|
|
346
|
+
// The GATE is per-session too, not just the trip.
|
|
347
|
+
expect(gateFlow.position(second).state).toBe("browsing");
|
|
348
|
+
expectDialogRefused(await run(confirmAction, second), "browsing");
|
|
349
|
+
expect(stateOf(first).bookings).toHaveLength(1);
|
|
350
|
+
});
|
|
356
351
|
});
|
|
357
352
|
|
|
358
|
-
|
|
359
|
-
const ctx = createToolContext();
|
|
360
|
-
await atDesk("flight", ctx);
|
|
361
|
-
// 17:40 and 21:15 and 19:55 are at or after 17:00; the two morning
|
|
362
|
-
// departures are not. Compared as STRINGS, which is only legal because
|
|
363
|
-
// every reading is zero-padded — the property `isClockTime` is asked for.
|
|
364
|
-
const evening = expectToolOk(await runTool(searchFlights, { departsAfter: "17:00" }, ctx));
|
|
365
|
-
expect(evening.widened).toBe(false);
|
|
366
|
-
expect(evening.flights.map((f) => f.flight)).toEqual(["LX54", "LX15", "LX17"]);
|
|
367
|
-
|
|
368
|
-
// Nothing that late, so the desk widens to the whole schedule rather than
|
|
369
|
-
// telling the caller there is nothing — the same "be generous" arm the
|
|
370
|
-
// route filter has.
|
|
371
|
-
const midnight = expectToolOk(await runTool(searchFlights, { departsAfter: "23:30" }, ctx));
|
|
372
|
-
expect(midnight.widened).toBe(true);
|
|
373
|
-
expect(midnight.flights).toHaveLength(FLIGHTS.length);
|
|
374
|
-
|
|
375
|
-
// The schedule's own half of the same rule: a row whose departure is not a
|
|
376
|
-
// clock reading has nothing to compare, and `departureClock` says so rather
|
|
377
|
-
// than ordering the caller's request against "Tue".
|
|
378
|
-
expect(departureClock(FLIGHTS[0] as Flight)).toBe("13:05");
|
|
379
|
-
expect(departureClock({ ...(FLIGHTS[0] as Flight), departs: "Tuesday" })).toBeUndefined();
|
|
380
|
-
});
|
|
353
|
+
// ─── 3. Search ───────────────────────────────────────────────────────────────
|
|
381
354
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
expect(all.hotels.map((h) => h.perNight)).toEqual(["$179.95", "$265.00", "$340.00"]);
|
|
390
|
-
|
|
391
|
-
const cheap = expectToolOk(
|
|
392
|
-
await runTool(searchHotels, { city: "Boston", maxPerNight: 200 }, ctx),
|
|
393
|
-
);
|
|
394
|
-
expect(cheap.hotels).toHaveLength(1);
|
|
395
|
-
expect(cheap.hotels[0]?.name).toBe("Cambridge Rooms");
|
|
396
|
-
});
|
|
355
|
+
describe("search tools", () => {
|
|
356
|
+
test("an unmatched route widens to the whole schedule rather than answering nothing", async () => {
|
|
357
|
+
const ctx = createToolContext();
|
|
358
|
+
await atDesk("flight", ctx);
|
|
359
|
+
const hit = expectToolOk(await run(searchFlights, { route: "Zurich to Boston" }, ctx));
|
|
360
|
+
expect(hit.widened).toBe(false);
|
|
361
|
+
expect(hit.flights).toHaveLength(3);
|
|
397
362
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
await runTool(searchExcursions, { city: "Boston", keyword: "skiing" }, ctx),
|
|
403
|
-
);
|
|
404
|
-
expect(result.widened).toBe(true);
|
|
405
|
-
expect(result.excursions).toHaveLength(3);
|
|
406
|
-
});
|
|
363
|
+
const miss = expectToolOk(await run(searchFlights, { route: "Osaka" }, ctx));
|
|
364
|
+
expect(miss.widened).toBe(true);
|
|
365
|
+
expect(miss.flights).toHaveLength(FLIGHTS.length);
|
|
366
|
+
});
|
|
407
367
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
368
|
+
test("a departure-time floor filters the schedule, and a bad clock is left out", async () => {
|
|
369
|
+
const ctx = createToolContext();
|
|
370
|
+
await atDesk("flight", ctx);
|
|
371
|
+
// 17:40 and 21:15 and 19:55 are at or after 17:00; the two morning
|
|
372
|
+
// departures are not. Compared as STRINGS, which is only legal because
|
|
373
|
+
// every reading is zero-padded — the property `isClockTime` is asked for.
|
|
374
|
+
const evening = expectToolOk(await run(searchFlights, { departsAfter: "17:00" }, ctx));
|
|
375
|
+
expect(evening.widened).toBe(false);
|
|
376
|
+
expect(evening.flights.map((f) => f.flight)).toEqual(["LX54", "LX15", "LX17"]);
|
|
377
|
+
|
|
378
|
+
// Nothing that late, so the desk widens to the whole schedule rather than
|
|
379
|
+
// telling the caller there is nothing — the same "be generous" arm the
|
|
380
|
+
// route filter has.
|
|
381
|
+
const midnight = expectToolOk(await run(searchFlights, { departsAfter: "23:30" }, ctx));
|
|
382
|
+
expect(midnight.widened).toBe(true);
|
|
383
|
+
expect(midnight.flights).toHaveLength(FLIGHTS.length);
|
|
384
|
+
|
|
385
|
+
// The schedule's own half of the same rule: a row whose departure is not a
|
|
386
|
+
// clock reading has nothing to compare, and `departureClock` says so rather
|
|
387
|
+
// than ordering the caller's request against "Tue".
|
|
388
|
+
expect(departureClock(FLIGHTS[0] as Flight)).toBe("13:05");
|
|
389
|
+
expect(departureClock({ ...(FLIGHTS[0] as Flight), departs: "Tuesday" })).toBeUndefined();
|
|
390
|
+
});
|
|
419
391
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
392
|
+
test("hotels come back cheapest first, and a ceiling filters them", async () => {
|
|
393
|
+
const ctx = createToolContext();
|
|
394
|
+
await atDesk("hotel", ctx);
|
|
395
|
+
const all = expectToolOk(await run(searchHotels, { city: "Boston" }, ctx));
|
|
396
|
+
// Always to the cent: `formatMoney` is one shape at every desk, where
|
|
397
|
+
// this template's own `toLocaleString` copy dropped `.00` on a round
|
|
398
|
+
// number and kept it on a price with change.
|
|
399
|
+
expect(all.hotels.map((h) => h.perNight)).toEqual(["$179.95", "$265.00", "$340.00"]);
|
|
400
|
+
|
|
401
|
+
const cheap = expectToolOk(
|
|
402
|
+
await run(searchHotels, { city: "Boston", maxPerNight: 200 }, ctx),
|
|
403
|
+
);
|
|
404
|
+
expect(cheap.hotels).toHaveLength(1);
|
|
405
|
+
expect(cheap.hotels[0]?.name).toBe("Cambridge Rooms");
|
|
433
406
|
});
|
|
434
|
-
expect(view.ticket?.flightId).toBe("LX40");
|
|
435
|
-
});
|
|
436
407
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
expect(view.pending).toContain("$380");
|
|
447
|
-
expect(view.log.at(-1)).toContain("Awaiting confirmation");
|
|
448
|
-
});
|
|
408
|
+
test("an excursion keyword that matches nothing falls back to the city", async () => {
|
|
409
|
+
const ctx = createToolContext();
|
|
410
|
+
await atDesk("excursion", ctx);
|
|
411
|
+
const result = expectToolOk(
|
|
412
|
+
await run(searchExcursions, { city: "Boston", keyword: "skiing" }, ctx),
|
|
413
|
+
);
|
|
414
|
+
expect(result.widened).toBe(true);
|
|
415
|
+
expect(result.excursions).toHaveLength(3);
|
|
416
|
+
});
|
|
449
417
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
// `179.95 * 3` is `539.8499999999999`, so this is the assertion `roundMoney`
|
|
461
|
-
// is there for: the price is what gets STORED and then summed, and a
|
|
462
|
-
// booking that carries the dust makes every later comparison a coin toss.
|
|
463
|
-
// It would print as $539.85 either way, which is what hides it.
|
|
464
|
-
expect(view.bookings[0]?.price).toBe(539.85);
|
|
465
|
-
expect(view.total).toBe(574.85);
|
|
466
|
-
expect(view.bookings.map((b) => b.kind)).toEqual(["hotel", "excursion"]);
|
|
467
|
-
expect(view.pending).toBeNull();
|
|
418
|
+
test("lookup_booking reports the ticket the caller is actually holding", async () => {
|
|
419
|
+
const ctx = createToolContext();
|
|
420
|
+
await atDesk("flight", ctx);
|
|
421
|
+
await run(updateTicket, { flightId: "LX52" }, ctx);
|
|
422
|
+
await run(confirmAction, ctx);
|
|
423
|
+
const booking = await run(lookupBooking, ctx);
|
|
424
|
+
expect(booking.passenger).toBe("Nadia Rossi");
|
|
425
|
+
expect(booking.ticket?.flight).toBe("LX52");
|
|
426
|
+
expect(booking.ticket?.departs).toBe("Wed 09:20");
|
|
427
|
+
});
|
|
468
428
|
});
|
|
469
|
-
});
|
|
470
429
|
|
|
471
|
-
|
|
472
|
-
test("is capped by the slot, so a long call cannot grow the frame without bound", async () => {
|
|
473
|
-
// The log rides in every `syncState` frame, and it now has writers that are
|
|
474
|
-
// not tool calls at all (`call-events.ts` appends on a reported error), so
|
|
475
|
-
// "how long can this get" is a question with no answer in the tools. The
|
|
476
|
-
// slot's `caps` is the answer, and this is the assertion that it is real.
|
|
477
|
-
const ctx = createToolContext();
|
|
478
|
-
for (let i = 0; i < LOG_CAP + 5; i++) {
|
|
479
|
-
await run("to_flight_assistant", { request: `ask ${i}` }, ctx);
|
|
480
|
-
}
|
|
481
|
-
const log = stateOf(ctx).log;
|
|
482
|
-
expect(log).toHaveLength(LOG_CAP);
|
|
483
|
-
// Capped at the FRONT: what a desk reading the sidebar wants is the end of
|
|
484
|
-
// the call, so the oldest lines are the ones that go.
|
|
485
|
-
expect(log[0]).toContain("ask 5");
|
|
486
|
-
expect(log.at(-1)).toContain(`ask ${LOG_CAP + 4}`);
|
|
487
|
-
});
|
|
488
|
-
});
|
|
430
|
+
// ─── 4. The projection contract with client.tsx ─────────────────────────────
|
|
489
431
|
|
|
490
|
-
describe("
|
|
491
|
-
|
|
492
|
-
|
|
432
|
+
describe("tripView projection", () => {
|
|
433
|
+
test("the slot keeps its contract", () => {
|
|
434
|
+
expectSlotContract(tripSlot, {
|
|
435
|
+
write: (trip) => {
|
|
436
|
+
trip.log.push("a line");
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
});
|
|
493
440
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
// A throw rather than an `expect`: this runs from a helper, and the failure
|
|
508
|
-
// it reports — the agent declares no hook for this event — is a fact about
|
|
509
|
-
// the declaration rather than about the case that called it.
|
|
510
|
-
if (!handler) throw new Error(`no handler is declared for ${event.type}`);
|
|
511
|
-
handler(event, ctx);
|
|
512
|
-
};
|
|
441
|
+
test("an untouched call projects the seeded booking at the concierge desk", () => {
|
|
442
|
+
// Exactly the frame `client.tsx` renders before the first push — it passes
|
|
443
|
+
// this same projection to `useAgentState`.
|
|
444
|
+
const view = tripSlot.projected();
|
|
445
|
+
expect(view).toMatchObject({
|
|
446
|
+
assistant: "primary",
|
|
447
|
+
assistantTitle: "concierge",
|
|
448
|
+
bookings: [],
|
|
449
|
+
total: 0,
|
|
450
|
+
pending: null,
|
|
451
|
+
});
|
|
452
|
+
expect(view.ticket?.flightId).toBe("LX40");
|
|
453
|
+
});
|
|
513
454
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
455
|
+
test("renders the staged action as the prose the concierge just spoke", async () => {
|
|
456
|
+
const ctx = createToolContext();
|
|
457
|
+
await run(toCarRentalAssistant, { request: "a car for the week" }, ctx);
|
|
458
|
+
await run(bookCarRental, { carId: "C3", days: 4 }, ctx);
|
|
459
|
+
|
|
460
|
+
const view = tripView(stateOf(ctx));
|
|
461
|
+
expect(view.assistant).toBe("car_rental");
|
|
462
|
+
expect(view.assistantTitle).toBe("car rental desk");
|
|
463
|
+
// $95/day × 4 — the sidebar and the spoken read-back derive from one string.
|
|
464
|
+
expect(view.pending).toContain("$380");
|
|
465
|
+
expect(view.log.at(-1)).toContain("Awaiting confirmation");
|
|
466
|
+
});
|
|
519
467
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
468
|
+
test("totals every confirmed booking, to the cent", async () => {
|
|
469
|
+
const ctx = createToolContext();
|
|
470
|
+
await atDesk("hotel", ctx);
|
|
471
|
+
await run(bookHotel, { hotelId: "H3", nights: 3 }, ctx); // 3 × 179.95
|
|
472
|
+
await run(confirmAction, ctx);
|
|
473
|
+
await atDesk("excursion", ctx);
|
|
474
|
+
await run(bookExcursion, { excursionId: "E1" }, ctx); // 35
|
|
475
|
+
await run(confirmAction, ctx);
|
|
476
|
+
|
|
477
|
+
const view = tripView(stateOf(ctx));
|
|
478
|
+
// `179.95 * 3` is `539.8499999999999`, so this is the assertion `roundMoney`
|
|
479
|
+
// is there for: the price is what gets STORED and then summed, and a
|
|
480
|
+
// booking that carries the dust makes every later comparison a coin toss.
|
|
481
|
+
// It would print as $539.85 either way, which is what hides it.
|
|
482
|
+
expect(view.bookings[0]?.price).toBe(539.85);
|
|
483
|
+
expect(view.total).toBe(574.85);
|
|
484
|
+
expect(view.bookings.map((b) => b.kind)).toEqual(["hotel", "excursion"]);
|
|
485
|
+
expect(view.pending).toBeNull();
|
|
486
|
+
});
|
|
523
487
|
});
|
|
524
488
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
// line above while losing the property the state exists for.
|
|
539
|
-
expect(gateFlow.position(ctx).state).toBe("abandoned");
|
|
489
|
+
describe("the call log", () => {
|
|
490
|
+
test("is capped by the slot, so a long call cannot grow the frame without bound", async () => {
|
|
491
|
+
const ctx = createToolContext();
|
|
492
|
+
for (let i = 0; i < LOG_CAP + 5; i++) {
|
|
493
|
+
await run(toFlightAssistant, { request: `ask ${i}` }, ctx);
|
|
494
|
+
}
|
|
495
|
+
const log = stateOf(ctx).log;
|
|
496
|
+
expect(log).toHaveLength(LOG_CAP);
|
|
497
|
+
// Capped at the FRONT: what a desk reading the sidebar wants is the end of
|
|
498
|
+
// the call, so the oldest lines are the ones that go.
|
|
499
|
+
expect(log[0]).toContain("ask 5");
|
|
500
|
+
expect(log.at(-1)).toContain(`ask ${LOG_CAP + 4}`);
|
|
501
|
+
});
|
|
540
502
|
});
|
|
541
503
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
await run("book_hotel", { hotelId: "H1", nights: 3 }, ctx);
|
|
546
|
-
gateFlow.receive(ctx, CALLER_GONE);
|
|
547
|
-
|
|
548
|
-
// Stated as a test because it is the feature's sharpest limit: a session
|
|
549
|
-
// event SENDS AN EVENT and cannot run a tool, so `pending` is untouched.
|
|
550
|
-
// That is safe here only because `abandoned` is final — the same shape as a
|
|
551
|
-
// timeout returning to `browsing` would strand a staged change in a call
|
|
552
|
-
// that carries on.
|
|
553
|
-
expect(tripSlot.get(ctx).pending).not.toBeNull();
|
|
554
|
-
});
|
|
504
|
+
describe("a caller who hangs up", () => {
|
|
505
|
+
/** The event the runtime hands a declared dialog when a session times out. */
|
|
506
|
+
const CALLER_GONE = sessionEvent("session.timedOut");
|
|
555
507
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
508
|
+
test("ends the call, from a gate that is holding a staged booking", async () => {
|
|
509
|
+
const ctx = createToolContext();
|
|
510
|
+
await atDesk("hotel", ctx);
|
|
511
|
+
await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
|
|
512
|
+
expect(gateFlow.position(ctx).state).toBe("awaitingConfirmation");
|
|
513
|
+
|
|
514
|
+
await fireEvent(agentDef, CALLER_GONE, ctx);
|
|
515
|
+
const at = gateFlow.position(ctx);
|
|
516
|
+
expect(at.state).toBe("abandoned");
|
|
517
|
+
expect(at.done).toBe(true);
|
|
564
518
|
});
|
|
565
519
|
|
|
566
|
-
|
|
520
|
+
test("a sensitive tool cannot run afterwards", async () => {
|
|
521
|
+
const ctx = createToolContext();
|
|
522
|
+
await atDesk("hotel", ctx);
|
|
523
|
+
await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
|
|
524
|
+
await fireEvent(agentDef, CALLER_GONE, ctx);
|
|
525
|
+
|
|
526
|
+
// The property the state exists for: `confirm_action` is what turns a
|
|
527
|
+
// staged booking into a real one, and nobody is on the call to agree to it.
|
|
528
|
+
expectDialogRefused(await run(confirmAction, ctx), "abandoned");
|
|
529
|
+
// Still abandoned afterwards: refusing once and reopening would lose the
|
|
530
|
+
// property the state exists for.
|
|
531
|
+
expect(gateFlow.position(ctx).state).toBe("abandoned");
|
|
532
|
+
});
|
|
567
533
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
});
|
|
534
|
+
test("the staged action is still THERE — the state is final so nothing reads it", async () => {
|
|
535
|
+
const ctx = createToolContext();
|
|
536
|
+
await atDesk("hotel", ctx);
|
|
537
|
+
await run(bookHotel, { hotelId: "H1", nights: 3 }, ctx);
|
|
538
|
+
await fireEvent(agentDef, CALLER_GONE, ctx);
|
|
574
539
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
540
|
+
// A session event sends an event and cannot run a tool, so `pending` is
|
|
541
|
+
// untouched. Safe only because `abandoned` is final — a timeout returning
|
|
542
|
+
// to `browsing` would strand a staged change in a call that carries on.
|
|
543
|
+
expect(tripSlot.get(ctx).pending).not.toBeNull();
|
|
544
|
+
});
|
|
580
545
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
{ type: "error.reported", meta, code: "tts", message: "voice down", fatal: false },
|
|
589
|
-
ctx,
|
|
590
|
-
);
|
|
591
|
-
deliver(
|
|
592
|
-
{ type: "error.reported", meta, code: "llm", message: "gateway 503", fatal: true },
|
|
593
|
-
ctx,
|
|
594
|
-
);
|
|
546
|
+
test("the call log says the caller went, and names what was never applied", async () => {
|
|
547
|
+
// `abandoned`'s `onEnter` writes the line in the same window the move
|
|
548
|
+
// lands in — a position is not something a desk can read afterwards.
|
|
549
|
+
const ctx = createToolContext();
|
|
550
|
+
tripSlot.update(ctx, (trip) => {
|
|
551
|
+
trip.pending = { kind: "book_hotel", hotelId: "H1", nights: 3 };
|
|
552
|
+
});
|
|
595
553
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
554
|
+
await fireEvent(agentDef, CALLER_GONE, ctx);
|
|
555
|
+
|
|
556
|
+
expect(tripSlot.get(ctx).log.at(-1)).toContain("Caller gone");
|
|
557
|
+
expect(tripSlot.get(ctx).log.at(-1)).toContain("Harborview Suites");
|
|
558
|
+
// A hook records; it does not settle.
|
|
559
|
+
expect(tripSlot.get(ctx).pending).not.toBeNull();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test("with nothing staged it says so, rather than naming an empty change", async () => {
|
|
563
|
+
const ctx = createToolContext();
|
|
564
|
+
await fireEvent(agentDef, CALLER_GONE, ctx);
|
|
565
|
+
expect(tripSlot.get(ctx).log).toEqual(["Caller gone — nothing was waiting."]);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test("an error on the call is recorded too, fatal or not", async () => {
|
|
569
|
+
const ctx = createToolContext();
|
|
570
|
+
// Declared under its own key, so the handler reads `code`, `message` and
|
|
571
|
+
// `fatal` off the event with no narrowing.
|
|
572
|
+
await fireEvent(
|
|
573
|
+
agentDef,
|
|
574
|
+
sessionEvent("error.reported", { code: "tts", message: "voice down", fatal: false }),
|
|
575
|
+
ctx,
|
|
576
|
+
);
|
|
577
|
+
await fireEvent(
|
|
578
|
+
agentDef,
|
|
579
|
+
sessionEvent("error.reported", { code: "llm", message: "gateway 503", fatal: true }),
|
|
580
|
+
ctx,
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
expect(tripSlot.get(ctx).log).toEqual([
|
|
584
|
+
"Trouble on the call (tts): voice down",
|
|
585
|
+
"Call failed (llm): gateway 503",
|
|
586
|
+
]);
|
|
587
|
+
});
|
|
600
588
|
});
|
|
601
589
|
});
|