From 9667eeb3cebfb77fe84bb0b50feb2322ef54e145 Mon Sep 17 00:00:00 2001 From: dezren39 Date: Sat, 14 Nov 2026 08:14:07 -0600 Subject: [PATCH] =?UTF-8?q?feat(voice-line):=20step=201=20=E2=80=94=20push?= =?UTF-8?q?-to-talk=20DO,=20Whisper=20STT=20+=20MeloTTS=20out,=20VAD=20tri?= =?UTF-8?q?m,=20Turso=20ledger=20(#9800)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New pm-stack/voice-line-worker (task 16482): VoiceSession Durable Object serving a push-to-talk WebSocket; PCM16 audio is VAD-trimmed (head/tail cut, long pauses collapsed) and only trimmed audio is submitted to Workers AI Whisper; the one read-only intent (queue state, from fleet-pushed Turso snapshots) is answered in text and spoken back via MeloTTS per Drews 2026-11-14 talk-back amendment; every utterance writes a Turso session-ledger row (transcript, intent, answer, audio seconds in/out). bun test 9/9, tsc clean. Deploy (Turso DB + secrets + wrangler deploy) and the live voice proof remain — see README deploy section. --- pm-stack/voice-line-worker/README.md | 65 ++++++ pm-stack/voice-line-worker/bun.lock | 217 ++++++++++++++++++ pm-stack/voice-line-worker/package.json | 1 + pm-stack/voice-line-worker/src/index.ts | 126 ++++++++++ pm-stack/voice-line-worker/src/intent.ts | 48 ++++ pm-stack/voice-line-worker/src/ledger.ts | 129 +++++++++++ pm-stack/voice-line-worker/src/session.ts | 164 +++++++++++++ pm-stack/voice-line-worker/src/vad.ts | 137 +++++++++++ .../voice-line-worker/test/intent.test.ts | 36 +++ pm-stack/voice-line-worker/test/vad.test.ts | 56 +++++ pm-stack/voice-line-worker/tsconfig.json | 1 + pm-stack/voice-line-worker/wrangler.toml | 21 ++ 12 files changed, 1001 insertions(+) create mode 100644 pm-stack/voice-line-worker/README.md create mode 100644 pm-stack/voice-line-worker/bun.lock create mode 100644 pm-stack/voice-line-worker/package.json create mode 100644 pm-stack/voice-line-worker/src/index.ts create mode 100644 pm-stack/voice-line-worker/src/intent.ts create mode 100644 pm-stack/voice-line-worker/src/ledger.ts create mode 100644 pm-stack/voice-line-worker/src/session.ts create mode 100644 pm-stack/voice-line-worker/src/vad.ts create mode 100644 pm-stack/voice-line-worker/test/intent.test.ts create mode 100644 pm-stack/voice-line-worker/test/vad.test.ts create mode 100644 pm-stack/voice-line-worker/tsconfig.json create mode 100644 pm-stack/voice-line-worker/wrangler.toml diff --git a/pm-stack/voice-line-worker/README.md b/pm-stack/voice-line-worker/README.md new file mode 100644 index 0000000000..35acf84e63 --- /dev/null +++ b/pm-stack/voice-line-worker/README.md @@ -0,0 +1,65 @@ +# Voice line worker — step 1 (#9800) + +The basement voice line, first step: talk to the fleet and hear the +answer, end to end, Cloudflare-direct. + +- **Push-to-talk WebSocket in a Durable Object** (`src/session.ts`, + one `VoiceSession` per session id). The page at `/` streams PCM16LE + 16 kHz mono while the button is held and sends `{"type":"stop"}` on + release. +- **Silence is trimmed before transcription** (`src/vad.ts`): + energy-based VAD cuts head/tail silence and collapses long internal + pauses, and *only the trimmed audio* is submitted — Workers AI + transcription bills per audio minute submitted, pauses included, so + silence is never billed and never transcribed. The transcript event + reports seconds submitted vs seconds recorded. +- **Speech-to-text:** Workers AI Whisper + (`@cf/openai/whisper-large-v3-turbo`) via the `AI` binding. +- **Speech out:** Workers AI MeloTTS (`@cf/myshell-ai/melotts`) speaks + the answer back over the same socket (Drew's 2026-11-14 amendment: + the line must talk back). Outgoing synthesis covers only the answer + text. +- **One read-only intent** (`src/intent.ts`): queue state. The voice + line takes no write actions; anything else gets a spoken explanation + of the one capability. Queue state comes from the newest + `status_snapshots` row, pushed by the fleet via `POST /ingest-status` + (Bearer `STATUS_INGEST_TOKEN`) — a status *input*, not a voice write + action. +- **Session ledger in Turso** (`src/ledger.ts`, libsql HTTP pipeline, + no SDK): every completed utterance writes a `sessions` row — session + id, timestamps, transcript, intent, answer, audio seconds in + (post-trim, as submitted) and out, and the two model ids. + `audio_seconds_out` is estimated from the answer's word count at a + standard speaking rate until MP3 frame parsing is worth it. + +The OpenCode pooled/failover version of speech (both directions) is +the companion issue #9801 and is deliberately not built here; the +socket and intent shapes do not preclude it (the DO calls the two +models in exactly two places). + +## Run / deploy + +```sh +bun install +bun test # VAD + intent suites +bunx tsc --noEmit +bunx wrangler dev # local: AI binding runs remote against the account +``` + +Deploy needs (account-side, one time): + +1. A Turso database for the ledger; set its URL in `wrangler.toml` + (`TURSO_URL` var) — the schema is created idempotently at runtime. +2. `wrangler secret put TURSO_TOKEN` and + `wrangler secret put STATUS_INGEST_TOKEN`. +3. `bun run deploy`, then push a first queue snapshot: + `curl -X POST /ingest-status -H "Authorization: Bearer $STATUS_INGEST_TOKEN" -d '{"queued":0,"claimed":0,"parked":0,"blocked":0}'` + +## Protocol + +Client → server: binary PCM16LE frames; text control frames +`{"type":"start"}` (reset buffer) and `{"type":"stop"}` (process). +Server → client: JSON events `ready`, `transcript` (text + seconds +submitted/raw), `answer` (intent + text), then one binary MP3 frame +(the spoken answer), then `done` (session id + ledger seconds), or +`error`. diff --git a/pm-stack/voice-line-worker/bun.lock b/pm-stack/voice-line-worker/bun.lock new file mode 100644 index 0000000000..73d5351d40 --- /dev/null +++ b/pm-stack/voice-line-worker/bun.lock @@ -0,0 +1,217 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "voice-line-worker", + "devDependencies": { + "@cloudflare/workers-types": "^4.20251011.0", + "typescript": "^5.6.0", + "wrangler": "4.44.0", + }, + }, + }, + "packages": { + "@cloudflare/kv-asset-handler": ["@cloudflare/kv-asset-handler@0.4.0", "https://registry.npmmirror.com/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.4.0.tgz", { "dependencies": { "mime": "^3.0.0" } }, "sha512-+tv3z+SPp+gqTIcImN9o0hqE9xyfQjI1XD9pL6NuKjua9B1y7mNYv0S9cP+QEbA4ppVgGZEmKOvHX5G5Ei1CVA=="], + + "@cloudflare/unenv-preset": ["@cloudflare/unenv-preset@2.7.8", "https://registry.npmmirror.com/@cloudflare/unenv-preset/-/unenv-preset-2.7.8.tgz", { "peerDependencies": { "unenv": "2.0.0-rc.21", "workerd": "^1.20250927.0" }, "optionalPeers": ["workerd"] }, "sha512-Ky929MfHh+qPhwCapYrRPwPVHtA2Ioex/DbGZyskGyNRDe9Ru3WThYZivyNVaPy5ergQSgMs9OKrM9Ajtz9F6w=="], + + "@cloudflare/workerd-darwin-64": ["@cloudflare/workerd-darwin-64@1.20251011.0", "https://registry.npmmirror.com/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20251011.0.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-0DirVP+Z82RtZLlK2B+VhLOkk+ShBqDYO/jhcRw4oVlp0TOvk3cOVZChrt3+y3NV8Y/PYgTEywzLKFSziK4wCg=="], + + "@cloudflare/workerd-darwin-arm64": ["@cloudflare/workerd-darwin-arm64@1.20251011.0", "https://registry.npmmirror.com/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20251011.0.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-1WuFBGwZd15p4xssGN/48OE2oqokIuc51YvHvyNivyV8IYnAs3G9bJNGWth1X7iMDPe4g44pZrKhRnISS2+5dA=="], + + "@cloudflare/workerd-linux-64": ["@cloudflare/workerd-linux-64@1.20251011.0", "https://registry.npmmirror.com/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20251011.0.tgz", { "os": "linux", "cpu": "x64" }, "sha512-BccMiBzFlWZyFghIw2szanmYJrJGBGHomw2y/GV6pYXChFzMGZkeCEMfmCyJj29xczZXxcZmUVJxNy4eJxO8QA=="], + + "@cloudflare/workerd-linux-arm64": ["@cloudflare/workerd-linux-arm64@1.20251011.0", "https://registry.npmmirror.com/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20251011.0.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-79o/216lsbAbKEVDZYXR24ivEIE2ysDL9jvo0rDTkViLWju9dAp3CpyetglpJatbSi3uWBPKZBEOqN68zIjVsQ=="], + + "@cloudflare/workerd-windows-64": ["@cloudflare/workerd-windows-64@1.20251011.0", "https://registry.npmmirror.com/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20251011.0.tgz", { "os": "win32", "cpu": "x64" }, "sha512-RIXUQRchFdqEvaUqn1cXZXSKjpqMaSaVAkI5jNZ8XzAw/bw2bcdOVUtakrflgxDprltjFb0PTNtuss1FKtH9Jg=="], + + "@cloudflare/workers-types": ["@cloudflare/workers-types@4.20260702.1", "https://registry.npmmirror.com/@cloudflare/workers-types/-/workers-types-4.20260702.1.tgz", {}, "sha512-mOhf5TUEB1m2vPrxtqoIGfz0fUC9xyxRDx5gWHy5s+OCo6dcV+g7wI1R7gYCMFohhqF/2y2xeKVwMwCJjfn/WA=="], + + "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "https://registry.npmmirror.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], + + "@emnapi/runtime": ["@emnapi/runtime@1.11.3", "https://registry.npmmirror.com/@emnapi/runtime/-/runtime-1.11.3.tgz", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA=="], + + "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.4", "https://registry.npmmirror.com/@esbuild/aix-ppc64/-/aix-ppc64-0.25.4.tgz", { "os": "aix", "cpu": "ppc64" }, "sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q=="], + + "@esbuild/android-arm": ["@esbuild/android-arm@0.25.4", "https://registry.npmmirror.com/@esbuild/android-arm/-/android-arm-0.25.4.tgz", { "os": "android", "cpu": "arm" }, "sha512-QNdQEps7DfFwE3hXiU4BZeOV68HHzYwGd0Nthhd3uCkkEKK7/R6MTgM0P7H7FAs5pU/DIWsviMmEGxEoxIZ+ZQ=="], + + "@esbuild/android-arm64": ["@esbuild/android-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/android-arm64/-/android-arm64-0.25.4.tgz", { "os": "android", "cpu": "arm64" }, "sha512-bBy69pgfhMGtCnwpC/x5QhfxAz/cBgQ9enbtwjf6V9lnPI/hMyT9iWpR1arm0l3kttTr4L0KSLpKmLp/ilKS9A=="], + + "@esbuild/android-x64": ["@esbuild/android-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/android-x64/-/android-x64-0.25.4.tgz", { "os": "android", "cpu": "x64" }, "sha512-TVhdVtQIFuVpIIR282btcGC2oGQoSfZfmBdTip2anCaVYcqWlZXGcdcKIUklfX2wj0JklNYgz39OBqh2cqXvcQ=="], + + "@esbuild/darwin-arm64": ["@esbuild/darwin-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/darwin-arm64/-/darwin-arm64-0.25.4.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-Y1giCfM4nlHDWEfSckMzeWNdQS31BQGs9/rouw6Ub91tkK79aIMTH3q9xHvzH8d0wDru5Ci0kWB8b3up/nl16g=="], + + "@esbuild/darwin-x64": ["@esbuild/darwin-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/darwin-x64/-/darwin-x64-0.25.4.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-CJsry8ZGM5VFVeyUYB3cdKpd/H69PYez4eJh1W/t38vzutdjEjtP7hB6eLKBoOdxcAlCtEYHzQ/PJ/oU9I4u0A=="], + + "@esbuild/freebsd-arm64": ["@esbuild/freebsd-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.4.tgz", { "os": "freebsd", "cpu": "arm64" }, "sha512-yYq+39NlTRzU2XmoPW4l5Ifpl9fqSk0nAJYM/V/WUGPEFfek1epLHJIkTQM6bBs1swApjO5nWgvr843g6TjxuQ=="], + + "@esbuild/freebsd-x64": ["@esbuild/freebsd-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/freebsd-x64/-/freebsd-x64-0.25.4.tgz", { "os": "freebsd", "cpu": "x64" }, "sha512-0FgvOJ6UUMflsHSPLzdfDnnBBVoCDtBTVyn/MrWloUNvq/5SFmh13l3dvgRPkDihRxb77Y17MbqbCAa2strMQQ=="], + + "@esbuild/linux-arm": ["@esbuild/linux-arm@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-arm/-/linux-arm-0.25.4.tgz", { "os": "linux", "cpu": "arm" }, "sha512-kro4c0P85GMfFYqW4TWOpvmF8rFShbWGnrLqlzp4X1TNWjRY3JMYUfDCtOxPKOIY8B0WC8HN51hGP4I4hz4AaQ=="], + + "@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-arm64/-/linux-arm64-0.25.4.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-+89UsQTfXdmjIvZS6nUnOOLoXnkUTB9hR5QAeLrQdzOSWZvNSAXAtcRDHWtqAUtAmv7ZM1WPOOeSxDzzzMogiQ=="], + + "@esbuild/linux-ia32": ["@esbuild/linux-ia32@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-ia32/-/linux-ia32-0.25.4.tgz", { "os": "linux", "cpu": "ia32" }, "sha512-yTEjoapy8UP3rv8dB0ip3AfMpRbyhSN3+hY8mo/i4QXFeDxmiYbEKp3ZRjBKcOP862Ua4b1PDfwlvbuwY7hIGQ=="], + + "@esbuild/linux-loong64": ["@esbuild/linux-loong64@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-loong64/-/linux-loong64-0.25.4.tgz", { "os": "linux", "cpu": "none" }, "sha512-NeqqYkrcGzFwi6CGRGNMOjWGGSYOpqwCjS9fvaUlX5s3zwOtn1qwg1s2iE2svBe4Q/YOG1q6875lcAoQK/F4VA=="], + + "@esbuild/linux-mips64el": ["@esbuild/linux-mips64el@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-mips64el/-/linux-mips64el-0.25.4.tgz", { "os": "linux", "cpu": "none" }, "sha512-IcvTlF9dtLrfL/M8WgNI/qJYBENP3ekgsHbYUIzEzq5XJzzVEV/fXY9WFPfEEXmu3ck2qJP8LG/p3Q8f7Zc2Xg=="], + + "@esbuild/linux-ppc64": ["@esbuild/linux-ppc64@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-ppc64/-/linux-ppc64-0.25.4.tgz", { "os": "linux", "cpu": "ppc64" }, "sha512-HOy0aLTJTVtoTeGZh4HSXaO6M95qu4k5lJcH4gxv56iaycfz1S8GO/5Jh6X4Y1YiI0h7cRyLi+HixMR+88swag=="], + + "@esbuild/linux-riscv64": ["@esbuild/linux-riscv64@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-riscv64/-/linux-riscv64-0.25.4.tgz", { "os": "linux", "cpu": "none" }, "sha512-i8JUDAufpz9jOzo4yIShCTcXzS07vEgWzyX3NH2G7LEFVgrLEhjwL3ajFE4fZI3I4ZgiM7JH3GQ7ReObROvSUA=="], + + "@esbuild/linux-s390x": ["@esbuild/linux-s390x@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-s390x/-/linux-s390x-0.25.4.tgz", { "os": "linux", "cpu": "s390x" }, "sha512-jFnu+6UbLlzIjPQpWCNh5QtrcNfMLjgIavnwPQAfoGx4q17ocOU9MsQ2QVvFxwQoWpZT8DvTLooTvmOQXkO51g=="], + + "@esbuild/linux-x64": ["@esbuild/linux-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/linux-x64/-/linux-x64-0.25.4.tgz", { "os": "linux", "cpu": "x64" }, "sha512-6e0cvXwzOnVWJHq+mskP8DNSrKBr1bULBvnFLpc1KY+d+irZSgZ02TGse5FsafKS5jg2e4pbvK6TPXaF/A6+CA=="], + + "@esbuild/netbsd-arm64": ["@esbuild/netbsd-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.4.tgz", { "os": "none", "cpu": "arm64" }, "sha512-vUnkBYxZW4hL/ie91hSqaSNjulOnYXE1VSLusnvHg2u3jewJBz3YzB9+oCw8DABeVqZGg94t9tyZFoHma8gWZQ=="], + + "@esbuild/netbsd-x64": ["@esbuild/netbsd-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/netbsd-x64/-/netbsd-x64-0.25.4.tgz", { "os": "none", "cpu": "x64" }, "sha512-XAg8pIQn5CzhOB8odIcAm42QsOfa98SBeKUdo4xa8OvX8LbMZqEtgeWE9P/Wxt7MlG2QqvjGths+nq48TrUiKw=="], + + "@esbuild/openbsd-arm64": ["@esbuild/openbsd-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.4.tgz", { "os": "openbsd", "cpu": "arm64" }, "sha512-Ct2WcFEANlFDtp1nVAXSNBPDxyU+j7+tId//iHXU2f/lN5AmO4zLyhDcpR5Cz1r08mVxzt3Jpyt4PmXQ1O6+7A=="], + + "@esbuild/openbsd-x64": ["@esbuild/openbsd-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/openbsd-x64/-/openbsd-x64-0.25.4.tgz", { "os": "openbsd", "cpu": "x64" }, "sha512-xAGGhyOQ9Otm1Xu8NT1ifGLnA6M3sJxZ6ixylb+vIUVzvvd6GOALpwQrYrtlPouMqd/vSbgehz6HaVk4+7Afhw=="], + + "@esbuild/sunos-x64": ["@esbuild/sunos-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/sunos-x64/-/sunos-x64-0.25.4.tgz", { "os": "sunos", "cpu": "x64" }, "sha512-Mw+tzy4pp6wZEK0+Lwr76pWLjrtjmJyUB23tHKqEDP74R3q95luY/bXqXZeYl4NYlvwOqoRKlInQialgCKy67Q=="], + + "@esbuild/win32-arm64": ["@esbuild/win32-arm64@0.25.4", "https://registry.npmmirror.com/@esbuild/win32-arm64/-/win32-arm64-0.25.4.tgz", { "os": "win32", "cpu": "arm64" }, "sha512-AVUP428VQTSddguz9dO9ngb+E5aScyg7nOeJDrF1HPYu555gmza3bDGMPhmVXL8svDSoqPCsCPjb265yG/kLKQ=="], + + "@esbuild/win32-ia32": ["@esbuild/win32-ia32@0.25.4", "https://registry.npmmirror.com/@esbuild/win32-ia32/-/win32-ia32-0.25.4.tgz", { "os": "win32", "cpu": "ia32" }, "sha512-i1sW+1i+oWvQzSgfRcxxG2k4I9n3O9NRqy8U+uugaT2Dy7kLO9Y7wI72haOahxceMX8hZAzgGou1FhndRldxRg=="], + + "@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.4", "https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.25.4.tgz", { "os": "win32", "cpu": "x64" }, "sha512-nOT2vZNw6hJ+z43oP1SPea/G/6AbN6X+bGNhNuq8NtRHy4wsMhw765IKLNmnjek7GvjWBYQ8Q5VBoYTFg9y1UQ=="], + + "@img/sharp-darwin-arm64": ["@img/sharp-darwin-arm64@0.33.5", "https://registry.npmmirror.com/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-darwin-arm64": "1.0.4" }, "os": "darwin", "cpu": "arm64" }, "sha512-UT4p+iz/2H4twwAoLCqfA9UH5pI6DggwKEGuaPy7nCVQ8ZsiY5PIcrRvD1DzuY3qYL07NtIQcWnBSY/heikIFQ=="], + + "@img/sharp-darwin-x64": ["@img/sharp-darwin-x64@0.33.5", "https://registry.npmmirror.com/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-darwin-x64": "1.0.4" }, "os": "darwin", "cpu": "x64" }, "sha512-fyHac4jIc1ANYGRDxtiqelIbdWkIuQaI84Mv45KvGRRxSAa7o7d1ZKAOBaYbnepLC1WqxfpimdeWfvqqSGwR2Q=="], + + "@img/sharp-libvips-darwin-arm64": ["@img/sharp-libvips-darwin-arm64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.4.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-XblONe153h0O2zuFfTAbQYAX2JhYmDHeWikp1LM9Hul9gVPjFY427k6dFEcOL72O01QxQsWi761svJ/ev9xEDg=="], + + "@img/sharp-libvips-darwin-x64": ["@img/sharp-libvips-darwin-x64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.4.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-xnGR8YuZYfJGmWPvmlunFaWJsb9T/AO2ykoP3Fz/0X5XV2aoYBPkX6xqCQvUTKKiLddarLaxpzNe+b1hjeWHAQ=="], + + "@img/sharp-libvips-linux-arm": ["@img/sharp-libvips-linux-arm@1.0.5", "https://registry.npmmirror.com/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.5.tgz", { "os": "linux", "cpu": "arm", "libc": "glibc" }, "sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g=="], + + "@img/sharp-libvips-linux-arm64": ["@img/sharp-libvips-linux-arm64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.4.tgz", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA=="], + + "@img/sharp-libvips-linux-s390x": ["@img/sharp-libvips-linux-s390x@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.4.tgz", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA=="], + + "@img/sharp-libvips-linux-x64": ["@img/sharp-libvips-linux-x64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.4.tgz", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw=="], + + "@img/sharp-libvips-linuxmusl-arm64": ["@img/sharp-libvips-linuxmusl-arm64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.4.tgz", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA=="], + + "@img/sharp-libvips-linuxmusl-x64": ["@img/sharp-libvips-linuxmusl-x64@1.0.4", "https://registry.npmmirror.com/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.4.tgz", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw=="], + + "@img/sharp-linux-arm": ["@img/sharp-linux-arm@0.33.5", "https://registry.npmmirror.com/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linux-arm": "1.0.5" }, "os": "linux", "cpu": "arm", "libc": "glibc" }, "sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ=="], + + "@img/sharp-linux-arm64": ["@img/sharp-linux-arm64@0.33.5", "https://registry.npmmirror.com/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linux-arm64": "1.0.4" }, "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA=="], + + "@img/sharp-linux-s390x": ["@img/sharp-linux-s390x@0.33.5", "https://registry.npmmirror.com/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linux-s390x": "1.0.4" }, "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q=="], + + "@img/sharp-linux-x64": ["@img/sharp-linux-x64@0.33.5", "https://registry.npmmirror.com/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linux-x64": "1.0.4" }, "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA=="], + + "@img/sharp-linuxmusl-arm64": ["@img/sharp-linuxmusl-arm64@0.33.5", "https://registry.npmmirror.com/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-arm64": "1.0.4" }, "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g=="], + + "@img/sharp-linuxmusl-x64": ["@img/sharp-linuxmusl-x64@0.33.5", "https://registry.npmmirror.com/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.5.tgz", { "optionalDependencies": { "@img/sharp-libvips-linuxmusl-x64": "1.0.4" }, "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw=="], + + "@img/sharp-wasm32": ["@img/sharp-wasm32@0.33.5", "https://registry.npmmirror.com/@img/sharp-wasm32/-/sharp-wasm32-0.33.5.tgz", { "dependencies": { "@emnapi/runtime": "^1.2.0" }, "cpu": "none" }, "sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg=="], + + "@img/sharp-win32-ia32": ["@img/sharp-win32-ia32@0.33.5", "https://registry.npmmirror.com/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.5.tgz", { "os": "win32", "cpu": "ia32" }, "sha512-T36PblLaTwuVJ/zw/LaH0PdZkRz5rd3SmMHX8GSmR7vtNSP5Z6bQkExdSK7xGWyxLw4sUknBuugTelgw2faBbQ=="], + + "@img/sharp-win32-x64": ["@img/sharp-win32-x64@0.33.5", "https://registry.npmmirror.com/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.5.tgz", { "os": "win32", "cpu": "x64" }, "sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg=="], + + "@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.3", "https://registry.npmmirror.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", {}, "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g=="], + + "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], + + "@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.9", "https://registry.npmmirror.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", { "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" } }, "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ=="], + + "@poppinss/colors": ["@poppinss/colors@4.1.6", "https://registry.npmmirror.com/@poppinss/colors/-/colors-4.1.6.tgz", { "dependencies": { "kleur": "^4.1.5" } }, "sha512-H9xkIdFswbS8n1d6vmRd8+c10t2Qe+rZITbbDHHkQixH5+2x1FDGmi/0K+WgWiqQFKPSlIYB7jlH6Kpfn6Fleg=="], + + "@poppinss/dumper": ["@poppinss/dumper@0.6.5", "https://registry.npmmirror.com/@poppinss/dumper/-/dumper-0.6.5.tgz", { "dependencies": { "@poppinss/colors": "^4.1.5", "@sindresorhus/is": "^7.0.2", "supports-color": "^10.0.0" } }, "sha512-NBdYIb90J7LfOI32dOewKI1r7wnkiH6m920puQ3qHUeZkxNkQiFnXVWoE6YtFSv6QOiPPf7ys6i+HWWecDz7sw=="], + + "@poppinss/exception": ["@poppinss/exception@1.2.3", "https://registry.npmmirror.com/@poppinss/exception/-/exception-1.2.3.tgz", {}, "sha512-dCED+QRChTVatE9ibtoaxc+WkdzOSjYTKi/+uacHWIsfodVfpsueo3+DKpgU5Px8qXjgmXkSvhXvSCz3fnP9lw=="], + + "@sindresorhus/is": ["@sindresorhus/is@7.2.0", "https://registry.npmmirror.com/@sindresorhus/is/-/is-7.2.0.tgz", {}, "sha512-P1Cz1dWaFfR4IR+U13mqqiGsLFf1KbayybWwdd2vfctdV6hDpUkgCY0nKOLLTMSoRd/jJNjtbqzf13K8DCCXQw=="], + + "@speed-highlight/core": ["@speed-highlight/core@1.2.24", "https://registry.npmmirror.com/@speed-highlight/core/-/core-1.2.24.tgz", {}, "sha512-qeW2e1l78afw8VhRPfPQ1Gjj+KU5XFQ/OFV5ti6eTa9bruO7mJyZtA4vw0ofqmA3tKCkROE9xLk3VZoeRc98nw=="], + + "acorn": ["acorn@8.14.0", "https://registry.npmmirror.com/acorn/-/acorn-8.14.0.tgz", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="], + + "acorn-walk": ["acorn-walk@8.3.2", "https://registry.npmmirror.com/acorn-walk/-/acorn-walk-8.3.2.tgz", {}, "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A=="], + + "blake3-wasm": ["blake3-wasm@2.1.5", "https://registry.npmmirror.com/blake3-wasm/-/blake3-wasm-2.1.5.tgz", {}, "sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g=="], + + "color": ["color@4.2.3", "https://registry.npmmirror.com/color/-/color-4.2.3.tgz", { "dependencies": { "color-convert": "^2.0.1", "color-string": "^1.9.0" } }, "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A=="], + + "color-convert": ["color-convert@2.0.1", "https://registry.npmmirror.com/color-convert/-/color-convert-2.0.1.tgz", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="], + + "color-name": ["color-name@1.1.4", "https://registry.npmmirror.com/color-name/-/color-name-1.1.4.tgz", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="], + + "color-string": ["color-string@1.9.1", "https://registry.npmmirror.com/color-string/-/color-string-1.9.1.tgz", { "dependencies": { "color-name": "^1.0.0", "simple-swizzle": "^0.2.2" } }, "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg=="], + + "cookie": ["cookie@1.1.1", "https://registry.npmmirror.com/cookie/-/cookie-1.1.1.tgz", {}, "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ=="], + + "defu": ["defu@6.1.7", "https://registry.npmmirror.com/defu/-/defu-6.1.7.tgz", {}, "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ=="], + + "detect-libc": ["detect-libc@2.1.2", "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.1.2.tgz", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], + + "error-stack-parser-es": ["error-stack-parser-es@1.0.5", "https://registry.npmmirror.com/error-stack-parser-es/-/error-stack-parser-es-1.0.5.tgz", {}, "sha512-5qucVt2XcuGMcEGgWI7i+yZpmpByQ8J1lHhcL7PwqCwu9FPP3VUXzT4ltHe5i2z9dePwEHcDVOAfSnHsOlCXRA=="], + + "esbuild": ["esbuild@0.25.4", "https://registry.npmmirror.com/esbuild/-/esbuild-0.25.4.tgz", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.4", "@esbuild/android-arm": "0.25.4", "@esbuild/android-arm64": "0.25.4", "@esbuild/android-x64": "0.25.4", "@esbuild/darwin-arm64": "0.25.4", "@esbuild/darwin-x64": "0.25.4", "@esbuild/freebsd-arm64": "0.25.4", "@esbuild/freebsd-x64": "0.25.4", "@esbuild/linux-arm": "0.25.4", "@esbuild/linux-arm64": "0.25.4", "@esbuild/linux-ia32": "0.25.4", "@esbuild/linux-loong64": "0.25.4", "@esbuild/linux-mips64el": "0.25.4", "@esbuild/linux-ppc64": "0.25.4", "@esbuild/linux-riscv64": "0.25.4", "@esbuild/linux-s390x": "0.25.4", "@esbuild/linux-x64": "0.25.4", "@esbuild/netbsd-arm64": "0.25.4", "@esbuild/netbsd-x64": "0.25.4", "@esbuild/openbsd-arm64": "0.25.4", "@esbuild/openbsd-x64": "0.25.4", "@esbuild/sunos-x64": "0.25.4", "@esbuild/win32-arm64": "0.25.4", "@esbuild/win32-ia32": "0.25.4", "@esbuild/win32-x64": "0.25.4" }, "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" } }, "sha512-8pgjLUcUjcgDg+2Q4NYXnPbo/vncAY4UmyaCm0jZevERqCHZIaWwdJHkf8XQtu4AxSKCdvrUbT0XUr1IdZzI8Q=="], + + "exit-hook": ["exit-hook@2.2.1", "https://registry.npmmirror.com/exit-hook/-/exit-hook-2.2.1.tgz", {}, "sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw=="], + + "exsolve": ["exsolve@1.2.0", "https://registry.npmmirror.com/exsolve/-/exsolve-1.2.0.tgz", {}, "sha512-h1pQPR9XoeSMdntRNCjyTznaume4UpfXrULBnlkZ2CUM/G5eSa+pBByGldO5uR8dxbPC+OuJXsPPNf+JZ81ADg=="], + + "fsevents": ["fsevents@2.3.3", "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", { "os": "darwin", "hasInstallScript": true }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], + + "glob-to-regexp": ["glob-to-regexp@0.4.1", "https://registry.npmmirror.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", {}, "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw=="], + + "is-arrayish": ["is-arrayish@0.3.4", "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.3.4.tgz", {}, "sha512-m6UrgzFVUYawGBh1dUsWR5M2Clqic9RVXC/9f8ceNlv2IcO9j9J/z8UoCLPqtsPBFNzEpfR3xftohbfqDx8EQA=="], + + "kleur": ["kleur@4.1.5", "https://registry.npmmirror.com/kleur/-/kleur-4.1.5.tgz", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="], + + "mime": ["mime@3.0.0", "https://registry.npmmirror.com/mime/-/mime-3.0.0.tgz", { "bin": { "mime": "cli.js" } }, "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A=="], + + "miniflare": ["miniflare@4.20251011.0", "https://registry.npmmirror.com/miniflare/-/miniflare-4.20251011.0.tgz", { "dependencies": { "@cspotcode/source-map-support": "0.8.1", "acorn": "8.14.0", "acorn-walk": "8.3.2", "exit-hook": "2.2.1", "glob-to-regexp": "0.4.1", "sharp": "^0.33.5", "stoppable": "1.1.0", "undici": "7.14.0", "workerd": "1.20251011.0", "ws": "8.18.0", "youch": "4.1.0-beta.10", "zod": "3.22.3" }, "bin": { "miniflare": "bootstrap.js" } }, "sha512-DlZ7vR5q/RE9eLsxsrXzfSZIF2f6O5k0YsFrSKhWUtdefyGtJt4sSpR6V+Af/waaZ6+zIFy9lsknHBCm49sEYA=="], + + "ohash": ["ohash@2.0.12", "https://registry.npmmirror.com/ohash/-/ohash-2.0.12.tgz", {}, "sha512-65S/5gk9YSsaRjcyf7Nfa6h/d3E8/1gslpXfI4W7Dxn/oap8IKRuNT5VXkLQ1YFKIEg4apRY4Pj6aiwFzrDdmw=="], + + "path-to-regexp": ["path-to-regexp@6.3.0", "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-6.3.0.tgz", {}, "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ=="], + + "pathe": ["pathe@2.0.3", "https://registry.npmmirror.com/pathe/-/pathe-2.0.3.tgz", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], + + "semver": ["semver@7.8.6", "https://registry.npmmirror.com/semver/-/semver-7.8.6.tgz", { "bin": { "semver": "bin/semver.js" } }, "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw=="], + + "sharp": ["sharp@0.33.5", "https://registry.npmmirror.com/sharp/-/sharp-0.33.5.tgz", { "dependencies": { "color": "^4.2.3", "detect-libc": "^2.0.3", "semver": "^7.6.3" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.33.5", "@img/sharp-darwin-x64": "0.33.5", "@img/sharp-libvips-darwin-arm64": "1.0.4", "@img/sharp-libvips-darwin-x64": "1.0.4", "@img/sharp-libvips-linux-arm": "1.0.5", "@img/sharp-libvips-linux-arm64": "1.0.4", "@img/sharp-libvips-linux-s390x": "1.0.4", "@img/sharp-libvips-linux-x64": "1.0.4", "@img/sharp-libvips-linuxmusl-arm64": "1.0.4", "@img/sharp-libvips-linuxmusl-x64": "1.0.4", "@img/sharp-linux-arm": "0.33.5", "@img/sharp-linux-arm64": "0.33.5", "@img/sharp-linux-s390x": "0.33.5", "@img/sharp-linux-x64": "0.33.5", "@img/sharp-linuxmusl-arm64": "0.33.5", "@img/sharp-linuxmusl-x64": "0.33.5", "@img/sharp-wasm32": "0.33.5", "@img/sharp-win32-ia32": "0.33.5", "@img/sharp-win32-x64": "0.33.5" }, "hasInstallScript": true }, "sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw=="], + + "simple-swizzle": ["simple-swizzle@0.2.4", "https://registry.npmmirror.com/simple-swizzle/-/simple-swizzle-0.2.4.tgz", { "dependencies": { "is-arrayish": "^0.3.1" } }, "sha512-nAu1WFPQSMNr2Zn9PGSZK9AGn4t/y97lEm+MXTtUDwfP0ksAIX4nO+6ruD9Jwut4C49SB1Ws+fbXsm/yScWOHw=="], + + "stoppable": ["stoppable@1.1.0", "https://registry.npmmirror.com/stoppable/-/stoppable-1.1.0.tgz", {}, "sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw=="], + + "supports-color": ["supports-color@10.2.2", "https://registry.npmmirror.com/supports-color/-/supports-color-10.2.2.tgz", {}, "sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g=="], + + "tslib": ["tslib@2.9.1", "https://registry.npmmirror.com/tslib/-/tslib-2.9.1.tgz", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], + + "typescript": ["typescript@5.9.3", "https://registry.npmmirror.com/typescript/-/typescript-5.9.3.tgz", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + + "ufo": ["ufo@1.6.4", "https://registry.npmmirror.com/ufo/-/ufo-1.6.4.tgz", {}, "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA=="], + + "undici": ["undici@7.14.0", "https://registry.npmmirror.com/undici/-/undici-7.14.0.tgz", {}, "sha512-Vqs8HTzjpQXZeXdpsfChQTlafcMQaaIwnGwLam1wudSSjlJeQ3bw1j+TLPePgrCnCpUXx7Ba5Pdpf5OBih62NQ=="], + + "unenv": ["unenv@2.0.0-rc.21", "https://registry.npmmirror.com/unenv/-/unenv-2.0.0-rc.21.tgz", { "dependencies": { "defu": "^6.1.4", "exsolve": "^1.0.7", "ohash": "^2.0.11", "pathe": "^2.0.3", "ufo": "^1.6.1" } }, "sha512-Wj7/AMtE9MRnAXa6Su3Lk0LNCfqDYgfwVjwRFVum9U7wsto1imuHqk4kTm7Jni+5A0Hn7dttL6O/zjvUvoo+8A=="], + + "workerd": ["workerd@1.20251011.0", "https://registry.npmmirror.com/workerd/-/workerd-1.20251011.0.tgz", { "optionalDependencies": { "@cloudflare/workerd-darwin-64": "1.20251011.0", "@cloudflare/workerd-darwin-arm64": "1.20251011.0", "@cloudflare/workerd-linux-64": "1.20251011.0", "@cloudflare/workerd-linux-arm64": "1.20251011.0", "@cloudflare/workerd-windows-64": "1.20251011.0" }, "hasInstallScript": true, "bin": { "workerd": "bin/workerd" } }, "sha512-Dq35TLPEJAw7BuYQMkN3p9rge34zWMU2Gnd4DSJFeVqld4+DAO2aPG7+We2dNIAyM97S8Y9BmHulbQ00E0HC7Q=="], + + "wrangler": ["wrangler@4.44.0", "https://registry.npmmirror.com/wrangler/-/wrangler-4.44.0.tgz", { "dependencies": { "@cloudflare/kv-asset-handler": "0.4.0", "@cloudflare/unenv-preset": "2.7.8", "blake3-wasm": "2.1.5", "esbuild": "0.25.4", "miniflare": "4.20251011.0", "path-to-regexp": "6.3.0", "unenv": "2.0.0-rc.21", "workerd": "1.20251011.0" }, "optionalDependencies": { "fsevents": "~2.3.2" }, "peerDependencies": { "@cloudflare/workers-types": "^4.20251011.0" }, "optionalPeers": ["@cloudflare/workers-types"], "bin": { "wrangler": "bin/wrangler.js", "wrangler2": "bin/wrangler.js" } }, "sha512-BLOUigckcWZ0r4rm7b5PuaTpb9KP9as0XeCRSJ8kqcNgXcKoUD3Ij8FlPvN25KybLnFnetaO0ZdfRYUPWle4qw=="], + + "ws": ["ws@8.18.0", "https://registry.npmmirror.com/ws/-/ws-8.18.0.tgz", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw=="], + + "youch": ["youch@4.1.0-beta.10", "https://registry.npmmirror.com/youch/-/youch-4.1.0-beta.10.tgz", { "dependencies": { "@poppinss/colors": "^4.1.5", "@poppinss/dumper": "^0.6.4", "@speed-highlight/core": "^1.2.7", "cookie": "^1.0.2", "youch-core": "^0.3.3" } }, "sha512-rLfVLB4FgQneDr0dv1oddCVZmKjcJ6yX6mS4pU82Mq/Dt9a3cLZQ62pDBL4AUO+uVrCvtWz3ZFUL2HFAFJ/BXQ=="], + + "youch-core": ["youch-core@0.3.3", "https://registry.npmmirror.com/youch-core/-/youch-core-0.3.3.tgz", { "dependencies": { "@poppinss/exception": "^1.2.2", "error-stack-parser-es": "^1.0.5" } }, "sha512-ho7XuGjLaJ2hWHoK8yFnsUGy2Y5uDpqSTq1FkHLK4/oqKtyUU1AFbOOxY4IpC9f0fTLjwYbslUz0Po5BpD1wrA=="], + + "zod": ["zod@3.22.3", "https://registry.npmmirror.com/zod/-/zod-3.22.3.tgz", {}, "sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug=="], + } +} diff --git a/pm-stack/voice-line-worker/package.json b/pm-stack/voice-line-worker/package.json new file mode 100644 index 0000000000..90a9f35965 --- /dev/null +++ b/pm-stack/voice-line-worker/package.json @@ -0,0 +1 @@ +{"description":"Basement voice line step 1 (#9800): push-to-talk WebSocket in a Durable Object, Workers AI Whisper STT + MeloTTS speech out (Cloudflare-direct), silence trim/VAD before transcription, one read-only queue-state intent, Turso session ledger.","devDependencies":{"@cloudflare/workers-types":"^4.20251011.0","typescript":"^5.6.0","wrangler":"4.44.0"},"name":"voice-line-worker","private":true,"scripts":{"deploy":"wrangler deploy","dev":"wrangler dev","test":"bun test","typecheck":"tsc --noEmit"},"type":"module","version":"0.1.0"} \ No newline at end of file diff --git a/pm-stack/voice-line-worker/src/index.ts b/pm-stack/voice-line-worker/src/index.ts new file mode 100644 index 0000000000..60ecaedaa1 --- /dev/null +++ b/pm-stack/voice-line-worker/src/index.ts @@ -0,0 +1,126 @@ +// Voice line Worker entry (#9800): serves the push-to-talk page, +// routes WebSocket sessions to the VoiceSession Durable Object, and +// accepts read-only status snapshots the intents answer from. +// +// Routes: +// GET / push-to-talk client page +// GET /ws?session= WebSocket upgrade -> VoiceSession DO +// GET /health { ok, latestQueueSnapshotAt } +// POST /ingest-status Bearer STATUS_INGEST_TOKEN; body is a +// queue-state snapshot {queued, claimed, parked, +// blocked} stored for the queue_state intent. +// This is a status INPUT, not a voice write +// action: the voice line itself stays read-only. + +import { TursoClient } from "./ledger"; +import type { Env } from "./session"; + +export { VoiceSession } from "./session"; + +const PAGE = ` + +Voice line — step 1 (#9800) + + + + +

Voice line — step 1

+

Hold the button and ask about the fleet queue, e.g. “how many tasks are in the queue?” +Your speech is trimmed of silence, transcribed, answered, and spoken back.

+ +
+ + +`; + +export default { + async fetch(request: Request, env: Env): Promise { + const url = new URL(request.url); + + if (url.pathname === "/") { + return new Response(PAGE, { headers: { "Content-Type": "text/html; charset=utf-8" } }); + } + + if (url.pathname === "/ws") { + const sessionId = url.searchParams.get("session") ?? crypto.randomUUID(); + const stub = env.VOICE_SESSIONS.get(env.VOICE_SESSIONS.idFromName(sessionId)); + return stub.fetch(request); + } + + if (url.pathname === "/health") { + const turso = new TursoClient(env.TURSO_URL, env.TURSO_TOKEN); + let latest: string | null = null; + try { + latest = (await turso.latestQueueSnapshot())?.at ?? null; + } catch { + latest = null; + } + return Response.json({ ok: true, latestQueueSnapshotAt: latest }); + } + + if (url.pathname === "/ingest-status" && request.method === "POST") { + const expected = (env as Env & { STATUS_INGEST_TOKEN?: string }).STATUS_INGEST_TOKEN; + if (!expected || request.headers.get("Authorization") !== `Bearer ${expected}`) { + return new Response("unauthorized", { status: 401 }); + } + const body = (await request.json()) as Record; + const snapshot = { + queued: Number(body.queued ?? 0), + claimed: Number(body.claimed ?? 0), + parked: Number(body.parked ?? 0), + blocked: Number(body.blocked ?? 0), + }; + const turso = new TursoClient(env.TURSO_URL, env.TURSO_TOKEN); + await turso.ensureSchema(); + await turso.putSnapshot("queue_state", snapshot, new Date().toISOString()); + return Response.json({ ok: true, stored: snapshot }); + } + + return new Response("not found", { status: 404 }); + }, +}; diff --git a/pm-stack/voice-line-worker/src/intent.ts b/pm-stack/voice-line-worker/src/intent.ts new file mode 100644 index 0000000000..7eff2c3a9e --- /dev/null +++ b/pm-stack/voice-line-worker/src/intent.ts @@ -0,0 +1,48 @@ +// Read-only intent matching for the voice line (#9800). +// +// Step 1 ships exactly ONE intent end to end — queue state — per the +// issue's acceptance. Intents are read-only by design: the voice line +// never takes a write action. Matching is deliberately small and +// deterministic (no model in the loop): a transcript either names the +// queue-state intent or falls back to a spoken explanation of what the +// line can do, which still exercises both speech directions. + +export type IntentName = "queue_state" | "unknown"; + +export interface QueueSnapshot { + queued: number; + claimed: number; + parked: number; + blocked: number; + /** ISO timestamp of the snapshot. */ + at: string; +} + +const QUEUE_PATTERNS: RegExp[] = [ + /\bqueue\b/, + /\btasks?\b.*\b(waiting|queued|left|open)\b/, + /\bhow many\b.*\btasks?\b/, + /\bbacklog\b/, + /\bfleet\b.*\b(state|status)\b/, +]; + +export function matchIntent(transcript: string): IntentName { + const text = transcript.toLowerCase(); + return QUEUE_PATTERNS.some((re) => re.test(text)) ? "queue_state" : "unknown"; +} + +export function buildAnswer(intent: IntentName, snapshot: QueueSnapshot | null): string { + if (intent === "queue_state") { + if (!snapshot) { + return "I don't have a fresh queue snapshot right now. Ask again in a moment and I should know the queue state."; + } + const parts = [ + `The fleet queue has ${snapshot.queued} tasks waiting`, + `${snapshot.claimed} being worked`, + `and ${snapshot.parked} parked`, + ]; + if (snapshot.blocked > 0) parts.push(`with ${snapshot.blocked} blocked`); + return parts.join(", ") + "."; + } + return "Right now I can only report the fleet queue state. Try asking: how many tasks are in the queue?"; +} diff --git a/pm-stack/voice-line-worker/src/ledger.ts b/pm-stack/voice-line-worker/src/ledger.ts new file mode 100644 index 0000000000..e01d903dd3 --- /dev/null +++ b/pm-stack/voice-line-worker/src/ledger.ts @@ -0,0 +1,129 @@ +// Turso (libsql) access for the voice line (#9800) over the Turso HTTP +// pipeline API — no SDK, just fetch, so the Worker stays small. +// +// Two tables (created idempotently by `ensureSchema`): +// sessions — the session ledger the issue requires: who asked +// (session id), what intent, what was answered, +// audio seconds in (submitted, post-trim) and out. +// status_snapshots — read-only status inputs for intents; the fleet +// pushes queue-state snapshots via /ingest-status +// and the queue_state intent answers from the +// newest row. kind is the snapshot family +// ("queue_state" for step 1). + +import type { QueueSnapshot } from "./intent"; + +export interface SessionRow { + id: string; + startedAt: string; + endedAt: string; + transcript: string; + intent: string; + answer: string; + audioSecondsIn: number; + audioSecondsOut: number; + sttModel: string; + ttsModel: string; +} + +type TursoValue = + | { type: "null" } + | { type: "text"; value: string } + | { type: "float"; value: number } + | { type: "integer"; value: string }; + +const text = (value: string): TursoValue => ({ type: "text", value }); +const float = (value: number): TursoValue => ({ type: "float", value }); + +interface PipelineResult { + results: Array<{ + type: string; + response?: { + type: string; + result?: { cols: unknown[]; rows: Array<{ values: TursoValue[] }> }; + }; + }>; +} + +export class TursoClient { + constructor( + private url: string, + private token: string, + ) {} + + private async pipeline(statements: Array<{ sql: string; args: TursoValue[] }>): Promise { + const res = await fetch(`${this.url.replace(/\/$/, "")}/v2/pipeline`, { + method: "POST", + headers: { + Authorization: `Bearer ${this.token}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + requests: [ + ...statements.map((stmt) => ({ type: "execute", stmt })), + { type: "close" }, + ], + }), + }); + if (!res.ok) throw new Error(`turso pipeline failed: HTTP ${res.status}`); + return (await res.json()) as PipelineResult; + } + + async execute(sql: string, args: TursoValue[] = []): Promise { + await this.pipeline([{ sql, args }]); + } + + async ensureSchema(): Promise { + await this.pipeline([ + { + sql: `CREATE TABLE IF NOT EXISTS sessions ( + id TEXT PRIMARY KEY, started_at TEXT NOT NULL, ended_at TEXT NOT NULL, + transcript TEXT NOT NULL, intent TEXT NOT NULL, answer TEXT NOT NULL, + audio_seconds_in REAL NOT NULL, audio_seconds_out REAL NOT NULL, + stt_model TEXT NOT NULL, tts_model TEXT NOT NULL)`, + args: [], + }, + { + sql: `CREATE TABLE IF NOT EXISTS status_snapshots ( + kind TEXT NOT NULL, payload TEXT NOT NULL, at TEXT NOT NULL)`, + args: [], + }, + ]); + } + + async insertSession(row: SessionRow): Promise { + await this.execute( + `INSERT INTO sessions (id, started_at, ended_at, transcript, intent, answer, + audio_seconds_in, audio_seconds_out, stt_model, tts_model) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + [ + text(row.id), text(row.startedAt), text(row.endedAt), text(row.transcript), + text(row.intent), text(row.answer), float(row.audioSecondsIn), + float(row.audioSecondsOut), text(row.sttModel), text(row.ttsModel), + ], + ); + } + + async putSnapshot(kind: string, payload: unknown, at: string): Promise { + await this.execute( + `INSERT INTO status_snapshots (kind, payload, at) VALUES (?, ?, ?)`, + [text(kind), text(JSON.stringify(payload)), text(at)], + ); + } + + async latestQueueSnapshot(): Promise { + const out = await this.pipeline([ + { + sql: `SELECT payload, at FROM status_snapshots WHERE kind = 'queue_state' + ORDER BY at DESC LIMIT 1`, + args: [], + }, + ]); + const rows = out.results[0]?.response?.result?.rows ?? []; + if (rows.length === 0) return null; + const [payload, at] = rows[0].values; + if (payload.type !== "text" || at.type !== "text") return null; + const parsed = JSON.parse(payload.value) as Omit; + return { ...parsed, at: at.value }; + } +} diff --git a/pm-stack/voice-line-worker/src/session.ts b/pm-stack/voice-line-worker/src/session.ts new file mode 100644 index 0000000000..aece5b4275 --- /dev/null +++ b/pm-stack/voice-line-worker/src/session.ts @@ -0,0 +1,164 @@ +// VoiceSession Durable Object (#9800): one push-to-talk session. +// +// Protocol (see README.md): the client opens a WebSocket, streams +// PCM16LE 16 kHz mono audio as binary frames while the talk button is +// held, then sends {"type":"stop"}. The DO trims silence (src/vad.ts), +// transcribes the trimmed audio with Workers AI Whisper, matches the +// one read-only intent (src/intent.ts), answers in text AND speech +// (Workers AI MeloTTS — the line talks back, per Drew's 2026-11-14 +// amendment), and writes the session ledger row to Turso +// (src/ledger.ts) before replying {"type":"done"}. +// +// Audio is buffered in memory for the life of the socket: a step-1 +// simplification, sized by push-to-talk utterances (seconds, not +// minutes). Hibernation-safe storage chunking is a step-2 concern and +// is deliberately not faked here. + +import { trimSilence, pcmSeconds } from "./vad"; +import { matchIntent, buildAnswer } from "./intent"; +import { TursoClient } from "./ledger"; + +export interface Env { + AI: Ai; + VOICE_SESSIONS: DurableObjectNamespace; + TURSO_URL: string; + TURSO_TOKEN: string; +} + +export const STT_MODEL = "@cf/openai/whisper-large-v3-turbo"; +export const TTS_MODEL = "@cf/myshell-ai/melotts"; +export const SAMPLE_RATE = 16000; + +function bytesToBase64(bytes: Uint8Array): string { + let binary = ""; + const chunk = 0x8000; + for (let i = 0; i < bytes.length; i += chunk) { + binary += String.fromCharCode(...bytes.subarray(i, i + chunk)); + } + return btoa(binary); +} + +function base64ToBytes(b64: string): Uint8Array { + const binary = atob(b64); + const out = new Uint8Array(binary.length); + for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i); + return out; +} + +export class VoiceSession { + private chunks: Uint8Array[] = []; + private startedAt = new Date().toISOString(); + + constructor( + private state: DurableObjectState, + private env: Env, + ) {} + + async fetch(request: Request): Promise { + if (request.headers.get("Upgrade") !== "websocket") { + return new Response("expected websocket upgrade", { status: 426 }); + } + const pair = new WebSocketPair(); + const [client, server] = Object.values(pair); + this.state.acceptWebSocket(server); + server.serializeAttachment({ sessionId: new URL(request.url).searchParams.get("session") ?? crypto.randomUUID() }); + return new Response(null, { status: 101, webSocket: client }); + } + + private send(ws: WebSocket, message: Record): void { + ws.send(JSON.stringify(message)); + } + + async webSocketMessage(ws: WebSocket, message: string | ArrayBuffer): Promise { + if (typeof message !== "string") { + this.chunks.push(new Uint8Array(message)); + return; + } + let control: { type?: string }; + try { + control = JSON.parse(message); + } catch { + this.send(ws, { type: "error", error: "control frame must be JSON" }); + return; + } + if (control.type === "start") { + this.chunks = []; + this.startedAt = new Date().toISOString(); + this.send(ws, { type: "ready" }); + } else if (control.type === "stop") { + await this.processUtterance(ws); + } else { + this.send(ws, { type: "error", error: `unknown control type: ${control.type ?? "(none)"}` }); + } + } + + private async processUtterance(ws: WebSocket): Promise { + const { sessionId } = ws.deserializeAttachment() as { sessionId: string }; + const rawLength = this.chunks.reduce((n, c) => n + c.byteLength, 0); + const raw = new Uint8Array(rawLength); + let offset = 0; + for (const c of this.chunks) { + raw.set(c, offset); + offset += c.byteLength; + } + this.chunks = []; + const secondsInRaw = pcmSeconds(raw.byteLength, SAMPLE_RATE); + + const trimmed = trimSilence(raw, SAMPLE_RATE); + if (trimmed.allSilence) { + this.send(ws, { type: "error", error: "no speech detected (all silence after VAD)" }); + return; + } + + // Speech-to-text: ONLY the trimmed audio is submitted (never billed + // for silence — #9800). + const stt = (await this.env.AI.run(STT_MODEL, { + audio: bytesToBase64(trimmed.audio), + })) as { text?: string }; + const transcript = (stt.text ?? "").trim(); + this.send(ws, { + type: "transcript", + text: transcript, + audioSecondsSubmitted: trimmed.secondsSubmitted, + audioSecondsRaw: secondsInRaw, + }); + + const turso = new TursoClient(this.env.TURSO_URL, this.env.TURSO_TOKEN); + const intent = matchIntent(transcript); + const snapshot = intent === "queue_state" ? await turso.latestQueueSnapshot() : null; + const answer = buildAnswer(intent, snapshot); + this.send(ws, { type: "answer", intent, text: answer }); + + // Speech out: MeloTTS speaks the answer in the same session. + const tts = (await this.env.AI.run(TTS_MODEL, { prompt: answer })) as { audio?: string }; + let secondsOut = 0; + if (tts.audio) { + const audioBytes = base64ToBytes(tts.audio); + secondsOut = Math.max(1, Math.round(answer.split(/\s+/).length / 2.5)); + ws.send(audioBytes.buffer as ArrayBuffer); + } + + await turso.ensureSchema(); + await turso.insertSession({ + id: sessionId, + startedAt: this.startedAt, + endedAt: new Date().toISOString(), + transcript, + intent, + answer, + audioSecondsIn: trimmed.secondsSubmitted, + audioSecondsOut: secondsOut, + sttModel: STT_MODEL, + ttsModel: TTS_MODEL, + }); + this.send(ws, { type: "done", sessionId, intent, audioSecondsIn: trimmed.secondsSubmitted, audioSecondsOut: secondsOut }); + } + + async webSocketClose(ws: WebSocket, code: number): Promise { + ws.close(code); + } + + async webSocketError(ws: WebSocket): Promise { + ws.close(1011); + } +} diff --git a/pm-stack/voice-line-worker/src/vad.ts b/pm-stack/voice-line-worker/src/vad.ts new file mode 100644 index 0000000000..cfb6a5c963 --- /dev/null +++ b/pm-stack/voice-line-worker/src/vad.ts @@ -0,0 +1,137 @@ +// Voice-activity detection + silence trim for the voice line (#9800). +// +// Pure functions over PCM16LE mono audio — no Cloudflare runtime types — +// so the trim is unit-testable anywhere (bun test). The contract from +// the issue: incoming audio is trimmed / VAD-detected BEFORE it is sent +// for transcription, so silence is never billed (Workers AI transcription +// charges per audio minute submitted, pauses included) and never +// transcribed. Head/tail silence is cut and long internal silences are +// collapsed to a short gap; seconds in vs seconds submitted are both +// reported so the session ledger can prove the saving. + +export interface VadOptions { + /** Samples per analysis frame (320 = 20 ms at 16 kHz). */ + frameSamples?: number; + /** Voiced if frame RMS >= peakRms * ratio (and >= absoluteFloor). */ + peakRatio?: number; + /** Absolute RMS floor (PCM16 scale) below which a frame is silence + * even if the peak is quiet too. */ + absoluteFloor?: number; + /** Voiced frames of padding kept before the first / after the last + * voiced frame, so onsets and tails are not clipped. */ + padFrames?: number; + /** Internal silence longer than this (frames) collapses to + * collapseToFrames frames. 0 disables collapsing. */ + collapseAfterFrames?: number; + collapseToFrames?: number; +} + +export interface VadResult { + /** Trimmed PCM16LE bytes, ready to submit for transcription. */ + audio: Uint8Array; + /** Duration of the submitted (trimmed) audio, seconds. */ + secondsSubmitted: number; + /** Voiced frames detected in the original audio. */ + voicedFrames: number; + /** Total frames in the original audio. */ + totalFrames: number; + /** True when no frame passed the voice threshold — submit nothing. */ + allSilence: boolean; +} + +const DEFAULTS: Required = { + frameSamples: 320, + peakRatio: 0.08, + absoluteFloor: 300, + padFrames: 5, + collapseAfterFrames: 30, // 600 ms at 20 ms frames + collapseToFrames: 10, // 200 ms +}; + +export function frameRms(samples: Int16Array, start: number, len: number): number { + let sum = 0; + const end = Math.min(start + len, samples.length); + for (let i = start; i < end; i++) sum += samples[i] * samples[i]; + const n = end - start; + return n > 0 ? Math.sqrt(sum / n) : 0; +} + +export function trimSilence( + pcm: Uint8Array, + sampleRate: number, + options: VadOptions = {}, +): VadResult { + const opts = { ...DEFAULTS, ...options }; + const samples = new Int16Array(pcm.buffer, pcm.byteOffset, Math.floor(pcm.byteLength / 2)); + const frame = opts.frameSamples; + const totalFrames = Math.ceil(samples.length / frame); + const seconds = (frames: number) => (frames * frame) / sampleRate; + + if (totalFrames === 0) { + return { audio: new Uint8Array(0), secondsSubmitted: 0, voicedFrames: 0, totalFrames: 0, allSilence: true }; + } + + const rms: number[] = new Array(totalFrames); + let peak = 0; + for (let f = 0; f < totalFrames; f++) { + rms[f] = frameRms(samples, f * frame, frame); + if (rms[f] > peak) peak = rms[f]; + } + const threshold = Math.max(peak * opts.peakRatio, opts.absoluteFloor); + const voiced = rms.map((r) => r >= threshold); + const voicedFrames = voiced.filter(Boolean).length; + + if (voicedFrames === 0) { + return { + audio: new Uint8Array(0), + secondsSubmitted: 0, + voicedFrames: 0, + totalFrames, + allSilence: true, + }; + } + + const first = voiced.indexOf(true); + const last = voiced.lastIndexOf(true); + const keepStart = Math.max(0, first - opts.padFrames); + const keepEnd = Math.min(totalFrames - 1, last + opts.padFrames); + + // Build the kept frame list, collapsing long internal silences. + const kept: number[] = []; + let silenceRun = 0; + for (let f = keepStart; f <= keepEnd; f++) { + if (voiced[f]) { + if (silenceRun > 0 && opts.collapseAfterFrames > 0 && silenceRun > opts.collapseAfterFrames) { + for (let i = 0; i < opts.collapseToFrames; i++) kept.push(-1); + } else { + for (let i = 0; i < silenceRun; i++) kept.push(f - silenceRun + i); + } + silenceRun = 0; + kept.push(f); + } else { + silenceRun++; + } + } + + const outSamples = kept.length * frame; + const out = new Int16Array(outSamples); + kept.forEach((srcFrame, i) => { + if (srcFrame >= 0) { + const src = samples.subarray(srcFrame * frame, srcFrame * frame + frame); + out.set(src, i * frame); + } + }); + + return { + audio: new Uint8Array(out.buffer), + secondsSubmitted: seconds(kept.length), + voicedFrames, + totalFrames, + allSilence: false, + }; +} + +/** Duration in seconds of raw PCM16LE audio at a sample rate. */ +export function pcmSeconds(byteLength: number, sampleRate: number): number { + return byteLength / 2 / sampleRate; +} diff --git a/pm-stack/voice-line-worker/test/intent.test.ts b/pm-stack/voice-line-worker/test/intent.test.ts new file mode 100644 index 0000000000..87ec70a197 --- /dev/null +++ b/pm-stack/voice-line-worker/test/intent.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, test } from "bun:test"; +import { matchIntent, buildAnswer } from "../src/intent"; + +describe("matchIntent", () => { + test("recognises queue-state phrasings", () => { + expect(matchIntent("How many tasks are in the queue?")).toBe("queue_state"); + expect(matchIntent("what's the queue state")).toBe("queue_state"); + expect(matchIntent("tell me about the backlog")).toBe("queue_state"); + }); + + test("anything else is unknown (read-only line, no write intents)", () => { + expect(matchIntent("merge the pull request")).toBe("unknown"); + expect(matchIntent("what's the weather")).toBe("unknown"); + expect(matchIntent("")).toBe("unknown"); + }); +}); + +describe("buildAnswer", () => { + test("speaks the snapshot numbers", () => { + const answer = buildAnswer("queue_state", { + queued: 203, claimed: 6, parked: 17, blocked: 3, at: "2026-11-14T14:00:00Z", + }); + expect(answer).toContain("203 tasks waiting"); + expect(answer).toContain("6 being worked"); + expect(answer).toContain("17 parked"); + expect(answer).toContain("3 blocked"); + }); + + test("no snapshot is an honest spoken fallback, not silence", () => { + expect(buildAnswer("queue_state", null)).toContain("don't have a fresh queue snapshot"); + }); + + test("unknown intent explains the one capability", () => { + expect(buildAnswer("unknown", null)).toContain("queue state"); + }); +}); diff --git a/pm-stack/voice-line-worker/test/vad.test.ts b/pm-stack/voice-line-worker/test/vad.test.ts new file mode 100644 index 0000000000..96edcb3403 --- /dev/null +++ b/pm-stack/voice-line-worker/test/vad.test.ts @@ -0,0 +1,56 @@ +import { describe, expect, test } from "bun:test"; +import { trimSilence, pcmSeconds } from "../src/vad"; + +const RATE = 16000; + +function pcm(...segments: Array<{ seconds: number; amplitude: number }>): Uint8Array { + const total = segments.reduce((n, s) => n + Math.round(s.seconds * RATE), 0); + const out = new Int16Array(total); + let at = 0; + for (const s of segments) { + const n = Math.round(s.seconds * RATE); + for (let i = 0; i < n; i++) out[at + i] = Math.round(s.amplitude * Math.sin(i / 4) * 32767); + at += n; + } + return new Uint8Array(out.buffer); +} + +describe("trimSilence", () => { + test("cuts head and tail silence, keeps the speech", () => { + const input = pcm( + { seconds: 1.0, amplitude: 0 }, + { seconds: 0.5, amplitude: 0.5 }, + { seconds: 1.0, amplitude: 0 }, + ); + const r = trimSilence(input, RATE); + expect(r.allSilence).toBe(false); + // 0.5 s of speech + at most 0.2 s of padding (5 frames each side). + expect(r.secondsSubmitted).toBeGreaterThanOrEqual(0.5); + expect(r.secondsSubmitted).toBeLessThan(0.75); + expect(pcmSeconds(input.byteLength, RATE)).toBeCloseTo(2.5, 1); + }); + + test("all silence submits nothing", () => { + const r = trimSilence(pcm({ seconds: 1, amplitude: 0 }), RATE); + expect(r.allSilence).toBe(true); + expect(r.audio.byteLength).toBe(0); + expect(r.secondsSubmitted).toBe(0); + }); + + test("collapses a long internal pause", () => { + const input = pcm( + { seconds: 0.4, amplitude: 0.5 }, + { seconds: 2.0, amplitude: 0 }, + { seconds: 0.4, amplitude: 0.5 }, + ); + const r = trimSilence(input, RATE); + // Without collapsing this would be ~2.8-3.0 s submitted. + expect(r.secondsSubmitted).toBeLessThan(1.6); + expect(r.secondsSubmitted).toBeGreaterThan(0.7); + }); + + test("empty input is all silence", () => { + const r = trimSilence(new Uint8Array(0), RATE); + expect(r.allSilence).toBe(true); + }); +}); diff --git a/pm-stack/voice-line-worker/tsconfig.json b/pm-stack/voice-line-worker/tsconfig.json new file mode 100644 index 0000000000..182d0622bc --- /dev/null +++ b/pm-stack/voice-line-worker/tsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"lib":["ES2022"],"module":"ESNext","moduleResolution":"bundler","noEmit":true,"skipLibCheck":true,"strict":true,"target":"ES2022","types":["@cloudflare/workers-types"]},"include":["src"]} \ No newline at end of file diff --git a/pm-stack/voice-line-worker/wrangler.toml b/pm-stack/voice-line-worker/wrangler.toml new file mode 100644 index 0000000000..75e81bb73b --- /dev/null +++ b/pm-stack/voice-line-worker/wrangler.toml @@ -0,0 +1,21 @@ +name = "voice-line" +main = "src/index.ts" +compatibility_date = "2025-09-15" +workers_dev = true + +# Workers AI: Whisper (speech-to-text) + MeloTTS (speech out), called +# directly per #9800 — the pooled/failover speech route is #9801. +[ai] +binding = "AI" + +[durable_objects] +bindings = [{ name = "VOICE_SESSIONS", class_name = "VoiceSession" }] + +[[migrations]] +tag = "v1" +new_sqlite_classes = ["VoiceSession"] + +# Turso session ledger (#9800). TURSO_TOKEN and STATUS_INGEST_TOKEN are +# secrets (wrangler secret put), never vars in this file. +[vars] +TURSO_URL = "REPLACE_WITH_TURSO_DATABASE_URL"