@livx.cc/agentx 0.99.156 → 0.99.158

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/dist/index.js CHANGED
@@ -6384,14 +6384,14 @@ function summarize(messages, focus) {
6384
6384
  if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
6385
6385
  if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
6386
6386
  if (focus?.trim()) {
6387
- const words3 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6387
+ const words4 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6388
6388
  const kept = [];
6389
6389
  const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
6390
6390
  outer: for (const msg of ordered) {
6391
6391
  if (msg.role === "tool") continue;
6392
6392
  for (const line of contentText(msg.content).split("\n")) {
6393
6393
  const l = line.toLowerCase();
6394
- if (line.trim() && words3.some((w) => l.includes(w))) {
6394
+ if (line.trim() && words4.some((w) => l.includes(w))) {
6395
6395
  kept.push(line.trim().slice(0, 200));
6396
6396
  if (kept.length >= 12) break outer;
6397
6397
  }
@@ -7663,13 +7663,13 @@ function isTranscriptComplete(text) {
7663
7663
  const trimmed = text.trim();
7664
7664
  if (!trimmed) return false;
7665
7665
  if (/[.?!]$/.test(trimmed)) return true;
7666
- const words3 = trimmed.toLowerCase().split(/\s+/);
7667
- const lastWord = words3[words3.length - 1];
7666
+ const words4 = trimmed.toLowerCase().split(/\s+/);
7667
+ const lastWord = words4[words4.length - 1];
7668
7668
  if (COMPLETE_ENDINGS.has(lastWord)) return true;
7669
7669
  if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
7670
7670
  const lower2 = trimmed.toLowerCase();
7671
7671
  for (const marker of CONTINUATION_MARKERS) if (lower2.endsWith(marker)) return false;
7672
- if (words3.length <= 2) return false;
7672
+ if (words4.length <= 2) return false;
7673
7673
  return true;
7674
7674
  }
7675
7675
  var MAX_HOLD_MS = 2e3;
@@ -7719,12 +7719,12 @@ var SpeakerRunsOptions = class {
7719
7719
  /** A run shorter than this (a diarization flap) joins its neighbour — the previous run, or the next for a leading one. */
7720
7720
  minRunWords = 2;
7721
7721
  };
7722
- function speakerRuns(words3, options) {
7722
+ function speakerRuns(words4, options) {
7723
7723
  const { minRunWords } = { ...new SpeakerRunsOptions(), ...options };
7724
7724
  let runs = [];
7725
- for (const w of words3) {
7725
+ for (const w of words4) {
7726
7726
  const last = runs[runs.length - 1];
7727
- const spk = w.spk ?? last?.spk ?? words3.find((x) => x.spk != null)?.spk ?? "";
7727
+ const spk = w.spk ?? last?.spk ?? words4.find((x) => x.spk != null)?.spk ?? "";
7728
7728
  if (last?.spk === spk) last.words.push(w);
7729
7729
  else runs.push({ spk, words: [w] });
7730
7730
  }
@@ -7753,6 +7753,105 @@ function formatTurns(turns, name = (t) => `Speaker ${t.speaker}`) {
7753
7753
  return turns.map((t) => `${name(t)}: ${t.text}`).join("\n");
7754
7754
  }
7755
7755
 
7756
+ // node_modules/@bod.ee/voice/src/core/agent-text-feed.ts
7757
+ var AgentTextFeedOptions = class {
7758
+ /** Deliver a piece (`text` may be '' with `endOfSegment`). */
7759
+ send = () => {
7760
+ };
7761
+ clock;
7762
+ /** Playback clock of the current turn (ms) — the same one word timestamps are anchored on. */
7763
+ playedMs = () => 0;
7764
+ /** Send this far ahead of playback (docs: 500 ms–1 s). */
7765
+ leadMs = 700;
7766
+ /** Speech-rate estimate without word timestamps. */
7767
+ charsPerSec = 15;
7768
+ tickMs = 50;
7769
+ };
7770
+ var AgentTextFeed = class {
7771
+ options;
7772
+ open = false;
7773
+ byWords = false;
7774
+ words = [];
7775
+ // [word, start sec on the playback clock]
7776
+ wordsSent = 0;
7777
+ chars = "";
7778
+ charsSent = 0;
7779
+ originMs = -1;
7780
+ // char clock: playback position of the turn's first audio byte (-1 = no audio yet)
7781
+ timer = null;
7782
+ constructor(options) {
7783
+ this.options = { ...new AgentTextFeedOptions(), ...options };
7784
+ }
7785
+ get active() {
7786
+ return this.open;
7787
+ }
7788
+ /** A spoken turn starts (closes a previous one still open — a gapless handoff plays it out). */
7789
+ begin(byWords) {
7790
+ if (this.open) this.end();
7791
+ this.open = true;
7792
+ this.byWords = byWords;
7793
+ this.words = [];
7794
+ this.wordsSent = 0;
7795
+ this.chars = "";
7796
+ this.charsSent = 0;
7797
+ this.originMs = -1;
7798
+ this.schedule();
7799
+ }
7800
+ /** Text handed to the TTS (char clock only). */
7801
+ text(t) {
7802
+ if (this.open && !this.byWords) this.chars += t;
7803
+ }
7804
+ /** The turn's first audio byte lands at this playback position (char clock only). */
7805
+ audioAt(ms) {
7806
+ if (this.open && this.originMs < 0) this.originMs = ms;
7807
+ }
7808
+ /** A TTS word timestamp on the playback clock (word clock only). */
7809
+ word(w, startSec) {
7810
+ if (this.open && this.byWords && w) this.words.push([w, startSec]);
7811
+ }
7812
+ /** The turn's audio finished playing: send the rest, close the segment. */
7813
+ end() {
7814
+ if (!this.open) return;
7815
+ this.flush(Infinity, true);
7816
+ }
7817
+ /** Barge-in: send only what was already due, close the segment. */
7818
+ cut() {
7819
+ if (!this.open) return;
7820
+ this.flush(this.options.playedMs() + this.options.leadMs, true);
7821
+ }
7822
+ schedule() {
7823
+ this.timer = this.options.clock.setTimeout(() => {
7824
+ this.timer = null;
7825
+ if (!this.open) return;
7826
+ this.flush(this.options.playedMs() + this.options.leadMs, false);
7827
+ if (this.open) this.schedule();
7828
+ }, this.options.tickMs);
7829
+ }
7830
+ flush(dueMs, close) {
7831
+ let piece = "";
7832
+ if (this.byWords) {
7833
+ let n = this.wordsSent;
7834
+ while (n < this.words.length && this.words[n][1] * 1e3 <= dueMs) n++;
7835
+ piece = this.words.slice(this.wordsSent, n).map(([w]) => w + " ").join("");
7836
+ this.wordsSent = n;
7837
+ } else if (this.originMs >= 0 || dueMs === Infinity) {
7838
+ const n = dueMs === Infinity ? this.chars.length : Math.min(this.chars.length, Math.floor((dueMs - this.originMs) / 1e3 * this.options.charsPerSec));
7839
+ if (n > this.charsSent) {
7840
+ piece = this.chars.slice(this.charsSent, n);
7841
+ this.charsSent = n;
7842
+ }
7843
+ }
7844
+ if (close) {
7845
+ this.open = false;
7846
+ if (this.timer) {
7847
+ this.options.clock.clearTimeout(this.timer);
7848
+ this.timer = null;
7849
+ }
7850
+ }
7851
+ if (piece || close) this.options.send(piece, close);
7852
+ }
7853
+ };
7854
+
7756
7855
  // node_modules/@bod.ee/voice/src/core/engine.ts
7757
7856
  var log15 = forComponent2("VoiceEngine");
7758
7857
  var addLangs = (to, from) => {
@@ -8045,6 +8144,8 @@ var VoiceEngine = class _VoiceEngine {
8045
8144
  // leading timestamped words that are the ack spoken on this turn's context, not the reply
8046
8145
  revealedN = 0;
8047
8146
  revealPoll = null;
8147
+ agentText = null;
8148
+ // stt.agentTextInput: our spoken text, paced to playback
8048
8149
  // Sub-turn timestamp anchoring. A TTS context emits word starts relative to ITS OWN audio start, so
8049
8150
  // `wordStarts` (one flat turn timeline) is only valid while the turn stays on one context. It does
8050
8151
  // not: `subturnBoundary()` rotates the context, and Cartesia ALSO rotates it on its own (~5s idle
@@ -8186,17 +8287,19 @@ var VoiceEngine = class _VoiceEngine {
8186
8287
  this.tts.onAudio = (c) => {
8187
8288
  if (!this.speaking && !this.bcActive) return;
8188
8289
  if (this.wordAnchorPending && this.speaking) this.anchorSubturn();
8290
+ if (this.speaking) this.agentText?.audioAt(this.player.endMs());
8189
8291
  this.player.write(c);
8190
8292
  };
8191
8293
  if (this.options.revealMode === "word" || this.options.heardTimestamps) {
8192
8294
  this.tts.wantTimestamps = true;
8193
- this.tts.onTimestamps = (words3, start) => {
8295
+ this.tts.onTimestamps = (words4, start) => {
8194
8296
  if (this.interrupted) return;
8195
8297
  start.forEach((s, i) => {
8196
- if (this.wordAnchorPending) this.wordPending.push([words3[i] ?? "", s]);
8298
+ if (this.wordAnchorPending) this.wordPending.push([words4[i] ?? "", s]);
8197
8299
  else {
8198
8300
  this.wordStarts.push(this.wordOrigin + s);
8199
- this.wordTexts.push(words3[i] ?? "");
8301
+ this.wordTexts.push(words4[i] ?? "");
8302
+ this.agentText?.word(words4[i] ?? "", this.wordOrigin + s);
8200
8303
  }
8201
8304
  });
8202
8305
  };
@@ -8222,6 +8325,18 @@ var VoiceEngine = class _VoiceEngine {
8222
8325
  this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
8223
8326
  };
8224
8327
  this.stt.onLevel = (rms) => this.handleLevel(rms);
8328
+ const stt = this.stt;
8329
+ this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
8330
+ clock: this.clock,
8331
+ playedMs: () => Math.max(0, this.player.playedMs()),
8332
+ send: (text, end) => {
8333
+ try {
8334
+ stt.sendAgentText(text, end);
8335
+ } catch (e) {
8336
+ log15.warn(`sendAgentText threw: ${e instanceof Error ? e.message : e}`);
8337
+ }
8338
+ }
8339
+ }) : null;
8225
8340
  await Promise.all([
8226
8341
  this.tts.connect(),
8227
8342
  this.stt.start(),
@@ -8327,10 +8442,11 @@ var VoiceEngine = class _VoiceEngine {
8327
8442
  this.lineBefore = new Set(this.echoWords);
8328
8443
  this.tts.newContext();
8329
8444
  this.clause = "";
8445
+ this.agentText?.begin(!!this.tts.wantTimestamps);
8330
8446
  this.clearAckTimer("new_turn");
8331
8447
  if (ack && this.options.ackPhrase) {
8332
8448
  this.diag("ack_fired", { phrase: this.options.ackPhrase, adaptive: false });
8333
- this.tts.speak(this.options.ackPhrase + " ", true);
8449
+ this.say(this.options.ackPhrase + " ");
8334
8450
  this.spokeDeltas = true;
8335
8451
  this.ackAt = this.clock.now();
8336
8452
  this.lastAck = this.options.ackPhrase;
@@ -8402,13 +8518,13 @@ var VoiceEngine = class _VoiceEngine {
8402
8518
  }
8403
8519
  for (const w of this.words(this.reply)) this.echoWords.add(w);
8404
8520
  const cut = this.options.flushFirstClause && this.clause !== null && this.tts.flush ? speech.search(/[,.;:!?…](?=\s|$)/) : -1;
8405
- if (cut < 0) this.tts.speak(forSpeech(speech), true);
8521
+ if (cut < 0) this.say(forSpeech(speech));
8406
8522
  else {
8407
- this.tts.speak(forSpeech(speech.slice(0, cut + 1)), true);
8523
+ this.say(forSpeech(speech.slice(0, cut + 1)));
8408
8524
  this.clause = null;
8409
8525
  this.tts.flush();
8410
8526
  this.diag("tts_first_clause_flush", {});
8411
- if (speech.slice(cut + 1)) this.tts.speak(forSpeech(speech.slice(cut + 1)), true);
8527
+ if (speech.slice(cut + 1)) this.say(forSpeech(speech.slice(cut + 1)));
8412
8528
  }
8413
8529
  if (!this.spokeDeltas && this.turnStartAt) log15.debug(`ttft: ${Math.round(this.clock.now() - this.turnStartAt)}ms`);
8414
8530
  this.spokeDeltas = true;
@@ -8449,6 +8565,7 @@ var VoiceEngine = class _VoiceEngine {
8449
8565
  for (const [w, s] of this.wordPending) {
8450
8566
  this.wordStarts.push(this.wordOrigin + s);
8451
8567
  this.wordTexts.push(w);
8568
+ this.agentText?.word(w, this.wordOrigin + s);
8452
8569
  }
8453
8570
  this.wordPending = [];
8454
8571
  }
@@ -8471,8 +8588,8 @@ var VoiceEngine = class _VoiceEngine {
8471
8588
  while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
8472
8589
  if (n !== this.revealedN) {
8473
8590
  this.revealedN = n;
8474
- const words3 = this.revealText.trim().split(/\s+/).filter(Boolean);
8475
- this.options.onReveal(words3.slice(0, n).join(" "));
8591
+ const words4 = this.revealText.trim().split(/\s+/).filter(Boolean);
8592
+ this.options.onReveal(words4.slice(0, n).join(" "));
8476
8593
  }
8477
8594
  this.revealPoll = this.clock.setTimeout(tick, 60);
8478
8595
  };
@@ -8491,6 +8608,11 @@ var VoiceEngine = class _VoiceEngine {
8491
8608
  if (full) this.options.onReveal(full);
8492
8609
  }
8493
8610
  }
8611
+ /** Speech on the open turn's TTS context — also fed to the STT's agent text input (when on). */
8612
+ say(text) {
8613
+ this.agentText?.text(text);
8614
+ this.tts.speak(text, true);
8615
+ }
8494
8616
  /** close the spoken turn (idempotent); stays audible until ALL audio arrived AND playback drains */
8495
8617
  endSpeech() {
8496
8618
  this.interrupted = false;
@@ -8510,7 +8632,7 @@ var VoiceEngine = class _VoiceEngine {
8510
8632
  const t = this.emo.flush();
8511
8633
  this.emo = null;
8512
8634
  if (t.prose) this.reply += t.prose;
8513
- if (t.speech) this.tts.speak(forSpeech(t.speech), true);
8635
+ if (t.speech) this.say(forSpeech(t.speech));
8514
8636
  }
8515
8637
  if (this.reply) this.prevReply = this.reply;
8516
8638
  const settle = () => {
@@ -8524,6 +8646,7 @@ var VoiceEngine = class _VoiceEngine {
8524
8646
  }
8525
8647
  this.drainTimer = null;
8526
8648
  this.speaking = false;
8649
+ this.agentText?.end();
8527
8650
  this.stopWordReveal(true);
8528
8651
  if (this.turnStartAt) log15.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
8529
8652
  this.echoUntil = this.clock.now() + 2500;
@@ -8639,7 +8762,7 @@ var VoiceEngine = class _VoiceEngine {
8639
8762
  return;
8640
8763
  }
8641
8764
  this.diag("ack_fired", { phrase, adaptive: true, waitedMs: this.options.adaptiveAckMs, ...picked ? { picked } : {} });
8642
- this.tts.speak(phrase + " ", true);
8765
+ this.say(phrase + " ");
8643
8766
  this.spokeDeltas = true;
8644
8767
  this.ackAt = this.clock.now();
8645
8768
  this.lastAck = phrase;
@@ -8725,6 +8848,7 @@ var VoiceEngine = class _VoiceEngine {
8725
8848
  this.interrupted = true;
8726
8849
  this.suspectUntil = 0;
8727
8850
  this.echoUntil = this.clock.now() + Math.max(2500, this.player.drainMs() + 3e3);
8851
+ this.agentText?.cut();
8728
8852
  this.tts.cancel();
8729
8853
  this.player.kill();
8730
8854
  if (!this.usingAec) this.echoHead = true;
@@ -8755,6 +8879,7 @@ var VoiceEngine = class _VoiceEngine {
8755
8879
  if (this.specTimer) this.clock.clearTimeout(this.specTimer);
8756
8880
  this.bcSupersede();
8757
8881
  this.cancelAside("stop");
8882
+ this.agentText?.cut();
8758
8883
  this.stt.stop();
8759
8884
  this.player.kill();
8760
8885
  this.tts.close();
@@ -9318,7 +9443,8 @@ var VoiceEngine = class _VoiceEngine {
9318
9443
  const names = lines.map((t) => this.options.speakerResolver.name(t.speaker, t));
9319
9444
  return { out: formatTurns(lines, (t) => names[lines.indexOf(t)]), speakers: [...new Set(names)] };
9320
9445
  }
9321
- handleUtterance(text, langs, rawTurns) {
9446
+ /** `judged`: the host yielded to these very words (decideOverlap) — the user's, never our echo. */
9447
+ handleUtterance(text, langs, rawTurns, judged = false) {
9322
9448
  let turns;
9323
9449
  const cap = this.uttEcho;
9324
9450
  this.uttEcho = void 0;
@@ -9352,12 +9478,23 @@ var VoiceEngine = class _VoiceEngine {
9352
9478
  }
9353
9479
  }
9354
9480
  const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
9481
+ if (this.speaking && this.ctxOpen && !this.pausedAt && this.overlapCapable && !ownTail && this.options.overlapDecideMs > 0 && this.shortOverlap(text) && this.novelWords(text).length > 0 && this.novelWords(text).length * 2 >= this.words(text).length) {
9482
+ this.pausedAt = this.clock.now();
9483
+ this.player.pause();
9484
+ this.lastOverlapPartial = text;
9485
+ this.decideHeldFinal = text;
9486
+ addLangs(this.decideHeldLangs, langs);
9487
+ this.decideHeldTurns.push(...turns);
9488
+ this.diag("overlap_pause", { text: text.slice(0, 60), final: true });
9489
+ this.awaitOverlapDecision(text);
9490
+ return;
9491
+ }
9355
9492
  if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
9356
9493
  this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
9357
9494
  this.stt.reset();
9358
9495
  return;
9359
9496
  }
9360
- if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9497
+ if (!judged && this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9361
9498
  this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
9362
9499
  this.stt.reset();
9363
9500
  return;
@@ -9514,7 +9651,7 @@ var VoiceEngine = class _VoiceEngine {
9514
9651
  this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
9515
9652
  this.interrupt();
9516
9653
  this.options.onBargeIn(phase);
9517
- if (held) this.handleUtterance(held, heldLangs, heldTurns);
9654
+ if (held) this.handleUtterance(held, heldLangs, heldTurns, trigger === "host_yield");
9518
9655
  }
9519
9656
  /** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
9520
9657
  * was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
@@ -9855,8 +9992,8 @@ var SonioxSTTOptions = class {
9855
9992
  /** `stt-rt-preview` was RETIRED (aliased to the two-generations-old v3 on 2025-10-31), so every
9856
9993
  * caller that never set this was silently running an old model while the alias kept it working —
9857
9994
  * the failure mode of a default that is a moving vendor pointer. Pin a real version instead;
9858
- * `stt-rt-v5` is live today (verified against GET https://api.soniox.com/v1/models). */
9859
- model = "stt-rt-v5";
9995
+ * `stt-rt-v6` (2026-11-03) replaced v5, deprecated and removed 2026-12-15 (docs.soniox.com/stt/models). */
9996
+ model = "stt-rt-v6";
9860
9997
  languageHints = ["en"];
9861
9998
  /** Opt-in Soniox language identification (`enable_language_identification`): every token is tagged with a
9862
9999
  * `language` code, and onUtterance's 3rd arg reports the utterance's dominant one (by characters). */
@@ -9881,6 +10018,10 @@ var SonioxSTTOptions = class {
9881
10018
  /** No-audio watchdog: if the mic source stops delivering chunks for this long, capture is dead →
9882
10019
  * fire onFatal + stop (else Soniox idle-timeouts and reconnect-loops forever). 0 = disable. */
9883
10020
  noAudioTimeoutMs = 1e4;
10021
+ /** Opt-in Soniox agent text input (`enable_agent_text_input`, stt-rt-v6 only): the assistant's spoken text goes on the
10022
+ * same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
10023
+ * of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
10024
+ agentTextInput = false;
9884
10025
  };
9885
10026
  var SonioxSTT = class {
9886
10027
  options;
@@ -9943,6 +10084,17 @@ var SonioxSTT = class {
9943
10084
  constructor(options) {
9944
10085
  this.options = { ...new SonioxSTTOptions(), ...options };
9945
10086
  }
10087
+ get agentTextInput() {
10088
+ return this.options.agentTextInput;
10089
+ }
10090
+ /** Send the next not-yet-sent piece of what the assistant is saying (`agent_text`); `endOfSegment` closes the
10091
+ * assistant's turn (finished or interrupted). Spaces are kept as given. No-op unless `agentTextInput` is on and the
10092
+ * socket is open (a reconnect starts a fresh stream; text sent before it is not re-sent). */
10093
+ sendAgentText(text, endOfSegment = false) {
10094
+ if (!this.options.agentTextInput || this.stopped || this.ws?.readyState !== WebSocket.OPEN) return;
10095
+ if (!text && !endOfSegment) return;
10096
+ this.ws.send(JSON.stringify({ type: "agent_text", text, ...endOfSegment ? { end_of_segment: true } : {} }));
10097
+ }
9946
10098
  get usingAec() {
9947
10099
  return this.options.source?.aec ?? false;
9948
10100
  }
@@ -9967,18 +10119,20 @@ var SonioxSTT = class {
9967
10119
  ...this.options.languageHintsStrict ? { language_hints_strict: true } : {},
9968
10120
  ...this.options.languageIdentification ? { enable_language_identification: true } : {},
9969
10121
  ...this.options.diarization ? { enable_speaker_diarization: true } : {},
9970
- ...this.options.terms?.length ? { context: { terms: this.options.terms } } : {}
10122
+ ...this.options.terms?.length ? { context: { terms: this.options.terms } } : {},
10123
+ ...this.options.agentTextInput ? { enable_agent_text_input: true } : {}
9971
10124
  })
9972
10125
  );
9973
10126
  this.ws.onmessage = (ev) => this.handle(JSON.parse(String(ev.data)));
9974
10127
  this.ws.onclose = (ev) => {
9975
- if (this.stopped) return;
10128
+ if (this.stopped || this.failed) return;
9976
10129
  log16.warn(`soniox ws closed (${ev.code} ${ev.reason || ""}) \u2014 reconnecting`);
9977
10130
  this.diag("stt_ws_closed", { code: ev.code, reason: String(ev.reason || ""), reconnecting: true });
9978
10131
  this.reset();
9979
10132
  this.connectWs().catch((e) => {
9980
10133
  log16.error(`soniox reconnect failed: ${e.message}`);
9981
10134
  this.diag("stt_reconnect_failed", { message: e.message });
10135
+ this.fail(`Speech-to-text (Soniox) lost its connection and could not reconnect (${e.message}).`);
9982
10136
  });
9983
10137
  };
9984
10138
  }
@@ -10038,7 +10192,10 @@ var SonioxSTT = class {
10038
10192
  handle(m) {
10039
10193
  if (m.error_message) {
10040
10194
  this.diag("stt_error", { message: String(m.error_message), code: m.error_code });
10041
- return log16.error(`soniox: ${m.error_message}`);
10195
+ log16.error(`soniox: ${m.error_message}`);
10196
+ const fatal = sonioxFatal(m.error_code, String(m.error_message));
10197
+ if (fatal) this.fail(fatal);
10198
+ return;
10042
10199
  }
10043
10200
  let endpoint = false;
10044
10201
  const foreign = this.options.languageHintsStrict ? foreignScript(this.options.languageHints) : null;
@@ -10100,8 +10257,8 @@ var SonioxSTT = class {
10100
10257
  /** Per-speaker turns of the current utterance (diarization only; undefined otherwise or when Soniox tagged no speaker). */
10101
10258
  turns(withPartials) {
10102
10259
  if (!this.options.diarization) return void 0;
10103
- const words3 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10104
- return words3.some((w) => w.spk != null) ? speakerRuns(words3) : void 0;
10260
+ const words4 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10261
+ return words4.some((w) => w.spk != null) ? speakerRuns(words4) : void 0;
10105
10262
  }
10106
10263
  reset() {
10107
10264
  this.finalToks = [];
@@ -10114,6 +10271,14 @@ var SonioxSTT = class {
10114
10271
  this.firstTokenAt = 0;
10115
10272
  this.lastWordEndMs = 0;
10116
10273
  }
10274
+ /** Unrecoverable: tell the host once, then stop (no reconnect loop). */
10275
+ failed = false;
10276
+ fail(message) {
10277
+ if (this.failed || this.stopped) return;
10278
+ this.failed = true;
10279
+ this.onFatal(message);
10280
+ this.stop();
10281
+ }
10117
10282
  stop() {
10118
10283
  this.stopped = true;
10119
10284
  if (this.endpointTimer) clearInterval(this.endpointTimer);
@@ -10123,6 +10288,15 @@ var SonioxSTT = class {
10123
10288
  this.ws?.close();
10124
10289
  }
10125
10290
  };
10291
+ function sonioxFatal(code, message) {
10292
+ const c = Number(code);
10293
+ if (c === 402 || /balance|autopay|add funds|payment required/i.test(message))
10294
+ return `Speech-to-text is out of credit (Soniox): ${message} Add funds at console.soniox.com.`;
10295
+ if (c === 401 || c === 403 || /api key|unauthori[sz]ed|forbidden/i.test(message))
10296
+ return `Speech-to-text (Soniox) rejected the API key: ${message}`;
10297
+ if (c === 400) return `Speech-to-text (Soniox) rejected the request: ${message}`;
10298
+ return null;
10299
+ }
10126
10300
  var SCRIPTS = {
10127
10301
  he: ["Hebrew"],
10128
10302
  yi: ["Hebrew"],
@@ -10455,6 +10629,14 @@ import { AIClient, DecideClient, JevAdapter, LlmDecideAdapter } from "ai.libx.js
10455
10629
 
10456
10630
  // src/voice/overlap.ts
10457
10631
  init_logging();
10632
+
10633
+ // src/voice/closing.ts
10634
+ var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
10635
+ function isClosing(text) {
10636
+ return words(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
10637
+ }
10638
+
10639
+ // src/voice/overlap.ts
10458
10640
  var log21 = forComponent("Overlap");
10459
10641
  var norm2 = (s) => s.toLowerCase().replace(/[’']/g, "'").replace(/[^\p{L}\p{N}' -]+/gu, " ").replace(/\s+/g, " ").trim();
10460
10642
  var HARD = /^(?:(?:stop|wait|no|nope|hold on|hang on|hold up|pause|cancel|quiet|enough|shut up|never ?mind)(?: |$))+$/;
@@ -10498,19 +10680,20 @@ function overlapRule(text) {
10498
10680
  if (CONTINUE.test(norm2(text))) return "keep";
10499
10681
  let t = norm2(text);
10500
10682
  if (!t) return void 0;
10683
+ if (isClosing(text)) return "cut";
10501
10684
  if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
10502
10685
  for (const p of PHRASES) t = t.split(p).join(" ");
10503
- const words3 = t.split(/[\s-]+/).filter(Boolean);
10686
+ const words4 = t.split(/[\s-]+/).filter(Boolean);
10504
10687
  const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
10505
- if (words3.every(ack)) return "keep";
10506
- const lead2 = words3.findIndex((w) => !LEAD.has(w));
10507
- if (lead2 >= 0 && LEADER.has(words3[lead2]) && !words3.some((w) => HARD.test(w + " ")) && words3.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
10688
+ if (words4.every(ack)) return "keep";
10689
+ const lead2 = words4.findIndex((w) => !LEAD.has(w));
10690
+ if (lead2 >= 0 && LEADER.has(words4[lead2]) && !words4.some((w) => HARD.test(w + " ")) && words4.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
10508
10691
  return void 0;
10509
10692
  }
10510
10693
  function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
10511
10694
  return async (heard, signal) => {
10512
10695
  const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
10513
- Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, or telling it to stop? A reaction is not steering: surprise, disbelief, "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10696
+ Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, telling it to stop, or saying goodbye? A reaction is not steering: surprise, disbelief, "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10514
10697
  Answer yes (steering) or no (a reaction).`;
10515
10698
  const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
10516
10699
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
@@ -10957,8 +11140,8 @@ function cleanLine(s, lang, maxWords = 6) {
10957
11140
  const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
10958
11141
  const raw = first.replace(LINE_TAG, " ").trim();
10959
11142
  if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
10960
- const words3 = cleanWords(raw, lang, maxWords);
10961
- return words3 && tags ? `${tags} ${words3}` : words3;
11143
+ const words4 = cleanWords(raw, lang, maxWords);
11144
+ return words4 && tags ? `${tags} ${words4}` : words4;
10962
11145
  }
10963
11146
  var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
10964
11147
  var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
@@ -11167,10 +11350,7 @@ function endsMidPhrase(text) {
11167
11350
  if (TRAILING_PREPS.has(last)) return !QUESTION_START.test(t) && !PHRASAL_HOST.has(prev);
11168
11351
  return MID_PHRASE_WORDS.has(last);
11169
11352
  }
11170
- var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11171
- function isClosing(text) {
11172
- return words(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
11173
- }
11353
+ var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11174
11354
  var TurnGateOptions = class {
11175
11355
  holdMs = 1200;
11176
11356
  /** A finished statement (not a question) waits this long for more speech before it is a turn. 0 = sent at once. */
@@ -11302,7 +11482,7 @@ var TurnGate = class {
11302
11482
  }
11303
11483
  refinal(last, t, key, sttId) {
11304
11484
  if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
11305
- const a = words(last.text), b = words(t);
11485
+ const a = words2(last.text), b = words2(t);
11306
11486
  let i = 0;
11307
11487
  while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
11308
11488
  const extra = b.slice(i).join(" ");
@@ -11349,8 +11529,8 @@ function isFalseStart(sentence) {
11349
11529
  return !!m && !/^(?:h+m+|u+m+|u+h+|o+h+|a+h+|well|so|er+m*)$/i.test(m[1]);
11350
11530
  }
11351
11531
  function wordOverlap(sentence, prior) {
11352
- const words3 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11353
- const have = new Set(words3(prior)), ws = words3(sentence);
11532
+ const words4 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11533
+ const have = new Set(words4(prior)), ws = words4(sentence);
11354
11534
  return ws.length ? ws.filter((w) => have.has(w)).length / ws.length : 0;
11355
11535
  }
11356
11536
  var DuplexAgentOptions = class {
@@ -13898,8 +14078,8 @@ var ConvoTree = class {
13898
14078
  this.from = heardWords;
13899
14079
  }
13900
14080
  /** Posterior of a node after seeing its cue. */
13901
- confidence(p, words3) {
13902
- const l = p * (words3 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
14081
+ confidence(p, words4) {
14082
+ const l = p * (words4 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
13903
14083
  return l / (l + 1 - p);
13904
14084
  }
13905
14085
  /** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
@@ -14322,10 +14502,10 @@ var SecondChannelOptions = class {
14322
14502
  now = () => performance.now();
14323
14503
  random = Math.random;
14324
14504
  };
14325
- var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14505
+ var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14326
14506
  var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
14327
14507
  var onlyHesitation = (s) => {
14328
- const w = words2(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14508
+ const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14329
14509
  return !!w.length && w.every((x) => HESITATION.test(x));
14330
14510
  };
14331
14511
  function withBudget(p, ms, what, ac) {
@@ -14491,7 +14671,7 @@ var SecondChannel = class {
14491
14671
  if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
14492
14672
  if (!this.tree.empty) {
14493
14673
  this.treeStep(t);
14494
- if (!this.regrown && words2(t).length >= this.o.regrowAtWords) {
14674
+ if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
14495
14675
  this.regrown = true;
14496
14676
  this.requestTree(t);
14497
14677
  }
@@ -14504,7 +14684,7 @@ var SecondChannel = class {
14504
14684
  }
14505
14685
  }
14506
14686
  if (this.o.anticipate && !this.tree) {
14507
- const n = words2(t).length;
14687
+ const n = words3(t).length;
14508
14688
  if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
14509
14689
  else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
14510
14690
  this.revised = true;
@@ -14517,7 +14697,7 @@ var SecondChannel = class {
14517
14697
  this.bcTimer = null;
14518
14698
  if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
14519
14699
  }, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
14520
- if (words2(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14700
+ if (words3(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14521
14701
  }
14522
14702
  /** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
14523
14703
  onPause(ms) {
@@ -14612,7 +14792,7 @@ var SecondChannel = class {
14612
14792
  this.heard = text.trim();
14613
14793
  this.said = (heardCut ?? this.reply).trim();
14614
14794
  this.lastWordAgo = Math.max(0, lastWordAgoMs);
14615
- this.floorWords = this.carried + words2(this.heard).length;
14795
+ this.floorWords = this.carried + words3(this.heard).length;
14616
14796
  this.lastUser = this.heard;
14617
14797
  this.detect(this.heard);
14618
14798
  this.main = "idle";
@@ -14671,7 +14851,7 @@ var SecondChannel = class {
14671
14851
  return this.main === "first_audio" || this.main === "speaking";
14672
14852
  }
14673
14853
  tail() {
14674
- return words2(this.heard).slice(-this.o.microWords).join(" ");
14854
+ return words3(this.heard).slice(-this.o.microWords).join(" ");
14675
14855
  }
14676
14856
  /** Hard gates every line passes, whoever proposed it. */
14677
14857
  allowed(k) {
@@ -14690,7 +14870,7 @@ var SecondChannel = class {
14690
14870
  }
14691
14871
  /** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
14692
14872
  bridgeBlock() {
14693
- const w = words2(this.heard), intent = turnIntent(this.heard);
14873
+ const w = words3(this.heard), intent = turnIntent(this.heard);
14694
14874
  if (!this.lang) return "language unknown";
14695
14875
  if (this.ownWords) return this.blocked("bridge");
14696
14876
  if (intent === "closer") return "no answer due";
@@ -14713,7 +14893,7 @@ var SecondChannel = class {
14713
14893
  }
14714
14894
  /** 0ms rule: the candidate line for this trigger, or silence. */
14715
14895
  rule(trigger, pauseMs = 0, breath = false, cue = null) {
14716
- const w = words2(this.heard);
14896
+ const w = words3(this.heard);
14717
14897
  if (!this.lang) return "silence";
14718
14898
  if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
14719
14899
  if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
@@ -14728,7 +14908,7 @@ var SecondChannel = class {
14728
14908
  this.planning = true;
14729
14909
  this.planTries++;
14730
14910
  }
14731
- const ctx = { agent: this.reply.trim(), user: words2(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
14911
+ const ctx = { agent: this.reply.trim(), user: words3(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
14732
14912
  void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
14733
14913
  if (p === null) ac.abort();
14734
14914
  if (turn !== this.turnNo) return;
@@ -14750,7 +14930,7 @@ var SecondChannel = class {
14750
14930
  const ctx = { talk: heard ? [...this.talk, `them (still talking): ${heard.slice(-240)}`] : [...this.talk], lang: detectLanguage(this.talk.join(" ").replace(/\b(them|you):/g, "")) ?? this.lang, recent: this.leaves.slice(-this.o.leafMemory), ...this.o.persona ? { persona: this.o.persona } : {} };
14751
14931
  const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
14752
14932
  void this.o.grow(ctx, ac.signal).then((r) => {
14753
- if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words2(this.heard).length : 0);
14933
+ if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
14754
14934
  this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: r.nodes.length, lines: r.nodes.flatMap((n) => [n.line, ...n.next.map((k) => k.line)]), ...r.tokens ? { tokens: r.tokens } : {} });
14755
14935
  }, (e) => {
14756
14936
  log31.warn(`tree failed: ${e?.message ?? e}`);
@@ -14766,10 +14946,10 @@ var SecondChannel = class {
14766
14946
  if (!hit) return;
14767
14947
  if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
14768
14948
  if (this.leafTimer) clearTimeout(this.leafTimer);
14769
- const at = words2(t).length;
14949
+ const at = words3(t).length;
14770
14950
  this.leafTimer = setTimeout(() => {
14771
14951
  this.leafTimer = null;
14772
- if (this.userSpeaking && words2(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
14952
+ if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
14773
14953
  }, this.o.cuePauseMs);
14774
14954
  }
14775
14955
  /** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
@@ -14779,14 +14959,14 @@ var SecondChannel = class {
14779
14959
  if (!this.o.pickLeaf || !this.o.aec) return;
14780
14960
  this.breathTimer = setTimeout(() => {
14781
14961
  this.breathTimer = null;
14782
- const n = words2(t).length, tree = this.tree;
14962
+ const n = words3(t).length, tree = this.tree;
14783
14963
  if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
14784
14964
  this.picking = true;
14785
14965
  const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
14786
14966
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
14787
14967
  this.picking = false;
14788
14968
  const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
14789
- if (!hit || !this.userSpeaking || words2(this.heard).length - n >= this.o.leafStaleWords) return;
14969
+ if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
14790
14970
  tree.take(hit.node, hit.conf);
14791
14971
  this.playLeaf(hit, "interim", "backchannel");
14792
14972
  });
@@ -14856,7 +15036,7 @@ var SecondChannel = class {
14856
15036
  if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
14857
15037
  return;
14858
15038
  }
14859
- const n0 = words2(this.heard).length;
15039
+ const n0 = words3(this.heard).length;
14860
15040
  this.decidedAt = n0;
14861
15041
  if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
14862
15042
  const opts = this.options;
@@ -14872,7 +15052,7 @@ var SecondChannel = class {
14872
15052
  this.busy = true;
14873
15053
  const gen = this.gen, t0 = this.o.now();
14874
15054
  const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
14875
- const stale = () => gen !== this.gen || words2(this.heard).length - n0 >= this.o.staleWords;
15055
+ const stale = () => gen !== this.gen || words3(this.heard).length - n0 >= this.o.staleWords;
14876
15056
  try {
14877
15057
  let kind = rule;
14878
15058
  let choice;
@@ -14892,7 +15072,7 @@ var SecondChannel = class {
14892
15072
  if (stale()) return ev({ choice, kind, text, acted: "stale" });
14893
15073
  if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
14894
15074
  const said = this.say(kind, text);
14895
- if (said && cue) this.cueFrom = words2(this.heard).length;
15075
+ if (said && cue) this.cueFrom = words3(this.heard).length;
14896
15076
  if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
14897
15077
  ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
14898
15078
  } finally {
@@ -14918,7 +15098,7 @@ var SecondChannel = class {
14918
15098
  this.noLine = "";
14919
15099
  if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
14920
15100
  const gen = this.gen, ac = new AbortController(), own = this.ownWords;
14921
- const said = own ? words2(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15101
+ const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
14922
15102
  const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
14923
15103
  log31.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
14924
15104
  this.bridgeReady = withBudget(this.o.generate(ctx, ac.signal), own ? this.o.bridgeBudgetMs : Math.max(this.o.generateBudgetMs, this.o.bridgeDelayMs), "bridge generate", ac).then((raw) => {
@@ -14986,8 +15166,8 @@ var SecondChannel = class {
14986
15166
  if (kind === "bridge") this.bridged = true;
14987
15167
  this.recent = [...this.recent, text].slice(-this.o.avoidLines);
14988
15168
  this.live = lineWords(text);
14989
- const words3 = this.live;
14990
- if (words3) this.o.show(words3, kind);
15169
+ const words4 = this.live;
15170
+ if (words4) this.o.show(words4, kind);
14991
15171
  const p = Promise.resolve(r).then(() => {
14992
15172
  }, (e) => {
14993
15173
  log31.warn(`channel line playback failed: ${e?.message ?? e}`);
@@ -15100,6 +15280,9 @@ var VoiceCallOptions = class {
15100
15280
  /** Stop the in-flight fill line now (barge-in only). */
15101
15281
  cancel = () => {
15102
15282
  };
15283
+ /** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
15284
+ cutAudio = () => {
15285
+ };
15103
15286
  /** Host caption — never history. */
15104
15287
  show = () => {
15105
15288
  };
@@ -15568,6 +15751,11 @@ var VoiceCall = class {
15568
15751
  const said = mv.kind === "resume" ? `${mv.line} ${cutSentence([...this.history].reverse().find((h) => h.who === "you" && h.cut)?.text ?? "")} ${rest}`.replace(/\s+/g, " ").trim() : mv.line;
15569
15752
  this.gate.replyStarted(c.id);
15570
15753
  const end = mv.kind === "say" && !!mv.end;
15754
+ if (end) try {
15755
+ this.o.cutAudio();
15756
+ } catch (e) {
15757
+ log32.warn(`cutAudio threw: ${e.message}`);
15758
+ }
15571
15759
  const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
15572
15760
  if (!played && !end) return this.close(c, "silent");
15573
15761
  if (played) this.o.show(said, "reply");