@alexkroman1/aai-cli 15.0.0 → 16.0.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 +8 -5
- package/bin.mjs +12 -3
- package/dist/_build-target-55dJisQ-.mjs +649 -0
- package/dist/_build-target.d.ts +105 -108
- package/dist/_deno-output.d.ts +23 -0
- package/dist/_deno-target.d.ts +73 -0
- package/dist/{_init-Bsi3DZNJ.mjs → _init-BzQbV8Zh.mjs} +3 -1
- package/dist/_modal-app.d.ts +77 -0
- package/dist/_modal-output.d.ts +31 -0
- package/dist/_modal-target.d.ts +64 -0
- package/dist/_target-bundle.d.ts +27 -0
- package/dist/_target-drain.d.ts +44 -0
- package/dist/_target-output.d.ts +63 -0
- package/dist/{_templates-CIlJ3Vay.mjs → _templates-CuP74F8D.mjs} +94 -4
- package/dist/_templates.d.ts +14 -1
- package/dist/_vercel-output.d.ts +4 -19
- package/dist/_vercel-target.d.ts +169 -0
- package/dist/{test-D032V2cA.mjs → _vitest-runner-AVR9VtXh.mjs} +28 -68
- package/dist/_vitest-runner.d.ts +154 -0
- package/dist/build-ButI2IKc.mjs +689 -0
- package/dist/build.d.ts +11 -0
- package/dist/cli.mjs +14 -20
- package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
- package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
- package/dist/{init-CFyusRbq.mjs → init-D363Ls5u.mjs} +13 -39
- package/dist/init.d.ts +5 -10
- package/dist/scaffold/CLAUDE.md +185 -35
- package/dist/scaffold/package.json +4 -4
- package/dist/start.mjs +3 -1
- package/dist/{studio-C_zuRC_z.mjs → studio-CtRBVVFR.mjs} +1 -1
- package/dist/templates/briefing-desk/agent.eval.test.ts +34 -6
- package/dist/templates/briefing-desk/agent.test.ts +347 -55
- package/dist/templates/briefing-desk/agent.ts +12 -0
- package/dist/templates/briefing-desk/shared.ts +220 -31
- package/dist/templates/briefing-desk/slack.ts +108 -0
- package/dist/templates/briefing-desk/system-prompt.md +12 -2
- package/dist/templates/briefing-desk/tools/briefing_so_far.ts +15 -7
- package/dist/templates/briefing-desk/tools/research_topic.ts +20 -28
- package/dist/templates/briefing-desk/tools/send_briefing.ts +77 -0
- package/dist/templates/briefing-desk/tools/verify_claim.ts +60 -14
- package/dist/templates/call-audit/agent.eval.test.ts +5 -0
- package/dist/templates/call-audit/agent.test.ts +6 -1
- package/dist/templates/call-audit/agent.ts +10 -23
- package/dist/templates/call-audit/client.tsx +30 -55
- package/dist/templates/call-audit/guards.test.ts +233 -0
- package/dist/templates/call-audit/workflows/audit.ts +95 -16
- package/dist/templates/call-audit/workflows/ingest.ts +107 -88
- package/dist/templates/call-audit/workflows/media.ts +98 -7
- package/dist/templates/call-audit/workflows/summarize.ts +35 -31
- package/dist/templates/call-audit/workflows/sync-api.ts +15 -6
- package/dist/templates/code-interpreter/agent.eval.test.ts +104 -56
- package/dist/templates/code-interpreter/agent.test.ts +44 -56
- package/dist/templates/code-interpreter/system-prompt.md +1 -1
- package/dist/templates/dispatch-center/agent.eval.test.ts +61 -24
- package/dist/templates/dispatch-center/agent.test.ts +253 -48
- package/dist/templates/dispatch-center/agent.ts +28 -1
- package/dist/templates/dispatch-center/client.tsx +126 -201
- package/dist/templates/dispatch-center/events.ts +48 -0
- package/dist/templates/dispatch-center/shared.ts +42 -1
- package/dist/templates/dispatch-center/tools/incident_create.ts +3 -2
- package/dist/templates/dispatch-center/tools/incident_escalate.ts +2 -1
- package/dist/templates/dispatch-center/tools/ops_dashboard.ts +35 -15
- package/dist/templates/dispatch-center/tools/ops_run_scenario.ts +3 -1
- package/dist/templates/dispatch-center/tools/resources_dispatch.ts +2 -2
- package/dist/templates/executive-assistant/agent.eval.test.ts +233 -0
- package/dist/templates/executive-assistant/agent.test.ts +672 -0
- package/dist/templates/executive-assistant/agent.ts +50 -0
- package/dist/templates/executive-assistant/calendar.test.ts +198 -0
- package/dist/templates/executive-assistant/client.tsx +195 -0
- package/dist/templates/executive-assistant/inbox.ts +233 -0
- package/dist/templates/executive-assistant/meeting.ts +138 -0
- package/dist/templates/executive-assistant/nodes.ts +152 -0
- package/dist/templates/executive-assistant/prompts.ts +331 -0
- package/dist/templates/executive-assistant/review.ts +425 -0
- package/dist/templates/executive-assistant/shared.ts +490 -0
- package/dist/templates/executive-assistant/system-prompt.md +15 -0
- package/dist/templates/executive-assistant/tools/accept.ts +10 -0
- package/dist/templates/executive-assistant/tools/ask_question.ts +30 -0
- package/dist/templates/executive-assistant/tools/draft_reply.ts +67 -0
- package/dist/templates/executive-assistant/tools/edit.ts +10 -0
- package/dist/templates/executive-assistant/tools/ignore.ts +10 -0
- package/dist/templates/executive-assistant/tools/inbox_status.ts +27 -0
- package/dist/templates/executive-assistant/tools/meeting_assistant.ts +52 -0
- package/dist/templates/executive-assistant/tools/new_email.ts +50 -0
- package/dist/templates/executive-assistant/tools/open_email.ts +165 -0
- package/dist/templates/executive-assistant/tools/respond.ts +10 -0
- package/dist/templates/executive-assistant/tools/review_memory.ts +22 -0
- package/dist/templates/executive-assistant/tools/send_calendar_invite.ts +68 -0
- package/dist/templates/executive-assistant/tools/triage_inbox.ts +75 -0
- package/dist/templates/health-assistant/agent.test.ts +134 -15
- package/dist/templates/health-assistant/agent.ts +8 -1
- package/dist/templates/health-assistant/fda.test.ts +130 -0
- package/dist/templates/health-assistant/fda.ts +75 -16
- package/dist/templates/health-assistant/system-prompt.md +9 -0
- package/dist/templates/health-assistant/tools/check_drug_interaction.ts +5 -2
- package/dist/templates/health-assistant/tools/medication_lookup.ts +16 -11
- package/dist/templates/hiring-desk/agent.eval.test.ts +242 -0
- package/dist/templates/hiring-desk/agent.test.ts +1021 -0
- package/dist/templates/hiring-desk/agent.ts +38 -0
- package/dist/templates/hiring-desk/client.tsx +154 -0
- package/dist/templates/hiring-desk/crews.ts +432 -0
- package/dist/templates/hiring-desk/leads.json +86 -0
- package/dist/templates/hiring-desk/screening-lock.test.ts +77 -0
- package/dist/templates/hiring-desk/screening-lock.ts +51 -0
- package/dist/templates/hiring-desk/shared.ts +480 -0
- package/dist/templates/hiring-desk/system-prompt.md +21 -0
- package/dist/templates/hiring-desk/tools/candidate_details.ts +49 -0
- package/dist/templates/hiring-desk/tools/proceed_to_emails.ts +127 -0
- package/dist/templates/hiring-desk/tools/read_email.ts +50 -0
- package/dist/templates/hiring-desk/tools/rescore_with_feedback.ts +140 -0
- package/dist/templates/hiring-desk/tools/screen_candidates.ts +128 -0
- package/dist/templates/hiring-desk/tools/screening_status.ts +51 -0
- package/dist/templates/hotel-desk/agent.eval.test.ts +177 -0
- package/dist/templates/hotel-desk/agent.test.ts +1128 -0
- package/dist/templates/hotel-desk/agent.ts +63 -0
- package/dist/templates/hotel-desk/booking.ts +159 -0
- package/dist/templates/hotel-desk/card.ts +92 -0
- package/dist/templates/hotel-desk/catalogs.ts +219 -0
- package/dist/templates/hotel-desk/client.tsx +137 -0
- package/dist/templates/hotel-desk/concierge.ts +99 -0
- package/dist/templates/hotel-desk/desk-seams.test.ts +334 -0
- package/dist/templates/hotel-desk/desk.ts +224 -0
- package/dist/templates/hotel-desk/disputes.ts +216 -0
- package/dist/templates/hotel-desk/events.ts +79 -0
- package/dist/templates/hotel-desk/hotel.ts +412 -0
- package/dist/templates/hotel-desk/policies.ts +209 -0
- package/dist/templates/hotel-desk/records.ts +384 -0
- package/dist/templates/hotel-desk/restaurant.ts +147 -0
- package/dist/templates/hotel-desk/seed.ts +955 -0
- package/dist/templates/hotel-desk/shared.ts +354 -0
- package/dist/templates/hotel-desk/system-prompt.md +76 -0
- package/dist/templates/hotel-desk/tools/abandon_booking.ts +30 -0
- package/dist/templates/hotel-desk/tools/add_to_waitlist.ts +41 -0
- package/dist/templates/hotel-desk/tools/book_airport_car.ts +57 -0
- package/dist/templates/hotel-desk/tools/book_business_center.ts +44 -0
- package/dist/templates/hotel-desk/tools/book_spa_appointment.ts +39 -0
- package/dist/templates/hotel-desk/tools/book_tour.ts +35 -0
- package/dist/templates/hotel-desk/tools/cancel_restaurant_reservation.ts +25 -0
- package/dist/templates/hotel-desk/tools/cancel_room_booking.ts +63 -0
- package/dist/templates/hotel-desk/tools/check_restaurant_availability.ts +24 -0
- package/dist/templates/hotel-desk/tools/check_room_availability.ts +40 -0
- package/dist/templates/hotel-desk/tools/choose_room.ts +93 -0
- package/dist/templates/hotel-desk/tools/confirm_booking.ts +153 -0
- package/dist/templates/hotel-desk/tools/dispatch_emergency.ts +61 -0
- package/dist/templates/hotel-desk/tools/dispute_charge.ts +90 -0
- package/dist/templates/hotel-desk/tools/flag_late_arrival.ts +26 -0
- package/dist/templates/hotel-desk/tools/lookup_booking.ts +48 -0
- package/dist/templates/hotel-desk/tools/lookup_guest_history.ts +28 -0
- package/dist/templates/hotel-desk/tools/lookup_invoice.ts +26 -0
- package/dist/templates/hotel-desk/tools/lookup_policy.ts +20 -0
- package/dist/templates/hotel-desk/tools/lookup_restaurant_reservation.ts +27 -0
- package/dist/templates/hotel-desk/tools/modify_restaurant_reservation.ts +75 -0
- package/dist/templates/hotel-desk/tools/order_flowers.ts +40 -0
- package/dist/templates/hotel-desk/tools/record_card.ts +46 -0
- package/dist/templates/hotel-desk/tools/record_followup.ts +50 -0
- package/dist/templates/hotel-desk/tools/record_group_inquiry.ts +44 -0
- package/dist/templates/hotel-desk/tools/record_guest_details.ts +71 -0
- package/dist/templates/hotel-desk/tools/reinstate_booking.ts +65 -0
- package/dist/templates/hotel-desk/tools/request_flight_reconfirmation.ts +54 -0
- package/dist/templates/hotel-desk/tools/resend_confirmation.ts +39 -0
- package/dist/templates/hotel-desk/tools/reserve_table.ts +87 -0
- package/dist/templates/hotel-desk/tools/resolve_room_conflict.ts +48 -0
- package/dist/templates/hotel-desk/tools/schedule_wakeup_call.ts +48 -0
- package/dist/templates/hotel-desk/tools/set_do_not_disturb.ts +28 -0
- package/dist/templates/hotel-desk/tools/set_extras.ts +51 -0
- package/dist/templates/hotel-desk/tools/set_stay.ts +97 -0
- package/dist/templates/hotel-desk/tools/start_booking_modification.ts +57 -0
- package/dist/templates/hotel-desk/tools/start_room_booking.ts +49 -0
- package/dist/templates/hotel-desk/tools/take_guest_message.ts +71 -0
- package/dist/templates/hotel-desk/tools/transfer_call.ts +47 -0
- package/dist/templates/hotel-desk/tools/update_card.ts +45 -0
- package/dist/templates/hotel-desk/tools/verify_booking.ts +95 -0
- package/dist/templates/infocom-adventure/agent.eval.test.ts +33 -1
- package/dist/templates/infocom-adventure/agent.test.ts +207 -52
- package/dist/templates/infocom-adventure/agent.ts +14 -3
- package/dist/templates/infocom-adventure/client.tsx +138 -176
- package/dist/templates/infocom-adventure/shared.ts +126 -6
- package/dist/templates/infocom-adventure/system-prompt.md +4 -4
- package/dist/templates/infocom-adventure/tools/game_state_drop.ts +20 -4
- package/dist/templates/infocom-adventure/tools/game_state_get.ts +6 -5
- package/dist/templates/infocom-adventure/tools/game_state_score.ts +9 -3
- package/dist/templates/link-digest/agent.eval.test.ts +8 -0
- package/dist/templates/link-digest/agent.test.ts +285 -29
- package/dist/templates/link-digest/agent.ts +9 -0
- package/dist/templates/link-digest/api-client.ts +144 -0
- package/dist/templates/link-digest/client.tsx +11 -30
- package/dist/templates/link-digest/workflows/digest.ts +72 -24
- package/dist/templates/night-owl/agent.eval.test.ts +55 -40
- package/dist/templates/night-owl/agent.test.ts +146 -12
- package/dist/templates/night-owl/client.tsx +50 -17
- package/dist/templates/night-owl/shared.ts +33 -2
- package/dist/templates/night-owl/system-prompt.md +3 -0
- package/dist/templates/night-owl/tools/recommend.ts +4 -1
- package/dist/templates/night-owl/tools/revisit.ts +49 -0
- package/dist/templates/pipeline-simple/agent.eval.test.ts +7 -6
- package/dist/templates/pipeline-simple/agent.test.ts +48 -91
- package/dist/templates/pipeline-simple/modes.test.ts +151 -0
- package/dist/templates/pipeline-simple/stages.test.ts +332 -0
- package/dist/templates/pizza-ordering/agent.test.ts +94 -38
- package/dist/templates/pizza-ordering/client.tsx +10 -5
- package/dist/templates/pizza-ordering/shared.ts +65 -6
- package/dist/templates/pizza-ordering/tools/add_pizza.ts +2 -7
- package/dist/templates/pizza-ordering/tools/place_order.ts +9 -6
- package/dist/templates/pizza-ordering/tools/remove_pizza.ts +6 -11
- package/dist/templates/pizza-ordering/tools/update_pizza.ts +8 -9
- package/dist/templates/pizza-ordering/tools/view_order.ts +2 -3
- package/dist/templates/plan-and-execute/agent.eval.test.ts +14 -6
- package/dist/templates/plan-and-execute/agent.test.ts +300 -113
- package/dist/templates/plan-and-execute/client.tsx +18 -7
- package/dist/templates/plan-and-execute/procedure.ts +162 -64
- package/dist/templates/plan-and-execute/prompts.ts +51 -15
- package/dist/templates/plan-and-execute/shared.ts +151 -45
- package/dist/templates/plan-and-execute/tools/plan_status.ts +15 -6
- package/dist/templates/plan-and-execute/tools/revise_plan.ts +2 -2
- package/dist/templates/plan-and-execute/tools/start_plan.ts +2 -2
- package/dist/templates/plan-and-execute/tools/work_next_step.ts +15 -13
- package/dist/templates/podcast-digest/agent.eval.test.ts +12 -7
- package/dist/templates/podcast-digest/agent.test.ts +126 -51
- package/dist/templates/podcast-digest/client.tsx +104 -68
- package/dist/templates/podcast-digest/workflows/digest.ts +71 -48
- package/dist/templates/podcast-digest/workflows/feeds.ts +5 -7
- package/dist/templates/podcast-digest/workflows/slack.ts +82 -17
- package/dist/templates/recap-workflow/agent.eval.test.ts +193 -209
- package/dist/templates/recap-workflow/agent.test.ts +207 -26
- package/dist/templates/recap-workflow/tools/recap_status.ts +2 -2
- package/dist/templates/recap-workflow/workflows/recap.ts +39 -28
- package/dist/templates/redline/agent.eval.test.ts +40 -3
- package/dist/templates/redline/agent.test.ts +216 -6
- package/dist/templates/redline/agent.ts +54 -34
- package/dist/templates/redline/client.tsx +82 -126
- package/dist/templates/redline/form.ts +74 -0
- package/dist/templates/redline/workflows/prompts.ts +3 -3
- package/dist/templates/redline/workflows/redline.ts +73 -4
- package/dist/templates/research-workflow/agent.eval.test.ts +152 -150
- package/dist/templates/research-workflow/agent.test.ts +436 -126
- package/dist/templates/research-workflow/agent.ts +20 -5
- package/dist/templates/research-workflow/tools/file_it_now.ts +11 -1
- package/dist/templates/research-workflow/tools/research_status.ts +39 -4
- package/dist/templates/research-workflow/workflows/filing.ts +164 -0
- package/dist/templates/research-workflow/workflows/notes.ts +69 -0
- package/dist/templates/research-workflow/workflows/prompts.ts +45 -31
- package/dist/templates/research-workflow/workflows/research.ts +227 -280
- package/dist/templates/research-workflow/workflows/review.ts +43 -0
- package/dist/templates/retail/address.ts +29 -35
- package/dist/templates/retail/agent.eval.test.ts +36 -16
- package/dist/templates/retail/agent.test.ts +104 -26
- package/dist/templates/retail/agent.ts +12 -0
- package/dist/templates/retail/cancel.ts +39 -42
- package/dist/templates/retail/client.tsx +111 -176
- package/dist/templates/retail/payment.ts +38 -43
- package/dist/templates/retail/pending.test.ts +16 -8
- package/dist/templates/retail/registry.test.ts +108 -49
- package/dist/templates/retail/resolve.test.ts +2 -63
- package/dist/templates/retail/resolve.ts +16 -56
- package/dist/templates/retail/returns.ts +53 -54
- package/dist/templates/retail/seed.test.ts +2 -1
- package/dist/templates/retail/shared.ts +58 -14
- package/dist/templates/retail/store.test.ts +40 -29
- package/dist/templates/retail/store.ts +60 -23
- package/dist/templates/retail/swap.ts +78 -81
- package/dist/templates/retail/tools/find_user_id_by_name_zip.ts +2 -1
- package/dist/templates/roadside-assist/agent.eval.test.ts +164 -0
- package/dist/templates/roadside-assist/agent.test.ts +617 -0
- package/dist/templates/roadside-assist/agent.ts +85 -0
- package/dist/templates/roadside-assist/call.ts +237 -0
- package/dist/templates/roadside-assist/events.ts +92 -0
- package/dist/templates/roadside-assist/shared.ts +334 -0
- package/dist/templates/roadside-assist/system-prompt.md +37 -0
- package/dist/templates/roadside-assist/tools/acknowledge_disclosure.ts +47 -0
- package/dist/templates/roadside-assist/tools/dispatch_truck.ts +148 -0
- package/dist/templates/roadside-assist/tools/job_status.ts +38 -0
- package/dist/templates/roadside-assist/tools/lookup_coverage.ts +72 -0
- package/dist/templates/roadside-assist/tools/report_location.ts +79 -0
- package/dist/templates/roadside-assist/tools/service_disclosure.ts +45 -0
- package/dist/templates/roadside-assist/yard.test.ts +158 -0
- package/dist/templates/roadside-assist/yard.ts +183 -0
- package/dist/templates/simple/agent.eval.test.ts +4 -1
- package/dist/templates/simple/agent.test.ts +54 -31
- package/dist/templates/solo-rpg/agent.eval.test.ts +19 -11
- package/dist/templates/solo-rpg/agent.test.ts +402 -175
- package/dist/templates/solo-rpg/agent.ts +14 -3
- package/dist/templates/solo-rpg/client.tsx +10 -10
- package/dist/templates/solo-rpg/shared.ts +198 -79
- package/dist/templates/solo-rpg/tools/action_roll.ts +7 -3
- package/dist/templates/solo-rpg/tools/burn_momentum.ts +16 -8
- package/dist/templates/solo-rpg/tools/oracle.ts +7 -7
- package/dist/templates/solo-rpg/tools/setup_character.ts +5 -5
- package/dist/templates/solo-rpg/tools/update_state.ts +29 -18
- package/dist/templates/spoken-summary/agent.test.ts +70 -15
- package/dist/templates/spoken-summary/agent.ts +25 -21
- package/dist/templates/spoken-summary/client.tsx +68 -88
- package/dist/templates/spoken-summary/workflows/summarize.ts +26 -8
- package/dist/templates/support-line/agent.test.ts +167 -36
- package/dist/templates/support-line/client.tsx +21 -9
- package/dist/templates/support-line/nodes.ts +74 -32
- package/dist/templates/support-line/procedure.ts +66 -21
- package/dist/templates/support-line/prompts.ts +9 -0
- package/dist/templates/support-line/shared.ts +55 -17
- package/dist/templates/support-line/tools/answer_question.ts +14 -14
- package/dist/templates/transcription-workflow/agent.test.ts +135 -13
- package/dist/templates/transcription-workflow/client.tsx +30 -23
- package/dist/templates/transcription-workflow/recover.test.ts +93 -12
- package/dist/templates/transcription-workflow/recover.ts +29 -5
- package/dist/templates/transcription-workflow/run-panel.tsx +40 -51
- package/dist/templates/transcription-workflow/workflows/normalize.ts +125 -24
- package/dist/templates/transcription-workflow/workflows/stream.ts +4 -1
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +7 -5
- package/dist/templates/transcription-workflow/workflows/wav.ts +42 -117
- package/dist/templates/travel-concierge/agent.eval.test.ts +6 -4
- package/dist/templates/travel-concierge/agent.test.ts +209 -40
- package/dist/templates/travel-concierge/agent.ts +24 -4
- package/dist/templates/travel-concierge/call-events.ts +80 -0
- package/dist/templates/travel-concierge/client.tsx +3 -2
- package/dist/templates/travel-concierge/routing.ts +5 -7
- package/dist/templates/travel-concierge/shared.ts +202 -41
- package/dist/templates/travel-concierge/tools/book_car_rental.ts +2 -4
- package/dist/templates/travel-concierge/tools/book_excursion.ts +2 -4
- package/dist/templates/travel-concierge/tools/book_hotel.ts +2 -4
- package/dist/templates/travel-concierge/tools/cancel_ticket.ts +6 -4
- package/dist/templates/travel-concierge/tools/search_car_rentals.ts +3 -5
- package/dist/templates/travel-concierge/tools/search_excursions.ts +3 -5
- package/dist/templates/travel-concierge/tools/search_flights.ts +20 -9
- package/dist/templates/travel-concierge/tools/search_hotels.ts +3 -5
- package/dist/templates/travel-concierge/tools/update_ticket.ts +2 -4
- package/dist/templates/web-researcher/agent.eval.test.ts +3 -6
- package/dist/templates/web-researcher/agent.test.ts +102 -65
- package/dist/templates/web-researcher/agent.ts +93 -1
- package/dist/templates/web-researcher/system-prompt.md +7 -1
- package/dist/templates/word-wrangler/agent.eval.test.ts +157 -0
- package/dist/templates/word-wrangler/agent.test.ts +432 -0
- package/dist/templates/word-wrangler/agent.ts +35 -0
- package/dist/templates/word-wrangler/client.tsx +211 -0
- package/dist/templates/word-wrangler/game.ts +107 -0
- package/dist/templates/word-wrangler/guess.ts +63 -0
- package/dist/templates/word-wrangler/player.ts +68 -0
- package/dist/templates/word-wrangler/shared.ts +263 -0
- package/dist/templates/word-wrangler/system-prompt.md +15 -0
- package/dist/templates/word-wrangler/tools/final_score.ts +37 -0
- package/dist/templates/word-wrangler/tools/relay_description.ts +137 -0
- package/dist/templates/word-wrangler/tools/repeat_word.ts +19 -0
- package/dist/templates/word-wrangler/tools/skip_word.ts +31 -0
- package/dist/templates/word-wrangler/tools/start_game.ts +47 -0
- package/dist/templates/word-wrangler/words.ts +278 -0
- package/dist/test-Cllnx81G.mjs +83 -0
- package/dist/test.d.ts +9 -114
- package/package.json +5 -5
- package/dist/build-BhEaxBPu.mjs +0 -481
- package/dist/templates/embedded-assets/agent.eval.test.ts +0 -130
- package/dist/templates/embedded-assets/agent.test.ts +0 -79
- package/dist/templates/embedded-assets/agent.ts +0 -7
- package/dist/templates/embedded-assets/knowledge.json +0 -20
- package/dist/templates/embedded-assets/shared.ts +0 -17
- package/dist/templates/embedded-assets/system-prompt.md +0 -13
- package/dist/templates/embedded-assets/tools/list_topics.ts +0 -9
- package/dist/templates/embedded-assets/tools/search_knowledge.ts +0 -26
- package/dist/templates/math-buddy/agent.eval.test.ts +0 -128
- package/dist/templates/math-buddy/agent.test.ts +0 -126
- package/dist/templates/math-buddy/agent.ts +0 -15
- package/dist/templates/math-buddy/system-prompt.md +0 -12
- package/dist/templates/personal-finance/agent.eval.test.ts +0 -149
- package/dist/templates/personal-finance/agent.test.ts +0 -127
- package/dist/templates/personal-finance/agent.ts +0 -8
- package/dist/templates/personal-finance/system-prompt.md +0 -21
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { _ as DENO_ENTRY_FILE, a as VERCEL_ENTRY_SOURCE, c as VERCEL_STATIC_DIR, d as MODAL_ENTRY_FILE, f as MODAL_ENTRY_SOURCE, g as DENO_CONFIG_SOURCE, h as DENO_CONFIG_FILE, i as VERCEL_BUILD_CONFIG_SOURCE, l as vercelFunctionConfigSource, m as MODAL_PORT, n as TARGET_OUTPUTS, o as VERCEL_FUNCTION_DIR, p as MODAL_OUTPUT_DIR, r as resolveBuildTarget, s as VERCEL_OUTPUT_DIR, u as MODAL_APP_FILE, v as DENO_ENTRY_SOURCE, y as DENO_OUTPUT_DIR } from "./_build-target-55dJisQ-.mjs";
|
|
3
|
+
import { a as ok, t as CliError } from "./_output-DBP9Op_d.mjs";
|
|
4
|
+
import { n as log, r as notify } from "./_ui-DCt4qZrk.mjs";
|
|
5
|
+
import { n as withPreservedNodeEnv } from "./_vite-env-kejF0p2L.mjs";
|
|
6
|
+
import { n as WORKER_ARTIFACT_REL, t as CLIENT_ARTIFACT_REL } from "./_artifacts-BJOYGQPp.mjs";
|
|
7
|
+
import { r as evalWorkerBundle, t as buildAgentBundle } from "./_bundler-DM0d0M7m.mjs";
|
|
8
|
+
import { assertTypechecks } from "./_typecheck-gate-U3jcil8L.mjs";
|
|
9
|
+
import { n as classifyVitestError, r as runVitest } from "./_vitest-runner-AVR9VtXh.mjs";
|
|
10
|
+
import { n as scanWorkflowDeterminism, t as determinismWarnings } from "./_workflow-determinism-CvpqMpdh.mjs";
|
|
11
|
+
import { TEST_FILES } from "./test-Cllnx81G.mjs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import fs from "node:fs/promises";
|
|
14
|
+
import { invariant } from "@alexkroman1/aai/internal";
|
|
15
|
+
import { build } from "vite";
|
|
16
|
+
import { defaultClientDir } from "@alexkroman1/aai-ui/client-dir";
|
|
17
|
+
import { agentConfigWarnings } from "@alexkroman1/aai/manifest";
|
|
18
|
+
import { DEFAULT_SYSTEM_PROMPT } from "@alexkroman1/aai";
|
|
19
|
+
//#region src/_target-bundle.ts
|
|
20
|
+
/**
|
|
21
|
+
* Bundling a deployment target's ENTRY into one self-contained ESM file.
|
|
22
|
+
*
|
|
23
|
+
* Shared by every target that emits one, because the reason is the same at
|
|
24
|
+
* each: the entry imports `@alexkroman1/aai-cli/start`, and what a host does
|
|
25
|
+
* with the module graph behind that import differs in ways that are all bad.
|
|
26
|
+
*
|
|
27
|
+
* - **Vercel** traces it with `@vercel/nft`, which cannot follow the dynamic
|
|
28
|
+
* `import(pathToFileURL(...))` that loads the worker.
|
|
29
|
+
* - **Deno Deploy** caches the dependency graph of the PACKAGE rather than of
|
|
30
|
+
* the import, and `@alexkroman1/aai-cli`'s dependencies are a build
|
|
31
|
+
* toolchain — vite, rolldown and the rest. Measured: the build exceeded its
|
|
32
|
+
* 1024 MiB memory limit at "Caching dependencies for the entrypoint" before
|
|
33
|
+
* it reached any code of ours.
|
|
34
|
+
*
|
|
35
|
+
* A bundle removes the question. The host resolves nothing, installs nothing,
|
|
36
|
+
* and what runs is what the project's own lockfile pinned.
|
|
37
|
+
*
|
|
38
|
+
* The entry is written INTO the project rather than a temp directory, because
|
|
39
|
+
* that is what makes `@alexkroman1/aai-cli/start` resolve against the user's
|
|
40
|
+
* install. Removed in a `finally`: a build that throws must not leave a file
|
|
41
|
+
* that looks authored.
|
|
42
|
+
*/
|
|
43
|
+
/** Bundle `source` as if it were a module in `cwd`, and answer the code. */
|
|
44
|
+
async function bundleTargetEntry(cwd, source, name) {
|
|
45
|
+
const entryPath = path.join(cwd, ".aai", `${name}-entry.mjs`);
|
|
46
|
+
await fs.mkdir(path.dirname(entryPath), { recursive: true });
|
|
47
|
+
await fs.writeFile(entryPath, source, "utf-8");
|
|
48
|
+
let result;
|
|
49
|
+
try {
|
|
50
|
+
result = await withPreservedNodeEnv(() => build({
|
|
51
|
+
root: cwd,
|
|
52
|
+
logLevel: "silent",
|
|
53
|
+
configFile: false,
|
|
54
|
+
ssr: { noExternal: true },
|
|
55
|
+
build: {
|
|
56
|
+
ssr: true,
|
|
57
|
+
lib: {
|
|
58
|
+
entry: entryPath,
|
|
59
|
+
formats: ["es"],
|
|
60
|
+
fileName: name
|
|
61
|
+
},
|
|
62
|
+
target: "node20",
|
|
63
|
+
minify: false,
|
|
64
|
+
write: false,
|
|
65
|
+
rollupOptions: { output: {
|
|
66
|
+
entryFileNames: "[name].mjs",
|
|
67
|
+
codeSplitting: false
|
|
68
|
+
} }
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
} finally {
|
|
72
|
+
await fs.rm(entryPath, { force: true }).catch(() => void 0);
|
|
73
|
+
}
|
|
74
|
+
const output = Array.isArray(result) ? result[0] : result;
|
|
75
|
+
invariant(output !== void 0, "target.entry.output", () => ({ name }));
|
|
76
|
+
const chunk = output.output.find((o) => o.type === "chunk" && o.isEntry);
|
|
77
|
+
invariant(chunk !== void 0, "target.entry.chunk", () => ({
|
|
78
|
+
name,
|
|
79
|
+
kinds: output.output.map((o) => o.type)
|
|
80
|
+
}));
|
|
81
|
+
return chunk.code;
|
|
82
|
+
}
|
|
83
|
+
/** Whether a path exists — the check every emit makes of an optional file. */
|
|
84
|
+
async function targetPathExists(target) {
|
|
85
|
+
return await fs.stat(target).then(() => true, () => false);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/_target-output.ts
|
|
89
|
+
/**
|
|
90
|
+
* The SELF-CONTAINED deployment directory — the half two targets share.
|
|
91
|
+
*
|
|
92
|
+
* `deno deploy` uploads a directory and runs one entrypoint in it; `modal
|
|
93
|
+
* deploy` uploads a directory into an image layer and spawns node on one file
|
|
94
|
+
* in it. Neither performs an install, so both emits have the identical job:
|
|
95
|
+
* put beside the bundled entry every file the server opens at RUN time. Each
|
|
96
|
+
* of the three was found by a deployment failing without it, which is the
|
|
97
|
+
* reason this is one module and not a shape each target re-derives —
|
|
98
|
+
* a fourth target must not get to rediscover them.
|
|
99
|
+
*
|
|
100
|
+
* - **`.aai/worker.mjs`**, loaded through `import(pathToFileURL(...))`. Bundling
|
|
101
|
+
* cannot inline it and nothing else would carry it.
|
|
102
|
+
* - **The browser client.** `resolveClientDir` falls back to `defaultClientDir()`,
|
|
103
|
+
* which is `require.resolve("@alexkroman1/aai-ui/package.json")` — a lookup
|
|
104
|
+
* with no `node_modules` to answer it. A bundled deployment died at boot on
|
|
105
|
+
* exactly that until the prebuilt UI was copied in.
|
|
106
|
+
* - **`.env.example`**, which DECLARES which variables become `ctx.env`. Without
|
|
107
|
+
* it every tool sees an empty env while the platform has the values set.
|
|
108
|
+
*
|
|
109
|
+
* **`.env` is deliberately absent**, the same rule the Vercel emit follows:
|
|
110
|
+
* declarations ship, values come from the host (`deno deploy env`, a
|
|
111
|
+
* `modal.Secret`). Copying it would upload a developer's live credentials AND
|
|
112
|
+
* let them outrank what the host was configured with.
|
|
113
|
+
*
|
|
114
|
+
* The nesting is not an accident. `createProjectServer` resolves the worker at
|
|
115
|
+
* `<cwd>/.aai/worker.mjs` and each entry passes its own directory as `cwd`, so
|
|
116
|
+
* the output holds its own `.aai/` — the layout the server already knows,
|
|
117
|
+
* rather than a second one this module would have to teach it.
|
|
118
|
+
*/
|
|
119
|
+
/** Files copied verbatim, each read at RUNTIME by a path no bundler can see. */
|
|
120
|
+
const RUNTIME_FILES$1 = [WORKER_ARTIFACT_REL, ".env.example"];
|
|
121
|
+
/**
|
|
122
|
+
* Write a target's self-contained directory and answer its absolute path.
|
|
123
|
+
*
|
|
124
|
+
* REMOVED first: the directory is uploaded wholesale, so anything an earlier
|
|
125
|
+
* build left in it would be deployed alongside this one.
|
|
126
|
+
*
|
|
127
|
+
* The path comes back so a target with MORE to write — Modal's `app.py` — adds
|
|
128
|
+
* it here rather than recomputing where "here" is.
|
|
129
|
+
*/
|
|
130
|
+
async function emitSelfContainedOutput(cwd, target, options = {}) {
|
|
131
|
+
const outputDir = path.join(cwd, target.outputDir);
|
|
132
|
+
await fs.rm(outputDir, {
|
|
133
|
+
recursive: true,
|
|
134
|
+
force: true
|
|
135
|
+
});
|
|
136
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
137
|
+
const bundle = options.bundle ?? ((dir) => bundleTargetEntry(dir, target.entrySource, target.name));
|
|
138
|
+
await fs.writeFile(path.join(outputDir, target.entryFile), await bundle(cwd), "utf-8");
|
|
139
|
+
for (const rel of RUNTIME_FILES$1) {
|
|
140
|
+
const from = path.join(cwd, rel);
|
|
141
|
+
if (!await targetPathExists(from)) continue;
|
|
142
|
+
const to = path.join(outputDir, rel);
|
|
143
|
+
await fs.mkdir(path.dirname(to), { recursive: true });
|
|
144
|
+
await fs.copyFile(from, to);
|
|
145
|
+
}
|
|
146
|
+
const clientSource = await targetPathExists(path.join(cwd, CLIENT_ARTIFACT_REL, "index.html")) ? path.join(cwd, CLIENT_ARTIFACT_REL) : defaultClientDir();
|
|
147
|
+
await fs.cp(clientSource, path.join(outputDir, CLIENT_ARTIFACT_REL), { recursive: true });
|
|
148
|
+
return outputDir;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/_deno-output.ts
|
|
152
|
+
/**
|
|
153
|
+
* Assemble a self-contained Deno Deploy directory — `.aai/deno/`.
|
|
154
|
+
*
|
|
155
|
+
* The assembly is `_target-output.ts`, shared with the Modal emit: both hosts
|
|
156
|
+
* upload a directory and run one file in it with no install step, so the set of
|
|
157
|
+
* runtime files that have to travel is the same set, and that module's doc
|
|
158
|
+
* carries which three and the deployment failure that found each.
|
|
159
|
+
*
|
|
160
|
+
* Deno's own half is two files. The ENTRY it bundles — see `DENO_ENTRY_SOURCE`
|
|
161
|
+
* — and a **`deno.json`** beside it (see {@link DENO_CONFIG_SOURCE}), so the
|
|
162
|
+
* directory describes how to run itself and no command against it has to
|
|
163
|
+
* re-supply `--entrypoint`.
|
|
164
|
+
*
|
|
165
|
+
* That second file is also the answer to "why is this not just the shared
|
|
166
|
+
* emit": both self-contained targets need a way to say what to RUN, and the two
|
|
167
|
+
* hosts take it differently — Deno reads a config it already understands, while
|
|
168
|
+
* Modal has no descriptor at all and needs a generated Python module.
|
|
169
|
+
*/
|
|
170
|
+
/** Write `.aai/deno/` for this project. */
|
|
171
|
+
async function emitDenoOutput(cwd, options = {}) {
|
|
172
|
+
const outputDir = await emitSelfContainedOutput(cwd, {
|
|
173
|
+
outputDir: DENO_OUTPUT_DIR,
|
|
174
|
+
entryFile: DENO_ENTRY_FILE,
|
|
175
|
+
entrySource: DENO_ENTRY_SOURCE,
|
|
176
|
+
name: "deno"
|
|
177
|
+
}, options);
|
|
178
|
+
await fs.writeFile(path.join(outputDir, DENO_CONFIG_FILE), DENO_CONFIG_SOURCE, "utf-8");
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/_modal-app.ts
|
|
182
|
+
/**
|
|
183
|
+
* The Modal app definition `aai build --target modal` emits — `app.py`.
|
|
184
|
+
*
|
|
185
|
+
* ## Why this target is a generated PYTHON file
|
|
186
|
+
*
|
|
187
|
+
* Every other target emits the host's expected entry shape and lets the host
|
|
188
|
+
* hold the rest: Vercel reads a routing table it already understands, Deno
|
|
189
|
+
* Deploy takes a directory and an entrypoint. Modal has no such descriptor.
|
|
190
|
+
* Its deploy unit is a Python module — `modal.App`, an image recipe, and a
|
|
191
|
+
* decorated function — and `modal deploy` runs that module rather than reading
|
|
192
|
+
* a manifest out of it. So the "preset" for Modal is the module itself, which
|
|
193
|
+
* is why this is the one target whose emit generates code in another language.
|
|
194
|
+
*
|
|
195
|
+
* ## The knobs are DEPLOY-TIME ENV, not edits to this file
|
|
196
|
+
*
|
|
197
|
+
* The awkward consequence is that Modal's policy — how many containers, how
|
|
198
|
+
* much CPU, which secret — lives in Python arguments rather than in a platform
|
|
199
|
+
* dashboard. A generated file carrying policy is a file people edit, and this
|
|
200
|
+
* one is overwritten by the next `aai build`, so "do not edit" would be a lie
|
|
201
|
+
* the first time somebody wanted a warm container.
|
|
202
|
+
*
|
|
203
|
+
* Four knobs are therefore read from the environment at deploy time
|
|
204
|
+
* ({@link MODAL_ENV_KNOBS}), which keeps the project committing nothing
|
|
205
|
+
* host-specific — the property `_build-target.ts` opens by defending:
|
|
206
|
+
*
|
|
207
|
+
* ```sh
|
|
208
|
+
* AAI_MODAL_MIN_CONTAINERS=1 modal deploy .aai/modal/app.py
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* The rest — cpu, memory, timeout, concurrency — stays a documented constant
|
|
212
|
+
* in the emitted file. Those are the numbers a reader needs to SEE to trust
|
|
213
|
+
* the deployment, and regenerating restates the default, which is the same
|
|
214
|
+
* contract every other generated artifact here has.
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* The Node major the emitted image may not go below — the SDK's own `engines`
|
|
218
|
+
* floor.
|
|
219
|
+
*
|
|
220
|
+
* The tag otherwise tracks the Node running the build, so the bundle runs on
|
|
221
|
+
* the runtime it was bundled for. Modal pulls any tag that exists on Docker
|
|
222
|
+
* Hub, so there is nothing to clamp from ABOVE — unlike `vercelNodeRuntime`,
|
|
223
|
+
* whose platform publishes a fixed list. The floor is the half that matters:
|
|
224
|
+
* npm does not enforce `engines` by default, so a build on Node 22 would
|
|
225
|
+
* otherwise emit a `node:22-slim` image in which the SDK genuinely does not
|
|
226
|
+
* run, and the failure would arrive as a crash-looping container.
|
|
227
|
+
*/
|
|
228
|
+
const MODAL_NODE_MAJOR_FLOOR = 24;
|
|
229
|
+
/**
|
|
230
|
+
* The Python `add_python` layers beside Node.
|
|
231
|
+
*
|
|
232
|
+
* Matches `scripts/modal_image.py`, which is the same arrangement one layer up:
|
|
233
|
+
* the container entrypoint is Modal's own Python runtime, and it spawns node.
|
|
234
|
+
*/
|
|
235
|
+
const MODAL_ADD_PYTHON = "3.13";
|
|
236
|
+
/** What a name sanitizes to when nothing usable survives — see {@link modalAppName}. */
|
|
237
|
+
const MODAL_FALLBACK_APP_NAME = "aai-agent";
|
|
238
|
+
/**
|
|
239
|
+
* Modal caps a resource name at 64 characters. Truncated rather than refused:
|
|
240
|
+
* the name is cosmetic (it appears in the app's URL), and failing a build over
|
|
241
|
+
* a long agent name would be the target's first impression.
|
|
242
|
+
*/
|
|
243
|
+
const MODAL_NAME_MAX = 64;
|
|
244
|
+
/**
|
|
245
|
+
* An agent name as a Modal app name.
|
|
246
|
+
*
|
|
247
|
+
* Modal accepts a narrow character set here and the name reaches a hostname —
|
|
248
|
+
* a deployed function is served at `<workspace>--<app>-<function>.modal.run` —
|
|
249
|
+
* so anything outside `[a-z0-9-]` becomes a dash rather than being passed
|
|
250
|
+
* through and rejected by the platform. Agent names are free text
|
|
251
|
+
* (`define({ name: "Retail Support Bot" })`), which is why this is a mapping
|
|
252
|
+
* and not a validation.
|
|
253
|
+
*
|
|
254
|
+
* Collapsed and trimmed, because `--` is what a hostname reader sees as the
|
|
255
|
+
* workspace separator, and a leading or trailing dash is not a legal label.
|
|
256
|
+
*/
|
|
257
|
+
function modalAppName(agentName) {
|
|
258
|
+
const slug = agentName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, MODAL_NAME_MAX).replace(/-+$/g, "");
|
|
259
|
+
return slug === "" ? MODAL_FALLBACK_APP_NAME : slug;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The Modal Secret the deployment reads its env from.
|
|
263
|
+
*
|
|
264
|
+
* `-env` rather than the app name alone: the secret holds exactly what
|
|
265
|
+
* `.env.example` declares, and a name that says so makes
|
|
266
|
+
* `modal secret create <name> …` self-explaining. Derived rather than
|
|
267
|
+
* configured, so the emitted file and the command in its docstring cannot name
|
|
268
|
+
* two different secrets.
|
|
269
|
+
*/
|
|
270
|
+
function modalSecretName(appName) {
|
|
271
|
+
return `${appName}-env`.slice(0, MODAL_NAME_MAX);
|
|
272
|
+
}
|
|
273
|
+
/** `node:<major>-slim` for the Node running this build, floored at the SDK's minimum. */
|
|
274
|
+
function modalNodeImageTag(version = process.versions.node) {
|
|
275
|
+
const major = Number.parseInt(version.split(".")[0] ?? "", 10);
|
|
276
|
+
return `node:${Number.isNaN(major) || major < MODAL_NODE_MAJOR_FLOOR ? MODAL_NODE_MAJOR_FLOOR : major}-slim`;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Render `app.py` for this agent.
|
|
280
|
+
*
|
|
281
|
+
* Every number the platform needs appears ONCE and is interpolated, so the
|
|
282
|
+
* emitted file cannot disagree with itself or with the entry beside it — see
|
|
283
|
+
* {@link MODAL_PORT} for the failure that motivates it.
|
|
284
|
+
*/
|
|
285
|
+
function modalAppSource(options) {
|
|
286
|
+
const app = modalAppName(options.name);
|
|
287
|
+
const secret = modalSecretName(app);
|
|
288
|
+
const image = options.nodeImage ?? modalNodeImageTag();
|
|
289
|
+
return `# Generated by \`aai build --target modal\` — do not edit, and do not commit.
|
|
290
|
+
"""Deploys this agent to Modal.
|
|
291
|
+
|
|
292
|
+
modal secret create ${secret} ASSEMBLYAI_API_KEY=... # once
|
|
293
|
+
modal deploy .aai/modal/${MODAL_APP_FILE}
|
|
294
|
+
|
|
295
|
+
Everything this serves is in THIS directory. \`${MODAL_ENTRY_FILE}\` is a bundle
|
|
296
|
+
with no imports left to resolve, so the image installs nothing, carries no
|
|
297
|
+
lockfile and needs no node_modules.
|
|
298
|
+
|
|
299
|
+
Policy is read from the environment at DEPLOY time rather than edited here,
|
|
300
|
+
because \`aai build --target modal\` overwrites this file:
|
|
301
|
+
|
|
302
|
+
AAI_MODAL_APP app name (default: ${app})
|
|
303
|
+
AAI_MODAL_SECRET secret holding the agent env (default: ${secret})
|
|
304
|
+
AAI_MODAL_MIN_CONTAINERS warm floor (default: 0, i.e. scales to zero)
|
|
305
|
+
AAI_MODAL_MAX_CONTAINERS autoscaler ceiling (default: 10)
|
|
306
|
+
"""
|
|
307
|
+
|
|
308
|
+
import atexit
|
|
309
|
+
import contextlib
|
|
310
|
+
import os
|
|
311
|
+
import signal
|
|
312
|
+
import subprocess
|
|
313
|
+
from pathlib import Path
|
|
314
|
+
|
|
315
|
+
import modal
|
|
316
|
+
|
|
317
|
+
# This file's OWN directory, never the shell's. \`modal deploy\` resolves a
|
|
318
|
+
# relative local path against the directory it was invoked FROM, so an
|
|
319
|
+
# \`add_local_dir(".")\` here would upload the project root or nothing at all,
|
|
320
|
+
# depending on where the deploy was run.
|
|
321
|
+
HERE = Path(__file__).parent
|
|
322
|
+
|
|
323
|
+
# Bound to \`@modal.web_server\` and baked into the image env from this one
|
|
324
|
+
# place. The proxy routes to the port it is told about, and a node process
|
|
325
|
+
# reading a different number listens where nothing is routed — a deployment
|
|
326
|
+
# that builds, starts, reports healthy and answers no request.
|
|
327
|
+
PORT = ${MODAL_PORT}
|
|
328
|
+
|
|
329
|
+
# The node server, spawned by \`server()\` below.
|
|
330
|
+
ENTRY = "${MODAL_ENTRY_FILE}"
|
|
331
|
+
|
|
332
|
+
APP_NAME = os.environ.get("AAI_MODAL_APP", "${app}")
|
|
333
|
+
SECRET_NAME = os.environ.get("AAI_MODAL_SECRET", "${secret}")
|
|
334
|
+
MIN_CONTAINERS = int(os.environ.get("AAI_MODAL_MIN_CONTAINERS", "0"))
|
|
335
|
+
MAX_CONTAINERS = int(os.environ.get("AAI_MODAL_MAX_CONTAINERS", "10"))
|
|
336
|
+
|
|
337
|
+
# How long a container stop waits for node to close its sessions before the
|
|
338
|
+
# force-kill. Modal's own SIGKILL backstop still bounds the real grace period,
|
|
339
|
+
# so this is headroom rather than a budget the shutdown spends.
|
|
340
|
+
NODE_STOP_TIMEOUT_SECS = 30
|
|
341
|
+
|
|
342
|
+
image = (
|
|
343
|
+
# \`add_python\` layers Modal's own Python beside Node: the container
|
|
344
|
+
# entrypoint is that Python runtime, and it spawns node. The Node major
|
|
345
|
+
# tracks the one this was BUILT with, so the bundle runs on the runtime it
|
|
346
|
+
# was bundled for.
|
|
347
|
+
modal.Image.from_registry("${image}", add_python="${MODAL_ADD_PYTHON}")
|
|
348
|
+
.env({"NODE_ENV": "production", "PORT": str(PORT)})
|
|
349
|
+
# \`copy=True\` puts these files in an image LAYER. The default mounts them
|
|
350
|
+
# at container start instead, which re-uploads the browser client on every
|
|
351
|
+
# cold start and makes the boot slower the larger the UI gets.
|
|
352
|
+
.add_local_dir(
|
|
353
|
+
HERE,
|
|
354
|
+
remote_path="/app",
|
|
355
|
+
copy=True,
|
|
356
|
+
ignore=["${MODAL_APP_FILE}", "__pycache__"],
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
app = modal.App(APP_NAME)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _run_node(entry: str, env: dict[str, str]) -> subprocess.Popen:
|
|
364
|
+
"""Spawn the node server and hand container stop signals to it.
|
|
365
|
+
|
|
366
|
+
Modal stops a container by signalling THIS Python process, and a child
|
|
367
|
+
spawned with a bare Popen receives nothing of its own — so the node
|
|
368
|
+
server's SIGTERM handler, the thing that closes live voice sessions, would
|
|
369
|
+
never run on a scale-in or a redeploy. Every call in progress would just
|
|
370
|
+
lose its socket.
|
|
371
|
+
|
|
372
|
+
Two hooks, because neither alone is reliable: \`signal.signal\` only works on
|
|
373
|
+
the main thread and Modal may call this off it, while the atexit fallback
|
|
374
|
+
catches the runtime handling the signal itself and exiting normally. Both
|
|
375
|
+
funnel into one memoized stop(), and the node handler is idempotent, so
|
|
376
|
+
double delivery is harmless.
|
|
377
|
+
"""
|
|
378
|
+
proc = subprocess.Popen(["node", entry], cwd="/app", env=env)
|
|
379
|
+
stopped = False
|
|
380
|
+
|
|
381
|
+
def stop() -> None:
|
|
382
|
+
nonlocal stopped
|
|
383
|
+
if stopped or proc.poll() is not None:
|
|
384
|
+
return
|
|
385
|
+
stopped = True
|
|
386
|
+
with contextlib.suppress(ProcessLookupError):
|
|
387
|
+
proc.send_signal(signal.SIGTERM)
|
|
388
|
+
with contextlib.suppress(subprocess.TimeoutExpired):
|
|
389
|
+
proc.wait(timeout=NODE_STOP_TIMEOUT_SECS)
|
|
390
|
+
if proc.poll() is None:
|
|
391
|
+
proc.kill()
|
|
392
|
+
|
|
393
|
+
def forward(signum: int) -> None:
|
|
394
|
+
previous = signal.getsignal(signum)
|
|
395
|
+
|
|
396
|
+
def handler(sig: int, frame: object) -> None:
|
|
397
|
+
stop()
|
|
398
|
+
if callable(previous):
|
|
399
|
+
previous(sig, frame)
|
|
400
|
+
elif previous == signal.SIG_DFL:
|
|
401
|
+
# Re-deliver with the default disposition so this runtime still
|
|
402
|
+
# dies the way the platform expects.
|
|
403
|
+
signal.signal(sig, signal.SIG_DFL)
|
|
404
|
+
os.kill(os.getpid(), sig)
|
|
405
|
+
|
|
406
|
+
signal.signal(signum, handler)
|
|
407
|
+
|
|
408
|
+
for signum in (signal.SIGTERM, signal.SIGINT):
|
|
409
|
+
with contextlib.suppress(ValueError): # not the main thread
|
|
410
|
+
forward(signum)
|
|
411
|
+
|
|
412
|
+
atexit.register(stop)
|
|
413
|
+
return proc
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
@app.function(
|
|
417
|
+
image=image,
|
|
418
|
+
# Values live in a Modal Secret; the \`.env.example\` beside this file
|
|
419
|
+
# DECLARES which names reach \`ctx.env\`. Deploy FAILS when the secret does
|
|
420
|
+
# not exist, which is the right time to hear about it — the alternative is
|
|
421
|
+
# a container that starts and has no provider credential.
|
|
422
|
+
secrets=[modal.Secret.from_name(SECRET_NAME)],
|
|
423
|
+
# An audio pipeline is not a burstable workload: STT framing, the LLM turn
|
|
424
|
+
# and TTS playback all run in this process.
|
|
425
|
+
cpu=1,
|
|
426
|
+
memory=1024,
|
|
427
|
+
min_containers=MIN_CONTAINERS,
|
|
428
|
+
max_containers=MAX_CONTAINERS,
|
|
429
|
+
# Hold a container after the last call rather than paying a cold start on
|
|
430
|
+
# the next one.
|
|
431
|
+
scaledown_window=300,
|
|
432
|
+
# Bounds ONE input, and a WebSocket is one input for as long as the call
|
|
433
|
+
# lasts — so this is the longest single call this deployment will carry.
|
|
434
|
+
timeout=3600,
|
|
435
|
+
)
|
|
436
|
+
# Without this a container serves ONE input at a time, and a voice call holds
|
|
437
|
+
# its input until the caller hangs up: the second caller would wait out the
|
|
438
|
+
# first, and every asset request for the browser client would queue behind
|
|
439
|
+
# whichever call is in progress. \`target_inputs\` is the scale-out set point,
|
|
440
|
+
# under the cap, so a container is joined by another before it saturates.
|
|
441
|
+
@modal.concurrent(max_inputs=50, target_inputs=25)
|
|
442
|
+
@modal.web_server(port=PORT, startup_timeout=180)
|
|
443
|
+
def server() -> None:
|
|
444
|
+
env = os.environ.copy()
|
|
445
|
+
# Modal points this at an in-container Unix socket serving its own Python
|
|
446
|
+
# task runtime. The \`modal\` JS SDK prefers that variable over the public
|
|
447
|
+
# endpoint, so anything in node that talks to Modal would dial a socket
|
|
448
|
+
# that does not answer it.
|
|
449
|
+
env.pop("MODAL_SERVER_URL", None)
|
|
450
|
+
# _run_node, not a bare Popen, so the container's stop signal reaches node
|
|
451
|
+
# and live sessions are closed rather than dropped.
|
|
452
|
+
_run_node(ENTRY, env)
|
|
453
|
+
`;
|
|
454
|
+
}
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/_modal-output.ts
|
|
457
|
+
/**
|
|
458
|
+
* Assemble a self-contained Modal deployment directory — `.aai/modal/`.
|
|
459
|
+
*
|
|
460
|
+
* The runtime files are `_target-output.ts`, shared with the Deno emit for the
|
|
461
|
+
* reason that module's doc gives: neither host installs anything, so both need
|
|
462
|
+
* the same three files carried in beside the bundled entry.
|
|
463
|
+
*
|
|
464
|
+
* Modal's own half is the fourth file, `app.py`. It is what makes this target
|
|
465
|
+
* different in kind from the other two — Vercel and Deno are each pointed at a
|
|
466
|
+
* directory and work out the rest, while `modal deploy` RUNS a Python module
|
|
467
|
+
* that declares the image, the app and the function. See `_modal-app.ts`.
|
|
468
|
+
*
|
|
469
|
+
* The `app.py` is written LAST, after the directory it describes exists. That
|
|
470
|
+
* ordering has no failure to point at yet; it is here because the file's
|
|
471
|
+
* `add_local_dir(HERE, …)` is a claim about this directory's contents, and a
|
|
472
|
+
* half-assembled directory is a worse thing to hand a user than a missing one.
|
|
473
|
+
*/
|
|
474
|
+
/** Write `.aai/modal/` for this project. */
|
|
475
|
+
async function emitModalOutput(cwd, options) {
|
|
476
|
+
const { name, ...emitOptions } = options;
|
|
477
|
+
const outputDir = await emitSelfContainedOutput(cwd, {
|
|
478
|
+
outputDir: MODAL_OUTPUT_DIR,
|
|
479
|
+
entryFile: MODAL_ENTRY_FILE,
|
|
480
|
+
entrySource: MODAL_ENTRY_SOURCE,
|
|
481
|
+
name: "modal"
|
|
482
|
+
}, emitOptions);
|
|
483
|
+
await fs.writeFile(path.join(outputDir, MODAL_APP_FILE), modalAppSource({ name }), "utf-8");
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/_vercel-output.ts
|
|
487
|
+
/**
|
|
488
|
+
* Assemble a PREBUILT Vercel deployment — `.vercel/output/` — from what
|
|
489
|
+
* `aai build` just produced.
|
|
490
|
+
*
|
|
491
|
+
* The argument for the Build Output API over an `api/` entry is in
|
|
492
|
+
* `_vercel-target.ts` at {@link VERCEL_OUTPUT_DIR}; what this module adds is the
|
|
493
|
+
* consequence of it. A `.func` directory is a directory WE fill, so every file
|
|
494
|
+
* the server reads at runtime is present because it was copied in, and nothing
|
|
495
|
+
* depends on a static tracer following a path it structurally cannot:
|
|
496
|
+
*
|
|
497
|
+
* - **`.aai/worker.mjs`** is loaded through `import(pathToFileURL(...))`
|
|
498
|
+
* (`start.ts`), which `@vercel/nft` cannot resolve. Under the `api/` shape
|
|
499
|
+
* the build was green and the function 500'd on its first request with
|
|
500
|
+
* "No built agent at .aai/worker.mjs".
|
|
501
|
+
* - **`.env.example`** is not documentation here. `resolveServerEnv` treats it
|
|
502
|
+
* as the DECLARATION of which variables become `ctx.env` (see
|
|
503
|
+
* `DEPLOY_ENV_FILES`), so a function without it hands every tool an empty
|
|
504
|
+
* env while the Vercel project has the values set — a failure that looks
|
|
505
|
+
* like a credential problem and is a packaging one.
|
|
506
|
+
* - **The client** is copied to `static/`, where the CDN serves it, and also
|
|
507
|
+
* beside the worker, so `resolveClientDir` finds a real directory rather
|
|
508
|
+
* than reaching into a `node_modules` that the bundle replaced.
|
|
509
|
+
*
|
|
510
|
+
* The entry is BUNDLED rather than shipped with a `node_modules` — see
|
|
511
|
+
* `_target-bundle.ts`, which every target that emits an entry shares.
|
|
512
|
+
*/
|
|
513
|
+
/**
|
|
514
|
+
* Files copied verbatim into the function, each one read at RUNTIME by a path
|
|
515
|
+
* no bundler can see. A missing one is skipped rather than fatal.
|
|
516
|
+
*
|
|
517
|
+
* **`.env` is deliberately NOT here.** `resolveServerEnv` reads
|
|
518
|
+
* {@link DEPLOY_ENV_FILES} — `.env.example` then `.env` — but only the first is
|
|
519
|
+
* a DECLARATION; the second holds a developer's own keys, and copying it would
|
|
520
|
+
* bake them into a deployment artifact and let them silently win over the
|
|
521
|
+
* values set in the Vercel project. Declarations ship, values come from the
|
|
522
|
+
* platform environment. Verified by building the `simple` template: a local
|
|
523
|
+
* `.env` with live credentials landed in the function until this list dropped
|
|
524
|
+
* it.
|
|
525
|
+
*/
|
|
526
|
+
const RUNTIME_FILES = [WORKER_ARTIFACT_REL, ".env.example"];
|
|
527
|
+
/**
|
|
528
|
+
* Write `.vercel/output/` for this project.
|
|
529
|
+
*
|
|
530
|
+
* The directory is REMOVED first. It is not addressed by content, so a
|
|
531
|
+
* function or a static asset left by an earlier build with a different shape
|
|
532
|
+
* would be deployed alongside this one — and `vercel deploy --prebuilt`
|
|
533
|
+
* uploads whatever is there.
|
|
534
|
+
*/
|
|
535
|
+
async function emitVercelOutput(cwd, options = {}) {
|
|
536
|
+
const outputDir = path.join(cwd, VERCEL_OUTPUT_DIR);
|
|
537
|
+
const functionDir = path.join(cwd, VERCEL_FUNCTION_DIR);
|
|
538
|
+
const staticDir = path.join(cwd, VERCEL_STATIC_DIR);
|
|
539
|
+
await fs.rm(outputDir, {
|
|
540
|
+
recursive: true,
|
|
541
|
+
force: true
|
|
542
|
+
});
|
|
543
|
+
await fs.mkdir(functionDir, { recursive: true });
|
|
544
|
+
await fs.writeFile(path.join(outputDir, "config.json"), VERCEL_BUILD_CONFIG_SOURCE, "utf-8");
|
|
545
|
+
await fs.writeFile(path.join(functionDir, ".vc-config.json"), vercelFunctionConfigSource(), "utf-8");
|
|
546
|
+
const bundle = options.bundle ?? ((dir) => bundleTargetEntry(dir, VERCEL_ENTRY_SOURCE, "vercel"));
|
|
547
|
+
await fs.writeFile(path.join(functionDir, "index.mjs"), await bundle(cwd), "utf-8");
|
|
548
|
+
for (const rel of RUNTIME_FILES) {
|
|
549
|
+
const from = path.join(cwd, rel);
|
|
550
|
+
if (!await targetPathExists(from)) continue;
|
|
551
|
+
const to = path.join(functionDir, rel);
|
|
552
|
+
await fs.mkdir(path.dirname(to), { recursive: true });
|
|
553
|
+
await fs.copyFile(from, to);
|
|
554
|
+
}
|
|
555
|
+
const clientSource = await targetPathExists(path.join(cwd, CLIENT_ARTIFACT_REL, "index.html")) ? path.join(cwd, CLIENT_ARTIFACT_REL) : defaultClientDir();
|
|
556
|
+
await fs.cp(clientSource, staticDir, { recursive: true });
|
|
557
|
+
await fs.cp(clientSource, path.join(functionDir, CLIENT_ARTIFACT_REL), { recursive: true });
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/build.ts
|
|
561
|
+
/**
|
|
562
|
+
* `aai build` — bundle the agent without deploying, behind the same gates
|
|
563
|
+
* deploy runs (tests, then typecheck), so the command previews the deploy
|
|
564
|
+
* artifact and its failures alike.
|
|
565
|
+
*
|
|
566
|
+
* It also LEAVES that artifact on disk, at {@link WORKER_ARTIFACT_REL}, which is
|
|
567
|
+
* what makes self-hosting work: `aai start` loads the built worker rather than
|
|
568
|
+
* `agent.ts`, because a tool is discovered by the bundler enumerating `tools/`
|
|
569
|
+
* and no un-bundled loader can see that directory. See `start.ts` and
|
|
570
|
+
* "Self-hosting is the scaffold's default" in `packages/aai-cli/CLAUDE.md`.
|
|
571
|
+
*
|
|
572
|
+
* `--target` decides what else it emits — see `_build-target.ts`.
|
|
573
|
+
*/
|
|
574
|
+
/**
|
|
575
|
+
* The prose slot, named by convention. Mirrors `worker-bundler.ts`'s constant of
|
|
576
|
+
* the same name — the two cannot share one without an import cycle
|
|
577
|
+
* (`build.ts` → `_bundler.ts` → `worker-bundler.ts`), so `_build.test.ts` pins
|
|
578
|
+
* the pair end to end instead: a build whose prompt really came from the file
|
|
579
|
+
* has to report the file.
|
|
580
|
+
*/
|
|
581
|
+
const SYSTEM_PROMPT_FILE = "system-prompt.md";
|
|
582
|
+
/** What {@link systemPromptSource} reports when nothing declared a prompt. */
|
|
583
|
+
const FRAMEWORK_DEFAULT_PROMPT_SOURCE = "the framework default (DEFAULT_SYSTEM_PROMPT)";
|
|
584
|
+
/**
|
|
585
|
+
* Which of the three possible authors of this agent's system prompt actually
|
|
586
|
+
* wrote the one in the bundle.
|
|
587
|
+
*
|
|
588
|
+
* `aai build` reported `name` and `workerBytes` and nothing about the prompt,
|
|
589
|
+
* and the prompt is the one field that can change COMPLETELY without any
|
|
590
|
+
* config changing: deleting `system-prompt.md` swaps in
|
|
591
|
+
* `DEFAULT_SYSTEM_PROMPT` — a total personality change — with exit 0 and no
|
|
592
|
+
* line anywhere. `withSystemPrompt` refuses the case where a file exists and
|
|
593
|
+
* nothing reads it; it cannot refuse a file that is simply GONE, because that
|
|
594
|
+
* is what an agent with no file legitimately looks like. So this is a report
|
|
595
|
+
* rather than a check.
|
|
596
|
+
*
|
|
597
|
+
* Decided by comparing VALUES against the built agent's resolved prompt, which
|
|
598
|
+
* is the same method `withSystemPrompt` uses and for the same reason — the
|
|
599
|
+
* alternative asks the bundler's module graph a question, and the author may
|
|
600
|
+
* have imported the file and composed it, which is neither "the file" nor
|
|
601
|
+
* "agent.ts" alone.
|
|
602
|
+
*/
|
|
603
|
+
async function systemPromptSource(cwd, resolved) {
|
|
604
|
+
if (resolved === DEFAULT_SYSTEM_PROMPT) return FRAMEWORK_DEFAULT_PROMPT_SOURCE;
|
|
605
|
+
const trimmed = (await fs.readFile(path.join(cwd, SYSTEM_PROMPT_FILE), "utf-8").catch(() => void 0))?.trim();
|
|
606
|
+
if (trimmed === void 0 || trimmed === "" || !resolved.includes(trimmed)) return "agent.ts";
|
|
607
|
+
return resolved.trim() === trimmed ? SYSTEM_PROMPT_FILE : `agent.ts (composing ${SYSTEM_PROMPT_FILE})`;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Map a {@link runVitest} failure to a CliError — distinguishing a real test
|
|
611
|
+
* failure (test_failed) from the runner not spawning (spawn_failed) instead
|
|
612
|
+
* of a generic command_failed.
|
|
613
|
+
*/
|
|
614
|
+
function testGateError(err) {
|
|
615
|
+
const { code, message } = classifyVitestError(err);
|
|
616
|
+
return new CliError(code, message, "Re-run with --skipTests to build without tests", { cause: err });
|
|
617
|
+
}
|
|
618
|
+
async function executeBuild(opts) {
|
|
619
|
+
const { cwd } = opts;
|
|
620
|
+
const target = resolveBuildTarget(opts.target);
|
|
621
|
+
if (!opts.skipTests) try {
|
|
622
|
+
runVitest(cwd, {
|
|
623
|
+
candidates: TEST_FILES,
|
|
624
|
+
all: true
|
|
625
|
+
});
|
|
626
|
+
} catch (err) {
|
|
627
|
+
throw testGateError(err);
|
|
628
|
+
}
|
|
629
|
+
await assertTypechecks(cwd, { skip: opts.skipTypecheck });
|
|
630
|
+
const bundle = await buildAgentBundle(cwd, { minify: true });
|
|
631
|
+
const agentDef = await evalWorkerBundle(bundle.worker);
|
|
632
|
+
for (const warning of agentConfigWarnings(agentDef)) notify("warn", warning);
|
|
633
|
+
for (const warning of determinismWarnings(await scanWorkflowDeterminism(cwd))) notify("warn", warning);
|
|
634
|
+
const worker = path.join(cwd, WORKER_ARTIFACT_REL);
|
|
635
|
+
await fs.mkdir(path.dirname(worker), { recursive: true });
|
|
636
|
+
await fs.writeFile(worker, bundle.worker, "utf-8");
|
|
637
|
+
await emitTargetFiles(cwd, target, { name: agentDef.name });
|
|
638
|
+
const output = TARGET_OUTPUTS[target];
|
|
639
|
+
if (output.dir !== void 0) log.info(`Target ${target}: wrote ${output.dir}`);
|
|
640
|
+
if (output.deploy !== void 0) log.info(`Deploy it with \`${output.deploy}\``);
|
|
641
|
+
const systemPrompt = await systemPromptSource(cwd, agentDef.systemPrompt);
|
|
642
|
+
log.info(`System prompt: ${systemPrompt}`);
|
|
643
|
+
log.success("Build complete");
|
|
644
|
+
return ok({
|
|
645
|
+
name: agentDef.name,
|
|
646
|
+
workerBytes: bundle.worker.length,
|
|
647
|
+
worker,
|
|
648
|
+
systemPrompt,
|
|
649
|
+
target,
|
|
650
|
+
outputDir: output.dir,
|
|
651
|
+
deploy: output.deploy
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Write what a target needs, if it needs anything.
|
|
656
|
+
*
|
|
657
|
+
* `node` writes nothing: a long-lived process runs `aai start`, which needs no
|
|
658
|
+
* generated file. `vercel` writes a complete prebuilt deployment under
|
|
659
|
+
* `.vercel/output/` — see `_vercel-output.ts`, and `VERCEL_OUTPUT_DIR` in
|
|
660
|
+
* `_vercel-target.ts` for why that directory and not an `api/` entry beside a
|
|
661
|
+
* generated `vercel.json`. `deno` and `modal` write a self-contained directory
|
|
662
|
+
* each — `_target-output.ts` for the half they share.
|
|
663
|
+
*
|
|
664
|
+
* WHERE each lands and how it is deployed is `TARGET_OUTPUTS`, not this
|
|
665
|
+
* function, and the caller reports it. Those strings were a `log.info` per
|
|
666
|
+
* `case` and drifted the way a per-arm string does: `vercel` named its
|
|
667
|
+
* directory and no deploy command at all.
|
|
668
|
+
*
|
|
669
|
+
* The agent's `name` reaches only `modal`, which needs it for the app name a
|
|
670
|
+
* deployment is served under. It is threaded through rather than re-read
|
|
671
|
+
* because `executeBuild` has already evaluated the bundle to report it.
|
|
672
|
+
*/
|
|
673
|
+
async function emitTargetFiles(cwd, target, agent) {
|
|
674
|
+
switch (target) {
|
|
675
|
+
case "node": return;
|
|
676
|
+
case "vercel":
|
|
677
|
+
await emitVercelOutput(cwd);
|
|
678
|
+
return;
|
|
679
|
+
case "deno":
|
|
680
|
+
await emitDenoOutput(cwd);
|
|
681
|
+
return;
|
|
682
|
+
case "modal":
|
|
683
|
+
await emitModalOutput(cwd, { name: agent.name });
|
|
684
|
+
return;
|
|
685
|
+
default: throw new Error(`Unhandled build target ${String(target)}`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
export { executeBuild };
|