dsh-voice-mode 0.7.26 → 0.7.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +13 -5
- package/README.md +27 -6
- package/lib/client.js +541 -77
- package/lib/index.js +165 -22
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1066,12 +1066,38 @@ function splitSentences(chunk) {
|
|
|
1066
1066
|
var SentenceSegmenter = class {
|
|
1067
1067
|
buffer = "";
|
|
1068
1068
|
maxChars;
|
|
1069
|
+
/** 是否处在 ``` 代码块内(跨 delta 有效:流式 delta 只有几个 token,代码块总是被切碎送达,
|
|
1070
|
+
* plainText 的整块正则匹配不到,代码会被逐句念出——「总是朗读」覆盖打字会话后尤其明显)。 */
|
|
1071
|
+
inFence = false;
|
|
1072
|
+
/** delta 末尾悬挂的 1-2 个反引号(可能是被切开的 ``` 前半)。 */
|
|
1073
|
+
ticks = "";
|
|
1069
1074
|
constructor(options = {}) {
|
|
1070
1075
|
this.maxChars = options.maxSentenceChars ?? 200;
|
|
1071
1076
|
}
|
|
1077
|
+
/** 去掉 ``` 代码块内容(状态跨 delta 保持);进入代码块处补一个换行,让前面的文字先成句。 */
|
|
1078
|
+
dropFences(chunk) {
|
|
1079
|
+
let s = this.ticks + chunk;
|
|
1080
|
+
this.ticks = "";
|
|
1081
|
+
const hang = /`{1,2}$/.exec(s);
|
|
1082
|
+
if (hang) {
|
|
1083
|
+
this.ticks = hang[0];
|
|
1084
|
+
s = s.slice(0, -hang[0].length);
|
|
1085
|
+
}
|
|
1086
|
+
let out = "";
|
|
1087
|
+
for (; ; ) {
|
|
1088
|
+
const i = s.indexOf("```");
|
|
1089
|
+
if (i < 0) {
|
|
1090
|
+
if (!this.inFence) out += s;
|
|
1091
|
+
return out;
|
|
1092
|
+
}
|
|
1093
|
+
if (!this.inFence) out += s.slice(0, i) + "\n";
|
|
1094
|
+
this.inFence = !this.inFence;
|
|
1095
|
+
s = s.slice(i + 3);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1072
1098
|
/** 喂入一段 raw delta,返回它补全的完整句子。 */
|
|
1073
1099
|
feed(chunk) {
|
|
1074
|
-
const cleaned = plainText(chunk);
|
|
1100
|
+
const cleaned = plainText(this.dropFences(chunk));
|
|
1075
1101
|
if (!cleaned) return [];
|
|
1076
1102
|
this.buffer += cleaned;
|
|
1077
1103
|
const { sentences, tail } = splitSentences(this.buffer);
|
|
@@ -1094,6 +1120,8 @@ var SentenceSegmenter = class {
|
|
|
1094
1120
|
flush() {
|
|
1095
1121
|
const t = sanitizeForTts(this.buffer).trim();
|
|
1096
1122
|
this.buffer = "";
|
|
1123
|
+
this.inFence = false;
|
|
1124
|
+
this.ticks = "";
|
|
1097
1125
|
if (t && !SKIP_PREFIX.test(t)) return [t];
|
|
1098
1126
|
return [];
|
|
1099
1127
|
}
|
|
@@ -1183,6 +1211,9 @@ var TtsQueue = class {
|
|
|
1183
1211
|
onError;
|
|
1184
1212
|
/** 单句合成重试耗尽被跳过通知(每句一次;此前是静默丢句——真机「回复偶尔不朗读」根因之一)。 */
|
|
1185
1213
|
onSkip;
|
|
1214
|
+
/** 某会话队列跑空(无在途、无积压):「说完就关」据此判定朗读真正结束——客户端只能看到
|
|
1215
|
+
* 句间的播放空档,分不清「后面还有句子在合成」与「已全部读完」。 */
|
|
1216
|
+
onIdle;
|
|
1186
1217
|
/**
|
|
1187
1218
|
* M7②(Issue #15 R11):退避重启计时器句柄集。
|
|
1188
1219
|
*
|
|
@@ -1219,6 +1250,12 @@ var TtsQueue = class {
|
|
|
1219
1250
|
this.engine = options.engine;
|
|
1220
1251
|
this.onError = options.onError;
|
|
1221
1252
|
this.onSkip = options.onSkip;
|
|
1253
|
+
this.onIdle = options.onIdle;
|
|
1254
|
+
}
|
|
1255
|
+
/** 该会话当前无在途合成、无积压(未建队列也算空闲)。 */
|
|
1256
|
+
isIdle(sessionId) {
|
|
1257
|
+
const q = this.queues.get(sessionId);
|
|
1258
|
+
return !q || !q.busy && q.pending.length === 0;
|
|
1222
1259
|
}
|
|
1223
1260
|
/** 当前引擎音频 MIME(/preview 的 Content-Type 也用它)。 */
|
|
1224
1261
|
get mime() {
|
|
@@ -1400,7 +1437,12 @@ var TtsQueue = class {
|
|
|
1400
1437
|
q.busy = false;
|
|
1401
1438
|
if (this.queues.get(sessionId) !== q) return;
|
|
1402
1439
|
if (this.closed) return;
|
|
1403
|
-
if (q.pending.length
|
|
1440
|
+
if (q.pending.length === 0) {
|
|
1441
|
+
try {
|
|
1442
|
+
this.onIdle?.(sessionId);
|
|
1443
|
+
} catch {
|
|
1444
|
+
}
|
|
1445
|
+
} else {
|
|
1404
1446
|
const delay = q.errorNotified ? q.backoff : 0;
|
|
1405
1447
|
q.backoff = Math.min(8e3, delay + 1e3);
|
|
1406
1448
|
if (delay > 0) {
|
|
@@ -2205,13 +2247,24 @@ var en = {
|
|
|
2205
2247
|
descBargeInSalvage: "When you speak to interrupt while the agent is reading aloud, keep what you said from speech onset to break confirmation and merge it into recognition (fixes swallowed break-in speech; off = discard pre-break audio; recommended off only on speakers without echo cancellation)",
|
|
2206
2248
|
descLlmCorrect: "Before sending, run one LLM pass over the whole transcribed text (typos/homophones/punctuation only, meaning preserved; requires a default model configured in the host \u2014 otherwise the original text is sent as-is). On = one extra correction round trip per message: usually under 1 second, at most ~10 seconds; at most 10 times per minute \u2014 when voice mode is off or the limit is hit, the original text is sent. Failed or abnormal output also falls back to the original text",
|
|
2207
2249
|
descYieldMs: "How long (ms) to drop frames after a yield trigger (500-3000, default 1500; within the window the existing hardBreak takes over if the user really wants to speak; auto-resume after the window expires). Hold-to-talk mode only, during playback",
|
|
2208
|
-
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk)",
|
|
2250
|
+
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk / once: one utterance, then exit after the reply is read aloud)",
|
|
2209
2251
|
modeToggle: "Continuous listening",
|
|
2210
2252
|
modeHold: "Hold to talk",
|
|
2253
|
+
modeOnce: "One-shot",
|
|
2254
|
+
stopReading: "Stop reading",
|
|
2255
|
+
readAloudLabel: "Read replies",
|
|
2256
|
+
readAloudVoice: "Voice mode",
|
|
2257
|
+
readAloudAlways: "Always",
|
|
2258
|
+
readAloudOff: "Off",
|
|
2259
|
+
descReadAloud: "Voice mode = read replies only in voice mode (default); Always = read every reply in the current session, typed ones included; Off = never read aloud",
|
|
2260
|
+
showCaptionsLabel: "Caption overlay",
|
|
2261
|
+
descShowCaptions: "Show a floating caption of the current sentence while reading aloud",
|
|
2262
|
+
showStatusBarLabel: "Status bar",
|
|
2263
|
+
descShowStatusBar: "Show the voice status bar above the composer (waveform, transcript, timer, notices, exit); when off, state shows only on the mic button",
|
|
2211
2264
|
descWakeWord: 'Wake word (default off; e.g. "Hey D"): recognition starts only after you say it, to avoid accidental triggers. You may say it together with your command ("Hey D, check the weather" \u2014 the wake word is stripped and never sent); it must be repeated after each utterance split or barge-in; toggle mode only (inactive in hold / manual barge-in \u2014 and equally inactive when the detect probe fails and falls back to manual, the default on machines without native echo cancellation such as Safari); saying it while the agent is reading does not trigger (barge-in stays VAD-based). Fault-tolerant matching (homophones / leading fillers); 3-4 characters recommended; not a dedicated KWS engine \u2014 noisy environments may delay or falsely trigger',
|
|
2212
2265
|
wakePlaceholder: "e.g. Hey D",
|
|
2213
2266
|
settingsCardDesc: "Engine / voice / rate / interrupt / barge-in / echo gate / silence / idle / model host / auto-send / auto-resume / mode / wake word / tool beep / ITN / caption font / caption width / yielding / yield window / barge-in salvage / LLM correction",
|
|
2214
|
-
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
2267
|
+
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / read replies / status bar / caption overlay / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
2215
2268
|
effectivePending: "{count} change(s) will apply next time you enter voice mode: {items}",
|
|
2216
2269
|
valueOn: "On",
|
|
2217
2270
|
valueOff: "Off",
|
|
@@ -2533,6 +2586,9 @@ var VOICE_SETTINGS_DEFAULTS = {
|
|
|
2533
2586
|
autoSend: true,
|
|
2534
2587
|
autoResume: false,
|
|
2535
2588
|
mode: "toggle",
|
|
2589
|
+
readAloud: "voice",
|
|
2590
|
+
showCaptions: true,
|
|
2591
|
+
showStatusBar: true,
|
|
2536
2592
|
// 批 7O(ADR-0006):bargeInMode 默认 'auto' → 'detect'(I10 豁免:ADR-0006 已 accepted 拍板,
|
|
2537
2593
|
// 老用户显式 auto 不受影响,新用户/未调过的用户开箱即对)。
|
|
2538
2594
|
bargeInMode: "detect",
|
|
@@ -2568,6 +2624,9 @@ var DESC = {
|
|
|
2568
2624
|
autoSend: en.descAutoSend,
|
|
2569
2625
|
autoResume: en.descAutoResume,
|
|
2570
2626
|
mode: en.descMode,
|
|
2627
|
+
readAloud: en.descReadAloud,
|
|
2628
|
+
showCaptions: en.descShowCaptions,
|
|
2629
|
+
showStatusBar: en.descShowStatusBar,
|
|
2571
2630
|
bargeInMode: en.descBargeIn,
|
|
2572
2631
|
echoGateDb: en.descEchoGate,
|
|
2573
2632
|
shortcut: en.descShortcut,
|
|
@@ -2605,7 +2664,10 @@ function createVoiceSettingsSchema(defs) {
|
|
|
2605
2664
|
autoSend: z.boolean().default(d.autoSend).description(DESC.autoSend),
|
|
2606
2665
|
// 批 7N 重做 5/5:与 strings.ts descAutoResume 同步——明确「下次进入语音会话即生效」。
|
|
2607
2666
|
autoResume: z.boolean().default(d.autoResume).description(DESC.autoResume),
|
|
2608
|
-
mode: z.union([z.const("toggle"), z.const("hold")]).default(d.mode).description(DESC.mode),
|
|
2667
|
+
mode: z.union([z.const("toggle"), z.const("hold"), z.const("once")]).default(d.mode).description(DESC.mode),
|
|
2668
|
+
readAloud: z.union([z.const("voice"), z.const("always"), z.const("off")]).default(d.readAloud).description(DESC.readAloud),
|
|
2669
|
+
showCaptions: z.boolean().default(d.showCaptions).description(DESC.showCaptions),
|
|
2670
|
+
showStatusBar: z.boolean().default(d.showStatusBar).description(DESC.showStatusBar),
|
|
2609
2671
|
bargeInMode: z.union([z.const("auto"), z.const("manual"), z.const("detect")]).default(d.bargeInMode).description(DESC.bargeInMode),
|
|
2610
2672
|
echoGateDb: z.number().min(3).max(12).default(d.echoGateDb).description(
|
|
2611
2673
|
DESC.echoGateDb
|
|
@@ -2664,7 +2726,10 @@ var Config = z.object({
|
|
|
2664
2726
|
// 本插件自带 settings-form 设置面板 + /voice-mode/config,不受影响)。
|
|
2665
2727
|
autoSend: z.boolean().default(true),
|
|
2666
2728
|
autoResume: z.boolean().default(false),
|
|
2667
|
-
mode: z.union([z.const("toggle"), z.const("hold")]).default("toggle"),
|
|
2729
|
+
mode: z.union([z.const("toggle"), z.const("hold"), z.const("once")]).default("toggle"),
|
|
2730
|
+
readAloud: z.union([z.const("voice"), z.const("always"), z.const("off")]).default("voice"),
|
|
2731
|
+
showCaptions: z.boolean().default(true),
|
|
2732
|
+
showStatusBar: z.boolean().default(true),
|
|
2668
2733
|
bargeInMode: z.union([z.const("auto"), z.const("manual"), z.const("detect")]).default("detect"),
|
|
2669
2734
|
// I3 + M7(zod 界):echoGateDb / yieldMs 与 settings schema 同界(3-12 dB / 500-3000ms)。
|
|
2670
2735
|
// client 与 NumberField 虽会 clamp,但那只是 UI 兜底——Config 层无界时 YAML 手滑
|
|
@@ -2686,6 +2751,9 @@ var Config = z.object({
|
|
|
2686
2751
|
// I3 + M7(zod 界):500-3000ms,与 settings schema 一致。
|
|
2687
2752
|
yieldMs: z.number().min(500).max(3e3).default(1500)
|
|
2688
2753
|
});
|
|
2754
|
+
function displayOf(v) {
|
|
2755
|
+
return { readAloud: v.readAloud, showCaptions: v.showCaptions, showStatusBar: v.showStatusBar };
|
|
2756
|
+
}
|
|
2689
2757
|
function voiceSettingsFromConfig(config) {
|
|
2690
2758
|
const {
|
|
2691
2759
|
ttsEngine,
|
|
@@ -2699,6 +2767,9 @@ function voiceSettingsFromConfig(config) {
|
|
|
2699
2767
|
autoSend,
|
|
2700
2768
|
autoResume,
|
|
2701
2769
|
mode,
|
|
2770
|
+
readAloud,
|
|
2771
|
+
showCaptions,
|
|
2772
|
+
showStatusBar,
|
|
2702
2773
|
bargeInMode,
|
|
2703
2774
|
echoGateDb,
|
|
2704
2775
|
shortcut,
|
|
@@ -2726,6 +2797,9 @@ function voiceSettingsFromConfig(config) {
|
|
|
2726
2797
|
autoSend,
|
|
2727
2798
|
autoResume,
|
|
2728
2799
|
mode,
|
|
2800
|
+
readAloud,
|
|
2801
|
+
showCaptions,
|
|
2802
|
+
showStatusBar,
|
|
2729
2803
|
bargeInMode,
|
|
2730
2804
|
echoGateDb,
|
|
2731
2805
|
shortcut,
|
|
@@ -2744,6 +2818,8 @@ function voiceSettingsFromConfig(config) {
|
|
|
2744
2818
|
}
|
|
2745
2819
|
function apply(ctx, config) {
|
|
2746
2820
|
let activeVoiceSession = null;
|
|
2821
|
+
let focusedSessionId = null;
|
|
2822
|
+
let focusedTabId = null;
|
|
2747
2823
|
let activeTabId = null;
|
|
2748
2824
|
let activeVoiceLang = "zh";
|
|
2749
2825
|
let ownerYieldTimer = null;
|
|
@@ -2924,7 +3000,8 @@ function apply(ctx, config) {
|
|
|
2924
3000
|
onError: (sessionId) => broadcast("tts-error", { sessionId }),
|
|
2925
3001
|
// 单句重试耗尽被跳过:显式下行(客户端提示 + 诊断),不再静默丢句。
|
|
2926
3002
|
// streak = 连续被跳过的句数:客户端据此区分偶发抖动与「云端整体不可用」(如服务端拒绝握手)。
|
|
2927
|
-
onSkip: (sessionId, text, streak) => broadcast("tts-skip", { sessionId, text: text.slice(0, 80), streak })
|
|
3003
|
+
onSkip: (sessionId, text, streak) => broadcast("tts-skip", { sessionId, text: text.slice(0, 80), streak }),
|
|
3004
|
+
onIdle: (sessionId) => broadcast("tts-idle", { sessionId })
|
|
2928
3005
|
});
|
|
2929
3006
|
queue.updateVoice(vset.voice, vset.rate);
|
|
2930
3007
|
const unsubscribe = queue.subscribe((frame) => broadcast("audio", frame));
|
|
@@ -2933,6 +3010,7 @@ function apply(ctx, config) {
|
|
|
2933
3010
|
const applyVset = (next) => {
|
|
2934
3011
|
const prev = vset;
|
|
2935
3012
|
vset = next;
|
|
3013
|
+
broadcast("display", displayOf(next));
|
|
2936
3014
|
if (next.ttsEngine !== engineKind) {
|
|
2937
3015
|
engineKind = next.ttsEngine;
|
|
2938
3016
|
queue.setEngine(makeEngine(engineKind));
|
|
@@ -2991,7 +3069,8 @@ function apply(ctx, config) {
|
|
|
2991
3069
|
const rawSessionId = options.sessionId;
|
|
2992
3070
|
if (!config.enabled || rawSessionId === void 0 || options.purpose !== void 0) return next();
|
|
2993
3071
|
const sessionId = rawSessionId;
|
|
2994
|
-
|
|
3072
|
+
const alwaysRead = vset.readAloud === "always" && focusedSessionId === sessionId;
|
|
3073
|
+
if (activeVoiceSession !== sessionId && !alwaysRead) return next();
|
|
2995
3074
|
const gen = (turnGen.get(sessionId) ?? 0) + 1;
|
|
2996
3075
|
turnGen.set(sessionId, gen);
|
|
2997
3076
|
return tapActiveStream(
|
|
@@ -3000,8 +3079,11 @@ function apply(ctx, config) {
|
|
|
3000
3079
|
queue,
|
|
3001
3080
|
broadcast,
|
|
3002
3081
|
(state) => {
|
|
3003
|
-
if ((turnGen.get(sessionId) ?? 0)
|
|
3004
|
-
|
|
3082
|
+
if ((turnGen.get(sessionId) ?? 0) !== gen) return;
|
|
3083
|
+
setTurn(sessionId, state);
|
|
3084
|
+
if (state === "listening" && queue.isIdle(sessionId)) broadcast("tts-idle", { sessionId });
|
|
3085
|
+
},
|
|
3086
|
+
vset.readAloud !== "off"
|
|
3005
3087
|
);
|
|
3006
3088
|
});
|
|
3007
3089
|
const base = BASE_PATH;
|
|
@@ -3038,6 +3120,9 @@ function apply(ctx, config) {
|
|
|
3038
3120
|
autoSend: vset.autoSend,
|
|
3039
3121
|
autoResume: vset.autoResume,
|
|
3040
3122
|
mode: vset.mode,
|
|
3123
|
+
readAloud: vset.readAloud,
|
|
3124
|
+
showCaptions: vset.showCaptions,
|
|
3125
|
+
showStatusBar: vset.showStatusBar,
|
|
3041
3126
|
bargeInMode: vset.bargeInMode,
|
|
3042
3127
|
echoGateDb: vset.echoGateDb,
|
|
3043
3128
|
shortcut: vset.shortcut,
|
|
@@ -3419,13 +3504,13 @@ function apply(ctx, config) {
|
|
|
3419
3504
|
keepAsr = parsed.keepAsr === true;
|
|
3420
3505
|
} catch {
|
|
3421
3506
|
}
|
|
3422
|
-
if (sessionId && sessionId === activeVoiceSession) {
|
|
3507
|
+
if (sessionId && (sessionId === activeVoiceSession || sessionId === focusedSessionId)) {
|
|
3423
3508
|
if (!limiter.hit(`cancel:${sessionId}`, 2, 1e3)) {
|
|
3424
3509
|
respondJson2(res, 429, { code: "rate_limited", error: "rate limited" });
|
|
3425
3510
|
return;
|
|
3426
3511
|
}
|
|
3427
3512
|
queue.cancel(sessionId);
|
|
3428
|
-
if (!keepAsr) asr.reset(sessionId);
|
|
3513
|
+
if (!keepAsr && sessionId === activeVoiceSession) asr.reset(sessionId);
|
|
3429
3514
|
}
|
|
3430
3515
|
respondJson2(res, 200, { ok: true });
|
|
3431
3516
|
});
|
|
@@ -3496,11 +3581,11 @@ function apply(ctx, config) {
|
|
|
3496
3581
|
let mode;
|
|
3497
3582
|
try {
|
|
3498
3583
|
const parsed = JSON.parse(body || "{}");
|
|
3499
|
-
mode = parsed.mode === "toggle" || parsed.mode === "hold" ? parsed.mode : void 0;
|
|
3584
|
+
mode = parsed.mode === "toggle" || parsed.mode === "hold" || parsed.mode === "once" ? parsed.mode : void 0;
|
|
3500
3585
|
} catch {
|
|
3501
3586
|
}
|
|
3502
3587
|
if (!mode) {
|
|
3503
|
-
respondJson2(res, 400, { code: "bad_request", error: "mode must be toggle or
|
|
3588
|
+
respondJson2(res, 400, { code: "bad_request", error: "mode must be toggle, hold or once" });
|
|
3504
3589
|
return;
|
|
3505
3590
|
}
|
|
3506
3591
|
const persistMode = settingsScopeRef ? settingsScopeRef.update({ mode }) : persistSettings({ mode });
|
|
@@ -3514,6 +3599,39 @@ function apply(ctx, config) {
|
|
|
3514
3599
|
}
|
|
3515
3600
|
})
|
|
3516
3601
|
);
|
|
3602
|
+
ctx.effect(
|
|
3603
|
+
() => ctx.webServer.register({
|
|
3604
|
+
kind: "exact",
|
|
3605
|
+
path: `${base}/focus`,
|
|
3606
|
+
handler: (req, res) => {
|
|
3607
|
+
if (denyNonLoopback(req, res)) return;
|
|
3608
|
+
if (denyCrossOrigin(req, res)) return;
|
|
3609
|
+
collectBody(req, res, MAX_JSON_BODY, (body) => {
|
|
3610
|
+
let parsed = {};
|
|
3611
|
+
try {
|
|
3612
|
+
parsed = JSON.parse(body || "{}");
|
|
3613
|
+
} catch {
|
|
3614
|
+
}
|
|
3615
|
+
const { sessionId, tabId } = parsed;
|
|
3616
|
+
const validTab = typeof tabId === "string" && tabId.length > 0 && tabId.length <= 64;
|
|
3617
|
+
const validSid = typeof sessionId === "string" && sessionId.length > 0 && sessionId.length <= 128;
|
|
3618
|
+
if (!validTab || !(validSid || sessionId === null)) {
|
|
3619
|
+
respondJson2(res, 400, { code: "bad_request", error: "expected {sessionId: string|null, tabId: string}" });
|
|
3620
|
+
return;
|
|
3621
|
+
}
|
|
3622
|
+
if (validSid) {
|
|
3623
|
+
focusedSessionId = sessionId;
|
|
3624
|
+
focusedTabId = tabId;
|
|
3625
|
+
} else if (tabId === focusedTabId) {
|
|
3626
|
+
focusedSessionId = null;
|
|
3627
|
+
focusedTabId = null;
|
|
3628
|
+
}
|
|
3629
|
+
broadcast("focus", { sessionId: focusedSessionId, tabId: focusedTabId });
|
|
3630
|
+
respondJson2(res, 200, { ok: true, sessionId: focusedSessionId, tabId: focusedTabId });
|
|
3631
|
+
});
|
|
3632
|
+
}
|
|
3633
|
+
})
|
|
3634
|
+
);
|
|
3517
3635
|
ctx.effect(
|
|
3518
3636
|
() => ctx.webServer.register({
|
|
3519
3637
|
kind: "exact",
|
|
@@ -3521,10 +3639,6 @@ function apply(ctx, config) {
|
|
|
3521
3639
|
handler: (req, res) => {
|
|
3522
3640
|
if (denyNonLoopback(req, res)) return;
|
|
3523
3641
|
if (denyCrossOrigin(req, res)) return;
|
|
3524
|
-
if (sseClients.size >= 4) {
|
|
3525
|
-
respondJson2(res, 429, { code: "too_many_streams", error: "too many streams" });
|
|
3526
|
-
return;
|
|
3527
|
-
}
|
|
3528
3642
|
let tabId = null;
|
|
3529
3643
|
try {
|
|
3530
3644
|
const u = new URL(req.url ?? "/", "http://localhost");
|
|
@@ -3532,6 +3646,21 @@ function apply(ctx, config) {
|
|
|
3532
3646
|
} catch {
|
|
3533
3647
|
}
|
|
3534
3648
|
if (tabId !== null && tabId.length > 64) tabId = null;
|
|
3649
|
+
if (tabId !== null) {
|
|
3650
|
+
for (const old of sseClients) {
|
|
3651
|
+
if (old.tabId !== tabId) continue;
|
|
3652
|
+
sseClients.delete(old);
|
|
3653
|
+
try {
|
|
3654
|
+
old.send("replaced", {});
|
|
3655
|
+
} catch {
|
|
3656
|
+
}
|
|
3657
|
+
old.end();
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
if (sseClients.size >= 8) {
|
|
3661
|
+
respondJson2(res, 429, { code: "too_many_streams", error: "too many streams" });
|
|
3662
|
+
return;
|
|
3663
|
+
}
|
|
3535
3664
|
res.writeHead(200, {
|
|
3536
3665
|
"content-type": "text/event-stream; charset=utf-8",
|
|
3537
3666
|
"cache-control": "no-cache, no-transform",
|
|
@@ -3544,7 +3673,13 @@ data: ${JSON.stringify(payload)}
|
|
|
3544
3673
|
|
|
3545
3674
|
`);
|
|
3546
3675
|
};
|
|
3547
|
-
const
|
|
3676
|
+
const end = () => {
|
|
3677
|
+
try {
|
|
3678
|
+
res.end();
|
|
3679
|
+
} catch {
|
|
3680
|
+
}
|
|
3681
|
+
};
|
|
3682
|
+
const client = { tabId, send, end };
|
|
3548
3683
|
sseClients.add(client);
|
|
3549
3684
|
if (tabId !== null) latestConnByTab.set(tabId, client);
|
|
3550
3685
|
if (tabId !== null && tabId === activeTabId && ownerYieldTimer) {
|
|
@@ -3552,10 +3687,13 @@ data: ${JSON.stringify(payload)}
|
|
|
3552
3687
|
ownerYieldTimer = null;
|
|
3553
3688
|
}
|
|
3554
3689
|
send("mode", { active: activeVoiceSession, ownerTabId: activeTabId });
|
|
3690
|
+
send("focus", { sessionId: focusedSessionId, tabId: focusedTabId });
|
|
3691
|
+
send("display", displayOf(vset));
|
|
3555
3692
|
const heartbeat = setInterval(() => {
|
|
3556
3693
|
try {
|
|
3557
3694
|
res.write(": hb\n");
|
|
3558
3695
|
} catch {
|
|
3696
|
+
cleanup();
|
|
3559
3697
|
}
|
|
3560
3698
|
}, 25e3);
|
|
3561
3699
|
let cleaned = false;
|
|
@@ -3566,6 +3704,11 @@ data: ${JSON.stringify(payload)}
|
|
|
3566
3704
|
sseClients.delete(client);
|
|
3567
3705
|
if (tabId !== null && latestConnByTab.get(tabId) === client) {
|
|
3568
3706
|
latestConnByTab.delete(tabId);
|
|
3707
|
+
if (tabId === focusedTabId) {
|
|
3708
|
+
focusedSessionId = null;
|
|
3709
|
+
focusedTabId = null;
|
|
3710
|
+
broadcast("focus", { sessionId: null, tabId: null });
|
|
3711
|
+
}
|
|
3569
3712
|
if (tabId === activeTabId) {
|
|
3570
3713
|
if (ownerYieldTimer) clearTimeout(ownerYieldTimer);
|
|
3571
3714
|
ownerYieldTimer = setTimeout(() => yieldActiveSession(activeVoiceSession), 8e3);
|
|
@@ -3608,7 +3751,7 @@ function collectBody(req, res, maxBytes, onBody) {
|
|
|
3608
3751
|
req.on("error", () => {
|
|
3609
3752
|
});
|
|
3610
3753
|
}
|
|
3611
|
-
async function* tapActiveStream(sessionId, inner, queue, broadcast, onTurn) {
|
|
3754
|
+
async function* tapActiveStream(sessionId, inner, queue, broadcast, onTurn, speak = true) {
|
|
3612
3755
|
const segmenter = new SentenceSegmenter();
|
|
3613
3756
|
let firstTokenBroadcast = false;
|
|
3614
3757
|
let firstSentenceBroadcast = false;
|
|
@@ -3618,7 +3761,7 @@ async function* tapActiveStream(sessionId, inner, queue, broadcast, onTurn) {
|
|
|
3618
3761
|
if (flushed) return;
|
|
3619
3762
|
flushed = true;
|
|
3620
3763
|
for (const s of segmenter.flush()) {
|
|
3621
|
-
queue.enqueue(sessionId, s);
|
|
3764
|
+
if (speak) queue.enqueue(sessionId, s);
|
|
3622
3765
|
}
|
|
3623
3766
|
};
|
|
3624
3767
|
try {
|
|
@@ -3634,7 +3777,7 @@ async function* tapActiveStream(sessionId, inner, queue, broadcast, onTurn) {
|
|
|
3634
3777
|
firstSentenceBroadcast = true;
|
|
3635
3778
|
broadcast("latency", { sessionId, stage: "first-sentence-text" });
|
|
3636
3779
|
}
|
|
3637
|
-
queue.enqueue(sessionId, s);
|
|
3780
|
+
if (speak) queue.enqueue(sessionId, s);
|
|
3638
3781
|
}
|
|
3639
3782
|
}
|
|
3640
3783
|
if (chunk.type === "tool-call-delta" && chunk.name) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-voice-mode",
|
|
3
3
|
"description": "Full-duplex voice plugin for DeepSeek Harness: local zipformer2 streaming ASR (no API key) → editable draft; Edge TTS or local VITS / Kokoro read-aloud with live captions; true barge-in; hardened HTTP surface + model SHA256 pinning; compatible with all dsh releases since 0.1.1-rc.2 (verified 0.1.1-rc.2 → 0.2.1-rc.2).",
|
|
4
4
|
"icon": "./icon.svg",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.27",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "node build.mjs",
|
|
49
49
|
"prepack": "node build.mjs",
|
|
50
|
-
"test": "node test/segmenter.test.mjs && node test/aec.test.mjs && node test/download.test.mjs && node test/endpoint.test.mjs && node test/endpoint-short.test.mjs && node test/resample.test.mjs && node test/sense-worker.test.mjs && node test/detect-route.test.mjs && node test/verify-client.mjs && node test/asr-host-rebuild.test.mjs && node test/barge-in-manual.test.mjs && node test/barge-in-detect-behavior.test.mjs && node test/sense-lang.test.mjs && node test/caption-a11y.test.mjs && node test/emotion.test.mjs && node test/emotion-tts-local.test.mjs && node test/emotion-integration.test.mjs && node test/backchannel.test.mjs && node test/strings-coverage.test.mjs && node test/yield-ms-wiring.test.mjs && node test/fail-streak-notice.test.mjs && node test/partial-gating.test.mjs && node test/asr-lifecycle.test.mjs && node test/steer-submit-behavior.test.mjs && node test/correct-cycle-behavior.test.mjs && node test/host-security-behavior.test.mjs && node test/echo-tail.test.mjs && node test/host-fixes.test.mjs && node test/tts-queue-engine.test.mjs && node test/matchBackchannel.test.mjs && node test/settings-load.test.mjs && node test/preview-error.test.mjs && node test/hold-clear.test.mjs && node test/barge-in-detect.test.mjs && node test/wakeword.test.mjs && node test/wake-standby.test.mjs && node test/wake-flow.test.mjs && node test/tts-playback.test.mjs && node test/settings-store.test.mjs && node test/i18n.test.mjs && node test/i18n-protocol.test.mjs && node test/package-install.test.mjs && node test/tts-runtime.test.mjs && node test/steer-submit.test.mjs && node test/draft-compose.test.mjs && node test/finalize-ux.test.mjs && node test/llm-correct.test.mjs && node test/autosend-decouple.test.mjs && node test/settings-effective.test.mjs && node test/silent-path-hints.test.mjs && node test/host-hardening.test.mjs",
|
|
50
|
+
"test": "node test/segmenter.test.mjs && node test/aec.test.mjs && node test/download.test.mjs && node test/endpoint.test.mjs && node test/endpoint-short.test.mjs && node test/resample.test.mjs && node test/sense-worker.test.mjs && node test/detect-route.test.mjs && node test/verify-client.mjs && node test/asr-host-rebuild.test.mjs && node test/barge-in-manual.test.mjs && node test/barge-in-detect-behavior.test.mjs && node test/sense-lang.test.mjs && node test/caption-a11y.test.mjs && node test/emotion.test.mjs && node test/emotion-tts-local.test.mjs && node test/emotion-integration.test.mjs && node test/backchannel.test.mjs && node test/strings-coverage.test.mjs && node test/yield-ms-wiring.test.mjs && node test/fail-streak-notice.test.mjs && node test/partial-gating.test.mjs && node test/asr-lifecycle.test.mjs && node test/steer-submit-behavior.test.mjs && node test/correct-cycle-behavior.test.mjs && node test/host-security-behavior.test.mjs && node test/echo-tail.test.mjs && node test/host-fixes.test.mjs && node test/tts-queue-engine.test.mjs && node test/matchBackchannel.test.mjs && node test/settings-load.test.mjs && node test/preview-error.test.mjs && node test/hold-clear.test.mjs && node test/barge-in-detect.test.mjs && node test/wakeword.test.mjs && node test/wake-standby.test.mjs && node test/wake-flow.test.mjs && node test/tts-playback.test.mjs && node test/settings-store.test.mjs && node test/i18n.test.mjs && node test/i18n-protocol.test.mjs && node test/package-install.test.mjs && node test/tts-runtime.test.mjs && node test/steer-submit.test.mjs && node test/draft-compose.test.mjs && node test/finalize-ux.test.mjs && node test/llm-correct.test.mjs && node test/autosend-decouple.test.mjs && node test/settings-effective.test.mjs && node test/silent-path-hints.test.mjs && node test/host-hardening.test.mjs && node test/mic-gesture.test.mjs",
|
|
51
51
|
"verify:client": "node test/verify-client.mjs",
|
|
52
52
|
"prefetch": "node scripts/prefetch.mjs",
|
|
53
53
|
"list-voices": "node scripts/list-voices.mjs",
|