@livx.cc/agentx 0.99.154 → 0.99.156

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
@@ -1699,9 +1699,12 @@ interface QuickContext {
1699
1699
  /** The unsaid rest of an answer the user just cut ('' = none). */
1700
1700
  rest?: string;
1701
1701
  }
1702
- type QuickMove = {
1702
+ type QuickMove =
1703
+ /** `end`: a farewell to someone ending the call — the host hangs up once it has played. */
1704
+ {
1703
1705
  kind: 'say';
1704
1706
  line: string;
1707
+ end?: true;
1705
1708
  } | {
1706
1709
  kind: 'deep';
1707
1710
  ack: string;
@@ -1810,7 +1813,7 @@ interface TurnTimeline {
1810
1813
  end?: 'answered' | 'cut' | 'replaced' | 'silent';
1811
1814
  }
1812
1815
  interface CallMetric {
1813
- name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane';
1816
+ name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup';
1814
1817
  id?: string;
1815
1818
  /** ms from the user's last word (see TurnTimeline) */
1816
1819
  ms?: number;
@@ -1843,6 +1846,9 @@ declare class VoiceCallOptions {
1843
1846
  /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
1844
1847
  * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
1845
1848
  quick?: QuickDecider;
1849
+ /** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
1850
+ * played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
1851
+ hangUp?: () => void;
1846
1852
  /** Past this the turn goes to MAIN as before (the bridge covers it). */
1847
1853
  quickBudgetMs: number;
1848
1854
  /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
@@ -1855,6 +1861,9 @@ declare class VoiceCallOptions {
1855
1861
  cancel: () => void;
1856
1862
  /** Host caption — never history. */
1857
1863
  show: (text: string, kind: FillKind) => void;
1864
+ /** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
1865
+ * turn the quick lane answered, `aside` = said while MAIN worked, `kept` = a soft barge-in kept over the reply. */
1866
+ userLine: (text: string, how: 'quick' | 'aside' | 'kept') => void;
1858
1867
  /** The fast model (lines, banks, progress) — used only with `ai`. */
1859
1868
  fastModel: string;
1860
1869
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
@@ -1947,6 +1956,12 @@ declare class VoiceCall {
1947
1956
  private giveWay;
1948
1957
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
1949
1958
  overlap(text: string): Promise<OverlapVerdict>;
1959
+ /** An overlap kept over the reply (no turn): the transcript and the quick lane's history still hold their words — once,
1960
+ * in full: the host asks about every growing partial ("Oh," "Oh, wow" "Oh, wow—really?"; Para replay showed all four). */
1961
+ kept(text: string): void;
1962
+ private keptLine?;
1963
+ /** The kept words go to the transcript; `turn` = the words a new turn starts with (they grew into it: no line of their own). */
1964
+ private flushKept;
1950
1965
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
1951
1966
  * while the reply is held, then resumes the same reply (bod-voice decideOverlap's aside). ≤4 canned words, never a
1952
1967
  * claim, the cue's language; null = stay quiet (a plain listener cue, too soon after the last, or no line). It is a
@@ -1968,7 +1983,9 @@ declare class VoiceCall {
1968
1983
  /** The quick lane owns this turn: it answers, acks and hands it to MAIN, resumes a cut answer, or stays quiet. A late
1969
1984
  * or unusable decision hands the turn to MAIN as before (the fill channel's bridge covers it). */
1970
1985
  private quickTurn;
1971
- /** say(), retried while the host's player is busy (up to 2s). */
1986
+ /** The quick lane's answer became audible at `at`: the turn's first word, and it is answered. */
1987
+ private quickWorded;
1988
+ /** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
1972
1989
  private sayRetry;
1973
1990
  private onDrop;
1974
1991
  /** Every fill/progress line passes here: only in the turn's known language, never after the call ended. */
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;
@@ -10460,7 +10482,10 @@ var ASIDES = {
10460
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?"] }
10461
10483
  };
10462
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;
10463
- var isReaction = (text) => REACT.test(norm2(text));
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"), ""));
10488
+ };
10464
10489
  function overlapAside(text, lang, avoid = "", pick = (n) => Math.floor(Math.random() * n), react = false) {
10465
10490
  const kind = react && REACT.test(norm2(text)) ? "react" : cueKind(text);
10466
10491
  const l = new RegExp("\\p{Script=Hebrew}", "u").test(text) ? "he" : /[a-z]/i.test(text) ? "en" : lang;
@@ -14021,9 +14046,17 @@ var ProgressOptions = class {
14021
14046
  now = () => performance.now();
14022
14047
  };
14023
14048
  function argsHint(args) {
14024
- if (!args || typeof args !== "object") return typeof args === "string" ? args.slice(0, 40) : "";
14025
- const s = Object.values(args).find((v) => typeof v === "string" && v.trim());
14026
- return typeof s === "string" ? s.trim().replace(/\s+/g, " ").slice(0, 40) : "";
14049
+ const s = !args || typeof args !== "object" ? args : Object.values(args).find((v) => typeof v === "string" && v.trim());
14050
+ return typeof s === "string" ? urlWords(s.trim()).replace(/\s+/g, " ").slice(0, 40).trim() : "";
14051
+ }
14052
+ function urlWords(s) {
14053
+ if (!/^https?:\/\/\S+$/i.test(s)) return s;
14054
+ try {
14055
+ const u = new URL(s), host = u.hostname.replace(/^www\./, "").split(".").slice(0, -1).filter((p) => p.length > 2);
14056
+ return [...host, ...decodeURIComponent(u.pathname).split(/[/._-]+/)].filter((w) => new RegExp("\\p{L}{2}", "u").test(w) && !/^(?:html?|php|aspx?|index)$/i.test(w)).join(" ");
14057
+ } catch {
14058
+ return s;
14059
+ }
14027
14060
  }
14028
14061
  var Progress = class {
14029
14062
  constructor(options) {
@@ -14106,13 +14139,17 @@ var Progress = class {
14106
14139
  return null;
14107
14140
  }), late]).finally(() => clearTimeout(t));
14108
14141
  const l = cleanLine(raw ?? "", lang, 5);
14109
- if (!l || about && !echoesHeard(l, hint) || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
14142
+ const why = raw === null ? "late or failed" : !l ? `unusable "${raw}"` : about && !echoesHeard(l, `${hint} ${about}`) ? `names nothing of "${hint}": "${l}"` : RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? `claims a result: "${l}"` : this.said.has(norm3(l)) ? `repeat: "${l}"` : this.streamed ? "reply streamed" : "";
14143
+ if (why) {
14144
+ log30.debug(`no line for ${tool || "(no tool)"}: ${why}`);
14145
+ return "";
14146
+ }
14110
14147
  return l;
14111
14148
  }
14112
14149
  };
14113
14150
  function fastProgressGenerator(ai, model, gender) {
14114
14151
  return async (tool, hint, lang, signal, avoid = []) => {
14115
- const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). ${hint ? 'Name what it works on the way a person would say it ("looking up that Astra post\u2026"), never a string of its keywords ("scanning Astra weights\u2026"). ' : ""}${avoid.length ? `It already said ${avoid.map((a) => `"${a}"`).join(", ")}: say something new, a different angle on the same work. ` : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
14152
+ const prompt = `An assistant on a live voice call is ${tool ? `running the tool "${tool}"` : "working on a request"}${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). ${hint ? 'Name what it works on the way a person would say it ("looking up that Astra post\u2026"), never a string of its keywords ("scanning Astra weights\u2026"). ' : ""}${avoid.length ? `It already said ${avoid.map((a) => `"${a}"`).join(", ")}: say something new, a different angle on the same work. ` : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
14116
14153
  return fastText(ai, { model, prompt, signal });
14117
14154
  };
14118
14155
  }
@@ -15049,6 +15086,9 @@ var VoiceCallOptions = class {
15049
15086
  /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
15050
15087
  * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
15051
15088
  quick;
15089
+ /** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
15090
+ * played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
15091
+ hangUp;
15052
15092
  /** Past this the turn goes to MAIN as before (the bridge covers it). */
15053
15093
  quickBudgetMs = 1800;
15054
15094
  /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
@@ -15063,6 +15103,10 @@ var VoiceCallOptions = class {
15063
15103
  /** Host caption — never history. */
15064
15104
  show = () => {
15065
15105
  };
15106
+ /** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
15107
+ * turn the quick lane answered, `aside` = said while MAIN worked, `kept` = a soft barge-in kept over the reply. */
15108
+ userLine = () => {
15109
+ };
15066
15110
  /** The fast model (lines, banks, progress) — used only with `ai`. */
15067
15111
  fastModel = latestClaude("haiku");
15068
15112
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
@@ -15130,7 +15174,9 @@ var VoiceCall = class {
15130
15174
  cancel: () => o.cancel(),
15131
15175
  now: o.now
15132
15176
  });
15133
- this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500, gapMs: 5e3 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
15177
+ const po = { ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500, gapMs: 5e3 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress };
15178
+ if (o.mode === "live") po.stageRepeatMs ??= po.gapMs;
15179
+ this.progress = new Progress(po);
15134
15180
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
15135
15181
  this.gate = new TurnGate({
15136
15182
  now: o.now,
@@ -15230,6 +15276,13 @@ var VoiceCall = class {
15230
15276
  if (this.ended) return;
15231
15277
  if (by === "main") return this.main({ type: "audio", ...this.cur ? { id: this.cur.id } : {} }, inMs);
15232
15278
  const at = this.o.now() + Math.max(0, inMs);
15279
+ const q = this.cur;
15280
+ if (q?.quickWord && !q.closed) {
15281
+ this.lastAudibleAt = at;
15282
+ q.marks.fillAudio ??= at;
15283
+ this.sounded(q, "quick", at);
15284
+ return this.quickWorded(q, at);
15285
+ }
15233
15286
  if (this.gate.holding || !this.cur || this.cur.closed) {
15234
15287
  this.earlyHeard ??= { at, by };
15235
15288
  return;
@@ -15345,11 +15398,44 @@ var VoiceCall = class {
15345
15398
  }
15346
15399
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15347
15400
  async overlap(text) {
15348
- if (this.o.mode === "live" && isReaction(text)) return "keep";
15401
+ if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
15349
15402
  const d = await this.judge.judge(text);
15350
15403
  if (d.verdict === "cut") this.barge();
15404
+ else if (d.verdict === "keep") this.kept(text);
15351
15405
  return d.verdict;
15352
15406
  }
15407
+ /** An overlap kept over the reply (no turn): the transcript and the quick lane's history still hold their words — once,
15408
+ * in full: the host asks about every growing partial ("Oh," "Oh, wow" "Oh, wow—really?"; Para replay showed all four). */
15409
+ kept(text) {
15410
+ if (!norm3(text)) return;
15411
+ const p = this.keptLine, a = norm3(text).replace(/ /g, ""), b = p ? norm3(p.text).replace(/ /g, "") : "";
15412
+ if (p && (a.startsWith(b) || b.startsWith(a))) {
15413
+ if (a.length > b.length) {
15414
+ p.text = text;
15415
+ if (p.line) p.line.text = text;
15416
+ }
15417
+ clearTimeout(p.timer);
15418
+ } else {
15419
+ this.flushKept();
15420
+ const line = this.quickOn ? { who: "user", text } : void 0;
15421
+ if (line) this.history.push(line);
15422
+ this.keptLine = { text, timer: void 0, line };
15423
+ }
15424
+ this.keptLine.timer = setTimeout(() => this.flushKept(), isReaction(this.keptLine.text) ? 1500 : 4e3);
15425
+ }
15426
+ keptLine;
15427
+ /** The kept words go to the transcript; `turn` = the words a new turn starts with (they grew into it: no line of their own). */
15428
+ flushKept(turn = "") {
15429
+ const p = this.keptLine;
15430
+ if (!p) return;
15431
+ this.keptLine = void 0;
15432
+ clearTimeout(p.timer);
15433
+ if (turn && norm3(turn).replace(/ /g, "").startsWith(norm3(p.text).replace(/ /g, ""))) {
15434
+ if (p.line) this.history.splice(this.history.indexOf(p.line), 1);
15435
+ return;
15436
+ }
15437
+ this.o.userLine(p.text, "kept");
15438
+ }
15353
15439
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
15354
15440
  * while the reply is held, then resumes the same reply (bod-voice decideOverlap's aside). ≤4 canned words, never a
15355
15441
  * claim, the cue's language; null = stay quiet (a plain listener cue, too soon after the last, or no line). It is a
@@ -15360,7 +15446,7 @@ var VoiceCall = class {
15360
15446
  const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
15361
15447
  if (!line) return null;
15362
15448
  this.lastAside = { text: line, at: now3 };
15363
- if (this.quickOn) this.history.push({ who: "user", text }, { who: "you", text: line });
15449
+ if (this.quickOn) this.history.push({ who: "you", text: line });
15364
15450
  this.o.onMetric({ name: "fill", kind: "aside", text: line, lang: this.lang });
15365
15451
  return line;
15366
15452
  }
@@ -15373,6 +15459,7 @@ var VoiceCall = class {
15373
15459
  return this.fill.drain();
15374
15460
  }
15375
15461
  end() {
15462
+ this.flushKept();
15376
15463
  if (this.cur) this.close(this.cur);
15377
15464
  this.ended = true;
15378
15465
  this.gate.end();
@@ -15393,6 +15480,7 @@ var VoiceCall = class {
15393
15480
  }
15394
15481
  onTurn(t) {
15395
15482
  this.floor = "";
15483
+ this.flushKept(t.text);
15396
15484
  if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15397
15485
  const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
15398
15486
  const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
@@ -15472,19 +15560,17 @@ var VoiceCall = class {
15472
15560
  return;
15473
15561
  }
15474
15562
  c.lane = "quick";
15563
+ this.o.userLine(t.text, "quick");
15475
15564
  if (mv.kind === "quiet") {
15476
15565
  c.due = false;
15477
15566
  return this.close(c, "silent");
15478
15567
  }
15479
- const said = mv.kind === "resume" ? `${mv.line} ${rest}`.trim() : mv.line;
15568
+ 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;
15480
15569
  this.gate.replyStarted(c.id);
15481
- if (!await this.sayRetry(said, "reply", c.id)) return this.close(c, "silent");
15482
- this.o.show(said, "reply");
15483
- if (!c.worded) {
15484
- c.worded = true;
15485
- c.marks.mainAudio = this.lastAudibleAt;
15486
- this.o.onMetric({ name: "first_word", id: c.id, ms: Math.round(this.lastAudibleAt - c.at), by: "quick" });
15487
- }
15570
+ const end = mv.kind === "say" && !!mv.end;
15571
+ const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
15572
+ if (!played && !end) return this.close(c, "silent");
15573
+ if (played) this.o.show(said, "reply");
15488
15574
  if (mv.kind === "resume") {
15489
15575
  this.cutRest = "";
15490
15576
  this.o.dropCut?.();
@@ -15494,11 +15580,36 @@ var VoiceCall = class {
15494
15580
  this.history.push({ who: "you", text: said });
15495
15581
  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.`);
15496
15582
  }
15583
+ if (end) {
15584
+ this.o.onMetric({ name: "hangup", id: c.id, text: said });
15585
+ if (played && (!this.o.hostAudio || c.worded)) this.quickWorded(c, this.lastAudibleAt);
15586
+ this.end();
15587
+ try {
15588
+ this.o.hangUp?.();
15589
+ } catch (e) {
15590
+ log32.warn(`hangUp threw: ${e.message}`);
15591
+ }
15592
+ return;
15593
+ }
15594
+ if (this.o.hostAudio && !c.worded) {
15595
+ c.quickWord = true;
15596
+ return;
15597
+ }
15598
+ this.quickWorded(c, this.lastAudibleAt);
15599
+ }
15600
+ /** The quick lane's answer became audible at `at`: the turn's first word, and it is answered. */
15601
+ quickWorded(c, at) {
15602
+ c.quickWord = false;
15603
+ if (!c.worded) {
15604
+ c.worded = true;
15605
+ c.marks.mainAudio = at;
15606
+ this.o.onMetric({ name: "first_word", id: c.id, ms: Math.round(at - c.at), by: "quick" });
15607
+ }
15497
15608
  this.close(c, "answered");
15498
15609
  }
15499
- /** say(), retried while the host's player is busy (up to 2s). */
15500
- async sayRetry(line, kind, id) {
15501
- for (let i = 0; i < 8; i++) {
15610
+ /** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
15611
+ async sayRetry(line, kind, id, tries = 8) {
15612
+ for (let i = 0; i < tries; i++) {
15502
15613
  if (this.ended) return false;
15503
15614
  if (this.say(line, kind) !== false) return true;
15504
15615
  await new Promise((r) => setTimeout(r, 250));
@@ -15592,6 +15703,7 @@ var VoiceCall = class {
15592
15703
  const stop = /^\s*stop\s*:/i.test(raw), change = !answer || /^\s*work\s*:/i.test(raw);
15593
15704
  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.]`;
15594
15705
  this.history.push({ who: "user", text: t.text });
15706
+ if (!change) this.o.userLine(t.text, "aside");
15595
15707
  if (line && !this.ended) {
15596
15708
  await this.sayRetry(line, "aside", t.id);
15597
15709
  if (this.lastAudibleAt >= at) {
@@ -15652,6 +15764,12 @@ var VoiceCall = class {
15652
15764
  }
15653
15765
  }
15654
15766
  };
15767
+ function cutSentence(heard) {
15768
+ const tail = heard.trim().split(/(?<=[.!?…])\s+/).at(-1) ?? "";
15769
+ if (!tail || /[.!?…]["'”’)]*$/.test(tail)) return "";
15770
+ const w = tail.split(/\s+/);
15771
+ return w.length <= 6 ? tail : w.slice(-3).join(" ");
15772
+ }
15655
15773
 
15656
15774
  // src/index.ts
15657
15775
  init_llm();