@alexkroman1/aai-cli 0.17.0 → 0.18.1
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
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { f as parseDecimalInt } from "./_utils-ChU85MEg.mjs";
|
|
3
|
+
import "node:module";
|
|
4
|
+
import { availableParallelism } from "node:os";
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __exportAll = (all, no_symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/_start-workers.ts
|
|
18
|
+
var _start_workers_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
BOOT_TIMEOUT_MS: () => BOOT_TIMEOUT_MS,
|
|
20
|
+
DEFAULT_DRAIN_TIMEOUT_S: () => 300,
|
|
21
|
+
DRAIN_TIMEOUT_ENV: () => DRAIN_TIMEOUT_ENV,
|
|
22
|
+
LIVENESS_TIMEOUT_MS: () => LIVENESS_TIMEOUT_MS,
|
|
23
|
+
MAX_CALLS_ENV: () => MAX_CALLS_ENV,
|
|
24
|
+
PING_INTERVAL_MS: () => PING_INTERVAL_MS,
|
|
25
|
+
SLOTS_ENV: () => SLOTS_ENV,
|
|
26
|
+
SLOT_ENV: () => SLOT_ENV,
|
|
27
|
+
SLOW_PONG_LOG_EVERY_MS: () => SLOW_PONG_LOG_EVERY_MS,
|
|
28
|
+
SLOW_PONG_MS: () => 500,
|
|
29
|
+
STOP_GRACE_MS: () => STOP_GRACE_MS,
|
|
30
|
+
WORKERS_ENV: () => WORKERS_ENV,
|
|
31
|
+
WORKER_STDIO: () => WORKER_STDIO,
|
|
32
|
+
isProtocolMessage: () => isProtocolMessage,
|
|
33
|
+
isStartWorker: () => isStartWorker,
|
|
34
|
+
loadCluster: () => loadCluster,
|
|
35
|
+
nodeCluster: () => nodeCluster,
|
|
36
|
+
parseWorkers: () => parseWorkers,
|
|
37
|
+
resolvePositiveInt: () => resolvePositiveInt,
|
|
38
|
+
resolveWorkers: () => resolveWorkers,
|
|
39
|
+
superviseWorkers: () => superviseWorkers
|
|
40
|
+
});
|
|
41
|
+
/** Process-env override for the worker count, for a container that cannot pass flags. */
|
|
42
|
+
const WORKERS_ENV = "AAI_WORKERS";
|
|
43
|
+
/** The env a worker learns its place from. Read only under `cluster.isWorker`. */
|
|
44
|
+
const SLOT_ENV = "AAI_START_SLOT";
|
|
45
|
+
const SLOTS_ENV = "AAI_START_SLOTS";
|
|
46
|
+
/**
|
|
47
|
+
* Parse a worker count: a positive integer, or `auto` for one per available CPU.
|
|
48
|
+
*
|
|
49
|
+
* @throws when the value is neither — named, so the CLI error says which input.
|
|
50
|
+
*/
|
|
51
|
+
function parseWorkers(value, source, cpus = availableParallelism) {
|
|
52
|
+
const trimmed = value.trim().toLowerCase();
|
|
53
|
+
if (trimmed === "auto") return Math.max(1, cpus());
|
|
54
|
+
const n = parseDecimalInt(trimmed, 1, Number.MAX_SAFE_INTEGER);
|
|
55
|
+
if (n === void 0) throw new Error(`${source} must be a positive integer or "auto" (got ${JSON.stringify(value)})`);
|
|
56
|
+
return n;
|
|
57
|
+
}
|
|
58
|
+
/** Env overrides for the drain timeout (seconds) and the per-worker call cap. */
|
|
59
|
+
const DRAIN_TIMEOUT_ENV = "AAI_DRAIN_TIMEOUT";
|
|
60
|
+
const MAX_CALLS_ENV = "AAI_MAX_CALLS_PER_WORKER";
|
|
61
|
+
/** How long a drain lets calls finish by default: most calls end well inside it. */
|
|
62
|
+
const DEFAULT_DRAIN_TIMEOUT_S = 300;
|
|
63
|
+
/**
|
|
64
|
+
* A positive integer from a flag, else its env var, else `fallback` — named on
|
|
65
|
+
* error, with its `unit` when it has one: `--drain-timeout 5m` is the natural
|
|
66
|
+
* thing to type, and "must be a positive integer" alone does not say seconds.
|
|
67
|
+
*/
|
|
68
|
+
function resolvePositiveInt(flag, flagName, envName, fallback, env = process.env, unit) {
|
|
69
|
+
const [raw, source] = flag !== void 0 ? [flag, flagName] : [env[envName]?.trim() || void 0, envName];
|
|
70
|
+
if (raw === void 0) return fallback;
|
|
71
|
+
const n = parseDecimalInt(raw.trim(), 1, Number.MAX_SAFE_INTEGER);
|
|
72
|
+
if (n === void 0) {
|
|
73
|
+
const what = unit ? `a positive whole number of ${unit}` : "a positive integer";
|
|
74
|
+
throw new Error(`${source} must be ${what} (got ${JSON.stringify(raw)})`);
|
|
75
|
+
}
|
|
76
|
+
return n;
|
|
77
|
+
}
|
|
78
|
+
/** The worker count: the flag, then {@link WORKERS_ENV}, then 1. */
|
|
79
|
+
function resolveWorkers(flag, env = process.env, cpus = availableParallelism) {
|
|
80
|
+
if (flag !== void 0) return parseWorkers(flag, "--workers", cpus);
|
|
81
|
+
const fromEnv = env[WORKERS_ENV]?.trim();
|
|
82
|
+
if (fromEnv) return parseWorkers(fromEnv, WORKERS_ENV, cpus);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
/** How often the primary pings each listening worker. */
|
|
86
|
+
const PING_INTERVAL_MS = 2500;
|
|
87
|
+
/**
|
|
88
|
+
* A worker that has not answered a ping for this long has a wedged event loop:
|
|
89
|
+
* it is killed and respawned into its slot.
|
|
90
|
+
*
|
|
91
|
+
* Shorter than LiveKit's 60 s on purpose. Theirs guards ONE call per process;
|
|
92
|
+
* a worker here holds hundreds, and a loop blocked for this long has already
|
|
93
|
+
* stopped every one of them — their audio stalled at the first missed frame —
|
|
94
|
+
* so waiting longer only lengthens the outage before the respawn.
|
|
95
|
+
*/
|
|
96
|
+
const LIVENESS_TIMEOUT_MS = 15e3;
|
|
97
|
+
/**
|
|
98
|
+
* How long a worker may take to start listening before it is killed as hung —
|
|
99
|
+
* a boot stuck on a database that never answers (`ensure*Schema` behind the
|
|
100
|
+
* schema lock, a silently partitioned Postgres) would otherwise hold the
|
|
101
|
+
* server at "starting", or a rolling restart open, forever. Generous: an
|
|
102
|
+
* agent's import and its schema DDL are seconds, not minutes.
|
|
103
|
+
*/
|
|
104
|
+
const BOOT_TIMEOUT_MS = 12e4;
|
|
105
|
+
/** How long a worker told to stop (or done draining) gets before it is SIGKILLed. */
|
|
106
|
+
const STOP_GRACE_MS = 1e4;
|
|
107
|
+
const SLOW_PONG_LOG_EVERY_MS = 3e4;
|
|
108
|
+
/** One of this protocol's messages (every type is `aai-start:`-prefixed) — either direction. */
|
|
109
|
+
function isProtocolMessage(message) {
|
|
110
|
+
const type = message?.type;
|
|
111
|
+
return typeof type === "string" && type.startsWith("aai-start:");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Is this process a `--workers` worker? The slot only our fork sets, plus the
|
|
115
|
+
* IPC channel `cluster.fork` opens — without importing `node:cluster`.
|
|
116
|
+
*
|
|
117
|
+
* Not `NODE_UNIQUE_ID`, though `cluster.fork` sets it: Node's bootstrap
|
|
118
|
+
* deletes it from a worker's `process.env` before any user code runs.
|
|
119
|
+
*/
|
|
120
|
+
function isStartWorker(env = process.env, hasIpc = process.send !== void 0) {
|
|
121
|
+
return hasIpc && env["AAI_START_SLOT"] !== void 0;
|
|
122
|
+
}
|
|
123
|
+
/** `node:cluster`, loaded on demand — see the import note at the top. */
|
|
124
|
+
async function loadCluster() {
|
|
125
|
+
return (await import("node:cluster")).default;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A worker's stdio: stdin and stderr inherited, stdout pointed at the
|
|
129
|
+
* primary's STDERR. The primary owns stdout's one `--json` result line, and a
|
|
130
|
+
* worker runs this same command, so anything it prints there would be a
|
|
131
|
+
* second one.
|
|
132
|
+
*/
|
|
133
|
+
const WORKER_STDIO = [
|
|
134
|
+
"inherit",
|
|
135
|
+
2,
|
|
136
|
+
"inherit",
|
|
137
|
+
"ipc"
|
|
138
|
+
];
|
|
139
|
+
/**
|
|
140
|
+
* `node:cluster` behind {@link ClusterLike}. Structured-clone IPC, because a
|
|
141
|
+
* relayed notice can carry audio (`Uint8Array`), which JSON would mangle.
|
|
142
|
+
*/
|
|
143
|
+
function nodeCluster(cluster) {
|
|
144
|
+
cluster.setupPrimary({
|
|
145
|
+
serialization: "advanced",
|
|
146
|
+
stdio: [...WORKER_STDIO]
|
|
147
|
+
});
|
|
148
|
+
const wrapped = /* @__PURE__ */ new Map();
|
|
149
|
+
const like = (worker) => {
|
|
150
|
+
let handle = wrapped.get(worker);
|
|
151
|
+
if (!handle) {
|
|
152
|
+
handle = {
|
|
153
|
+
pid: worker.process.pid,
|
|
154
|
+
kill: (signal) => worker.process.kill(signal),
|
|
155
|
+
send: (message, socket) => {
|
|
156
|
+
if (!worker.isConnected()) return false;
|
|
157
|
+
worker.send(message, socket);
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
wrapped.set(worker, handle);
|
|
162
|
+
}
|
|
163
|
+
return handle;
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
fork: (env) => like(cluster.fork(env)),
|
|
167
|
+
onExit: (listener) => cluster.on("exit", (worker, code, signal) => {
|
|
168
|
+
listener(like(worker), code, signal);
|
|
169
|
+
wrapped.delete(worker);
|
|
170
|
+
}),
|
|
171
|
+
onMessage: (listener) => cluster.on("message", (worker, message) => listener(like(worker), message))
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function realTimers() {
|
|
175
|
+
return {
|
|
176
|
+
now: Date.now,
|
|
177
|
+
every: (ms, tick) => {
|
|
178
|
+
const timer = setInterval(tick, ms);
|
|
179
|
+
timer.unref();
|
|
180
|
+
return () => clearInterval(timer);
|
|
181
|
+
},
|
|
182
|
+
after: (ms, fire) => {
|
|
183
|
+
setTimeout(fire, ms).unref();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Fork one worker per slot and keep each slot served — see the module doc. */
|
|
188
|
+
function superviseWorkers(opts) {
|
|
189
|
+
const { slots, cluster: host, log } = opts;
|
|
190
|
+
const maxCalls = opts.maxCallsPerWorker ?? Number.POSITIVE_INFINITY;
|
|
191
|
+
const { now, every, after } = {
|
|
192
|
+
...realTimers(),
|
|
193
|
+
...opts.timers
|
|
194
|
+
};
|
|
195
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
196
|
+
/** Slot → its current, listening worker. */
|
|
197
|
+
const ready = /* @__PURE__ */ new Map();
|
|
198
|
+
/** Slot → the replacement a rolling restart is waiting on. */
|
|
199
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
200
|
+
/**
|
|
201
|
+
* Relays awaiting a result, keyed by an id the PRIMARY assigns. Keyed by
|
|
202
|
+
* process, never by slot: each worker numbers its relays from 1, and across
|
|
203
|
+
* a crash-respawn or a roll a slot is two processes — a result routed by
|
|
204
|
+
* slot reached the wrong one (an `acked` for a notice it never sent).
|
|
205
|
+
*/
|
|
206
|
+
const relays = /* @__PURE__ */ new Map();
|
|
207
|
+
let nextRelayId = 0;
|
|
208
|
+
let name;
|
|
209
|
+
let fatal;
|
|
210
|
+
let bootFailure;
|
|
211
|
+
/** Draining or stopping: no respawns, no new calls, exit once every worker has. */
|
|
212
|
+
let ending = false;
|
|
213
|
+
let forced = false;
|
|
214
|
+
/** The slots a rolling restart has yet to replace, in order. */
|
|
215
|
+
let rollQueue = [];
|
|
216
|
+
let rollDrainMs = 0;
|
|
217
|
+
let exitCode = 0;
|
|
218
|
+
/** Every slot has listened once; a rolling restart before then is refused. */
|
|
219
|
+
let started = false;
|
|
220
|
+
const booted = Promise.withResolvers();
|
|
221
|
+
const exited = Promise.withResolvers();
|
|
222
|
+
booted.promise.catch(() => void 0);
|
|
223
|
+
/**
|
|
224
|
+
* Every worker has exited. `ready` rejects only now, so a boot failure never
|
|
225
|
+
* races the shutdown — and it does reject if the server stopped before it
|
|
226
|
+
* was ever ready, rather than leaving the caller waiting forever.
|
|
227
|
+
*/
|
|
228
|
+
const settle = () => {
|
|
229
|
+
booted.reject(bootFailure ?? /* @__PURE__ */ new Error("the server stopped before every worker was listening"));
|
|
230
|
+
exited.resolve(exitCode);
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* How a worker is named in a log line: its slot first, because that is what
|
|
234
|
+
* the `[worker N]` tag on its own lines and `/workers` both key on; the pid
|
|
235
|
+
* is what `kill` and `ps` need.
|
|
236
|
+
*/
|
|
237
|
+
const who = (worker) => `worker ${tracked.get(worker)?.slot ?? "?"} (pid ${worker.pid})`;
|
|
238
|
+
const fork = (slot) => {
|
|
239
|
+
const worker = host.fork({
|
|
240
|
+
[SLOT_ENV]: String(slot),
|
|
241
|
+
[SLOTS_ENV]: String(slots)
|
|
242
|
+
});
|
|
243
|
+
tracked.set(worker, {
|
|
244
|
+
slot,
|
|
245
|
+
forkedAt: now(),
|
|
246
|
+
admitted: 0
|
|
247
|
+
});
|
|
248
|
+
return worker;
|
|
249
|
+
};
|
|
250
|
+
/** Tell `worker` to drain for `drainMs` (or, `undefined`, to stop now); SIGKILL it if still alive past that plus the grace. */
|
|
251
|
+
const retire = (worker, drainMs) => {
|
|
252
|
+
worker.send(drainMs === void 0 ? { type: "aai-start:stop" } : {
|
|
253
|
+
type: "aai-start:drain",
|
|
254
|
+
timeoutMs: drainMs
|
|
255
|
+
});
|
|
256
|
+
after((drainMs ?? 0) + STOP_GRACE_MS, () => {
|
|
257
|
+
if (tracked.has(worker)) worker.kill("SIGKILL");
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
const end = (drainMs) => {
|
|
261
|
+
ending = true;
|
|
262
|
+
rollQueue = [];
|
|
263
|
+
for (const [worker, state] of tracked) {
|
|
264
|
+
if (state.load) {
|
|
265
|
+
retire(worker, drainMs);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
state.abandoned = true;
|
|
269
|
+
worker.kill("SIGKILL");
|
|
270
|
+
}
|
|
271
|
+
if (tracked.size === 0) settle();
|
|
272
|
+
};
|
|
273
|
+
const stop = () => {
|
|
274
|
+
if (forced) return;
|
|
275
|
+
forced = true;
|
|
276
|
+
end(void 0);
|
|
277
|
+
};
|
|
278
|
+
/** Start the next slot's replacement, if a rolling restart has one left. */
|
|
279
|
+
const rollNext = () => {
|
|
280
|
+
const slot = rollQueue.shift();
|
|
281
|
+
if (slot === void 0) {
|
|
282
|
+
log(`rolling restart complete: every slot has a new worker; the old ones finish their calls (up to ${Math.round(rollDrainMs / 1e3)}s)`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
incoming.set(slot, fork(slot));
|
|
286
|
+
};
|
|
287
|
+
const roll = (drainTimeoutMs) => {
|
|
288
|
+
if (ending) {
|
|
289
|
+
log("rolling restart ignored: the server is shutting down");
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (!started) {
|
|
293
|
+
log("rolling restart ignored: the server is still starting");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (rollQueue.length > 0 || incoming.size > 0) {
|
|
297
|
+
log("rolling restart ignored: one is already running");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
rollDrainMs = drainTimeoutMs;
|
|
301
|
+
fatal = void 0;
|
|
302
|
+
rollQueue = Array.from({ length: slots }, (_, slot) => slot);
|
|
303
|
+
log(`rolling restart of ${slots} workers`);
|
|
304
|
+
rollNext();
|
|
305
|
+
};
|
|
306
|
+
const answer = (origin, originId, outcome) => {
|
|
307
|
+
if (tracked.has(origin)) origin.send({
|
|
308
|
+
type: "aai-start:relay-result",
|
|
309
|
+
id: originId,
|
|
310
|
+
outcome
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const relay = (origin, message) => {
|
|
314
|
+
const target = ready.get(message.target)?.worker;
|
|
315
|
+
if (!target) return answer(origin, message.id, "offline");
|
|
316
|
+
const id = ++nextRelayId;
|
|
317
|
+
relays.set(id, {
|
|
318
|
+
origin,
|
|
319
|
+
originId: message.id,
|
|
320
|
+
target
|
|
321
|
+
});
|
|
322
|
+
if (!target.send({
|
|
323
|
+
type: "aai-start:relay",
|
|
324
|
+
id,
|
|
325
|
+
payload: message.payload
|
|
326
|
+
})) {
|
|
327
|
+
relays.delete(id);
|
|
328
|
+
answer(origin, message.id, "offline");
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
const onListening = (worker, state, port, agentName) => {
|
|
332
|
+
const { slot } = state;
|
|
333
|
+
state.heard = now();
|
|
334
|
+
state.forkedAt = void 0;
|
|
335
|
+
state.load = {
|
|
336
|
+
calls: 0,
|
|
337
|
+
elu: 0
|
|
338
|
+
};
|
|
339
|
+
const old = ready.get(slot);
|
|
340
|
+
ready.set(slot, {
|
|
341
|
+
worker,
|
|
342
|
+
port
|
|
343
|
+
});
|
|
344
|
+
if (incoming.get(slot) === worker) {
|
|
345
|
+
incoming.delete(slot);
|
|
346
|
+
if (old) {
|
|
347
|
+
const oldState = tracked.get(old.worker);
|
|
348
|
+
if (oldState) oldState.retiring = true;
|
|
349
|
+
retire(old.worker, rollDrainMs);
|
|
350
|
+
}
|
|
351
|
+
return rollNext();
|
|
352
|
+
}
|
|
353
|
+
name ??= agentName;
|
|
354
|
+
if (!ending && ready.size === slots) {
|
|
355
|
+
started = true;
|
|
356
|
+
booted.resolve({ name });
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const onPong = (worker, state, pong) => {
|
|
360
|
+
const at = now();
|
|
361
|
+
const sent = state.pingSentAt;
|
|
362
|
+
state.heard = at;
|
|
363
|
+
state.load = {
|
|
364
|
+
calls: pong.calls + Math.max(0, state.admitted - pong.received),
|
|
365
|
+
elu: pong.elu
|
|
366
|
+
};
|
|
367
|
+
state.pingSentAt = void 0;
|
|
368
|
+
if (sent === void 0 || at - sent <= 500) return;
|
|
369
|
+
if (at - (state.slowLoggedAt ?? Number.NEGATIVE_INFINITY) < 3e4) return;
|
|
370
|
+
state.slowLoggedAt = at;
|
|
371
|
+
log(`${who(worker)} answered a ping in ${at - sent}ms; its event loop is lagging`);
|
|
372
|
+
};
|
|
373
|
+
/** The origin stopped waiting, so nothing is owed back to it; tell the target to stop delivering. */
|
|
374
|
+
const cancelRelay = (origin, originId) => {
|
|
375
|
+
for (const [id, entry] of relays) {
|
|
376
|
+
if (entry.origin !== origin || entry.originId !== originId) continue;
|
|
377
|
+
relays.delete(id);
|
|
378
|
+
entry.target.send({
|
|
379
|
+
type: "aai-start:relay-cancel",
|
|
380
|
+
id
|
|
381
|
+
});
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const settleRelay = (from, id, outcome) => {
|
|
386
|
+
const entry = relays.get(id);
|
|
387
|
+
if (!entry || entry.target !== from) return;
|
|
388
|
+
relays.delete(id);
|
|
389
|
+
answer(entry.origin, entry.originId, outcome);
|
|
390
|
+
};
|
|
391
|
+
host.onMessage((worker, message) => {
|
|
392
|
+
const state = tracked.get(worker);
|
|
393
|
+
if (state === void 0 || !isProtocolMessage(message)) return;
|
|
394
|
+
switch (message.type) {
|
|
395
|
+
case "aai-start:listening": return onListening(worker, state, message.port, message.name);
|
|
396
|
+
case "aai-start:fatal":
|
|
397
|
+
fatal = message.message;
|
|
398
|
+
return;
|
|
399
|
+
case "aai-start:pong": return onPong(worker, state, message);
|
|
400
|
+
case "aai-start:relay": return relay(worker, message);
|
|
401
|
+
case "aai-start:relay-cancel": return cancelRelay(worker, message.id);
|
|
402
|
+
case "aai-start:relay-result": return settleRelay(worker, message.id, message.outcome);
|
|
403
|
+
default: return;
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
/**
|
|
407
|
+
* Forget a worker that exited: answer the relays it was delivering (whether
|
|
408
|
+
* or not it was still its slot's current worker — a retired one drains
|
|
409
|
+
* them too) and drop the ones it was waiting on. `true` when it was its
|
|
410
|
+
* slot's current worker.
|
|
411
|
+
*/
|
|
412
|
+
const release = (worker, slot) => {
|
|
413
|
+
tracked.delete(worker);
|
|
414
|
+
for (const [id, entry] of relays) {
|
|
415
|
+
if (entry.target === worker) answer(entry.origin, entry.originId, "disconnected");
|
|
416
|
+
if (entry.target === worker || entry.origin === worker) relays.delete(id);
|
|
417
|
+
}
|
|
418
|
+
if (ready.get(slot)?.worker !== worker) return false;
|
|
419
|
+
ready.delete(slot);
|
|
420
|
+
return true;
|
|
421
|
+
};
|
|
422
|
+
/** An exit while draining or stopping: count the verdict, settle with the last. */
|
|
423
|
+
const onEndingExit = (worker, slot, code, signal) => {
|
|
424
|
+
const abandoned = tracked.get(worker)?.abandoned === true;
|
|
425
|
+
release(worker, slot);
|
|
426
|
+
if (code !== 0 && !((forced || abandoned) && signal === "SIGKILL")) exitCode = 1;
|
|
427
|
+
if (tracked.size === 0) settle();
|
|
428
|
+
};
|
|
429
|
+
/** An exit mid-rollover: a retired worker is simply gone; a failed replacement aborts the roll. */
|
|
430
|
+
const onRollingExit = (worker, state, how) => {
|
|
431
|
+
const { slot } = state;
|
|
432
|
+
if (state.retiring) {
|
|
433
|
+
release(worker, slot);
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
if (incoming.get(slot) !== worker) return false;
|
|
437
|
+
release(worker, slot);
|
|
438
|
+
incoming.delete(slot);
|
|
439
|
+
rollQueue = [];
|
|
440
|
+
const why = fatal === void 0 ? "" : `: ${fatal}`;
|
|
441
|
+
log(`rolling restart stopped: the replacement for slot ${slot} exited with ${how} while starting${why}`);
|
|
442
|
+
return true;
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Any other exit. Before listening it is a boot failure, which a respawn
|
|
446
|
+
* would only repeat, so the server stops; after, the slot gets a replacement.
|
|
447
|
+
*/
|
|
448
|
+
const onCrash = (worker, state, how) => {
|
|
449
|
+
const label = who(worker);
|
|
450
|
+
if (!release(worker, state.slot)) {
|
|
451
|
+
log(`${label} exited with ${how} while starting; stopping the server`);
|
|
452
|
+
bootFailure = new Error(fatal ?? `a worker exited with ${how} before it was listening`);
|
|
453
|
+
exitCode = 1;
|
|
454
|
+
stop();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const held = state.load?.calls ?? 0;
|
|
458
|
+
const cost = held === 0 ? "" : ` (it held ${held} live call${held === 1 ? "" : "s"})`;
|
|
459
|
+
log(`${label} exited with ${how}; starting a replacement${cost}`);
|
|
460
|
+
fork(state.slot);
|
|
461
|
+
};
|
|
462
|
+
host.onExit((worker, code, signal) => {
|
|
463
|
+
const state = tracked.get(worker);
|
|
464
|
+
if (state === void 0) return;
|
|
465
|
+
const how = signal ? `signal ${signal}` : `code ${code}`;
|
|
466
|
+
if (ending) return onEndingExit(worker, state.slot, code, signal);
|
|
467
|
+
if (!onRollingExit(worker, state, how)) onCrash(worker, state, how);
|
|
468
|
+
});
|
|
469
|
+
const stopPinging = every(PING_INTERVAL_MS, () => {
|
|
470
|
+
const at = now();
|
|
471
|
+
for (const [worker, state] of tracked) {
|
|
472
|
+
if (state.forkedAt !== void 0 && at - state.forkedAt >= 12e4) {
|
|
473
|
+
const why = `did not start listening within ${BOOT_TIMEOUT_MS / 1e3}s`;
|
|
474
|
+
log(`${who(worker)} ${why}; stopping it`);
|
|
475
|
+
fatal = `a worker ${why}`;
|
|
476
|
+
state.forkedAt = void 0;
|
|
477
|
+
worker.kill("SIGKILL");
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (state.heard === void 0) continue;
|
|
481
|
+
const silentFor = at - state.heard;
|
|
482
|
+
if (silentFor >= 15e3) {
|
|
483
|
+
log(`${who(worker)} has not answered for ${Math.round(silentFor / 1e3)}s; restarting it`);
|
|
484
|
+
state.heard = void 0;
|
|
485
|
+
worker.kill("SIGKILL");
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
state.pingSentAt ??= at;
|
|
489
|
+
worker.send({ type: "aai-start:ping" });
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
exited.promise.then(stopPinging);
|
|
493
|
+
for (let slot = 0; slot < slots; slot++) fork(slot);
|
|
494
|
+
return {
|
|
495
|
+
ready: booted.promise,
|
|
496
|
+
exited: exited.promise,
|
|
497
|
+
target: (slot) => ready.get(slot),
|
|
498
|
+
accepting: () => !ending,
|
|
499
|
+
admit: (slot, resume) => {
|
|
500
|
+
if (ending && !resume) return "draining";
|
|
501
|
+
const current = ready.get(slot);
|
|
502
|
+
const state = current && tracked.get(current.worker);
|
|
503
|
+
const load = state?.load;
|
|
504
|
+
if (!(state && load)) return "ok";
|
|
505
|
+
if (load.calls >= maxCalls) return "full";
|
|
506
|
+
load.calls += 1;
|
|
507
|
+
state.admitted += 1;
|
|
508
|
+
return "ok";
|
|
509
|
+
},
|
|
510
|
+
status: () => [...tracked].map(([worker, state]) => {
|
|
511
|
+
let phase = state.load ? "serving" : "starting";
|
|
512
|
+
if (ending || state.retiring) phase = "draining";
|
|
513
|
+
return {
|
|
514
|
+
slot: state.slot,
|
|
515
|
+
pid: worker.pid,
|
|
516
|
+
state: phase,
|
|
517
|
+
calls: state.load?.calls ?? 0,
|
|
518
|
+
elu: state.load?.elu ?? 0
|
|
519
|
+
};
|
|
520
|
+
}),
|
|
521
|
+
drain: (timeoutMs) => {
|
|
522
|
+
if (!ending) end(timeoutMs);
|
|
523
|
+
},
|
|
524
|
+
stop,
|
|
525
|
+
roll
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
529
|
+
export { isProtocolMessage as a, nodeCluster as c, _start_workers_exports as i, superviseWorkers as l, SLOTS_ENV as n, isStartWorker as o, SLOT_ENV as r, loadCluster as s, DEFAULT_DRAIN_TIMEOUT_S as t };
|