@vellumai/assistant 0.12.2-dev.202609172017.3da279e → 0.12.2-dev.202609172214.42042c3

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.
Files changed (26) hide show
  1. package/docs/voice-input-diagnostics.md +46 -0
  2. package/openapi.yaml +3 -3
  3. package/package.json +1 -1
  4. package/src/__tests__/inference-profile-session-handler.test.ts +1 -1
  5. package/src/__tests__/llm-catalog-parity.test.ts +2 -2
  6. package/src/config/__tests__/default-provider.test.ts +3 -1
  7. package/src/config/profile-text-generation.test.ts +2 -2
  8. package/src/config/schemas/llm.ts +1 -1
  9. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +241 -0
  10. package/src/live-voice/__tests__/voice-input-diagnostics.test.ts +117 -0
  11. package/src/live-voice/live-voice-session.ts +232 -33
  12. package/src/live-voice/voice-input-diagnostics.ts +117 -0
  13. package/src/mcp/__tests__/manager-tool-caps.test.ts +32 -20
  14. package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +119 -1
  15. package/src/plugins/defaults/memory/v3/orchestrate.ts +3 -1
  16. package/src/plugins/defaults/memory/v3/pool-select.ts +263 -6
  17. package/src/providers/inference/adapter-factory.ts +1 -1
  18. package/src/providers/jev/client.test.ts +10 -0
  19. package/src/providers/jev/client.ts +16 -1
  20. package/src/providers/model-catalog.ts +4 -3
  21. package/src/providers/speech-to-text/__tests__/deepgram-flux-frames.test.ts +24 -0
  22. package/src/providers/speech-to-text/__tests__/deepgram-flux-realtime.test.ts +7 -1
  23. package/src/providers/speech-to-text/deepgram-flux-frames.ts +11 -0
  24. package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +1 -1
  25. package/src/runtime/routes/secret-routes.ts +1 -1
  26. package/src/stt/types.ts +4 -0
@@ -0,0 +1,46 @@
1
+ # Voice input diagnostics
2
+
3
+ Hands-free voice records signal measurements in the ordinary support log export. This includes calls started from the macOS companion. These diagnostics do not change capture constraints, speech thresholds, interruption timing, or task cancellation. They add no PCM recordings, transcript text, microphone labels, or device identifiers.
4
+
5
+ ## Collect a reproduction
6
+
7
+ Use the same microphone, output device, volume, and companion surface as the failing call. Note whether output is through headphones or speakers.
8
+
9
+ 1. Start a companion voice call. Stay quiet for about 20 seconds to capture the room baseline.
10
+ 2. Ask for an explanation long enough to produce sustained speech. Stay quiet while it answers; note the time of any unexpected cutoff.
11
+ 3. Ask it to start a background investigation. Stay quiet during startup; note missing acknowledgements or cancelled starts.
12
+ 4. Deliberately interrupt an answer with a short spoken question. This provides a real interruption to compare against the unexplained cutoffs.
13
+ 5. End the call and export logs through the existing feedback log export.
14
+
15
+ Keep the initial reproduction on the original audio setup. A second call using headphones, or using the built-in microphone instead of a headset, can isolate a route-dependent problem after the first capture.
16
+
17
+ ## Client records
18
+
19
+ `[live-voice-input]` entries are serialized JSON in `electron-main-logs.txt`. Electron collects them from every renderer, so export does not depend on which window hosts the companion call. The same events appear as `voice_input` in the web diagnostics lifecycle ring.
20
+
21
+ - `capture_started` and `input_switched` report applied echo cancellation, noise suppression, gain control, channel count, and track/context/output sample rates. `null` means the browser did not report a setting. An explicit device selection reports whether it matched, without logging either device identifier.
22
+ - `capture_mute`, `capture_unmute`, `capture_ended`, and `capture_statechange` expose track and audio-context transitions. Listeners retire with the old stream on a device switch or stop.
23
+ - `session_ready` links the client `captureId` to the server `sessionId`. Capture can open before the server is ready, so earlier entries have a null session ID. `entry` identifies the launch surface when supplied.
24
+ - `speech_started`, `turn_cancelled`, and `utterance_discarded` report whether playback was active, held, or actually resumed after an unusable utterance.
25
+
26
+ ## Server records
27
+
28
+ Search the assistant log for `Live voice input diagnostics` or `voice_input_`. All records include session, input-turn, assistant-turn, and speech-generation identifiers where available, plus the effective threshold, room floor, echo configuration, playback estimate, and foreground-task state.
29
+
30
+ - `voice_input_window` summarizes each approximately five-second arrival window: received audio duration, zero-signal duration, duration-weighted mean amplitude, minimum/maximum chunk mean amplitude, classified speech/silence/echo duration, and maximum arrival gap. Window emission requires incoming audio; `voice_input_closed` flushes a partial window.
31
+ - The same window includes `sttSubmittedChunks`, `sttSubmittedAudioMs`, and `sttMaxSubmissionGapMs`. These measure handoff to the transcription adapter, not provider receipt. A probe can buffer audio before submission, and the final chunk of an arrival window can be submitted in the next window. Compare sustained windows to identify input that arrives normally but stops reaching transcription.
32
+ - `voice_input_provider_turn_start` and `voice_input_provider_turn_end` record provider boundaries alongside local VAD state. End records include confidence, the provider's `trigger` (`model`, `timeout`, or `manual`), decoded audio position in seconds from stream start, and elapsed time since locally detected speech. Missing provider fields are null. These records describe received decisions, including ones ignored as stale or after fallback; correlate with the turn metrics to identify the boundary that committed the request.
33
+ - `voice_input_barge_in_armed`, `voice_input_barge_in_fired`, and `voice_input_barge_in_expired` distinguish a candidate from an accepted or expired interruption. Fired events include accumulated speech duration, guard resets, and a bounded trace of the preceding two seconds (at most 40 input chunks).
34
+ - Each trace entry captures the amplitude and gate/echo state before classification, and classified durations, remaining probe buffer, and correlation result after classification. The classifier can hold a probe and release multiple older chunks together, so a row's classified duration can differ from its received duration. A null correlation means no comparison ran, not a measured zero correlation.
35
+ - `voice_input_speech_routed` binds the speech generation to the input turn that actually receives its audio. At onset, the prior spent cycle may still be installed, so use this routing record for correlation rather than assuming the onset's `inputTurnId` is the new utterance.
36
+ - `voice_input_transcript` reports committed character count and provider, never words. `voice_input_utterance_discarded` reports the discard reason and remaining transcript/partial state.
37
+
38
+ Amplitude uses the classifier's PCM16 mean-absolute scale, not the client's normalized UI meter. Playback timing is the server's estimate, not proof that sound was heard. An empty transcript is evidence of no usable transcription; it does not establish that the person was silent or that the detector was wrong.
39
+
40
+ These are local diagnostic logs, not new analytics events or voice protocol fields. Existing log retention and export apply.
41
+
42
+ ## Flux pause handling
43
+
44
+ When Flux owns turn detection, it receives microphone audio through idle periods and pauses, including quiet speech below the local VAD gate. Confirmed playback echo is replaced by silence of the same duration so it advances the provider's audio clock without transcribing the assistant's voice. Echo probes can briefly buffer that audio. Local VAD still owns barge-in; its thresholds and guard are independent of this continuous transcription feed. Idle audio is not accumulated into request recordings.
45
+
46
+ For a focused reproduction, say an unfinished question such as "Did they help invent", pause briefly, then complete it with "ChatGPT". Repeat with a shorter and a longer pause, plus a complete short question. Note when the assistant starts answering and export the logs. Check that STT submissions continue during the pause, then use the provider end event's time, confidence, and trigger to distinguish model endpointing from a timeout. Tests verify audio delivery and event handling; they do not establish how Flux will segment real speech.
package/openapi.yaml CHANGED
@@ -16556,7 +16556,7 @@ paths:
16556
16556
  type: string
16557
16557
  description:
16558
16558
  "Filter by provider id. One of: anthropic, openai, gemini, ollama, fireworks, together, openrouter,
16559
- vercel-ai-gateway, litellm, opencode, openai-compatible, minimax, atlascloud, baseten, poolside, jev,
16559
+ vercel-ai-gateway, litellm, opencode, openai-compatible, minimax, atlascloud, baseten, poolside, typesafe,
16560
16560
  vellum"
16561
16561
  responses:
16562
16562
  "200":
@@ -16829,7 +16829,7 @@ paths:
16829
16829
  type: string
16830
16830
  description:
16831
16831
  "Filter by provider. One of: anthropic, openai, gemini, ollama, fireworks, together, openrouter,
16832
- vercel-ai-gateway, litellm, opencode, openai-compatible, minimax, atlascloud, baseten, poolside, jev,
16832
+ vercel-ai-gateway, litellm, opencode, openai-compatible, minimax, atlascloud, baseten, poolside, typesafe,
16833
16833
  vellum, chatgpt"
16834
16834
  responses:
16835
16835
  "200":
@@ -38400,7 +38400,7 @@ components:
38400
38400
  - atlascloud
38401
38401
  - baseten
38402
38402
  - poolside
38403
- - jev
38403
+ - typesafe
38404
38404
  - vellum
38405
38405
  - chatgpt
38406
38406
  Auth:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.12.2-dev.202609172017.3da279e",
3
+ "version": "0.12.2-dev.202609172214.42042c3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -389,7 +389,7 @@ describe("setInferenceProfileSession", () => {
389
389
  profiles: {
390
390
  jev: {
391
391
  source: "user",
392
- provider: "jev",
392
+ provider: "typesafe",
393
393
  model: "jev-latest",
394
394
  status: "active",
395
395
  },
@@ -234,12 +234,12 @@ describe("LLM catalog parity: daemon vs client", () => {
234
234
  });
235
235
 
236
236
  test("jev-latest opts out of chat text generation", () => {
237
- expect(catalogModelSupportsText("jev", "jev-latest")).toBe(false);
237
+ expect(catalogModelSupportsText("typesafe", "jev-latest")).toBe(false);
238
238
  expect(catalogModelSupportsText("anthropic", "claude-opus-4-8")).toBe(true);
239
239
  expect(catalogModelSupportsText("openai-compatible", "local-model")).toBe(
240
240
  true,
241
241
  );
242
- expect(DEFAULT_PROVIDER_CHOICES).not.toContain("jev");
242
+ expect(DEFAULT_PROVIDER_CHOICES).not.toContain("typesafe");
243
243
  expect(DEFAULT_PROVIDER_CHOICES).toContain("poolside");
244
244
  });
245
245
 
@@ -73,7 +73,9 @@ describe("LLMSchema.defaultProvider", () => {
73
73
  });
74
74
 
75
75
  test("rejects a structured-decision catalog provider", () => {
76
- expect(() => DefaultProviderSchema.parse({ provider: "jev" })).toThrow();
76
+ expect(() =>
77
+ DefaultProviderSchema.parse({ provider: "typesafe" }),
78
+ ).toThrow();
77
79
  });
78
80
 
79
81
  test("rejects an empty connectionName", () => {
@@ -9,7 +9,7 @@ describe("profileSupportsTextGeneration", () => {
9
9
  test("false for a structured-decision catalog model", () => {
10
10
  expect(
11
11
  profileSupportsTextGeneration(
12
- { provider: "jev", model: "jev-latest" },
12
+ { provider: "typesafe", model: "jev-latest" },
13
13
  {},
14
14
  ),
15
15
  ).toBe(false);
@@ -35,7 +35,7 @@ describe("profileSupportsTextGeneration", () => {
35
35
  profileSupportsTextGeneration(
36
36
  { mix: [{ profile: "jev" }, { profile: "balanced" }] },
37
37
  {
38
- jev: { provider: "jev", model: "jev-latest" },
38
+ jev: { provider: "typesafe", model: "jev-latest" },
39
39
  balanced: { provider: "anthropic", model: "claude-opus-4-8" },
40
40
  },
41
41
  ),
@@ -62,7 +62,7 @@ export const KNOWN_LLM_PROVIDERS = [
62
62
  "opencode",
63
63
  "baseten",
64
64
  "poolside",
65
- "jev",
65
+ "typesafe",
66
66
  // Routing identities: "vellum" = the platform-managed route (upstream
67
67
  // derived from the model at dispatch) and the catalog owner of
68
68
  // Vellum-hosted GPU models; "chatgpt" = the subscription route to OpenAI.
@@ -13,6 +13,7 @@ import type {
13
13
  } from "../../stt/types.js";
14
14
  import {
15
15
  LiveVoiceSession,
16
+ type LiveVoiceSessionAudioArchiver,
16
17
  type LiveVoiceTtsStreamer,
17
18
  } from "../live-voice-session.js";
18
19
  import type { LiveVoiceSessionFactoryContext } from "../live-voice-session-manager.js";
@@ -63,6 +64,7 @@ class MockFluxTranscriber implements StreamingTranscriber {
63
64
  readonly boundaryId = "daemon-streaming" as const;
64
65
  readonly received: Buffer[] = [];
65
66
  stopped = false;
67
+ onAudio: ((chunk: Buffer) => void) | null = null;
66
68
  private onEvent: ((event: SttStreamServerEvent) => void) | null = null;
67
69
 
68
70
  constructor(readonly providerId: SttProviderId) {}
@@ -73,6 +75,7 @@ class MockFluxTranscriber implements StreamingTranscriber {
73
75
 
74
76
  sendAudio(chunk: Buffer): void {
75
77
  this.received.push(Buffer.from(chunk));
78
+ this.onAudio?.(chunk);
76
79
  }
77
80
 
78
81
  // Transcript Flux answers `CloseStream` with, for a turn still in flight
@@ -121,6 +124,7 @@ function createHarness(options: {
121
124
  }>;
122
125
  streamTtsAudio?: LiveVoiceTtsStreamer | null;
123
126
  emitMetrics?: boolean;
127
+ archiveAudio?: LiveVoiceSessionAudioArchiver;
124
128
  // Holds the STT dial open so a test can drive a whole utterance through the
125
129
  // window between `ready` and the resolved provider.
126
130
  resolveGate?: Promise<unknown>;
@@ -163,6 +167,7 @@ function createHarness(options: {
163
167
  startVoiceTurn,
164
168
  streamTtsAudio: options.streamTtsAudio ?? null,
165
169
  emitMetrics: options.emitMetrics ?? false,
170
+ archiveAudio: options.archiveAudio,
166
171
  spawnBackgroundContinuation: mock(async () => ""),
167
172
  turnDetectorConfig: {
168
173
  silenceThresholdMs: options.silenceThresholdMs ?? 40,
@@ -285,6 +290,219 @@ const FLUX_OFF = {
285
290
  } as const satisfies Partial<LiveVoiceFluxConfig>;
286
291
 
287
292
  describe("LiveVoiceSession Flux end-of-turn", () => {
293
+ test("keeps continuous idle audio out of the request recording", async () => {
294
+ const recordings: Buffer[] = [];
295
+ const { session, transcribers } = createHarness({
296
+ fluxConfig: FLUX_ON,
297
+ startVoiceTurn: autoCompletingTurn(),
298
+ archiveAudio: async (input) => {
299
+ recordings.push(Buffer.from(input.audio.dataBase64, "base64"));
300
+ return {
301
+ type: "warning",
302
+ warning: {
303
+ code: "message_id_unavailable",
304
+ message: "No persisted message in this test.",
305
+ },
306
+ };
307
+ },
308
+ });
309
+ try {
310
+ await session.start();
311
+ await waitFor(() => transcribers.length === 1);
312
+ for (let index = 0; index < 50; index++) {
313
+ await session.handleBinaryAudio(pcm(100));
314
+ }
315
+ await session.handleBinaryAudio(LOUD_CHUNK);
316
+ transcribers[0]!.endOfTurn("a complete question", 0);
317
+ await waitFor(() => recordings.length === 1);
318
+ expect(recordings).toEqual([Buffer.from(LOUD_CHUNK)]);
319
+ } finally {
320
+ await session.close("client_end");
321
+ }
322
+ });
323
+
324
+ test("replaces confirmed playback echo with equal-duration silence for Flux", async () => {
325
+ const echo = Buffer.alloc(SAMPLE_RATE * 2 * 2);
326
+ for (let index = 0; index < echo.byteLength / 2; index++) {
327
+ echo.writeInt16LE(
328
+ Math.round(4_700 * Math.sin((2 * Math.PI * 200 * index) / SAMPLE_RATE)),
329
+ index * 2,
330
+ );
331
+ }
332
+ const { session, frames, transcribers } = createHarness({
333
+ fluxConfig: FLUX_ON,
334
+ startVoiceTurn: async (options) => {
335
+ options.callbacks?.assistant_text_delta?.(
336
+ makeTextDelta("Here is an answer."),
337
+ );
338
+ return { turnId: "bridge-turn", abort: mock() };
339
+ },
340
+ streamTtsAudio: async (options) => {
341
+ options.onAudioChunk({
342
+ type: "tts_audio",
343
+ contentType: "audio/pcm",
344
+ sampleRate: SAMPLE_RATE,
345
+ dataBase64: echo.toString("base64"),
346
+ });
347
+ return {
348
+ provider: "fish-audio",
349
+ contentType: "audio/pcm",
350
+ sampleRate: SAMPLE_RATE,
351
+ chunks: 1,
352
+ bytes: echo.byteLength,
353
+ };
354
+ },
355
+ });
356
+ try {
357
+ await session.start();
358
+ await session.handleBinaryAudio(LOUD_CHUNK);
359
+ await waitFor(() => transcribers.length === 1);
360
+ const transcriber = transcribers[0]!;
361
+ transcriber.endOfTurn("a complete question", 0);
362
+ await waitFor(() => countFrames(frames, "tts_audio") === 1);
363
+ const before = transcriber.received.length;
364
+ const echoChunk = echo.subarray(0, 480);
365
+ for (let index = 0; index < 40; index++) {
366
+ await session.handleBinaryAudio(echoChunk);
367
+ }
368
+ const submitted = Buffer.concat(transcriber.received.slice(before));
369
+ expect(submitted.byteLength).toBe(echoChunk.byteLength * 40);
370
+ expect(submitted.every((byte) => byte === 0)).toBe(true);
371
+ expect(countFrames(frames, "turn_cancelled")).toBe(0);
372
+ } finally {
373
+ await session.close("client_end");
374
+ }
375
+ });
376
+
377
+ test("keeps idle quiet audio flowing without starting a user request", async () => {
378
+ const { frames, session, transcribers, turnCalls } = createHarness({
379
+ fluxConfig: FLUX_ON,
380
+ });
381
+ try {
382
+ await session.start();
383
+ await waitFor(() => transcribers.length === 1);
384
+ const quiet = pcm(100);
385
+ for (let index = 0; index < 30; index++) {
386
+ await session.handleBinaryAudio(quiet);
387
+ }
388
+ expect(transcribers[0]?.received).toEqual(
389
+ Array.from({ length: 30 }, () => Buffer.from(quiet)),
390
+ );
391
+ expect(turnCalls).toHaveLength(0);
392
+ expect(countFrames(frames, "speech_started")).toBe(0);
393
+ expect(countFrames(frames, "utterance_end")).toBe(0);
394
+ } finally {
395
+ await session.close("client_end");
396
+ }
397
+ });
398
+
399
+ test("a provider can finish from trailing audio after the local silence boundary", async () => {
400
+ const { session, transcribers, turnCalls } = createHarness({
401
+ fluxConfig: FLUX_ON,
402
+ startVoiceTurn: autoCompletingTurn(),
403
+ });
404
+ try {
405
+ await session.start();
406
+ await session.handleBinaryAudio(LOUD_CHUNK);
407
+ await waitFor(() => transcribers.length === 1);
408
+ const transcriber = transcribers[0]!;
409
+ transcriber.emit({ type: "partial", text: "a complete question" });
410
+ await sleep(PAST_SILENCE_BOUNDARY_MS);
411
+ let quietChunks = 0;
412
+ transcriber.onAudio = (chunk) => {
413
+ if (chunk.every((byte) => byte === 0)) {
414
+ quietChunks += 1;
415
+ if (quietChunks === 20) {
416
+ transcriber.endOfTurn("a complete question", 0);
417
+ }
418
+ }
419
+ };
420
+ for (let index = 0; index < 20; index++) {
421
+ await session.handleBinaryAudio(pcm(0));
422
+ }
423
+ await waitFor(() => turnCalls.length === 1);
424
+ expect(turnCalls[0]?.content).toBe("a complete question");
425
+ expect(transcriber.stopped).toBe(false);
426
+ expect(transcribers).toHaveLength(1);
427
+ } finally {
428
+ await session.close("client_end");
429
+ }
430
+ });
431
+
432
+ test("preserves quiet continuation audio across a pause until Flux commits", async () => {
433
+ const { frames, session, transcribers, turnCalls } = createHarness({
434
+ fluxConfig: FLUX_ON,
435
+ startVoiceTurn: autoCompletingTurn(),
436
+ });
437
+ try {
438
+ await session.start();
439
+ await session.handleBinaryAudio(LOUD_CHUNK);
440
+ await waitFor(() => transcribers.length === 1);
441
+ const transcriber = transcribers[0]!;
442
+ transcriber.emit({ type: "partial", text: "did they help invent" });
443
+ await sleep(PAST_SILENCE_BOUNDARY_MS);
444
+ const continuation = [pcm(0), pcm(120, 7_200), pcm(0)];
445
+ const before = transcriber.received.length;
446
+ for (const chunk of continuation) {
447
+ await session.handleBinaryAudio(chunk);
448
+ }
449
+ expect(transcriber.received.slice(before)).toEqual(
450
+ continuation.map((chunk) => Buffer.from(chunk)),
451
+ );
452
+ expect(turnCalls).toHaveLength(0);
453
+ expect(countFrames(frames, "utterance_end")).toBe(0);
454
+ transcriber.endOfTurn("did they help invent ChatGPT", 0);
455
+ await waitFor(() => turnCalls.length === 1);
456
+ expect(turnCalls[0]?.content).toBe("did they help invent ChatGPT");
457
+ } finally {
458
+ await session.close("client_end");
459
+ }
460
+ });
461
+
462
+ test("continues quiet audio through an active answer without interrupting it", async () => {
463
+ const { frames, session, transcribers, turnCalls } = createHarness({
464
+ fluxConfig: FLUX_ON,
465
+ });
466
+ try {
467
+ await session.start();
468
+ await session.handleBinaryAudio(LOUD_CHUNK);
469
+ await waitFor(() => transcribers.length === 1);
470
+ const transcriber = transcribers[0]!;
471
+ transcriber.endOfTurn("a complete question", 0);
472
+ await waitFor(() => turnCalls.length === 1);
473
+ const before = transcriber.received.length;
474
+ for (let index = 0; index < 10; index++) {
475
+ await session.handleBinaryAudio(pcm(0));
476
+ }
477
+ expect(transcriber.received.length - before).toBe(10);
478
+ expect(transcribers).toHaveLength(1);
479
+ expect(countFrames(frames, "turn_cancelled")).toBe(0);
480
+ expect(turnCalls).toHaveLength(1);
481
+ } finally {
482
+ await session.close("client_end");
483
+ }
484
+ });
485
+
486
+ test.each([
487
+ { providerId: "deepgram-flux" as const, fluxConfig: FLUX_OFF },
488
+ { providerId: "deepgram" as const, fluxConfig: FLUX_ON },
489
+ ])("locally endpointed streams retain idle pre-roll: %j", async (options) => {
490
+ const { session, transcribers } = createHarness(options);
491
+ try {
492
+ await session.start();
493
+ await waitFor(() => transcribers.length === 1);
494
+ await session.handleBinaryAudio(pcm(0));
495
+ expect(transcribers[0]?.received).toHaveLength(0);
496
+ await session.handleBinaryAudio(LOUD_CHUNK);
497
+ expect(transcribers[0]?.received).toEqual([
498
+ Buffer.from(pcm(0)),
499
+ Buffer.from(LOUD_CHUNK),
500
+ ]);
501
+ } finally {
502
+ await session.close("client_end");
503
+ }
504
+ });
505
+
288
506
  test("commits the turn on turn-end without an endpoint-decision leg", async () => {
289
507
  const { frames, session, transcribers, turnCalls } = createHarness({
290
508
  fluxConfig: FLUX_ON,
@@ -843,6 +1061,29 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
843
1061
  setConfig("services", { stt: { provider: "deepgram", providers: {} } });
844
1062
  });
845
1063
 
1064
+ test("empty Flux updates do not prevent a language change during idle input", async () => {
1065
+ const { session, transcribers } = createHarness({ fluxConfig: FLUX_ON });
1066
+ try {
1067
+ await session.start();
1068
+ await waitFor(() => transcribers.length === 1);
1069
+ transcribers[0]!.emit({ type: "partial", text: "" });
1070
+ setConfig("services", {
1071
+ stt: {
1072
+ provider: "deepgram",
1073
+ providers: { deepgram: { model: "flux" } },
1074
+ language: "es",
1075
+ },
1076
+ });
1077
+ await session.handleBinaryAudio(pcm(0));
1078
+ await waitFor(() => transcribers.length === 2);
1079
+ expect(transcribers[0]!.stopped).toBe(true);
1080
+ await session.handleBinaryAudio(pcm(100));
1081
+ expect(transcribers[1]!.received.at(-1)).toEqual(Buffer.from(pcm(100)));
1082
+ } finally {
1083
+ await session.close("client_end");
1084
+ }
1085
+ });
1086
+
846
1087
  test("waits for turn-end when the boundary lands before the dial resolves", async () => {
847
1088
  const gate = createDialGate();
848
1089
  const { frames, session, transcribers, turnCalls } = createHarness({
@@ -0,0 +1,117 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ VoiceInputDiagnostics,
5
+ type VoiceInputSample,
6
+ } from "../voice-input-diagnostics.js";
7
+
8
+ function sample(
9
+ receivedAtMs: number,
10
+ overrides: Partial<VoiceInputSample> = {},
11
+ ): VoiceInputSample {
12
+ return {
13
+ receivedAtMs,
14
+ chunkMs: 50,
15
+ meanAmplitude: 100,
16
+ baseThreshold: 800,
17
+ roomNoiseFloor: null,
18
+ echoEnergy: 0,
19
+ echoOnsetLapsed: false,
20
+ echoWindowMs: 0,
21
+ echoGuardCarryover: false,
22
+ echoReferenceMs: 0,
23
+ echoProbeMs: 0,
24
+ echoCorrelation: null,
25
+ playbackRemainingMs: 0,
26
+ playbackEchoPossible: false,
27
+ speechMs: 0,
28
+ silenceMs: 50,
29
+ echoMs: 0,
30
+ ...overrides,
31
+ };
32
+ }
33
+
34
+ describe("voice input diagnostics", () => {
35
+ test("distinguishes arriving audio from gaps in submission to STT", () => {
36
+ const diagnostics = new VoiceInputDiagnostics();
37
+ diagnostics.observe(sample(0));
38
+ diagnostics.recordSttSubmission(0, 50);
39
+ diagnostics.observe(sample(50));
40
+ diagnostics.observe(sample(100));
41
+ diagnostics.recordSttSubmission(100, 50);
42
+ expect(diagnostics.flush()).toMatchObject({
43
+ chunks: 3,
44
+ audioMs: 150,
45
+ maxArrivalGapMs: 50,
46
+ sttSubmittedChunks: 2,
47
+ sttSubmittedAudioMs: 100,
48
+ sttMaxSubmissionGapMs: 100,
49
+ });
50
+ diagnostics.observe(sample(150));
51
+ diagnostics.recordSttSubmission(150, 50);
52
+ expect(diagnostics.flush()).toMatchObject({
53
+ sttSubmittedChunks: 1,
54
+ sttSubmittedAudioMs: 50,
55
+ sttMaxSubmissionGapMs: 50,
56
+ });
57
+ });
58
+ test("bounds traces by count and age, including burst arrivals", () => {
59
+ const diagnostics = new VoiceInputDiagnostics();
60
+ for (let index = 0; index < 100; index++) {
61
+ diagnostics.observe(sample(index));
62
+ }
63
+ const trace = diagnostics.snapshot(100);
64
+ expect(trace).toHaveLength(40);
65
+ expect(trace[0]?.receivedAtMs).toBe(60);
66
+ trace[0]!.meanAmplitude = 999;
67
+ expect(diagnostics.snapshot(100)[0]?.meanAmplitude).toBe(100);
68
+ expect(diagnostics.snapshot(2_100)).toEqual([]);
69
+ });
70
+
71
+ test("weights levels by audio duration and distinguishes silence from missing audio", () => {
72
+ const diagnostics = new VoiceInputDiagnostics();
73
+ expect(diagnostics.observe(sample(0, { meanAmplitude: 0 }))).toBeNull();
74
+ const summary = diagnostics.observe(
75
+ sample(5_000, {
76
+ chunkMs: 150,
77
+ meanAmplitude: 2_000,
78
+ speechMs: 150,
79
+ silenceMs: 0,
80
+ }),
81
+ );
82
+ expect(summary).toMatchObject({
83
+ firstAtMs: 0,
84
+ lastAtMs: 5_000,
85
+ audioMs: 200,
86
+ chunks: 2,
87
+ meanAmplitude: 1_500,
88
+ minAmplitude: 0,
89
+ maxAmplitude: 2_000,
90
+ zeroAudioMs: 50,
91
+ maxArrivalGapMs: 5_000,
92
+ speechMs: 150,
93
+ silenceMs: 50,
94
+ });
95
+ expect(diagnostics.flush()).toBeNull();
96
+ diagnostics.observe(sample(5_050));
97
+ expect(diagnostics.flush()).toMatchObject({
98
+ chunks: 1,
99
+ audioMs: 50,
100
+ maxArrivalGapMs: 50,
101
+ });
102
+ });
103
+
104
+ test("keeps buffered echo-probe decisions distinct from newly received audio", () => {
105
+ const diagnostics = new VoiceInputDiagnostics();
106
+ diagnostics.observe(sample(0, { silenceMs: 0, echoProbeMs: 50 }));
107
+ diagnostics.observe(
108
+ sample(50, { silenceMs: 0, echoMs: 100, echoCorrelation: 0.9 }),
109
+ );
110
+ expect(diagnostics.flush()).toMatchObject({
111
+ audioMs: 100,
112
+ echoMs: 100,
113
+ silenceMs: 0,
114
+ });
115
+ expect(diagnostics.snapshot(50)[1]?.echoCorrelation).toBe(0.9);
116
+ });
117
+ });