@alexkroman1/aai-cli 0.12.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/bin.mjs +58 -0
- package/dist/_agent-BopNO5Bq.mjs +152 -0
- package/dist/_agent.d.ts +83 -0
- package/dist/_api-client.d.ts +92 -0
- package/dist/_artifacts-BJOYGQPp.mjs +21 -0
- package/dist/_artifacts.d.ts +16 -0
- package/dist/_build-target-C08aM-Es.mjs +1119 -0
- package/dist/_build-target.d.ts +276 -0
- package/dist/_bundler-CgBw5Bcu.mjs +102 -0
- package/dist/_bundler.d.ts +60 -0
- package/dist/_cli-common.d.ts +173 -0
- package/dist/_client-plugins.d.ts +57 -0
- package/dist/_config-mq1I5Cva.mjs +263 -0
- package/dist/_config.d.ts +122 -0
- package/dist/_console-audio.d.ts +17 -0
- package/dist/_console-session.d.ts +70 -0
- package/dist/_default-html.d.ts +33 -0
- package/dist/_deno-output.d.ts +23 -0
- package/dist/_deno-target.d.ts +74 -0
- package/dist/_deploy.d.ts +22 -0
- package/dist/_dev-agent-env.d.ts +27 -0
- package/dist/_dev-env-D9Uy5wNt.mjs +89 -0
- package/dist/_dev-env.d.ts +77 -0
- package/dist/_dev-restart.d.ts +64 -0
- package/dist/_dev-server-BNq5OnUJ.mjs +737 -0
- package/dist/_dev-server.d.ts +89 -0
- package/dist/_dev-session-ticket.d.ts +63 -0
- package/dist/_dev-source.d.ts +55 -0
- package/dist/_dev-tunnel.d.ts +90 -0
- package/dist/_dev-typecheck.d.ts +38 -0
- package/dist/_dev-vite-config.d.ts +100 -0
- package/dist/_dev-watch.d.ts +35 -0
- package/dist/_dotenv-file.d.ts +45 -0
- package/dist/_e2e-test-utils.d.ts +120 -0
- package/dist/_fault-mode.d.ts +194 -0
- package/dist/_help.d.ts +31 -0
- package/dist/_init.d.ts +66 -0
- package/dist/_mock-api.d.ts +22 -0
- package/dist/_mock-registry.d.ts +17 -0
- package/dist/_modal-app.d.ts +77 -0
- package/dist/_modal-output.d.ts +31 -0
- package/dist/_modal-target.d.ts +69 -0
- package/dist/_output-DBP9Op_d.mjs +120 -0
- package/dist/_output.d.ts +74 -0
- package/dist/_preflight-Bv6Ct4ss.mjs +149 -0
- package/dist/_preflight.d.ts +170 -0
- package/dist/_resource-commands.d.ts +22 -0
- package/dist/_run-code-deno-C0AtfHeH.mjs +268 -0
- package/dist/_run-code-deno.d.ts +130 -0
- package/dist/_server-common-CVXIeWrY.mjs +114 -0
- package/dist/_server-common.d.ts +75 -0
- package/dist/_slug-api-DJuwYZ6T.mjs +68 -0
- package/dist/_slug-api.d.ts +61 -0
- package/dist/_stop-server.d.ts +17 -0
- package/dist/_studio-BH05zugt.mjs +251 -0
- package/dist/_studio-commands.d.ts +73 -0
- package/dist/_studio.d.ts +80 -0
- package/dist/_target-bundle.d.ts +139 -0
- package/dist/_target-drain.d.ts +44 -0
- package/dist/_target-entry.d.ts +81 -0
- package/dist/_target-output.d.ts +63 -0
- package/dist/_templates-Bv-rd0SO.mjs +135 -0
- package/dist/_templates.d.ts +82 -0
- package/dist/_typecheck-gate-CcX2gLJZ.mjs +19 -0
- package/dist/_typecheck-gate.d.ts +11 -0
- package/dist/_ui-Coe0zwmm.mjs +102 -0
- package/dist/_ui.d.ts +90 -0
- package/dist/_utils-BVLdBvdT.mjs +186 -0
- package/dist/_utils.d.ts +126 -0
- package/dist/_vercel-output.d.ts +48 -0
- package/dist/_vercel-target.d.ts +169 -0
- package/dist/_vite-env-BiyJ0GQH.mjs +105 -0
- package/dist/_vite-env.d.ts +38 -0
- package/dist/_vitest-runner-CKI8_K1b.mjs +207 -0
- package/dist/_vitest-runner.d.ts +182 -0
- package/dist/_workflow-determinism-CLxFQ5ox.mjs +198 -0
- package/dist/_workflow-determinism.d.ts +118 -0
- package/dist/build-B37oBfEv.mjs +592 -0
- package/dist/build.d.ts +146 -0
- package/dist/cli-workflow.d.ts +10 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +1061 -194
- package/dist/client-bundler-D4SeZJ8E.mjs +240 -0
- package/dist/client-bundler.d.ts +32 -0
- package/dist/client-bundler.mjs +3 -0
- package/dist/console-D6OOjjeJ.mjs +443 -0
- package/dist/console.d.ts +70 -0
- package/dist/delete-Br0EOH0g.mjs +55 -0
- package/dist/delete.d.ts +25 -0
- package/dist/deploy-CLUH5cv2.mjs +97 -0
- package/dist/deploy.d.ts +25 -0
- package/dist/dev-ZVuyPLUk.mjs +274 -0
- package/dist/dev.d.ts +34 -0
- package/dist/eval-Dl8o91yC.mjs +74 -0
- package/dist/eval.d.ts +46 -0
- package/dist/init-x3FsKl2q.mjs +609 -0
- package/dist/init.d.ts +101 -0
- package/dist/login-oJdBWu2B.mjs +166 -0
- package/dist/login.d.ts +54 -0
- package/dist/logs-BfRq1HX9.mjs +80 -0
- package/dist/logs.d.ts +65 -0
- package/dist/project-config.d.ts +23 -0
- package/dist/project-config.mjs +3 -0
- package/dist/scaffold/.env.example +51 -0
- package/dist/scaffold/CLAUDE.md +390 -0
- package/dist/scaffold/agent-guide/AGENT-API.md +223 -0
- package/dist/scaffold/agent-guide/HOSTING.md +140 -0
- package/dist/scaffold/agent-guide/PIPELINE-TUNING.md +235 -0
- package/dist/scaffold/agent-guide/PROVIDERS.md +143 -0
- package/dist/scaffold/agent-guide/TESTING-EVALS.md +158 -0
- package/dist/scaffold/agent-guide/TOOLS.md +628 -0
- package/dist/scaffold/agent-guide/UI.md +291 -0
- package/dist/scaffold/agent-guide/WORKFLOWS.md +801 -0
- package/dist/scaffold/package.json +38 -0
- package/dist/scaffold/pnpm-workspace.yaml +45 -0
- package/dist/scaffold/tsconfig.json +3 -0
- package/dist/scaffold/vitest.config.ts +8 -0
- package/dist/secret-Db1UWLSZ.mjs +300 -0
- package/dist/secret.d.ts +70 -0
- package/dist/start.d.ts +112 -0
- package/dist/start.mjs +183 -0
- package/dist/studio-DAoJApzD.mjs +209 -0
- package/dist/studio.d.ts +55 -0
- package/dist/templates/applicant-screening-agent/agent.eval.test.ts +258 -0
- package/dist/templates/applicant-screening-agent/agent.test.ts +987 -0
- package/dist/templates/applicant-screening-agent/agent.ts +66 -0
- package/dist/templates/applicant-screening-agent/client.tsx +154 -0
- package/dist/templates/applicant-screening-agent/crews.ts +432 -0
- package/dist/templates/applicant-screening-agent/leads.json +86 -0
- package/dist/templates/applicant-screening-agent/screening-lock.test.ts +77 -0
- package/dist/templates/applicant-screening-agent/screening-lock.ts +51 -0
- package/dist/templates/applicant-screening-agent/shared.ts +483 -0
- package/dist/templates/applicant-screening-agent/system-prompt.md +21 -0
- package/dist/templates/applicant-screening-agent/tools/candidate_details.ts +49 -0
- package/dist/templates/applicant-screening-agent/tools/proceed_to_emails.ts +127 -0
- package/dist/templates/applicant-screening-agent/tools/read_email.ts +50 -0
- package/dist/templates/applicant-screening-agent/tools/rescore_with_feedback.ts +140 -0
- package/dist/templates/applicant-screening-agent/tools/screen_candidates.ts +128 -0
- package/dist/templates/applicant-screening-agent/tools/screening_status.ts +51 -0
- package/dist/templates/call-audit-workflow/agent.eval.test.ts +492 -0
- package/dist/templates/call-audit-workflow/agent.test.ts +1032 -0
- package/dist/templates/call-audit-workflow/agent.ts +161 -0
- package/dist/templates/call-audit-workflow/client.tsx +236 -0
- package/dist/templates/call-audit-workflow/guards.test.ts +233 -0
- package/dist/templates/call-audit-workflow/workflows/audit.ts +391 -0
- package/dist/templates/call-audit-workflow/workflows/ingest.ts +279 -0
- package/dist/templates/call-audit-workflow/workflows/media.ts +729 -0
- package/dist/templates/call-audit-workflow/workflows/summarize.ts +201 -0
- package/dist/templates/call-audit-workflow/workflows/sync-api.ts +54 -0
- package/dist/templates/code-interpreter-agent/agent.eval.test.ts +195 -0
- package/dist/templates/code-interpreter-agent/agent.test.ts +91 -0
- package/dist/templates/code-interpreter-agent/agent.ts +9 -0
- package/dist/templates/code-interpreter-agent/system-prompt.md +18 -0
- package/dist/templates/coding-agent/agent.eval.test.ts +135 -0
- package/dist/templates/coding-agent/agent.test.ts +109 -0
- package/dist/templates/coding-agent/agent.ts +45 -0
- package/dist/templates/coding-agent/chat.ts +63 -0
- package/dist/templates/coding-agent/shared.ts +46 -0
- package/dist/templates/coding-agent/system-prompt.md +32 -0
- package/dist/templates/coding-agent/tools/bash.ts +6 -0
- package/dist/templates/coding-agent/tools/delete_file.ts +6 -0
- package/dist/templates/coding-agent/tools/edit_file.ts +6 -0
- package/dist/templates/coding-agent/tools/glob.ts +6 -0
- package/dist/templates/coding-agent/tools/grep.ts +6 -0
- package/dist/templates/coding-agent/tools/list_files.ts +6 -0
- package/dist/templates/coding-agent/tools/read_file.ts +6 -0
- package/dist/templates/coding-agent/tools/todo_write.ts +6 -0
- package/dist/templates/coding-agent/tools/write_file.ts +6 -0
- package/dist/templates/custom-pipeline-agent/agent.eval.test.ts +79 -0
- package/dist/templates/custom-pipeline-agent/agent.test.ts +79 -0
- package/dist/templates/custom-pipeline-agent/agent.ts +13 -0
- package/dist/templates/custom-pipeline-agent/modes.test.ts +162 -0
- package/dist/templates/custom-pipeline-agent/stages.test.ts +330 -0
- package/dist/templates/document-redline-workflow/agent.eval.test.ts +254 -0
- package/dist/templates/document-redline-workflow/agent.test.ts +552 -0
- package/dist/templates/document-redline-workflow/agent.ts +112 -0
- package/dist/templates/document-redline-workflow/client.tsx +224 -0
- package/dist/templates/document-redline-workflow/form.ts +74 -0
- package/dist/templates/document-redline-workflow/workflows/prompts.ts +68 -0
- package/dist/templates/document-redline-workflow/workflows/redline.ts +317 -0
- package/dist/templates/emergency-dispatch-agent/agent.eval.test.ts +372 -0
- package/dist/templates/emergency-dispatch-agent/agent.test.ts +576 -0
- package/dist/templates/emergency-dispatch-agent/agent.ts +63 -0
- package/dist/templates/emergency-dispatch-agent/client.tsx +453 -0
- package/dist/templates/emergency-dispatch-agent/events.ts +48 -0
- package/dist/templates/emergency-dispatch-agent/guardrails.ts +105 -0
- package/dist/templates/emergency-dispatch-agent/shared.ts +768 -0
- package/dist/templates/emergency-dispatch-agent/system-prompt.md +42 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_add_note.ts +28 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_create.ts +95 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_escalate.ts +96 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_get.ts +40 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_triage.ts +90 -0
- package/dist/templates/emergency-dispatch-agent/tools/incident_update_status.ts +75 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_dashboard.ts +72 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_protocols.ts +27 -0
- package/dist/templates/emergency-dispatch-agent/tools/ops_run_scenario.ts +154 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_dispatch.ts +112 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_get_available.ts +34 -0
- package/dist/templates/emergency-dispatch-agent/tools/resources_update_status.ts +63 -0
- package/dist/templates/entertainment-picks-agent/agent.eval.test.ts +281 -0
- package/dist/templates/entertainment-picks-agent/agent.test.ts +260 -0
- package/dist/templates/entertainment-picks-agent/agent.ts +14 -0
- package/dist/templates/entertainment-picks-agent/client.tsx +169 -0
- package/dist/templates/entertainment-picks-agent/shared.ts +50 -0
- package/dist/templates/entertainment-picks-agent/system-prompt.md +19 -0
- package/dist/templates/entertainment-picks-agent/tools/recommend.ts +79 -0
- package/dist/templates/entertainment-picks-agent/tools/revisit.ts +56 -0
- package/dist/templates/executive-inbox-agent/agent.eval.test.ts +296 -0
- package/dist/templates/executive-inbox-agent/agent.test.ts +682 -0
- package/dist/templates/executive-inbox-agent/agent.ts +51 -0
- package/dist/templates/executive-inbox-agent/calendar.test.ts +203 -0
- package/dist/templates/executive-inbox-agent/client.tsx +195 -0
- package/dist/templates/executive-inbox-agent/inbox.ts +233 -0
- package/dist/templates/executive-inbox-agent/meeting.ts +138 -0
- package/dist/templates/executive-inbox-agent/nodes.ts +148 -0
- package/dist/templates/executive-inbox-agent/prompts.ts +333 -0
- package/dist/templates/executive-inbox-agent/review.ts +425 -0
- package/dist/templates/executive-inbox-agent/shared.ts +486 -0
- package/dist/templates/executive-inbox-agent/system-prompt.md +15 -0
- package/dist/templates/executive-inbox-agent/tools/accept.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/ask_question.ts +30 -0
- package/dist/templates/executive-inbox-agent/tools/draft_reply.ts +67 -0
- package/dist/templates/executive-inbox-agent/tools/edit.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/ignore.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/inbox_status.ts +27 -0
- package/dist/templates/executive-inbox-agent/tools/meeting_assistant.ts +52 -0
- package/dist/templates/executive-inbox-agent/tools/new_email.ts +50 -0
- package/dist/templates/executive-inbox-agent/tools/open_email.ts +157 -0
- package/dist/templates/executive-inbox-agent/tools/respond.ts +10 -0
- package/dist/templates/executive-inbox-agent/tools/review_memory.ts +22 -0
- package/dist/templates/executive-inbox-agent/tools/send_calendar_invite.ts +68 -0
- package/dist/templates/executive-inbox-agent/tools/triage_inbox.ts +75 -0
- package/dist/templates/front-desk-agent/agent.eval.test.ts +177 -0
- package/dist/templates/front-desk-agent/agent.test.ts +155 -0
- package/dist/templates/front-desk-agent/agent.ts +22 -0
- package/dist/templates/front-desk-agent/shared.ts +239 -0
- package/dist/templates/front-desk-agent/system-prompt.md +13 -0
- package/dist/templates/front-desk-agent/tools/verify_account.ts +41 -0
- package/dist/templates/home-assistant-agent/agent.eval.test.ts +176 -0
- package/dist/templates/home-assistant-agent/agent.test.ts +513 -0
- package/dist/templates/home-assistant-agent/agent.ts +37 -0
- package/dist/templates/home-assistant-agent/client.tsx +176 -0
- package/dist/templates/home-assistant-agent/ring.tsx +55 -0
- package/dist/templates/home-assistant-agent/shared.ts +130 -0
- package/dist/templates/home-assistant-agent/system-prompt.md +43 -0
- package/dist/templates/home-assistant-agent/tools/cancel_reminders.ts +16 -0
- package/dist/templates/home-assistant-agent/tools/deep_research.ts +55 -0
- package/dist/templates/home-assistant-agent/tools/remind_me.ts +53 -0
- package/dist/templates/home-assistant-agent/tools/stop.ts +25 -0
- package/dist/templates/home-assistant-agent/use-speaker.ts +98 -0
- package/dist/templates/home-assistant-agent/workflows/remind.ts +25 -0
- package/dist/templates/home-assistant-agent/workflows/research-prompts.ts +41 -0
- package/dist/templates/home-assistant-agent/workflows/research.ts +110 -0
- package/dist/templates/home-assistant-agent/workflows/text.ts +30 -0
- package/dist/templates/hotel-reception-agent/agent.eval.test.ts +241 -0
- package/dist/templates/hotel-reception-agent/agent.test.ts +1121 -0
- package/dist/templates/hotel-reception-agent/agent.ts +66 -0
- package/dist/templates/hotel-reception-agent/booking.ts +159 -0
- package/dist/templates/hotel-reception-agent/card.ts +92 -0
- package/dist/templates/hotel-reception-agent/catalogs.ts +219 -0
- package/dist/templates/hotel-reception-agent/client.tsx +150 -0
- package/dist/templates/hotel-reception-agent/concierge.ts +104 -0
- package/dist/templates/hotel-reception-agent/desk-seams.test.ts +339 -0
- package/dist/templates/hotel-reception-agent/desk.ts +220 -0
- package/dist/templates/hotel-reception-agent/disputes.ts +214 -0
- package/dist/templates/hotel-reception-agent/events.ts +80 -0
- package/dist/templates/hotel-reception-agent/hotel.ts +412 -0
- package/dist/templates/hotel-reception-agent/policies.ts +209 -0
- package/dist/templates/hotel-reception-agent/records.ts +384 -0
- package/dist/templates/hotel-reception-agent/restaurant.ts +147 -0
- package/dist/templates/hotel-reception-agent/seed.ts +955 -0
- package/dist/templates/hotel-reception-agent/session.ts +50 -0
- package/dist/templates/hotel-reception-agent/shared.ts +353 -0
- package/dist/templates/hotel-reception-agent/system-prompt.md +76 -0
- package/dist/templates/hotel-reception-agent/tools/abandon_booking.ts +31 -0
- package/dist/templates/hotel-reception-agent/tools/add_to_waitlist.ts +42 -0
- package/dist/templates/hotel-reception-agent/tools/book_airport_car.ts +58 -0
- package/dist/templates/hotel-reception-agent/tools/book_business_center.ts +44 -0
- package/dist/templates/hotel-reception-agent/tools/book_spa_appointment.ts +39 -0
- package/dist/templates/hotel-reception-agent/tools/book_tour.ts +35 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_restaurant_reservation.ts +26 -0
- package/dist/templates/hotel-reception-agent/tools/cancel_room_booking.ts +64 -0
- package/dist/templates/hotel-reception-agent/tools/check_restaurant_availability.ts +24 -0
- package/dist/templates/hotel-reception-agent/tools/check_room_availability.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/choose_room.ts +93 -0
- package/dist/templates/hotel-reception-agent/tools/confirm_booking.ts +154 -0
- package/dist/templates/hotel-reception-agent/tools/dispatch_emergency.ts +62 -0
- package/dist/templates/hotel-reception-agent/tools/dispute_charge.ts +91 -0
- package/dist/templates/hotel-reception-agent/tools/flag_late_arrival.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_booking.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_guest_history.ts +28 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_invoice.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_policy.ts +20 -0
- package/dist/templates/hotel-reception-agent/tools/lookup_restaurant_reservation.ts +27 -0
- package/dist/templates/hotel-reception-agent/tools/modify_restaurant_reservation.ts +75 -0
- package/dist/templates/hotel-reception-agent/tools/order_flowers.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/record_card.ts +46 -0
- package/dist/templates/hotel-reception-agent/tools/record_followup.ts +51 -0
- package/dist/templates/hotel-reception-agent/tools/record_group_inquiry.ts +45 -0
- package/dist/templates/hotel-reception-agent/tools/record_guest_details.ts +71 -0
- package/dist/templates/hotel-reception-agent/tools/reinstate_booking.ts +65 -0
- package/dist/templates/hotel-reception-agent/tools/request_flight_reconfirmation.ts +55 -0
- package/dist/templates/hotel-reception-agent/tools/resend_confirmation.ts +40 -0
- package/dist/templates/hotel-reception-agent/tools/reserve_table.ts +87 -0
- package/dist/templates/hotel-reception-agent/tools/resolve_room_conflict.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/schedule_wakeup_call.ts +49 -0
- package/dist/templates/hotel-reception-agent/tools/set_do_not_disturb.ts +29 -0
- package/dist/templates/hotel-reception-agent/tools/set_extras.ts +51 -0
- package/dist/templates/hotel-reception-agent/tools/set_stay.ts +98 -0
- package/dist/templates/hotel-reception-agent/tools/start_booking_modification.ts +58 -0
- package/dist/templates/hotel-reception-agent/tools/start_room_booking.ts +50 -0
- package/dist/templates/hotel-reception-agent/tools/take_guest_message.ts +72 -0
- package/dist/templates/hotel-reception-agent/tools/transfer_call.ts +48 -0
- package/dist/templates/hotel-reception-agent/tools/update_card.ts +46 -0
- package/dist/templates/hotel-reception-agent/tools/verify_booking.ts +96 -0
- package/dist/templates/link-digest-workflow/agent.eval.test.ts +231 -0
- package/dist/templates/link-digest-workflow/agent.test.ts +647 -0
- package/dist/templates/link-digest-workflow/agent.ts +100 -0
- package/dist/templates/link-digest-workflow/api-client.ts +144 -0
- package/dist/templates/link-digest-workflow/client.tsx +231 -0
- package/dist/templates/link-digest-workflow/workflows/digest.ts +334 -0
- package/dist/templates/medication-safety-agent/agent.eval.test.ts +182 -0
- package/dist/templates/medication-safety-agent/agent.test.ts +332 -0
- package/dist/templates/medication-safety-agent/agent.ts +62 -0
- package/dist/templates/medication-safety-agent/fda.test.ts +130 -0
- package/dist/templates/medication-safety-agent/fda.ts +159 -0
- package/dist/templates/medication-safety-agent/system-prompt.md +26 -0
- package/dist/templates/medication-safety-agent/tools/check_drug_interaction.ts +62 -0
- package/dist/templates/medication-safety-agent/tools/medication_lookup.ts +36 -0
- package/dist/templates/meeting-recap-agent/agent.eval.test.ts +446 -0
- package/dist/templates/meeting-recap-agent/agent.test.ts +1408 -0
- package/dist/templates/meeting-recap-agent/agent.ts +104 -0
- package/dist/templates/meeting-recap-agent/shared.ts +44 -0
- package/dist/templates/meeting-recap-agent/tools/cancel_recap.ts +23 -0
- package/dist/templates/meeting-recap-agent/tools/keep_transcript.ts +31 -0
- package/dist/templates/meeting-recap-agent/tools/recap_progress.ts +24 -0
- package/dist/templates/meeting-recap-agent/tools/recap_status.ts +45 -0
- package/dist/templates/meeting-recap-agent/tools/request_recap.ts +44 -0
- package/dist/templates/meeting-recap-agent/workflows/recap.ts +838 -0
- package/dist/templates/meeting-recap-agent/workflows/tokens.ts +47 -0
- package/dist/templates/pizza-ordering-agent/agent.eval.test.ts +228 -0
- package/dist/templates/pizza-ordering-agent/agent.test.ts +299 -0
- package/dist/templates/pizza-ordering-agent/agent.ts +24 -0
- package/dist/templates/pizza-ordering-agent/client.tsx +104 -0
- package/dist/templates/pizza-ordering-agent/shared.ts +225 -0
- package/dist/templates/pizza-ordering-agent/system-prompt.md +23 -0
- package/dist/templates/pizza-ordering-agent/tools/add_pizza.ts +27 -0
- package/dist/templates/pizza-ordering-agent/tools/place_order.ts +26 -0
- package/dist/templates/pizza-ordering-agent/tools/remove_pizza.ts +18 -0
- package/dist/templates/pizza-ordering-agent/tools/set_customer_name.ts +13 -0
- package/dist/templates/pizza-ordering-agent/tools/update_pizza.ts +28 -0
- package/dist/templates/pizza-ordering-agent/tools/view_order.ts +21 -0
- package/dist/templates/podcast-digest-workflow/agent.eval.test.ts +421 -0
- package/dist/templates/podcast-digest-workflow/agent.test.ts +1225 -0
- package/dist/templates/podcast-digest-workflow/agent.ts +143 -0
- package/dist/templates/podcast-digest-workflow/client.tsx +259 -0
- package/dist/templates/podcast-digest-workflow/workflows/digest.ts +499 -0
- package/dist/templates/podcast-digest-workflow/workflows/feeds.ts +575 -0
- package/dist/templates/podcast-digest-workflow/workflows/slack.ts +153 -0
- package/dist/templates/push-to-talk-agent/agent.eval.test.ts +78 -0
- package/dist/templates/push-to-talk-agent/agent.test.ts +63 -0
- package/dist/templates/push-to-talk-agent/agent.ts +22 -0
- package/dist/templates/push-to-talk-agent/client.tsx +124 -0
- package/dist/templates/push-to-talk-agent/shared.ts +28 -0
- package/dist/templates/push-to-talk-agent/system-prompt.md +11 -0
- package/dist/templates/push-to-talk-agent/tools/list_notes.ts +15 -0
- package/dist/templates/push-to-talk-agent/tools/save_note.ts +26 -0
- package/dist/templates/quickstart-agent/agent.eval.test.ts +148 -0
- package/dist/templates/quickstart-agent/agent.test.ts +96 -0
- package/dist/templates/quickstart-agent/agent.ts +25 -0
- package/dist/templates/quickstart-agent/system-prompt.md +8 -0
- package/dist/templates/quickstart-agent/tools/get_weather.ts +59 -0
- package/dist/templates/research-handoff-agent/agent.eval.test.ts +341 -0
- package/dist/templates/research-handoff-agent/agent.test.ts +831 -0
- package/dist/templates/research-handoff-agent/agent.ts +118 -0
- package/dist/templates/research-handoff-agent/shared.ts +41 -0
- package/dist/templates/research-handoff-agent/tools/file_it_now.ts +32 -0
- package/dist/templates/research-handoff-agent/tools/request_research.ts +33 -0
- package/dist/templates/research-handoff-agent/tools/research_progress.ts +23 -0
- package/dist/templates/research-handoff-agent/tools/research_status.ts +73 -0
- package/dist/templates/research-handoff-agent/workflows/filing.ts +164 -0
- package/dist/templates/research-handoff-agent/workflows/prompts.ts +46 -0
- package/dist/templates/research-handoff-agent/workflows/research.ts +100 -0
- package/dist/templates/research-handoff-agent/workflows/review.ts +43 -0
- package/dist/templates/research-planner-agent/agent.eval.test.ts +241 -0
- package/dist/templates/research-planner-agent/agent.test.ts +635 -0
- package/dist/templates/research-planner-agent/agent.ts +26 -0
- package/dist/templates/research-planner-agent/client.tsx +120 -0
- package/dist/templates/research-planner-agent/procedure.ts +287 -0
- package/dist/templates/research-planner-agent/prompts.ts +153 -0
- package/dist/templates/research-planner-agent/shared.ts +327 -0
- package/dist/templates/research-planner-agent/system-prompt.md +18 -0
- package/dist/templates/research-planner-agent/tools/plan_status.ts +41 -0
- package/dist/templates/research-planner-agent/tools/revise_plan.ts +71 -0
- package/dist/templates/research-planner-agent/tools/start_plan.ts +62 -0
- package/dist/templates/research-planner-agent/tools/work_next_step.ts +177 -0
- package/dist/templates/retail-orders-agent/address.ts +109 -0
- package/dist/templates/retail-orders-agent/agent.eval.test.ts +305 -0
- package/dist/templates/retail-orders-agent/agent.test.ts +1260 -0
- package/dist/templates/retail-orders-agent/agent.ts +103 -0
- package/dist/templates/retail-orders-agent/authenticate.ts +34 -0
- package/dist/templates/retail-orders-agent/cancel.ts +114 -0
- package/dist/templates/retail-orders-agent/client.tsx +579 -0
- package/dist/templates/retail-orders-agent/keyterms.ts +154 -0
- package/dist/templates/retail-orders-agent/payment.ts +103 -0
- package/dist/templates/retail-orders-agent/pending.test.ts +204 -0
- package/dist/templates/retail-orders-agent/pending.ts +137 -0
- package/dist/templates/retail-orders-agent/refund.ts +19 -0
- package/dist/templates/retail-orders-agent/registry.test.ts +446 -0
- package/dist/templates/retail-orders-agent/resolve.test.ts +100 -0
- package/dist/templates/retail-orders-agent/resolve.ts +114 -0
- package/dist/templates/retail-orders-agent/returns.ts +101 -0
- package/dist/templates/retail-orders-agent/seed.json +4260 -0
- package/dist/templates/retail-orders-agent/seed.test.ts +233 -0
- package/dist/templates/retail-orders-agent/shared.test.ts +240 -0
- package/dist/templates/retail-orders-agent/shared.ts +547 -0
- package/dist/templates/retail-orders-agent/store.test.ts +331 -0
- package/dist/templates/retail-orders-agent/store.ts +485 -0
- package/dist/templates/retail-orders-agent/swap.test.ts +189 -0
- package/dist/templates/retail-orders-agent/swap.ts +358 -0
- package/dist/templates/retail-orders-agent/system-prompt.md +152 -0
- package/dist/templates/retail-orders-agent/tools/cancel_change.ts +33 -0
- package/dist/templates/retail-orders-agent/tools/cancel_pending_order.ts +31 -0
- package/dist/templates/retail-orders-agent/tools/confirm_change.ts +42 -0
- package/dist/templates/retail-orders-agent/tools/exchange_delivered_order_items.ts +47 -0
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_email.ts +31 -0
- package/dist/templates/retail-orders-agent/tools/find_user_id_by_name_zip.ts +36 -0
- package/dist/templates/retail-orders-agent/tools/get_item_details.ts +27 -0
- package/dist/templates/retail-orders-agent/tools/get_order_details.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/get_product_details.ts +30 -0
- package/dist/templates/retail-orders-agent/tools/get_user_details.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/list_all_product_types.ts +22 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_address.ts +27 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_items.ts +48 -0
- package/dist/templates/retail-orders-agent/tools/modify_pending_order_payment.ts +32 -0
- package/dist/templates/retail-orders-agent/tools/modify_user_address.ts +26 -0
- package/dist/templates/retail-orders-agent/tools/return_delivered_order_items.ts +37 -0
- package/dist/templates/retail-orders-agent/tools/transfer_to_human_agents.ts +28 -0
- package/dist/templates/roadside-assistance-agent/agent.eval.test.ts +283 -0
- package/dist/templates/roadside-assistance-agent/agent.test.ts +650 -0
- package/dist/templates/roadside-assistance-agent/agent.ts +89 -0
- package/dist/templates/roadside-assistance-agent/call.ts +232 -0
- package/dist/templates/roadside-assistance-agent/events.ts +92 -0
- package/dist/templates/roadside-assistance-agent/shared.ts +346 -0
- package/dist/templates/roadside-assistance-agent/system-prompt.md +37 -0
- package/dist/templates/roadside-assistance-agent/tools/acknowledge_disclosure.ts +61 -0
- package/dist/templates/roadside-assistance-agent/tools/dispatch_truck.ts +149 -0
- package/dist/templates/roadside-assistance-agent/tools/job_status.ts +38 -0
- package/dist/templates/roadside-assistance-agent/tools/lookup_coverage.ts +83 -0
- package/dist/templates/roadside-assistance-agent/tools/report_location.ts +79 -0
- package/dist/templates/roadside-assistance-agent/tools/service_disclosure.ts +51 -0
- package/dist/templates/roadside-assistance-agent/yard.test.ts +162 -0
- package/dist/templates/roadside-assistance-agent/yard.ts +183 -0
- package/dist/templates/spoken-summary-workflow/agent.eval.test.ts +354 -0
- package/dist/templates/spoken-summary-workflow/agent.test.ts +493 -0
- package/dist/templates/spoken-summary-workflow/agent.ts +164 -0
- package/dist/templates/spoken-summary-workflow/client.tsx +220 -0
- package/dist/templates/spoken-summary-workflow/workflows/summarize.ts +260 -0
- package/dist/templates/spoken-summary-workflow/workflows/transcribe.ts +137 -0
- package/dist/templates/tabletop-rpg-agent/agent.eval.test.ts +314 -0
- package/dist/templates/tabletop-rpg-agent/agent.test.ts +1000 -0
- package/dist/templates/tabletop-rpg-agent/agent.ts +58 -0
- package/dist/templates/tabletop-rpg-agent/client.tsx +814 -0
- package/dist/templates/tabletop-rpg-agent/shared.ts +1028 -0
- package/dist/templates/tabletop-rpg-agent/system-prompt.md +116 -0
- package/dist/templates/tabletop-rpg-agent/tools/action_roll.ts +119 -0
- package/dist/templates/tabletop-rpg-agent/tools/burn_momentum.ts +110 -0
- package/dist/templates/tabletop-rpg-agent/tools/check_state.ts +37 -0
- package/dist/templates/tabletop-rpg-agent/tools/oracle.ts +255 -0
- package/dist/templates/tabletop-rpg-agent/tools/setup_character.ts +228 -0
- package/dist/templates/tabletop-rpg-agent/tools/update_state.ts +194 -0
- package/dist/templates/technical-support-agent/agent.eval.test.ts +260 -0
- package/dist/templates/technical-support-agent/agent.test.ts +424 -0
- package/dist/templates/technical-support-agent/agent.ts +39 -0
- package/dist/templates/technical-support-agent/client.tsx +132 -0
- package/dist/templates/technical-support-agent/knowledge.json +65 -0
- package/dist/templates/technical-support-agent/knowledge.ts +165 -0
- package/dist/templates/technical-support-agent/nodes.ts +143 -0
- package/dist/templates/technical-support-agent/procedure.ts +453 -0
- package/dist/templates/technical-support-agent/prompts.ts +102 -0
- package/dist/templates/technical-support-agent/shared.ts +128 -0
- package/dist/templates/technical-support-agent/system-prompt.md +18 -0
- package/dist/templates/technical-support-agent/tools/answer_question.ts +134 -0
- package/dist/templates/technical-support-agent/tools/list_topics.ts +23 -0
- package/dist/templates/technical-support-agent/tools/log_ticket.ts +30 -0
- package/dist/templates/text-adventure-agent/agent.eval.test.ts +222 -0
- package/dist/templates/text-adventure-agent/agent.test.ts +429 -0
- package/dist/templates/text-adventure-agent/agent.ts +76 -0
- package/dist/templates/text-adventure-agent/client.tsx +359 -0
- package/dist/templates/text-adventure-agent/shared.ts +210 -0
- package/dist/templates/text-adventure-agent/system-prompt.md +50 -0
- package/dist/templates/text-adventure-agent/tools/game_state_drop.ts +29 -0
- package/dist/templates/text-adventure-agent/tools/game_state_flag.ts +13 -0
- package/dist/templates/text-adventure-agent/tools/game_state_get.ts +17 -0
- package/dist/templates/text-adventure-agent/tools/game_state_move.ts +15 -0
- package/dist/templates/text-adventure-agent/tools/game_state_restart.ts +13 -0
- package/dist/templates/text-adventure-agent/tools/game_state_score.ts +19 -0
- package/dist/templates/text-adventure-agent/tools/game_state_take.ts +13 -0
- package/dist/templates/topic-briefing-agent/agent.eval.test.ts +202 -0
- package/dist/templates/topic-briefing-agent/agent.test.ts +651 -0
- package/dist/templates/topic-briefing-agent/agent.ts +45 -0
- package/dist/templates/topic-briefing-agent/shared.ts +392 -0
- package/dist/templates/topic-briefing-agent/slack.ts +108 -0
- package/dist/templates/topic-briefing-agent/system-prompt.md +54 -0
- package/dist/templates/topic-briefing-agent/tools/briefing_so_far.ts +43 -0
- package/dist/templates/topic-briefing-agent/tools/research_topic.ts +80 -0
- package/dist/templates/topic-briefing-agent/tools/send_briefing.ts +115 -0
- package/dist/templates/topic-briefing-agent/tools/verify_claim.ts +123 -0
- package/dist/templates/transcription-workflow/agent.eval.test.ts +237 -0
- package/dist/templates/transcription-workflow/agent.test.ts +2032 -0
- package/dist/templates/transcription-workflow/agent.ts +188 -0
- package/dist/templates/transcription-workflow/client.tsx +511 -0
- package/dist/templates/transcription-workflow/recover.test.ts +222 -0
- package/dist/templates/transcription-workflow/recover.ts +154 -0
- package/dist/templates/transcription-workflow/run-panel.tsx +212 -0
- package/dist/templates/transcription-workflow/total-latency.tsx +170 -0
- package/dist/templates/transcription-workflow/workflows/batch.ts +189 -0
- package/dist/templates/transcription-workflow/workflows/downsample.ts +273 -0
- package/dist/templates/transcription-workflow/workflows/normalize.ts +385 -0
- package/dist/templates/transcription-workflow/workflows/stitch.ts +122 -0
- package/dist/templates/transcription-workflow/workflows/stream.ts +690 -0
- package/dist/templates/transcription-workflow/workflows/sync-api.ts +81 -0
- package/dist/templates/transcription-workflow/workflows/transcribe.ts +479 -0
- package/dist/templates/transcription-workflow/workflows/wav.ts +250 -0
- package/dist/templates/travel-concierge-agent/agent.eval.test.ts +300 -0
- package/dist/templates/travel-concierge-agent/agent.test.ts +601 -0
- package/dist/templates/travel-concierge-agent/agent.ts +62 -0
- package/dist/templates/travel-concierge-agent/call-events.ts +80 -0
- package/dist/templates/travel-concierge-agent/client.tsx +146 -0
- package/dist/templates/travel-concierge-agent/routing.ts +170 -0
- package/dist/templates/travel-concierge-agent/shared.ts +862 -0
- package/dist/templates/travel-concierge-agent/system-prompt.md +30 -0
- package/dist/templates/travel-concierge-agent/tools/book_car_rental.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/book_excursion.ts +19 -0
- package/dist/templates/travel-concierge-agent/tools/book_hotel.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/cancel_action.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/cancel_ticket.ts +21 -0
- package/dist/templates/travel-concierge-agent/tools/complete_or_escalate.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/confirm_action.ts +9 -0
- package/dist/templates/travel-concierge-agent/tools/lookup_booking.ts +36 -0
- package/dist/templates/travel-concierge-agent/tools/search_car_rentals.ts +36 -0
- package/dist/templates/travel-concierge-agent/tools/search_excursions.ts +40 -0
- package/dist/templates/travel-concierge-agent/tools/search_flights.ts +58 -0
- package/dist/templates/travel-concierge-agent/tools/search_hotels.ts +39 -0
- package/dist/templates/travel-concierge-agent/tools/to_car_rental_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_excursion_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_flight_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/to_hotel_assistant.ts +11 -0
- package/dist/templates/travel-concierge-agent/tools/update_ticket.ts +23 -0
- package/dist/templates/web-research-agent/agent.eval.test.ts +144 -0
- package/dist/templates/web-research-agent/agent.test.ts +181 -0
- package/dist/templates/web-research-agent/agent.ts +128 -0
- package/dist/templates/web-research-agent/system-prompt.md +33 -0
- package/dist/templates/word-game-agent/agent.eval.test.ts +222 -0
- package/dist/templates/word-game-agent/agent.test.ts +484 -0
- package/dist/templates/word-game-agent/agent.ts +55 -0
- package/dist/templates/word-game-agent/client.tsx +211 -0
- package/dist/templates/word-game-agent/game.ts +133 -0
- package/dist/templates/word-game-agent/guess.ts +63 -0
- package/dist/templates/word-game-agent/player.ts +67 -0
- package/dist/templates/word-game-agent/shared.ts +249 -0
- package/dist/templates/word-game-agent/system-prompt.md +15 -0
- package/dist/templates/word-game-agent/tools/final_score.ts +37 -0
- package/dist/templates/word-game-agent/tools/relay_description.ts +137 -0
- package/dist/templates/word-game-agent/tools/repeat_word.ts +19 -0
- package/dist/templates/word-game-agent/tools/skip_word.ts +31 -0
- package/dist/templates/word-game-agent/tools/start_game.ts +52 -0
- package/dist/templates/word-game-agent/words.ts +278 -0
- package/dist/test-XufelYGW.mjs +104 -0
- package/dist/test.d.ts +81 -0
- package/dist/typecheck.d.ts +44 -0
- package/dist/typecheck.mjs +185 -0
- package/dist/worker-bundler.d.ts +37 -0
- package/dist/worker-bundler.mjs +156 -0
- package/dist/workflow-CDUlTD5B.mjs +239 -0
- package/dist/workflow.d.ts +76 -0
- package/package.json +75 -24
- package/dist/_api-client-H4MFOr8j.mjs +0 -35
- package/dist/_bundler-2yKukgnU.mjs +0 -125
- package/dist/_discover-a8yIuqEp.mjs +0 -220
- package/dist/_init-VzVTpJFZ.mjs +0 -56
- package/dist/_templates-CtZBILce.mjs +0 -72
- package/dist/_ui-DWGXImbO.mjs +0 -30
- package/dist/delete-BvRel3Tw.mjs +0 -34
- package/dist/deploy-CnscqVZv.mjs +0 -92
- package/dist/dev-DEZKrw8v.mjs +0 -18
- package/dist/init-BYX6pxjd.mjs +0 -114
- package/dist/secret-DLosn47q.mjs +0 -47
- package/dist/test-CYoqKJP0.mjs +0 -38
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Copyright 2026 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Press to transcript, which is the one number neither bar can give.
|
|
4
|
+
*
|
|
5
|
+
* The upload bar and the progress log describe the two stretches separately, and
|
|
6
|
+
* neither answers the question a reader comparing the three modes is actually
|
|
7
|
+
* asking. Nothing on the server can answer it either — `output.elapsedMs` is the
|
|
8
|
+
* RUN's own wall clock, so in the two modes that store the file first it begins
|
|
9
|
+
* after the upload and misses most of the wait. Only the browser holds both
|
|
10
|
+
* ends.
|
|
11
|
+
*
|
|
12
|
+
* Its own module because it is a self-contained instrument — a stopwatch and the
|
|
13
|
+
* one section that prints it — and `client.tsx` is the file a reader goes to for
|
|
14
|
+
* the page's SHAPE.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { formatDuration } from "@alexkroman1/aai/utils";
|
|
18
|
+
import { Facts } from "@alexkroman1/aai-ui";
|
|
19
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* How often the running stopwatch re-renders.
|
|
23
|
+
*
|
|
24
|
+
* Under a second, so the displayed seconds turn over promptly rather than up to a
|
|
25
|
+
* second late; nothing reads this value, since the elapsed time is measured from
|
|
26
|
+
* the clock at render (see {@link useTotalLatency}).
|
|
27
|
+
*/
|
|
28
|
+
const STOPWATCH_TICK_MS = 250;
|
|
29
|
+
|
|
30
|
+
/** What {@link useTotalLatency} reports. */
|
|
31
|
+
export type TotalLatency = {
|
|
32
|
+
/**
|
|
33
|
+
* The mark the clock started at, or undefined before the first submit.
|
|
34
|
+
*
|
|
35
|
+
* The raw mark rather than an elapsed duration, and that is the load-bearing
|
|
36
|
+
* part: an elapsed number is stale the instant it is computed, so a page
|
|
37
|
+
* holding one has to re-render to keep it true — which is what used to drive
|
|
38
|
+
* the whole tree at 4 Hz. {@link TotalLatency} turns these two marks into a
|
|
39
|
+
* duration, and only that section re-renders.
|
|
40
|
+
*/
|
|
41
|
+
startedAt: number | undefined;
|
|
42
|
+
/** The elapsed time at the moment the run settled, once it has. */
|
|
43
|
+
frozenMs: number | undefined;
|
|
44
|
+
/** Start (or restart) the clock. Called from the form's own submit handler. */
|
|
45
|
+
start: () => void;
|
|
46
|
+
/** Drop it, for a panel that no longer describes the submission it timed. */
|
|
47
|
+
clear: () => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Wall clock from the submit to the finish, across both waits.
|
|
52
|
+
*
|
|
53
|
+
* `inFlight` is the submission's own `pending` — true from `submit()` until the run
|
|
54
|
+
* reaches a terminal status — so the clock covers the upload, the run, and the
|
|
55
|
+
* gap between them, which is the whole of what a reader waits for and is the one
|
|
56
|
+
* measurement no server-side number can make.
|
|
57
|
+
*
|
|
58
|
+
* Two details it would be easy to get wrong:
|
|
59
|
+
*
|
|
60
|
+
* - **The interval re-renders; it does not accumulate.** The elapsed time is read
|
|
61
|
+
* from the clock at render, so a tick the tab throttled or dropped cannot make
|
|
62
|
+
* the number lag behind real time. The interval lives in {@link TotalLatency}
|
|
63
|
+
* rather than here, because a hook called from the page makes its ticks the
|
|
64
|
+
* PAGE's re-renders — the form, the upload bar, the run panel and the whole
|
|
65
|
+
* history list, four times a second, to move one duration string.
|
|
66
|
+
* - **`performance.now()`, not `Date.now()`.** It is monotonic, so a clock
|
|
67
|
+
* correction (NTP, a laptop waking up) cannot make a transcription look
|
|
68
|
+
* instant — or negative.
|
|
69
|
+
*/
|
|
70
|
+
export function useTotalLatency(inFlight: boolean): TotalLatency {
|
|
71
|
+
const [startedAt, setStartedAt] = useState<number | undefined>(undefined);
|
|
72
|
+
const [frozenMs, setFrozenMs] = useState<number | undefined>(undefined);
|
|
73
|
+
// Whether `inFlight` has been seen true since the last `start()`. Without it,
|
|
74
|
+
// a start that lands one render before the submission reports itself in flight
|
|
75
|
+
// would freeze the clock at zero instead of running it.
|
|
76
|
+
const began = useRef(false);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (startedAt === undefined || frozenMs !== undefined) return;
|
|
80
|
+
if (inFlight) {
|
|
81
|
+
began.current = true;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Measured here rather than at render, so the frozen number is the one at the
|
|
85
|
+
// moment the run settled rather than whenever this page next drew.
|
|
86
|
+
if (began.current) setFrozenMs(performance.now() - startedAt);
|
|
87
|
+
}, [startedAt, frozenMs, inFlight]);
|
|
88
|
+
|
|
89
|
+
const start = useCallback(() => {
|
|
90
|
+
began.current = false;
|
|
91
|
+
setFrozenMs(undefined);
|
|
92
|
+
setStartedAt(performance.now());
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const clear = useCallback(() => {
|
|
96
|
+
began.current = false;
|
|
97
|
+
setStartedAt(undefined);
|
|
98
|
+
setFrozenMs(undefined);
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
startedAt,
|
|
103
|
+
frozenMs,
|
|
104
|
+
start,
|
|
105
|
+
clear,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The one number the two bars cannot give: click to transcript.
|
|
111
|
+
*
|
|
112
|
+
* Rendered above the run panel rather than inside it, because the stretch it
|
|
113
|
+
* covers starts before there IS a run — in two of the three modes the run does
|
|
114
|
+
* not exist until the upload finishes, so a clock living in the panel would
|
|
115
|
+
* appear only after the wait it is supposed to be timing.
|
|
116
|
+
*
|
|
117
|
+
* `runMs` is the run's own elapsed, once it reports one. The remainder is
|
|
118
|
+
* everything the run could not see: storing the file (or, in streaming mode,
|
|
119
|
+
* minting the upload id), the `POST` that starts the run, and the poll that
|
|
120
|
+
* notices it finished. Clamped at zero, because the two numbers come from two
|
|
121
|
+
* different clocks on two different machines and a few milliseconds the wrong way
|
|
122
|
+
* would otherwise print a negative.
|
|
123
|
+
*
|
|
124
|
+
* The stopwatch interval lives HERE rather than in {@link useTotalLatency}, so a
|
|
125
|
+
* running clock re-renders this section and nothing else.
|
|
126
|
+
*/
|
|
127
|
+
export function TotalLatency({
|
|
128
|
+
startedAt,
|
|
129
|
+
frozenMs,
|
|
130
|
+
runMs,
|
|
131
|
+
}: {
|
|
132
|
+
startedAt: number | undefined;
|
|
133
|
+
frozenMs: number | undefined;
|
|
134
|
+
runMs: number | undefined;
|
|
135
|
+
}) {
|
|
136
|
+
// Re-render trigger only: the elapsed time is read from the clock below, so a
|
|
137
|
+
// tick the tab throttled or dropped cannot make the number lag real time.
|
|
138
|
+
const [, tick] = useState(0);
|
|
139
|
+
const running = startedAt !== undefined && frozenMs === undefined;
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!running) return;
|
|
142
|
+
const id = setInterval(() => tick((n) => n + 1), STOPWATCH_TICK_MS);
|
|
143
|
+
return () => clearInterval(id);
|
|
144
|
+
}, [running]);
|
|
145
|
+
|
|
146
|
+
if (startedAt === undefined) return null;
|
|
147
|
+
const elapsedMs = frozenMs ?? performance.now() - startedAt;
|
|
148
|
+
const outside = runMs === undefined ? undefined : Math.max(0, elapsedMs - runMs);
|
|
149
|
+
return (
|
|
150
|
+
<section className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 rounded-md border px-5 py-3">
|
|
151
|
+
<h2 className="text-sm font-medium uppercase tracking-[1.2px]">
|
|
152
|
+
{running ? "Elapsed" : "Total latency"}
|
|
153
|
+
</h2>
|
|
154
|
+
<span className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
|
155
|
+
<span className="text-sm tabular-nums">{formatDuration(elapsedMs)}</span>
|
|
156
|
+
{runMs !== undefined && outside !== undefined && (
|
|
157
|
+
<Facts
|
|
158
|
+
size="xs"
|
|
159
|
+
as="span"
|
|
160
|
+
className="tabular-nums"
|
|
161
|
+
items={[
|
|
162
|
+
`${formatDuration(outside)} before the run`,
|
|
163
|
+
`${formatDuration(runMs)} inside it`,
|
|
164
|
+
]}
|
|
165
|
+
/>
|
|
166
|
+
)}
|
|
167
|
+
</span>
|
|
168
|
+
</section>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Copyright 2026 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* The third desk: hand the whole recording to AssemblyAI's ASYNC API and wait.
|
|
4
|
+
*
|
|
5
|
+
* The other two flows exist because of one provider limit: the SYNC endpoint answers
|
|
6
|
+
* inside the request and pays for it with a hard 120-second, 40 MB cap, so a long
|
|
7
|
+
* recording has to be cut up and fanned out — and this template's whole subject is
|
|
8
|
+
* the two ways to arrange that. The async API has no such cap. You submit a job, it
|
|
9
|
+
* answers with an id in milliseconds, and the transcript is ready minutes later.
|
|
10
|
+
*
|
|
11
|
+
* So this flow is three steps and no arithmetic:
|
|
12
|
+
*
|
|
13
|
+
* ```text
|
|
14
|
+
* uploadToProvider one step → the file, streamed, and the URL it answered
|
|
15
|
+
* createJob one step → the transcript id
|
|
16
|
+
* pollTranscript one step + a durable sleep, until the text comes back
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* **It is here to be compared against the other two, and it usually wins.** No
|
|
20
|
+
* segment planning, no seam stitching, no concurrency to tune, no WAV-only
|
|
21
|
+
* restriction — the provider accepts compressed audio, so an m4a straight off a
|
|
22
|
+
* phone works where both sync flows refuse it. What you give up is control of the
|
|
23
|
+
* inside: the latency is the provider's queue rather than your fan-out, and there is
|
|
24
|
+
* nothing to report between "submitted" and "done" except the job's own status.
|
|
25
|
+
*
|
|
26
|
+
* ## The endpoint is the SDK's; the STEPS are ours
|
|
27
|
+
*
|
|
28
|
+
* `stepTranscribeUpload` / `stepTranscribeSubmit` / `stepTranscribePoll` on
|
|
29
|
+
* `@alexkroman1/aai/step` own the URL, the raw-key auth, the windowed streaming
|
|
30
|
+
* upload, the PLURAL `speech_models` field and the failure classification. This file
|
|
31
|
+
* used to spell all of that out, and so did `spoken-summary-workflow` — the same ~200 lines
|
|
32
|
+
* twice, reworded, identical in behaviour, and drifting apart at the edges.
|
|
33
|
+
*
|
|
34
|
+
* What stays here is what a dependency cannot decide: how many steps to cut the job
|
|
35
|
+
* into, and therefore what is journaled and what a retry repeats. That is also
|
|
36
|
+
* structural rather than stylistic — only the caller with a `ctx` can open a
|
|
37
|
+
* step, so a step boundary shipped inside the SDK would be no boundary at all:
|
|
38
|
+
* it would run inline, with no journal and no retry, silently.
|
|
39
|
+
*
|
|
40
|
+
* ## The one thing that makes this a WORKFLOW rather than a request
|
|
41
|
+
*
|
|
42
|
+
* The wait. A job takes minutes, and nothing about an HTTP request survives minutes:
|
|
43
|
+
* the poll has to outlive the process that started it, which is exactly what a
|
|
44
|
+
* durable `sleep` is. `meeting-recap-agent` ports Temporal's `polling` sample for this
|
|
45
|
+
* shape and its module doc carries the argument; this is the same pattern with the
|
|
46
|
+
* poll bounded by attempts rather than by a deadline.
|
|
47
|
+
*
|
|
48
|
+
* ## Three steps, not four, and the fourth was a wasted round trip
|
|
49
|
+
*
|
|
50
|
+
* This used to poll `GET /v2/transcript/:id` for a status and then fetch the
|
|
51
|
+
* identical URL a second time to read the text the poll already had in its hand.
|
|
52
|
+
* {@link pollTranscript} answers with the transcript, so a finished job costs one
|
|
53
|
+
* request rather than two and the value journaled by the last poll IS the result.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
import type { WorkflowContext } from "@alexkroman1/aai";
|
|
57
|
+
import {
|
|
58
|
+
stepReport,
|
|
59
|
+
stepTranscribePoll,
|
|
60
|
+
stepTranscribeSubmit,
|
|
61
|
+
stepTranscribeUpload,
|
|
62
|
+
stepUploadInfo,
|
|
63
|
+
TRANSCRIBE_API,
|
|
64
|
+
} from "@alexkroman1/aai/step";
|
|
65
|
+
import { orFail } from "@alexkroman1/aai/step-errors";
|
|
66
|
+
import { countWords, formatBytes } from "@alexkroman1/aai/utils";
|
|
67
|
+
import type { Transcript } from "./transcribe.ts";
|
|
68
|
+
|
|
69
|
+
/** How long between polls of a submitted job. */
|
|
70
|
+
const POLL_INTERVAL_MS = 10_000;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Polls before the run gives up on a job.
|
|
74
|
+
*
|
|
75
|
+
* At {@link POLL_INTERVAL_MS} this is an hour, well past what the async API takes for
|
|
76
|
+
* any recording it accepts. Bounded rather than endless because a job that never
|
|
77
|
+
* leaves `queued` is a run that would otherwise be replayed forever.
|
|
78
|
+
*/
|
|
79
|
+
const MAX_POLLS = 360;
|
|
80
|
+
|
|
81
|
+
/** Transcribe a recording through the async API. */
|
|
82
|
+
export async function transcribeBatchFlow(
|
|
83
|
+
input: { recording: string },
|
|
84
|
+
ctx: WorkflowContext,
|
|
85
|
+
): Promise<Transcript> {
|
|
86
|
+
// Both at once: the clock does not depend on the upload, and issuing them
|
|
87
|
+
// together costs one round trip instead of two before a byte moves. Their issue
|
|
88
|
+
// order is still decided by this line rather than by which lands first.
|
|
89
|
+
// `maxAttempts: 6` was `uploadToProvider.maxRetries = 5` — five retries after
|
|
90
|
+
// the first, so six in all. More than the default 3 because an upload is the
|
|
91
|
+
// one call here worth another attempt: it moves the whole recording, and a lost
|
|
92
|
+
// connection on a file this size is the expected failure.
|
|
93
|
+
const [startedAt, { audioUrl }] = await Promise.all([
|
|
94
|
+
ctx.now(),
|
|
95
|
+
ctx.step("uploadToProvider", () => uploadToProvider(input.recording), { maxAttempts: 6 }),
|
|
96
|
+
]);
|
|
97
|
+
const job = await ctx.step("createJob", () => createJob(audioUrl));
|
|
98
|
+
|
|
99
|
+
for (let poll = 0; poll < MAX_POLLS; poll += 1) {
|
|
100
|
+
const progress = await ctx.step("pollTranscript", () =>
|
|
101
|
+
pollTranscript(input.recording, job.id, startedAt),
|
|
102
|
+
);
|
|
103
|
+
if (progress.done) return progress.transcript;
|
|
104
|
+
await ctx.sleep("poll", POLL_INTERVAL_MS);
|
|
105
|
+
}
|
|
106
|
+
// A plain throw: this is the BODY, where the fatal/retryable distinction has
|
|
107
|
+
// nothing to apply to — see `stream.ts`'s `abandon` for the same reasoning.
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Transcript ${job.id} was still unfinished after ${MAX_POLLS} polls. It is not lost — ` +
|
|
110
|
+
`read it directly with GET ${TRANSCRIBE_API}/v2/transcript/${job.id}.`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Upload the recording to the provider and answer with the URL it gave.
|
|
116
|
+
*
|
|
117
|
+
* Its own step, and that was a MEASUREMENT rather than a judgement. It began as one
|
|
118
|
+
* step doing both calls, on the argument that an `upload_url` is useless alone and
|
|
119
|
+
* expires — and the first live run showed what that costs: the create call failed on
|
|
120
|
+
* a deprecated field, and the DevKit retried the whole step five times, re-uploading
|
|
121
|
+
* 24 MB on every attempt for a fault in a JSON body. A retry that repeats the
|
|
122
|
+
* expensive half to fix the cheap half is not a retry.
|
|
123
|
+
*
|
|
124
|
+
* So the URL is journaled after all. The risk that made that look wrong is real but
|
|
125
|
+
* far smaller: if it expires before the next step runs, the run fails and a fresh one
|
|
126
|
+
* re-uploads — which is what would have happened anyway, once, instead of five times.
|
|
127
|
+
*
|
|
128
|
+
* The `OrFail` callers on `@alexkroman1/aai/step-errors` are the SDK's own
|
|
129
|
+
* `stepTranscribe*` plus `throwStepError` and nothing else, which is what turns the
|
|
130
|
+
* SDK's `TranscribeError` into the DevKit's verdict: a missing key and a 400 stop, a
|
|
131
|
+
* 429 waits as long as the service asked. Every step here ends the same way for the
|
|
132
|
+
* same reason.
|
|
133
|
+
*/
|
|
134
|
+
export async function uploadToProvider(uploadId: string): Promise<{ audioUrl: string }> {
|
|
135
|
+
const stored = await stepUploadInfo(uploadId);
|
|
136
|
+
await stepReport(
|
|
137
|
+
`Uploading ${stored.name || uploadId} (${formatBytes(stored.size)}) to the async API.`,
|
|
138
|
+
);
|
|
139
|
+
return await orFail(stepTranscribeUpload)(uploadId);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Create the transcription job, and answer with the id that outlives this run. */
|
|
143
|
+
export async function createJob(audioUrl: string): Promise<{ id: string }> {
|
|
144
|
+
const job = await orFail(stepTranscribeSubmit)(audioUrl);
|
|
145
|
+
await stepReport(`Submitted — job ${job.id}.`);
|
|
146
|
+
return job;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Ask once whether the job has finished, and read it when it has.
|
|
151
|
+
*
|
|
152
|
+
* `done` rather than the raw status, because the BODY branches on it and a body must
|
|
153
|
+
* not be where a provider's vocabulary is interpreted — a new status string would
|
|
154
|
+
* otherwise read as "not done yet" forever. A failed job is a terminal failure
|
|
155
|
+
* inside the SDK call, not a `done: true` the caller has to re-check.
|
|
156
|
+
*/
|
|
157
|
+
export async function pollTranscript(
|
|
158
|
+
uploadId: string,
|
|
159
|
+
id: string,
|
|
160
|
+
startedAt: number,
|
|
161
|
+
): Promise<{ done: false } | { done: true; transcript: Transcript }> {
|
|
162
|
+
const progress = await orFail(stepTranscribePoll)(id);
|
|
163
|
+
if (!progress.done) {
|
|
164
|
+
await stepReport(`Transcript ${id} is ${progress.status}.`);
|
|
165
|
+
return { done: false };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const stored = await stepUploadInfo(uploadId);
|
|
169
|
+
const transcript = progress.transcript.text;
|
|
170
|
+
return {
|
|
171
|
+
done: true,
|
|
172
|
+
transcript: {
|
|
173
|
+
source: stored.name || uploadId,
|
|
174
|
+
// ONE, and it is not a fudge: the async API transcribed the recording in one
|
|
175
|
+
// piece, which is the difference this flow is here to show. A reader comparing
|
|
176
|
+
// the three sees 7 segments, 7 segments, and 1.
|
|
177
|
+
segments: 1,
|
|
178
|
+
// The provider's own measurement — the only one of the three flows that does
|
|
179
|
+
// not have to derive this from byte offsets.
|
|
180
|
+
durationMs: progress.transcript.durationMs,
|
|
181
|
+
// Wall clock, the same way both sync flows measure it — the body's
|
|
182
|
+
// `ctx.now()`, subtracted inside this step. For this flow it is mostly the
|
|
183
|
+
// provider's queue, which is exactly the thing a reader wants to see.
|
|
184
|
+
elapsedMs: Date.now() - startedAt,
|
|
185
|
+
words: countWords(transcript),
|
|
186
|
+
transcript,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// Copyright 2026 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Making one REQUEST light, where `normalize.ts` makes the whole FILE cuttable.
|
|
4
|
+
*
|
|
5
|
+
* The two look like the same job and are not, and the difference is the reason
|
|
6
|
+
* this module exists at all:
|
|
7
|
+
*
|
|
8
|
+
* | | `normalize.ts` | this |
|
|
9
|
+
* | --- | --- | --- |
|
|
10
|
+
* | fixes | a recording the desk cannot CUT | a request the endpoint cannot FINISH |
|
|
11
|
+
* | works on | the whole file, via ffmpeg | one segment's bytes, in process |
|
|
12
|
+
* | needs | every byte to have arrived | only the segment's own window |
|
|
13
|
+
* | produces | a new upload | a request body, thrown away after |
|
|
14
|
+
*
|
|
15
|
+
* `normalizeRecording` reads the entire recording out of the store, runs ffmpeg
|
|
16
|
+
* over it and writes a second upload back. That is exactly right for the classic
|
|
17
|
+
* flow, and it is unavailable to the streaming one by construction: a file that
|
|
18
|
+
* is still arriving is not a file ffmpeg can transcode, and waiting for the last
|
|
19
|
+
* byte before converting would give up the whole property `stream.ts` exists to
|
|
20
|
+
* demonstrate. So the streaming desk needs the byte saving WITHOUT the whole-file
|
|
21
|
+
* pass, and a segment it has already cut is linear PCM it can resample itself.
|
|
22
|
+
*
|
|
23
|
+
* ## Why it is worth doing at all
|
|
24
|
+
*
|
|
25
|
+
* The sync endpoint deadlines a request at **30 seconds**, wall clock, and that
|
|
26
|
+
* budget covers the upload as well as the transcription. A 92-second segment of
|
|
27
|
+
* 48 kHz 16-bit stereo is **17.66 MB**; the same audio at
|
|
28
|
+
* {@link NORMALIZED_SAMPLE_RATE} mono is **2.94 MB**. Six times the bytes per
|
|
29
|
+
* request, against a fixed deadline, is not a slower run — it is a run that dies:
|
|
30
|
+
*
|
|
31
|
+
* ```text
|
|
32
|
+
* HTTP 504 — request exceeded 30.0s
|
|
33
|
+
* sync.assemblyai.com did not answer: ConnectTimeoutError (timeout: 10000ms)
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Both of those are from one real 50-minute stereo recording, where half the
|
|
37
|
+
* segments landed and three burned all six attempts. A 504 is transient, so every
|
|
38
|
+
* one of them is retried the full six times before the body throws — and when it
|
|
39
|
+
* does, every sibling still in flight is discarded and re-billed on the resume.
|
|
40
|
+
*
|
|
41
|
+
* ## It is a BOX FILTER, and that is a real trade
|
|
42
|
+
*
|
|
43
|
+
* Averaging each output frame's window of input frames is a low-pass filter and a
|
|
44
|
+
* decimation in one pass, which is the cheap end of resampling. It is genuinely
|
|
45
|
+
* better than taking every Nth sample — that folds everything above the new
|
|
46
|
+
* Nyquist straight back into the speech band — but it is not what ffmpeg's
|
|
47
|
+
* `swr` does, and at 48 kHz -> 16 kHz it attenuates the top of the kept band by
|
|
48
|
+
* about a third and leaves the first alias image around -12 dB.
|
|
49
|
+
*
|
|
50
|
+
* That is the honest cost, and the classic flow does not pay it: `normalize.ts`
|
|
51
|
+
* has the whole file and uses ffmpeg. This is the streaming flow's option,
|
|
52
|
+
* chosen because 8 kHz of slightly soft speech transcribes and a request that
|
|
53
|
+
* never finishes does not. A desk that cares more about the top octave than
|
|
54
|
+
* about the tail latency should run the classic flow.
|
|
55
|
+
*
|
|
56
|
+
* ## Pure, and deliberately so
|
|
57
|
+
*
|
|
58
|
+
* Nothing here reaches a `node:` builtin or an SDK subpath that does. `stream.ts`
|
|
59
|
+
* is compiled as a `node:vm` Script with no `require` (see `normalize.ts`'s module
|
|
60
|
+
* doc), so a module it imports at module scope may not drag one in — which is why
|
|
61
|
+
* the normalize TARGETS live here, the pure module, and `normalize.ts` imports
|
|
62
|
+
* them rather than the other way round.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
import type { PcmFormat } from "@alexkroman1/aai/step";
|
|
66
|
+
import { blockAlign, UnsupportedRecordingError, type WavFormat } from "./wav.ts";
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The rate everything is converted TO.
|
|
70
|
+
*
|
|
71
|
+
* 16 kHz because that is what speech models are trained at — a higher rate
|
|
72
|
+
* carries no information the decoder uses and costs proportional bytes in a
|
|
73
|
+
* fan-out whose width is bounded by bytes in flight (`BYTES_IN_FLIGHT` in
|
|
74
|
+
* `transcribe.ts`) and whose requests are bounded by a 30-second deadline. A
|
|
75
|
+
* converted two-hour recording is 230 MB of 16 kHz mono against 1.4 GB of
|
|
76
|
+
* 48 kHz stereo, which is the difference between a fan-out that saturates on
|
|
77
|
+
* width and one that saturates on the queue.
|
|
78
|
+
*/
|
|
79
|
+
export const NORMALIZED_SAMPLE_RATE = 16_000;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Channels everything is converted TO.
|
|
83
|
+
*
|
|
84
|
+
* Mono, and it is a real loss rather than a free win: a stereo call recording
|
|
85
|
+
* with one party per channel is exactly the file where the channels are the most
|
|
86
|
+
* interesting thing about it, and downmixing throws that away. This desk
|
|
87
|
+
* transcribes rather than diarizes, so it takes the 2x saving; a desk that wants
|
|
88
|
+
* the speakers apart splits the channels first and transcribes each one.
|
|
89
|
+
*/
|
|
90
|
+
export const NORMALIZED_CHANNELS = 1;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Whether sending this format AS IS would make every request too heavy.
|
|
94
|
+
*
|
|
95
|
+
* The format-level half of `normalize.ts`'s `heavierThanNormalized`, which asks
|
|
96
|
+
* the same question of an unparsed header. Both are here rather than there
|
|
97
|
+
* because the streaming flow answers it from a format it already has and must
|
|
98
|
+
* not import a module that reaches ffmpeg.
|
|
99
|
+
*
|
|
100
|
+
* Compared against the normalize targets rather than against a byte budget of
|
|
101
|
+
* its own: the question is literally "would converting make this smaller", and
|
|
102
|
+
* anything at or below {@link NORMALIZED_SAMPLE_RATE} /
|
|
103
|
+
* {@link NORMALIZED_CHANNELS} would only be re-encoded into itself.
|
|
104
|
+
*
|
|
105
|
+
* It deliberately does NOT look at `bitsPerSample`, matching the whole-file
|
|
106
|
+
* predicate so the two flows cannot disagree about which files are heavy. A
|
|
107
|
+
* 24-bit file at 16 kHz mono really would shrink, but that is a 1.5-2x saving
|
|
108
|
+
* on a file already inside the budget.
|
|
109
|
+
*/
|
|
110
|
+
export function heavierThanNormalizedFormat(
|
|
111
|
+
format: Pick<WavFormat, "sampleRate" | "channels">,
|
|
112
|
+
): boolean {
|
|
113
|
+
return format.sampleRate > NORMALIZED_SAMPLE_RATE || format.channels > NORMALIZED_CHANNELS;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* One segment's PCM, resampled to something the endpoint can swallow in 30s.
|
|
118
|
+
*
|
|
119
|
+
* Returns the input UNCHANGED when it is already light — same array, same
|
|
120
|
+
* format, no copy — so this is inert on the classic flow, where
|
|
121
|
+
* `normalizeRecording` has already converted the whole file, and on any
|
|
122
|
+
* recording that arrived at 16 kHz mono to begin with. That inertness is what
|
|
123
|
+
* lets `transcribeSegment` call it unconditionally and both flows share the one
|
|
124
|
+
* step.
|
|
125
|
+
*
|
|
126
|
+
* @param bytes - The segment's window, interleaved little-endian linear PCM.
|
|
127
|
+
* A ragged tail is truncated to whole frames: `dataEnd` is clamped to the
|
|
128
|
+
* file's real size, which no recorder guarantees is frame-aligned.
|
|
129
|
+
* @param from - The recording's format, from `parseWav`.
|
|
130
|
+
*
|
|
131
|
+
* @returns The bytes to send and the format to write a header with — always
|
|
132
|
+
* 16-bit mono once anything was done, because there is one output path and a
|
|
133
|
+
* narrower one saves nothing worth a second.
|
|
134
|
+
*
|
|
135
|
+
* @throws {UnsupportedRecordingError} for a bit depth `parseWav` admits and this
|
|
136
|
+
* cannot serve, and for a window holding no whole frame. Both are checked
|
|
137
|
+
* BEFORE the fast path, so the LIGHT path answers them too — see the two
|
|
138
|
+
* guards below. Terminal, which is right: each answers the same way forever.
|
|
139
|
+
*/
|
|
140
|
+
export function downsampleSegment(
|
|
141
|
+
bytes: Uint8Array,
|
|
142
|
+
from: Pick<WavFormat, "sampleRate" | "channels" | "bitsPerSample">,
|
|
143
|
+
): { bytes: Uint8Array; format: PcmFormat } {
|
|
144
|
+
// Both guards run before the fast path, and that is the fix rather than an
|
|
145
|
+
// ordering preference: they ask what can be SENT, which the light path does
|
|
146
|
+
// as much as the heavy one. Hung off the resampler they only ever ran when
|
|
147
|
+
// there was resampling to do, so a recording already at 16 kHz mono took the
|
|
148
|
+
// identity path below with its samples never once looked at — and a 12-bit
|
|
149
|
+
// one then died in `encodeWav` on an UNCLASSIFIED `RangeError`, worth six
|
|
150
|
+
// attempts against a file no attempt can fix, while a 64-bit one passed that
|
|
151
|
+
// check and went on the wire mislabelled.
|
|
152
|
+
const bind = sampleReaderFor(from);
|
|
153
|
+
const frame = blockAlign(from);
|
|
154
|
+
const inFrames = Math.floor(bytes.length / frame);
|
|
155
|
+
// A CALLER ERROR, and stated as one. `stepReadUpload` clamps a window to what is
|
|
156
|
+
// stored, so the streaming flow can hand a short read down here; with no whole
|
|
157
|
+
// frame the averaging window below is zero wide, `total / 0` is `NaN`, and
|
|
158
|
+
// `setInt16` writes that as a 0 — a two-byte WAV of silence, transcribed and
|
|
159
|
+
// reported as if it were audio. There is no honest empty result to return
|
|
160
|
+
// either: the endpoint is being asked to decode nothing.
|
|
161
|
+
if (inFrames === 0) {
|
|
162
|
+
throw new UnsupportedRecordingError(
|
|
163
|
+
`That segment holds ${bytes.length} byte(s), which is under one ${frame}-byte frame — ` +
|
|
164
|
+
"there is no audio in it to transcribe.",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const format = requestFormat(from);
|
|
169
|
+
if (format === from) return { bytes, format };
|
|
170
|
+
|
|
171
|
+
const ratio = from.sampleRate / format.sampleRate;
|
|
172
|
+
const outFrames = Math.max(1, Math.floor(inFrames / ratio));
|
|
173
|
+
|
|
174
|
+
const read = bind(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength));
|
|
175
|
+
const out = new Uint8Array(outFrames * 2);
|
|
176
|
+
const wrote = new DataView(out.buffer);
|
|
177
|
+
const sampleBytes = from.bitsPerSample / 8;
|
|
178
|
+
|
|
179
|
+
for (let i = 0; i < outFrames; i++) {
|
|
180
|
+
// The window this output frame averages. Half-open, at least one frame wide
|
|
181
|
+
// however the ratio divides — a zero-wide window is a division by zero, and
|
|
182
|
+
// a non-integer ratio (44.1 kHz -> 16 kHz is 2.75625) produces windows of
|
|
183
|
+
// two different widths, which is the box filter tracking the true rate
|
|
184
|
+
// rather than drifting off it.
|
|
185
|
+
const lo = Math.floor(i * ratio);
|
|
186
|
+
const hi = Math.min(inFrames, Math.max(lo + 1, Math.floor((i + 1) * ratio)));
|
|
187
|
+
|
|
188
|
+
// Every channel of every frame in the window, in one accumulator: the
|
|
189
|
+
// low-pass and the downmix are the same average, so doing them separately
|
|
190
|
+
// would be two passes for one answer.
|
|
191
|
+
let total = 0;
|
|
192
|
+
for (let f = lo; f < hi; f++) {
|
|
193
|
+
const at = f * frame;
|
|
194
|
+
for (let c = 0; c < from.channels; c++) total += read(at + c * sampleBytes);
|
|
195
|
+
}
|
|
196
|
+
// No clamp: an average of values already inside the 16-bit range is inside
|
|
197
|
+
// it, and `Math.round` cannot carry one out.
|
|
198
|
+
wrote.setInt16(i * 2, Math.round(total / ((hi - lo) * from.channels)), true);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return { bytes: out, format };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The format that will go ON THE WIRE for a recording in `from`.
|
|
206
|
+
*
|
|
207
|
+
* Returns `from` ITSELF — identity, not a copy — when nothing needs doing, which
|
|
208
|
+
* is what {@link downsampleSegment} tests to take its fast path. That identity is
|
|
209
|
+
* load-bearing rather than an optimisation: the alternative is two places deciding
|
|
210
|
+
* "is this heavy" and the resampler disagreeing with the fast path about one
|
|
211
|
+
* edge case.
|
|
212
|
+
*
|
|
213
|
+
* Exported because `segmentConcurrency` (`transcribe.ts`) divides a byte budget by
|
|
214
|
+
* a segment's cost, and that budget is bytes UPLOADING — so it has to be asked of
|
|
215
|
+
* what is SENT rather than of what was cut. Deriving both from this is what stops
|
|
216
|
+
* the width and the resampler drifting apart.
|
|
217
|
+
*/
|
|
218
|
+
export function requestFormat(
|
|
219
|
+
from: Pick<WavFormat, "sampleRate" | "channels" | "bitsPerSample">,
|
|
220
|
+
): Pick<WavFormat, "sampleRate" | "channels" | "bitsPerSample"> {
|
|
221
|
+
if (!heavierThanNormalizedFormat(from)) return from;
|
|
222
|
+
return {
|
|
223
|
+
// Never UP. An 8 kHz stereo recording needs the downmix and not the rate, and
|
|
224
|
+
// resampling it to 16 kHz would invent bytes to pay a deadline with.
|
|
225
|
+
sampleRate: Math.min(from.sampleRate, NORMALIZED_SAMPLE_RATE),
|
|
226
|
+
channels: NORMALIZED_CHANNELS,
|
|
227
|
+
bitsPerSample: 16,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* How to read one sample of this format, as a number on the 16-bit scale.
|
|
233
|
+
*
|
|
234
|
+
* Chosen ONCE rather than switched per sample: a 92-second stereo segment is
|
|
235
|
+
* 8.8 million frames, so the branch is the difference between a closure call and
|
|
236
|
+
* a jump table 17.6 million times over.
|
|
237
|
+
*
|
|
238
|
+
* TWO stages, and the split is what lets one switch serve both paths. The depth
|
|
239
|
+
* is settled here — including the REFUSAL — and the view is bound after, because
|
|
240
|
+
* a light-path call has no view to bind and still owes that refusal: the four
|
|
241
|
+
* depths this can read are also the four the request can carry, since `encodeWav`
|
|
242
|
+
* rejects anything that is not a whole number of bytes and the endpoint decodes
|
|
243
|
+
* what the header describes.
|
|
244
|
+
*
|
|
245
|
+
* `parseWav` admits only `WAVE_FORMAT_PCM`, so every depth here is a signed
|
|
246
|
+
* little-endian integer — except 8-bit, which RIFF specifies as UNSIGNED and
|
|
247
|
+
* centred on 128. That asymmetry is the one thing in this function worth
|
|
248
|
+
* knowing; reading an 8-bit file as signed is a transcript of loud static.
|
|
249
|
+
*/
|
|
250
|
+
function sampleReaderFor(
|
|
251
|
+
from: Pick<WavFormat, "bitsPerSample">,
|
|
252
|
+
): (view: DataView) => (at: number) => number {
|
|
253
|
+
switch (from.bitsPerSample) {
|
|
254
|
+
case 8:
|
|
255
|
+
return (view) => (at) => (view.getUint8(at) - 128) * 256;
|
|
256
|
+
case 16:
|
|
257
|
+
return (view) => (at) => view.getInt16(at, true);
|
|
258
|
+
case 24:
|
|
259
|
+
// `getInt8` on the top byte is what sign-extends: the low two are read
|
|
260
|
+
// unsigned and OR'd under it, then the whole thing is shifted down to the
|
|
261
|
+
// 16-bit scale by an ARITHMETIC shift, which preserves that sign.
|
|
262
|
+
return (view) => (at) =>
|
|
263
|
+
(view.getUint8(at) | (view.getUint8(at + 1) << 8) | (view.getInt8(at + 2) << 16)) >> 8;
|
|
264
|
+
case 32:
|
|
265
|
+
return (view) => (at) => view.getInt32(at, true) >> 16;
|
|
266
|
+
default:
|
|
267
|
+
throw new UnsupportedRecordingError(
|
|
268
|
+
`That WAV holds ${from.bitsPerSample}-bit samples, which this desk can cut but cannot ` +
|
|
269
|
+
"send: a request carries 8-, 16-, 24- or 32-bit linear PCM. Re-encode it with " +
|
|
270
|
+
"`-c:a pcm_s16le`.",
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|