@alexkroman1/aai-cli 0.12.3 → 0.14.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/README.md +69 -0
- package/bin.mjs +58 -0
- package/dist/_agent-BopNO5Bq.mjs +152 -0
- package/dist/_agent.d.ts +83 -0
- package/dist/_api-client.d.ts +92 -0
- package/dist/_artifacts-BJOYGQPp.mjs +21 -0
- package/dist/_artifacts.d.ts +16 -0
- package/dist/_build-target-C08aM-Es.mjs +1119 -0
- package/dist/_build-target.d.ts +276 -0
- package/dist/_bundler-B6v31ROV.mjs +102 -0
- package/dist/_bundler.d.ts +60 -0
- package/dist/_cli-common.d.ts +173 -0
- package/dist/_client-plugins.d.ts +57 -0
- package/dist/_config-mq1I5Cva.mjs +263 -0
- package/dist/_config.d.ts +122 -0
- package/dist/_console-audio.d.ts +35 -0
- package/dist/_console-session.d.ts +70 -0
- package/dist/_default-html.d.ts +33 -0
- package/dist/_deno-output.d.ts +23 -0
- package/dist/_deno-target.d.ts +74 -0
- package/dist/_deploy.d.ts +22 -0
- package/dist/_dev-agent-env.d.ts +27 -0
- package/dist/_dev-env-D9Uy5wNt.mjs +89 -0
- package/dist/_dev-env.d.ts +77 -0
- package/dist/_dev-restart.d.ts +64 -0
- package/dist/_dev-server-GoEXEVpA.mjs +737 -0
- package/dist/_dev-server.d.ts +89 -0
- package/dist/_dev-session-ticket.d.ts +63 -0
- package/dist/_dev-source.d.ts +55 -0
- package/dist/_dev-tunnel.d.ts +90 -0
- package/dist/_dev-typecheck.d.ts +38 -0
- package/dist/_dev-vite-config.d.ts +100 -0
- package/dist/_dev-watch.d.ts +35 -0
- package/dist/_dotenv-file.d.ts +45 -0
- package/dist/_e2e-test-utils.d.ts +120 -0
- package/dist/_fault-mode.d.ts +194 -0
- package/dist/_help.d.ts +31 -0
- package/dist/_init.d.ts +66 -0
- package/dist/_mock-api.d.ts +22 -0
- package/dist/_mock-registry.d.ts +17 -0
- package/dist/_modal-app.d.ts +77 -0
- package/dist/_modal-output.d.ts +31 -0
- package/dist/_modal-target.d.ts +69 -0
- package/dist/_output-DBP9Op_d.mjs +120 -0
- package/dist/_output.d.ts +74 -0
- package/dist/_preflight-Bv6Ct4ss.mjs +149 -0
- package/dist/_preflight.d.ts +170 -0
- package/dist/_resource-commands.d.ts +54 -0
- package/dist/_run-code-deno-C0AtfHeH.mjs +268 -0
- package/dist/_run-code-deno.d.ts +130 -0
- package/dist/_server-common-CVXIeWrY.mjs +114 -0
- package/dist/_server-common.d.ts +75 -0
- package/dist/_slug-api-BnmTHtjd.mjs +68 -0
- package/dist/_slug-api.d.ts +61 -0
- package/dist/_stop-server.d.ts +17 -0
- package/dist/_studio-B5m4jBTD.mjs +256 -0
- package/dist/_studio-commands.d.ts +73 -0
- package/dist/_studio.d.ts +92 -0
- package/dist/_target-bundle.d.ts +141 -0
- package/dist/_target-drain.d.ts +44 -0
- package/dist/_target-entry.d.ts +81 -0
- package/dist/_target-output.d.ts +63 -0
- package/dist/_templates-BVMVsQh0.mjs +139 -0
- package/dist/_templates.d.ts +89 -0
- package/dist/_typecheck-gate-CcX2gLJZ.mjs +19 -0
- package/dist/_typecheck-gate.d.ts +11 -0
- package/dist/_ui-Coe0zwmm.mjs +102 -0
- package/dist/_ui.d.ts +90 -0
- package/dist/_utils-BVLdBvdT.mjs +186 -0
- package/dist/_utils.d.ts +126 -0
- package/dist/_vercel-output.d.ts +48 -0
- package/dist/_vercel-target.d.ts +169 -0
- package/dist/_vite-env-BiyJ0GQH.mjs +105 -0
- package/dist/_vite-env.d.ts +38 -0
- package/dist/_vitest-runner-CKI8_K1b.mjs +207 -0
- package/dist/_vitest-runner.d.ts +182 -0
- package/dist/_workflow-determinism-CLxFQ5ox.mjs +198 -0
- package/dist/_workflow-determinism.d.ts +118 -0
- package/dist/build-CKhanHVv.mjs +588 -0
- package/dist/build.d.ts +146 -0
- package/dist/cli-workflow.d.ts +17 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +1092 -195
- package/dist/client-bundler-DZ_Zoznn.mjs +241 -0
- package/dist/client-bundler.d.ts +38 -0
- package/dist/client-bundler.mjs +3 -0
- package/dist/console-Dxq26Adz.mjs +447 -0
- package/dist/console.d.ts +70 -0
- package/dist/delete-DwXCHzTl.mjs +55 -0
- package/dist/delete.d.ts +26 -0
- package/dist/deploy-CbA8Ibiu.mjs +97 -0
- package/dist/deploy.d.ts +25 -0
- package/dist/dev-BWBDbUEb.mjs +274 -0
- package/dist/dev.d.ts +34 -0
- package/dist/eval-Dl8o91yC.mjs +74 -0
- package/dist/eval.d.ts +46 -0
- package/dist/init-CidslZZz.mjs +609 -0
- package/dist/init.d.ts +101 -0
- package/dist/login-oJdBWu2B.mjs +166 -0
- package/dist/login.d.ts +54 -0
- package/dist/logs-CnPK-Prw.mjs +102 -0
- package/dist/logs.d.ts +65 -0
- package/dist/project-config.d.ts +23 -0
- package/dist/project-config.mjs +3 -0
- package/dist/scaffold/.env.example +51 -0
- package/dist/scaffold/CLAUDE.md +390 -0
- package/dist/scaffold/agent-guide/AGENT-API.md +223 -0
- package/dist/scaffold/agent-guide/HOSTING.md +139 -0
- package/dist/scaffold/agent-guide/PIPELINE-TUNING.md +232 -0
- package/dist/scaffold/agent-guide/PROVIDERS.md +140 -0
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +158 -0
- package/dist/scaffold/agent-guide/TOOLS.md +627 -0
- package/dist/scaffold/agent-guide/UI.md +292 -0
- package/dist/scaffold/agent-guide/WORKFLOWS.md +803 -0
- package/dist/scaffold/package.json +38 -0
- package/dist/scaffold/pnpm-workspace.yaml +45 -0
- package/dist/scaffold/tsconfig.json +3 -0
- package/dist/scaffold/vitest.config.ts +8 -0
- package/dist/secret-DPdPEet2.mjs +300 -0
- package/dist/secret.d.ts +70 -0
- package/dist/start.d.ts +112 -0
- package/dist/start.mjs +183 -0
- package/dist/studio-COjK25Rl.mjs +208 -0
- package/dist/studio.d.ts +56 -0
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +258 -0
- package/dist/templates/applicant-screening-agent/agent.test.ts +987 -0
- package/dist/templates/applicant-screening-agent/agent.ts +66 -0
- package/dist/templates/applicant-screening-agent/client.tsx +154 -0
- package/dist/templates/applicant-screening-agent/crews.ts +432 -0
- package/dist/templates/applicant-screening-agent/leads.json +86 -0
- package/dist/templates/applicant-screening-agent/screening-lock.test.ts +77 -0
- package/dist/templates/applicant-screening-agent/screening-lock.ts +51 -0
- package/dist/templates/applicant-screening-agent/shared.ts +483 -0
- package/dist/templates/applicant-screening-agent/system-prompt.md +21 -0
- package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +49 -0
- package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +127 -0
- package/dist/templates/applicant-screening-agent/tools/read_email.ts +50 -0
- package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +140 -0
- package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +128 -0
- package/dist/templates/applicant-screening-agent/tools/screening_status.ts +51 -0
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +492 -0
- package/dist/templates/call-audit-workflow/agent.test.ts +1032 -0
- package/dist/templates/call-audit-workflow/agent.ts +161 -0
- package/dist/templates/call-audit-workflow/client.tsx +236 -0
- package/dist/templates/call-audit-workflow/guards.test.ts +233 -0
- package/dist/templates/call-audit-workflow/workflows/audit.ts +391 -0
- package/dist/templates/call-audit-workflow/workflows/ingest.ts +279 -0
- package/dist/templates/call-audit-workflow/workflows/media.ts +729 -0
- package/dist/templates/call-audit-workflow/workflows/summarize.ts +201 -0
- package/dist/templates/call-audit-workflow/workflows/sync-api.ts +54 -0
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +195 -0
- package/dist/templates/code-interpreter-agent/agent.test.ts +91 -0
- package/dist/templates/code-interpreter-agent/agent.ts +9 -0
- package/dist/templates/code-interpreter-agent/system-prompt.md +18 -0
- package/dist/templates/coding-agent/agent.eval.test.ts +135 -0
- package/dist/templates/coding-agent/agent.test.ts +109 -0
- package/dist/templates/coding-agent/agent.ts +45 -0
- package/dist/templates/coding-agent/chat.ts +63 -0
- package/dist/templates/coding-agent/shared.ts +46 -0
- package/dist/templates/coding-agent/system-prompt.md +32 -0
- package/dist/templates/coding-agent/tools/bash.ts +6 -0
- package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
- package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
- package/dist/templates/coding-agent/tools/glob.ts +6 -0
- package/dist/templates/coding-agent/tools/grep.ts +6 -0
- package/dist/templates/coding-agent/tools/list_files.ts +6 -0
- package/dist/templates/coding-agent/tools/read_file.ts +6 -0
- package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
- package/dist/templates/coding-agent/tools/write_file.ts +6 -0
- package/dist/templates/custom-pipeline-agent/agent.eval.test.ts +79 -0
- package/dist/templates/custom-pipeline-agent/agent.test.ts +79 -0
- package/dist/templates/custom-pipeline-agent/agent.ts +13 -0
- package/dist/templates/custom-pipeline-agent/modes.test.ts +162 -0
- package/dist/templates/custom-pipeline-agent/stages.test.ts +330 -0
- package/dist/templates/document-redline-workflow/agent.eval.test.ts +251 -0
- package/dist/templates/document-redline-workflow/agent.test.ts +552 -0
- package/dist/templates/document-redline-workflow/agent.ts +112 -0
- package/dist/templates/document-redline-workflow/client.tsx +224 -0
- package/dist/templates/document-redline-workflow/form.ts +74 -0
- package/dist/templates/document-redline-workflow/workflows/prompts.ts +68 -0
- package/dist/templates/document-redline-workflow/workflows/redline.ts +317 -0
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +372 -0
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +576 -0
- package/dist/templates/emergency-dispatch-agent/agent.ts +63 -0
- package/dist/templates/emergency-dispatch-agent/client.tsx +453 -0
- package/dist/templates/emergency-dispatch-agent/events.ts +48 -0
- package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
- package/dist/templates/emergency-dispatch-agent/shared.ts +768 -0
- package/dist/templates/emergency-dispatch-agent/system-prompt.md +42 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +28 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +95 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +96 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +40 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +90 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +75 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +72 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +27 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +154 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +112 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_get_available.ts +34 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +63 -0
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +281 -0
- package/dist/templates/entertainment-picks-agent/agent.test.ts +260 -0
- package/dist/templates/entertainment-picks-agent/agent.ts +14 -0
- package/dist/templates/entertainment-picks-agent/client.tsx +169 -0
- package/dist/templates/entertainment-picks-agent/shared.ts +50 -0
- package/dist/templates/entertainment-picks-agent/system-prompt.md +19 -0
- package/dist/templates/entertainment-picks-agent/tools/recommend.ts +79 -0
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +56 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +296 -0
- package/dist/templates/executive-inbox-agent/agent.test.ts +682 -0
- package/dist/templates/executive-inbox-agent/agent.ts +51 -0
- package/dist/templates/executive-inbox-agent/calendar.test.ts +203 -0
- package/dist/templates/executive-inbox-agent/client.tsx +195 -0
- package/dist/templates/executive-inbox-agent/inbox.ts +233 -0
- package/dist/templates/executive-inbox-agent/meeting.ts +138 -0
- package/dist/templates/executive-inbox-agent/nodes.ts +148 -0
- package/dist/templates/executive-inbox-agent/prompts.ts +333 -0
- package/dist/templates/executive-inbox-agent/review.ts +425 -0
- package/dist/templates/executive-inbox-agent/shared.ts +486 -0
- package/dist/templates/executive-inbox-agent/system-prompt.md +15 -0
- package/dist/templates/executive-inbox-agent/tools/accept.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/ask_question.ts +30 -0
- package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +67 -0
- package/dist/templates/executive-inbox-agent/tools/edit.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/ignore.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +27 -0
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +52 -0
- package/dist/templates/executive-inbox-agent/tools/new_email.ts +50 -0
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +157 -0
- package/dist/templates/executive-inbox-agent/tools/respond.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/review_memory.ts +22 -0
- package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +68 -0
- package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +75 -0
- package/dist/templates/front-desk-agent/agent.eval.test.ts +177 -0
- package/dist/templates/front-desk-agent/agent.test.ts +155 -0
- package/dist/templates/front-desk-agent/agent.ts +22 -0
- package/dist/templates/front-desk-agent/shared.ts +239 -0
- package/dist/templates/front-desk-agent/system-prompt.md +13 -0
- package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
- package/dist/templates/home-assistant-agent/agent.eval.test.ts +176 -0
- package/dist/templates/home-assistant-agent/agent.test.ts +512 -0
- package/dist/templates/home-assistant-agent/agent.ts +37 -0
- package/dist/templates/home-assistant-agent/client.tsx +176 -0
- package/dist/templates/home-assistant-agent/ring.tsx +55 -0
- package/dist/templates/home-assistant-agent/shared.ts +130 -0
- package/dist/templates/home-assistant-agent/system-prompt.md +43 -0
- package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +16 -0
- package/dist/templates/home-assistant-agent/tools/deep_research.ts +55 -0
- package/dist/templates/home-assistant-agent/tools/remind_me.ts +53 -0
- package/dist/templates/home-assistant-agent/tools/stop.ts +25 -0
- package/dist/templates/home-assistant-agent/use-speaker.ts +98 -0
- package/dist/templates/home-assistant-agent/workflows/remind.ts +25 -0
- package/dist/templates/home-assistant-agent/workflows/research-prompts.ts +41 -0
- package/dist/templates/home-assistant-agent/workflows/research.ts +110 -0
- package/dist/templates/home-assistant-agent/workflows/text.ts +30 -0
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +241 -0
- package/dist/templates/hotel-reception-agent/agent.test.ts +1121 -0
- package/dist/templates/hotel-reception-agent/agent.ts +66 -0
- package/dist/templates/hotel-reception-agent/booking.ts +159 -0
- package/dist/templates/hotel-reception-agent/card.ts +92 -0
- package/dist/templates/hotel-reception-agent/catalogs.ts +219 -0
- package/dist/templates/hotel-reception-agent/client.tsx +150 -0
- package/dist/templates/hotel-reception-agent/concierge.ts +104 -0
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +339 -0
- package/dist/templates/hotel-reception-agent/desk.ts +220 -0
- package/dist/templates/hotel-reception-agent/disputes.ts +214 -0
- package/dist/templates/hotel-reception-agent/events.ts +80 -0
- package/dist/templates/hotel-reception-agent/hotel.ts +412 -0
- package/dist/templates/hotel-reception-agent/policies.ts +209 -0
- package/dist/templates/hotel-reception-agent/records.ts +384 -0
- package/dist/templates/hotel-reception-agent/restaurant.ts +147 -0
- package/dist/templates/hotel-reception-agent/seed.ts +955 -0
- package/dist/templates/hotel-reception-agent/session.ts +50 -0
- package/dist/templates/hotel-reception-agent/shared.ts +353 -0
- package/dist/templates/hotel-reception-agent/system-prompt.md +76 -0
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +31 -0
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +42 -0
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +58 -0
- package/dist/templates/hotel-reception-agent/tools/book_business_center.ts +44 -0
- package/dist/templates/hotel-reception-agent/tools/book_spa_appointment.ts +39 -0
- package/dist/templates/hotel-reception-agent/tools/book_tour.ts +35 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +26 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +64 -0
- package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +24 -0
- package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +93 -0
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +154 -0
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +62 -0
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +91 -0
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +28 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_policy.ts +20 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +75 -0
- package/dist/templates/hotel-reception-agent/tools/order_flowers.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +46 -0
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +51 -0
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +45 -0
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +71 -0
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +65 -0
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +55 -0
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +87 -0
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +29 -0
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +51 -0
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +98 -0
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +58 -0
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +50 -0
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +72 -0
- package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +48 -0
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +46 -0
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +96 -0
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +231 -0
- package/dist/templates/link-digest-workflow/agent.test.ts +646 -0
- package/dist/templates/link-digest-workflow/agent.ts +100 -0
- package/dist/templates/link-digest-workflow/api-client.ts +144 -0
- package/dist/templates/link-digest-workflow/client.tsx +231 -0
- package/dist/templates/link-digest-workflow/workflows/digest.ts +334 -0
- package/dist/templates/medication-safety-agent/agent.eval.test.ts +182 -0
- package/dist/templates/medication-safety-agent/agent.test.ts +329 -0
- package/dist/templates/medication-safety-agent/agent.ts +62 -0
- package/dist/templates/medication-safety-agent/fda.test.ts +129 -0
- package/dist/templates/medication-safety-agent/fda.ts +166 -0
- package/dist/templates/medication-safety-agent/system-prompt.md +26 -0
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +70 -0
- package/dist/templates/medication-safety-agent/tools/medication_lookup.ts +46 -0
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +459 -0
- package/dist/templates/meeting-recap-agent/agent.test.ts +1408 -0
- package/dist/templates/meeting-recap-agent/agent.ts +104 -0
- package/dist/templates/meeting-recap-agent/shared.ts +44 -0
- package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +23 -0
- package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +31 -0
- package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +24 -0
- package/dist/templates/meeting-recap-agent/tools/recap_status.ts +45 -0
- package/dist/templates/meeting-recap-agent/tools/request_recap.ts +44 -0
- package/dist/templates/meeting-recap-agent/workflows/recap.ts +838 -0
- package/dist/templates/meeting-recap-agent/workflows/tokens.ts +47 -0
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +228 -0
- package/dist/templates/pizza-ordering-agent/agent.test.ts +299 -0
- package/dist/templates/pizza-ordering-agent/agent.ts +24 -0
- package/dist/templates/pizza-ordering-agent/client.tsx +104 -0
- package/dist/templates/pizza-ordering-agent/shared.ts +225 -0
- package/dist/templates/pizza-ordering-agent/system-prompt.md +23 -0
- package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +27 -0
- package/dist/templates/pizza-ordering-agent/tools/place_order.ts +26 -0
- package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +18 -0
- package/dist/templates/pizza-ordering-agent/tools/set_customer_name.ts +13 -0
- package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +28 -0
- package/dist/templates/pizza-ordering-agent/tools/view_order.ts +21 -0
- package/dist/templates/podcast-digest-workflow/agent.eval.test.ts +421 -0
- package/dist/templates/podcast-digest-workflow/agent.test.ts +1225 -0
- package/dist/templates/podcast-digest-workflow/agent.ts +143 -0
- package/dist/templates/podcast-digest-workflow/client.tsx +259 -0
- package/dist/templates/podcast-digest-workflow/workflows/digest.ts +499 -0
- package/dist/templates/podcast-digest-workflow/workflows/feeds.ts +575 -0
- package/dist/templates/podcast-digest-workflow/workflows/slack.ts +153 -0
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +78 -0
- package/dist/templates/push-to-talk-agent/agent.test.ts +63 -0
- package/dist/templates/push-to-talk-agent/agent.ts +22 -0
- package/dist/templates/push-to-talk-agent/client.tsx +124 -0
- package/dist/templates/push-to-talk-agent/shared.ts +28 -0
- package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +148 -0
- package/dist/templates/quickstart-agent/agent.test.ts +96 -0
- package/dist/templates/quickstart-agent/agent.ts +25 -0
- package/dist/templates/quickstart-agent/system-prompt.md +8 -0
- package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +348 -0
- package/dist/templates/research-handoff-agent/agent.test.ts +818 -0
- package/dist/templates/research-handoff-agent/agent.ts +118 -0
- package/dist/templates/research-handoff-agent/shared.ts +41 -0
- package/dist/templates/research-handoff-agent/tools/file_it_now.ts +32 -0
- package/dist/templates/research-handoff-agent/tools/request_research.ts +33 -0
- package/dist/templates/research-handoff-agent/tools/research_progress.ts +23 -0
- package/dist/templates/research-handoff-agent/tools/research_status.ts +73 -0
- package/dist/templates/research-handoff-agent/workflows/filing.ts +164 -0
- package/dist/templates/research-handoff-agent/workflows/prompts.ts +46 -0
- package/dist/templates/research-handoff-agent/workflows/research.ts +100 -0
- package/dist/templates/research-handoff-agent/workflows/review.ts +43 -0
- package/dist/templates/research-planner-agent/agent.eval.test.ts +241 -0
- package/dist/templates/research-planner-agent/agent.test.ts +640 -0
- package/dist/templates/research-planner-agent/agent.ts +26 -0
- package/dist/templates/research-planner-agent/client.tsx +120 -0
- package/dist/templates/research-planner-agent/procedure.ts +287 -0
- package/dist/templates/research-planner-agent/prompts.ts +153 -0
- package/dist/templates/research-planner-agent/shared.ts +356 -0
- package/dist/templates/research-planner-agent/system-prompt.md +18 -0
- package/dist/templates/research-planner-agent/tools/plan_status.ts +41 -0
- package/dist/templates/research-planner-agent/tools/revise_plan.ts +71 -0
- package/dist/templates/research-planner-agent/tools/start_plan.ts +62 -0
- package/dist/templates/research-planner-agent/tools/work_next_step.ts +177 -0
- package/dist/templates/retail-orders-agent/address.ts +109 -0
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +305 -0
- package/dist/templates/retail-orders-agent/agent.test.ts +1260 -0
- package/dist/templates/retail-orders-agent/agent.ts +103 -0
- package/dist/templates/retail-orders-agent/authenticate.ts +34 -0
- package/dist/templates/retail-orders-agent/cancel.ts +114 -0
- package/dist/templates/retail-orders-agent/client.tsx +579 -0
- package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
- package/dist/templates/retail-orders-agent/payment.ts +103 -0
- package/dist/templates/retail-orders-agent/pending.test.ts +204 -0
- package/dist/templates/retail-orders-agent/pending.ts +137 -0
- package/dist/templates/retail-orders-agent/refund.ts +19 -0
- package/dist/templates/retail-orders-agent/registry.test.ts +446 -0
- package/dist/templates/retail-orders-agent/resolve.test.ts +100 -0
- package/dist/templates/retail-orders-agent/resolve.ts +114 -0
- package/dist/templates/retail-orders-agent/returns.ts +101 -0
- package/dist/templates/retail-orders-agent/seed.json +4260 -0
- package/dist/templates/retail-orders-agent/seed.test.ts +233 -0
- package/dist/templates/retail-orders-agent/shared.test.ts +240 -0
- package/dist/templates/retail-orders-agent/shared.ts +547 -0
- package/dist/templates/retail-orders-agent/store.test.ts +331 -0
- package/dist/templates/retail-orders-agent/store.ts +485 -0
- package/dist/templates/retail-orders-agent/swap.test.ts +189 -0
- package/dist/templates/retail-orders-agent/swap.ts +358 -0
- package/dist/templates/retail-orders-agent/system-prompt.md +152 -0
- package/dist/templates/retail-orders-agent/tools/cancel_change.ts +33 -0
- package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +31 -0
- package/dist/templates/retail-orders-agent/tools/confirm_change.ts +42 -0
- package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +47 -0
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +31 -0
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +36 -0
- package/dist/templates/retail-orders-agent/tools/get_item_details.ts +27 -0
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/get_product_details.ts +30 -0
- package/dist/templates/retail-orders-agent/tools/get_user_details.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +22 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +27 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +48 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +32 -0
- package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +26 -0
- package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +28 -0
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +283 -0
- package/dist/templates/roadside-assistance-agent/agent.test.ts +650 -0
- package/dist/templates/roadside-assistance-agent/agent.ts +89 -0
- package/dist/templates/roadside-assistance-agent/call.ts +232 -0
- package/dist/templates/roadside-assistance-agent/events.ts +92 -0
- package/dist/templates/roadside-assistance-agent/shared.ts +346 -0
- package/dist/templates/roadside-assistance-agent/system-prompt.md +37 -0
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +61 -0
- package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +149 -0
- package/dist/templates/roadside-assistance-agent/tools/job_status.ts +38 -0
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +83 -0
- package/dist/templates/roadside-assistance-agent/tools/report_location.ts +79 -0
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +51 -0
- package/dist/templates/roadside-assistance-agent/yard.test.ts +162 -0
- package/dist/templates/roadside-assistance-agent/yard.ts +183 -0
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +354 -0
- package/dist/templates/spoken-summary-workflow/agent.test.ts +493 -0
- package/dist/templates/spoken-summary-workflow/agent.ts +164 -0
- package/dist/templates/spoken-summary-workflow/client.tsx +220 -0
- package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +260 -0
- package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +137 -0
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +314 -0
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +1000 -0
- package/dist/templates/tabletop-rpg-agent/agent.ts +58 -0
- package/dist/templates/tabletop-rpg-agent/client.tsx +814 -0
- package/dist/templates/tabletop-rpg-agent/shared.ts +1028 -0
- package/dist/templates/tabletop-rpg-agent/system-prompt.md +116 -0
- package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +119 -0
- package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +110 -0
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +37 -0
- package/dist/templates/tabletop-rpg-agent/tools/oracle.ts +255 -0
- package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +228 -0
- package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +194 -0
- package/dist/templates/technical-support-agent/agent.eval.test.ts +260 -0
- package/dist/templates/technical-support-agent/agent.test.ts +424 -0
- package/dist/templates/technical-support-agent/agent.ts +39 -0
- package/dist/templates/technical-support-agent/client.tsx +132 -0
- package/dist/templates/technical-support-agent/knowledge.json +65 -0
- package/dist/templates/technical-support-agent/knowledge.ts +165 -0
- package/dist/templates/technical-support-agent/nodes.ts +143 -0
- package/dist/templates/technical-support-agent/procedure.ts +453 -0
- package/dist/templates/technical-support-agent/prompts.ts +102 -0
- package/dist/templates/technical-support-agent/shared.ts +128 -0
- package/dist/templates/technical-support-agent/system-prompt.md +18 -0
- package/dist/templates/technical-support-agent/tools/answer_question.ts +134 -0
- package/dist/templates/technical-support-agent/tools/list_topics.ts +23 -0
- package/dist/templates/technical-support-agent/tools/log_ticket.ts +30 -0
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +222 -0
- package/dist/templates/text-adventure-agent/agent.test.ts +429 -0
- package/dist/templates/text-adventure-agent/agent.ts +76 -0
- package/dist/templates/text-adventure-agent/client.tsx +359 -0
- package/dist/templates/text-adventure-agent/shared.ts +210 -0
- package/dist/templates/text-adventure-agent/system-prompt.md +50 -0
- package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +29 -0
- package/dist/templates/text-adventure-agent/tools/game_state_flag.ts +13 -0
- package/dist/templates/text-adventure-agent/tools/game_state_get.ts +17 -0
- package/dist/templates/text-adventure-agent/tools/game_state_move.ts +15 -0
- package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +13 -0
- package/dist/templates/text-adventure-agent/tools/game_state_score.ts +19 -0
- package/dist/templates/text-adventure-agent/tools/game_state_take.ts +13 -0
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +202 -0
- package/dist/templates/topic-briefing-agent/agent.test.ts +651 -0
- package/dist/templates/topic-briefing-agent/agent.ts +45 -0
- package/dist/templates/topic-briefing-agent/shared.ts +392 -0
- package/dist/templates/topic-briefing-agent/slack.ts +108 -0
- package/dist/templates/topic-briefing-agent/system-prompt.md +54 -0
- package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +43 -0
- package/dist/templates/topic-briefing-agent/tools/research_topic.ts +80 -0
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +115 -0
- package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +123 -0
- package/dist/templates/transcription-workflow/agent.eval.test.ts +237 -0
- package/dist/templates/transcription-workflow/agent.test.ts +2033 -0
- package/dist/templates/transcription-workflow/agent.ts +188 -0
- package/dist/templates/transcription-workflow/client.tsx +511 -0
- package/dist/templates/transcription-workflow/recover.test.ts +219 -0
- package/dist/templates/transcription-workflow/recover.ts +154 -0
- package/dist/templates/transcription-workflow/run-panel.tsx +212 -0
- package/dist/templates/transcription-workflow/total-latency.tsx +170 -0
- package/dist/templates/transcription-workflow/workflows/batch.ts +189 -0
- package/dist/templates/transcription-workflow/workflows/downsample.ts +273 -0
- package/dist/templates/transcription-workflow/workflows/normalize.ts +385 -0
- package/dist/templates/transcription-workflow/workflows/stitch.ts +122 -0
- package/dist/templates/transcription-workflow/workflows/stream.ts +690 -0
- package/dist/templates/transcription-workflow/workflows/sync-api.ts +81 -0
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +479 -0
- package/dist/templates/transcription-workflow/workflows/wav.ts +250 -0
- package/dist/templates/travel-concierge-agent/agent.eval.test.ts +300 -0
- package/dist/templates/travel-concierge-agent/agent.test.ts +601 -0
- package/dist/templates/travel-concierge-agent/agent.ts +62 -0
- package/dist/templates/travel-concierge-agent/call-events.ts +80 -0
- package/dist/templates/travel-concierge-agent/client.tsx +146 -0
- package/dist/templates/travel-concierge-agent/routing.ts +170 -0
- package/dist/templates/travel-concierge-agent/shared.ts +862 -0
- package/dist/templates/travel-concierge-agent/system-prompt.md +30 -0
- package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +19 -0
- package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/cancel_action.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/complete_or_escalate.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/confirm_action.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/lookup_booking.ts +36 -0
- package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +36 -0
- package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +40 -0
- package/dist/templates/travel-concierge-agent/tools/search_flights.ts +58 -0
- package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +39 -0
- package/dist/templates/travel-concierge-agent/tools/to_car_rental_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_excursion_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_flight_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_hotel_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +23 -0
- package/dist/templates/web-research-agent/agent.eval.test.ts +144 -0
- package/dist/templates/web-research-agent/agent.test.ts +182 -0
- package/dist/templates/web-research-agent/agent.ts +128 -0
- package/dist/templates/web-research-agent/system-prompt.md +33 -0
- package/dist/templates/word-game-agent/agent.eval.test.ts +222 -0
- package/dist/templates/word-game-agent/agent.test.ts +490 -0
- package/dist/templates/word-game-agent/agent.ts +55 -0
- package/dist/templates/word-game-agent/client.tsx +211 -0
- package/dist/templates/word-game-agent/game.ts +133 -0
- package/dist/templates/word-game-agent/guess.ts +63 -0
- package/dist/templates/word-game-agent/player.ts +67 -0
- package/dist/templates/word-game-agent/shared.ts +249 -0
- package/dist/templates/word-game-agent/system-prompt.md +15 -0
- package/dist/templates/word-game-agent/tools/final_score.ts +37 -0
- package/dist/templates/word-game-agent/tools/relay_description.ts +137 -0
- package/dist/templates/word-game-agent/tools/repeat_word.ts +19 -0
- package/dist/templates/word-game-agent/tools/skip_word.ts +31 -0
- package/dist/templates/word-game-agent/tools/start_game.ts +52 -0
- package/dist/templates/word-game-agent/words.ts +278 -0
- package/dist/test-XufelYGW.mjs +104 -0
- package/dist/test.d.ts +81 -0
- package/dist/typecheck.d.ts +44 -0
- package/dist/typecheck.mjs +185 -0
- package/dist/worker-bundler.d.ts +37 -0
- package/dist/worker-bundler.mjs +156 -0
- package/dist/workflow-CDUlTD5B.mjs +239 -0
- package/dist/workflow.d.ts +76 -0
- package/package.json +74 -28
- package/dist/_api-client-H4MFOr8j.mjs +0 -35
- package/dist/_bundler-DQtFVeww.mjs +0 -125
- package/dist/_discover-DzsMlg3G.mjs +0 -218
- package/dist/_init-CbMs9S2O.mjs +0 -56
- package/dist/_templates-BDkbj3TM.mjs +0 -72
- package/dist/_ui-DWGXImbO.mjs +0 -30
- package/dist/delete-CalIL6Pg.mjs +0 -34
- package/dist/deploy-CLs8gLHV.mjs +0 -53
- package/dist/dev-DEZKrw8v.mjs +0 -18
- package/dist/init-CNuntiij.mjs +0 -114
- package/dist/secret-xmLQ96Yz.mjs +0 -46
- package/dist/test-yqHGZPF3.mjs +0 -44
|
@@ -0,0 +1,862 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The concierge's booking world, its dialog stack, and its confirmation gate.
|
|
3
|
+
*
|
|
4
|
+
* **Adapted from LangGraph's customer-support tutorial** (MIT,
|
|
5
|
+
* <https://github.com/langchain-ai/langgraph>,
|
|
6
|
+
* `docs/docs/tutorials/customer-support/customer-support.ipynb`) — the Swiss
|
|
7
|
+
* Airlines support bot. Two things in it are the reason to take its shape
|
|
8
|
+
* rather than invent one, and both land differently over a phone than in a
|
|
9
|
+
* chat window:
|
|
10
|
+
*
|
|
11
|
+
* | customer-support | here |
|
|
12
|
+
* | --- | --- |
|
|
13
|
+
* | `State.dialog_state` (an annotated push/pop stack) | {@link TripState.dialogState} |
|
|
14
|
+
* | `ToFlightBookingAssistant` & friends (delegation tools) | the four tools {@link SPECIALISTS} generates in `routing.ts` |
|
|
15
|
+
* | `CompleteOrEscalate` | `complete_or_escalate`, which pops the same stack |
|
|
16
|
+
* | `interrupt_before=["…_sensitive_tools"]` | {@link stageAction} + `confirm_action` |
|
|
17
|
+
* | a specialist node's BOUND tool set | {@link deskTool} / {@link deskUpdateTool}, which every desk tool is declared through |
|
|
18
|
+
* | `fetch_user_flight_information` (sqlite) | `lookup_booking` over {@link seedTrip} |
|
|
19
|
+
*
|
|
20
|
+
* **The dialog stack is what keeps a long call on the rails.** Their insight is
|
|
21
|
+
* that one prompt holding every tool degrades as the tool list grows, so the
|
|
22
|
+
* primary assistant delegates to a specialist and the specialist works with a
|
|
23
|
+
* narrow brief. The specialist's brief arrives as the DELEGATION TOOL'S RESULT,
|
|
24
|
+
* which is the last thing the model reads before it answers.
|
|
25
|
+
*
|
|
26
|
+
* That used to be stated here as a hard limit — "a voice agent cannot swap its
|
|
27
|
+
* system prompt mid-session" — and it is no longer true in general: a state's
|
|
28
|
+
* `instruction` reaches the model on EVERY turn now, on the pipeline and on
|
|
29
|
+
* OpenAI Realtime (AssemblyAI S2S still resolves once). It stays true for THIS
|
|
30
|
+
* template, for a different reason: the desks are a STACK in a session slot,
|
|
31
|
+
* not a dialog position, and a dialog holds one position per session where a
|
|
32
|
+
* stack holds several. Reaching for the new mechanism here would mean modelling
|
|
33
|
+
* the desks as states, which is the port's own design question rather than a
|
|
34
|
+
* fix. The stack itself is real state either way, which is what
|
|
35
|
+
* `complete_or_escalate` pops and what the sidebar renders — and what
|
|
36
|
+
* {@link deskTool} makes binding, so the position is never merely a label on
|
|
37
|
+
* work that happened somewhere else.
|
|
38
|
+
*
|
|
39
|
+
* **`interrupt_before` becomes a spoken confirmation, and that is not a
|
|
40
|
+
* downgrade.** Their graph halts before a sensitive tool and waits for a human
|
|
41
|
+
* to approve in the notebook; a caller cannot type "y", but asking out loud and
|
|
42
|
+
* hearing "yes" is the same gate with a better interface. So a sensitive tool
|
|
43
|
+
* never mutates: it STAGES a {@link PendingAction} and returns the sentence the
|
|
44
|
+
* model should read back, and `confirm_action` is the only thing that applies
|
|
45
|
+
* one. The mechanism is worth copying whole — it is the difference between an
|
|
46
|
+
* agent that can rebook a flight and one that can rebook a flight *by mistake*.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import {
|
|
50
|
+
type DeepReadonly,
|
|
51
|
+
type DialogSpec,
|
|
52
|
+
dialog,
|
|
53
|
+
isClockTime,
|
|
54
|
+
type SlotToolDef,
|
|
55
|
+
sessionSlot,
|
|
56
|
+
type ToolContext,
|
|
57
|
+
type ToolDef,
|
|
58
|
+
type ToolFailure,
|
|
59
|
+
type ToolInputSchema,
|
|
60
|
+
} from "@alexkroman1/aai";
|
|
61
|
+
import { formatMoney, plural, roundMoney } from "@alexkroman1/aai/utils";
|
|
62
|
+
|
|
63
|
+
// ─── The booking world ───────────────────────────────────────────────────────
|
|
64
|
+
// Their notebook downloads a sqlite database of a real airline's schedule and
|
|
65
|
+
// rewrites its timestamps to "now". A template ships no database, so the world
|
|
66
|
+
// is a handful of frozen rows — enough for every tool to return something a
|
|
67
|
+
// caller could act on, and small enough to read.
|
|
68
|
+
|
|
69
|
+
export interface Flight {
|
|
70
|
+
id: string;
|
|
71
|
+
route: string;
|
|
72
|
+
departs: string;
|
|
73
|
+
arrives: string;
|
|
74
|
+
fare: number;
|
|
75
|
+
seatsLeft: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface Hotel {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
city: string;
|
|
82
|
+
area: string;
|
|
83
|
+
pricePerNight: number;
|
|
84
|
+
stars: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface CarRental {
|
|
88
|
+
id: string;
|
|
89
|
+
vendor: string;
|
|
90
|
+
city: string;
|
|
91
|
+
tier: string;
|
|
92
|
+
pricePerDay: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface Excursion {
|
|
96
|
+
id: string;
|
|
97
|
+
name: string;
|
|
98
|
+
city: string;
|
|
99
|
+
kind: string;
|
|
100
|
+
price: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const FLIGHTS: Flight[] = [
|
|
104
|
+
{
|
|
105
|
+
id: "LX40",
|
|
106
|
+
route: "Zurich to Boston",
|
|
107
|
+
departs: "Tue 13:05",
|
|
108
|
+
arrives: "Tue 15:45",
|
|
109
|
+
fare: 640,
|
|
110
|
+
seatsLeft: 9,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "LX52",
|
|
114
|
+
route: "Zurich to Boston",
|
|
115
|
+
departs: "Wed 09:20",
|
|
116
|
+
arrives: "Wed 12:05",
|
|
117
|
+
fare: 590,
|
|
118
|
+
seatsLeft: 2,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "LX54",
|
|
122
|
+
route: "Zurich to Boston",
|
|
123
|
+
departs: "Thu 17:40",
|
|
124
|
+
arrives: "Thu 20:25",
|
|
125
|
+
fare: 505,
|
|
126
|
+
seatsLeft: 21,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "LX15",
|
|
130
|
+
route: "Boston to Zurich",
|
|
131
|
+
departs: "Sun 21:15",
|
|
132
|
+
arrives: "Mon 10:40",
|
|
133
|
+
fare: 615,
|
|
134
|
+
seatsLeft: 6,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "LX17",
|
|
138
|
+
route: "Boston to Zurich",
|
|
139
|
+
departs: "Mon 19:55",
|
|
140
|
+
arrives: "Tue 09:30",
|
|
141
|
+
fare: 700,
|
|
142
|
+
seatsLeft: 14,
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
export const HOTELS: Hotel[] = [
|
|
147
|
+
{
|
|
148
|
+
id: "H1",
|
|
149
|
+
name: "Harborview Suites",
|
|
150
|
+
city: "Boston",
|
|
151
|
+
area: "Seaport",
|
|
152
|
+
pricePerNight: 265,
|
|
153
|
+
stars: 4,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "H2",
|
|
157
|
+
name: "The Back Bay",
|
|
158
|
+
city: "Boston",
|
|
159
|
+
area: "Back Bay",
|
|
160
|
+
pricePerNight: 340,
|
|
161
|
+
stars: 5,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
// The one rate with cents in it, and it is deliberate: three nights here is
|
|
165
|
+
// `179.95 * 3 === 539.8499999999999`, so this row is what makes
|
|
166
|
+
// {@link roundMoney} load-bearing rather than decorative — see the totals in
|
|
167
|
+
// `applyPending` and {@link tripView}.
|
|
168
|
+
id: "H3",
|
|
169
|
+
name: "Cambridge Rooms",
|
|
170
|
+
city: "Boston",
|
|
171
|
+
area: "Cambridge",
|
|
172
|
+
pricePerNight: 179.95,
|
|
173
|
+
stars: 3,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: "H4",
|
|
177
|
+
name: "Limmat Riverside",
|
|
178
|
+
city: "Zurich",
|
|
179
|
+
area: "Old Town",
|
|
180
|
+
pricePerNight: 295,
|
|
181
|
+
stars: 4,
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
export const CAR_RENTALS: CarRental[] = [
|
|
186
|
+
{ id: "C1", vendor: "Alpine Rentals", city: "Boston", tier: "compact", pricePerDay: 48 },
|
|
187
|
+
{ id: "C2", vendor: "Alpine Rentals", city: "Boston", tier: "midsize", pricePerDay: 62 },
|
|
188
|
+
{ id: "C3", vendor: "Harbor Auto", city: "Boston", tier: "suv", pricePerDay: 95 },
|
|
189
|
+
{ id: "C4", vendor: "Limmat Cars", city: "Zurich", tier: "compact", pricePerDay: 54 },
|
|
190
|
+
];
|
|
191
|
+
|
|
192
|
+
export const EXCURSIONS: Excursion[] = [
|
|
193
|
+
{ id: "E1", name: "Freedom Trail walk", city: "Boston", kind: "walking tour", price: 35 },
|
|
194
|
+
{ id: "E2", name: "Harbor sunset sail", city: "Boston", kind: "boat", price: 78 },
|
|
195
|
+
{ id: "E3", name: "North End food crawl", city: "Boston", kind: "food", price: 95 },
|
|
196
|
+
{ id: "E4", name: "Lake Zurich cruise", city: "Zurich", kind: "boat", price: 52 },
|
|
197
|
+
];
|
|
198
|
+
|
|
199
|
+
// ─── The dialog stack ────────────────────────────────────────────────────────
|
|
200
|
+
|
|
201
|
+
export const SPECIALIST_IDS = ["flight", "hotel", "car_rental", "excursion"] as const;
|
|
202
|
+
export type SpecialistId = (typeof SPECIALIST_IDS)[number];
|
|
203
|
+
|
|
204
|
+
/** Who is holding the call. `"primary"` is the host assistant — their
|
|
205
|
+
* `dialog_state` bottom, reached by popping everything else off. */
|
|
206
|
+
export type DialogState = "primary" | SpecialistId;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* One specialist's brief, handed back as the delegation tool's RESULT.
|
|
210
|
+
*
|
|
211
|
+
* The instructions are adapted from the four `…_prompt` templates in the
|
|
212
|
+
* notebook, compressed for a phone: theirs end in a paragraph about not making
|
|
213
|
+
* up tools, which a chat model needs and a voice model has no room for. What is
|
|
214
|
+
* kept verbatim in spirit is the part that does the work — search persistently,
|
|
215
|
+
* confirm the details back, and escalate rather than improvise.
|
|
216
|
+
*/
|
|
217
|
+
export interface Specialist {
|
|
218
|
+
/** What the caller hears this desk called. */
|
|
219
|
+
title: string;
|
|
220
|
+
/** The brief the model is handed on delegation. */
|
|
221
|
+
instructions: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Each brief spells the STAGE-then-read-back ORDER out, and that is a fix
|
|
226
|
+
* measured rather than a preference.
|
|
227
|
+
*
|
|
228
|
+
* The flight desk's used to say "read the fare change back to the caller before
|
|
229
|
+
* you change a ticket", which is true of `confirm_action` and reads as a rule
|
|
230
|
+
* about `update_ticket` — and live, that is how it was read: the desk searched,
|
|
231
|
+
* quoted a fare it had not staged, waited for a yes, and then called
|
|
232
|
+
* `confirm_action` with nothing waiting for it. Two of three runs never staged
|
|
233
|
+
* anything at all. The sentence to read back IS the staging tool's return
|
|
234
|
+
* value, so a brief that puts the read-back first describes a call the desk
|
|
235
|
+
* cannot make.
|
|
236
|
+
*/
|
|
237
|
+
export const SPECIALISTS: Record<SpecialistId, Specialist> = {
|
|
238
|
+
flight: {
|
|
239
|
+
title: "flight desk",
|
|
240
|
+
instructions: [
|
|
241
|
+
"You are now the flight desk. Handle searching and changing flights only.",
|
|
242
|
+
"Search before you quote anything, and be persistent: if the first search",
|
|
243
|
+
"finds nothing, widen it rather than telling the caller there is nothing.",
|
|
244
|
+
"update_ticket is a QUOTE, not a change: it moves nothing, so call it as",
|
|
245
|
+
"soon as you know which flight they want and never ask permission first.",
|
|
246
|
+
"Changing a ticket is TWO steps and never one: call update_ticket first —",
|
|
247
|
+
"it changes nothing and hands you the sentence to say — then read the",
|
|
248
|
+
"flight number, the day, the departure time and the fare change back to",
|
|
249
|
+
"the caller and ask them plainly to confirm. A ticket is only changed once",
|
|
250
|
+
"confirm_action has run, and confirm_action has nothing to apply until",
|
|
251
|
+
"update_ticket has staged it.",
|
|
252
|
+
"Never quote a departure time or a fare you did not just read out of a",
|
|
253
|
+
"tool result, and never end a turn on 'shall I confirm?' with nothing",
|
|
254
|
+
"staged: update_ticket goes out in the SAME turn as that question, before",
|
|
255
|
+
"you stop. There is nothing for a yes to apply until it has.",
|
|
256
|
+
"Your next action, right now, is a TOOL and not a sentence: call",
|
|
257
|
+
"update_ticket if you already know which flight they want, or",
|
|
258
|
+
"search_flights if you do not. Do not speak until one of them has",
|
|
259
|
+
"answered — anything you would say before that is invented.",
|
|
260
|
+
"If the caller wants a hotel, a car or something to do, or changes their",
|
|
261
|
+
"mind, call complete_or_escalate instead of improvising.",
|
|
262
|
+
].join(" "),
|
|
263
|
+
},
|
|
264
|
+
hotel: {
|
|
265
|
+
title: "hotel desk",
|
|
266
|
+
instructions: [
|
|
267
|
+
"You are now the hotel desk. Handle searching and booking hotels only.",
|
|
268
|
+
"Ask which city and roughly what budget, then search. Offer at most three",
|
|
269
|
+
"options out loud, cheapest first, with the neighbourhood and nightly rate.",
|
|
270
|
+
"book_hotel is a QUOTE, not a change: it holds nothing, so call it as",
|
|
271
|
+
"soon as you know what the caller wants and never ask permission",
|
|
272
|
+
"first.",
|
|
273
|
+
"Booking is TWO steps and never one: call book_hotel first — it holds",
|
|
274
|
+
"nothing and hands you the sentence to say — then read the hotel, the",
|
|
275
|
+
"number of nights and the total back and ask them to confirm. A room is",
|
|
276
|
+
"only held once confirm_action has run, and confirm_action has nothing to",
|
|
277
|
+
"apply until book_hotel has staged it.",
|
|
278
|
+
"Your next action, right now, is a TOOL and not a sentence: call",
|
|
279
|
+
"book_hotel if you already know which room and how many nights, or",
|
|
280
|
+
"search_hotels if you do not. Do not speak until one of them has",
|
|
281
|
+
"answered — anything you would say before that is invented.",
|
|
282
|
+
"If the caller wants flights, a car or an excursion, call",
|
|
283
|
+
"complete_or_escalate.",
|
|
284
|
+
].join(" "),
|
|
285
|
+
},
|
|
286
|
+
car_rental: {
|
|
287
|
+
title: "car rental desk",
|
|
288
|
+
instructions: [
|
|
289
|
+
"You are now the car rental desk. Handle searching and booking cars only.",
|
|
290
|
+
"Ask the city and how many days, then search. Name the vendor, the tier",
|
|
291
|
+
"and the daily rate.",
|
|
292
|
+
"book_car_rental is a QUOTE, not a change: it holds nothing, so call it as",
|
|
293
|
+
"soon as you know what the caller wants and never ask permission",
|
|
294
|
+
"first.",
|
|
295
|
+
"Reserving is TWO steps and never one: call book_car_rental first — it",
|
|
296
|
+
"reserves nothing and hands you the sentence to say — then read the total",
|
|
297
|
+
"back and ask them to confirm. A car is only reserved once confirm_action",
|
|
298
|
+
"has run, and confirm_action has nothing to apply until book_car_rental",
|
|
299
|
+
"has staged it.",
|
|
300
|
+
"Your next action, right now, is a TOOL and not a sentence: call",
|
|
301
|
+
"book_car_rental if you already know which car and how many days, or",
|
|
302
|
+
"search_car_rentals if you do not. Do not speak until one of them has",
|
|
303
|
+
"answered — anything you would say before that is invented.",
|
|
304
|
+
"If the caller wants flights, a hotel or an excursion, call",
|
|
305
|
+
"complete_or_escalate.",
|
|
306
|
+
].join(" "),
|
|
307
|
+
},
|
|
308
|
+
excursion: {
|
|
309
|
+
title: "excursions desk",
|
|
310
|
+
instructions: [
|
|
311
|
+
"You are now the excursions desk. Handle recommending and booking things",
|
|
312
|
+
"to do only. Ask the city and what kind of thing they enjoy, then search.",
|
|
313
|
+
"Describe two or three options in a sentence each — this is the part of",
|
|
314
|
+
"the call a caller actually wants to hear about.",
|
|
315
|
+
"book_excursion is a QUOTE, not a change: it holds nothing, so call it as",
|
|
316
|
+
"soon as you know what the caller wants and never ask permission",
|
|
317
|
+
"first.",
|
|
318
|
+
"Booking is TWO steps and never one: call book_excursion first — it books",
|
|
319
|
+
"nothing and hands you the sentence to say — then read it back and ask",
|
|
320
|
+
"them to confirm. A booking is only made once confirm_action has run, and",
|
|
321
|
+
"confirm_action has nothing to apply until book_excursion has staged it.",
|
|
322
|
+
"Your next action, right now, is a TOOL and not a sentence: call",
|
|
323
|
+
"book_excursion if you already know which one they want, or",
|
|
324
|
+
"search_excursions if you do not. Do not speak until one of them has",
|
|
325
|
+
"answered — anything you would say before that is invented.",
|
|
326
|
+
"If the caller wants flights, a hotel or a car, call complete_or_escalate.",
|
|
327
|
+
].join(" "),
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// ─── Session state ───────────────────────────────────────────────────────────
|
|
332
|
+
|
|
333
|
+
/** A confirmed booking, as the itinerary carries it. */
|
|
334
|
+
export interface BookingRecord {
|
|
335
|
+
kind: "flight" | "hotel" | "car" | "excursion";
|
|
336
|
+
reference: string;
|
|
337
|
+
summary: string;
|
|
338
|
+
price: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* A sensitive action that has been described to the caller and not yet applied.
|
|
343
|
+
*
|
|
344
|
+
* A discriminated union rather than a stored closure: the whole point is that
|
|
345
|
+
* the staged action is INSPECTABLE — `confirm_action` re-derives the effect
|
|
346
|
+
* from it, the projection renders it in the sidebar, and a spec can assert on
|
|
347
|
+
* it. A closure would be none of those things.
|
|
348
|
+
*/
|
|
349
|
+
export type PendingAction =
|
|
350
|
+
| { kind: "update_ticket"; flightId: string }
|
|
351
|
+
| { kind: "cancel_ticket" }
|
|
352
|
+
| { kind: "book_hotel"; hotelId: string; nights: number }
|
|
353
|
+
| { kind: "book_car"; carId: string; days: number }
|
|
354
|
+
| { kind: "book_excursion"; excursionId: string };
|
|
355
|
+
|
|
356
|
+
export interface TripState {
|
|
357
|
+
passenger: string;
|
|
358
|
+
/** The ticket the caller is holding, or `null` once they cancel it. */
|
|
359
|
+
ticket: { reference: string; flightId: string } | null;
|
|
360
|
+
/** Their `dialog_state` stack: `primary` is always the bottom. */
|
|
361
|
+
dialogState: DialogState[];
|
|
362
|
+
/** Staged-but-unconfirmed sensitive action — at most one at a time, which
|
|
363
|
+
* {@link stageAction} ENFORCES by refusing a second rather than by saying so
|
|
364
|
+
* here. A concurrent step emitting two sensitive tools is ordinary. */
|
|
365
|
+
pending: PendingAction | null;
|
|
366
|
+
bookings: BookingRecord[];
|
|
367
|
+
/** What has happened on this call, for the sidebar. Capped by the slot. */
|
|
368
|
+
log: string[];
|
|
369
|
+
bookingCounter: number;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The caller as the airline already knows them — their
|
|
373
|
+
* `fetch_user_flight_information`, minus the sqlite. */
|
|
374
|
+
export function seedTrip(): TripState {
|
|
375
|
+
return {
|
|
376
|
+
passenger: "Nadia Rossi",
|
|
377
|
+
ticket: { reference: "QZ7F2K", flightId: "LX40" },
|
|
378
|
+
dialogState: ["primary"],
|
|
379
|
+
pending: null,
|
|
380
|
+
bookings: [],
|
|
381
|
+
log: [],
|
|
382
|
+
bookingCounter: 0,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** How many call-log lines survive in the projection the browser is pushed. */
|
|
387
|
+
export const LOG_CAP = 40;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* The call's state, as one typed slot.
|
|
391
|
+
*
|
|
392
|
+
* `after` holds the one invariant nothing else should have to remember: the
|
|
393
|
+
* stack always has `primary` at the bottom, so a `complete_or_escalate` that
|
|
394
|
+
* pops one too many cannot leave the session with no assistant at all.
|
|
395
|
+
*/
|
|
396
|
+
export const tripSlot = sessionSlot("trip", seedTrip, {
|
|
397
|
+
view: tripView,
|
|
398
|
+
after: (state) => {
|
|
399
|
+
if (state.dialogState.length === 0) state.dialogState.push("primary");
|
|
400
|
+
},
|
|
401
|
+
// The call log rides in every `syncState` frame, and its writers are no longer
|
|
402
|
+
// only tools — `call-events.ts` appends on a hang-up and on a reported error.
|
|
403
|
+
// The bound is declared here rather than at each push, and `LOG_CAP` is
|
|
404
|
+
// exported because a spec reads it.
|
|
405
|
+
caps: { log: LOG_CAP },
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The call as a READ hands it out: deep-frozen, and typed to say so.
|
|
410
|
+
*
|
|
411
|
+
* The pure helpers below take this rather than {@link TripState}, which is the
|
|
412
|
+
* widening a deep-readonly slot forces and the reason it is worth doing: a
|
|
413
|
+
* mutable state still satisfies it, so every `updateTool` draft passes
|
|
414
|
+
* unchanged, while a helper that WOULD have mutated stops compiling instead of
|
|
415
|
+
* throwing at its first call.
|
|
416
|
+
*/
|
|
417
|
+
export type FrozenTripState = DeepReadonly<TripState>;
|
|
418
|
+
|
|
419
|
+
export function activeAssistant(state: FrozenTripState): DialogState {
|
|
420
|
+
return state.dialogState.at(-1) ?? "primary";
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ─── The desk gate ───────────────────────────────────────────────────────────
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Is the call at `id`'s desk? A {@link ToolFailure} naming the way in if not.
|
|
427
|
+
*
|
|
428
|
+
* **This is the narrowing their graph gets for free, and it used to be prose.**
|
|
429
|
+
* Each specialist node there binds its own tool set, so a node physically cannot
|
|
430
|
+
* call another desk's tools; a voice session has ONE model with ONE tool list
|
|
431
|
+
* for its whole life, so for a long time the stack was real state that the model
|
|
432
|
+
* was merely ASKED to respect — `agent.ts` said so in place, and this guide's
|
|
433
|
+
* own eval predicted the failure. Measured: the prompt lost 0 of 5 live runs.
|
|
434
|
+
* The caller said "I need a hotel in Boston" and the model called
|
|
435
|
+
* `search_hotels` at the concierge desk every time, so `dialogState` said
|
|
436
|
+
* `primary` while the call was plainly doing hotel work — a stack the sidebar
|
|
437
|
+
* renders and nothing keeps true.
|
|
438
|
+
*
|
|
439
|
+
* A tool list cannot be narrowed mid-session, but a tool can REFUSE, and a
|
|
440
|
+
* refusal is a thing the model recovers from inside the same turn: it reads the
|
|
441
|
+
* failure, calls `to_hotel_assistant`, gets the desk's brief, and searches. So
|
|
442
|
+
* the delegation is now structural — every desk tool is reachable only from its
|
|
443
|
+
* own desk — and the brief the delegation returns is guaranteed to have been
|
|
444
|
+
* read before any of that desk's work happens, which was the whole point of
|
|
445
|
+
* handing it back as a tool result.
|
|
446
|
+
*
|
|
447
|
+
* It costs one wasted round trip the first time the model reaches past the
|
|
448
|
+
* stack, which is the right price: the alternative is a desk whose position is
|
|
449
|
+
* decoration.
|
|
450
|
+
*
|
|
451
|
+
* Not exported: {@link deskTool} and {@link deskUpdateTool} are the only callers,
|
|
452
|
+
* which is what makes a desk tool unable to skip it.
|
|
453
|
+
*/
|
|
454
|
+
function requireDesk(state: FrozenTripState, id: SpecialistId): ToolFailure | undefined {
|
|
455
|
+
const at = activeAssistant(state);
|
|
456
|
+
if (at === id) return undefined;
|
|
457
|
+
const here = at === "primary" ? "the main concierge" : SPECIALISTS[at].title;
|
|
458
|
+
return {
|
|
459
|
+
error:
|
|
460
|
+
`That tool belongs to the ${SPECIALISTS[id].title} and this call is at ${here}. ` +
|
|
461
|
+
`Nothing was searched, staged or booked. Call to_${id}_assistant with what the ` +
|
|
462
|
+
"caller asked for — its answer is that desk's brief — and then call this tool again. " +
|
|
463
|
+
"Do not tell the caller about any of this; they should hear one continuous conversation.",
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* What a desk tool declares: the slot's own {@link SlotToolDef}, with the schema
|
|
469
|
+
* REQUIRED — `cancel_ticket` takes no arguments and passes `z.object({})`.
|
|
470
|
+
*
|
|
471
|
+
* One code path in the wrapper is worth more than a line saved at one call
|
|
472
|
+
* site: `exactOptionalPropertyTypes` is on, so an `inputSchema` forwarded
|
|
473
|
+
* through a spread arrives as `P | undefined`, which is not what "this tool
|
|
474
|
+
* takes no arguments" means to the slot.
|
|
475
|
+
*/
|
|
476
|
+
type DeskToolDef<P extends ToolInputSchema, V, R> = Omit<SlotToolDef<P, V, R>, "inputSchema"> & {
|
|
477
|
+
inputSchema: P;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* A desk's own tool: {@link requireDesk} first, then the body — declared once.
|
|
482
|
+
*
|
|
483
|
+
* Nine tools used to open with the same two lines, and a wrapper is what makes
|
|
484
|
+
* the narrowing STRUCTURAL rather than remembered: their graph binds a tool set
|
|
485
|
+
* per node, and the tenth desk tool written here cannot forget the gate the way
|
|
486
|
+
* a copied prologue can. It is the per-agent wrapper `retail-orders-agent` demonstrates, at
|
|
487
|
+
* its smallest — all this one adds is the gate, so what it takes is the SLOT's
|
|
488
|
+
* OWN {@link SlotToolDef} rather than a spec of its own, and a tool file reads
|
|
489
|
+
* exactly as it did minus the prologue.
|
|
490
|
+
*
|
|
491
|
+
* Two of them because the slot has two halves and choosing wrong is a compile
|
|
492
|
+
* error: a search READS the frozen state, a staging tool takes the mutable
|
|
493
|
+
* draft. `requireDesk` short-circuits before either body runs, so a refused call
|
|
494
|
+
* really searches, stages and books nothing.
|
|
495
|
+
*/
|
|
496
|
+
export function deskTool<P extends ToolInputSchema, R>(
|
|
497
|
+
id: SpecialistId,
|
|
498
|
+
def: DeskToolDef<P, FrozenTripState, R>,
|
|
499
|
+
): ToolDef<P, R | ToolFailure> {
|
|
500
|
+
return tripSlot.tool<P, R | ToolFailure>({
|
|
501
|
+
description: def.description,
|
|
502
|
+
inputSchema: def.inputSchema,
|
|
503
|
+
execute: (args, trip, ctx) => requireDesk(trip, id) ?? def.execute(args, trip, ctx),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* {@link deskTool} for a tool that WRITES — the draft half of the slot.
|
|
509
|
+
*
|
|
510
|
+
* Its result type is FIXED at {@link StagedReadBack} rather than generic, and
|
|
511
|
+
* that is the template's central rule stated as a type: a desk tool that touches
|
|
512
|
+
* the draft may only STAGE. There is nothing else for one to answer — a body
|
|
513
|
+
* that applied a change itself would have to invent a receipt, and the compiler
|
|
514
|
+
* asks for the read-back instead.
|
|
515
|
+
*/
|
|
516
|
+
export function deskUpdateTool<P extends ToolInputSchema>(
|
|
517
|
+
id: SpecialistId,
|
|
518
|
+
def: DeskToolDef<P, TripState, StagedReadBack | ToolFailure>,
|
|
519
|
+
): ToolDef<P, StagedReadBack | ToolFailure> {
|
|
520
|
+
return tripSlot.updateTool<P, StagedReadBack | ToolFailure>({
|
|
521
|
+
description: def.description,
|
|
522
|
+
inputSchema: def.inputSchema,
|
|
523
|
+
execute: (args, trip, ctx) => requireDesk(trip, id) ?? def.execute(args, trip, ctx),
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* A flight's departure as a comparable `HH:MM`, or `undefined` for a row that
|
|
529
|
+
* does not carry one.
|
|
530
|
+
*
|
|
531
|
+
* The schedule writes a departure as `"Tue 13:05"` — a weekday a caller says
|
|
532
|
+
* and a clock reading a caller filters by — and `search_flights` compares the
|
|
533
|
+
* clock half as a STRING, which is legal for exactly the reason
|
|
534
|
+
* {@link isClockTime} exists: a zero-padded 24-hour reading sorts the way the
|
|
535
|
+
* clock runs, and `"9:05"` does not. So the predicate is what stands between a
|
|
536
|
+
* row and a comparison, rather than a regex written here: a row it refuses is
|
|
537
|
+
* left out of a time-filtered search instead of being ordered against `"Tue"`.
|
|
538
|
+
*/
|
|
539
|
+
export function departureClock(flight: DeepReadonly<Flight>): string | undefined {
|
|
540
|
+
const clock = flight.departs.slice(-5);
|
|
541
|
+
return isClockTime(clock) ? clock : undefined;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// ─── The confirmation gate ───────────────────────────────────────────────────
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* The gate as a STATE MAP — their `interrupt_before`, which is a graph construct.
|
|
548
|
+
*
|
|
549
|
+
* This port had to hand-roll it: a voice session had no graph, so "halt before a
|
|
550
|
+
* sensitive tool and resume on approval" became "every sensitive tool STAGES and
|
|
551
|
+
* `confirm_action` is the only thing that applies one". That half is unchanged
|
|
552
|
+
* and is still the mechanism — see {@link stageAction}. What the machine adds is
|
|
553
|
+
* the PRECONDITION on the other side of the halt: `confirm_action` and
|
|
554
|
+
* `cancel_action` are legal only while something is actually waiting, which was
|
|
555
|
+
* a null check inside each of them and is now `when`.
|
|
556
|
+
*
|
|
557
|
+
* **The staging tools are deliberately NOT gated on `browsing`.**
|
|
558
|
+
* {@link stageAction}'s refusal NAMES the sentence already waiting, which is what
|
|
559
|
+
* lets the model settle that one first and restage the rest; a state gate can
|
|
560
|
+
* only say "you are in awaitingConfirmation", since a state's instruction is
|
|
561
|
+
* static. So the specific refusal stays where it is and the flow follows it.
|
|
562
|
+
*/
|
|
563
|
+
const gateSpec = {
|
|
564
|
+
initial: "browsing",
|
|
565
|
+
states: {
|
|
566
|
+
browsing: {
|
|
567
|
+
instruction:
|
|
568
|
+
"Nothing is waiting for the caller's yes. Stage a change with a booking tool first.",
|
|
569
|
+
on: { STAGED: "awaitingConfirmation", "@session.timedOut": "abandoned" },
|
|
570
|
+
},
|
|
571
|
+
awaitingConfirmation: {
|
|
572
|
+
instruction:
|
|
573
|
+
"Read the staged change back and hear a clear yes or no, then use confirm_action or cancel_action.",
|
|
574
|
+
on: { SETTLED: "browsing", "@session.timedOut": "abandoned" },
|
|
575
|
+
},
|
|
576
|
+
/**
|
|
577
|
+
* The caller hung up, or the session timed out under them.
|
|
578
|
+
*
|
|
579
|
+
* Declared on both live states rather than on a parent, because wrapping
|
|
580
|
+
* them would rename `browsing` and `awaitingConfirmation` to
|
|
581
|
+
* `onCall.browsing` and `onCall.awaitingConfirmation` — the two names every
|
|
582
|
+
* `when` in `tools/` is written against, and the sidebar renders.
|
|
583
|
+
*
|
|
584
|
+
* What it does NOT do is settle the staged action: a deadline or a session
|
|
585
|
+
* event SENDS AN EVENT, it does not run a tool, so `pending` is still
|
|
586
|
+
* whatever `stageAction` left there. That is fine here and is the reason
|
|
587
|
+
* this state is `final` — nothing may act on this call again, so nothing
|
|
588
|
+
* reads `pending` again either. It would NOT be fine as a timeout that
|
|
589
|
+
* returned to `browsing`, which is the trap recorded in
|
|
590
|
+
* `aai-runtime`'s `DIALOG-CLAUDE.md`.
|
|
591
|
+
*/
|
|
592
|
+
abandoned: {
|
|
593
|
+
final: true,
|
|
594
|
+
instruction:
|
|
595
|
+
"The caller is gone. Do nothing further — do not confirm the staged change, do not " +
|
|
596
|
+
"book anything, and do not promise a callback.",
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
} as const satisfies DialogSpec;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Whether a change is waiting on the caller's word.
|
|
603
|
+
*
|
|
604
|
+
* Its own slot, beside {@link tripSlot}: the flow holds the POSITION and the
|
|
605
|
+
* trip holds the staged action itself, because an inspectable
|
|
606
|
+
* {@link PendingAction} is what `confirm_action` re-derives the effect from. One
|
|
607
|
+
* tool call always moves both — {@link stageAction} sends `STAGED` in the same
|
|
608
|
+
* synchronous window it writes `pending` in, and the two settling tools send
|
|
609
|
+
* `SETTLED` only on success.
|
|
610
|
+
*/
|
|
611
|
+
export const gateFlow = dialog("gate", gateSpec);
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Describe a staged action in one sentence, in the second person — this is
|
|
615
|
+
* read aloud, so it is a question's worth of text and not a receipt.
|
|
616
|
+
*/
|
|
617
|
+
export function describeAction(action: DeepReadonly<PendingAction>): string | ToolFailure {
|
|
618
|
+
switch (action.kind) {
|
|
619
|
+
case "update_ticket": {
|
|
620
|
+
const flight = FLIGHTS.find((f) => f.id === action.flightId);
|
|
621
|
+
if (!flight) return { error: `No flight ${action.flightId} in the schedule.` };
|
|
622
|
+
return `move your ticket to ${flight.id}, ${flight.route}, departing ${flight.departs}, at ${formatMoney(flight.fare)}`;
|
|
623
|
+
}
|
|
624
|
+
case "cancel_ticket":
|
|
625
|
+
return "cancel your ticket entirely";
|
|
626
|
+
case "book_hotel": {
|
|
627
|
+
const hotel = HOTELS.find((h) => h.id === action.hotelId);
|
|
628
|
+
if (!hotel) return { error: `No hotel ${action.hotelId}.` };
|
|
629
|
+
return `book ${hotel.name} in ${hotel.area} for ${action.nights} ${plural(action.nights, "night")}, ${formatMoney(hotel.pricePerNight * action.nights)} total`;
|
|
630
|
+
}
|
|
631
|
+
case "book_car": {
|
|
632
|
+
const car = CAR_RENTALS.find((c) => c.id === action.carId);
|
|
633
|
+
if (!car) return { error: `No car ${action.carId}.` };
|
|
634
|
+
return `reserve the ${car.tier} from ${car.vendor} for ${action.days} ${plural(action.days, "day")}, ${formatMoney(car.pricePerDay * action.days)} total`;
|
|
635
|
+
}
|
|
636
|
+
case "book_excursion": {
|
|
637
|
+
const excursion = EXCURSIONS.find((e) => e.id === action.excursionId);
|
|
638
|
+
if (!excursion) return { error: `No excursion ${action.excursionId}.` };
|
|
639
|
+
return `book ${excursion.name} at ${formatMoney(excursion.price)}`;
|
|
640
|
+
}
|
|
641
|
+
// Unreachable while `PendingAction` is exhausted above — and the arm a new
|
|
642
|
+
// member of the union lands in until it has one of its own, which is a
|
|
643
|
+
// refusal rather than an unexplained sentence read down a phone.
|
|
644
|
+
default:
|
|
645
|
+
return { error: "That change cannot be described, so it will not be staged." };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* The sentence for an action that has ALREADY been staged.
|
|
651
|
+
*
|
|
652
|
+
* `describeAction` answers `string | ToolFailure` because {@link stageAction} is
|
|
653
|
+
* the one caller that can be handed an id naming nothing, and its refusal names
|
|
654
|
+
* that id. Everything else describes something `stageAction` already accepted,
|
|
655
|
+
* so the failure arm is unreachable — and every such site had written
|
|
656
|
+
* `typeof described === "string" ? described : ...` to guard it, one of which
|
|
657
|
+
* read as if a `ToolFailure` might be spoken to the caller. The fallback is the
|
|
658
|
+
* action's own kind, so a catalog that somehow lost an entry mid-call degrades
|
|
659
|
+
* to a rough noun rather than to a stray `[object Object]`.
|
|
660
|
+
*/
|
|
661
|
+
export function describeStaged(action: DeepReadonly<PendingAction>): string {
|
|
662
|
+
const described = describeAction(action);
|
|
663
|
+
return typeof described === "string" ? described : action.kind;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* What a sensitive tool answers with: the sentence to read aloud, and the fact
|
|
668
|
+
* that nothing has happened yet.
|
|
669
|
+
*
|
|
670
|
+
* Named because {@link deskUpdateTool} pins every writing desk tool to it — see
|
|
671
|
+
* there for why that is the gate rather than a convenience.
|
|
672
|
+
*/
|
|
673
|
+
export type StagedReadBack = {
|
|
674
|
+
awaitingConfirmation: true;
|
|
675
|
+
readBack: string;
|
|
676
|
+
expires: "on the caller's next answer";
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Stage a sensitive action and return what a sensitive tool answers with.
|
|
681
|
+
*
|
|
682
|
+
* Every sensitive tool ends in this call and none of them mutate anything —
|
|
683
|
+
* that is the whole gate, and keeping it to one helper is what stops the next
|
|
684
|
+
* sensitive tool from being the one that forgets it.
|
|
685
|
+
*
|
|
686
|
+
* **It REFUSES a second staging, and that is the enforcement half of
|
|
687
|
+
* {@link TripState.pending}'s "at most one at a time".** The LLM loop runs a
|
|
688
|
+
* step's tool calls CONCURRENTLY, so two sensitive tools in one step is an
|
|
689
|
+
* ordinary outcome — the model says "change my flight and book the hotel" and
|
|
690
|
+
* emits both. An unconditional assignment made the second win: both tools
|
|
691
|
+
* answered `awaitingConfirmation`, the model read both back, the caller said
|
|
692
|
+
* yes, and `confirm_action` applied ONE of them with nothing anywhere saying
|
|
693
|
+
* the other had been dropped. A gate whose failure is a silent no-op is not a
|
|
694
|
+
* gate. Refusing names the sentence already waiting, which is what lets the
|
|
695
|
+
* model ask about that one first and restage the rest afterwards.
|
|
696
|
+
*/
|
|
697
|
+
export function stageAction(
|
|
698
|
+
ctx: ToolContext,
|
|
699
|
+
state: TripState,
|
|
700
|
+
action: PendingAction,
|
|
701
|
+
): StagedReadBack | ToolFailure {
|
|
702
|
+
const described = describeAction(action);
|
|
703
|
+
if (typeof described !== "string") return described;
|
|
704
|
+
if (state.pending) {
|
|
705
|
+
return {
|
|
706
|
+
error:
|
|
707
|
+
`Something is already waiting for the caller's yes: ${describeStaged(state.pending)}. ` +
|
|
708
|
+
"Settle it with confirm_action or cancel_action, then ask for this one. " +
|
|
709
|
+
"Only one change can be waiting at a time — nothing about this request has been staged.",
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
state.pending = action;
|
|
713
|
+
// The flow moves in the SAME synchronous window `pending` is written in, so
|
|
714
|
+
// the position and the payload cannot be observed disagreeing. `gateFlow` is
|
|
715
|
+
// a different slot from `tripSlot`, so this is not a nested write to the draft
|
|
716
|
+
// being held — the open-draft guard is per slot.
|
|
717
|
+
gateFlow.send(ctx, { type: "STAGED" });
|
|
718
|
+
state.log.push(`Awaiting confirmation: ${described}`);
|
|
719
|
+
return {
|
|
720
|
+
awaitingConfirmation: true,
|
|
721
|
+
readBack: `Ask the caller to confirm, out loud, that they want to ${described}. Nothing has changed yet.`,
|
|
722
|
+
expires: "on the caller's next answer",
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Apply the staged action. The ONE place any of them takes effect.
|
|
728
|
+
*
|
|
729
|
+
* The "nothing is waiting" guard is gone: `confirm_action` is gated on
|
|
730
|
+
* `awaitingConfirmation`, so reaching here means something IS staged. The
|
|
731
|
+
* remaining `!action` arm is the flow and the payload disagreeing, which one
|
|
732
|
+
* synchronous window per transition is what rules out — it reports rather than
|
|
733
|
+
* throwing, because a live call is the wrong place to find out.
|
|
734
|
+
*/
|
|
735
|
+
export function applyPending(
|
|
736
|
+
state: TripState,
|
|
737
|
+
): { applied: string; reference?: string } | ToolFailure {
|
|
738
|
+
const action = state.pending;
|
|
739
|
+
if (!action) {
|
|
740
|
+
return { error: "Nothing is staged after all — ask the caller again what they want." };
|
|
741
|
+
}
|
|
742
|
+
state.pending = null;
|
|
743
|
+
state.bookingCounter++;
|
|
744
|
+
const reference = `BK${String(1000 + state.bookingCounter)}`;
|
|
745
|
+
|
|
746
|
+
switch (action.kind) {
|
|
747
|
+
case "update_ticket": {
|
|
748
|
+
const flight = FLIGHTS.find((f) => f.id === action.flightId);
|
|
749
|
+
if (!flight) return { error: `No flight ${action.flightId}.` };
|
|
750
|
+
if (flight.seatsLeft <= 0) return { error: `${flight.id} has no seats left.` };
|
|
751
|
+
if (!state.ticket) return { error: "There is no ticket to move — it was cancelled." };
|
|
752
|
+
state.ticket = { reference: state.ticket.reference, flightId: flight.id };
|
|
753
|
+
state.log.push(`Ticket ${state.ticket.reference} moved to ${flight.id}`);
|
|
754
|
+
return { applied: `Ticket moved to ${flight.id}, ${flight.departs}.` };
|
|
755
|
+
}
|
|
756
|
+
case "cancel_ticket": {
|
|
757
|
+
if (!state.ticket) return { error: "There is no ticket to cancel." };
|
|
758
|
+
const cancelled = state.ticket.reference;
|
|
759
|
+
state.ticket = null;
|
|
760
|
+
state.log.push(`Ticket ${cancelled} cancelled`);
|
|
761
|
+
return { applied: `Ticket ${cancelled} cancelled.` };
|
|
762
|
+
}
|
|
763
|
+
case "book_hotel": {
|
|
764
|
+
const hotel = HOTELS.find((h) => h.id === action.hotelId);
|
|
765
|
+
if (!hotel) return { error: `No hotel ${action.hotelId}.` };
|
|
766
|
+
// `roundMoney` because this is STORED and then summed into the itinerary
|
|
767
|
+
// total: `179.95 * 3` is `539.8499999999999`, which prints as $539.85 and
|
|
768
|
+
// compares equal to nothing anyone would write down.
|
|
769
|
+
const price = roundMoney(hotel.pricePerNight * action.nights);
|
|
770
|
+
state.bookings.push({
|
|
771
|
+
kind: "hotel",
|
|
772
|
+
reference,
|
|
773
|
+
summary: `${hotel.name} (${hotel.area}), ${action.nights} ${plural(action.nights, "night")}`,
|
|
774
|
+
price,
|
|
775
|
+
});
|
|
776
|
+
state.log.push(`Hotel booked: ${hotel.name} — ${reference}`);
|
|
777
|
+
return { applied: `${hotel.name} booked, ${formatMoney(price)}.`, reference };
|
|
778
|
+
}
|
|
779
|
+
case "book_car": {
|
|
780
|
+
const car = CAR_RENTALS.find((c) => c.id === action.carId);
|
|
781
|
+
if (!car) return { error: `No car ${action.carId}.` };
|
|
782
|
+
const price = roundMoney(car.pricePerDay * action.days);
|
|
783
|
+
state.bookings.push({
|
|
784
|
+
kind: "car",
|
|
785
|
+
reference,
|
|
786
|
+
summary: `${car.vendor} ${car.tier}, ${action.days} ${plural(action.days, "day")}`,
|
|
787
|
+
price,
|
|
788
|
+
});
|
|
789
|
+
state.log.push(`Car reserved: ${car.vendor} ${car.tier} — ${reference}`);
|
|
790
|
+
return {
|
|
791
|
+
applied: `${car.tier} from ${car.vendor} reserved, ${formatMoney(price)}.`,
|
|
792
|
+
reference,
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
case "book_excursion": {
|
|
796
|
+
const excursion = EXCURSIONS.find((e) => e.id === action.excursionId);
|
|
797
|
+
if (!excursion) return { error: `No excursion ${action.excursionId}.` };
|
|
798
|
+
state.bookings.push({
|
|
799
|
+
kind: "excursion",
|
|
800
|
+
reference,
|
|
801
|
+
summary: `${excursion.name} (${excursion.city})`,
|
|
802
|
+
price: excursion.price,
|
|
803
|
+
});
|
|
804
|
+
state.log.push(`Excursion booked: ${excursion.name} — ${reference}`);
|
|
805
|
+
return { applied: `${excursion.name} booked, ${formatMoney(excursion.price)}.`, reference };
|
|
806
|
+
}
|
|
807
|
+
// Same as `describeAction`: unreachable today, and a refusal rather than a
|
|
808
|
+
// silent no-op for whatever the union grows next.
|
|
809
|
+
default:
|
|
810
|
+
return { error: "That change has no handler, so nothing was applied." };
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// ─── The projection ──────────────────────────────────────────────────────────
|
|
815
|
+
|
|
816
|
+
export interface TripView {
|
|
817
|
+
passenger: string;
|
|
818
|
+
/** Which desk is holding the call — the stack's top, rendered as a badge. */
|
|
819
|
+
assistant: DialogState;
|
|
820
|
+
assistantTitle: string;
|
|
821
|
+
ticket: { reference: string; flightId: string; route: string; departs: string } | null;
|
|
822
|
+
bookings: readonly DeepReadonly<BookingRecord>[];
|
|
823
|
+
total: number;
|
|
824
|
+
/** The staged action's sentence, so the browser shows what voice just asked. */
|
|
825
|
+
pending: string | null;
|
|
826
|
+
log: readonly string[];
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* What the browser sees. A projection rather than the raw state, for the reason
|
|
831
|
+
* `syncState` takes one: the caller's ticket reference is theirs, the staged
|
|
832
|
+
* action has to be rendered as PROSE rather than as a union the client would
|
|
833
|
+
* have to re-switch on, and the stack top is the one field the sidebar is
|
|
834
|
+
* actually built around.
|
|
835
|
+
*/
|
|
836
|
+
export function tripView(state: FrozenTripState): TripView {
|
|
837
|
+
const assistant = activeAssistant(state);
|
|
838
|
+
const flight = state.ticket ? FLIGHTS.find((f) => f.id === state.ticket?.flightId) : undefined;
|
|
839
|
+
const described = state.pending ? describeStaged(state.pending) : null;
|
|
840
|
+
return {
|
|
841
|
+
passenger: state.passenger,
|
|
842
|
+
assistant,
|
|
843
|
+
assistantTitle: assistant === "primary" ? "concierge" : SPECIALISTS[assistant].title,
|
|
844
|
+
ticket:
|
|
845
|
+
state.ticket && flight
|
|
846
|
+
? {
|
|
847
|
+
reference: state.ticket.reference,
|
|
848
|
+
flightId: flight.id,
|
|
849
|
+
route: flight.route,
|
|
850
|
+
departs: flight.departs,
|
|
851
|
+
}
|
|
852
|
+
: null,
|
|
853
|
+
bookings: state.bookings,
|
|
854
|
+
// The running total the sidebar prints and a spec compares. Each booking's
|
|
855
|
+
// price was already rounded where it was STORED — which is where today's
|
|
856
|
+
// catalog actually produces dust — and the sum goes through the same rule
|
|
857
|
+
// rather than through a rate table that happens not to need it.
|
|
858
|
+
total: roundMoney(state.bookings.reduce((sum, b) => sum + b.price, 0)),
|
|
859
|
+
pending: described,
|
|
860
|
+
log: state.log,
|
|
861
|
+
};
|
|
862
|
+
}
|