@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,1032 @@
|
|
|
1
|
+
// Copyright 2026 the AAI authors. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Specs for the audit desk's declaration, its ffmpeg argv, the two analyses it
|
|
4
|
+
* reads back, and where it decides to cut.
|
|
5
|
+
*
|
|
6
|
+
* **The pipeline is not driven end to end here, and that is the tier rather than
|
|
7
|
+
* a gap.** A unit test may not spawn a subprocess or write a file, so the three
|
|
8
|
+
* steps that run ffmpeg cannot be. What CAN be — and what this file therefore
|
|
9
|
+
* spends most of its lines on — is everything those steps decide, because
|
|
10
|
+
* `media.ts` exists precisely to hold it: the argv is a pure function, so it is a
|
|
11
|
+
* value to assert on rather than a string buried in a step; and both analyses are
|
|
12
|
+
* parsed by pure functions, so ffmpeg's real output can be a fixture.
|
|
13
|
+
*
|
|
14
|
+
* The fixtures below are **captured from ffmpeg 6.1.1**, verbatim, by running the
|
|
15
|
+
* argv these functions build. That matters more than it usually would: every field
|
|
16
|
+
* here is a string ffmpeg chose (`"input_i" : "-16.19"`, tabs and spaces included),
|
|
17
|
+
* so a fixture somebody typed from the documentation would be a spec that passes
|
|
18
|
+
* against a parser no real recording can satisfy.
|
|
19
|
+
*
|
|
20
|
+
* What the ffmpeg steps get instead is the two things a spec can still reach: the
|
|
21
|
+
* argv they will run, and the classification of a failure — which is where a
|
|
22
|
+
* mistake is silent, since a `timeout` called fatal is a run that gives up on work
|
|
23
|
+
* that would have finished.
|
|
24
|
+
*
|
|
25
|
+
* The last block adds a third: the ENGINE's half of that classification, on a
|
|
26
|
+
* real run. `runWorkflow` starts this desk's declared workflow on the replay
|
|
27
|
+
* engine, and with no ffmpeg the first step fails fatally — which is exactly the
|
|
28
|
+
* case worth asserting, because `FatalError` exists to stop the engine spending
|
|
29
|
+
* the six attempts this call site asks for on a file that will never convert.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { readdir } from "node:fs/promises";
|
|
33
|
+
import { tmpdir } from "node:os";
|
|
34
|
+
import { FatalError, RetryableError } from "@alexkroman1/aai/step-errors";
|
|
35
|
+
import {
|
|
36
|
+
createWorkflowContext,
|
|
37
|
+
runWorkflow,
|
|
38
|
+
stubSpeech,
|
|
39
|
+
WORKFLOW_CONTEXT_NOW,
|
|
40
|
+
} from "@alexkroman1/aai-runtime/testing";
|
|
41
|
+
import {
|
|
42
|
+
installStubGateway,
|
|
43
|
+
installStubReporter,
|
|
44
|
+
installStubSpeech,
|
|
45
|
+
installStubTranscribe,
|
|
46
|
+
installStubUploads,
|
|
47
|
+
} from "@alexkroman1/aai-runtime/testing/vitest";
|
|
48
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
49
|
+
import agentDef, { audit } from "./agent.ts";
|
|
50
|
+
import {
|
|
51
|
+
auditFlow,
|
|
52
|
+
joinSegments,
|
|
53
|
+
SEGMENT_CONCURRENCY,
|
|
54
|
+
transcribeSegment,
|
|
55
|
+
} from "./workflows/audit.ts";
|
|
56
|
+
import { analyse, ingestRecording } from "./workflows/ingest.ts";
|
|
57
|
+
import {
|
|
58
|
+
ANALYSIS_FORMAT,
|
|
59
|
+
BYTES_PER_SECOND,
|
|
60
|
+
durationSeconds,
|
|
61
|
+
type Loudness,
|
|
62
|
+
MAX_SEGMENT_SECONDS,
|
|
63
|
+
MediaAnalysisError,
|
|
64
|
+
MIN_SILENCE_SECONDS,
|
|
65
|
+
masterArgs,
|
|
66
|
+
measureLoudnessArgs,
|
|
67
|
+
normalizeArgs,
|
|
68
|
+
parseLoudness,
|
|
69
|
+
parseSilences,
|
|
70
|
+
planSegments,
|
|
71
|
+
type Silence,
|
|
72
|
+
speechFraction,
|
|
73
|
+
} from "./workflows/media.ts";
|
|
74
|
+
import { narrate, summarize } from "./workflows/summarize.ts";
|
|
75
|
+
|
|
76
|
+
/** The id every spec below uploads under. */
|
|
77
|
+
const UPLOAD_ID = "upl_test";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* `loudnorm`'s first pass, exactly as ffmpeg 6.1.1 printed it to stderr.
|
|
81
|
+
*
|
|
82
|
+
* Kept verbatim — the leading log line, the blank line, the tab indentation, and
|
|
83
|
+
* every value as a STRING. Two of those are load-bearing: the parser has to FIND
|
|
84
|
+
* the block rather than assume the text starts with it, and it has to coerce
|
|
85
|
+
* strings rather than read numbers.
|
|
86
|
+
*/
|
|
87
|
+
const LOUDNORM_STDERR = `[Parsed_loudnorm_0 @ 0x558882c84140]
|
|
88
|
+
{
|
|
89
|
+
\t"input_i" : "-16.19",
|
|
90
|
+
\t"input_tp" : "-7.42",
|
|
91
|
+
\t"input_lra" : "4.80",
|
|
92
|
+
\t"input_thresh" : "-26.34",
|
|
93
|
+
\t"output_i" : "-16.13",
|
|
94
|
+
\t"output_tp" : "-7.48",
|
|
95
|
+
\t"output_lra" : "4.80",
|
|
96
|
+
\t"output_thresh" : "-26.26",
|
|
97
|
+
\t"normalization_type" : "dynamic",
|
|
98
|
+
\t"target_offset" : "0.13"
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* What `ametadata=mode=print:file=…` wrote for a 20-second recording, verbatim.
|
|
104
|
+
*
|
|
105
|
+
* Two things about it are the whole reason `parseSilences` is not a two-line
|
|
106
|
+
* regex, and both were verified rather than assumed:
|
|
107
|
+
*
|
|
108
|
+
* - The event times are NOT the frame's `pts_time`. `silence_start=3` sits on a
|
|
109
|
+
* frame at 3.599, because the filter needed 0.6s of silence to be sure.
|
|
110
|
+
* - The LAST event has no `silence_end`. The recording ended during a pause, so
|
|
111
|
+
* the filter never saw the sound come back.
|
|
112
|
+
*/
|
|
113
|
+
const SILENCE_LOG = `frame:155 pts:158720 pts_time:3.59909
|
|
114
|
+
lavfi.silence_start=3
|
|
115
|
+
frame:215 pts:220160 pts_time:4.99229
|
|
116
|
+
lavfi.silence_end=5.00005
|
|
117
|
+
lavfi.silence_duration=2.00005
|
|
118
|
+
frame:370 pts:378880 pts_time:8.59138
|
|
119
|
+
lavfi.silence_start=7.99998
|
|
120
|
+
frame:430 pts:440320 pts_time:9.98458
|
|
121
|
+
lavfi.silence_end=10
|
|
122
|
+
lavfi.silence_duration=2.00007
|
|
123
|
+
frame:585 pts:599040 pts_time:13.5837
|
|
124
|
+
lavfi.silence_start=13
|
|
125
|
+
frame:645 pts:660480 pts_time:14.9769
|
|
126
|
+
lavfi.silence_end=15
|
|
127
|
+
lavfi.silence_duration=2.00007
|
|
128
|
+
frame:801 pts:820224 pts_time:18.5992
|
|
129
|
+
lavfi.silence_start=18
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Bytes the real normalize pass wrote for the recording {@link SILENCE_LOG} came
|
|
134
|
+
* from, and the exact seconds that is.
|
|
135
|
+
*
|
|
136
|
+
* Not 20 seconds: AAC carries encoder priming samples, so decoding a nominally
|
|
137
|
+
* 20-second file yields 20.015625. The difference is small and it is the whole
|
|
138
|
+
* reason `planSegments` takes a byte count — see `durationSeconds`.
|
|
139
|
+
*/
|
|
140
|
+
const REAL_PCM_BYTES = 640_500;
|
|
141
|
+
const EXACT_SECONDS = durationSeconds(REAL_PCM_BYTES);
|
|
142
|
+
|
|
143
|
+
/** The measurement above, parsed — the input the second pass's argv is built from. */
|
|
144
|
+
const MEASURED: Loudness = {
|
|
145
|
+
inputLufs: -16.19,
|
|
146
|
+
inputTruePeak: -7.42,
|
|
147
|
+
inputRange: 4.8,
|
|
148
|
+
inputThreshold: -26.34,
|
|
149
|
+
targetOffset: 0.13,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The bytes one stubbed request carried, ASSERTED rather than cast.
|
|
154
|
+
*
|
|
155
|
+
* A `throw` returns `never`, so this narrows without an `as Uint8Array` — and the
|
|
156
|
+
* cast is what a first draft reaches for, which Biome then rejects as unsafe
|
|
157
|
+
* optional chaining, because a missing call would throw on `.byteLength` rather
|
|
158
|
+
* than fail with a message. A typed seam is the repo's remedy for a concentration
|
|
159
|
+
* of identical casts, and two is where it starts paying.
|
|
160
|
+
*
|
|
161
|
+
* A bare `throw` rather than `expect.fail`, which is the shape the repo prefers in
|
|
162
|
+
* a test BODY and which Biome's `noMisplacedAssertion` forbids in a helper — an
|
|
163
|
+
* assertion outside a `test()` is a real hazard, and here the throw is doing type
|
|
164
|
+
* narrowing rather than making a claim.
|
|
165
|
+
*/
|
|
166
|
+
function sentBytes(body: unknown): Uint8Array {
|
|
167
|
+
if (!(body instanceof Uint8Array)) {
|
|
168
|
+
throw new TypeError("the stub records a Uint8Array request body");
|
|
169
|
+
}
|
|
170
|
+
return body;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** A pause at each of `starts`, each exactly long enough to be a candidate. */
|
|
174
|
+
function pauses(...starts: number[]): Silence[] {
|
|
175
|
+
return starts.map((startSec) => ({ startSec, endSec: startSec + MIN_SILENCE_SECONDS }));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
beforeEach(() => {
|
|
179
|
+
// The step env, which is where `requireStepEnv`, `stepSpeak` and the gateway
|
|
180
|
+
// read the key. `vi.stubEnv` rather than an assignment: `unstubEnvs` undoes it
|
|
181
|
+
// before every test, so nothing here has to remember to put it back.
|
|
182
|
+
vi.stubEnv("ASSEMBLYAI_API_KEY", "test-key");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("the declaration", () => {
|
|
186
|
+
test("is a workflow app with the one workflow the page starts by name", () => {
|
|
187
|
+
// The page calls `api.start("audit", …)`, so a rename here is a runtime 400
|
|
188
|
+
// rather than a compile error. This is what pins it.
|
|
189
|
+
// `toContain` rather than an exact key list: adding a second workflow is an
|
|
190
|
+
// invited edit and must not redden a test the author did not write. The
|
|
191
|
+
// NAME is still pinned, deliberately — the page starts a run by this
|
|
192
|
+
// string, so renaming the key is a runtime 400 rather than a compile
|
|
193
|
+
// error, and this pin is the only thing that says so. Rename it here and
|
|
194
|
+
// in `client.tsx` together.
|
|
195
|
+
expect(Object.keys(agentDef.workflows ?? {})).toContain("audit");
|
|
196
|
+
expect(agentDef.workflows?.audit).toBe(audit);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("declares the credential its steps read, so a deploy checks for it", () => {
|
|
200
|
+
// A workflow app has no session, so nothing else in its config could name one
|
|
201
|
+
// — and one AssemblyAI key covers transcription, the model and the voice.
|
|
202
|
+
// Note what is NOT here: ffmpeg. `requiredEnv` checks the environment, and a
|
|
203
|
+
// binary on `PATH` is not an environment variable.
|
|
204
|
+
//
|
|
205
|
+
// `toContain` rather than an exact list: a step of your own that reads a
|
|
206
|
+
// second credential belongs in `requiredEnv` beside this one, and declaring
|
|
207
|
+
// it must not fail this test.
|
|
208
|
+
expect(agentDef.requiredEnv).toContain("ASSEMBLYAI_API_KEY");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("takes the recording as an UPLOAD, which is what makes the form a file picker", () => {
|
|
212
|
+
expect(audit.uploads).toEqual(["recording"]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("offers real voice ids, so the synthesis cannot fail silently in band", async () => {
|
|
216
|
+
// A wrong voice is accepted by the socket and refused in band, so the schema
|
|
217
|
+
// is the only thing that can catch one. The list is read from the SDK catalog.
|
|
218
|
+
expect(
|
|
219
|
+
(await audit.input?.["~standard"].validate({ recording: UPLOAD_ID, voice: "not-a-voice" }))
|
|
220
|
+
?.issues,
|
|
221
|
+
).toBeTruthy();
|
|
222
|
+
expect(
|
|
223
|
+
(await audit.input?.["~standard"].validate({ recording: UPLOAD_ID, voice: "jane" }))?.issues,
|
|
224
|
+
).toBeUndefined();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("accepts a recording with no voice chosen, so the SDK default applies", async () => {
|
|
228
|
+
expect(
|
|
229
|
+
(await audit.input?.["~standard"].validate({ recording: UPLOAD_ID }))?.issues,
|
|
230
|
+
).toBeUndefined();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("the ffmpeg argv", () => {
|
|
235
|
+
test("every invocation is quiet, non-interactive, and overwrites", () => {
|
|
236
|
+
// `-nostdin` is the one that matters in a guest: an ffmpeg that decides to
|
|
237
|
+
// read stdin is a process that never exits.
|
|
238
|
+
for (const argv of [
|
|
239
|
+
measureLoudnessArgs("in.m4a"),
|
|
240
|
+
normalizeArgs("in.m4a", MEASURED, "out.pcm", "silence.txt"),
|
|
241
|
+
masterArgs("spoken.wav", "out.mp3"),
|
|
242
|
+
]) {
|
|
243
|
+
expect(argv).toEqual(expect.arrayContaining(["-hide_banner", "-nostats", "-nostdin", "-y"]));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("the measure pass writes no audio and asks for JSON", () => {
|
|
248
|
+
const argv = measureLoudnessArgs("in.m4a");
|
|
249
|
+
// `-f null -` is what makes this cost a decode and produce five numbers.
|
|
250
|
+
expect(argv.slice(-3)).toEqual(["-f", "null", "-"]);
|
|
251
|
+
expect(argv.join(" ")).toContain("print_format=json");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("the measure pass runs at `info`, because that is where the JSON is printed", () => {
|
|
255
|
+
// The failure this pins is silent: at `-loglevel error` the pass still runs
|
|
256
|
+
// and still succeeds, and prints nothing at all — which reads as a parser bug.
|
|
257
|
+
const argv = measureLoudnessArgs("in.m4a");
|
|
258
|
+
expect(argv[argv.indexOf("-loglevel") + 1]).toBe("info");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("the normalize pass stays quiet, because its analysis goes to a FILE", () => {
|
|
262
|
+
const argv = normalizeArgs("in.m4a", MEASURED, "out.pcm", "silence.txt");
|
|
263
|
+
expect(argv[argv.indexOf("-loglevel") + 1]).toBe("error");
|
|
264
|
+
// `ametadata` writes the path directly rather than through the log, which is
|
|
265
|
+
// the property that lets this pass be both silent and complete.
|
|
266
|
+
expect(argv.join(" ")).toContain("ametadata=mode=print:file=silence.txt");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("the normalize pass feeds back every measured value", () => {
|
|
270
|
+
// A missing `measured_*` makes loudnorm silently run a ONE-pass normalization
|
|
271
|
+
// instead — no error, just a different result — so all five are pinned.
|
|
272
|
+
const filter = normalizeArgs("in.m4a", MEASURED, "out.pcm", "silence.txt").join(" ");
|
|
273
|
+
expect(filter).toContain("measured_I=-16.19");
|
|
274
|
+
expect(filter).toContain("measured_TP=-7.42");
|
|
275
|
+
expect(filter).toContain("measured_LRA=4.8");
|
|
276
|
+
expect(filter).toContain("measured_thresh=-26.34");
|
|
277
|
+
expect(filter).toContain("offset=0.13");
|
|
278
|
+
// One constant gain rather than a moving one, so speech does not pump.
|
|
279
|
+
expect(filter).toContain("linear=true");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("the normalize pass writes HEADERLESS PCM in the analysis format", () => {
|
|
283
|
+
// The decision the whole template rests on: `-f s16le`, not `-f wav`, so byte
|
|
284
|
+
// zero is second zero and nothing has to parse a RIFF chunk list.
|
|
285
|
+
const argv = normalizeArgs("in.m4a", MEASURED, "out.pcm", "silence.txt");
|
|
286
|
+
expect(argv.slice(-3)).toEqual(["-f", "s16le", "out.pcm"]);
|
|
287
|
+
expect(argv[argv.indexOf("-ar") + 1]).toBe(String(ANALYSIS_FORMAT.sampleRate));
|
|
288
|
+
expect(argv[argv.indexOf("-ac") + 1]).toBe(String(ANALYSIS_FORMAT.channels));
|
|
289
|
+
expect(argv[argv.indexOf("-c:a") + 1]).toBe("pcm_s16le");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("the filter chain is ONE argv element, so its commas never meet a shell", () => {
|
|
293
|
+
// `runFfmpeg` spawns without a shell, which is what makes an unquoted filter
|
|
294
|
+
// graph safe — and what would break if this were ever assembled into a string.
|
|
295
|
+
const argv = normalizeArgs("in.m4a", MEASURED, "out.pcm", "silence.txt");
|
|
296
|
+
const filter = argv[argv.indexOf("-af") + 1] ?? "";
|
|
297
|
+
expect(filter).toContain(",silencedetect=");
|
|
298
|
+
expect(filter.startsWith("loudnorm=")).toBe(true);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("the mastering pass encodes MP3, which is the point of running it", () => {
|
|
302
|
+
const argv = masterArgs("spoken.wav", "out.mp3");
|
|
303
|
+
expect(argv[argv.indexOf("-c:a") + 1]).toBe("libmp3lame");
|
|
304
|
+
expect(argv.at(-1)).toBe("out.mp3");
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe("reading the loudness measurement", () => {
|
|
309
|
+
test("parses ffmpeg's own block, strings and all", () => {
|
|
310
|
+
expect(parseLoudness(LOUDNORM_STDERR)).toEqual(MEASURED);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("finds the block after whatever info-level chatter preceded it", () => {
|
|
314
|
+
// The pass runs at `-loglevel info`, so the captured stderr tail holds stream
|
|
315
|
+
// descriptions and a muxing-overhead line before the JSON.
|
|
316
|
+
const noisy = ` Stream #0:0(und): Audio: pcm_s16le, 192000 Hz, mono\nsize=N/A time=00:00:17.20\n${LOUDNORM_STDERR}`;
|
|
317
|
+
expect(parseLoudness(noisy)).toEqual(MEASURED);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("takes the LAST block, so a retried pass reads its own numbers", () => {
|
|
321
|
+
const twice = LOUDNORM_STDERR + LOUDNORM_STDERR.replace('"-16.19"', '"-20.50"');
|
|
322
|
+
expect(parseLoudness(twice).inputLufs).toBe(-20.5);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test("names the missing `-loglevel info` when nothing was printed", () => {
|
|
326
|
+
// The most likely way this breaks, so the message says how to fix it rather
|
|
327
|
+
// than reporting a parse failure.
|
|
328
|
+
expect(() => parseLoudness("size=N/A time=00:00:17.20\n")).toThrow(MediaAnalysisError);
|
|
329
|
+
expect(() => parseLoudness("")).toThrow(/-loglevel info/);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("names the KEY when a value is missing or unparseable", () => {
|
|
333
|
+
// A silent `NaN` would flow into the second pass's argv as the literal text
|
|
334
|
+
// `NaN` and come back as an ffmpeg option-parsing error about a filter.
|
|
335
|
+
const missing = LOUDNORM_STDERR.replace('"input_tp" : "-7.42",', "");
|
|
336
|
+
expect(() => parseLoudness(missing)).toThrow(/input_tp/);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test("names the KEY when the value is unreadable, and QUOTES what came", () => {
|
|
340
|
+
// The other half of the case above: the key is there and holds something no
|
|
341
|
+
// number can be read out of — `"n/a"`, which is ffmpeg's own spelling for a
|
|
342
|
+
// value it could not measure, or a type that was never a number. Terminal
|
|
343
|
+
// either way, and the message has to carry the value, which is why the
|
|
344
|
+
// object gate and the value schema are two parses rather than one.
|
|
345
|
+
expect(() => parseLoudness(LOUDNORM_STDERR.replace('"-7.42"', '"n/a"'))).toThrow(
|
|
346
|
+
/input_tp.*got "n\/a"/,
|
|
347
|
+
);
|
|
348
|
+
expect(() => parseLoudness(LOUDNORM_STDERR.replace('"-7.42"', "[1,2]"))).toThrow(/input_tp/);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test("coerces exactly as `Number(…)` does, corners included", () => {
|
|
352
|
+
// Every value is a STRING on the wire, so the read has always been a
|
|
353
|
+
// coercion — and `Number(null)` is 0, not `NaN`. Pinned rather than
|
|
354
|
+
// tightened: the schema replaced a hand-written reader, so its corners are
|
|
355
|
+
// the ones that reader had, and narrowing them is a change to make on
|
|
356
|
+
// purpose rather than a side effect of declaring a schema.
|
|
357
|
+
const nulled = LOUDNORM_STDERR.replace('"0.13"', "null");
|
|
358
|
+
expect(parseLoudness(nulled).targetOffset).toBe(0);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test("refuses a block that is not JSON at all", () => {
|
|
362
|
+
expect(() => parseLoudness("[loudnorm] {not json}")).toThrow(MediaAnalysisError);
|
|
363
|
+
expect(() => parseLoudness("[loudnorm] {not json}")).toThrow(/not JSON/);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe("reading the pauses", () => {
|
|
368
|
+
test("parses every event ffmpeg logged, and closes the unterminated one", () => {
|
|
369
|
+
// The trailing `silence_start=18` has no `silence_end` — the recording ended
|
|
370
|
+
// during the pause. It is closed at the duration, which is why this function
|
|
371
|
+
// takes one.
|
|
372
|
+
expect(parseSilences(SILENCE_LOG, EXACT_SECONDS)).toEqual([
|
|
373
|
+
{ startSec: 3, endSec: 5.000_05 },
|
|
374
|
+
{ startSec: 7.999_98, endSec: 10 },
|
|
375
|
+
{ startSec: 13, endSec: 15 },
|
|
376
|
+
{ startSec: 18, endSec: EXACT_SECONDS },
|
|
377
|
+
]);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("reads the EVENT time, not the frame's", () => {
|
|
381
|
+
// `silence_start=3` sits on a frame at `pts_time:3.59909`. Reading the frame
|
|
382
|
+
// would put every cut 0.6s late and lose the word before it.
|
|
383
|
+
const [first] = parseSilences(SILENCE_LOG, EXACT_SECONDS);
|
|
384
|
+
expect(first?.startSec).toBe(3);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test("an empty log is no pauses, not a failure", () => {
|
|
388
|
+
// Verified against ffmpeg 6.1: `ametadata` creates the file at filter-init, so
|
|
389
|
+
// a recording with no pause in it leaves an empty log rather than none.
|
|
390
|
+
expect(parseSilences("", 30)).toEqual([]);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("a pause that never ended before a recording that already did is dropped", () => {
|
|
394
|
+
// `durationSec` is measured from the PCM byte count and the log from the same
|
|
395
|
+
// pass, so they agree — but a zero-length pause would produce a cut candidate
|
|
396
|
+
// at the very end, which `planSegments` would then have to reject.
|
|
397
|
+
expect(parseSilences("lavfi.silence_start=30\n", 30)).toEqual([]);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("an end without a start is ignored rather than inventing a pause at zero", () => {
|
|
401
|
+
expect(parseSilences("lavfi.silence_end=4\n", 30)).toEqual([]);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
test("a truncated numeric value is skipped rather than read as NaN", () => {
|
|
405
|
+
// A `NaN` boundary would make every downstream comparison false, so the cut
|
|
406
|
+
// planner would silently fall back to blind cuts for the whole recording.
|
|
407
|
+
expect(parseSilences("lavfi.silence_start=\nlavfi.silence_end=4\n", 30)).toEqual([]);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
describe("planning where to cut", () => {
|
|
412
|
+
test("a recording inside the cap is one segment, whatever its pauses", () => {
|
|
413
|
+
// Nothing to decide, and the pauses must not tempt the planner into cutting: a
|
|
414
|
+
// request per pause would be dozens of requests for a two-minute call.
|
|
415
|
+
const segments = planSegments(pauses(10, 20, 30), 60 * BYTES_PER_SECOND);
|
|
416
|
+
expect(segments).toHaveLength(1);
|
|
417
|
+
expect(segments[0]).toMatchObject({ index: 0, startByte: 0, startMs: 0, endMs: 60_000 });
|
|
418
|
+
expect(segments[0]?.endByte).toBe(60 * BYTES_PER_SECOND);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test("cuts at the LAST pause that still fits, not the first", () => {
|
|
422
|
+
// Greedy from the front, so segments are as long as the cap allows — the
|
|
423
|
+
// alternative is twice as many requests for the same audio.
|
|
424
|
+
const segments = planSegments(pauses(30, 60, 100), 150 * BYTES_PER_SECOND);
|
|
425
|
+
// The pause at 100 spans 100–100.6, so its midpoint is 100.3.
|
|
426
|
+
expect(segments.map((s) => s.endMs)).toEqual([100_300, 150_000]);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test("the cut is the pause's MIDPOINT, so neither side is clipped", () => {
|
|
430
|
+
// Cutting at the start clips the decay of the word before; cutting at the end
|
|
431
|
+
// clips the attack of the word after.
|
|
432
|
+
const segments = planSegments([{ startSec: 100, endSec: 101 }], 150 * BYTES_PER_SECOND);
|
|
433
|
+
expect(segments[0]?.endMs).toBe(100_500);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test("segments are contiguous and non-overlapping, which is what deletes the stitcher", () => {
|
|
437
|
+
const segments = planSegments(pauses(50, 100, 160, 210), 260 * BYTES_PER_SECOND);
|
|
438
|
+
expect(segments.length).toBeGreaterThan(1);
|
|
439
|
+
for (const [i, segment] of segments.entries()) {
|
|
440
|
+
if (i === 0) continue;
|
|
441
|
+
expect(segment.startByte).toBe(segments[i - 1]?.endByte);
|
|
442
|
+
expect(segment.startMs).toBe(segments[i - 1]?.endMs);
|
|
443
|
+
}
|
|
444
|
+
expect(segments[0]?.startByte).toBe(0);
|
|
445
|
+
expect(segments.at(-1)?.endByte).toBe(260 * BYTES_PER_SECOND);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test("no segment exceeds the endpoint's cap", () => {
|
|
449
|
+
const segments = planSegments(pauses(20, 40, 61, 130, 200), 400 * BYTES_PER_SECOND);
|
|
450
|
+
for (const segment of segments) {
|
|
451
|
+
expect(segment.endMs - segment.startMs).toBeLessThanOrEqual(MAX_SEGMENT_SECONDS * 1000);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("an unbroken monologue falls back to a blind cut, and SAYS so", () => {
|
|
456
|
+
// The case the pretty invariant cannot serve. Refusing it would be the worse
|
|
457
|
+
// trade, so it degrades to exactly what `transcription-workflow` does — and
|
|
458
|
+
// reports it, because a mangled word at a seam is otherwise a mystery.
|
|
459
|
+
const segments = planSegments([], 300 * BYTES_PER_SECOND);
|
|
460
|
+
expect(segments).toHaveLength(3);
|
|
461
|
+
expect(segments.map((s) => s.endMs)).toEqual([110_000, 220_000, 300_000]);
|
|
462
|
+
expect(segments.map((s) => s.cutInSpeech)).toEqual([true, true, false]);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
test("a cut that landed in a pause is NOT reported as a blind cut", () => {
|
|
466
|
+
const segments = planSegments(pauses(100), 150 * BYTES_PER_SECOND);
|
|
467
|
+
expect(segments.map((s) => s.cutInSpeech)).toEqual([false, false]);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test("a tail too short to be worth a request joins its predecessor", () => {
|
|
471
|
+
// The endpoint refuses audio under 80ms, and a 0.4-second tail holds at most one
|
|
472
|
+
// word — but the word is a word, so it is merged rather than dropped. A pause at
|
|
473
|
+
// 150 leaves the predecessor well short of the cap, which is what makes the merge
|
|
474
|
+
// legal; see the cap test below for when it is not.
|
|
475
|
+
const segments = planSegments(pauses(150), 200.5 * BYTES_PER_SECOND);
|
|
476
|
+
expect(segments).toHaveLength(2);
|
|
477
|
+
expect(segments.at(-1)?.endMs).toBe(200_500);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test("a short tail is NOT absorbed into a segment already at the cap", () => {
|
|
481
|
+
// The greedy loop leaves a final segment of at most `MAX_SEGMENT_SECONDS`, so
|
|
482
|
+
// merging a sub-second tail into a predecessor already at the cap would make one
|
|
483
|
+
// 110.5 seconds long — inside the endpoint's own 120-second limit, and outside
|
|
484
|
+
// the bound this module promises. A short final request is the cheaper mistake,
|
|
485
|
+
// and it is still an order of magnitude above the 80ms the endpoint refuses.
|
|
486
|
+
const segments = planSegments([], 110.5 * BYTES_PER_SECOND);
|
|
487
|
+
expect(segments).toHaveLength(2);
|
|
488
|
+
for (const segment of segments) {
|
|
489
|
+
expect(segment.endMs - segment.startMs).toBeLessThanOrEqual(MAX_SEGMENT_SECONDS * 1000);
|
|
490
|
+
}
|
|
491
|
+
// Still contiguous, still covering the whole recording.
|
|
492
|
+
expect(segments[0]?.endByte).toBe(segments[1]?.startByte);
|
|
493
|
+
expect(segments.at(-1)?.endMs).toBe(110_500);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test("every byte offset lands on a sample-frame boundary", () => {
|
|
497
|
+
// A byte offset mid-sample shifts every sample after it by one byte, which is
|
|
498
|
+
// not a click — it is white noise the decoder transcribes into confident
|
|
499
|
+
// nonsense.
|
|
500
|
+
const frame = (ANALYSIS_FORMAT.channels * ANALYSIS_FORMAT.bitsPerSample) / 8;
|
|
501
|
+
for (const segment of planSegments(pauses(37.333, 88.777, 150.5), 200 * BYTES_PER_SECOND)) {
|
|
502
|
+
expect(segment.startByte % frame).toBe(0);
|
|
503
|
+
expect(segment.endByte % frame).toBe(0);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
test("an empty recording plans nothing rather than one empty request", () => {
|
|
508
|
+
expect(planSegments([], 0)).toEqual([]);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test("the real 20-second capture is one segment covering all of it", () => {
|
|
512
|
+
// End to end over the captured fixture, which is the case a reader can check
|
|
513
|
+
// against the numbers in `SILENCE_LOG`.
|
|
514
|
+
const silences = parseSilences(SILENCE_LOG, EXACT_SECONDS);
|
|
515
|
+
const segments = planSegments(silences, REAL_PCM_BYTES);
|
|
516
|
+
expect(segments).toHaveLength(1);
|
|
517
|
+
expect(segments[0]?.cutInSpeech).toBe(false);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test("the last segment never addresses a byte the file does not have", () => {
|
|
521
|
+
// The twelve-byte bug this API shape exists to prevent: planning from a
|
|
522
|
+
// duration rounded to whole milliseconds put `endByte` at 640,512 for a
|
|
523
|
+
// 640,500-byte file. `stepReadUpload` clamps a window to the stored size, so
|
|
524
|
+
// nothing threw — the plan was simply describing audio that does not exist.
|
|
525
|
+
// Found by running the real argv against a real ffmpeg, which is the only
|
|
526
|
+
// place a twelve-byte error was ever going to surface.
|
|
527
|
+
for (const bytes of [REAL_PCM_BYTES, 32_001, 999_999, 2]) {
|
|
528
|
+
const segments = planSegments(parseSilences(SILENCE_LOG, durationSeconds(bytes)), bytes);
|
|
529
|
+
expect(segments.at(-1)?.endByte ?? 0).toBeLessThanOrEqual(bytes);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
describe("what the page is told about the recording", () => {
|
|
535
|
+
test("speech is the complement of the pauses", () => {
|
|
536
|
+
// 20 seconds with 8 of pause in it.
|
|
537
|
+
expect(
|
|
538
|
+
Math.round(
|
|
539
|
+
speechFraction(
|
|
540
|
+
[
|
|
541
|
+
{ startSec: 3, endSec: 5 },
|
|
542
|
+
{ startSec: 8, endSec: 10 },
|
|
543
|
+
{ startSec: 13, endSec: 15 },
|
|
544
|
+
{ startSec: 18, endSec: 20 },
|
|
545
|
+
],
|
|
546
|
+
20,
|
|
547
|
+
) * 100,
|
|
548
|
+
),
|
|
549
|
+
).toBe(60);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
test("a recording of pure silence is 0% speech, and one with no pause is 100%", () => {
|
|
553
|
+
expect(speechFraction([{ startSec: 0, endSec: 30 }], 30)).toBe(0);
|
|
554
|
+
expect(speechFraction([], 30)).toBe(1);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test("a zero-length recording answers 0 rather than dividing by it", () => {
|
|
558
|
+
expect(speechFraction([], 0)).toBe(0);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
describe("joining the segments", () => {
|
|
563
|
+
/** Two segments whose shared boundary is `cutInSpeech` on the first. */
|
|
564
|
+
function pair(cutInSpeech: boolean) {
|
|
565
|
+
return [
|
|
566
|
+
{ index: 0, startByte: 0, endByte: 10, startMs: 0, endMs: 10, cutInSpeech },
|
|
567
|
+
{ index: 1, startByte: 10, endByte: 20, startMs: 10, endMs: 20, cutInSpeech: false },
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
test("a cut made in a pause becomes a paragraph break", () => {
|
|
572
|
+
// The plan knows where the turn boundaries are, so the transcript can show
|
|
573
|
+
// them. This is the one place `cutInSpeech` changes an output, not a report.
|
|
574
|
+
expect(
|
|
575
|
+
joinSegments(pair(false), [
|
|
576
|
+
{ index: 0, text: "Good morning." },
|
|
577
|
+
{ index: 1, text: "Let us begin." },
|
|
578
|
+
]),
|
|
579
|
+
).toBe("Good morning.\n\nLet us begin.");
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
test("a blind cut is joined with a space, because it landed mid-sentence", () => {
|
|
583
|
+
expect(
|
|
584
|
+
joinSegments(pair(true), [
|
|
585
|
+
{ index: 0, text: "the number was" },
|
|
586
|
+
{ index: 1, text: "roughly four" },
|
|
587
|
+
]),
|
|
588
|
+
).toBe("the number was roughly four");
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
test("puts the parts in index order however they arrived", () => {
|
|
592
|
+
// `mapConcurrent` resolves in item order, so this is belt and braces — a merge
|
|
593
|
+
// is where an ordering mistake would be invisible rather than loud.
|
|
594
|
+
expect(
|
|
595
|
+
joinSegments(pair(true), [
|
|
596
|
+
{ index: 1, text: "second" },
|
|
597
|
+
{ index: 0, text: "first" },
|
|
598
|
+
]),
|
|
599
|
+
).toBe("first second");
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test("a segment that transcribed to nothing leaves no stray separator", () => {
|
|
603
|
+
// A stretch that is all room tone comes back empty, and a naive join would
|
|
604
|
+
// leave a leading or doubled break in the transcript.
|
|
605
|
+
expect(
|
|
606
|
+
joinSegments(pair(false), [
|
|
607
|
+
{ index: 0, text: "" },
|
|
608
|
+
{ index: 1, text: "words" },
|
|
609
|
+
]),
|
|
610
|
+
).toBe("words");
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
describe("transcribing one segment", () => {
|
|
615
|
+
/**
|
|
616
|
+
* One second of stored PCM, and a sync endpoint that answers.
|
|
617
|
+
*
|
|
618
|
+
* A published `stepFetch`, not `vi.stubGlobal("fetch", …)`: the step calls
|
|
619
|
+
* `stepFetch`, which reaches a published slot rather than the global. Stubbing
|
|
620
|
+
* the global still passes, because an unpublished slot falls back to it, and
|
|
621
|
+
* would be asserting against a path production does not take.
|
|
622
|
+
*/
|
|
623
|
+
function stubProvider(failure?: { status: number; message: string }) {
|
|
624
|
+
installStubUploads({
|
|
625
|
+
[UPLOAD_ID]: {
|
|
626
|
+
bytes: new Uint8Array(BYTES_PER_SECOND),
|
|
627
|
+
name: "call.pcm",
|
|
628
|
+
type: "application/octet-stream",
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
installStubReporter();
|
|
632
|
+
// `installStubTranscribe` answers AssemblyAI's own endpoints off the SDK's
|
|
633
|
+
// endpoint constants, so this spec no longer re-types the wire — and a refusal
|
|
634
|
+
// is staged as a STATUS, which is what makes the classification below a test of
|
|
635
|
+
// the SDK's reading of it rather than of a `TranscribeError` a fake minted.
|
|
636
|
+
return installStubTranscribe({
|
|
637
|
+
text: "hello there",
|
|
638
|
+
failure: failure === undefined ? undefined : { leg: "sync", ...failure },
|
|
639
|
+
}).calls;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const SEGMENT = {
|
|
643
|
+
index: 0,
|
|
644
|
+
startByte: 0,
|
|
645
|
+
endByte: BYTES_PER_SECOND,
|
|
646
|
+
startMs: 0,
|
|
647
|
+
endMs: 1000,
|
|
648
|
+
cutInSpeech: false,
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
test("puts a WAV header back on the headerless span before sending it", async () => {
|
|
652
|
+
// The endpoint decodes each request independently, so a slice of raw PCM is
|
|
653
|
+
// meaningless bytes until a header says what they are. `encodeWav` is the SDK's
|
|
654
|
+
// — this template deliberately carries no copy of it.
|
|
655
|
+
const calls = stubProvider();
|
|
656
|
+
await expect(transcribeSegment(UPLOAD_ID, SEGMENT)).resolves.toEqual({
|
|
657
|
+
index: 0,
|
|
658
|
+
text: "hello there",
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// Inside a multipart body, so the header is not at byte zero — what matters is
|
|
662
|
+
// that it is there at all, and immediately followed by `WAVE`.
|
|
663
|
+
const sent = new TextDecoder("latin1").decode(sentBytes(calls[0]?.body));
|
|
664
|
+
expect(sent).toContain("RIFF");
|
|
665
|
+
expect(sent.indexOf("WAVE")).toBe(sent.indexOf("RIFF") + 8);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
test("sends the whole span, header included, and nothing else", async () => {
|
|
669
|
+
const calls = stubProvider();
|
|
670
|
+
await transcribeSegment(UPLOAD_ID, SEGMENT);
|
|
671
|
+
// 44 bytes of canonical header plus one second of audio, inside a multipart
|
|
672
|
+
// body — so the request is strictly larger than the span and close to it.
|
|
673
|
+
const size = sentBytes(calls[0]?.body).byteLength;
|
|
674
|
+
expect(size).toBeGreaterThan(BYTES_PER_SECOND);
|
|
675
|
+
expect(size).toBeLessThan(BYTES_PER_SECOND + 2000);
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test("a rate limit is RETRYABLE, so one busy minute does not fail the run", async () => {
|
|
679
|
+
// The expected failure of a 32-wide fan-out, and the reason the BODY calls
|
|
680
|
+
// this step with more attempts than the default — asserted where the policy
|
|
681
|
+
// now lives, in `the whole run` below.
|
|
682
|
+
stubProvider({ status: 429, message: "slow down" });
|
|
683
|
+
await expect(transcribeSegment(UPLOAD_ID, SEGMENT)).rejects.toBeInstanceOf(RetryableError);
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
test("a rejected request is FATAL, so it is not asked five more times", async () => {
|
|
687
|
+
stubProvider({ status: 400, message: "that is not audio" });
|
|
688
|
+
await expect(transcribeSegment(UPLOAD_ID, SEGMENT)).rejects.toBeInstanceOf(FatalError);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
test("the fan-out width is a constant, because the format is", () => {
|
|
692
|
+
// The payoff of normalizing: a segment is at most 3.5 MB whatever was
|
|
693
|
+
// uploaded, so there is no byte budget to divide — see the constant's doc.
|
|
694
|
+
expect(SEGMENT_CONCURRENCY).toBe(32);
|
|
695
|
+
expect(MAX_SEGMENT_SECONDS * BYTES_PER_SECOND * SEGMENT_CONCURRENCY).toBeLessThan(
|
|
696
|
+
640 * 1024 * 1024,
|
|
697
|
+
);
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
describe("auditing the transcript", () => {
|
|
702
|
+
test("asks for a script as well as lists, and keeps both", async () => {
|
|
703
|
+
// The two-summaries decision: a voice reading a bullet list says "one. two.
|
|
704
|
+
// three." with no connective tissue, so the schema demands sentences too.
|
|
705
|
+
installStubReporter();
|
|
706
|
+
// The stub answers with TEXT, because that is what a gateway returns — and
|
|
707
|
+
// `stepGenerateJson` parsing it is part of what this exercises.
|
|
708
|
+
installStubGateway(
|
|
709
|
+
JSON.stringify({
|
|
710
|
+
headline: "Renewal call with Northwind",
|
|
711
|
+
risks: ["Nobody owns the migration date"],
|
|
712
|
+
actions: ["Ana to send revised pricing"],
|
|
713
|
+
spoken: "The renewal is close, but the migration date has no owner yet.",
|
|
714
|
+
}),
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
const summary = await summarize("… transcript …", "call.m4a", 600_000);
|
|
718
|
+
expect(summary.headline).toBe("Renewal call with Northwind");
|
|
719
|
+
expect(summary.risks).toEqual(["Nobody owns the migration date"]);
|
|
720
|
+
expect(summary.spoken).toContain("migration date");
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
test("an empty risk list is an ANSWER, not a retry", async () => {
|
|
724
|
+
// A schema that demanded a risk would get an invented one, which is worse than
|
|
725
|
+
// silence on a call that really had none.
|
|
726
|
+
installStubReporter();
|
|
727
|
+
installStubGateway(
|
|
728
|
+
JSON.stringify({
|
|
729
|
+
headline: "Weekly standup",
|
|
730
|
+
risks: [],
|
|
731
|
+
actions: [],
|
|
732
|
+
spoken: "Nothing was decided and nothing is blocked.",
|
|
733
|
+
}),
|
|
734
|
+
);
|
|
735
|
+
await expect(summarize("…", "standup.wav", 60_000)).resolves.toMatchObject({ risks: [] });
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
test("a reply with no spoken script is a RETRY rather than silence", async () => {
|
|
739
|
+
// `spoken` is required rather than defaulted precisely so this fails: a default
|
|
740
|
+
// would turn a missing field into half a second of audio nobody notices.
|
|
741
|
+
installStubReporter();
|
|
742
|
+
installStubGateway(JSON.stringify({ headline: "A call", risks: [], actions: [] }));
|
|
743
|
+
await expect(summarize("…", "call.m4a", 60_000)).rejects.toThrow();
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
describe("classifying a failure", () => {
|
|
748
|
+
/**
|
|
749
|
+
* The FFMPEG verdict is no longer tested here, and its absence is the change
|
|
750
|
+
* rather than a gap: `throwFfmpegStepError` on `@alexkroman1/aai/step-errors` owns
|
|
751
|
+
* it now, with both arms pinned in `sdk/step-errors.test.ts` — including the case
|
|
752
|
+
* this template contributed, a cause that is not an ffmpeg failure at all.
|
|
753
|
+
*
|
|
754
|
+
* What stays is what is still THIS desk's: `analyse`, which decides that an
|
|
755
|
+
* analysis `media.ts` cannot read is terminal.
|
|
756
|
+
*/
|
|
757
|
+
test("an analysis this desk cannot read is fatal, because a retry reads it again", () => {
|
|
758
|
+
// ffmpeg SUCCEEDED and printed something unrecognized — a renamed key, a lost
|
|
759
|
+
// `-loglevel info`. Every retry runs the same binary and prints the same thing.
|
|
760
|
+
expect(() =>
|
|
761
|
+
analyse(() => {
|
|
762
|
+
throw new MediaAnalysisError("no JSON block");
|
|
763
|
+
}),
|
|
764
|
+
).toThrow(FatalError);
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
test("an analysis helper's OTHER failures are not swallowed", () => {
|
|
768
|
+
// Only `MediaAnalysisError` is a verdict. Anything else is a bug in the parser,
|
|
769
|
+
// and turning that into a terminal step failure would hide it.
|
|
770
|
+
const bug = new TypeError("cannot read properties of undefined");
|
|
771
|
+
expect(() =>
|
|
772
|
+
analyse(() => {
|
|
773
|
+
throw bug;
|
|
774
|
+
}),
|
|
775
|
+
).toThrow(bug);
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
describe("the mastered narration", () => {
|
|
780
|
+
test("is not driven here, and the spec says why rather than pretending", () => {
|
|
781
|
+
// `narrate` speaks, writes a temp file, spawns ffmpeg and stores the result. A
|
|
782
|
+
// unit test may do none of those, so what is covered is `masterArgs` above and
|
|
783
|
+
// the classification below — and `stubSpeech` is imported to make the omission
|
|
784
|
+
// deliberate rather than an oversight: filling only that slot would leave the
|
|
785
|
+
// step failing on the subprocess, which is a test of the tier, not the code.
|
|
786
|
+
expect(typeof stubSpeech).toBe("function");
|
|
787
|
+
expect(masterArgs("in.wav", "out.mp3").at(-1)).toBe("out.mp3");
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
describe("the ffmpeg steps, up to the spawn", () => {
|
|
792
|
+
/**
|
|
793
|
+
* These reach the point where ffmpeg would run and stop there, DETERMINISTICALLY
|
|
794
|
+
* — which is the trick that makes them unit tests rather than scenario tests.
|
|
795
|
+
*
|
|
796
|
+
* `AAI_FFMPEG_PATH` / `AAI_FFPROBE_PATH` name the binary the SDK resolves, so
|
|
797
|
+
* pointing them at a path that does not exist produces `kind: "missing-binary"`
|
|
798
|
+
* on every machine: one where ffmpeg is installed, one where it is not, and CI's
|
|
799
|
+
* Linux leg alike. A test that instead relied on ffmpeg being ABSENT would pass
|
|
800
|
+
* here and behave differently in CI, which is the green-locally/red-in-CI
|
|
801
|
+
* asymmetry this repo is built to avoid.
|
|
802
|
+
*
|
|
803
|
+
* What they cover is everything before the subprocess — reading the upload,
|
|
804
|
+
* materializing it, building the argv — plus the classification of the failure.
|
|
805
|
+
* They also pin the behaviour a developer actually meets: `aai dev` on a laptop
|
|
806
|
+
* with no ffmpeg is the one place dev/prod parity is partial, and it must fail
|
|
807
|
+
* FATALLY with an installable remedy rather than retry four times.
|
|
808
|
+
*/
|
|
809
|
+
beforeEach(() => {
|
|
810
|
+
vi.stubEnv("AAI_FFMPEG_PATH", "/nonexistent/aai-test/ffmpeg");
|
|
811
|
+
vi.stubEnv("AAI_FFPROBE_PATH", "/nonexistent/aai-test/ffprobe");
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
test("ingestRecording materializes the upload, then fails fatally with no ffprobe", async () => {
|
|
815
|
+
installStubUploads({
|
|
816
|
+
[UPLOAD_ID]: { bytes: new Uint8Array(2048), name: "call.m4a", type: "audio/mp4" },
|
|
817
|
+
});
|
|
818
|
+
installStubReporter();
|
|
819
|
+
// Fatal, not retryable: four more attempts find the same missing binary, and the
|
|
820
|
+
// message already carries the install instructions.
|
|
821
|
+
await expect(ingestRecording(UPLOAD_ID)).rejects.toBeInstanceOf(FatalError);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
test("narrate speaks first, then fails fatally with no ffmpeg to master with", async () => {
|
|
825
|
+
// `stepSpeak` runs — the synthesis is not what is broken here — so this also
|
|
826
|
+
// pins the ORDER: a step that mastered before speaking would fail without ever
|
|
827
|
+
// calling the voice service.
|
|
828
|
+
const speech = installStubSpeech();
|
|
829
|
+
installStubReporter();
|
|
830
|
+
installStubUploads({}, { writable: true });
|
|
831
|
+
|
|
832
|
+
await expect(narrate("Read this back.", "jane")).rejects.toBeInstanceOf(FatalError);
|
|
833
|
+
expect(speech.calls.length).toBe(1);
|
|
834
|
+
expect(speech.calls[0]?.text).toBe("Read this back.");
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
test("the temp directory is gone even though the mastering pass failed", async () => {
|
|
838
|
+
// The `finally` in `withTempDir`, on the path that matters: a guest's disk is
|
|
839
|
+
// small, and a step that leaked a directory per failed run would fill it.
|
|
840
|
+
const before = await readdir(tmpdir());
|
|
841
|
+
installStubSpeech();
|
|
842
|
+
installStubReporter();
|
|
843
|
+
installStubUploads({}, { writable: true });
|
|
844
|
+
|
|
845
|
+
await expect(narrate("Read this back.")).rejects.toBeInstanceOf(FatalError);
|
|
846
|
+
const after = await readdir(tmpdir());
|
|
847
|
+
expect(after.filter((name) => name.startsWith("aai-call-audit-"))).toEqual(
|
|
848
|
+
before.filter((name) => name.startsWith("aai-call-audit-")),
|
|
849
|
+
);
|
|
850
|
+
});
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
describe("the body's step policy", () => {
|
|
854
|
+
/**
|
|
855
|
+
* A `ctx.now` that answers each reach from `samples`, in order.
|
|
856
|
+
*
|
|
857
|
+
* The last value repeats rather than running out: a spec naming two reads
|
|
858
|
+
* should fail on the DURATION if the body grows a third, not on an
|
|
859
|
+
* `undefined` from the fake.
|
|
860
|
+
*/
|
|
861
|
+
const clockReads = (...samples: readonly number[]) => {
|
|
862
|
+
let reach = 0;
|
|
863
|
+
return () => samples[Math.min(reach++, samples.length - 1)] ?? 0;
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* A `ctx` that walks the whole body without running a single step.
|
|
868
|
+
*
|
|
869
|
+
* `runSteps: false` plus one journaled result per step name: no ffmpeg, no
|
|
870
|
+
* provider, no model. Both specs below need the identical skeleton and each
|
|
871
|
+
* only reads `ctx.steps` afterwards, so it is built once.
|
|
872
|
+
*/
|
|
873
|
+
const walkedCtx = () =>
|
|
874
|
+
createWorkflowContext({
|
|
875
|
+
runSteps: false,
|
|
876
|
+
// The body reads the clock at both ends with `ctx.now()`, which the engine
|
|
877
|
+
// journals under `now!0` and `now!1`. A PRODUCER here rather than a fixed
|
|
878
|
+
// number, so the two reaches differ and `elapsedMs` is assertable — based
|
|
879
|
+
// on `WORKFLOW_CONTEXT_NOW`, the instant the fake otherwise freezes at, rather
|
|
880
|
+
// than on a second arbitrary epoch nobody can relate to the first.
|
|
881
|
+
now: clockReads(WORKFLOW_CONTEXT_NOW, WORKFLOW_CONTEXT_NOW + 3000),
|
|
882
|
+
results: {
|
|
883
|
+
ingestRecording: {
|
|
884
|
+
audio: "upl_pcm",
|
|
885
|
+
source: "call.wav",
|
|
886
|
+
codec: "pcm_s16le",
|
|
887
|
+
durationMs: 20_000,
|
|
888
|
+
bytes: 60 * BYTES_PER_SECOND,
|
|
889
|
+
silences: pauses(10, 20, 30),
|
|
890
|
+
loudness: MEASURED,
|
|
891
|
+
ffmpegMs: 1200,
|
|
892
|
+
},
|
|
893
|
+
transcribeSegment: { index: 0, text: "hello" },
|
|
894
|
+
summarize: { headline: "H", risks: [], actions: [], spoken: "S." },
|
|
895
|
+
narrate: { audio: "upl_wav", durationMs: 500, bytes: 32, ffmpegMs: 300 },
|
|
896
|
+
},
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
test("raises the attempt budget on both steps whose failure is transient I/O", async () => {
|
|
900
|
+
// The retry policy is an argument to `ctx.step` now rather than a
|
|
901
|
+
// `maxRetries` property, so the CALL is the only place it is observable —
|
|
902
|
+
// which is also the honest place for it, since the same function called from
|
|
903
|
+
// two sites may deserve different patience.
|
|
904
|
+
const ctx = walkedCtx();
|
|
905
|
+
|
|
906
|
+
await auditFlow({ recording: UPLOAD_ID }, ctx);
|
|
907
|
+
|
|
908
|
+
const budgets = new Map(ctx.steps.map((step) => [step.name, step.maxAttempts]));
|
|
909
|
+
// The EXACT number, not `toBeGreaterThan(3)`: the value is a literal in the
|
|
910
|
+
// body and a typo'd `maxAttempts: 4` is exactly what this should catch.
|
|
911
|
+
expect(budgets.get("ingestRecording")).toBe(6);
|
|
912
|
+
expect(budgets.get("transcribeSegment")).toBe(6);
|
|
913
|
+
// The clock and the two model-shaped steps take the default, which is the
|
|
914
|
+
// other half of the claim: a raised budget is a decision about ONE step.
|
|
915
|
+
// Asserted as PRESENT-with-no-budget rather than as `get(…) === undefined`,
|
|
916
|
+
// which a step the body never reached at all would also satisfy.
|
|
917
|
+
for (const name of ["narrate", "summarize"]) {
|
|
918
|
+
expect(budgets.has(name)).toBe(true);
|
|
919
|
+
expect(budgets.get(name)).toBeUndefined();
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
test("reads the clock with `ctx.now()` at each end, and subtracts in the body", async () => {
|
|
924
|
+
// Two reaches of one method, keyed `now!0` and `now!1` and journaled
|
|
925
|
+
// separately by the engine. This used to be two NAMED steps over an exported
|
|
926
|
+
// one-line clock read, and the names existed only so a person reading the
|
|
927
|
+
// run's history could tell the ends apart; the affordance journals the read
|
|
928
|
+
// itself. What is left to assert is that the body subtracts two journaled
|
|
929
|
+
// values rather than re-reading a clock, which is what makes a replay report
|
|
930
|
+
// the same elapsed.
|
|
931
|
+
const ctx = walkedCtx();
|
|
932
|
+
|
|
933
|
+
const output = await auditFlow({ recording: UPLOAD_ID }, ctx);
|
|
934
|
+
|
|
935
|
+
expect(output.elapsedMs).toBe(3000);
|
|
936
|
+
// And the ffmpeg time is SUMMED from the two journaled step results rather
|
|
937
|
+
// than measured again — which is what makes a replay report what the passes
|
|
938
|
+
// really cost instead of zero for work it did not redo.
|
|
939
|
+
expect(output.ffmpegMs).toBe(1500);
|
|
940
|
+
// And the clock is no longer a step, which is the other half of the claim: a
|
|
941
|
+
// name here would mean the migration left one behind.
|
|
942
|
+
expect(ctx.steps.map((step) => step.name)).not.toContain("clockStart");
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* `auditFlow` on the real replay engine — as far as this tier can take it.
|
|
948
|
+
*
|
|
949
|
+
* The block above drives the body through `createWorkflowContext` with
|
|
950
|
+
* `runSteps: false` and a journaled result per step, which is what makes it
|
|
951
|
+
* affordable: `ingestRecording` shells out to the ffmpeg toolchain, which this
|
|
952
|
+
* tier cannot usefully feed — the `ingestRecording` and `narrate` specs above
|
|
953
|
+
* assert the `FatalError` that produces, unconditionally.
|
|
954
|
+
*
|
|
955
|
+
* **The run fails here whether or not ffmpeg is installed, and the two failures
|
|
956
|
+
* do not say the same thing** — which is what the assertion below has to be
|
|
957
|
+
* written against. With no binary on `PATH` the step reports the missing
|
|
958
|
+
* toolchain as an instruction (the template's own doc promises that rather than
|
|
959
|
+
* `spawn ffmpeg ENOENT`); WITH one, the step gets a step further and `ffprobe`
|
|
960
|
+
* rejects the 2 KB stub above with `ffprobe exited with code 1`. This docblock
|
|
961
|
+
* used to state "this repo's test environment has none" as a premise, and the
|
|
962
|
+
* spec below matched `/ffmpeg/i` on the strength of it — so the test passed only
|
|
963
|
+
* on a machine where ffmpeg was ABSENT, and a developer with Homebrew's ffmpeg
|
|
964
|
+
* saw a red suite on a clean checkout of `main`. CI has no ffmpeg, so nothing
|
|
965
|
+
* caught it.
|
|
966
|
+
*
|
|
967
|
+
* So a whole run of this desk is not reachable here and this file does not
|
|
968
|
+
* pretend otherwise; `aai-cli`'s `dev-workflow.scenario.test.ts` is the tier
|
|
969
|
+
* with a built project. What IS reachable, and what nothing else asserts, is the
|
|
970
|
+
* ENGINE's half of the fatal/retryable contract: a step that throws a
|
|
971
|
+
* `FatalError` must fail its run on the first attempt rather than spending the
|
|
972
|
+
* six this body asks for. The step specs above assert the class; only a real
|
|
973
|
+
* engine can assert what the class is FOR.
|
|
974
|
+
*/
|
|
975
|
+
describe("the run is DURABLE, as far as ffmpeg allows", () => {
|
|
976
|
+
beforeEach(() => {
|
|
977
|
+
installStubUploads({
|
|
978
|
+
[UPLOAD_ID]: { bytes: new Uint8Array(2048), name: "call.m4a", type: "audio/mp4" },
|
|
979
|
+
});
|
|
980
|
+
installStubReporter();
|
|
981
|
+
vi.stubEnv("ASSEMBLYAI_API_KEY", "test-key");
|
|
982
|
+
// Neither binary is this block's subject (see its doc), and a real
|
|
983
|
+
// conversion here would make a developer with ffmpeg installed run a
|
|
984
|
+
// slower, different test from CI, which has none.
|
|
985
|
+
vi.stubEnv("AAI_FFMPEG_PATH", "/nonexistent/ffmpeg");
|
|
986
|
+
vi.stubEnv("AAI_FFPROBE_PATH", "/nonexistent/ffprobe");
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
test("a FatalError in the first step fails the run on ONE attempt, not six", async () => {
|
|
990
|
+
const run = await runWorkflow(audit, { recording: UPLOAD_ID }, { name: "audit" });
|
|
991
|
+
|
|
992
|
+
expect(run.status).toBe("failed");
|
|
993
|
+
// Either member of the toolchain, for the reason this block's doc gives: the
|
|
994
|
+
// step names `ffmpeg` when the binary is missing and `ffprobe` when it is
|
|
995
|
+
// present, and this spec is about neither. What it is about is the two
|
|
996
|
+
// assertions below — the ENGINE honouring `FatalError`.
|
|
997
|
+
expect(run.error).toMatch(/ff(mpeg|probe)/i);
|
|
998
|
+
const ingest = run.steps.find((step) => step.name === "ingestRecording");
|
|
999
|
+
// The whole point of `FatalError`: `maxAttempts: 6` is the budget this call
|
|
1000
|
+
// site asks for, and a failure that cannot change must not spend it. A step
|
|
1001
|
+
// that burned all six here would delay the real error by minutes in
|
|
1002
|
+
// production and cost five more conversions of a file that is not going to
|
|
1003
|
+
// convert.
|
|
1004
|
+
expect(ingest?.status).toBe("failed");
|
|
1005
|
+
expect(ingest?.attempts).toBe(1);
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
test("the failure is DURABLE: a redelivery reports it rather than trying again", async () => {
|
|
1009
|
+
const run = await runWorkflow(audit, { recording: UPLOAD_ID }, { name: "audit" });
|
|
1010
|
+
expect(run.status).toBe("failed");
|
|
1011
|
+
|
|
1012
|
+
// A terminal run is done, and a redelivery of one is ordinary rather than an
|
|
1013
|
+
// error — the platform's queue acks on a 200, so any delivery whose ack was
|
|
1014
|
+
// lost arrives again after the run finished.
|
|
1015
|
+
await run.restart();
|
|
1016
|
+
expect(run.status).toBe("failed");
|
|
1017
|
+
expect(run.steps.filter((step) => step.name === "ingestRecording")).toHaveLength(1);
|
|
1018
|
+
expect(run.deliveries).toBe(2);
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
test("the clock is journaled BEFORE the step that fails, so the run's start survives", async () => {
|
|
1022
|
+
// `ctx.now()` and the ingest are issued together in one `Promise.all`, so a
|
|
1023
|
+
// failing ingest must not lose the clock read that went out beside it. It is
|
|
1024
|
+
// journaled through the same append a step is, into a key space of its own —
|
|
1025
|
+
// which is why it reads back off `reads` rather than `steps`.
|
|
1026
|
+
const run = await runWorkflow(audit, { recording: UPLOAD_ID }, { name: "audit" });
|
|
1027
|
+
|
|
1028
|
+
const clock = run.reads.find((read) => read.key === "now!0");
|
|
1029
|
+
expect(clock?.kind).toBe("now");
|
|
1030
|
+
expect(typeof clock?.value).toBe("number");
|
|
1031
|
+
});
|
|
1032
|
+
});
|