@vellumai/assistant 0.10.8-dev.202607142125.4cfef21 → 0.10.8-dev.202607142322.265489c
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/package.json +1 -1
- package/src/__tests__/config-schema.test.ts +3 -2
- package/src/calls/media-turn-detector.ts +11 -1
- package/src/cli/lib/bundled-marketplace.json +64 -35
- package/src/config/schemas/__tests__/live-voice.test.ts +24 -6
- package/src/config/schemas/live-voice.ts +10 -4
- package/src/config/schemas/memory-retrospective.ts +8 -0
- package/src/live-voice/__tests__/live-voice-integration.test.ts +116 -2
- package/src/live-voice/__tests__/live-voice-vad.test.ts +85 -7
- package/src/live-voice/__tests__/protocol.test.ts +122 -0
- package/src/live-voice/live-voice-session.ts +65 -13
- package/src/live-voice/protocol.ts +143 -1
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +66 -6
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-prompt.test.ts +180 -0
- package/src/plugins/defaults/memory/graph/tools.ts +47 -13
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +2 -122
- package/src/plugins/defaults/memory/memory-retrospective-prompt.ts +216 -0
- package/src/plugins/defaults/memory/tools.test.ts +34 -0
- package/src/plugins/defaults/memory/tools.ts +12 -2
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +4 -0
- package/src/telemetry/AGENTS.md +27 -1
- package/src/telemetry/__tests__/telemetry-event-fixtures.ts +35 -37
- package/src/telemetry/telemetry-event-sources.test.ts +36 -2
- package/src/telemetry/telemetry-event-sources.ts +37 -17
- package/src/telemetry/telemetry-wire-source.json +1 -1
- package/src/telemetry/telemetry-wire-validation.test.ts +18 -10
- package/src/telemetry/telemetry-wire.generated.ts +60 -9
- package/src/telemetry/types.test.ts +0 -12
- package/src/telemetry/types.ts +59 -22
|
@@ -63,9 +63,10 @@ function pcm(amplitude: number, sampleCount = 240): Uint8Array {
|
|
|
63
63
|
|
|
64
64
|
// 10 ms of speech at 24 kHz.
|
|
65
65
|
const LOUD_CHUNK = pcm(8_000);
|
|
66
|
-
//
|
|
67
|
-
// guard (bargeInMinSpeechMs) in a single chunk
|
|
68
|
-
|
|
66
|
+
// 300 ms of speech at 24 kHz — comfortably exceeds the default sustained-speech
|
|
67
|
+
// barge-in guard (bargeInMinSpeechMs, 250 ms) in a single chunk, so a lone
|
|
68
|
+
// chunk trips barge-in. Must stay above that default.
|
|
69
|
+
const SUSTAINED_LOUD_CHUNK = pcm(8_000, 7_200);
|
|
69
70
|
const SILENT_CHUNK = pcm(0);
|
|
70
71
|
|
|
71
72
|
class MockStreamingTranscriber implements StreamingTranscriber {
|
|
@@ -1110,14 +1111,14 @@ describe("LiveVoiceSession VAD threshold configuration", () => {
|
|
|
1110
1111
|
expect(countType(raisedGate.frames, "speech_started")).toBe(0);
|
|
1111
1112
|
});
|
|
1112
1113
|
|
|
1113
|
-
test("with no config set the factory defaults to 800 energy /
|
|
1114
|
+
test("with no config set the factory defaults to 800 energy / 1200 ms silence / 30 s max turn / 250 ms barge-in", async () => {
|
|
1114
1115
|
// The test workspace has no liveVoice config, so the factory reads the
|
|
1115
|
-
// schema defaults
|
|
1116
|
+
// schema defaults.
|
|
1116
1117
|
expect(getConfig().liveVoice.vad).toEqual({
|
|
1117
1118
|
speechEnergyThreshold: 800,
|
|
1118
|
-
silenceThresholdMs:
|
|
1119
|
+
silenceThresholdMs: 1200,
|
|
1119
1120
|
maxTurnDurationMs: 30_000,
|
|
1120
|
-
bargeInMinSpeechMs:
|
|
1121
|
+
bargeInMinSpeechMs: 250,
|
|
1121
1122
|
});
|
|
1122
1123
|
|
|
1123
1124
|
const { frames, session } = createHarness({ viaFactory: true });
|
|
@@ -1172,6 +1173,56 @@ describe("LiveVoiceSession VAD threshold configuration", () => {
|
|
|
1172
1173
|
saveRawConfig(originalRaw);
|
|
1173
1174
|
}
|
|
1174
1175
|
});
|
|
1176
|
+
|
|
1177
|
+
// JARVIS-1284 (in-session gear): a mid-session `update_config` frame retunes
|
|
1178
|
+
// the live turn detector's pause, so the "pause before reply" slider in the
|
|
1179
|
+
// voice room takes effect without reconnecting.
|
|
1180
|
+
test("update_config retunes the live silence threshold mid-session", async () => {
|
|
1181
|
+
const { frames, session } = createHarness({
|
|
1182
|
+
// Start with a long pause that would time the waitFor out on its own.
|
|
1183
|
+
startFrame: { ...VAD_START_FRAME, silenceThresholdMs: 5_000 },
|
|
1184
|
+
finals: ["configured turn"],
|
|
1185
|
+
startVoiceTurn: makeAutoCompletingTurnStarter(["Done."]).startVoiceTurn,
|
|
1186
|
+
});
|
|
1187
|
+
await session.start();
|
|
1188
|
+
|
|
1189
|
+
// Retune to a short pause mid-session…
|
|
1190
|
+
await session.handleClientFrame({
|
|
1191
|
+
type: "update_config",
|
|
1192
|
+
silenceThresholdMs: 60,
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
// …so this utterance ends ~60 ms after speech, inside the waitFor budget.
|
|
1196
|
+
await session.handleBinaryAudio(pcm(3_000));
|
|
1197
|
+
await waitFor(() => countType(frames, "utterance_end") === 1);
|
|
1198
|
+
expect(
|
|
1199
|
+
frames.find((frame) => frame.type === "utterance_end"),
|
|
1200
|
+
).toMatchObject({ type: "utterance_end", reason: "silence" });
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
// JARVIS-1284: the per-session start-frame `silenceThresholdMs` wins over the
|
|
1204
|
+
// daemon-config/option value, so the client's "pause before reply" setting
|
|
1205
|
+
// takes effect.
|
|
1206
|
+
test("start-frame silenceThresholdMs overrides the option value", async () => {
|
|
1207
|
+
const { frames, session } = createHarness({
|
|
1208
|
+
// A short per-session pause on the start frame…
|
|
1209
|
+
startFrame: { ...VAD_START_FRAME, silenceThresholdMs: 60 },
|
|
1210
|
+
// …beats a long option/config threshold that would otherwise time the
|
|
1211
|
+
// waitFor out.
|
|
1212
|
+
turnDetectorConfig: { silenceThresholdMs: 5_000 },
|
|
1213
|
+
finals: ["configured turn"],
|
|
1214
|
+
startVoiceTurn: makeAutoCompletingTurnStarter(["Done."]).startVoiceTurn,
|
|
1215
|
+
});
|
|
1216
|
+
await session.start();
|
|
1217
|
+
|
|
1218
|
+
// One speech chunk, then silence: the turn ends ~60 ms later (the frame's
|
|
1219
|
+
// value), well inside the waitFor budget — the 5 s option would time out.
|
|
1220
|
+
await session.handleBinaryAudio(pcm(3_000));
|
|
1221
|
+
await waitFor(() => countType(frames, "utterance_end") === 1);
|
|
1222
|
+
expect(
|
|
1223
|
+
frames.find((frame) => frame.type === "utterance_end"),
|
|
1224
|
+
).toMatchObject({ type: "utterance_end", reason: "silence" });
|
|
1225
|
+
});
|
|
1175
1226
|
});
|
|
1176
1227
|
|
|
1177
1228
|
describe("LiveVoiceSession sustained-speech barge-in guard", () => {
|
|
@@ -1182,6 +1233,7 @@ describe("LiveVoiceSession sustained-speech barge-in guard", () => {
|
|
|
1182
1233
|
function createSpeakingTurnHarness(options: {
|
|
1183
1234
|
bargeInMinSpeechMs: number;
|
|
1184
1235
|
finals?: string[];
|
|
1236
|
+
startFrame?: LiveVoiceClientStartFrame;
|
|
1185
1237
|
}) {
|
|
1186
1238
|
let callbacks: VoiceTurnCallbacks | undefined;
|
|
1187
1239
|
const abort = mock();
|
|
@@ -1199,6 +1251,7 @@ describe("LiveVoiceSession sustained-speech barge-in guard", () => {
|
|
|
1199
1251
|
streamTtsAudio,
|
|
1200
1252
|
bargeInMinSpeechMs: options.bargeInMinSpeechMs,
|
|
1201
1253
|
turnDetectorConfig: { silenceThresholdMs: 5_000 },
|
|
1254
|
+
...(options.startFrame ? { startFrame: options.startFrame } : {}),
|
|
1202
1255
|
});
|
|
1203
1256
|
|
|
1204
1257
|
async function speakFirstReply(): Promise<void> {
|
|
@@ -1398,4 +1451,29 @@ describe("LiveVoiceSession sustained-speech barge-in guard", () => {
|
|
|
1398
1451
|
expect(countType(frames, "turn_cancelled")).toBe(0);
|
|
1399
1452
|
expect(abort).not.toHaveBeenCalled();
|
|
1400
1453
|
});
|
|
1454
|
+
|
|
1455
|
+
// JARVIS-1284: the per-session start-frame `bargeInMinSpeechMs` wins over the
|
|
1456
|
+
// daemon-config/option value, so the client's "interrupt sensitivity" setting
|
|
1457
|
+
// takes effect.
|
|
1458
|
+
test("start-frame bargeInMinSpeechMs overrides the option value (0 → instant barge-in)", async () => {
|
|
1459
|
+
const { frames, session, abort, speakFirstReply } =
|
|
1460
|
+
createSpeakingTurnHarness({
|
|
1461
|
+
// The option (daemon config) would make barge-in effectively impossible…
|
|
1462
|
+
bargeInMinSpeechMs: 5_000,
|
|
1463
|
+
// …but the start-frame override disables the guard, so barge-in is
|
|
1464
|
+
// instant.
|
|
1465
|
+
startFrame: { ...VAD_START_FRAME, bargeInMinSpeechMs: 0 },
|
|
1466
|
+
});
|
|
1467
|
+
await speakFirstReply();
|
|
1468
|
+
|
|
1469
|
+
// A single speech chunk barges in immediately — proving the frame's 0 won.
|
|
1470
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1471
|
+
await waitFor(() =>
|
|
1472
|
+
frames.some((frame) => frame.type === "turn_cancelled"),
|
|
1473
|
+
);
|
|
1474
|
+
expect(
|
|
1475
|
+
frames.find((frame) => frame.type === "turn_cancelled"),
|
|
1476
|
+
).toMatchObject({ type: "turn_cancelled", turnId: "live-turn-1" });
|
|
1477
|
+
await waitFor(() => abort.mock.calls.length === 1);
|
|
1478
|
+
});
|
|
1401
1479
|
});
|
|
@@ -62,6 +62,54 @@ describe("parseLiveVoiceClientTextFrame", () => {
|
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
+
test("parses an update_config frame with both fields", () => {
|
|
66
|
+
const frame = {
|
|
67
|
+
type: "update_config",
|
|
68
|
+
silenceThresholdMs: 1400,
|
|
69
|
+
bargeInMinSpeechMs: 300,
|
|
70
|
+
} satisfies LiveVoiceClientFrame;
|
|
71
|
+
const result = parseLiveVoiceClientTextFrame(JSON.stringify(frame));
|
|
72
|
+
expect(result).toEqual({ ok: true, frame });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("parses an update_config frame with a single field, omitting the other", () => {
|
|
76
|
+
const result = parseLiveVoiceClientTextFrame(
|
|
77
|
+
JSON.stringify({ type: "update_config", silenceThresholdMs: 900 }),
|
|
78
|
+
);
|
|
79
|
+
expect(result.ok).toBe(true);
|
|
80
|
+
if (!result.ok) return;
|
|
81
|
+
expect(result.frame).toEqual({
|
|
82
|
+
type: "update_config",
|
|
83
|
+
silenceThresholdMs: 900,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("parses an empty update_config frame (no-op)", () => {
|
|
88
|
+
const result = parseLiveVoiceClientTextFrame(
|
|
89
|
+
JSON.stringify({ type: "update_config" }),
|
|
90
|
+
);
|
|
91
|
+
expect(result).toEqual({ ok: true, frame: { type: "update_config" } });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test.each([
|
|
95
|
+
["silenceThresholdMs", 50],
|
|
96
|
+
["silenceThresholdMs", 10_000],
|
|
97
|
+
["bargeInMinSpeechMs", -1],
|
|
98
|
+
["bargeInMinSpeechMs", 9_000],
|
|
99
|
+
])("rejects an out-of-range update_config %s=%p", (field, badValue) => {
|
|
100
|
+
const result = validateLiveVoiceClientFrame({
|
|
101
|
+
type: "update_config",
|
|
102
|
+
[field]: badValue,
|
|
103
|
+
});
|
|
104
|
+
expect(result.ok).toBe(false);
|
|
105
|
+
if (result.ok) return;
|
|
106
|
+
expect(result.error).toMatchObject({
|
|
107
|
+
code: "invalid_field",
|
|
108
|
+
field,
|
|
109
|
+
frameType: "update_config",
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
65
113
|
test("returns typed protocol errors for invalid JSON", () => {
|
|
66
114
|
const result = parseLiveVoiceClientTextFrame("{");
|
|
67
115
|
|
|
@@ -264,6 +312,80 @@ describe("parseLiveVoiceClientTextFrame", () => {
|
|
|
264
312
|
});
|
|
265
313
|
});
|
|
266
314
|
|
|
315
|
+
test("parses per-session silenceThresholdMs and bargeInMinSpeechMs overrides", () => {
|
|
316
|
+
const result = parseLiveVoiceClientTextFrame(
|
|
317
|
+
JSON.stringify({
|
|
318
|
+
type: "start",
|
|
319
|
+
turnDetection: "server_vad",
|
|
320
|
+
silenceThresholdMs: 1500,
|
|
321
|
+
bargeInMinSpeechMs: 400,
|
|
322
|
+
audio: { mimeType: "audio/pcm", sampleRate: 24000, channels: 1 },
|
|
323
|
+
}),
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
expect(result.ok).toBe(true);
|
|
327
|
+
if (!result.ok) return;
|
|
328
|
+
expect(result.frame).toMatchObject({
|
|
329
|
+
type: "start",
|
|
330
|
+
silenceThresholdMs: 1500,
|
|
331
|
+
bargeInMinSpeechMs: 400,
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test("accepts bargeInMinSpeechMs of 0 (barge-in guard disabled)", () => {
|
|
336
|
+
const result = parseLiveVoiceClientTextFrame(
|
|
337
|
+
JSON.stringify({
|
|
338
|
+
type: "start",
|
|
339
|
+
bargeInMinSpeechMs: 0,
|
|
340
|
+
audio: { mimeType: "audio/pcm", sampleRate: 24000, channels: 1 },
|
|
341
|
+
}),
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(result.ok).toBe(true);
|
|
345
|
+
if (!result.ok) return;
|
|
346
|
+
expect(result.frame).toMatchObject({ bargeInMinSpeechMs: 0 });
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test("omits silenceThresholdMs / bargeInMinSpeechMs when absent", () => {
|
|
350
|
+
const result = parseLiveVoiceClientTextFrame(
|
|
351
|
+
JSON.stringify({
|
|
352
|
+
type: "start",
|
|
353
|
+
audio: { mimeType: "audio/pcm", sampleRate: 24000, channels: 1 },
|
|
354
|
+
}),
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
expect(result.ok).toBe(true);
|
|
358
|
+
if (!result.ok) return;
|
|
359
|
+
expect("silenceThresholdMs" in result.frame).toBe(false);
|
|
360
|
+
expect("bargeInMinSpeechMs" in result.frame).toBe(false);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test.each([
|
|
364
|
+
["silenceThresholdMs", 50], // below MIN_SILENCE_THRESHOLD_MS
|
|
365
|
+
["silenceThresholdMs", 10_000], // above MAX_SILENCE_THRESHOLD_MS
|
|
366
|
+
["silenceThresholdMs", 800.5], // non-integer
|
|
367
|
+
["bargeInMinSpeechMs", -1], // below MIN_BARGE_IN_MIN_SPEECH_MS
|
|
368
|
+
["bargeInMinSpeechMs", 9_000], // above MAX_BARGE_IN_MIN_SPEECH_MS
|
|
369
|
+
["bargeInMinSpeechMs", 250.5], // non-integer
|
|
370
|
+
])(
|
|
371
|
+
"returns a typed protocol error for out-of-range %s=%p",
|
|
372
|
+
(field, badValue) => {
|
|
373
|
+
const result = validateLiveVoiceClientFrame({
|
|
374
|
+
type: "start",
|
|
375
|
+
[field]: badValue,
|
|
376
|
+
audio: { mimeType: "audio/pcm", sampleRate: 24000, channels: 1 },
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
expect(result.ok).toBe(false);
|
|
380
|
+
if (result.ok) return;
|
|
381
|
+
expect(result.error).toMatchObject({
|
|
382
|
+
code: "invalid_field",
|
|
383
|
+
field,
|
|
384
|
+
frameType: "start",
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
);
|
|
388
|
+
|
|
267
389
|
test("returns typed protocol errors for missing audio configuration fields", () => {
|
|
268
390
|
const result = validateLiveVoiceClientFrame({
|
|
269
391
|
type: "start",
|
|
@@ -67,6 +67,7 @@ import type {
|
|
|
67
67
|
} from "./live-voice-tts.js";
|
|
68
68
|
import {
|
|
69
69
|
type LiveVoiceClientFrame,
|
|
70
|
+
type LiveVoiceClientUpdateConfigFrame,
|
|
70
71
|
LiveVoiceProtocolErrorCode,
|
|
71
72
|
type LiveVoiceServerFramePayload,
|
|
72
73
|
} from "./protocol.js";
|
|
@@ -93,10 +94,12 @@ const SERVER_VAD_PRE_ROLL_MAX_CHUNKS = 25;
|
|
|
93
94
|
// provider keeps its own, longer, finalize fallback).
|
|
94
95
|
const FINALIZE_GRACE_MS = 1_000;
|
|
95
96
|
// Consecutive speech (ms) required before speech during assistant playback
|
|
96
|
-
// flushes it (speech_started) and cancels the turn, so a cough
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
|
|
97
|
+
// flushes it (speech_started) and cancels the turn, so a cough, a filler word,
|
|
98
|
+
// or the assistant's own TTS bleeding through imperfect browser echo
|
|
99
|
+
// cancellation cannot kill a reply mid-sentence. Mirrors the
|
|
100
|
+
// liveVoice.vad.bargeInMinSpeechMs schema default; 0 disables the guard for
|
|
101
|
+
// instant barge-in.
|
|
102
|
+
const DEFAULT_BARGE_IN_MIN_SPEECH_MS = 250;
|
|
100
103
|
// At most this many TTS segment jobs are open (provider stream started,
|
|
101
104
|
// frames not yet fully emitted) per turn: the emitting job plus one
|
|
102
105
|
// prefetching job. The prefetch buffers its chunks in memory until promoted;
|
|
@@ -306,7 +309,9 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
306
309
|
// Energy gate for server-VAD speech classification; undefined defers to
|
|
307
310
|
// DEFAULT_SPEECH_ENERGY_THRESHOLD.
|
|
308
311
|
private readonly speechEnergyThreshold: number | undefined;
|
|
309
|
-
|
|
312
|
+
// Mutable so a mid-session `update_config` frame can retune "interrupt
|
|
313
|
+
// sensitivity" live (see applyConfigUpdate).
|
|
314
|
+
private bargeInMinSpeechMs: number;
|
|
310
315
|
// Sustained-speech barge-in guard, armed at speech onset while the
|
|
311
316
|
// assistant turn is audibly speaking: consecutive speech-chunk duration
|
|
312
317
|
// accumulates until it reaches bargeInMinSpeechMs, then the deferred
|
|
@@ -386,12 +391,23 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
386
391
|
...(options.metricsClock ? { clock: options.metricsClock } : {}),
|
|
387
392
|
});
|
|
388
393
|
this.speechEnergyThreshold = options.speechEnergyThreshold;
|
|
394
|
+
// Precedence for the two sensitivity knobs: per-session start-frame
|
|
395
|
+
// override (the client's user setting) > daemon `liveVoice.vad` config
|
|
396
|
+
// (seeded into `options` by the factory) > in-code default.
|
|
389
397
|
this.bargeInMinSpeechMs =
|
|
390
|
-
|
|
398
|
+
context.startFrame.bargeInMinSpeechMs ??
|
|
399
|
+
options.bargeInMinSpeechMs ??
|
|
400
|
+
DEFAULT_BARGE_IN_MIN_SPEECH_MS;
|
|
391
401
|
this.finalizeGraceMs = options.finalizeGraceMs ?? FINALIZE_GRACE_MS;
|
|
402
|
+
const turnDetectorConfig: TurnDetectorConfig = {
|
|
403
|
+
...(options.turnDetectorConfig ?? {}),
|
|
404
|
+
...(context.startFrame.silenceThresholdMs !== undefined
|
|
405
|
+
? { silenceThresholdMs: context.startFrame.silenceThresholdMs }
|
|
406
|
+
: {}),
|
|
407
|
+
};
|
|
392
408
|
this.turnDetector =
|
|
393
409
|
context.startFrame.turnDetection === "server_vad"
|
|
394
|
-
? new MediaTurnDetector(
|
|
410
|
+
? new MediaTurnDetector(turnDetectorConfig, {
|
|
395
411
|
onTurnStart: () => this.handleVadSpeechStart(),
|
|
396
412
|
onTurnEnd: (reason) => this.handleVadUtteranceEnd(reason),
|
|
397
413
|
})
|
|
@@ -461,6 +477,25 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
461
477
|
return;
|
|
462
478
|
case "start":
|
|
463
479
|
return;
|
|
480
|
+
case "update_config":
|
|
481
|
+
this.applyConfigUpdate(frame);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Apply a mid-session `update_config` frame: retune the live turn detector's
|
|
488
|
+
* pause ("pause before reply") and/or the barge-in guard ("interrupt
|
|
489
|
+
* sensitivity") without reconnecting. Each field is optional and independent;
|
|
490
|
+
* changes take effect from the next utterance. A no-op on manual (non-
|
|
491
|
+
* server_vad) sessions, which have no turn detector.
|
|
492
|
+
*/
|
|
493
|
+
private applyConfigUpdate(frame: LiveVoiceClientUpdateConfigFrame): void {
|
|
494
|
+
if (frame.silenceThresholdMs !== undefined) {
|
|
495
|
+
this.turnDetector?.setSilenceThresholdMs(frame.silenceThresholdMs);
|
|
496
|
+
}
|
|
497
|
+
if (frame.bargeInMinSpeechMs !== undefined) {
|
|
498
|
+
this.bargeInMinSpeechMs = frame.bargeInMinSpeechMs;
|
|
464
499
|
}
|
|
465
500
|
}
|
|
466
501
|
|
|
@@ -2072,9 +2107,13 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
2072
2107
|
if (activeTurn?.token !== token) {
|
|
2073
2108
|
return;
|
|
2074
2109
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
)
|
|
2110
|
+
// Only retain the assistant TTS audio when it will be archived (see
|
|
2111
|
+
// collectUserAudio); the mime/sample-rate are cheap and left unconditional.
|
|
2112
|
+
if (this.archiveAudio) {
|
|
2113
|
+
activeTurn.assistantAudioChunks.push(
|
|
2114
|
+
Buffer.from(chunk.dataBase64, "base64"),
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2078
2117
|
activeTurn.assistantAudioMimeType = chunk.contentType;
|
|
2079
2118
|
activeTurn.assistantAudioSampleRate = chunk.sampleRate;
|
|
2080
2119
|
job.frames = job.frames.then(async () => {
|
|
@@ -2114,7 +2153,12 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
2114
2153
|
}
|
|
2115
2154
|
|
|
2116
2155
|
private collectUserAudio(utterance: UtteranceCycle, chunk: Buffer): void {
|
|
2117
|
-
|
|
2156
|
+
// Only retain the raw audio when it will actually be archived — otherwise
|
|
2157
|
+
// buffering a whole turn's PCM is dead memory. The first-audio metric is
|
|
2158
|
+
// independent of archiving, so it stays unconditional.
|
|
2159
|
+
if (this.archiveAudio) {
|
|
2160
|
+
utterance.userAudioChunks.push(Buffer.from(chunk));
|
|
2161
|
+
}
|
|
2118
2162
|
this.markUtteranceMetric(utterance, "firstAudioAtMs", (turnId) =>
|
|
2119
2163
|
this.metrics.markFirstAudio(turnId),
|
|
2120
2164
|
);
|
|
@@ -2509,7 +2553,8 @@ export function createLiveVoiceSession(
|
|
|
2509
2553
|
// unchanged. Optional-chained
|
|
2510
2554
|
// because hand-built test configs may predate the liveVoice namespace;
|
|
2511
2555
|
// absent config falls through to the in-code defaults.
|
|
2512
|
-
const
|
|
2556
|
+
const liveVoiceConfig = getConfig().liveVoice;
|
|
2557
|
+
const vadConfig = liveVoiceConfig?.vad;
|
|
2513
2558
|
return new LiveVoiceSession(context, {
|
|
2514
2559
|
...options,
|
|
2515
2560
|
turnDetectorConfig:
|
|
@@ -2533,9 +2578,16 @@ export function createLiveVoiceSession(
|
|
|
2533
2578
|
options.streamTtsAudio === undefined
|
|
2534
2579
|
? defaultStreamLiveVoiceTtsAudio
|
|
2535
2580
|
: options.streamTtsAudio,
|
|
2581
|
+
// Off by default (see the `liveVoice.archiveAudio` schema): voice turns
|
|
2582
|
+
// persist only their transcribed text, so the recorded audio never lands
|
|
2583
|
+
// as an attachment on the conversation messages. Enable via config for
|
|
2584
|
+
// playback/debugging. An explicit option (incl. `null`) always wins — the
|
|
2585
|
+
// test seam and any future caller override.
|
|
2536
2586
|
archiveAudio:
|
|
2537
2587
|
options.archiveAudio === undefined
|
|
2538
|
-
?
|
|
2588
|
+
? liveVoiceConfig?.archiveAudio
|
|
2589
|
+
? defaultArchiveLiveVoiceAudio
|
|
2590
|
+
: null
|
|
2539
2591
|
: options.archiveAudio,
|
|
2540
2592
|
emitMetrics: options.emitMetrics ?? true,
|
|
2541
2593
|
});
|
|
@@ -4,6 +4,7 @@ const LIVE_VOICE_CLIENT_FRAME_TYPES = [
|
|
|
4
4
|
"ptt_release",
|
|
5
5
|
"interrupt",
|
|
6
6
|
"end",
|
|
7
|
+
"update_config",
|
|
7
8
|
] as const;
|
|
8
9
|
|
|
9
10
|
type LiveVoiceClientFrameType = (typeof LIVE_VOICE_CLIENT_FRAME_TYPES)[number];
|
|
@@ -78,8 +79,36 @@ export interface LiveVoiceClientStartFrame {
|
|
|
78
79
|
* utterance boundaries and runs repeated utterance→turn cycles.
|
|
79
80
|
*/
|
|
80
81
|
readonly turnDetection?: LiveVoiceTurnDetectionMode;
|
|
82
|
+
/**
|
|
83
|
+
* Per-session override for the trailing-silence duration (ms) that ends the
|
|
84
|
+
* user's turn — the "pause before reply" the client exposes as a setting.
|
|
85
|
+
* Absent falls back to the daemon `liveVoice.vad.silenceThresholdMs` config.
|
|
86
|
+
* Only meaningful for `turnDetection: "server_vad"`. Bounded to
|
|
87
|
+
* [{@link MIN_SILENCE_THRESHOLD_MS}, {@link MAX_SILENCE_THRESHOLD_MS}].
|
|
88
|
+
*/
|
|
89
|
+
readonly silenceThresholdMs?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Per-session override for the sustained speech (ms) required before the
|
|
92
|
+
* user's speech interrupts the assistant mid-reply — the "interrupt
|
|
93
|
+
* sensitivity" the client exposes as a setting (higher = harder to
|
|
94
|
+
* interrupt; 0 disables the guard so barge-in is immediate). Absent falls
|
|
95
|
+
* back to the daemon `liveVoice.vad.bargeInMinSpeechMs` config. Bounded to
|
|
96
|
+
* [{@link MIN_BARGE_IN_MIN_SPEECH_MS}, {@link MAX_BARGE_IN_MIN_SPEECH_MS}].
|
|
97
|
+
*/
|
|
98
|
+
readonly bargeInMinSpeechMs?: number;
|
|
81
99
|
}
|
|
82
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Bounds for the per-session turn-detection overrides carried on the start
|
|
103
|
+
* frame. Kept deliberately wide — they only reject nonsensical values (a
|
|
104
|
+
* sub-100 ms pause would end turns mid-word; a 10 s barge-in guard would make
|
|
105
|
+
* the assistant uninterruptible). The daemon config defaults sit inside these.
|
|
106
|
+
*/
|
|
107
|
+
export const MIN_SILENCE_THRESHOLD_MS = 100;
|
|
108
|
+
export const MAX_SILENCE_THRESHOLD_MS = 5_000;
|
|
109
|
+
export const MIN_BARGE_IN_MIN_SPEECH_MS = 0;
|
|
110
|
+
export const MAX_BARGE_IN_MIN_SPEECH_MS = 3_000;
|
|
111
|
+
|
|
83
112
|
export interface LiveVoiceClientAudioFrame {
|
|
84
113
|
readonly type: "audio";
|
|
85
114
|
readonly dataBase64: string;
|
|
@@ -97,12 +126,26 @@ export interface LiveVoiceClientEndFrame {
|
|
|
97
126
|
readonly type: "end";
|
|
98
127
|
}
|
|
99
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Mid-session tuning update: applies the same turn-detection knobs the start
|
|
131
|
+
* frame carries to the *running* session, so the client can retune "pause
|
|
132
|
+
* before reply" / "interrupt sensitivity" without reconnecting. Each field is
|
|
133
|
+
* optional and independently applied; the same bounds as the start frame apply.
|
|
134
|
+
* Only meaningful for `server_vad` sessions.
|
|
135
|
+
*/
|
|
136
|
+
export interface LiveVoiceClientUpdateConfigFrame {
|
|
137
|
+
readonly type: "update_config";
|
|
138
|
+
readonly silenceThresholdMs?: number;
|
|
139
|
+
readonly bargeInMinSpeechMs?: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
100
142
|
export type LiveVoiceClientFrame =
|
|
101
143
|
| LiveVoiceClientStartFrame
|
|
102
144
|
| LiveVoiceClientAudioFrame
|
|
103
145
|
| LiveVoiceClientPttReleaseFrame
|
|
104
146
|
| LiveVoiceClientInterruptFrame
|
|
105
|
-
| LiveVoiceClientEndFrame
|
|
147
|
+
| LiveVoiceClientEndFrame
|
|
148
|
+
| LiveVoiceClientUpdateConfigFrame;
|
|
106
149
|
|
|
107
150
|
interface LiveVoiceBinaryAudioFrame {
|
|
108
151
|
readonly type: "binary_audio";
|
|
@@ -358,9 +401,60 @@ export function validateLiveVoiceClientFrame(
|
|
|
358
401
|
return { ok: true, frame: { type: "interrupt" } };
|
|
359
402
|
case "end":
|
|
360
403
|
return { ok: true, frame: { type: "end" } };
|
|
404
|
+
case "update_config":
|
|
405
|
+
return validateUpdateConfigFrame(value);
|
|
361
406
|
}
|
|
362
407
|
}
|
|
363
408
|
|
|
409
|
+
function validateUpdateConfigFrame(
|
|
410
|
+
value: Record<string, unknown>,
|
|
411
|
+
): LiveVoiceParseResult<LiveVoiceClientUpdateConfigFrame> {
|
|
412
|
+
if (
|
|
413
|
+
"silenceThresholdMs" in value &&
|
|
414
|
+
!isIntInRange(
|
|
415
|
+
value.silenceThresholdMs,
|
|
416
|
+
MIN_SILENCE_THRESHOLD_MS,
|
|
417
|
+
MAX_SILENCE_THRESHOLD_MS,
|
|
418
|
+
)
|
|
419
|
+
) {
|
|
420
|
+
return protocolError(
|
|
421
|
+
"invalid_field",
|
|
422
|
+
`update_config field silenceThresholdMs must be an integer in [${MIN_SILENCE_THRESHOLD_MS}, ${MAX_SILENCE_THRESHOLD_MS}]`,
|
|
423
|
+
"silenceThresholdMs",
|
|
424
|
+
"update_config",
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (
|
|
429
|
+
"bargeInMinSpeechMs" in value &&
|
|
430
|
+
!isIntInRange(
|
|
431
|
+
value.bargeInMinSpeechMs,
|
|
432
|
+
MIN_BARGE_IN_MIN_SPEECH_MS,
|
|
433
|
+
MAX_BARGE_IN_MIN_SPEECH_MS,
|
|
434
|
+
)
|
|
435
|
+
) {
|
|
436
|
+
return protocolError(
|
|
437
|
+
"invalid_field",
|
|
438
|
+
`update_config field bargeInMinSpeechMs must be an integer in [${MIN_BARGE_IN_MIN_SPEECH_MS}, ${MAX_BARGE_IN_MIN_SPEECH_MS}]`,
|
|
439
|
+
"bargeInMinSpeechMs",
|
|
440
|
+
"update_config",
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return {
|
|
445
|
+
ok: true,
|
|
446
|
+
frame: {
|
|
447
|
+
type: "update_config",
|
|
448
|
+
...(typeof value.silenceThresholdMs === "number"
|
|
449
|
+
? { silenceThresholdMs: value.silenceThresholdMs }
|
|
450
|
+
: {}),
|
|
451
|
+
...(typeof value.bargeInMinSpeechMs === "number"
|
|
452
|
+
? { bargeInMinSpeechMs: value.bargeInMinSpeechMs }
|
|
453
|
+
: {}),
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
364
458
|
export function parseLiveVoiceBinaryAudioFrame(
|
|
365
459
|
data: unknown,
|
|
366
460
|
): LiveVoiceParseResult<LiveVoiceBinaryAudioFrame> {
|
|
@@ -448,6 +542,38 @@ function validateStartFrame(
|
|
|
448
542
|
);
|
|
449
543
|
}
|
|
450
544
|
|
|
545
|
+
if (
|
|
546
|
+
"silenceThresholdMs" in value &&
|
|
547
|
+
!isIntInRange(
|
|
548
|
+
value.silenceThresholdMs,
|
|
549
|
+
MIN_SILENCE_THRESHOLD_MS,
|
|
550
|
+
MAX_SILENCE_THRESHOLD_MS,
|
|
551
|
+
)
|
|
552
|
+
) {
|
|
553
|
+
return protocolError(
|
|
554
|
+
"invalid_field",
|
|
555
|
+
`start frame field silenceThresholdMs must be an integer in [${MIN_SILENCE_THRESHOLD_MS}, ${MAX_SILENCE_THRESHOLD_MS}]`,
|
|
556
|
+
"silenceThresholdMs",
|
|
557
|
+
"start",
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (
|
|
562
|
+
"bargeInMinSpeechMs" in value &&
|
|
563
|
+
!isIntInRange(
|
|
564
|
+
value.bargeInMinSpeechMs,
|
|
565
|
+
MIN_BARGE_IN_MIN_SPEECH_MS,
|
|
566
|
+
MAX_BARGE_IN_MIN_SPEECH_MS,
|
|
567
|
+
)
|
|
568
|
+
) {
|
|
569
|
+
return protocolError(
|
|
570
|
+
"invalid_field",
|
|
571
|
+
`start frame field bargeInMinSpeechMs must be an integer in [${MIN_BARGE_IN_MIN_SPEECH_MS}, ${MAX_BARGE_IN_MIN_SPEECH_MS}]`,
|
|
572
|
+
"bargeInMinSpeechMs",
|
|
573
|
+
"start",
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
|
|
451
577
|
return {
|
|
452
578
|
ok: true,
|
|
453
579
|
frame: {
|
|
@@ -459,10 +585,26 @@ function validateStartFrame(
|
|
|
459
585
|
...(isLiveVoiceTurnDetectionMode(value.turnDetection)
|
|
460
586
|
? { turnDetection: value.turnDetection }
|
|
461
587
|
: {}),
|
|
588
|
+
...(typeof value.silenceThresholdMs === "number"
|
|
589
|
+
? { silenceThresholdMs: value.silenceThresholdMs }
|
|
590
|
+
: {}),
|
|
591
|
+
...(typeof value.bargeInMinSpeechMs === "number"
|
|
592
|
+
? { bargeInMinSpeechMs: value.bargeInMinSpeechMs }
|
|
593
|
+
: {}),
|
|
462
594
|
},
|
|
463
595
|
};
|
|
464
596
|
}
|
|
465
597
|
|
|
598
|
+
/** Whether `value` is an integer within the inclusive `[min, max]` range. */
|
|
599
|
+
function isIntInRange(value: unknown, min: number, max: number): boolean {
|
|
600
|
+
return (
|
|
601
|
+
typeof value === "number" &&
|
|
602
|
+
Number.isInteger(value) &&
|
|
603
|
+
value >= min &&
|
|
604
|
+
value <= max
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
466
608
|
function validateAudioFrame(
|
|
467
609
|
value: Record<string, unknown>,
|
|
468
610
|
): LiveVoiceParseResult<LiveVoiceClientAudioFrame> {
|