@livx.cc/agentx 0.99.156 → 0.99.157

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/cli.js CHANGED
@@ -6493,14 +6493,14 @@ function summarize(messages, focus) {
6493
6493
  if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
6494
6494
  if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
6495
6495
  if (focus?.trim()) {
6496
- const words4 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6496
+ const words5 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
6497
6497
  const kept = [];
6498
6498
  const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
6499
6499
  outer: for (const msg of ordered) {
6500
6500
  if (msg.role === "tool") continue;
6501
6501
  for (const line of contentText(msg.content).split("\n")) {
6502
6502
  const l = line.toLowerCase();
6503
- if (line.trim() && words4.some((w) => l.includes(w))) {
6503
+ if (line.trim() && words5.some((w) => l.includes(w))) {
6504
6504
  kept.push(line.trim().slice(0, 200));
6505
6505
  if (kept.length >= 12) break outer;
6506
6506
  }
@@ -7667,13 +7667,13 @@ function isTranscriptComplete(text) {
7667
7667
  const trimmed = text.trim();
7668
7668
  if (!trimmed) return false;
7669
7669
  if (/[.?!]$/.test(trimmed)) return true;
7670
- const words4 = trimmed.toLowerCase().split(/\s+/);
7671
- const lastWord = words4[words4.length - 1];
7670
+ const words5 = trimmed.toLowerCase().split(/\s+/);
7671
+ const lastWord = words5[words5.length - 1];
7672
7672
  if (COMPLETE_ENDINGS.has(lastWord)) return true;
7673
7673
  if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
7674
7674
  const lower2 = trimmed.toLowerCase();
7675
7675
  for (const marker of CONTINUATION_MARKERS) if (lower2.endsWith(marker)) return false;
7676
- if (words4.length <= 2) return false;
7676
+ if (words5.length <= 2) return false;
7677
7677
  return true;
7678
7678
  }
7679
7679
  var MAX_HOLD_MS = 2e3;
@@ -7723,12 +7723,12 @@ var SpeakerRunsOptions = class {
7723
7723
  /** A run shorter than this (a diarization flap) joins its neighbour — the previous run, or the next for a leading one. */
7724
7724
  minRunWords = 2;
7725
7725
  };
7726
- function speakerRuns(words4, options) {
7726
+ function speakerRuns(words5, options) {
7727
7727
  const { minRunWords } = { ...new SpeakerRunsOptions(), ...options };
7728
7728
  let runs = [];
7729
- for (const w of words4) {
7729
+ for (const w of words5) {
7730
7730
  const last = runs[runs.length - 1];
7731
- const spk = w.spk ?? last?.spk ?? words4.find((x) => x.spk != null)?.spk ?? "";
7731
+ const spk = w.spk ?? last?.spk ?? words5.find((x) => x.spk != null)?.spk ?? "";
7732
7732
  if (last?.spk === spk) last.words.push(w);
7733
7733
  else runs.push({ spk, words: [w] });
7734
7734
  }
@@ -8194,13 +8194,13 @@ var VoiceEngine = class _VoiceEngine {
8194
8194
  };
8195
8195
  if (this.options.revealMode === "word" || this.options.heardTimestamps) {
8196
8196
  this.tts.wantTimestamps = true;
8197
- this.tts.onTimestamps = (words4, start) => {
8197
+ this.tts.onTimestamps = (words5, start) => {
8198
8198
  if (this.interrupted) return;
8199
8199
  start.forEach((s, i) => {
8200
- if (this.wordAnchorPending) this.wordPending.push([words4[i] ?? "", s]);
8200
+ if (this.wordAnchorPending) this.wordPending.push([words5[i] ?? "", s]);
8201
8201
  else {
8202
8202
  this.wordStarts.push(this.wordOrigin + s);
8203
- this.wordTexts.push(words4[i] ?? "");
8203
+ this.wordTexts.push(words5[i] ?? "");
8204
8204
  }
8205
8205
  });
8206
8206
  };
@@ -8475,8 +8475,8 @@ var VoiceEngine = class _VoiceEngine {
8475
8475
  while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
8476
8476
  if (n !== this.revealedN) {
8477
8477
  this.revealedN = n;
8478
- const words4 = this.revealText.trim().split(/\s+/).filter(Boolean);
8479
- this.options.onReveal(words4.slice(0, n).join(" "));
8478
+ const words5 = this.revealText.trim().split(/\s+/).filter(Boolean);
8479
+ this.options.onReveal(words5.slice(0, n).join(" "));
8480
8480
  }
8481
8481
  this.revealPoll = this.clock.setTimeout(tick, 60);
8482
8482
  };
@@ -9322,7 +9322,8 @@ var VoiceEngine = class _VoiceEngine {
9322
9322
  const names = lines.map((t) => this.options.speakerResolver.name(t.speaker, t));
9323
9323
  return { out: formatTurns(lines, (t) => names[lines.indexOf(t)]), speakers: [...new Set(names)] };
9324
9324
  }
9325
- handleUtterance(text, langs, rawTurns) {
9325
+ /** `judged`: the host yielded to these very words (decideOverlap) — the user's, never our echo. */
9326
+ handleUtterance(text, langs, rawTurns, judged = false) {
9326
9327
  let turns;
9327
9328
  const cap = this.uttEcho;
9328
9329
  this.uttEcho = void 0;
@@ -9356,12 +9357,23 @@ var VoiceEngine = class _VoiceEngine {
9356
9357
  }
9357
9358
  }
9358
9359
  const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
9360
+ 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) {
9361
+ this.pausedAt = this.clock.now();
9362
+ this.player.pause();
9363
+ this.lastOverlapPartial = text;
9364
+ this.decideHeldFinal = text;
9365
+ addLangs(this.decideHeldLangs, langs);
9366
+ this.decideHeldTurns.push(...turns);
9367
+ this.diag("overlap_pause", { text: text.slice(0, 60), final: true });
9368
+ this.awaitOverlapDecision(text);
9369
+ return;
9370
+ }
9359
9371
  if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
9360
9372
  this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
9361
9373
  this.stt.reset();
9362
9374
  return;
9363
9375
  }
9364
- if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9376
+ if (!judged && this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9365
9377
  this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
9366
9378
  this.stt.reset();
9367
9379
  return;
@@ -9518,7 +9530,7 @@ var VoiceEngine = class _VoiceEngine {
9518
9530
  this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
9519
9531
  this.interrupt();
9520
9532
  this.options.onBargeIn(phase);
9521
- if (held2) this.handleUtterance(held2, heldLangs, heldTurns);
9533
+ if (held2) this.handleUtterance(held2, heldLangs, heldTurns, trigger === "host_yield");
9522
9534
  }
9523
9535
  /** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
9524
9536
  * was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
@@ -10104,8 +10116,8 @@ var SonioxSTT = class {
10104
10116
  /** Per-speaker turns of the current utterance (diarization only; undefined otherwise or when Soniox tagged no speaker). */
10105
10117
  turns(withPartials) {
10106
10118
  if (!this.options.diarization) return void 0;
10107
- const words4 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10108
- return words4.some((w) => w.spk != null) ? speakerRuns(words4) : void 0;
10119
+ const words5 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
10120
+ return words5.some((w) => w.spk != null) ? speakerRuns(words5) : void 0;
10109
10121
  }
10110
10122
  reset() {
10111
10123
  this.finalToks = [];
@@ -10459,6 +10471,14 @@ import { AIClient, DecideClient, JevAdapter, LlmDecideAdapter } from "ai.libx.js
10459
10471
 
10460
10472
  // src/voice/overlap.ts
10461
10473
  init_logging();
10474
+
10475
+ // src/voice/closing.ts
10476
+ var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
10477
+ function isClosing(text) {
10478
+ 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);
10479
+ }
10480
+
10481
+ // src/voice/overlap.ts
10462
10482
  var log20 = forComponent("Overlap");
10463
10483
  var norm2 = (s) => s.toLowerCase().replace(/[’']/g, "'").replace(/[^\p{L}\p{N}' -]+/gu, " ").replace(/\s+/g, " ").trim();
10464
10484
  var HARD = /^(?:(?:stop|wait|no|nope|hold on|hang on|hold up|pause|cancel|quiet|enough|shut up|never ?mind)(?: |$))+$/;
@@ -10502,19 +10522,20 @@ function overlapRule(text) {
10502
10522
  if (CONTINUE.test(norm2(text))) return "keep";
10503
10523
  let t = norm2(text);
10504
10524
  if (!t) return void 0;
10525
+ if (isClosing(text)) return "cut";
10505
10526
  if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
10506
10527
  for (const p of PHRASES) t = t.split(p).join(" ");
10507
- const words4 = t.split(/[\s-]+/).filter(Boolean);
10528
+ const words5 = t.split(/[\s-]+/).filter(Boolean);
10508
10529
  const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
10509
- if (words4.every(ack)) return "keep";
10510
- const lead2 = words4.findIndex((w) => !LEAD.has(w));
10511
- 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";
10530
+ if (words5.every(ack)) return "keep";
10531
+ const lead2 = words5.findIndex((w) => !LEAD.has(w));
10532
+ if (lead2 >= 0 && LEADER.has(words5[lead2]) && !words5.some((w) => HARD.test(w + " ")) && words5.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
10512
10533
  return void 0;
10513
10534
  }
10514
10535
  function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
10515
10536
  return async (heard, signal) => {
10516
10537
  const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
10517
- 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.
10538
+ 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.
10518
10539
  Answer yes (steering) or no (a reaction).`;
10519
10540
  const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
10520
10541
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
@@ -10719,7 +10740,7 @@ function interruptionNote(cut, intent, hold = true) {
10719
10740
  }
10720
10741
  var FRAME = "You are the instinct of a warm, attentive human in a live spoken conversation. Decide what a natural human would do THIS instant \u2014 the way people do without thinking. ";
10721
10742
  var acted = (what, r) => r === false ? `${what}_skipped` : what;
10722
- var words = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
10743
+ var words2 = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
10723
10744
  var Instinct = class {
10724
10745
  constructor(options) {
10725
10746
  this.options = options;
@@ -10764,7 +10785,7 @@ var Instinct = class {
10764
10785
  this.turnStart = 0;
10765
10786
  }
10766
10787
  async consult(heard) {
10767
- if (this.inflight || words(heard) < this.o.minWords) return;
10788
+ if (this.inflight || words2(heard) < this.o.minWords) return;
10768
10789
  this.inflight = true;
10769
10790
  try {
10770
10791
  const now4 = this.o.now();
@@ -10778,7 +10799,7 @@ var Instinct = class {
10778
10799
  interject: "cut in now with a short correction, the word they are reaching for, or an answer"
10779
10800
  });
10780
10801
  if (!d) return;
10781
- if (!this.partial || words(this.partial) - words(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
10802
+ if (!this.partial || words2(this.partial) - words2(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
10782
10803
  const p = d.probabilities, t = this.o.now();
10783
10804
  if (d.choice === "interject" && p.interject >= this.o.interjectMin && t - this.lastInterjectAt > this.o.interjectGapMs) {
10784
10805
  this.lastInterjectAt = t;
@@ -11272,8 +11293,8 @@ function cleanLine(s, lang, maxWords = 6) {
11272
11293
  const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
11273
11294
  const raw = first.replace(LINE_TAG, " ").trim();
11274
11295
  if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
11275
- const words4 = cleanWords(raw, lang, maxWords);
11276
- return words4 && tags ? `${tags} ${words4}` : words4;
11296
+ const words5 = cleanWords(raw, lang, maxWords);
11297
+ return words5 && tags ? `${tags} ${words5}` : words5;
11277
11298
  }
11278
11299
  var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
11279
11300
  var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
@@ -11482,10 +11503,7 @@ function endsMidPhrase(text) {
11482
11503
  if (TRAILING_PREPS.has(last)) return !QUESTION_START.test(t) && !PHRASAL_HOST.has(prev);
11483
11504
  return MID_PHRASE_WORDS.has(last);
11484
11505
  }
11485
- var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11486
- function isClosing(text) {
11487
- return words2(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);
11488
- }
11506
+ var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
11489
11507
  var TurnGateOptions = class {
11490
11508
  holdMs = 1200;
11491
11509
  /** A finished statement (not a question) waits this long for more speech before it is a turn. 0 = sent at once. */
@@ -11617,7 +11635,7 @@ var TurnGate = class {
11617
11635
  }
11618
11636
  refinal(last, t, key, sttId) {
11619
11637
  if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
11620
- const a = words2(last.text), b = words2(t);
11638
+ const a = words3(last.text), b = words3(t);
11621
11639
  let i = 0;
11622
11640
  while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
11623
11641
  const extra = b.slice(i).join(" ");
@@ -11664,8 +11682,8 @@ function isFalseStart(sentence) {
11664
11682
  return !!m && !/^(?:h+m+|u+m+|u+h+|o+h+|a+h+|well|so|er+m*)$/i.test(m[1]);
11665
11683
  }
11666
11684
  function wordOverlap(sentence, prior) {
11667
- const words4 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11668
- const have = new Set(words4(prior)), ws = words4(sentence);
11685
+ const words5 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
11686
+ const have = new Set(words5(prior)), ws = words5(sentence);
11669
11687
  return ws.length ? ws.filter((w) => have.has(w)).length / ws.length : 0;
11670
11688
  }
11671
11689
  var DuplexAgentOptions = class {
@@ -14236,8 +14254,8 @@ var ConvoTree = class {
14236
14254
  this.from = heardWords;
14237
14255
  }
14238
14256
  /** Posterior of a node after seeing its cue. */
14239
- confidence(p, words4) {
14240
- const l = p * (words4 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
14257
+ confidence(p, words5) {
14258
+ const l = p * (words5 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
14241
14259
  return l / (l + 1 - p);
14242
14260
  }
14243
14261
  /** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
@@ -14722,10 +14740,10 @@ var SecondChannelOptions = class {
14722
14740
  now = () => performance.now();
14723
14741
  random = Math.random;
14724
14742
  };
14725
- var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14743
+ var words4 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14726
14744
  var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
14727
14745
  var onlyHesitation = (s) => {
14728
- const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14746
+ const w = words4(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14729
14747
  return !!w.length && w.every((x) => HESITATION.test(x));
14730
14748
  };
14731
14749
  function withBudget(p, ms, what, ac) {
@@ -14891,7 +14909,7 @@ var SecondChannel = class {
14891
14909
  if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
14892
14910
  if (!this.tree.empty) {
14893
14911
  this.treeStep(t);
14894
- if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
14912
+ if (!this.regrown && words4(t).length >= this.o.regrowAtWords) {
14895
14913
  this.regrown = true;
14896
14914
  this.requestTree(t);
14897
14915
  }
@@ -14904,7 +14922,7 @@ var SecondChannel = class {
14904
14922
  }
14905
14923
  }
14906
14924
  if (this.o.anticipate && !this.tree) {
14907
- const n = words3(t).length;
14925
+ const n = words4(t).length;
14908
14926
  if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
14909
14927
  else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
14910
14928
  this.revised = true;
@@ -14917,7 +14935,7 @@ var SecondChannel = class {
14917
14935
  this.bcTimer = null;
14918
14936
  if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
14919
14937
  }, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
14920
- if (words3(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14938
+ if (words4(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
14921
14939
  }
14922
14940
  /** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
14923
14941
  onPause(ms) {
@@ -15012,7 +15030,7 @@ var SecondChannel = class {
15012
15030
  this.heard = text.trim();
15013
15031
  this.said = (heardCut ?? this.reply).trim();
15014
15032
  this.lastWordAgo = Math.max(0, lastWordAgoMs);
15015
- this.floorWords = this.carried + words3(this.heard).length;
15033
+ this.floorWords = this.carried + words4(this.heard).length;
15016
15034
  this.lastUser = this.heard;
15017
15035
  this.detect(this.heard);
15018
15036
  this.main = "idle";
@@ -15071,7 +15089,7 @@ var SecondChannel = class {
15071
15089
  return this.main === "first_audio" || this.main === "speaking";
15072
15090
  }
15073
15091
  tail() {
15074
- return words3(this.heard).slice(-this.o.microWords).join(" ");
15092
+ return words4(this.heard).slice(-this.o.microWords).join(" ");
15075
15093
  }
15076
15094
  /** Hard gates every line passes, whoever proposed it. */
15077
15095
  allowed(k) {
@@ -15090,7 +15108,7 @@ var SecondChannel = class {
15090
15108
  }
15091
15109
  /** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
15092
15110
  bridgeBlock() {
15093
- const w = words3(this.heard), intent = turnIntent(this.heard);
15111
+ const w = words4(this.heard), intent = turnIntent(this.heard);
15094
15112
  if (!this.lang) return "language unknown";
15095
15113
  if (this.ownWords) return this.blocked("bridge");
15096
15114
  if (intent === "closer") return "no answer due";
@@ -15113,7 +15131,7 @@ var SecondChannel = class {
15113
15131
  }
15114
15132
  /** 0ms rule: the candidate line for this trigger, or silence. */
15115
15133
  rule(trigger, pauseMs = 0, breath = false, cue = null) {
15116
- const w = words3(this.heard);
15134
+ const w = words4(this.heard);
15117
15135
  if (!this.lang) return "silence";
15118
15136
  if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
15119
15137
  if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
@@ -15128,7 +15146,7 @@ var SecondChannel = class {
15128
15146
  this.planning = true;
15129
15147
  this.planTries++;
15130
15148
  }
15131
- const ctx = { agent: this.reply.trim(), user: words3(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
15149
+ const ctx = { agent: this.reply.trim(), user: words4(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
15132
15150
  void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
15133
15151
  if (p === null) ac.abort();
15134
15152
  if (turn !== this.turnNo) return;
@@ -15150,7 +15168,7 @@ var SecondChannel = class {
15150
15168
  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 } : {} };
15151
15169
  const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
15152
15170
  void this.o.grow(ctx, ac.signal).then((r) => {
15153
- if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
15171
+ if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words4(this.heard).length : 0);
15154
15172
  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 } : {} });
15155
15173
  }, (e) => {
15156
15174
  log30.warn(`tree failed: ${e?.message ?? e}`);
@@ -15166,10 +15184,10 @@ var SecondChannel = class {
15166
15184
  if (!hit) return;
15167
15185
  if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
15168
15186
  if (this.leafTimer) clearTimeout(this.leafTimer);
15169
- const at = words3(t).length;
15187
+ const at = words4(t).length;
15170
15188
  this.leafTimer = setTimeout(() => {
15171
15189
  this.leafTimer = null;
15172
- if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
15190
+ if (this.userSpeaking && words4(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
15173
15191
  }, this.o.cuePauseMs);
15174
15192
  }
15175
15193
  /** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
@@ -15179,14 +15197,14 @@ var SecondChannel = class {
15179
15197
  if (!this.o.pickLeaf || !this.o.aec) return;
15180
15198
  this.breathTimer = setTimeout(() => {
15181
15199
  this.breathTimer = null;
15182
- const n = words3(t).length, tree = this.tree;
15200
+ const n = words4(t).length, tree = this.tree;
15183
15201
  if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
15184
15202
  this.picking = true;
15185
15203
  const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
15186
15204
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
15187
15205
  this.picking = false;
15188
15206
  const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
15189
- if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
15207
+ if (!hit || !this.userSpeaking || words4(this.heard).length - n >= this.o.leafStaleWords) return;
15190
15208
  tree.take(hit.node, hit.conf);
15191
15209
  this.playLeaf(hit, "interim", "backchannel");
15192
15210
  });
@@ -15256,7 +15274,7 @@ var SecondChannel = class {
15256
15274
  if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
15257
15275
  return;
15258
15276
  }
15259
- const n0 = words3(this.heard).length;
15277
+ const n0 = words4(this.heard).length;
15260
15278
  this.decidedAt = n0;
15261
15279
  if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
15262
15280
  const opts = this.options;
@@ -15272,7 +15290,7 @@ var SecondChannel = class {
15272
15290
  this.busy = true;
15273
15291
  const gen = this.gen, t0 = this.o.now();
15274
15292
  const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
15275
- const stale = () => gen !== this.gen || words3(this.heard).length - n0 >= this.o.staleWords;
15293
+ const stale = () => gen !== this.gen || words4(this.heard).length - n0 >= this.o.staleWords;
15276
15294
  try {
15277
15295
  let kind = rule;
15278
15296
  let choice;
@@ -15292,7 +15310,7 @@ var SecondChannel = class {
15292
15310
  if (stale()) return ev({ choice, kind, text, acted: "stale" });
15293
15311
  if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
15294
15312
  const said = this.say(kind, text);
15295
- if (said && cue) this.cueFrom = words3(this.heard).length;
15313
+ if (said && cue) this.cueFrom = words4(this.heard).length;
15296
15314
  if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
15297
15315
  ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
15298
15316
  } finally {
@@ -15318,7 +15336,7 @@ var SecondChannel = class {
15318
15336
  this.noLine = "";
15319
15337
  if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
15320
15338
  const gen = this.gen, ac = new AbortController(), own = this.ownWords;
15321
- const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15339
+ const said = own ? words4(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
15322
15340
  const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
15323
15341
  log30.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
15324
15342
  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) => {
@@ -15386,8 +15404,8 @@ var SecondChannel = class {
15386
15404
  if (kind === "bridge") this.bridged = true;
15387
15405
  this.recent = [...this.recent, text].slice(-this.o.avoidLines);
15388
15406
  this.live = lineWords(text);
15389
- const words4 = this.live;
15390
- if (words4) this.o.show(words4, kind);
15407
+ const words5 = this.live;
15408
+ if (words5) this.o.show(words5, kind);
15391
15409
  const p = Promise.resolve(r).then(() => {
15392
15410
  }, (e) => {
15393
15411
  log30.warn(`channel line playback failed: ${e?.message ?? e}`);
@@ -15504,6 +15522,9 @@ var VoiceCallOptions = class {
15504
15522
  /** Stop the in-flight fill line now (barge-in only). */
15505
15523
  cancel = () => {
15506
15524
  };
15525
+ /** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
15526
+ cutAudio = () => {
15527
+ };
15507
15528
  /** Host caption — never history. */
15508
15529
  show = () => {
15509
15530
  };
@@ -15972,6 +15993,11 @@ var VoiceCall = class {
15972
15993
  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;
15973
15994
  this.gate.replyStarted(c.id);
15974
15995
  const end = mv.kind === "say" && !!mv.end;
15996
+ if (end) try {
15997
+ this.o.cutAudio();
15998
+ } catch (e) {
15999
+ log31.warn(`cutAudio threw: ${e.message}`);
16000
+ }
15975
16001
  const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
15976
16002
  if (!played && !end) return this.close(c, "silent");
15977
16003
  if (played) this.o.show(said, "reply");
@@ -17580,8 +17606,8 @@ var CutInAbsorber = class {
17580
17606
  const cut = this.cut || (meta?.supersedes !== void 0 && meta.supersedes === this.absorbed?.text ? this.absorbed.cut : "");
17581
17607
  this.cut = "";
17582
17608
  this.absorbed = void 0;
17583
- const words4 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
17584
- if (!cut || words4(text) - words4(cut) >= 3) return false;
17609
+ const words5 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
17610
+ if (!cut || words5(text) - words5(cut) >= 3) return false;
17585
17611
  this.absorbed = { text, cut };
17586
17612
  return true;
17587
17613
  }
@@ -17765,6 +17791,9 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
17765
17791
  };
17766
17792
  call.options.cancel = () => {
17767
17793
  };
17794
+ call.options.cutAudio = () => {
17795
+ if (v.audible) v.interrupt();
17796
+ };
17768
17797
  }
17769
17798
  function keepHeard(transcript, cut) {
17770
17799
  const full = cut.full.trim(), heard = cut.heard.trim();
@@ -17935,10 +17964,12 @@ function fakeVoiceParts(uttFile) {
17935
17964
  function fakeTape(heardFile, saidFile) {
17936
17965
  const CHAR = TTS_SAMPLE_RATE * 2 / 15;
17937
17966
  const makeTts = () => {
17967
+ let at = 0;
17938
17968
  const t = {
17939
17969
  connect() {
17940
17970
  },
17941
17971
  newContext() {
17972
+ at = 0;
17942
17973
  },
17943
17974
  cancel() {
17944
17975
  },
@@ -17950,6 +17981,13 @@ function fakeTape(heardFile, saidFile) {
17950
17981
  },
17951
17982
  speak(text, more = true) {
17952
17983
  if (saidFile) appendFileSync(saidFile, JSON.stringify({ t: Date.now(), speak: text }) + "\n");
17984
+ const words5 = [], start = [];
17985
+ for (const m of text.matchAll(/\S+/g)) {
17986
+ words5.push(m[0]);
17987
+ start.push((at + m.index) / 15);
17988
+ }
17989
+ at += text.length;
17990
+ if (t.wantTimestamps && words5.length) setTimeout(() => t.onTimestamps?.(words5, start), 5);
17953
17991
  const pcm = new Uint8Array(text.length * CHAR), v = new DataView(pcm.buffer);
17954
17992
  for (let i = 0; i < text.length; i++) for (let b = 0; b < CHAR; b += 2) v.setUint16(i * CHAR + b, text.charCodeAt(i), true);
17955
17993
  setTimeout(() => {
@@ -18198,7 +18236,7 @@ function quickMove(raw, c) {
18198
18236
  }
18199
18237
  if (isClosing(c.heard) && (!mv || mv.kind === "quiet")) {
18200
18238
  const l = ownLine(BYES[c.lang], c);
18201
- return l ? { kind: "say", line: l } : mv;
18239
+ return l ? { kind: "say", line: l, end: true } : mv;
18202
18240
  }
18203
18241
  return mv;
18204
18242
  }