@livx.cc/agentx 0.99.153 → 0.99.155

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.d.ts CHANGED
@@ -1676,6 +1676,44 @@ declare function makeTaskBatchTool(opts: TaskToolOptions): AgentTool;
1676
1676
  /** Component-scoped logger (libx.js). debug/verbose gated via DEBUG env/localStorage. */
1677
1677
  declare const forComponent: (name: string) => libx_js_src_modules_log.ComponentLogger;
1678
1678
 
1679
+ /**
1680
+ * The quick lane of a live call (#1331): a fast model that OWNS the conversation. Each user turn it either answers
1681
+ * itself (chit-chat, a reaction, a clarification, restating something already said), acknowledges and hands the turn
1682
+ * to the deep lane (MAIN: tools, facts it can't know, real thinking), resumes an answer the user cut, or stays quiet.
1683
+ * It knows only the call's shared history — what the user said and what was said aloud by either lane — so a fact
1684
+ * comes only from the deep lane or from what was already said; `quickMove` enforces it (a line that names a number or
1685
+ * a name the call never held goes to the deep lane instead).
1686
+ */
1687
+
1688
+ interface LaneLine {
1689
+ who: 'user' | 'you';
1690
+ text: string;
1691
+ cut?: boolean;
1692
+ }
1693
+ interface QuickContext {
1694
+ /** The call so far, oldest first (the turn being decided is `heard`, not in here). */
1695
+ history: LaneLine[];
1696
+ /** The user's turn, verbatim from the STT. */
1697
+ heard: string;
1698
+ lang: string;
1699
+ /** The unsaid rest of an answer the user just cut ('' = none). */
1700
+ rest?: string;
1701
+ }
1702
+ type QuickMove = {
1703
+ kind: 'say';
1704
+ line: string;
1705
+ } | {
1706
+ kind: 'deep';
1707
+ ack: string;
1708
+ brief: string;
1709
+ } | {
1710
+ kind: 'resume';
1711
+ line: string;
1712
+ } | {
1713
+ kind: 'quiet';
1714
+ };
1715
+ type QuickDecider = (c: QuickContext, signal: AbortSignal) => Promise<QuickMove | null>;
1716
+
1679
1717
  type Topic = 'board' | 'websearch' | 'page' | 'browser' | 'search' | 'mail' | 'calendar' | 'memory' | 'write' | 'run' | 'read' | 'delegate';
1680
1718
  /** Two phrasings per topic and language (never the same line twice in a call). Hebrew is gendered on the speaker:
1681
1719
  * 'he-f' / 'he-m' follow the voice (ProgressOptions.gender); 'he' (plural present) when the gender is unknown. */
@@ -1736,7 +1774,8 @@ interface WorkContext {
1736
1774
  /** The spoken answer. `stop:` opens it when they called the work off, `work:` when they change or add to it. '' = silence. */
1737
1775
  type WorkReply = (c: WorkContext, signal: AbortSignal) => Promise<string>;
1738
1776
 
1739
- type FillKind = LineKind | 'progress' | 'aside';
1777
+ /** 'ack'/'reply': the quick lane's own words (live with `quick`) — an acknowledgement before the deep lane, or its answer. */
1778
+ type FillKind = LineKind | 'progress' | 'aside' | 'ack' | 'reply';
1740
1779
  /** MAIN's stream as the host forwards it. `id` = the turn (sendTurn's id); absent → the current turn. */
1741
1780
  interface MainEvent {
1742
1781
  type: 'start' | 'text' | 'tool' | 'tool_done' | 'audio' | 'done' | 'error';
@@ -1771,11 +1810,11 @@ interface TurnTimeline {
1771
1810
  end?: 'answered' | 'cut' | 'replaced' | 'silent';
1772
1811
  }
1773
1812
  interface CallMetric {
1774
- name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline';
1813
+ name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane';
1775
1814
  id?: string;
1776
1815
  /** ms from the user's last word (see TurnTimeline) */
1777
1816
  ms?: number;
1778
- by?: 'fill' | 'progress' | 'main';
1817
+ by?: 'fill' | 'progress' | 'main' | 'quick';
1779
1818
  kind?: string;
1780
1819
  text?: string;
1781
1820
  lang?: string | null;
@@ -1801,12 +1840,24 @@ declare class VoiceCallOptions {
1801
1840
  /** Writes that immediate answer (fastWorkReply). */
1802
1841
  workReply?: WorkReply;
1803
1842
  workReplyBudgetMs: number;
1843
+ /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
1844
+ * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
1845
+ quick?: QuickDecider;
1846
+ /** Past this the turn goes to MAIN as before (the bridge covers it). */
1847
+ quickBudgetMs: number;
1848
+ /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
1849
+ cutRest?: () => string | null;
1850
+ /** A resume said that rest: the host drops the cut (MAIN's history keeps the whole reply). */
1851
+ dropCut?: () => void;
1804
1852
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
1805
1853
  speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
1806
1854
  /** Stop the in-flight fill line now (barge-in only). */
1807
1855
  cancel: () => void;
1808
1856
  /** Host caption — never history. */
1809
1857
  show: (text: string, kind: FillKind) => void;
1858
+ /** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
1859
+ * turn the quick lane answered, `aside` = said while MAIN worked, `kept` = a soft barge-in kept over the reply. */
1860
+ userLine: (text: string, how: 'quick' | 'aside' | 'kept') => void;
1810
1861
  /** The fast model (lines, banks, progress) — used only with `ai`. */
1811
1862
  fastModel: string;
1812
1863
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
@@ -1854,6 +1905,10 @@ declare class VoiceCall {
1854
1905
  private progressTimer;
1855
1906
  private lastUserAt;
1856
1907
  private ended;
1908
+ /** The call as both lanes know it: the user's turns and what was said aloud (quick lines, MAIN's heard replies). */
1909
+ readonly history: LaneLine[];
1910
+ private cutRest;
1911
+ private cutTurn?;
1857
1912
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1858
1913
  private get o();
1859
1914
  /** The language the fill channel speaks right now (null = unknown → silent). */
@@ -1895,6 +1950,12 @@ declare class VoiceCall {
1895
1950
  private giveWay;
1896
1951
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
1897
1952
  overlap(text: string): Promise<OverlapVerdict>;
1953
+ /** An overlap kept over the reply (no turn): the transcript and the quick lane's history still hold their words — once,
1954
+ * in full: the host asks about every growing partial ("Oh," "Oh, wow" "Oh, wow—really?"; Para replay showed all four). */
1955
+ kept(text: string): void;
1956
+ private keptLine?;
1957
+ /** The kept words go to the transcript; `turn` = the words a new turn starts with (they grew into it: no line of their own). */
1958
+ private flushKept;
1898
1959
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
1899
1960
  * while the reply is held, then resumes the same reply (bod-voice decideOverlap's aside). ≤4 canned words, never a
1900
1961
  * claim, the cue's language; null = stay quiet (a plain listener cue, too soon after the last, or no line). It is a
@@ -1908,7 +1969,18 @@ declare class VoiceCall {
1908
1969
  /** Follow the user's language from their own words: a confident detection, else the current language if the words
1909
1970
  * fit it, else unknown (silent). Pinned into the channel so its own detection never diverges. */
1910
1971
  private follow;
1972
+ private get quickOn();
1911
1973
  private onTurn;
1974
+ /** A MAIN reply cut while it played: the history keeps the part heard; a resume may say the rest. */
1975
+ private logCut;
1976
+ private logReply;
1977
+ /** The quick lane owns this turn: it answers, acks and hands it to MAIN, resumes a cut answer, or stays quiet. A late
1978
+ * or unusable decision hands the turn to MAIN as before (the fill channel's bridge covers it). */
1979
+ private quickTurn;
1980
+ /** The quick lane's answer became audible at `at`: the turn's first word, and it is answered. */
1981
+ private quickWorded;
1982
+ /** say(), retried while the host's player is busy (up to 2s). */
1983
+ private sayRetry;
1912
1984
  private onDrop;
1913
1985
  /** Every fill/progress line passes here: only in the turn's known language, never after the call ended. */
1914
1986
  private say;
package/dist/index.js CHANGED
@@ -7791,6 +7791,7 @@ function heardPrefix(text, spoken, lookahead = 4) {
7791
7791
  }
7792
7792
  return at;
7793
7793
  }
7794
+ var ECHO_RECENT_SEC = 1.8;
7794
7795
  var NumberedSpeakers = class {
7795
7796
  ids = /* @__PURE__ */ new Map();
7796
7797
  name(label) {
@@ -8063,6 +8064,10 @@ var VoiceEngine = class _VoiceEngine {
8063
8064
  drainTimer = null;
8064
8065
  // heuristic tier state (inert under AEC) — frozen as validated in the experiment
8065
8066
  echoWords = /* @__PURE__ */ new Set();
8067
+ /** Our words audible when this utterance's first partial came (undefined = no partial yet, null = no word timestamps). */
8068
+ uttEcho;
8069
+ /** The words of the line before this turn: its audio may still be playing ahead of this turn's first word. */
8070
+ lineBefore = /* @__PURE__ */ new Set();
8066
8071
  prevReply = "";
8067
8072
  reply = "";
8068
8073
  echoUntil = 0;
@@ -8319,6 +8324,7 @@ var VoiceEngine = class _VoiceEngine {
8319
8324
  if (this.options.revealMode === "word") this.startWordReveal();
8320
8325
  this.emo = this.options.emotions ? new EmotionStream(this.options.showEmotions) : null;
8321
8326
  this.echoWords = new Set(this.words(this.prevReply));
8327
+ this.lineBefore = new Set(this.echoWords);
8322
8328
  this.tts.newContext();
8323
8329
  this.clause = "";
8324
8330
  this.clearAckTimer("new_turn");
@@ -8807,6 +8813,18 @@ var VoiceEngine = class _VoiceEngine {
8807
8813
  this.diag("echo_head", { dropped: toks.slice(0, i).join(" ").slice(0, 60) });
8808
8814
  return toks.slice(i).join(" ");
8809
8815
  }
8816
+ /** Our words whose audio played in the last ECHO_RECENT_SEC (+ the ack just said) — what an echo can be made of right
8817
+ * now. null = no word timestamps (the bag rule judges alone). */
8818
+ audibleWords() {
8819
+ if (!this.echoActive() || !this.wordStarts.length) return null;
8820
+ const now3 = this.player.playedMs() / 1e3, out = /* @__PURE__ */ new Set();
8821
+ this.wordStarts.forEach((s, i) => {
8822
+ if (s <= now3 + 0.3 && s >= now3 - ECHO_RECENT_SEC) for (const w of this.words(this.wordTexts[i] ?? "")) out.add(w);
8823
+ });
8824
+ if (now3 < this.wordStarts[0] + ECHO_RECENT_SEC) for (const w of this.lineBefore) out.add(w);
8825
+ if (this.ackAt && this.clock.now() - this.ackAt < 3e3) for (const w of this.words(this.lastAck)) out.add(w);
8826
+ return out;
8827
+ }
8810
8828
  novelWords(text) {
8811
8829
  return this.words(text).filter((w) => !this.echoWords.has(w));
8812
8830
  }
@@ -8833,10 +8851,10 @@ var VoiceEngine = class _VoiceEngine {
8833
8851
  * of our last words in their own sentence is neither: live 20261103-114604, over "…Want me to open the thread?" the
8834
8852
  * user's "You can't open the thread?" (3 of 5 in line) was swallowed and they had to say it again — the old rule
8835
8853
  * (half the words in a word pair we said) counted it as echo. Shorter finals can't show order → bag rule. */
8836
- echoFinal(text) {
8854
+ echoFinal(text, audible = null) {
8837
8855
  if (this.genuine(text)) return false;
8838
8856
  const w = this.words(text);
8839
- if (w.length < 4) return true;
8857
+ if (w.length < 4) return audible ? w.every((x) => audible.has(x)) : true;
8840
8858
  const said = this.words(`${this.prevReply} ${this.reply} ${this.lastAck}`);
8841
8859
  const span = w.length + 2;
8842
8860
  let best = 0, run = 0;
@@ -8878,6 +8896,7 @@ var VoiceEngine = class _VoiceEngine {
8878
8896
  return w.length === 1 && d.length > 0 && this.clock.now() - this.lastDispatchAt < _VoiceEngine.DUP_FINAL_MS && d[d.length - 1].startsWith(w[0]);
8879
8897
  }
8880
8898
  handlePartial(text) {
8899
+ if (text.trim() && !this.uttEcho) this.uttEcho = { at: this.clock.now(), words: this.audibleWords() };
8881
8900
  if (this.speaking) {
8882
8901
  if (!this.options.bargeIn) return;
8883
8902
  if (this.clock.now() < this.bargeGraceUntil) {
@@ -9301,6 +9320,9 @@ var VoiceEngine = class _VoiceEngine {
9301
9320
  }
9302
9321
  handleUtterance(text, langs, rawTurns) {
9303
9322
  let turns;
9323
+ const cap = this.uttEcho;
9324
+ this.uttEcho = void 0;
9325
+ const audible = cap && this.clock.now() - cap.at < 15e3 ? cap.words : null;
9304
9326
  if (this.echoHead) {
9305
9327
  this.echoHead = false;
9306
9328
  text = this.dropEchoHead(text);
@@ -9335,7 +9357,7 @@ var VoiceEngine = class _VoiceEngine {
9335
9357
  this.stt.reset();
9336
9358
  return;
9337
9359
  }
9338
- if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text) : this.novelWords(text).length < 2))) {
9360
+ if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
9339
9361
  this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
9340
9362
  this.stt.reset();
9341
9363
  return;
@@ -10456,11 +10478,16 @@ function cueKind(text) {
10456
10478
  return r.split(" ").some((w) => AGREE.has(w)) ? "agree" : null;
10457
10479
  }
10458
10480
  var ASIDES = {
10459
- en: { agree: ["Oh yeah, definitely.", "Yeah, exactly.", "Right, yeah."], continue: [] },
10460
- he: { agree: ["\u05DB\u05DF, \u05D1\u05D3\u05D9\u05D5\u05E7.", "\u05DB\u05DF, \u05DE\u05DE\u05E9.", "\u05E0\u05DB\u05D5\u05DF, \u05DB\u05DF."], continue: [] }
10481
+ en: { agree: ["Oh yeah, definitely.", "Yeah, exactly.", "Right, yeah."], continue: [], react: ["I know, right?", "Right? Wild.", "Yeah, crazy, right?"] },
10482
+ he: { agree: ["\u05DB\u05DF, \u05D1\u05D3\u05D9\u05D5\u05E7.", "\u05DB\u05DF, \u05DE\u05DE\u05E9.", "\u05E0\u05DB\u05D5\u05DF, \u05DB\u05DF."], continue: [], react: ["\u05E0\u05DB\u05D5\u05DF? \u05DE\u05D8\u05D5\u05E8\u05E3.", "\u05DB\u05DF, \u05DE\u05D8\u05D5\u05E8\u05E3.", "\u05DE\u05D8\u05D5\u05E8\u05E3, \u05E0\u05DB\u05D5\u05DF?"] }
10483
+ };
10484
+ var REACT = /^(?:(?:oh|and|so|wait|but|ok|okay|yeah)\s+)*(?:wow|whoa|woah|really|seriously|no way|oh my god|omg|crazy|insane|amazing|unbelievable|what|are you serious|you're kidding|וואו|באמת|מה|מטורף|רצינית?|לא נכון)(?:\s+(?:wow|really|seriously|that's crazy|that's wild|no way|באמת|וואו))*$/u;
10485
+ var isReaction = (text) => {
10486
+ const t = norm2(text);
10487
+ return REACT.test(t) || new RegExp("\\s\\p{L}{1,3}$", "u").test(t) && REACT.test(t.replace(new RegExp("\\s\\p{L}{1,3}$", "u"), ""));
10461
10488
  };
10462
- function overlapAside(text, lang, avoid = "", pick = (n) => Math.floor(Math.random() * n)) {
10463
- const kind = cueKind(text);
10489
+ function overlapAside(text, lang, avoid = "", pick = (n) => Math.floor(Math.random() * n), react = false) {
10490
+ const kind = react && REACT.test(norm2(text)) ? "react" : cueKind(text);
10464
10491
  const l = new RegExp("\\p{Script=Hebrew}", "u").test(text) ? "he" : /[a-z]/i.test(text) ? "en" : lang;
10465
10492
  const pool = kind && l ? ASIDES[l]?.[kind] : void 0;
10466
10493
  if (!pool?.length) return null;
@@ -13820,8 +13847,8 @@ var SOFT_CUE = "~";
13820
13847
  var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
13821
13848
  var isContent = (w) => w.length >= 4 && !STOP4.has(w);
13822
13849
  function echoesHeard(line, heard) {
13823
- const said = cueWords(heard).map(stem).filter(echoable);
13824
- return cueWords(lineWords(line)).map(stem).filter(echoable).some((w) => said.some((h) => h === w || Math.min(h.length, w.length) >= 4 && (h.startsWith(w) || w.startsWith(h))));
13850
+ const said = cueWords(heard).filter(echoable).map(stem);
13851
+ return cueWords(lineWords(line)).filter(echoable).map(stem).some((w) => said.some((h) => h === w || Math.min(h.length, w.length) >= 4 && (h.startsWith(w) || w.startsWith(h))));
13825
13852
  }
13826
13853
  var stem = (w) => w.replace(/['’]s$/, "").replace(new RegExp("(?<=\\p{L}{3})s$", "u"), "");
13827
13854
  var SHORT_STOP = new Set("the and you are was for not but has had his her its our who why how can did get got let may one out see she two use way yes all any new now off old own say too him hey huh ooh wow yep".split(" "));
@@ -15044,6 +15071,15 @@ var VoiceCallOptions = class {
15044
15071
  /** Writes that immediate answer (fastWorkReply). */
15045
15072
  workReply;
15046
15073
  workReplyBudgetMs = 1500;
15074
+ /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
15075
+ * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
15076
+ quick;
15077
+ /** Past this the turn goes to MAIN as before (the bridge covers it). */
15078
+ quickBudgetMs = 1800;
15079
+ /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
15080
+ cutRest;
15081
+ /** A resume said that rest: the host drops the cut (MAIN's history keeps the whole reply). */
15082
+ dropCut;
15047
15083
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
15048
15084
  speak = () => false;
15049
15085
  /** Stop the in-flight fill line now (barge-in only). */
@@ -15052,6 +15088,10 @@ var VoiceCallOptions = class {
15052
15088
  /** Host caption — never history. */
15053
15089
  show = () => {
15054
15090
  };
15091
+ /** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
15092
+ * turn the quick lane answered, `aside` = said while MAIN worked, `kept` = a soft barge-in kept over the reply. */
15093
+ userLine = () => {
15094
+ };
15055
15095
  /** The fast model (lines, banks, progress) — used only with `ai`. */
15056
15096
  fastModel = latestClaude("haiku");
15057
15097
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
@@ -15085,6 +15125,7 @@ var VoiceCallOptions = class {
15085
15125
  progressLeadMs = 1e3;
15086
15126
  };
15087
15127
  var VoiceCall = class {
15128
+ // a MAIN reply cut while audible: its heard part goes to the history at the next turn
15088
15129
  constructor(options) {
15089
15130
  this.options = options;
15090
15131
  this.options = { ...new VoiceCallOptions(), ...options };
@@ -15147,6 +15188,11 @@ var VoiceCall = class {
15147
15188
  progressTimer = null;
15148
15189
  lastUserAt = -Infinity;
15149
15190
  ended = false;
15191
+ /** The call as both lanes know it: the user's turns and what was said aloud (quick lines, MAIN's heard replies). */
15192
+ history = [];
15193
+ cutRest = "";
15194
+ // the unsaid rest of the last cut MAIN reply, until the next turn decides it
15195
+ cutTurn;
15150
15196
  get o() {
15151
15197
  return this.options;
15152
15198
  }
@@ -15213,6 +15259,13 @@ var VoiceCall = class {
15213
15259
  if (this.ended) return;
15214
15260
  if (by === "main") return this.main({ type: "audio", ...this.cur ? { id: this.cur.id } : {} }, inMs);
15215
15261
  const at = this.o.now() + Math.max(0, inMs);
15262
+ const q = this.cur;
15263
+ if (q?.quickWord && !q.closed) {
15264
+ this.lastAudibleAt = at;
15265
+ q.marks.fillAudio ??= at;
15266
+ this.sounded(q, "quick", at);
15267
+ return this.quickWorded(q, at);
15268
+ }
15216
15269
  if (this.gate.holding || !this.cur || this.cur.closed) {
15217
15270
  this.earlyHeard ??= { at, by };
15218
15271
  return;
@@ -15242,6 +15295,7 @@ var VoiceCall = class {
15242
15295
  return;
15243
15296
  case "text":
15244
15297
  if (!ev.text) return;
15298
+ c.reply += ev.text;
15245
15299
  c.marks.mainFirst ??= this.o.now();
15246
15300
  c.marks.mainText ??= this.o.now();
15247
15301
  if (!c.streamed) {
@@ -15318,6 +15372,7 @@ var VoiceCall = class {
15318
15372
  } catch (e) {
15319
15373
  log32.warn(`cancel threw: ${e.message}`);
15320
15374
  }
15375
+ if (c?.worded && c.lane === "deep" && !c.cutRead) this.cutTurn = c;
15321
15376
  if (c?.running) {
15322
15377
  c.running = false;
15323
15378
  this.o.abortTurn(c.id);
@@ -15326,10 +15381,44 @@ var VoiceCall = class {
15326
15381
  }
15327
15382
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15328
15383
  async overlap(text) {
15384
+ if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
15329
15385
  const d = await this.judge.judge(text);
15330
15386
  if (d.verdict === "cut") this.barge();
15387
+ else if (d.verdict === "keep") this.kept(text);
15331
15388
  return d.verdict;
15332
15389
  }
15390
+ /** An overlap kept over the reply (no turn): the transcript and the quick lane's history still hold their words — once,
15391
+ * in full: the host asks about every growing partial ("Oh," "Oh, wow" "Oh, wow—really?"; Para replay showed all four). */
15392
+ kept(text) {
15393
+ if (!norm3(text)) return;
15394
+ const p = this.keptLine, a = norm3(text).replace(/ /g, ""), b = p ? norm3(p.text).replace(/ /g, "") : "";
15395
+ if (p && (a.startsWith(b) || b.startsWith(a))) {
15396
+ if (a.length > b.length) {
15397
+ p.text = text;
15398
+ if (p.line) p.line.text = text;
15399
+ }
15400
+ clearTimeout(p.timer);
15401
+ } else {
15402
+ this.flushKept();
15403
+ const line = this.quickOn ? { who: "user", text } : void 0;
15404
+ if (line) this.history.push(line);
15405
+ this.keptLine = { text, timer: void 0, line };
15406
+ }
15407
+ this.keptLine.timer = setTimeout(() => this.flushKept(), isReaction(this.keptLine.text) ? 1500 : 4e3);
15408
+ }
15409
+ keptLine;
15410
+ /** The kept words go to the transcript; `turn` = the words a new turn starts with (they grew into it: no line of their own). */
15411
+ flushKept(turn = "") {
15412
+ const p = this.keptLine;
15413
+ if (!p) return;
15414
+ this.keptLine = void 0;
15415
+ clearTimeout(p.timer);
15416
+ if (turn && norm3(turn).replace(/ /g, "").startsWith(norm3(p.text).replace(/ /g, ""))) {
15417
+ if (p.line) this.history.splice(this.history.indexOf(p.line), 1);
15418
+ return;
15419
+ }
15420
+ this.o.userLine(p.text, "kept");
15421
+ }
15333
15422
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
15334
15423
  * while the reply is held, then resumes the same reply (bod-voice decideOverlap's aside). ≤4 canned words, never a
15335
15424
  * claim, the cue's language; null = stay quiet (a plain listener cue, too soon after the last, or no line). It is a
@@ -15337,9 +15426,10 @@ var VoiceCall = class {
15337
15426
  aside(text) {
15338
15427
  const now3 = this.o.now();
15339
15428
  if (now3 - this.lastAside.at < this.o.asideGapMs) return null;
15340
- const line = overlapAside(text, this.lang, this.lastAside.text);
15429
+ const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
15341
15430
  if (!line) return null;
15342
15431
  this.lastAside = { text: line, at: now3 };
15432
+ if (this.quickOn) this.history.push({ who: "you", text: line });
15343
15433
  this.o.onMetric({ name: "fill", kind: "aside", text: line, lang: this.lang });
15344
15434
  return line;
15345
15435
  }
@@ -15352,6 +15442,7 @@ var VoiceCall = class {
15352
15442
  return this.fill.drain();
15353
15443
  }
15354
15444
  end() {
15445
+ this.flushKept();
15355
15446
  if (this.cur) this.close(this.cur);
15356
15447
  this.ended = true;
15357
15448
  this.gate.end();
@@ -15367,18 +15458,24 @@ var VoiceCall = class {
15367
15458
  this.lang = l;
15368
15459
  if (l) this.fill.setLanguage(l, true);
15369
15460
  }
15461
+ get quickOn() {
15462
+ return this.o.mode === "live" && !!this.o.quick;
15463
+ }
15370
15464
  onTurn(t) {
15371
15465
  this.floor = "";
15466
+ this.flushKept(t.text);
15372
15467
  if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15468
+ const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
15373
15469
  const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
15374
15470
  const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
15375
15471
  const finalAt = this.finalAt || now3;
15376
15472
  this.firstFinalAt = null;
15377
15473
  this.lastWordAt = null;
15378
- if (this.cur) this.close(this.cur, t.replaces === this.cur.id ? "replaced" : void 0);
15474
+ if (this.quickOn) this.logCut();
15475
+ if (prev) this.close(prev, t.replaces === prev.id ? "replaced" : void 0);
15379
15476
  this.follow(t.text);
15380
15477
  this.clearProgress();
15381
- this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: true, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now3 }, closed: false, due: turnIntent(t.text) !== "closer", open: 0, tool: "", draft: "", drafting: false, draftAt: -Infinity };
15478
+ this.cur = { id: t.id, text: t.text, at, finalAt, lastWord, running: !quick, streamed: false, sounded: false, worded: false, done: false, marks: { sent: now3 }, closed: false, due: turnIntent(t.text) !== "closer", open: 0, tool: "", draft: "", drafting: false, draftAt: -Infinity, reply: "", ...this.quickOn ? { lane: quick ? "pending" : "deep" } : {} };
15382
15479
  const early = this.earlyHeard;
15383
15480
  this.earlyHeard = null;
15384
15481
  if (early && early.at >= at) {
@@ -15387,9 +15484,109 @@ var VoiceCall = class {
15387
15484
  }
15388
15485
  this.progress.turn();
15389
15486
  this.o.onMetric({ name: "turn", id: t.id, kind: t.kind, text: t.text });
15390
- this.o.sendTurn(t.text, { id: t.id, ...t.replaces ? { replaces: t.replaces } : {} });
15487
+ if (this.quickOn) {
15488
+ const last = this.history.at(-1);
15489
+ if (t.kind !== "new" && last?.who === "user") last.text = t.text;
15490
+ else this.history.push({ who: "user", text: t.text });
15491
+ }
15492
+ if (quick) return void this.quickTurn(this.cur, t);
15493
+ this.o.sendTurn(t.text, { id: t.id, ...t.replaces && (!this.quickOn || prev?.lane === "deep") ? { replaces: t.replaces } : {} });
15391
15494
  if (t.kind === "new") this.fill.onUserTurn(t.text, now3 - at, this.o.heardCut?.() ?? void 0);
15392
15495
  }
15496
+ /** A MAIN reply cut while it played: the history keeps the part heard; a resume may say the rest. */
15497
+ logCut() {
15498
+ const c = this.cutTurn;
15499
+ this.cutTurn = void 0;
15500
+ if (!c || c.cutRead) return;
15501
+ c.cutRead = true;
15502
+ this.cutRest = "";
15503
+ const heard = this.o.heardCut?.() ?? null;
15504
+ if (heard === null) return void this.logReply(c);
15505
+ if (c.logged) Object.assign(c.logged, { text: heard, cut: true });
15506
+ else this.history.push(c.logged = { who: "you", text: heard, cut: true });
15507
+ this.cutRest = this.o.cutRest?.() ?? "";
15508
+ }
15509
+ logReply(c) {
15510
+ if (c.lane !== "deep" || c.logged || !c.reply.trim()) return;
15511
+ this.history.push(c.logged = { who: "you", text: c.reply.replace(/\[[a-z ]+\]\s*/gi, "").trim() });
15512
+ }
15513
+ /** The quick lane owns this turn: it answers, acks and hands it to MAIN, resumes a cut answer, or stays quiet. A late
15514
+ * or unusable decision hands the turn to MAIN as before (the fill channel's bridge covers it). */
15515
+ async quickTurn(c, t) {
15516
+ const ac = new AbortController(), t0 = this.o.now(), lang = this.lang, rest = this.cutRest;
15517
+ c.ask = ac;
15518
+ const late = setTimeout(() => ac.abort(), this.o.quickBudgetMs);
15519
+ const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest }, ac.signal).catch((e) => {
15520
+ if (this.cur === c) log32.warn(`quick lane ${ac.signal.aborted ? `late (${this.o.quickBudgetMs}ms)` : `failed: ${e?.message ?? e}`} \u2014 deep lane`);
15521
+ return null;
15522
+ }).finally(() => clearTimeout(late)) : null;
15523
+ if (this.ended || this.cur !== c || c.closed) return;
15524
+ c.ask = void 0;
15525
+ this.o.onMetric({ name: "lane", id: c.id, kind: mv?.kind ?? "fallback", ms: Math.round(this.o.now() - t0), ...mv && "line" in mv && mv.line ? { text: mv.line } : mv?.kind === "deep" && mv.ack ? { text: mv.ack } : {} });
15526
+ const note = (n) => this.o.noteTurn?.(`[${n}]`);
15527
+ if (!mv || mv.kind === "deep") {
15528
+ c.lane = "deep";
15529
+ c.running = true;
15530
+ this.cutRest = "";
15531
+ const ack = mv?.kind === "deep" ? mv.ack : "", brief = mv?.kind === "deep" ? mv.brief : "";
15532
+ if (ack) {
15533
+ note(`You (the call's quick voice) already told them aloud: "${ack}". Do not acknowledge again \u2014 start with the answer itself.${brief && brief !== t.text ? ` It took their words to mean: ${brief}.` : ""}`);
15534
+ this.history.push({ who: "you", text: ack });
15535
+ }
15536
+ this.o.sendTurn(t.text, { id: t.id });
15537
+ if (!ack) return void this.fill.onUserTurn(t.text, this.o.now() - c.at, this.o.heardCut?.() ?? void 0);
15538
+ this.gate.replyStarted(c.id);
15539
+ if (await this.sayRetry(ack, "ack", c.id)) {
15540
+ this.o.show(ack, "ack");
15541
+ if (this.cur === c && c.running) this.beat(c);
15542
+ }
15543
+ return;
15544
+ }
15545
+ c.lane = "quick";
15546
+ this.o.userLine(t.text, "quick");
15547
+ if (mv.kind === "quiet") {
15548
+ c.due = false;
15549
+ return this.close(c, "silent");
15550
+ }
15551
+ 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;
15552
+ this.gate.replyStarted(c.id);
15553
+ if (!await this.sayRetry(said, "reply", c.id)) return this.close(c, "silent");
15554
+ this.o.show(said, "reply");
15555
+ if (mv.kind === "resume") {
15556
+ this.cutRest = "";
15557
+ this.o.dropCut?.();
15558
+ this.history.push({ who: "you", text: rest });
15559
+ note(`They asked you to go on, and you continued your cut answer aloud: "${rest}". All of it has now been said.`);
15560
+ } else {
15561
+ this.history.push({ who: "you", text: said });
15562
+ note(`On the call they said "${t.text}" and you (the call's quick voice) answered aloud: "${said}". Already said \u2014 do not repeat it.`);
15563
+ }
15564
+ if (this.o.hostAudio && !c.worded) {
15565
+ c.quickWord = true;
15566
+ return;
15567
+ }
15568
+ this.quickWorded(c, this.lastAudibleAt);
15569
+ }
15570
+ /** The quick lane's answer became audible at `at`: the turn's first word, and it is answered. */
15571
+ quickWorded(c, at) {
15572
+ c.quickWord = false;
15573
+ if (!c.worded) {
15574
+ c.worded = true;
15575
+ c.marks.mainAudio = at;
15576
+ this.o.onMetric({ name: "first_word", id: c.id, ms: Math.round(at - c.at), by: "quick" });
15577
+ }
15578
+ this.close(c, "answered");
15579
+ }
15580
+ /** say(), retried while the host's player is busy (up to 2s). */
15581
+ async sayRetry(line, kind, id) {
15582
+ for (let i = 0; i < 8; i++) {
15583
+ if (this.ended) return false;
15584
+ if (this.say(line, kind) !== false) return true;
15585
+ await new Promise((r) => setTimeout(r, 250));
15586
+ }
15587
+ this.o.onMetric({ name: "drop", id, kind: `${kind} unplayed`, text: line });
15588
+ return false;
15589
+ }
15393
15590
  onDrop(text, why) {
15394
15591
  if (!this.gate.holding) {
15395
15592
  this.firstFinalAt = null;
@@ -15413,7 +15610,7 @@ var VoiceCall = class {
15413
15610
  this.o.onMetric({ name: "fill", kind, text, lang: this.lang });
15414
15611
  if (kind !== "backchannel") this.progress.heard();
15415
15612
  const c = this.cur && !this.cur.closed ? this.cur : void 0;
15416
- const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "filler" && c.running && !c.sounded);
15613
+ const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "ack" || kind === "reply" || kind === "filler" && c.running && !c.sounded);
15417
15614
  if (c && forTurn && c.marks.fill === void 0) {
15418
15615
  c.marks.fill = this.o.now();
15419
15616
  c.fillKind = kind;
@@ -15423,7 +15620,7 @@ var VoiceCall = class {
15423
15620
  this.lastAudibleAt = this.o.now();
15424
15621
  if (c && forTurn) {
15425
15622
  c.marks.fillAudio ??= this.o.now();
15426
- this.sounded(c, kind === "progress" ? "progress" : "fill");
15623
+ this.sounded(c, kind === "progress" ? "progress" : kind === "ack" || kind === "reply" ? "quick" : "fill");
15427
15624
  }
15428
15625
  return r;
15429
15626
  }
@@ -15437,6 +15634,8 @@ var VoiceCall = class {
15437
15634
  close(c, end) {
15438
15635
  if (c.closed) return;
15439
15636
  c.closed = true;
15637
+ c.ask?.abort();
15638
+ this.logReply(c);
15440
15639
  c.end = c.worded ? "answered" : end ?? c.end ?? "silent";
15441
15640
  if (!c.worded) this.o.onMetric({ name: "first_word", id: c.id, by: "main", kind: c.end });
15442
15641
  const rel = (t) => t === void 0 ? void 0 : Math.round(t - c.at);
@@ -15473,17 +15672,14 @@ var VoiceCall = class {
15473
15672
  const line = own || (this.o.mode === "live" ? "" : answer);
15474
15673
  const stop = /^\s*stop\s*:/i.test(raw), change = !answer || /^\s*work\s*:/i.test(raw);
15475
15674
  const noted = `[The user said this on the call while you worked: "${t.text}".${line ? ` You answered aloud: "${line}".` : ""}${stop ? " That stopped the work." : ""} Take it into account; do not answer it again.]`;
15675
+ this.history.push({ who: "user", text: t.text });
15676
+ if (!change) this.o.userLine(t.text, "aside");
15476
15677
  if (line && !this.ended) {
15477
- for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
15478
- if (i === 7) {
15479
- this.o.onMetric({ name: "drop", id: t.id, kind: "aside unplayed", text: line });
15480
- break;
15481
- }
15482
- await new Promise((r) => setTimeout(r, 250));
15483
- }
15678
+ await this.sayRetry(line, "aside", t.id);
15484
15679
  if (this.lastAudibleAt >= at) {
15485
15680
  this.progress.note(line);
15486
15681
  this.o.show(line, "aside");
15682
+ this.history.push({ who: "you", text: line });
15487
15683
  }
15488
15684
  } else if (!line) this.o.onMetric({ name: "drop", id: t.id, kind: "no aside line" });
15489
15685
  if (stop) {
@@ -15538,6 +15734,12 @@ var VoiceCall = class {
15538
15734
  }
15539
15735
  }
15540
15736
  };
15737
+ function cutSentence(heard) {
15738
+ const tail = heard.trim().split(/(?<=[.!?…])\s+/).at(-1) ?? "";
15739
+ if (!tail || /[.!?…]["'”’)]*$/.test(tail)) return "";
15740
+ const w = tail.split(/\s+/);
15741
+ return w.length <= 6 ? tail : w.slice(-3).join(" ");
15742
+ }
15541
15743
 
15542
15744
  // src/index.ts
15543
15745
  init_llm();