@alexkroman1/aai-cli 15.1.0 → 16.0.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/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 +12 -11
- package/dist/{dev-Bx9gYBHM.mjs → dev-kodAY23K.mjs} +7 -1
- package/dist/{eval-B3I7FqN9.mjs → eval-DvoSz7SZ.mjs} +1 -1
- package/dist/{init-CQbj3ycf.mjs → init-D363Ls5u.mjs} +2 -2
- 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
|
@@ -4,5 +4,12 @@ export default agent({
|
|
|
4
4
|
name: "Dr. Sage",
|
|
5
5
|
greeting:
|
|
6
6
|
"Hey, I'm Dr. Sage. Try asking me something like, what are the side effects of ibuprofen, can I take aspirin and warfarin together, or calculate my BMI. Just remember, I'm not a real doctor, so always check with your healthcare provider.",
|
|
7
|
-
|
|
7
|
+
// Three builtins, and `fetch_json` is the one worth explaining: `fda.ts`
|
|
8
|
+
// already reaches openFDA's LABEL endpoint in tool code, and a label is the
|
|
9
|
+
// manufacturer's text. What the two tools cannot answer is what people
|
|
10
|
+
// actually REPORT, which lives in a different dataset (`/drug/event.json`)
|
|
11
|
+
// and is a counting query rather than a lookup — so it is the model's to
|
|
12
|
+
// compose, not a fixed tool's. `system-prompt.md` holds the endpoint and the
|
|
13
|
+
// caveat that a report count is not an incidence rate.
|
|
14
|
+
builtinTools: ["web_search", "run_code", "fetch_json"],
|
|
8
15
|
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The half of `fda.ts` that `agent.test.ts` cannot reach.
|
|
3
|
+
*
|
|
4
|
+
* That spec replaces `fetchFdaLabel` with a `vi.fn()`, which is right for what
|
|
5
|
+
* it is about — the cross-mention scan, the refuse-on-a-missing-drug rule — and
|
|
6
|
+
* leaves the lookup itself, the cache and the section readers untested. This
|
|
7
|
+
* file drives the REAL function, with no module mocking at all: `CallOptions`
|
|
8
|
+
* carries a `fetch`, documented as being for exactly this, so the query openFDA
|
|
9
|
+
* receives and the signal it is cancelled by are both observable from here
|
|
10
|
+
* while `fetchJson`'s own screening, deadline and byte cap stay in the path.
|
|
11
|
+
*
|
|
12
|
+
* Drug names are unique per test on purpose — the cache in `fda.ts` is module
|
|
13
|
+
* state shared by every test in this file, which is the same thing it is in a
|
|
14
|
+
* session and is the reason it exists.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { CallOptions } from "@alexkroman1/aai/tools";
|
|
18
|
+
import { describe, expect, test, vi } from "vitest";
|
|
19
|
+
import { fetchFdaLabel, first, sectionText, toDrugInfo } from "./fda.ts";
|
|
20
|
+
|
|
21
|
+
/** A fetch that answers one JSON body and records the requests it was given. */
|
|
22
|
+
function stubFetch(body: unknown, status = 200) {
|
|
23
|
+
const calls: { url: string; signal: AbortSignal | null | undefined }[] = [];
|
|
24
|
+
const fetch = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
25
|
+
calls.push({ url: String(input), signal: init?.signal });
|
|
26
|
+
return new Response(JSON.stringify(body), { status });
|
|
27
|
+
});
|
|
28
|
+
return { calls, options: { fetch } satisfies CallOptions };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ASPIRIN = {
|
|
32
|
+
results: [
|
|
33
|
+
{
|
|
34
|
+
openfda: { generic_name: ["ASPIRIN"], manufacturer_name: ["SMITH & NEPHEW"] },
|
|
35
|
+
purpose: ["Pain reliever"],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe("fetchFdaLabel", () => {
|
|
41
|
+
test("asks openFDA for the generic OR brand match and answers the first result", async () => {
|
|
42
|
+
const { calls, options } = stubFetch(ASPIRIN);
|
|
43
|
+
|
|
44
|
+
const label = await fetchFdaLabel("Aspirin", options);
|
|
45
|
+
|
|
46
|
+
expect(label).toMatchObject({ purpose: ["Pain reliever"] });
|
|
47
|
+
// Lowercased and URL-encoded, and BOTH fields searched — a caller who says
|
|
48
|
+
// "Advil" has to reach the same label as one who says "ibuprofen".
|
|
49
|
+
expect(calls[0]?.url).toContain('openfda.generic_name:"aspirin"');
|
|
50
|
+
expect(calls[0]?.url).toContain('openfda.brand_name:"aspirin"');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("a second question about the same drug does not go back to the network", async () => {
|
|
54
|
+
// The whole reason the cache is in this module rather than in either tool:
|
|
55
|
+
// a session that looks a drug up and then checks it for interactions would
|
|
56
|
+
// otherwise pay the round-trip twice.
|
|
57
|
+
const { options } = stubFetch({ results: [{ purpose: ["Anticoagulant"] }] });
|
|
58
|
+
|
|
59
|
+
await fetchFdaLabel("dabigatran", options);
|
|
60
|
+
await fetchFdaLabel("DABIGATRAN", options);
|
|
61
|
+
|
|
62
|
+
expect(options.fetch).toHaveBeenCalledTimes(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("a failed lookup is NOT cached, so the next turn retries", async () => {
|
|
66
|
+
// openFDA answers 404 for a search that matches nothing, which `fetchJson`
|
|
67
|
+
// reports as a `ToolFailure` rather than throwing. Caching it would pin a
|
|
68
|
+
// transient outage for the rest of the call.
|
|
69
|
+
const { options } = stubFetch({ error: { code: "NOT_FOUND" } }, 404);
|
|
70
|
+
|
|
71
|
+
expect(await fetchFdaLabel("sparkleforin", options)).toBeNull();
|
|
72
|
+
expect(await fetchFdaLabel("sparkleforin", options)).toBeNull();
|
|
73
|
+
|
|
74
|
+
expect(options.fetch).toHaveBeenCalledTimes(2);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("the caller's signal reaches the request", async () => {
|
|
78
|
+
// What `CallOptions.signal` buys this template: `check_drug_interaction`
|
|
79
|
+
// fires one of these per drug, and a hang-up mid-check has to take them all
|
|
80
|
+
// down. The signal the request sees is a COMBINED one — `fetchJson` folds
|
|
81
|
+
// its own deadline in — so the claim is that aborting the caller's aborts it.
|
|
82
|
+
const { calls, options } = stubFetch({ results: [{ purpose: ["Statin"] }] });
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
|
|
85
|
+
await fetchFdaLabel("rosuvastatin", { ...options, signal: controller.signal });
|
|
86
|
+
const seen = calls[0]?.signal;
|
|
87
|
+
expect(seen?.aborted).toBe(false);
|
|
88
|
+
|
|
89
|
+
controller.abort();
|
|
90
|
+
expect(seen?.aborted).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("label section readers", () => {
|
|
95
|
+
test("first decodes the entities SPL leaves in the text", () => {
|
|
96
|
+
// Read ALOUD by a voice agent: "SMITH ampersand-a-m-p" is the failure.
|
|
97
|
+
expect(first(["SMITH & NEPHEW"])).toBe("SMITH & NEPHEW");
|
|
98
|
+
expect(first("it's a bare string, not an array")).toBe("it's a bare string, not an array");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("first answers undefined for anything that is not a string", () => {
|
|
102
|
+
// The runtime half of dropping the `as string[] | undefined` casts: openFDA
|
|
103
|
+
// serves `effective_time` and `id` as bare values and a section can be
|
|
104
|
+
// missing entirely, and neither may crash a lookup.
|
|
105
|
+
expect(first(undefined)).toBeUndefined();
|
|
106
|
+
expect(first([])).toBeUndefined();
|
|
107
|
+
expect(first([{ not: "a string" }])).toBeUndefined();
|
|
108
|
+
expect(first(20_240_101)).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("sectionText joins every entry, so a split section is scanned whole", () => {
|
|
112
|
+
// A Drug Interactions section split across entries with the cross-mention
|
|
113
|
+
// in the second one is exactly the case where reading only the first would
|
|
114
|
+
// report "no interaction found".
|
|
115
|
+
expect(sectionText(["Ask a doctor.", "Do not use with WARFARIN."])).toBe(
|
|
116
|
+
"Ask a doctor. Do not use with WARFARIN.",
|
|
117
|
+
);
|
|
118
|
+
expect(sectionText(undefined)).toBe("");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("toDrugInfo scans the whole decoded section, not just its first entry", () => {
|
|
122
|
+
const info = toDrugInfo("ibuprofen", {
|
|
123
|
+
openfda: { generic_name: ["IBUPROFEN"] },
|
|
124
|
+
drug_interactions: ["Ask a doctor before use.", "Taking with WARFARIN & aspirin."],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(info.interactionsText).toContain("warfarin & aspirin");
|
|
128
|
+
expect(info.aliases).toEqual(["ibuprofen"]);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -7,13 +7,58 @@
|
|
|
7
7
|
* argument stops being true.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { type CallOptions, fetchJson } from "@alexkroman1/aai/tools";
|
|
11
|
+
import { decodeHtmlEntities, isToolFailure } from "@alexkroman1/aai/utils";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* One openFDA label document.
|
|
15
|
+
*
|
|
16
|
+
* `Record<string, unknown>` rather than `fetchJson`'s own `UntypedJsonBody`,
|
|
17
|
+
* which looks like the obvious fit and is the wrong one here: that alias is
|
|
18
|
+
* `Record<string, DefaultToolResult>` and `DefaultToolResult` is `any`, so its
|
|
19
|
+
* index signature would win the intersection below and `label.openfda` — the
|
|
20
|
+
* ONE field this file knows the shape of — would stop being checked at all.
|
|
21
|
+
* `unknown` is the same "nothing validated this" claim with the checking left
|
|
22
|
+
* on; the two readers under it are what make it usable at a call site.
|
|
23
|
+
*/
|
|
13
24
|
export type FdaLabel = Record<string, unknown> & { openfda?: Record<string, string[]> };
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The first string of a label section, decoded.
|
|
28
|
+
*
|
|
29
|
+
* Takes `unknown` rather than `string[] | undefined`, which is what retires the
|
|
30
|
+
* seven `as string[] | undefined` casts this file and `medication_lookup` used
|
|
31
|
+
* to spell at every section read. Each was an assertion about a THIRD PARTY's
|
|
32
|
+
* document that openFDA does not honour uniformly — `effective_time`, `id` and
|
|
33
|
+
* `version` are bare strings, not arrays — so the cast was a lie one field away
|
|
34
|
+
* from being read, and the check that replaces it is a line.
|
|
35
|
+
*
|
|
36
|
+
* The decode is `decodeHtmlEntities` (`@alexkroman1/aai/utils`): label text is
|
|
37
|
+
* lifted out of SPL XML and arrives with its entities intact (`SMITH &
|
|
38
|
+
* NEPHEW`, `it's`), and everything this module returns is read ALOUD — an
|
|
39
|
+
* `&` is a word the desk says.
|
|
40
|
+
*/
|
|
41
|
+
export function first(value: unknown): string | undefined {
|
|
42
|
+
const [head] = sectionLines(value);
|
|
43
|
+
return head === undefined ? undefined : decodeHtmlEntities(head);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A whole label section as one decoded string.
|
|
48
|
+
*
|
|
49
|
+
* A section arrives as an ARRAY, and openFDA splits a long one across entries,
|
|
50
|
+
* so a reader that takes only the first (see {@link first}) would scan half of
|
|
51
|
+
* a Drug Interactions section for a cross-mention and report the other half as
|
|
52
|
+
* absent — which for this template reads as "no interaction found".
|
|
53
|
+
*/
|
|
54
|
+
export function sectionText(value: unknown): string {
|
|
55
|
+
return decodeHtmlEntities(sectionLines(value).join(" "));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A label section as the strings it really holds, dropping anything that is not one. */
|
|
59
|
+
function sectionLines(value: unknown): string[] {
|
|
60
|
+
if (typeof value === "string") return [value];
|
|
61
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
17
62
|
}
|
|
18
63
|
|
|
19
64
|
/**
|
|
@@ -27,12 +72,25 @@ const labelCache = new Map<string, Promise<FdaLabel | null>>();
|
|
|
27
72
|
/**
|
|
28
73
|
* Fetch a drug's FDA label (generic OR brand name match) from openFDA.
|
|
29
74
|
* Returns null when the drug can't be found or the API is unreachable.
|
|
75
|
+
*
|
|
76
|
+
* `options` is the SDK's own `CallOptions`, and a tool passes `ctx.signal`
|
|
77
|
+
* through it: `check_drug_interaction` fans one request out per drug the caller
|
|
78
|
+
* named, and without a signal the only bound on any of them is the builtin's
|
|
79
|
+
* own deadline — a caller who hangs up or barges in mid-check leaves every one
|
|
80
|
+
* of those requests running. Passing the signal is also why the type is the
|
|
81
|
+
* SDK's rather than a local `{ signal?: AbortSignal }`: the option belongs to
|
|
82
|
+
* `fetchJson`, and restating it here is how the two drift.
|
|
83
|
+
*
|
|
84
|
+
* The signal the FIRST caller passes governs the shared request, which is the
|
|
85
|
+
* right answer for the shape this template actually has — the concurrent
|
|
86
|
+
* lookups all come from one tool call, so they abort together — and an aborted
|
|
87
|
+
* lookup is evicted below like any other failure, so the next turn retries.
|
|
30
88
|
*/
|
|
31
|
-
export function fetchFdaLabel(name: string): Promise<FdaLabel | null> {
|
|
89
|
+
export function fetchFdaLabel(name: string, options?: CallOptions): Promise<FdaLabel | null> {
|
|
32
90
|
const key = name.toLowerCase();
|
|
33
91
|
let p = labelCache.get(key);
|
|
34
92
|
if (!p) {
|
|
35
|
-
p = fetchFdaLabelUncached(key).then((label) => {
|
|
93
|
+
p = fetchFdaLabelUncached(key, options).then((label) => {
|
|
36
94
|
if (label === null) labelCache.delete(key);
|
|
37
95
|
return label;
|
|
38
96
|
});
|
|
@@ -47,22 +105,25 @@ export function fetchFdaLabel(name: string): Promise<FdaLabel | null> {
|
|
|
47
105
|
*
|
|
48
106
|
* `fetchJson` (`@alexkroman1/aai/tools`) is the same implementation behind the
|
|
49
107
|
* model-facing `fetch_json` builtin, so this inherits the three things a bare
|
|
50
|
-
* `fetch` here had none of: a request DEADLINE
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* bounded read so an unexpected body cannot be buffered whole, and URL
|
|
54
|
-
* screening on a developer's own machine under `aai dev`.
|
|
108
|
+
* `fetch` here had none of: a request DEADLINE, a bounded read so an unexpected
|
|
109
|
+
* body cannot be buffered whole, and URL screening on a developer's own machine
|
|
110
|
+
* under `aai dev`.
|
|
55
111
|
*
|
|
56
112
|
* It ANSWERS with `{ error }` rather than throwing for an HTTP failure, which
|
|
57
113
|
* is the builtin contract — narrowed with `isToolFailure` and folded into the
|
|
58
114
|
* same `null` this has always returned. The `catch` still earns its keep: a
|
|
59
|
-
* connection failure, a timeout
|
|
115
|
+
* connection failure, a timeout, a refused URL or the caller's own abort is a
|
|
116
|
+
* throw.
|
|
60
117
|
*/
|
|
61
|
-
async function fetchFdaLabelUncached(
|
|
118
|
+
async function fetchFdaLabelUncached(
|
|
119
|
+
name: string,
|
|
120
|
+
options?: CallOptions,
|
|
121
|
+
): Promise<FdaLabel | null> {
|
|
62
122
|
const q = encodeURIComponent(name);
|
|
63
123
|
try {
|
|
64
124
|
const raw = await fetchJson<{ results?: FdaLabel[] }>(
|
|
65
125
|
`https://api.fda.gov/drug/label.json?search=openfda.generic_name:"${q}"+openfda.brand_name:"${q}"&limit=1`,
|
|
126
|
+
options,
|
|
66
127
|
);
|
|
67
128
|
if (isToolFailure(raw)) return null;
|
|
68
129
|
return raw.results?.[0] ?? null;
|
|
@@ -85,9 +146,7 @@ export function toDrugInfo(name: string, label: FdaLabel): DrugInfo {
|
|
|
85
146
|
const generic = openfda.generic_name ?? [];
|
|
86
147
|
const brands = openfda.brand_name ?? [];
|
|
87
148
|
const aliases = [...new Set([name, ...generic, ...brands].map((n) => n.toLowerCase()))];
|
|
88
|
-
const interactionsText = (
|
|
89
|
-
.join(" ")
|
|
90
|
-
.toLowerCase();
|
|
149
|
+
const interactionsText = sectionText(label.drug_interactions).toLowerCase();
|
|
91
150
|
return { name, aliases, interactionsText };
|
|
92
151
|
}
|
|
93
152
|
|
|
@@ -15,3 +15,12 @@ Use run_code for health calculations:
|
|
|
15
15
|
- BMI: weight_kg / (height_m * height_m). Categories: <18.5 underweight, 18.5-25 normal, 25-30 overweight, >30 obese
|
|
16
16
|
Unit conversions: 1 lb = 0.453592 kg, 1 in = 0.0254 m, 1 ft = 0.3048 m, 1 cm = 0.01 m
|
|
17
17
|
- Weight-based dosage: dose_mg = weight_kg * dose_per_kg. Always note this is an estimate.
|
|
18
|
+
|
|
19
|
+
Use fetch_json for what people REPORT, which the two tools above cannot answer:
|
|
20
|
+
|
|
21
|
+
- Adverse event counts: https://api.fda.gov/drug/event.json?search=patient.drug.openfda.generic_name:"{drug}"&count=patient.reaction.reactionmeddrapt.exact
|
|
22
|
+
— returns { results: [{ term, count }, ...] }, the reactions most often reported alongside that drug. Read the top few terms aloud, lowercased.
|
|
23
|
+
- These are voluntary REPORTS, not an incidence rate: a high count can mean a
|
|
24
|
+
widely used drug rather than a risky one, and the dataset has no denominator.
|
|
25
|
+
Say so whenever you quote one, and never turn a count into a percentage or a
|
|
26
|
+
risk. Use run_code if you need to total or sort what comes back.
|
|
@@ -11,13 +11,16 @@ export default tool({
|
|
|
11
11
|
.min(2)
|
|
12
12
|
.describe("Medication names to check, e.g. ['ibuprofen', 'warfarin']"),
|
|
13
13
|
}),
|
|
14
|
-
async execute(args) {
|
|
14
|
+
async execute(args, ctx) {
|
|
15
15
|
const names = args.drugs.map((d) => d.trim().toLowerCase()).filter((d) => d.length > 0);
|
|
16
16
|
if (names.length < 2) {
|
|
17
17
|
return toolFailure("Provide at least two medication names to check.");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// One request per drug, all under the caller's own signal (`CallOptions`).
|
|
21
|
+
// This fan-out is the reason `fetchFdaLabel` takes one at all: a hang-up
|
|
22
|
+
// used to leave N openFDA requests running with nobody left to answer.
|
|
23
|
+
const labels = await Promise.all(names.map((n) => fetchFdaLabel(n, { signal: ctx.signal })));
|
|
21
24
|
const unresolved = names.filter((_, i) => labels[i] === null);
|
|
22
25
|
if (unresolved.length > 0) {
|
|
23
26
|
// Never silently drop a drug from an interaction check — a partial
|
|
@@ -8,24 +8,29 @@ export default tool({
|
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
name: z.string().describe("Medication name (generic or brand, e.g. 'ibuprofen' or 'Advil')"),
|
|
10
10
|
}),
|
|
11
|
-
async execute(args) {
|
|
12
|
-
|
|
11
|
+
async execute(args, ctx) {
|
|
12
|
+
// `ctx.signal` reaches openFDA through `CallOptions`: a caller who barges in
|
|
13
|
+
// or hangs up mid-lookup cancels the request rather than leaving it to run
|
|
14
|
+
// out the builtin's own deadline with nobody left to tell.
|
|
15
|
+
const drug = await fetchFdaLabel(args.name, { signal: ctx.signal });
|
|
13
16
|
if (!drug) {
|
|
14
17
|
return toolFailure(`No FDA data found for: ${args.name}`);
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
// Every read goes through `first`, which is where the runtime check and the
|
|
21
|
+
// entity decode live — see `fda.ts`. A section openFDA served as something
|
|
22
|
+
// other than an array of strings reads as absent instead of crashing the
|
|
23
|
+
// tool, and `SMITH & NEPHEW` is spoken as a manufacturer rather than as
|
|
24
|
+
// an ampersand entity.
|
|
17
25
|
const openfda = drug.openfda ?? {};
|
|
18
26
|
return {
|
|
19
|
-
name: openfda.generic_name
|
|
27
|
+
name: first(openfda.generic_name) ?? args.name,
|
|
20
28
|
brand_names: openfda.brand_name ?? [],
|
|
21
|
-
purpose:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
dosage: first(drug.dosage_and_administration as string[] | undefined)?.slice(0, 500) ?? "N/A",
|
|
27
|
-
side_effects: first(drug.adverse_reactions as string[] | undefined)?.slice(0, 500) ?? "N/A",
|
|
28
|
-
manufacturer: openfda.manufacturer_name?.[0] ?? "N/A",
|
|
29
|
+
purpose: first(drug.purpose) ?? first(drug.indications_and_usage) ?? "N/A",
|
|
30
|
+
warnings: first(drug.warnings)?.slice(0, 500) ?? "N/A",
|
|
31
|
+
dosage: first(drug.dosage_and_administration)?.slice(0, 500) ?? "N/A",
|
|
32
|
+
side_effects: first(drug.adverse_reactions)?.slice(0, 500) ?? "N/A",
|
|
33
|
+
manufacturer: first(openfda.manufacturer_name) ?? "N/A",
|
|
29
34
|
};
|
|
30
35
|
},
|
|
31
36
|
});
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// An EVAL: does the desk really run the FLOW, or does it rank people itself?
|
|
2
|
+
//
|
|
3
|
+
// `agent.test.ts` settles what each tool does once it has been called — it
|
|
4
|
+
// scripts the evaluator and the coordinator and asserts on the table. What it
|
|
5
|
+
// cannot settle is the two things this port exists to demonstrate: that the
|
|
6
|
+
// MODEL, told "screen them", spends ONE `screen_candidates` call and reads the
|
|
7
|
+
// evaluator's top three back rather than forming its own opinion of twelve
|
|
8
|
+
// bios, and that "weight TypeScript more" becomes `rescore_with_feedback` with
|
|
9
|
+
// the caller's words in it rather than a re-ordered list the desk made up.
|
|
10
|
+
//
|
|
11
|
+
// Run it with `aai eval`. Without a provider key every case runs against a
|
|
12
|
+
// SCRIPTED model — `stubReply` for the turn, `stubGenerate` for the evaluator,
|
|
13
|
+
// whose calls resolve a model instance of their own — which proves the wiring
|
|
14
|
+
// and nothing about the choice, so the two claims above are `{ live: true }`.
|
|
15
|
+
// The gate case is the mirror: a competent model does not call a tool its
|
|
16
|
+
// prompt says is not yet available, so the refusal can only be OBSERVED under a
|
|
17
|
+
// script that forces the call.
|
|
18
|
+
//
|
|
19
|
+
// **`system-prompt.md` is applied HERE, not by `agent.ts`.** The build discovers
|
|
20
|
+
// the file, so an eval driving the raw default export would run this agent with
|
|
21
|
+
// the FRAMEWORK DEFAULT prompt — and "do not rank applicants yourself" is the
|
|
22
|
+
// discipline the whole file measures.
|
|
23
|
+
|
|
24
|
+
/** The def a DEPLOYED agent runs: authored, plus what `tools/` declares, plus its PROMPT. */
|
|
25
|
+
import agentDef from "virtual:aai/agent";
|
|
26
|
+
import { dialogRefusalPattern, dialogResultSchema } from "@alexkroman1/aai/testing";
|
|
27
|
+
import { countWords } from "@alexkroman1/aai/utils";
|
|
28
|
+
import {
|
|
29
|
+
describeTurn,
|
|
30
|
+
type EvalSession,
|
|
31
|
+
lastStateIn,
|
|
32
|
+
toolNames,
|
|
33
|
+
toolResultIn,
|
|
34
|
+
} from "@alexkroman1/aai-runtime/eval";
|
|
35
|
+
import { describeEval } from "@alexkroman1/aai-runtime/eval/vitest";
|
|
36
|
+
import { expect } from "vitest";
|
|
37
|
+
import { z } from "zod";
|
|
38
|
+
import { LEADS, MAX_FEEDBACK_ROUNDS, SHORTLIST_SIZE } from "./shared.ts";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Every tool the desk declares, typed out rather than derived, so the negative
|
|
42
|
+
* below — nothing else was called — is a second, independent statement of what
|
|
43
|
+
* this agent may do.
|
|
44
|
+
*/
|
|
45
|
+
const DESK_TOOLS: readonly string[] = [
|
|
46
|
+
"screen_candidates",
|
|
47
|
+
"rescore_with_feedback",
|
|
48
|
+
"proceed_to_emails",
|
|
49
|
+
"candidate_details",
|
|
50
|
+
"read_email",
|
|
51
|
+
"screening_status",
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* What the BROWSER is sent, as this eval reads it — parsed rather than cast, so
|
|
56
|
+
* a projection that stopped matching fails naming the field.
|
|
57
|
+
*/
|
|
58
|
+
const ProjectedHiring = z.object({
|
|
59
|
+
jobTitle: z.string().nullable(),
|
|
60
|
+
leaderboard: z.array(z.object({ name: z.string(), score: z.number(), rank: z.number() })),
|
|
61
|
+
rounds: z.number(),
|
|
62
|
+
feedback: z.array(z.string()),
|
|
63
|
+
drafts: z.array(z.unknown()),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const hiringState = (session: EvalSession) => lastStateIn(session.events(), ProjectedHiring);
|
|
67
|
+
|
|
68
|
+
/** What `screen_candidates` answers with. */
|
|
69
|
+
const Screened = z.object({
|
|
70
|
+
screened: z.number(),
|
|
71
|
+
top: z.array(
|
|
72
|
+
z.object({ rank: z.number(), name: z.string(), score: z.number(), reason: z.string() }),
|
|
73
|
+
),
|
|
74
|
+
state: z.string(),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* What `rescore_with_feedback` answers with, inside the dialog's envelope —
|
|
79
|
+
* asked of the SDK rather than restated, which is the drift the comment used to
|
|
80
|
+
* assert away.
|
|
81
|
+
*/
|
|
82
|
+
const Rescored = dialogResultSchema(
|
|
83
|
+
z.object({
|
|
84
|
+
round: z.number(),
|
|
85
|
+
feedbackApplied: z.array(z.string()),
|
|
86
|
+
top: z.array(z.object({ name: z.string() })),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
/** What `screening_status` answers with on an untouched desk. */
|
|
91
|
+
const IdleStatus = z.object({ stage: z.string(), state: z.string(), screened: z.number() });
|
|
92
|
+
|
|
93
|
+
/** The evaluator's verdict, as the JSON a scripted `ctx.generate` returns. The
|
|
94
|
+
* script's last line repeats, so every applicant scores the same — enough to
|
|
95
|
+
* prove twelve calls were made and a table was written, which is all a script
|
|
96
|
+
* can prove. */
|
|
97
|
+
const FLAT_VERDICT = JSON.stringify({ score: 71, reason: "Scripted: a fair match." });
|
|
98
|
+
|
|
99
|
+
describeEval(agentDef, (test) => {
|
|
100
|
+
test(
|
|
101
|
+
"the stage the desk reports is the flow's, and an untouched desk spends no evaluator",
|
|
102
|
+
async ({ session }) => {
|
|
103
|
+
const turn = await session.say("Where are we with this?");
|
|
104
|
+
|
|
105
|
+
expect(toolNames(turn.toolCalls), describeTurn(turn)).toEqual(["screening_status"]);
|
|
106
|
+
// `stage` comes off `hiringFlow.position`, and `state` is the position
|
|
107
|
+
// itself — deriving either from "is there a job" is the drift the dialog
|
|
108
|
+
// exists to end, and it would show up here.
|
|
109
|
+
const status = toolResultIn(turn.toolCalls, "screening_status", IdleStatus);
|
|
110
|
+
expect(status).toMatchObject({ stage: "nothing screened yet", state: "idle", screened: 0 });
|
|
111
|
+
expect(hiringState(session)?.leaderboard ?? []).toEqual([]);
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
stubReply: [
|
|
115
|
+
{ tool: "screening_status", args: {} },
|
|
116
|
+
"Nothing's been screened yet — want me to run the applicants for the React role?",
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
test(
|
|
122
|
+
"no feedback can be applied before there is a ranking",
|
|
123
|
+
async ({ session }) => {
|
|
124
|
+
const turn = await session.say("Just weight TypeScript more heavily and score them.");
|
|
125
|
+
|
|
126
|
+
// Their router is only reachable after `score_leads`. The script FORCES
|
|
127
|
+
// the call so the gate really runs; the refusal names the position and
|
|
128
|
+
// quotes the state's instruction so the model can recover on its turn.
|
|
129
|
+
const attempts = turn.toolCalls.filter((call) => call.name === "rescore_with_feedback");
|
|
130
|
+
expect(attempts, describeTurn(turn)).toHaveLength(1);
|
|
131
|
+
for (const attempt of attempts) {
|
|
132
|
+
expect(attempt.result).toMatch(dialogRefusalPattern("idle"));
|
|
133
|
+
expect(attempt.result).toMatch(/screen_candidates/);
|
|
134
|
+
}
|
|
135
|
+
expect(hiringState(session)?.rounds ?? 0).toBe(0);
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
// A gate can only be observed refusing if something CALLS the gated tool,
|
|
139
|
+
// and a live model, told the tool is not yet available, sensibly does not.
|
|
140
|
+
scripted: true,
|
|
141
|
+
stubReply: [
|
|
142
|
+
{ tool: "rescore_with_feedback", args: { feedback: "weight TypeScript more heavily" } },
|
|
143
|
+
"I haven't screened anyone yet — shall I run them against the React role first?",
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
test(
|
|
149
|
+
"a screening is one call, one evaluation per applicant, and the top three come back",
|
|
150
|
+
async ({ session }) => {
|
|
151
|
+
const turn = await session.say(
|
|
152
|
+
"Yes, the Junior React Developer contract — screen the applicants for me.",
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// ONE call: their `load_leads` and `score_leads` are one tool, and a desk
|
|
156
|
+
// that called it once per applicant, or once per read-back, is spending
|
|
157
|
+
// twelve evaluations each time.
|
|
158
|
+
const calls = turn.toolCalls.filter((call) => call.name === "screen_candidates");
|
|
159
|
+
expect(calls, describeTurn(turn)).toHaveLength(1);
|
|
160
|
+
const screened = toolResultIn(turn.toolCalls, "screen_candidates", Screened);
|
|
161
|
+
expect(screened.screened).toBe(LEADS.length);
|
|
162
|
+
expect(screened.top).toHaveLength(SHORTLIST_SIZE);
|
|
163
|
+
expect(screened.top.map((one) => one.rank)).toEqual([1, 2, 3]);
|
|
164
|
+
expect(screened.state).toBe("reviewing");
|
|
165
|
+
// The browser was sent the whole table, not the three the caller heard.
|
|
166
|
+
const view = hiringState(session);
|
|
167
|
+
expect(view?.leaderboard).toHaveLength(LEADS.length);
|
|
168
|
+
expect(view?.jobTitle).toBe("Junior React Developer");
|
|
169
|
+
// Nothing outside the desk's own six tools was called: the evaluator is a
|
|
170
|
+
// `ctx.generate` inside a tool, never a tool the desk holds.
|
|
171
|
+
expect(toolNames(turn.toolCalls).filter((name) => !DESK_TOOLS.includes(name))).toEqual([]);
|
|
172
|
+
expect(turn.text).not.toBe("");
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
stubReply: [
|
|
176
|
+
{ tool: "screen_candidates", args: {} },
|
|
177
|
+
"All twelve are scored. The top three are Priya, Sofia and Tom — want the reasons?",
|
|
178
|
+
],
|
|
179
|
+
stubGenerate: [FLAT_VERDICT],
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
test(
|
|
184
|
+
"scores are the evaluator's, spread apart, and the desk does not rank from its own reading",
|
|
185
|
+
async ({ session }) => {
|
|
186
|
+
const turn = await session.say(
|
|
187
|
+
"Screen the applicants for the Junior React Developer role and tell me who stands out.",
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const calls = turn.toolCalls.filter((call) => call.name === "screen_candidates");
|
|
191
|
+
expect(calls, describeTurn(turn)).toHaveLength(1);
|
|
192
|
+
const screened = toolResultIn(turn.toolCalls, "screen_candidates", Screened);
|
|
193
|
+
// Their "don't use numbers like 100, 75, or 50" rule, measured: a live
|
|
194
|
+
// evaluator that ties three applicants at 75 has produced a list, not a
|
|
195
|
+
// ranking, and the desk cannot read back "who stands out" from a tie.
|
|
196
|
+
const scores = screened.top.map((one) => one.score);
|
|
197
|
+
expect(new Set(scores).size).toBe(scores.length);
|
|
198
|
+
for (const one of screened.top) expect(one.reason.length).toBeGreaterThan(30);
|
|
199
|
+
// What the caller HEARS names the evaluator's top pick. A desk that read
|
|
200
|
+
// twelve bios and formed its own view would name whoever it fancied.
|
|
201
|
+
const first = screened.top[0]?.name.split(" ")[0] ?? "";
|
|
202
|
+
expect(turn.text).toContain(first);
|
|
203
|
+
expect(toolNames(turn.toolCalls).filter((name) => !DESK_TOOLS.includes(name))).toEqual([]);
|
|
204
|
+
},
|
|
205
|
+
// Live only: a script cannot spread the scores, and the spread is the claim.
|
|
206
|
+
{ live: true },
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
test(
|
|
210
|
+
"the caller's feedback reaches the evaluator as a re-score, in their own words",
|
|
211
|
+
async ({ session }) => {
|
|
212
|
+
await session.say("Screen the applicants for the Junior React Developer contract.");
|
|
213
|
+
expect(hiringState(session)?.leaderboard.length ?? 0).toBe(LEADS.length);
|
|
214
|
+
|
|
215
|
+
const turn = await session.say(
|
|
216
|
+
"Hmm. I care much more about TypeScript depth than about years of experience — " +
|
|
217
|
+
"score them again with that in mind.",
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
// Option 2 of their router. The desk must not re-order the list itself —
|
|
221
|
+
// it has no scores of its own to re-order by — and it must not screen from
|
|
222
|
+
// scratch, which would throw the ranking the caller just heard away.
|
|
223
|
+
const names = toolNames(turn.toolCalls);
|
|
224
|
+
expect(names, describeTurn(turn)).toContain("rescore_with_feedback");
|
|
225
|
+
expect(names).not.toContain("screen_candidates");
|
|
226
|
+
const rescored = toolResultIn(turn.toolCalls, "rescore_with_feedback", Rescored);
|
|
227
|
+
expect(rescored.state).toBe("reviewing");
|
|
228
|
+
expect(rescored.result.round).toBe(1);
|
|
229
|
+
// The feedback is the caller's, carried whole — not a keyword.
|
|
230
|
+
const feedback = rescored.result.feedbackApplied.at(-1) ?? "";
|
|
231
|
+
expect(feedback.toLowerCase()).toContain("typescript");
|
|
232
|
+
expect(countWords(feedback)).toBeGreaterThan(3);
|
|
233
|
+
expect(rescored.result.top).toHaveLength(SHORTLIST_SIZE);
|
|
234
|
+
const view = hiringState(session);
|
|
235
|
+
expect(view?.rounds).toBe(1);
|
|
236
|
+
expect(view?.rounds).toBeLessThanOrEqual(MAX_FEEDBACK_ROUNDS);
|
|
237
|
+
expect(view?.feedback).toHaveLength(1);
|
|
238
|
+
},
|
|
239
|
+
// Live only: choosing option 2 over a fresh screening IS the measurement.
|
|
240
|
+
{ live: true },
|
|
241
|
+
);
|
|
242
|
+
});
|