dsh-voice-mode 0.7.27 → 0.7.28

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/lib/client.js CHANGED
@@ -510,6 +510,7 @@ function createAsrEngine(config, sessionId) {
510
510
  let preRollStartWall = 0;
511
511
  let preRollSeedWall = null;
512
512
  let wasPlaying = false;
513
+ let gateQueryScope = false;
513
514
  let partialFailStreak = 0;
514
515
  let detectFailStreak = 0;
515
516
  let salvagedSegment = false;
@@ -560,6 +561,14 @@ function createAsrEngine(config, sessionId) {
560
561
  return out;
561
562
  };
562
563
  const sliceSince = (from) => sliceChunks(segment, from);
564
+ const deliverIsSpeech = (speech) => {
565
+ gateQueryScope = true;
566
+ try {
567
+ config.onIsSpeech?.(speech);
568
+ } finally {
569
+ gateQueryScope = false;
570
+ }
571
+ };
563
572
  const requestPartial = async () => {
564
573
  if (partialInFlight || segment.length === 0) return;
565
574
  await resetGate;
@@ -624,6 +633,7 @@ function createAsrEngine(config, sessionId) {
624
633
  if (epoch !== segmentEpoch) return;
625
634
  if (state === "wake" && wakeEnabled) {
626
635
  uploadedSamples = Math.max(uploadedSamples, from + samples.length);
636
+ partialFailStreak = 0;
627
637
  emit(partialListeners, out.text ?? "");
628
638
  if (matchWakeWord(out.text ?? "", wakeWord)) {
629
639
  wakeConsumed = true;
@@ -633,7 +643,7 @@ function createAsrEngine(config, sessionId) {
633
643
  }
634
644
  return;
635
645
  }
636
- if (out.isSpeech !== void 0) config.onIsSpeech?.(out.isSpeech);
646
+ if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
637
647
  if (state === "loading-model") setState("speech");
638
648
  uploadedSamples = Math.max(uploadedSamples, from + samples.length);
639
649
  partialFailStreak = 0;
@@ -683,8 +693,8 @@ function createAsrEngine(config, sessionId) {
683
693
  if (!res.ok) return;
684
694
  const out = await res.json();
685
695
  if (epoch !== segmentEpoch || gen !== detectGeneration) return;
686
- if (out.isSpeech !== void 0) config.onIsSpeech?.(out.isSpeech);
687
696
  if (out.isSpeech === true && preRollSeedWall === null) preRollSeedWall = reqBodyStartWall - 250;
697
+ if (out.isSpeech !== void 0) deliverIsSpeech(out.isSpeech);
688
698
  detectFailStreak = 0;
689
699
  detectSent += samples.length;
690
700
  while (detectChunks.length > 0 && detectSent >= detectChunks[0].length) {
@@ -883,8 +893,20 @@ function createAsrEngine(config, sessionId) {
883
893
  data = echo.process(data, ref);
884
894
  }
885
895
  let sum = 0;
886
- for (let i = 0; i < data.length; i++) sum += data[i] * data[i];
887
- const rms = Math.sqrt(sum / data.length);
896
+ let nonFinite = 0;
897
+ for (let i = 0; i < data.length; i++) {
898
+ const v = data[i];
899
+ if (Number.isFinite(v)) sum += v * v;
900
+ else nonFinite++;
901
+ }
902
+ let rms = Math.sqrt(sum / data.length);
903
+ if (nonFinite > 0) {
904
+ const clean = new Float32Array(data);
905
+ for (let i = 0; i < clean.length; i++) if (!Number.isFinite(clean[i])) clean[i] = 0;
906
+ data = clean;
907
+ if (!Number.isFinite(rms)) rms = 0;
908
+ }
909
+ const frameValid = nonFinite === 0;
888
910
  const durationMs = data.length / SAMPLE_RATE2 * 1e3;
889
911
  for (const fn of levelListeners) {
890
912
  try {
@@ -896,14 +918,18 @@ function createAsrEngine(config, sessionId) {
896
918
  const gateRatio = Math.pow(10, (config.echoGateDb ?? 6) / 20);
897
919
  const peakDecay = Math.pow(0.9, durationMs / 64);
898
920
  const floorAlpha = 1 - Math.pow(0.98, durationMs / 64);
899
- if (playingNow) {
921
+ if (!Number.isFinite(echoFloorRms)) echoFloorRms = 0;
922
+ if (!Number.isFinite(echoPeak)) echoPeak = 0;
923
+ if (playingNow && frameValid) {
900
924
  latestResidualRms = rms;
901
925
  echoPeak = Math.max(echoPeak * peakDecay, rms);
902
926
  }
903
927
  const doubleTalk = playingNow && echoFloorRms > 0 && rms > echoFloorRms * gateRatio;
904
928
  if (playingNow) {
905
- if (echoFloorRms === 0) echoFloorRms = rms;
906
- else if (!doubleTalk) echoFloorRms = echoFloorRms * (1 - floorAlpha) + rms * floorAlpha;
929
+ if (frameValid) {
930
+ if (echoFloorRms === 0) echoFloorRms = rms;
931
+ else if (!doubleTalk) echoFloorRms = echoFloorRms * (1 - floorAlpha) + rms * floorAlpha;
932
+ }
907
933
  } else {
908
934
  echoPeak = 0;
909
935
  }
@@ -1192,10 +1218,21 @@ function createAsrEngine(config, sessionId) {
1192
1218
  get holding() {
1193
1219
  return holdActive;
1194
1220
  },
1195
- /** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。 */
1221
+ /** A2.5 回声门控:当前残差是否明显高于回声地板(marginDb 默认 6dB)——判用户人声而非回声。
1222
+ * Issue #15 R15-5:本方法是客户端回声门控的**唯一询问点**——客户端在「本次检测达到
1223
+ * 打断确认帧数」的瞬间问本方法,答 false 即「放弃本次检测(判为回声,不打断)」。
1224
+ * 引擎据此作废抢救种子:被拒检测的窗口不得成为下次真打断的锚点(种子陈旧会被
1225
+ * Math.max 钳到环起点 → 整环 2s AI 音频并入用户消息)。作用域限定见 gateQueryScope。 */
1196
1226
  aboveEchoFloor(marginDb = 6) {
1197
- if (echoFloorRms === 0) return false;
1198
- return echoPeak > echoFloorRms * Math.pow(10, marginDb / 20);
1227
+ const pass = echoFloorRms > 0 && echoPeak > echoFloorRms * Math.pow(10, marginDb / 20);
1228
+ if (!pass && gateQueryScope) preRollSeedWall = null;
1229
+ return pass;
1230
+ },
1231
+ /** 作废抢救种子(客户端放弃本次检测时调用——语义见 AsrEngine.invalidateSalvageSeed)。
1232
+ * Issue #15 R15-5:补「从未问过门控」的放弃路径(确认帧数未达门槛 / 迟滞衰减归零):
1233
+ * 这类检测不会触发上面的门控询问点,引擎只能由客户端显式告知。 */
1234
+ invalidateSalvageSeed() {
1235
+ preRollSeedWall = null;
1199
1236
  },
1200
1237
  echoLevels() {
1201
1238
  return { floorRms: echoFloorRms, residualRms: latestResidualRms, peakRms: echoPeak };
@@ -1444,7 +1481,9 @@ var NlmsAec = class {
1444
1481
  const bufLen = xBuf.length;
1445
1482
  let cursor = this.cursor;
1446
1483
  for (let i = 0; i < n; i++) {
1447
- xBuf[cursor] = i < ref.length ? ref[i] : 0;
1484
+ let r = i < ref.length ? ref[i] : 0;
1485
+ if (!Number.isFinite(r) && !Number.isNaN(r)) r = 0;
1486
+ xBuf[cursor] = r;
1448
1487
  cursor = (cursor + 1) % bufLen;
1449
1488
  this.filled = Math.min(this.filled + 1, bufLen);
1450
1489
  const d = mic[i];
@@ -1459,10 +1498,11 @@ var NlmsAec = class {
1459
1498
  idx = (idx - 1 + bufLen) % bufLen;
1460
1499
  }
1461
1500
  const e = d - y;
1462
- out[i] = Number.isFinite(e) ? e : 0;
1501
+ const eSafe = Number.isFinite(e) ? e : 0;
1502
+ out[i] = eSafe;
1463
1503
  if (norm > MIN_REF_NORM && !this.frozen) {
1464
1504
  const denom = norm + this.eps;
1465
- const gain = this.mu * e / denom;
1505
+ const gain = this.mu * eSafe / denom;
1466
1506
  idx = (cursor - this.delay + bufLen) % bufLen;
1467
1507
  for (let t3 = 0; t3 < this.filterLength; t3++) {
1468
1508
  this.w[t3] += gain * xBuf[idx];
@@ -1470,10 +1510,16 @@ var NlmsAec = class {
1470
1510
  }
1471
1511
  }
1472
1512
  } else {
1473
- out[i] = d;
1513
+ out[i] = Number.isFinite(d) ? d : 0;
1474
1514
  }
1475
1515
  }
1476
1516
  this.cursor = cursor;
1517
+ for (let t3 = 0; t3 < this.filterLength; t3++) {
1518
+ if (!Number.isFinite(this.w[t3])) {
1519
+ this.w.fill(0);
1520
+ break;
1521
+ }
1522
+ }
1477
1523
  return out;
1478
1524
  }
1479
1525
  };
@@ -1546,6 +1592,7 @@ var ERROR_I18N_KEY = {
1546
1592
  unknown_session: "errUnknownSession",
1547
1593
  forbidden: "errForbidden",
1548
1594
  bad_request: "errBadRequest",
1595
+ method_not_allowed: "errMethodNotAllowed",
1549
1596
  engine_not_active: "errEngineNotActive",
1550
1597
  model_download_failed: "errModelDownload",
1551
1598
  too_many_streams: "errTooManyStreams",
@@ -1611,7 +1658,7 @@ var zh = {
1611
1658
  startFail: "\u8BED\u97F3\u6A21\u5F0F\u542F\u52A8\u5931\u8D25\uFF1A{err}",
1612
1659
  holdDots: "\u6309\u4F4F\u8BF4\u8BDD\u2026",
1613
1660
  exit: "\u9000\u51FA",
1614
- configUnavailableNote: "\uFF08\u8BBE\u7F6E\u6587\u6863\u672A\u5C31\u7EEA\uFF0C\u9762\u677F\u5C31\u7EEA\u540E\u4F1A\u81EA\u52A8\u51FA\u73B0\uFF09\u3002",
1661
+ configUnavailableNote: "\uFF08\u8BBE\u7F6E\u6587\u6863\u672A\u5C31\u7EEA\uFF0C\u6B63\u5728\u91CD\u8BD5\uFF1B\u9762\u677F\u5C31\u7EEA\u540E\u4F1A\u81EA\u52A8\u51FA\u73B0\uFF09\u3002",
1615
1662
  // settings-form
1616
1663
  previewNameFirst: "\u8BF7\u5148\u586B\u5199\u97F3\u8272\u540D\uFF08ShortName\uFF09",
1617
1664
  previewDisabled: "\u8BED\u97F3\u6A21\u5F0F\u5DF2\u7981\u7528\uFF08\u63D2\u4EF6 enabled=false\uFF09\uFF0C\u65E0\u6CD5\u8BD5\u542C",
@@ -1653,6 +1700,17 @@ var zh = {
1653
1700
  // R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
1654
1701
  echoRejectHint: "\u56DE\u58F0\u8F83\u5F3A\uFF0C\u6253\u65AD\u53EF\u80FD\u4E0D\u7075\u654F\u2014\u2014\u8FD9\u662F\u56DE\u58F0\u9632\u62A4\u5728\u751F\u6548\uFF0C\u53EF\u6234\u8033\u673A\u6216\u6539\u7528\u300C\u624B\u52A8\u6253\u65AD\u300D",
1655
1702
  shortcutInvalid: "\u5FEB\u6377\u952E\u65E0\u6548\uFF0C\u5DF2\u505C\u7528\uFF08\u53EF\u5728\u8BBE\u7F6E\u91CC\u6539\u4E3A\u5982 Ctrl+Shift+V\uFF1B\u7559\u7A7A\u8868\u793A\u53EA\u7528\u9EA6\u514B\u98CE\u6309\u94AE\uFF09",
1703
+ descComposerShortcut: "\u8F93\u5165\u6846\u6709\u7126\u70B9\u65F6\u7684\u5207\u6362\u5FEB\u6377\u952E\uFF08\u9ED8\u8BA4 Alt/Option+Enter\uFF1B\u7559\u7A7A\u5219\u53EA\u5728\u8F93\u5165\u6846\u5916\u751F\u6548\uFF09",
1704
+ composerShortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u8F93\u5165\u6846\u5185\uFF09",
1705
+ shortcutRecord: "\u5F55\u5236",
1706
+ shortcutRecording: "\u6309\u4E0B\u7EC4\u5408\u952E\u2026",
1707
+ shortcutCancel: "\u53D6\u6D88",
1708
+ shortcutNeedModifier: "\u9700\u8981\u81F3\u5C11\u4E00\u4E2A\u4FEE\u9970\u952E",
1709
+ shortcutUnsupportedKey: "\u53EA\u652F\u6301\u5B57\u6BCD\u3001\u6570\u5B57\u3001Enter\u3001Space\u3001Tab",
1710
+ shortcutPlaceholder: "\u70B9\u5F55\u5236\u540E\u6309\u7EC4\u5408\u952E",
1711
+ shortcutReset: "\u6062\u590D\u9ED8\u8BA4",
1712
+ shortcutNote: "\u8F93\u5165\u6846\u5185\u53EF\u7528 Alt/Option+Enter \u5207\u6362\uFF1B\u652F\u6301 Cmd / Ctrl / Alt / Shift \u7EC4\u5408\uFF1B\u7559\u7A7A\u8868\u793A\u53EA\u7528\u9EA6\u514B\u98CE\u6309\u94AE\u3002\u5F55\u5236\u65F6 Backspace \u6E05\u7A7A\u3001Esc \u53D6\u6D88\uFF1B\u907F\u514D\u6D4F\u89C8\u5668\u5360\u7528\u7684\u7EC4\u5408\uFF08\u5982 Cmd+W / T / N / L\uFF09\u3002\u4FEE\u6539\u540E\u7ACB\u5373\u751F\u6548\uFF0C\u65E0\u9700\u5237\u65B0\u3002",
1713
+ secShortcut: "\u5FEB\u6377\u952E",
1656
1714
  elapsedHint: "\u5F53\u524D\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u7528\u65F6\u957F",
1657
1715
  botLevelsHint: "AI \u6717\u8BFB\u97F3\u91CF\uFF08\u84DD\u8272\u6761 = \u6717\u8BFB\uFF0C\u7EFF\u8272\u6761 = \u9EA6\u514B\u98CE\uFF09",
1658
1716
  interruptConfirm: "\u6253\u65AD\u786E\u8BA4",
@@ -1706,7 +1764,7 @@ var zh = {
1706
1764
  descShowStatusBar: "\u5728\u8F93\u5165\u6846\u4E0A\u65B9\u663E\u793A\u8BED\u97F3\u72B6\u6001\u6761\uFF08\u6CE2\u5F62\u3001\u8BC6\u522B\u6587\u5B57\u3001\u8BA1\u65F6\u3001\u63D0\u793A\u3001\u9000\u51FA\uFF09\uFF1B\u5173\u95ED\u540E\u72B6\u6001\u53EA\u5728\u9EA6\u514B\u98CE\u6309\u94AE\u4E0A\u663E\u793A",
1707
1765
  descWakeWord: "\u5524\u9192\u8BCD\uFF08\u9ED8\u8BA4\u5173\uFF1B\u5982\u300C\u4F60\u597D\u5C0FD\u300D\uFF09\uFF1A\u8BF4\u51FA\u8BCD\u5934\u624D\u8FDB\u5165\u8BC6\u522B\uFF0C\u907F\u514D\u8BEF\u89E6\u3002\u53EF\u4E0E\u547D\u4EE4\u8FDE\u8BF4\uFF08\u300C\u4F60\u597D\u5C0FD\uFF0C\u5E2E\u6211\u67E5\u5929\u6C14\u300D\u2014\u2014\u8BCD\u5934\u4F1A\u81EA\u52A8\u5265\u6389\u3001\u4E0D\u8FDB\u6D88\u606F\uFF09\uFF1B\u6BCF\u53E5\u65AD\u53E5\u6216\u6253\u65AD\u540E\u9700\u91CD\u8BF4\uFF1B\u4EC5 toggle \u6A21\u5F0F\u751F\u6548\uFF08hold / \u624B\u52A8\u6253\u65AD\u4E0B\u4E0D\u751F\u6548\uFF1Bdetect \u81EA\u52A8\u63A2\u6D4B\u672A\u751F\u6548\u3001\u56DE\u843D manual \u65F6\u540C\u6837\u4E0D\u751F\u6548\u2014\u2014Safari \u7B49\u65E0\u539F\u751F\u56DE\u58F0\u6D88\u9664\u7684\u673A\u5668\u4F1A\u9ED8\u8BA4\u843D\u5230\u8FD9\u4E00\u6863\uFF09\uFF1B\u6717\u8BFB\u671F\u8BF4\u5524\u9192\u8BCD\u4E0D\u89E6\u53D1\uFF08\u6253\u65AD\u4ECD\u6309 VAD \u5F00\u53E3\u5373\u6253\u65AD\uFF09\u3002\u5339\u914D\u5E26\u5BB9\u9519\uFF08\u540C\u97F3\u5B57 / \u524D\u5BFC\u8BED\u6C14\u8BCD\uFF09\uFF0C\u5EFA\u8BAE 3-4 \u5B57\uFF1B\u975E\u4E13\u7528 KWS \u5F15\u64CE\uFF0C\u5608\u6742\u73AF\u5883\u53EF\u80FD\u5EF6\u8FDF\u6216\u8BEF\u6FC0\u6D3B",
1708
1766
  wakePlaceholder: "\u5982\uFF1A\u4F60\u597D\u5C0FD",
1709
- settingsCardDesc: "\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / \u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u9759\u97F3\u505C\u987F / \u7A7A\u95F2\u8D85\u65F6 / \u6A21\u578B\u955C\u50CF / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u9006\u6587\u672C\u5F52\u4E00\u5316 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519",
1767
+ settingsCardDesc: "\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / \u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u9759\u97F3\u505C\u987F / \u7A7A\u95F2\u8D85\u65F6 / \u6A21\u578B\u955C\u50CF / \u81EA\u52A8\u53D1\u9001 / \u6717\u8BFB\u56DE\u590D / \u72B6\u6001\u6761 / \u5B57\u5E55\u6D6E\u5C42 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u9006\u6587\u672C\u5F52\u4E00\u5316 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519",
1710
1768
  settingsEffectiveNote: "\u751F\u6548\u65F6\u673A\u5206\u56DB\u6863\uFF1A\u2460 \u5373\u65F6\u2014\u2014\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / Kokoro \u6A21\u578B\u7CBE\u5EA6\uFF08\u5DF2\u7F13\u5B58\u5219\u5373\u65F6\uFF0C\u5426\u5219\u4E0B\u6B21\u4E0B\u8F7D\uFF09/ \u53E3\u8BED\u5316\u63D0\u793A\u8BCD\uFF08\u5BF9\u540E\u7EED\u56DE\u590D\u751F\u6548\uFF09/ \u6717\u8BFB\u56DE\u590D / \u72B6\u6001\u6761 / \u5B57\u5E55\u6D6E\u5C42 / \u6A21\u578B\u955C\u50CF\uFF08\u4E0B\u6B21\u4E0B\u8F7D\u5C1D\u8BD5\u5373\u751F\u6548\uFF09\uFF1B\u2461 \u4E0B\u6B21\u8BC6\u522B\u65F6\u2014\u2014\u5B9A\u7A3F\u91CD\u8BD1\uFF08SenseVoice\uFF09/ \u9006\u6587\u672C\u5F52\u4E00\u5316\uFF1B\u2462 \u4E0B\u4E00\u6BB5\u8BDD\u2014\u2014\u9759\u97F3\u5224\u5B9A\u65F6\u957F\uFF08\u65AD\u53E5\u7AEF\u70B9\uFF1B\u53D1\u9001\u7B49\u5F85\u56FA\u5B9A 1.2 \u79D2\u4E0D\u53D7\u5F71\u54CD\uFF09\uFF1B\u2463 \u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u2014\u2014\u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u5FEB\u6377\u952E / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519 / \u7A7A\u95F2\u65F6\u957F\u3002\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u624D\u751F\u6548\u7684\u9879\u4F1A\u5217\u5728\u5361\u7247\u9876\u90E8\uFF08\u542B\u5F53\u524D\u751F\u6548\u503C\uFF09\u3002",
1711
1769
  effectivePending: "\u6709 {count} \u9879\u4FEE\u6539\u5C06\u5728\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u65F6\u751F\u6548\uFF1A{items}",
1712
1770
  valueOn: "\u5F00",
@@ -1790,7 +1848,7 @@ var zh = {
1790
1848
  bargeInModeLabel: "\u6253\u65AD\u65B9\u5F0F",
1791
1849
  echoGateDbLabel: "\u56DE\u58F0\u95E8\u63A7",
1792
1850
  modeLabel: "\u4EA4\u4E92\u6A21\u5F0F",
1793
- shortcutLabel: "\u5FEB\u6377\u952E",
1851
+ shortcutLabel: "\u8FDB\u5165 / \u9000\u51FA\u8BED\u97F3\u6A21\u5F0F\uFF08\u5E94\u7528\u5185\uFF09",
1794
1852
  wakeWordLabel: "\u5524\u9192\u8BCD",
1795
1853
  toolBeepLabel: "\u5DE5\u5177\u63D0\u793A\u97F3",
1796
1854
  autoSendLabel: "\u81EA\u52A8\u53D1\u9001",
@@ -1826,6 +1884,7 @@ var zh = {
1826
1884
  errUnknownSession: "\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u5F00\u542F\u8BED\u97F3\u6A21\u5F0F",
1827
1885
  errForbidden: "\u8BF7\u6C42\u88AB\u62D2\u7EDD\uFF08\u4EC5\u9650\u672C\u673A\u8BBF\u95EE\uFF0C\u6216\u6765\u6E90\u4E0D\u7B26\uFF09",
1828
1886
  errBadRequest: "\u8BF7\u6C42\u65E0\u6548",
1887
+ errMethodNotAllowed: "\u8BF7\u6C42\u65B9\u6CD5\u4E0D\u88AB\u652F\u6301",
1829
1888
  errEngineNotActive: "\u8BE5\u6717\u8BFB\u5F15\u64CE\u5F53\u524D\u672A\u542F\u7528",
1830
1889
  errModelDownload: "\u6A21\u578B\u4E0B\u8F7D\u5931\u8D25\uFF1A\u8BF7\u68C0\u67E5\u7F51\u7EDC",
1831
1890
  errTooManyStreams: "\u8BED\u97F3\u8FDE\u63A5\u8FC7\u591A\uFF0C\u8BF7\u5173\u95ED\u5176\u5B83\u8BED\u97F3\u9875\u9762\u540E\u91CD\u8BD5",
@@ -1885,7 +1944,7 @@ var en = {
1885
1944
  startFail: "Voice mode failed to start: {err}",
1886
1945
  holdDots: "Hold to talk\u2026",
1887
1946
  exit: "Exit",
1888
- configUnavailableNote: " (settings document not ready; the panel will appear when it is).",
1947
+ configUnavailableNote: " (settings document not ready; retrying \u2014 the panel will appear when it is).",
1889
1948
  previewNameFirst: "Enter a voice ShortName first",
1890
1949
  previewDisabled: "Voice mode disabled (plugin enabled=false); preview unavailable",
1891
1950
  // 批 G 任务 6:本地 TTS 引擎未下载模型时禁用试听按钮 + 提示。
@@ -1925,6 +1984,17 @@ var en = {
1925
1984
  // R1 收尾(fix-client 直连 tk() 调用):连续 3 次回声拒断的解释出口 + 快捷键非法停用提示。
1926
1985
  echoRejectHint: "Strong echo detected \u2014 barge-in is limited by echo protection. Use headphones or switch to manual barge-in",
1927
1986
  shortcutInvalid: "Invalid shortcut, disabled. Fix it in settings (e.g. Ctrl+Shift+V); leave empty to use the mic button only",
1987
+ descComposerShortcut: "Shortcut to toggle voice mode while the composer has focus (default Alt/Option+Enter)",
1988
+ composerShortcutLabel: "Enter / exit voice mode (in composer)",
1989
+ shortcutRecord: "Record",
1990
+ shortcutRecording: "Press a key combo\u2026",
1991
+ shortcutCancel: "Cancel",
1992
+ shortcutNeedModifier: "At least one modifier is required",
1993
+ shortcutUnsupportedKey: "Only letters, digits, Enter, Space and Tab are supported",
1994
+ shortcutPlaceholder: "Click Record, then press a combo",
1995
+ shortcutReset: "Reset to default",
1996
+ shortcutNote: "Alt/Option+Enter toggles inside the composer; Cmd / Ctrl / Alt / Shift combos are supported; leaving it empty means mic button only. While recording, Backspace clears and Esc cancels; avoid browser-reserved combos (Cmd+W / T / N / L). Changes apply immediately.",
1997
+ secShortcut: "Shortcut",
1928
1998
  elapsedHint: "Current voice session duration",
1929
1999
  botLevelsHint: "AI playback level (blue bar = TTS playback, green bar = microphone)",
1930
2000
  interruptConfirm: "interrupt confirm",
@@ -1977,7 +2047,7 @@ var en = {
1977
2047
  descShowStatusBar: "Show the voice status bar above the composer (waveform, transcript, timer, notices, exit); when off, state shows only on the mic button",
1978
2048
  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',
1979
2049
  wakePlaceholder: "e.g. Hey D",
1980
- 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",
2050
+ settingsCardDesc: "Engine / voice / rate / interrupt / barge-in / echo gate / silence / idle / model host / auto-send / read replies / status bar / caption overlay / auto-resume / mode / wake word / tool beep / ITN / caption font / caption width / yielding / yield window / barge-in salvage / LLM correction",
1981
2051
  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.",
1982
2052
  effectivePending: "{count} change(s) will apply next time you enter voice mode: {items}",
1983
2053
  valueOn: "On",
@@ -2055,7 +2125,7 @@ var en = {
2055
2125
  bargeInModeLabel: "Interrupt mode",
2056
2126
  echoGateDbLabel: "Echo gate",
2057
2127
  modeLabel: "Interaction mode",
2058
- shortcutLabel: "Shortcut",
2128
+ shortcutLabel: "Enter / exit voice mode (app-wide)",
2059
2129
  wakeWordLabel: "Wake word",
2060
2130
  toolBeepLabel: "Tool-call beep",
2061
2131
  autoSendLabel: "Auto-send",
@@ -2091,6 +2161,7 @@ var en = {
2091
2161
  errUnknownSession: "Voice session expired \u2014 re-enter voice mode",
2092
2162
  errForbidden: "Request denied (local access only, or origin mismatch)",
2093
2163
  errBadRequest: "Invalid request",
2164
+ errMethodNotAllowed: "Request method not allowed",
2094
2165
  errEngineNotActive: "That read-aloud engine is not active",
2095
2166
  errModelDownload: "Model download failed \u2014 check your network",
2096
2167
  errTooManyStreams: "Too many voice connections \u2014 close other voice tabs and retry",
@@ -2228,6 +2299,160 @@ function takeToggleSlot(history, now) {
2228
2299
  function onceFinished(o, running, ttsDrained, playing) {
2229
2300
  return o.sawRun && !running && ttsDrained && !playing;
2230
2301
  }
2302
+ function isPrimaryPress(button, opts) {
2303
+ if (button !== 0) return false;
2304
+ if (opts.mac && opts.ctrlKey) return false;
2305
+ return true;
2306
+ }
2307
+ function eqPaintMode(reducedMotion) {
2308
+ return reducedMotion ? "static-full" : "animated";
2309
+ }
2310
+ function menuFocusIndex(i, len, dir) {
2311
+ if (len <= 0) return -1;
2312
+ if (i < 0) return dir === 1 ? 0 : len - 1;
2313
+ return (i + dir + len) % len;
2314
+ }
2315
+ function handleReplaced(o) {
2316
+ if (o.staleBus) {
2317
+ o.retire();
2318
+ return;
2319
+ }
2320
+ o.reconnect(o.renewTabId());
2321
+ }
2322
+ function decayConfirmCount(count, abandon) {
2323
+ const next = Math.max(0, count - 1);
2324
+ if (next === 0) abandon();
2325
+ return next;
2326
+ }
2327
+ function shouldReleaseStopLine(o) {
2328
+ if (!o.hasStopLine) return false;
2329
+ if (o.untilNextRun) return false;
2330
+ if (o.turn !== void 0 && o.lastTurn !== void 0) return o.turn !== o.lastTurn;
2331
+ if (o.sameRoundContinuation) return false;
2332
+ return true;
2333
+ }
2334
+ function applyTurnEvent(o) {
2335
+ const release = shouldReleaseStopLine({
2336
+ hasStopLine: o.hasStopLine,
2337
+ untilNextRun: o.untilNextRun,
2338
+ turn: o.turn,
2339
+ lastTurn: o.identity.lastTurn,
2340
+ sameRoundContinuation: o.sameRoundContinuation
2341
+ });
2342
+ return {
2343
+ identity: o.turn !== void 0 ? { lastTurn: o.turn } : o.identity,
2344
+ release
2345
+ };
2346
+ }
2347
+ function cancelPayload(o) {
2348
+ return JSON.stringify({ sessionId: o.sessionId, keepAsr: o.keepAsr, reason: o.reason });
2349
+ }
2350
+ function auxClickPending(button, opts) {
2351
+ return button === 0 && opts.mac && opts.ctrlKey;
2352
+ }
2353
+ function isAuxClickToIgnore(pending, clickDetail) {
2354
+ return pending && clickDetail !== 0;
2355
+ }
2356
+ function isGestureEnd(armed, up) {
2357
+ if (!armed) return false;
2358
+ return armed.id === up.id && armed.button === up.button;
2359
+ }
2360
+ function pointerUpAction(armed, up) {
2361
+ if (!armed) return "unarmed";
2362
+ if (!isGestureEnd(armed, up)) return "ignore";
2363
+ return "finish";
2364
+ }
2365
+ function focusFailureAction(status, attempt) {
2366
+ if (status !== 403) return "silent";
2367
+ return attempt === 1 ? "retry-later" : "report-once";
2368
+ }
2369
+ async function reportFocus(o) {
2370
+ const wait = o.wait ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
2371
+ const warn = o.warn ?? (() => {
2372
+ });
2373
+ const retryMs = o.retryMs ?? 800;
2374
+ let attempts = 0;
2375
+ for (let attempt = 1; attempt <= 2; attempt++) {
2376
+ attempts++;
2377
+ let status;
2378
+ try {
2379
+ status = (await o.fetchImpl()).status;
2380
+ } catch {
2381
+ return { ok: false, reported: false, attempts, skipped: false };
2382
+ }
2383
+ const action = focusFailureAction(status, attempt);
2384
+ if (action === "silent") return { ok: status >= 200 && status < 300, reported: false, attempts, skipped: false };
2385
+ if (action === "retry-later") {
2386
+ if (o.sessionId === null) return { ok: false, reported: false, attempts, skipped: false };
2387
+ await wait(retryMs);
2388
+ if (o.stillRelevant && !o.stillRelevant()) {
2389
+ return { ok: false, reported: false, attempts, skipped: true };
2390
+ }
2391
+ continue;
2392
+ }
2393
+ warn({ sessionId: o.sessionId, status });
2394
+ return { ok: false, reported: true, attempts, skipped: false };
2395
+ }
2396
+ return { ok: false, reported: false, attempts, skipped: false };
2397
+ }
2398
+ var FOCUS_OWNER_DEFAULT = "default";
2399
+ function focusSession(owners) {
2400
+ let last = null;
2401
+ for (const sessionId of owners.values()) last = sessionId;
2402
+ return last;
2403
+ }
2404
+ function focusClaim(owners, owner, sessionId) {
2405
+ owners.delete(owner);
2406
+ owners.set(owner, sessionId);
2407
+ }
2408
+ function focusRelease(owners, owner) {
2409
+ const before = focusSession(owners);
2410
+ owners.delete(owner);
2411
+ const focused = focusSession(owners);
2412
+ return { changed: before !== focused, focused };
2413
+ }
2414
+ function registerScopeDispose(host, raw) {
2415
+ host.effect(() => raw.dispose);
2416
+ }
2417
+ function createScopeBridge(raw) {
2418
+ const listeners = [];
2419
+ let off = null;
2420
+ function resubscribe() {
2421
+ off?.();
2422
+ off = raw.subscribe(forward);
2423
+ }
2424
+ function forward() {
2425
+ for (const entry of [...listeners]) entry.fn();
2426
+ }
2427
+ const scope = {
2428
+ getSnapshot: () => raw.getSnapshot(),
2429
+ subscribe(fn) {
2430
+ const entry = { fn };
2431
+ listeners.push(entry);
2432
+ if (listeners.length === 1) off = raw.subscribe(forward);
2433
+ return () => {
2434
+ const i = listeners.indexOf(entry);
2435
+ if (i >= 0) listeners.splice(i, 1);
2436
+ if (listeners.length === 0 && off !== null) {
2437
+ off();
2438
+ off = null;
2439
+ }
2440
+ };
2441
+ },
2442
+ set: (field, value) => raw.set(field, value)
2443
+ };
2444
+ return {
2445
+ scope,
2446
+ invalidate() {
2447
+ if (typeof raw.invalidate === "function") {
2448
+ raw.invalidate();
2449
+ return;
2450
+ }
2451
+ if (listeners.length === 0) return;
2452
+ resubscribe();
2453
+ }
2454
+ };
2455
+ }
2231
2456
 
2232
2457
  // src/runtime-boot.ts
2233
2458
  var runtimeBoot = null;
@@ -2635,6 +2860,114 @@ function TextField({
2635
2860
  }
2636
2861
  );
2637
2862
  }
2863
+ function ShortcutField({
2864
+ score,
2865
+ field,
2866
+ value
2867
+ }) {
2868
+ const [draft, setDraft] = (0, import_react2.useState)(String(value ?? ""));
2869
+ const [recording, setRecording] = (0, import_react2.useState)(false);
2870
+ const [err, setErr] = (0, import_react2.useState)("");
2871
+ (0, import_react2.useEffect)(() => {
2872
+ setDraft((d) => d === String(value ?? "") ? d : String(value ?? ""));
2873
+ }, [value]);
2874
+ const notify = () => {
2875
+ try {
2876
+ window.dispatchEvent(new Event("dshvm-settings-changed"));
2877
+ } catch {
2878
+ }
2879
+ };
2880
+ const commit = () => {
2881
+ void score.set(field, draft.trim());
2882
+ notify();
2883
+ };
2884
+ (0, import_react2.useEffect)(() => {
2885
+ if (!recording) return;
2886
+ const onKey = (e) => {
2887
+ e.preventDefault();
2888
+ e.stopPropagation();
2889
+ if (e.key === "Escape") {
2890
+ setRecording(false);
2891
+ setErr("");
2892
+ return;
2893
+ }
2894
+ if (e.key === "Backspace" || e.key === "Delete") {
2895
+ setDraft("");
2896
+ void score.set(field, "");
2897
+ notify();
2898
+ setRecording(false);
2899
+ return;
2900
+ }
2901
+ if (e.key === "Control" || e.key === "Alt" || e.key === "Shift" || e.key === "Meta") return;
2902
+ const mods = [];
2903
+ if (e.metaKey) mods.push("Cmd");
2904
+ else if (e.ctrlKey) mods.push("Ctrl");
2905
+ if (e.altKey) mods.push("Alt");
2906
+ if (e.shiftKey) mods.push("Shift");
2907
+ if (mods.length === 0) {
2908
+ setErr(t("shortcutNeedModifier"));
2909
+ return;
2910
+ }
2911
+ const named = e.key === "Enter" ? "Enter" : e.key === " " ? "Space" : e.key === "Tab" ? "Tab" : "";
2912
+ const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "");
2913
+ const k = named || (/^[A-Za-z0-9]$/.test(codeKey) ? codeKey.toUpperCase() : /^[A-Za-z0-9]$/.test(e.key) ? e.key.toUpperCase() : "");
2914
+ if (!k) {
2915
+ setErr(t("shortcutUnsupportedKey"));
2916
+ return;
2917
+ }
2918
+ const combo = [...mods, k].join("+");
2919
+ setDraft(combo);
2920
+ void score.set(field, combo);
2921
+ notify();
2922
+ setRecording(false);
2923
+ setErr("");
2924
+ };
2925
+ window.addEventListener("keydown", onKey, true);
2926
+ return () => window.removeEventListener("keydown", onKey, true);
2927
+ }, [recording, score, field]);
2928
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", flexDirection: "column", alignItems: "flex-end", gap: 3 }, children: [
2929
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 6 }, children: [
2930
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2931
+ "input",
2932
+ {
2933
+ style: { ...inputStyle, width: 150 },
2934
+ value: draft,
2935
+ placeholder: t("shortcutPlaceholder"),
2936
+ onChange: (e) => {
2937
+ setDraft(e.target.value);
2938
+ if (err) setErr("");
2939
+ },
2940
+ onBlur: commit,
2941
+ onKeyDown: (e) => {
2942
+ if (e.key === "Enter") commit();
2943
+ }
2944
+ }
2945
+ ),
2946
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2947
+ "button",
2948
+ {
2949
+ type: "button",
2950
+ onClick: () => {
2951
+ setRecording((r) => !r);
2952
+ setErr("");
2953
+ },
2954
+ style: {
2955
+ height: 28,
2956
+ padding: "0 10px",
2957
+ borderRadius: 6,
2958
+ border: "1px solid var(--dsw-alias-border-l3)",
2959
+ background: "transparent",
2960
+ color: "var(--dsw-alias-label-secondary)",
2961
+ fontSize: 12,
2962
+ cursor: "pointer"
2963
+ },
2964
+ children: recording ? t("shortcutCancel") : t("shortcutRecord")
2965
+ }
2966
+ )
2967
+ ] }),
2968
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, lineHeight: "14px", color: err ? "var(--dsw-alias-state-error-primary)" : "var(--dsw-alias-label-tertiary)" }, children: recording ? t("shortcutRecording") : err })
2969
+ ] });
2970
+ }
2638
2971
  function SelectField({
2639
2972
  score,
2640
2973
  field,
@@ -3313,7 +3646,6 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
3313
3646
  ]
3314
3647
  }
3315
3648
  ) }),
3316
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "shortcut", desc: t("descShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextField, { score: scope, field: "shortcut", value: value.shortcut ?? "Ctrl+Shift+V", placeholder: "Ctrl+Shift+V" }) }),
3317
3649
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "wakeWord", desc: t("descWakeWord"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextField, { score: scope, field: "wakeWord", value: value.wakeWord ?? "", placeholder: t("wakePlaceholder") }) }),
3318
3650
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "toolBeep", desc: t("descToolBeep"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.toolBeep), onChange: (e) => void scope.set("toolBeep", e.target.checked) }) }),
3319
3651
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "autoSend", desc: t("descAutoSend"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.autoSend), onChange: (e) => void scope.set("autoSend", e.target.checked) }) }),
@@ -3365,6 +3697,39 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
3365
3697
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "llmCorrect", desc: t("descLlmCorrect"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.llmCorrect === true, onChange: (e) => void scope.set("llmCorrect", e.target.checked) }) }),
3366
3698
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "yieldMs", desc: t("descYieldMs"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NumberField, { score: scope, field: "yieldMs", value: value.yieldMs ?? 1500, min: 500, max: 3e3, step: 100 }) })
3367
3699
  ] }),
3700
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secShortcut"), children: [
3701
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "shortcut", desc: t("descShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShortcutField, { score: scope, field: "shortcut", value: value.shortcut ?? "" }) }),
3702
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "composerShortcut", desc: t("descComposerShortcut"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShortcutField, { score: scope, field: "composerShortcut", value: value.composerShortcut ?? "Alt+Enter" }) }),
3703
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: 10, padding: "2px 0 6px" }, children: [
3704
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { flex: 1, fontSize: 11, lineHeight: "17px", color: "var(--dsw-alias-label-tertiary)" }, children: t("shortcutNote") }),
3705
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3706
+ "button",
3707
+ {
3708
+ type: "button",
3709
+ onClick: () => {
3710
+ void scope.set("shortcut", "Ctrl+Shift+V");
3711
+ void scope.set("composerShortcut", "Alt+Enter");
3712
+ try {
3713
+ window.dispatchEvent(new Event("dshvm-settings-changed"));
3714
+ } catch {
3715
+ }
3716
+ },
3717
+ style: {
3718
+ flexShrink: 0,
3719
+ height: 26,
3720
+ padding: "0 10px",
3721
+ borderRadius: 6,
3722
+ border: "1px solid var(--dsw-alias-border-l3)",
3723
+ background: "transparent",
3724
+ color: "var(--dsw-alias-label-secondary)",
3725
+ fontSize: 12,
3726
+ cursor: "pointer"
3727
+ },
3728
+ children: t("shortcutReset")
3729
+ }
3730
+ )
3731
+ ] })
3732
+ ] }),
3368
3733
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Section, { title: t("secRecognition"), children: [
3369
3734
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "senseVoice", desc: t("descSenseVoice"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.senseVoice), onChange: (e) => void scope.set("senseVoice", e.target.checked) }) }),
3370
3735
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "senseITN", desc: t("descSenseITN"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.senseITN !== false, onChange: (e) => void scope.set("senseITN", e.target.checked) }) }),
@@ -3382,39 +3747,94 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
3382
3747
 
3383
3748
  // src/settings-http-scope.ts
3384
3749
  var SETTINGS_URL = "/voice-mode/settings";
3750
+ var RETRY_BASE_MS = 500;
3751
+ var RETRY_MAX_MS = 1e4;
3385
3752
  function createHttpScope(origin = location.origin, fetchImpl = fetch) {
3386
3753
  let snap = { status: "loading", value: {} };
3387
3754
  const subs = /* @__PURE__ */ new Set();
3388
- let started = false;
3755
+ let inFlight = false;
3756
+ let writing = 0;
3757
+ let writeGen = 0;
3758
+ let pendingReload = false;
3759
+ let disposed = false;
3760
+ let retryTimer = null;
3761
+ let retryDelay = 0;
3389
3762
  const emit = (next) => {
3390
3763
  snap = next;
3391
- for (const fn of [...subs]) fn();
3764
+ for (const fn of [...subs]) {
3765
+ try {
3766
+ fn();
3767
+ } catch (e) {
3768
+ console.warn("[dsh-voice-mode] settings scope subscriber failed: " + String(e));
3769
+ }
3770
+ }
3771
+ };
3772
+ const clearRetry = () => {
3773
+ if (retryTimer !== null) {
3774
+ clearTimeout(retryTimer);
3775
+ retryTimer = null;
3776
+ }
3392
3777
  };
3393
3778
  const load = async () => {
3779
+ if (disposed) return;
3780
+ if (inFlight) {
3781
+ pendingReload = true;
3782
+ return;
3783
+ }
3784
+ inFlight = true;
3785
+ clearRetry();
3786
+ const myGen = writeGen;
3394
3787
  try {
3395
3788
  const res = await fetchImpl(origin + SETTINGS_URL);
3396
3789
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
3397
3790
  const data = await res.json();
3398
- emit({ status: "ready", value: data.value ?? {} });
3791
+ retryDelay = 0;
3792
+ if (writing === 0 && myGen === writeGen) emit({ status: "ready", value: data.value ?? {} });
3399
3793
  } catch {
3400
3794
  emit({ status: "unavailable", value: snap.value });
3795
+ scheduleRetry();
3796
+ } finally {
3797
+ inFlight = false;
3798
+ if (pendingReload) {
3799
+ pendingReload = false;
3800
+ if (!disposed && subs.size > 0) void load();
3801
+ }
3401
3802
  }
3402
3803
  };
3403
- return {
3804
+ const scheduleRetry = () => {
3805
+ if (disposed || subs.size === 0 || retryTimer !== null) return;
3806
+ retryDelay = retryDelay === 0 ? RETRY_BASE_MS : Math.min(retryDelay * 2, RETRY_MAX_MS);
3807
+ retryTimer = setTimeout(() => {
3808
+ retryTimer = null;
3809
+ void load();
3810
+ }, retryDelay);
3811
+ };
3812
+ const onFocus = () => {
3813
+ if (subs.size > 0) void load();
3814
+ };
3815
+ if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
3816
+ window.addEventListener("focus", onFocus);
3817
+ }
3818
+ const scope = {
3404
3819
  getSnapshot: () => snap,
3405
3820
  subscribe(fn) {
3821
+ const first = subs.size === 0;
3406
3822
  subs.add(fn);
3407
- if (!started) {
3408
- started = true;
3823
+ if (first) {
3824
+ retryDelay = 0;
3409
3825
  void load();
3410
3826
  }
3411
3827
  return () => {
3412
3828
  subs.delete(fn);
3829
+ if (subs.size === 0) clearRetry();
3413
3830
  };
3414
3831
  },
3415
3832
  async set(field, value) {
3833
+ if (disposed) return;
3416
3834
  const before = snap;
3835
+ writing++;
3417
3836
  emit({ status: "ready", value: { ...snap.value, [field]: value } });
3837
+ let ok = false;
3418
3838
  try {
3419
3839
  const res = await fetchImpl(origin + SETTINGS_URL, {
3420
3840
  method: "POST",
@@ -3424,12 +3844,25 @@ function createHttpScope(origin = location.origin, fetchImpl = fetch) {
3424
3844
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
3425
3845
  const data = await res.json();
3426
3846
  emit({ status: "ready", value: data.value ?? before.value });
3847
+ ok = true;
3427
3848
  } catch {
3428
3849
  emit(before);
3429
- await load();
3850
+ } finally {
3851
+ writing--;
3852
+ writeGen++;
3853
+ }
3854
+ if (!ok) await load();
3855
+ },
3856
+ dispose: () => {
3857
+ disposed = true;
3858
+ pendingReload = false;
3859
+ if (typeof window !== "undefined" && typeof window.removeEventListener === "function") {
3860
+ window.removeEventListener("focus", onFocus);
3430
3861
  }
3862
+ clearRetry();
3431
3863
  }
3432
3864
  };
3865
+ return scope;
3433
3866
  }
3434
3867
 
3435
3868
  // src/client.tsx
@@ -3463,7 +3896,7 @@ function telemetryDeltas(tel) {
3463
3896
  }
3464
3897
  return out;
3465
3898
  }
3466
- var BUILD_TAG = "8c0368a";
3899
+ var BUILD_TAG = "dc828c8";
3467
3900
  var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
3468
3901
  var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
3469
3902
  console.log("[dsh-voice] build=" + BUILD_TAG);
@@ -3524,6 +3957,8 @@ function getTabId(fresh = false) {
3524
3957
  }
3525
3958
  var TAB_ID = getTabId();
3526
3959
  var BUS_GEN_KEY = "__dshvmBusGen";
3960
+ var focusOwnerSeq = 0;
3961
+ var settingsScopeInvalidate = null;
3527
3962
  function parseShortcut(s) {
3528
3963
  const parts = (s || "").split("+");
3529
3964
  const mods = { ctrl: false, shift: false, alt: false, meta: false };
@@ -3537,6 +3972,9 @@ function parseShortcut(s) {
3537
3972
  else if (t3.length === 1 && /^[a-z0-9]$/.test(t3)) {
3538
3973
  if (key) return null;
3539
3974
  key = t3;
3975
+ } else if (t3 === "enter" || t3 === "space" || t3 === "tab") {
3976
+ if (key) return null;
3977
+ key = t3;
3540
3978
  } else return null;
3541
3979
  }
3542
3980
  if (!key) return null;
@@ -3651,7 +4089,17 @@ function apply(ctx) {
3651
4089
  )
3652
4090
  );
3653
4091
  const settingsScope = ctx.get?.("settingsScope");
3654
- const scope = settingsScope ? settingsScope.bind({ namespace: "voice-mode" }) : createHttpScope();
4092
+ let scope;
4093
+ if (settingsScope) {
4094
+ scope = settingsScope.bind({ namespace: "voice-mode" });
4095
+ settingsScopeInvalidate = null;
4096
+ } else {
4097
+ const raw = createHttpScope();
4098
+ const bridge = createScopeBridge(raw);
4099
+ scope = bridge.scope;
4100
+ settingsScopeInvalidate = bridge.invalidate;
4101
+ registerScopeDispose(ctx, raw);
4102
+ }
3655
4103
  ctx.slots.inject(
3656
4104
  "settings.plugin.item",
3657
4105
  () => ctx.slots.register(
@@ -3858,17 +4306,38 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
3858
4306
  function createVoiceBus(basePath = BASE_PATH2, ctx) {
3859
4307
  let activeSessionId = null;
3860
4308
  let focusedSessionId = null;
4309
+ const focusOwners = /* @__PURE__ */ new Map();
3861
4310
  let focusOwnerTab = null;
3862
4311
  let voiceActive = null;
3863
4312
  let voiceOwnerTab = null;
3864
4313
  const busGen = globalThis[BUS_GEN_KEY] = (globalThis[BUS_GEN_KEY] ?? 0) + 1;
4314
+ const focusWarned = /* @__PURE__ */ new Set();
3865
4315
  const postFocus = (sessionId) => {
3866
- void fetch(`${location.origin}${basePath}/focus`, {
3867
- method: "POST",
3868
- headers: { "content-type": "application/json" },
3869
- body: JSON.stringify({ sessionId, tabId: TAB_ID }),
3870
- signal: AbortSignal.timeout(3e3)
3871
- }).catch(() => {
4316
+ void reportFocus({
4317
+ sessionId,
4318
+ fetchImpl: () => fetch(`${location.origin}${basePath}/focus`, {
4319
+ method: "POST",
4320
+ headers: { "content-type": "application/json" },
4321
+ body: JSON.stringify({ sessionId, tabId: TAB_ID }),
4322
+ signal: AbortSignal.timeout(3e3)
4323
+ }).then((r) => ({ status: r.status })),
4324
+ // 补报前复核焦点是否已变:403 → 等 800ms 期间用户切到别的会话 → 补报会把**旧**
4325
+ // 会话重新 POST → host 的焦点归属指回旧会话(当前会话不朗读、旧会话被朗读)。
4326
+ stillRelevant: () => focusedSessionId === sessionId,
4327
+ // 留痕文案放在 client.tsx(mic-gesture.ts 不在 strings-coverage 白名单里)。
4328
+ // 日志文案用英文:本仓红线禁止 console.* 里出现中文字面量(见 strings-coverage)。
4329
+ // 含义:/focus 被 host 拒绝(host 不认识这个会话 = 会话表滞后)→ 焦点静默失败,
4330
+ // readAloud=always 可能整页不朗读而用户看不到原因。
4331
+ // 每会话只留一次痕:反复切标签页/可见性变化会反复触发 postFocus。
4332
+ warn: ({ sessionId: warnedSession, status }) => {
4333
+ if (warnedSession !== null) {
4334
+ if (focusWarned.has(warnedSession)) return;
4335
+ focusWarned.add(warnedSession);
4336
+ }
4337
+ console.warn(
4338
+ "[dsh-voice-mode] /focus rejected by host (" + status + " unknown_session): session " + String(warnedSession) + " is not in the host session table -> focus silently failed, readAloud=always may not play at all"
4339
+ );
4340
+ }
3872
4341
  });
3873
4342
  };
3874
4343
  const DEFAULT_BOOT = {
@@ -3886,6 +4355,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
3886
4355
  bargeInMode: "detect",
3887
4356
  echoGateDb: 6,
3888
4357
  shortcut: "Ctrl+Shift+V",
4358
+ composerShortcut: "Alt+Enter",
3889
4359
  wakeWord: "",
3890
4360
  toolBeep: false,
3891
4361
  captionFontSize: 0,
@@ -4102,13 +4572,18 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4102
4572
  source.addEventListener("replaced", () => {
4103
4573
  source?.close();
4104
4574
  source = null;
4105
- if (globalThis[BUS_GEN_KEY] !== busGen) {
4106
- ui.sseDown = true;
4107
- notify();
4108
- return;
4109
- }
4110
- TAB_ID = getTabId(true);
4111
- connect();
4575
+ handleReplaced({
4576
+ staleBus: globalThis[BUS_GEN_KEY] !== busGen,
4577
+ renewTabId: () => {
4578
+ TAB_ID = getTabId(true);
4579
+ return TAB_ID;
4580
+ },
4581
+ reconnect: () => connect(),
4582
+ retire: () => {
4583
+ ui.sseDown = true;
4584
+ notify();
4585
+ }
4586
+ });
4112
4587
  });
4113
4588
  source.addEventListener("display", (e) => {
4114
4589
  try {
@@ -4116,6 +4591,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4116
4591
  notify();
4117
4592
  } catch {
4118
4593
  }
4594
+ settingsScopeInvalidate?.();
4119
4595
  });
4120
4596
  source.addEventListener("focus", (e) => {
4121
4597
  try {
@@ -4164,8 +4640,19 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4164
4640
  source.addEventListener("turn", (e) => {
4165
4641
  try {
4166
4642
  const ev = JSON.parse(e.data);
4167
- if (ev.state === "agent-speaking" && ev.sessionId && rejectSeqUpTo.get(ev.sessionId) === STOP_READING_LINE && !stopUntilRun.has(ev.sessionId)) {
4168
- rejectSeqUpTo.delete(ev.sessionId);
4643
+ if (ev.state === "agent-speaking" && ev.sessionId) {
4644
+ const sameRoundContinuation = toolPending.has(ev.sessionId);
4645
+ toolPending.delete(ev.sessionId);
4646
+ const turn = typeof ev.turn === "number" ? ev.turn : void 0;
4647
+ const r = applyTurnEvent({
4648
+ turn,
4649
+ identity: { lastTurn: currentTurn.get(ev.sessionId) },
4650
+ hasStopLine: rejectSeqUpTo.get(ev.sessionId) === STOP_READING_LINE,
4651
+ untilNextRun: stopUntilRun.has(ev.sessionId),
4652
+ sameRoundContinuation
4653
+ });
4654
+ if (r.identity.lastTurn !== void 0) currentTurn.set(ev.sessionId, r.identity.lastTurn);
4655
+ if (r.release) rejectSeqUpTo.delete(ev.sessionId);
4169
4656
  }
4170
4657
  if (ev.sessionId === activeSessionId && ev.state) {
4171
4658
  ui.turn = ev.state;
@@ -4258,6 +4745,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4258
4745
  source.addEventListener("tool", (e) => {
4259
4746
  try {
4260
4747
  const p = JSON.parse(e.data);
4748
+ if (p.sessionId) toolPending.add(p.sessionId);
4261
4749
  if (p.sessionId === activeSessionId && ui.boot.toolBeep === true) playToolBeep();
4262
4750
  } catch {
4263
4751
  }
@@ -4266,6 +4754,8 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4266
4754
  connect();
4267
4755
  const rejectSeqUpTo = /* @__PURE__ */ new Map();
4268
4756
  const stopUntilRun = /* @__PURE__ */ new Set();
4757
+ const toolPending = /* @__PURE__ */ new Set();
4758
+ const currentTurn = /* @__PURE__ */ new Map();
4269
4759
  const lastFinalSeq = /* @__PURE__ */ new Map();
4270
4760
  let curSentenceId = null;
4271
4761
  let curChunks = [];
@@ -4472,13 +4962,19 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4472
4962
  if (rejectSeqUpTo.get(sessionId) === STOP_READING_LINE) rejectSeqUpTo.delete(sessionId);
4473
4963
  stopUntilRun.delete(sessionId);
4474
4964
  },
4475
- setFocusedSession(sessionId) {
4965
+ setFocusedSession(sessionId, owner = FOCUS_OWNER_DEFAULT) {
4476
4966
  if (sessionId === null) {
4477
- if (focusedSessionId === null) return;
4478
- focusedSessionId = null;
4967
+ const { changed, focused } = focusRelease(focusOwners, owner);
4968
+ if (!changed) return;
4969
+ focusedSessionId = focused;
4970
+ if (focused !== null) {
4971
+ if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(focused);
4972
+ return;
4973
+ }
4479
4974
  if (focusOwnerTab === TAB_ID) postFocus(null);
4480
4975
  return;
4481
4976
  }
4977
+ focusClaim(focusOwners, owner, sessionId);
4482
4978
  focusedSessionId = sessionId;
4483
4979
  if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(sessionId);
4484
4980
  },
@@ -4492,7 +4988,9 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4492
4988
  void fetch(`${location.origin}${basePath}/cancel`, {
4493
4989
  method: "POST",
4494
4990
  headers: { "content-type": "application/json" },
4495
- body: JSON.stringify({ sessionId: sid, keepAsr: true }),
4991
+ // reason=stop-reading:host 据此**不**动回合闸门(否则「停止朗读」后的排空分支
4992
+ // 会补发 tts-idle → mode:once 提前退出,R15 Important-1 回归)。
4993
+ body: cancelPayload({ sessionId: sid, keepAsr: true, reason: "stop-reading" }),
4496
4994
  signal: AbortSignal.timeout(3e3)
4497
4995
  }).catch(() => {
4498
4996
  });
@@ -4594,7 +5092,8 @@ function MicMenu({ scope, anchor, onClose }) {
4594
5092
  e.preventDefault();
4595
5093
  const items = Array.from(menuRef.current?.querySelectorAll("button") ?? []);
4596
5094
  const i = items.indexOf(document.activeElement);
4597
- items[(i + (e.key === "ArrowDown" ? 1 : items.length - 1)) % items.length]?.focus();
5095
+ const next = menuFocusIndex(i, items.length, e.key === "ArrowDown" ? 1 : -1);
5096
+ if (next >= 0) items[next]?.focus();
4598
5097
  };
4599
5098
  document.addEventListener("pointerdown", onDown, true);
4600
5099
  document.addEventListener("keydown", onKey, true);
@@ -4664,6 +5163,9 @@ function MicButton({
4664
5163
  const manualHoldRef = (0, import_react3.useRef)(false);
4665
5164
  const breakRef = (0, import_react3.useRef)(null);
4666
5165
  const pausedForHiddenRef = (0, import_react3.useRef)(false);
5166
+ const focusOwnerRef = (0, import_react3.useRef)(null);
5167
+ if (focusOwnerRef.current === null) focusOwnerRef.current = `mic-${++focusOwnerSeq}`;
5168
+ const focusOwner = focusOwnerRef.current;
4667
5169
  const onceRef = (0, import_react3.useRef)(null);
4668
5170
  const [onceWaiting, setOnceWaiting] = (0, import_react3.useState)(false);
4669
5171
  const [onceEnding, setOnceEnding] = (0, import_react3.useState)(false);
@@ -4683,6 +5185,7 @@ function MicButton({
4683
5185
  bargeInMode: "detect",
4684
5186
  echoGateDb: 6,
4685
5187
  shortcut: "Ctrl+Shift+V",
5188
+ composerShortcut: "Alt+Enter",
4686
5189
  wakeWord: "",
4687
5190
  toolBeep: false,
4688
5191
  captionFontSize: 0,
@@ -4730,6 +5233,7 @@ function MicButton({
4730
5233
  bargeInMode: c.bargeInMode === "manual" ? "manual" : c.bargeInMode === "detect" ? "detect" : "auto",
4731
5234
  echoGateDb: typeof c.echoGateDb === "number" ? Math.min(12, Math.max(3, c.echoGateDb)) : cur.echoGateDb,
4732
5235
  shortcut: typeof c.shortcut === "string" ? c.shortcut : cur.shortcut,
5236
+ composerShortcut: typeof c.composerShortcut === "string" ? c.composerShortcut : cur.composerShortcut,
4733
5237
  wakeWord: typeof c.wakeWord === "string" ? c.wakeWord : cur.wakeWord,
4734
5238
  toolBeep: c.toolBeep === true,
4735
5239
  // 批 3:fetchConfig 是白名单拼接(plan §5.2 措辞「通用透传」与此处源码不符——见 commit message)
@@ -5018,6 +5522,9 @@ function MicButton({
5018
5522
  };
5019
5523
  const exitMode = async (reason) => {
5020
5524
  if (localRef.current === "off") return;
5525
+ pendingHoldRef.current = false;
5526
+ pendingHoldReleaseRef.current = false;
5527
+ clearHoldExit();
5021
5528
  setLocalMode("off");
5022
5529
  clearOnce();
5023
5530
  clearIdle();
@@ -5097,7 +5604,13 @@ function MicButton({
5097
5604
  method: "POST",
5098
5605
  headers: { "content-type": "application/json" },
5099
5606
  // hold 按压中保留 host ASR 段(松手定稿续传前半句,防吃句)。
5100
- body: JSON.stringify({ sessionId: sidRef.current, keepAsr: engineRef.current?.holding === true }),
5607
+ // reason=interrupt:host 据此可收口回合闸门(abandonTurn)——用户打断与
5608
+ // 「停止朗读」靠它区分(两者 keepAsr 都可能是 true,载荷本身区分不了)。
5609
+ body: cancelPayload({
5610
+ sessionId: sidRef.current,
5611
+ keepAsr: engineRef.current?.holding === true,
5612
+ reason: "interrupt"
5613
+ }),
5101
5614
  signal: AbortSignal.timeout(3e3)
5102
5615
  }).catch(() => {
5103
5616
  });
@@ -5189,7 +5702,10 @@ function MicButton({
5189
5702
  isSpeechFalseRun++;
5190
5703
  if (isSpeechFalseRun >= 2) {
5191
5704
  isSpeechFalseRun = 0;
5192
- isSpeechTrueCount = Math.max(0, isSpeechTrueCount - 1);
5705
+ isSpeechTrueCount = decayConfirmCount(
5706
+ isSpeechTrueCount,
5707
+ () => engineRef.current?.invalidateSalvageSeed()
5708
+ );
5193
5709
  if (isSpeechTrueCount === 0) interruptFirstAt = 0;
5194
5710
  }
5195
5711
  }
@@ -5305,6 +5821,16 @@ function MicButton({
5305
5821
  resetIdle();
5306
5822
  submitInFlightRef.current = false;
5307
5823
  bus.setUi({ partial: "" });
5824
+ if (holdReleaseExitRef.current && meta?.force) {
5825
+ clearHoldExit();
5826
+ if (bootNow().autoSend === false) {
5827
+ setTimeout(() => {
5828
+ if (!holdPtrRef.current) void exitModeRef.current("manual");
5829
+ }, 300);
5830
+ } else {
5831
+ beginOnceWait();
5832
+ }
5833
+ }
5308
5834
  const actions = actionsRef.current;
5309
5835
  const trimmed = text.trim();
5310
5836
  if (!trimmed) return;
@@ -5320,6 +5846,7 @@ function MicButton({
5320
5846
  }
5321
5847
  if (meta?.force) {
5322
5848
  cancelAutoSend();
5849
+ if (bootNow().mode === "hold" && bootNow().autoSend === false) return;
5323
5850
  submitDraftNow(nextDraft);
5324
5851
  return;
5325
5852
  }
@@ -5350,7 +5877,24 @@ function MicButton({
5350
5877
  micReadyRef.current = true;
5351
5878
  setLocalMode("on");
5352
5879
  resetIdle();
5880
+ if (pendingHoldRef.current) {
5881
+ pendingHoldRef.current = false;
5882
+ if (holdPtrRef.current) {
5883
+ setHolding(true);
5884
+ engineRef.current?.beginHeld();
5885
+ } else if (pendingHoldReleaseRef.current) {
5886
+ pendingHoldReleaseRef.current = false;
5887
+ engineRef.current?.endHeld(true);
5888
+ if (holdReleaseExitRef.current) {
5889
+ clearHoldExit();
5890
+ void exitModeRef.current("manual");
5891
+ }
5892
+ }
5893
+ }
5353
5894
  } catch (e) {
5895
+ pendingHoldRef.current = false;
5896
+ pendingHoldReleaseRef.current = false;
5897
+ clearHoldExit();
5354
5898
  setLocalMode("off");
5355
5899
  const msg = e instanceof DOMException ? e.name === "NotAllowedError" ? t("micDenied") : (
5356
5900
  // UX:NotReadableError = 麦克风被占用(其他程序/标签页)——与「不可用」
@@ -5382,6 +5926,32 @@ function MicButton({
5382
5926
  (0, import_react3.useEffect)(() => {
5383
5927
  sidRef.current = sessionId;
5384
5928
  }, [sessionId]);
5929
+ (0, import_react3.useEffect)(() => {
5930
+ const onChanged = () => {
5931
+ void fetchConfig();
5932
+ };
5933
+ window.addEventListener("dshvm-settings-changed", onChanged);
5934
+ return () => window.removeEventListener("dshvm-settings-changed", onChanged);
5935
+ }, []);
5936
+ (0, import_react3.useEffect)(() => {
5937
+ const onComposerKey = (e) => {
5938
+ const el = e.target;
5939
+ const editable = el instanceof HTMLElement && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable);
5940
+ if (!editable || e.isComposing) return;
5941
+ if (el.closest("[data-dshvm-settings]")) return;
5942
+ const combo = parseShortcut(bootNow().composerShortcut);
5943
+ if (!combo) return;
5944
+ const key = e.key.toLowerCase();
5945
+ const codeKey = (e.code || "").replace(/^Key/, "").replace(/^Digit/, "").toLowerCase();
5946
+ if (key !== combo.key && codeKey !== combo.key) return;
5947
+ if (e.ctrlKey !== combo.ctrl || e.shiftKey !== combo.shift || e.altKey !== combo.alt || e.metaKey !== combo.meta) return;
5948
+ e.preventDefault();
5949
+ e.stopPropagation();
5950
+ if (!e.repeat) toggleRef.current();
5951
+ };
5952
+ window.addEventListener("keydown", onComposerKey, true);
5953
+ return () => window.removeEventListener("keydown", onComposerKey, true);
5954
+ }, []);
5385
5955
  const autoResumeTriedForRef = (0, import_react3.useRef)(null);
5386
5956
  const autoResumeHintTimerRef = (0, import_react3.useRef)(null);
5387
5957
  (0, import_react3.useEffect)(() => {
@@ -5421,14 +5991,14 @@ function MicButton({
5421
5991
  (0, import_react3.useEffect)(() => bus.subscribe(() => checkOnce()), [bus]);
5422
5992
  (0, import_react3.useEffect)(() => {
5423
5993
  if (!sessionId) return;
5424
- bus.setFocusedSession(sessionId);
5994
+ bus.setFocusedSession(sessionId, focusOwner);
5425
5995
  const onVis = () => {
5426
- if (document.visibilityState === "visible") bus.setFocusedSession(sessionId);
5996
+ if (document.visibilityState === "visible") bus.setFocusedSession(sessionId, focusOwner);
5427
5997
  };
5428
5998
  document.addEventListener("visibilitychange", onVis);
5429
5999
  return () => {
5430
6000
  document.removeEventListener("visibilitychange", onVis);
5431
- bus.setFocusedSession(null);
6001
+ bus.setFocusedSession(null, focusOwner);
5432
6002
  };
5433
6003
  }, [bus, sessionId]);
5434
6004
  (0, import_react3.useEffect)(() => {
@@ -5631,8 +6201,30 @@ function MicButton({
5631
6201
  t("buttonListening")
5632
6202
  ) : local === "pending" ? t("entering") : t("voiceBtn");
5633
6203
  const holdPtrRef = (0, import_react3.useRef)(null);
6204
+ const auxClickRef = (0, import_react3.useRef)(false);
5634
6205
  const toggleHoldRef = (0, import_react3.useRef)(false);
5635
6206
  const suppressClickUntilRef = (0, import_react3.useRef)(0);
6207
+ const pendingHoldRef = (0, import_react3.useRef)(false);
6208
+ const pendingHoldReleaseRef = (0, import_react3.useRef)(false);
6209
+ const holdReleaseExitRef = (0, import_react3.useRef)(false);
6210
+ const pressFromOffRef = (0, import_react3.useRef)(false);
6211
+ const holdExitFallbackRef = (0, import_react3.useRef)(null);
6212
+ function clearHoldExit() {
6213
+ holdReleaseExitRef.current = false;
6214
+ if (holdExitFallbackRef.current) clearTimeout(holdExitFallbackRef.current);
6215
+ holdExitFallbackRef.current = null;
6216
+ }
6217
+ function armHoldExit() {
6218
+ clearHoldExit();
6219
+ holdReleaseExitRef.current = true;
6220
+ holdExitFallbackRef.current = setTimeout(() => {
6221
+ holdExitFallbackRef.current = null;
6222
+ if (holdReleaseExitRef.current && !holdPtrRef.current && !onceRef.current) {
6223
+ holdReleaseExitRef.current = false;
6224
+ void exitModeRef.current("manual");
6225
+ }
6226
+ }, 25e3);
6227
+ }
5636
6228
  const breakTimerRef = (0, import_react3.useRef)(null);
5637
6229
  const breakDotsTimerRef = (0, import_react3.useRef)(null);
5638
6230
  const clearBreakTimer = () => {
@@ -5687,10 +6279,24 @@ function MicButton({
5687
6279
  return () => el.removeEventListener("touchstart", onTouchStart);
5688
6280
  }, []);
5689
6281
  const onPointerDown = (e) => {
6282
+ auxClickRef.current = auxClickPending(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey });
6283
+ if (!isPrimaryPress(e.button, { mac: IS_MAC, ctrlKey: e.ctrlKey })) return;
5690
6284
  lockSelection();
5691
- holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId };
6285
+ holdPtrRef.current = { t: Date.now(), y: e.clientY, id: e.pointerId, button: e.button };
5692
6286
  e.currentTarget.setPointerCapture?.(e.pointerId);
5693
6287
  if (bootNow().mode === "hold") {
6288
+ pressFromOffRef.current = localRef.current === "off";
6289
+ clearHoldExit();
6290
+ if (localRef.current === "off" && !readingOutside()) {
6291
+ pendingHoldRef.current = true;
6292
+ pendingHoldReleaseRef.current = false;
6293
+ void enterMode().finally(() => {
6294
+ pendingHoldRef.current = false;
6295
+ pendingHoldReleaseRef.current = false;
6296
+ if (localRef.current !== "on") clearHoldExit();
6297
+ });
6298
+ return;
6299
+ }
5694
6300
  if (localRef.current === "on") {
5695
6301
  setHolding(true);
5696
6302
  const eng = engineRef.current;
@@ -5728,11 +6334,21 @@ function MicButton({
5728
6334
  };
5729
6335
  const onPointerUp = (e) => {
5730
6336
  const p = holdPtrRef.current;
6337
+ const action = pointerUpAction(p, { id: e.pointerId, button: e.button });
6338
+ if (action === "ignore") return;
5731
6339
  holdPtrRef.current = null;
5732
6340
  clearBreakTimer();
6341
+ if (action === "unarmed" || !p) return;
5733
6342
  setHolding(false);
5734
- if (!p || p.id !== e.pointerId) return;
5735
6343
  const ms = Date.now() - p.t;
6344
+ if (pendingHoldRef.current) {
6345
+ pendingHoldReleaseRef.current = true;
6346
+ if (ms >= 250) {
6347
+ armHoldExit();
6348
+ suppressClickUntilRef.current = Date.now() + 500;
6349
+ }
6350
+ return;
6351
+ }
5736
6352
  if (bootNow().mode !== "hold") {
5737
6353
  if (toggleHoldRef.current) {
5738
6354
  toggleHoldRef.current = false;
@@ -5750,6 +6366,10 @@ function MicButton({
5750
6366
  bus.stopReading(!!useSession);
5751
6367
  return;
5752
6368
  }
6369
+ if (localRef.current === "on" && pressFromOffRef.current) {
6370
+ engineRef.current?.endHeld(true);
6371
+ return;
6372
+ }
5753
6373
  if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
5754
6374
  if (localRef.current === "on") {
5755
6375
  engineRef.current?.endHeld(true);
@@ -5759,9 +6379,14 @@ function MicButton({
5759
6379
  }
5760
6380
  return;
5761
6381
  }
5762
- if (localRef.current === "on") engineRef.current?.endHeld(false);
6382
+ if (localRef.current === "on") {
6383
+ engineRef.current?.endHeld(false);
6384
+ armHoldExit();
6385
+ suppressClickUntilRef.current = Date.now() + 500;
6386
+ }
5763
6387
  };
5764
6388
  const onPointerCancel = () => {
6389
+ if (!holdPtrRef.current && !toggleHoldRef.current) return;
5765
6390
  holdPtrRef.current = null;
5766
6391
  toggleHoldRef.current = false;
5767
6392
  clearBreakTimer();
@@ -5778,10 +6403,7 @@ function MicButton({
5778
6403
  const bars = Array.from(el.querySelectorAll(".dshvm-eq i"));
5779
6404
  const base = eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8];
5780
6405
  const paint = (lv) => bars.forEach((b, i) => b.style.height = `${Math.max(3, base[i] * (0.35 + 0.65 * lv)).toFixed(1)}px`);
5781
- if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
5782
- paint(1);
5783
- return;
5784
- }
6406
+ const mq = typeof matchMedia === "function" ? matchMedia("(prefers-reduced-motion: reduce)") : null;
5785
6407
  let smooth = 0;
5786
6408
  let raf = 0;
5787
6409
  const tick = () => {
@@ -5790,8 +6412,33 @@ function MicButton({
5790
6412
  paint(smooth);
5791
6413
  raf = requestAnimationFrame(tick);
5792
6414
  };
5793
- tick();
5794
- return () => cancelAnimationFrame(raf);
6415
+ const apply2 = () => {
6416
+ if (eqPaintMode(mq?.matches === true) === "static-full") {
6417
+ if (raf) {
6418
+ cancelAnimationFrame(raf);
6419
+ raf = 0;
6420
+ }
6421
+ paint(1);
6422
+ return;
6423
+ }
6424
+ if (!raf) {
6425
+ smooth = 0;
6426
+ tick();
6427
+ }
6428
+ };
6429
+ apply2();
6430
+ let detach = null;
6431
+ if (mq && typeof mq.addEventListener === "function") {
6432
+ mq.addEventListener("change", apply2);
6433
+ detach = () => mq.removeEventListener("change", apply2);
6434
+ } else if (mq && typeof mq.addListener === "function") {
6435
+ mq.addListener(apply2);
6436
+ detach = () => mq.removeListener(apply2);
6437
+ }
6438
+ return () => {
6439
+ if (raf) cancelAnimationFrame(raf);
6440
+ detach?.();
6441
+ };
5795
6442
  }, [eqKind, bus]);
5796
6443
  const showTimer = on && !statusBarShown && !onceWaiting;
5797
6444
  const [elapsed, setElapsed] = (0, import_react3.useState)(0);
@@ -5815,12 +6462,24 @@ function MicButton({
5815
6462
  className: "dshvm-mic",
5816
6463
  "data-state": visual,
5817
6464
  onClick: (e) => {
6465
+ if (isAuxClickToIgnore(auxClickRef.current, e.detail)) {
6466
+ auxClickRef.current = false;
6467
+ return;
6468
+ }
5818
6469
  if (Date.now() < suppressClickUntilRef.current) return;
6470
+ if (localRef.current === "on" && (bus.ui.playing || onceRef.current)) {
6471
+ bus.stopReading(!!useSession);
6472
+ void exitModeRef.current("manual");
6473
+ return;
6474
+ }
5819
6475
  if (holdMode && !readingOutside()) {
5820
6476
  if (e.detail !== 0) return;
5821
6477
  }
5822
6478
  toggle();
5823
6479
  },
6480
+ onMouseDown: (e) => {
6481
+ e.preventDefault();
6482
+ },
5824
6483
  onPointerDown,
5825
6484
  onPointerMove,
5826
6485
  onPointerUp,