@livx.cc/agentx 0.99.147 → 0.99.149

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
@@ -1668,12 +1668,14 @@ declare class ProgressOptions {
1668
1668
  /** The voice's gender: picks the gendered table (`${lang}-f`/`-m`) when one exists. */
1669
1669
  gender: Gender;
1670
1670
  /** Fast-model fallback for a tool with no template (fastProgressGenerator). Absent → silence. */
1671
- generate?: (tool: string, hint: string, lang: string, signal: AbortSignal) => Promise<string>;
1671
+ generate?: (tool: string, hint: string, lang: string, signal: AbortSignal, avoid?: string[]) => Promise<string>;
1672
1672
  generateBudgetMs: number;
1673
1673
  /** Speak only when nothing has been audible for this long. */
1674
1674
  silenceMs: number;
1675
- /** At most one progress line per this long. */
1675
+ /** At most one spoken work line (progress, bridge or aside) per this long. */
1676
1676
  gapMs: number;
1677
+ /** One stage (a tool's topic) gets one line; a stage still running after this long may get another. 0 = 3 × gapMs. */
1678
+ stageRepeatMs: number;
1677
1679
  now: () => number;
1678
1680
  }
1679
1681
  declare class Progress {
@@ -1681,21 +1683,43 @@ declare class Progress {
1681
1683
  private said;
1682
1684
  private lastAt;
1683
1685
  private streamed;
1686
+ private lines;
1687
+ private stages;
1684
1688
  constructor(options?: Partial<ProgressOptions> | undefined);
1685
1689
  private get o();
1686
1690
  /** A new MAIN turn started. */
1687
1691
  turn(): void;
1688
- /** MAIN's text streamed this turn: no more progress lines for it. */
1692
+ /** MAIN's text streamed this turn: no more progress lines, until a tool runs again. */
1689
1693
  text(): void;
1690
- /** May a line play now? (the caller passes when the user last heard anything) */
1691
- due(lastAudibleAt: number): boolean;
1692
- /** Mark `line` spoken. */
1693
- spoke(line: string): void;
1694
+ /** A tool started: MAIN is working again. */
1695
+ tool(): void;
1696
+ /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
1697
+ due(lastAudibleAt: number, leadMs?: number, tool?: string): boolean;
1698
+ /** Mark `line` spoken, for `tool`'s stage. */
1699
+ spoke(line: string, tool?: string): void;
1700
+ /** A work line played from elsewhere (a bridge, an aside): the same thought, so the gap counts from it. */
1701
+ heard(): void;
1702
+ private stage;
1703
+ /** A line the user heard from elsewhere (an aside): progress never repeats it. */
1704
+ note(line: string): void;
1705
+ /** The last lines heard, for a writer to avoid. */
1706
+ get recent(): string[];
1694
1707
  /** `about`: the user's request, for a generated line. The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
1695
1708
  line(tool: string, args: unknown, lang: string, about?: string): Promise<string>;
1696
1709
  }
1710
+ /** What the fast model knows when the user speaks over MAIN's work. */
1711
+ interface WorkContext {
1712
+ request: string;
1713
+ heard: string;
1714
+ tool: string;
1715
+ hint: string;
1716
+ lang: string;
1717
+ avoid: string[];
1718
+ }
1719
+ /** The spoken answer. `stop:` opens it when they called the work off, `work:` when they change or add to it. '' = silence. */
1720
+ type WorkReply = (c: WorkContext, signal: AbortSignal) => Promise<string>;
1697
1721
 
1698
- type FillKind = LineKind | 'progress';
1722
+ type FillKind = LineKind | 'progress' | 'aside';
1699
1723
  /** MAIN's stream as the host forwards it. `id` = the turn (sendTurn's id); absent → the current turn. */
1700
1724
  interface MainEvent {
1701
1725
  type: 'start' | 'text' | 'tool' | 'tool_done' | 'audio' | 'done' | 'error';
@@ -1749,6 +1773,14 @@ declare class VoiceCallOptions {
1749
1773
  }) => void;
1750
1774
  /** Host aborts a running MAIN turn (barge-in). */
1751
1775
  abortTurn: (id: string) => void;
1776
+ /** Host keeps `note` for MAIN's next turn. With it (and `workReply`), what the user says while MAIN works is answered at
1777
+ * once by the fast model and MAIN is not aborted or restarted: a remark reaches MAIN as this note, a change or addition
1778
+ * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
1779
+ * barges in as before. */
1780
+ noteTurn?: (note: string) => void;
1781
+ /** Writes that immediate answer (fastWorkReply). */
1782
+ workReply?: WorkReply;
1783
+ workReplyBudgetMs: number;
1752
1784
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
1753
1785
  speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
1754
1786
  /** Stop the in-flight fill line now (barge-in only). */
@@ -1778,6 +1810,13 @@ declare class VoiceCallOptions {
1778
1810
  now: () => number;
1779
1811
  /** An aside (aside()) needs this long since the last one — a cue answered every time sounds scripted. */
1780
1812
  asideGapMs: number;
1813
+ /** After a turn went out, new words this soon are the same turn going on (it gives way to the fuller one), if MAIN has
1814
+ * not started. Later ones are a new thing said over the work. */
1815
+ resumeMs: number;
1816
+ /** Progress waits while the user spoke this recently. */
1817
+ userQuietMs: number;
1818
+ /** A progress line starts being written this long before it is due. */
1819
+ progressLeadMs: number;
1781
1820
  }
1782
1821
  declare class VoiceCall {
1783
1822
  options?: Partial<VoiceCallOptions> | undefined;
@@ -1793,6 +1832,7 @@ declare class VoiceCall {
1793
1832
  private lastWordAt;
1794
1833
  private earlyHeard;
1795
1834
  private progressTimer;
1835
+ private lastUserAt;
1796
1836
  private ended;
1797
1837
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1798
1838
  private get o();
@@ -1804,6 +1844,8 @@ declare class VoiceCall {
1804
1844
  text: string;
1805
1845
  running: boolean;
1806
1846
  } | undefined;
1847
+ /** MAIN is on this turn and has the floor to itself: nothing the user says now stops it, unless they ask it to. */
1848
+ get working(): boolean;
1807
1849
  /** The host STT's language (BCP-47): the current language until the user's words say otherwise. */
1808
1850
  setLanguage(tag: string): void;
1809
1851
  /** STT partial (the whole partial). */
@@ -1829,6 +1871,7 @@ declare class VoiceCall {
1829
1871
  main(ev: MainEvent, inMs?: number): void;
1830
1872
  /** The user barged in (hard): cut fill + MAIN audio (the host cuts its own), abort a running MAIN turn. */
1831
1873
  barge(): void;
1874
+ private giveWay;
1832
1875
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
1833
1876
  overlap(text: string): Promise<OverlapVerdict>;
1834
1877
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
@@ -1852,7 +1895,11 @@ declare class VoiceCall {
1852
1895
  /** The turn is over (answered + audible, replaced, the next turn, the call's end): its timeline, once. A turn whose MAIN
1853
1896
  * never became audible still reports first_word — with no ms and why (cut / replaced / silent) — so every turn has one. */
1854
1897
  private close;
1855
- private onTool;
1898
+ /** The user spoke while MAIN works: the fast model answers now, the words reach MAIN as a note, MAIN keeps going. */
1899
+ private overWork;
1900
+ /** While MAIN's tools run: a progress line once nothing was heard for `silenceMs`, then every `gapMs`, written just ahead
1901
+ * so it plays on time. Ticks are local (no network) and stop with the turn. */
1902
+ private beat;
1856
1903
  private clearProgress;
1857
1904
  }
1858
1905
 
package/dist/index.js CHANGED
@@ -10511,6 +10511,7 @@ var OverlapJudge = class {
10511
10511
  };
10512
10512
  const rule = overlapRule(heard);
10513
10513
  if (rule) return done(rule, "rule");
10514
+ if (norm2(heard).split(/[\s-]+/).filter(Boolean).length < 2) return done("keep", "lone");
10514
10515
  if (!this.o.model) return done("cut", "none");
10515
10516
  const ctl = new AbortController();
10516
10517
  let timer;
@@ -13727,9 +13728,6 @@ init_logging();
13727
13728
  init_logging();
13728
13729
  init_models();
13729
13730
 
13730
- // src/voice/progress.ts
13731
- init_logging();
13732
-
13733
13731
  // src/voice/convoTree.ts
13734
13732
  init_logging();
13735
13733
 
@@ -13859,10 +13857,13 @@ var ConvoTree = class {
13859
13857
  };
13860
13858
 
13861
13859
  // src/voice/progress.ts
13860
+ init_logging();
13862
13861
  var log29 = forComponent("Progress");
13863
13862
  var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
13863
+ var PLUMBING = /toolsearch|^mcp__.*__(list_commands|call_info)$/;
13864
+ var isPlumbing = (tool) => PLUMBING.test(tool.toLowerCase());
13864
13865
  var TOPICS = [
13865
- [/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
13866
+ [PLUMBING, null],
13866
13867
  // tool plumbing — no line (and no generated one)
13867
13868
  [/kanban|board|card|\bkb\b|list_cards/, "board"],
13868
13869
  [/mail|gmail|inbox/, "mail"],
@@ -13944,8 +13945,10 @@ var ProgressOptions = class {
13944
13945
  generateBudgetMs = 800;
13945
13946
  /** Speak only when nothing has been audible for this long. */
13946
13947
  silenceMs = 3e3;
13947
- /** At most one progress line per this long. */
13948
+ /** At most one spoken work line (progress, bridge or aside) per this long. */
13948
13949
  gapMs = 4e3;
13950
+ /** One stage (a tool's topic) gets one line; a stage still running after this long may get another. 0 = 3 × gapMs. */
13951
+ stageRepeatMs = 0;
13949
13952
  now = () => performance.now();
13950
13953
  };
13951
13954
  function argsHint(args) {
@@ -13962,6 +13965,8 @@ var Progress = class {
13962
13965
  said = /* @__PURE__ */ new Set();
13963
13966
  lastAt = -Infinity;
13964
13967
  streamed = false;
13968
+ lines = [];
13969
+ stages = /* @__PURE__ */ new Map();
13965
13970
  get o() {
13966
13971
  return this.options;
13967
13972
  }
@@ -13969,20 +13974,43 @@ var Progress = class {
13969
13974
  turn() {
13970
13975
  this.streamed = false;
13971
13976
  }
13972
- /** MAIN's text streamed this turn: no more progress lines for it. */
13977
+ /** MAIN's text streamed this turn: no more progress lines, until a tool runs again. */
13973
13978
  text() {
13974
13979
  this.streamed = true;
13975
13980
  }
13976
- /** May a line play now? (the caller passes when the user last heard anything) */
13977
- due(lastAudibleAt) {
13978
- const now3 = this.o.now();
13979
- return !this.streamed && now3 - lastAudibleAt >= this.o.silenceMs && now3 - this.lastAt >= this.o.gapMs;
13981
+ /** A tool started: MAIN is working again. */
13982
+ tool() {
13983
+ this.streamed = false;
13980
13984
  }
13981
- /** Mark `line` spoken. */
13982
- spoke(line) {
13983
- this.said.add(norm3(line));
13985
+ /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
13986
+ due(lastAudibleAt, leadMs = 0, tool = "") {
13987
+ const now3 = this.o.now(), spoken = tool ? this.stages.get(this.stage(tool)) : void 0;
13988
+ if (spoken !== void 0 && now3 - spoken < (this.o.stageRepeatMs || 3 * this.o.gapMs) - leadMs) return false;
13989
+ return !this.streamed && now3 - lastAudibleAt >= this.o.silenceMs - leadMs && now3 - this.lastAt >= this.o.gapMs - leadMs;
13990
+ }
13991
+ /** Mark `line` spoken, for `tool`'s stage. */
13992
+ spoke(line, tool = "") {
13993
+ this.note(line);
13994
+ this.heard();
13995
+ if (tool) this.stages.set(this.stage(tool), this.o.now());
13996
+ }
13997
+ /** A work line played from elsewhere (a bridge, an aside): the same thought, so the gap counts from it. */
13998
+ heard() {
13984
13999
  this.lastAt = this.o.now();
13985
14000
  }
14001
+ stage(tool) {
14002
+ const n = tool.toLowerCase();
14003
+ return TOPICS.find(([re]) => re.test(n))?.[1] ?? n;
14004
+ }
14005
+ /** A line the user heard from elsewhere (an aside): progress never repeats it. */
14006
+ note(line) {
14007
+ this.said.add(norm3(line));
14008
+ this.lines = [...this.lines, line].slice(-6);
14009
+ }
14010
+ /** The last lines heard, for a writer to avoid. */
14011
+ get recent() {
14012
+ return [...this.lines];
14013
+ }
13986
14014
  /** `about`: the user's request, for a generated line. The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
13987
14015
  async line(tool, args, lang, about = "") {
13988
14016
  if (this.streamed) return "";
@@ -14003,7 +14031,7 @@ var Progress = class {
14003
14031
  r(null);
14004
14032
  }, this.o.generateBudgetMs);
14005
14033
  });
14006
- const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal).catch((e) => {
14034
+ const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal, this.lines).catch((e) => {
14007
14035
  log29.warn(`progress line failed: ${e?.message ?? e}`);
14008
14036
  return null;
14009
14037
  }), late]).finally(() => clearTimeout(t));
@@ -14013,13 +14041,24 @@ var Progress = class {
14013
14041
  }
14014
14042
  };
14015
14043
  function fastProgressGenerator(ai, model, gender) {
14016
- return async (tool, hint, lang, signal) => {
14017
- 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 ? "Use the words of what it is about. " : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
14044
+ return async (tool, hint, lang, signal, avoid = []) => {
14045
+ 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 ? "Use the words of what it is about. " : ""}${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.`;
14018
14046
  const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14019
14047
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14020
14048
  return r.content ?? "";
14021
14049
  };
14022
14050
  }
14051
+ var WORK_CLAIM = /\b(?:none|nothing|nobody|zero|\d+|one|two|three|four|five|many|several|some|looks like|seems|turns out|apparently|it'?s|they'?re|there'?s)\b|(?:^|\s)(?:כלום|אף|נראה)(?=\s|$|[.,!…])/iu;
14052
+ var claimsResult = (l) => RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || WORK_CLAIM.test(l);
14053
+ function cleanWorkReply(raw, lang) {
14054
+ const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14055
+ return claimsResult(l) ? "" : l;
14056
+ }
14057
+ function workAck(raw, lang, gender = "") {
14058
+ const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14059
+ if (!l || !claimsResult(l)) return "";
14060
+ return (PROGRESS_TEMPLATES[gender ? `${lang}-${gender[0]}` : lang] ?? PROGRESS_TEMPLATES[lang])?.delegate[1] ?? "";
14061
+ }
14023
14062
 
14024
14063
  // src/voice/secondChannel.ts
14025
14064
  init_logging();
@@ -14179,6 +14218,11 @@ var SecondChannelOptions = class {
14179
14218
  random = Math.random;
14180
14219
  };
14181
14220
  var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14221
+ var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
14222
+ var onlyHesitation = (s) => {
14223
+ const w = words2(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14224
+ return !!w.length && w.every((x) => HESITATION.test(x));
14225
+ };
14182
14226
  function withBudget(p, ms, what, ac) {
14183
14227
  let t;
14184
14228
  const late = new Promise((r) => {
@@ -14611,7 +14655,7 @@ var SecondChannel = class {
14611
14655
  this.breathTimer = setTimeout(() => {
14612
14656
  this.breathTimer = null;
14613
14657
  const n = words2(t).length, tree = this.tree;
14614
- if (n < this.o.backchannelMinWords || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
14658
+ if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
14615
14659
  this.picking = true;
14616
14660
  const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
14617
14661
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
@@ -14673,6 +14717,7 @@ var SecondChannel = class {
14673
14717
  * sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
14674
14718
  * "Check hacker news for recent news.", just before the final). */
14675
14719
  backchannelMoment(n, breath) {
14720
+ if (!cueWords(this.heard).some(isContent)) return false;
14676
14721
  if (/\?$/.test(this.heard) || pendingQuestion(this.heard)) return false;
14677
14722
  if (this.carried) n += this.carried;
14678
14723
  else if (n < this.o.requestHoldWords && requestOpener(this.heard)) return false;
@@ -14796,6 +14841,7 @@ var SecondChannel = class {
14796
14841
  return p;
14797
14842
  }
14798
14843
  say(kind, text) {
14844
+ if (kind === "backchannel" && onlyHesitation(this.heard)) return false;
14799
14845
  let r;
14800
14846
  try {
14801
14847
  r = this.o.speak(text, kind);
@@ -14888,6 +14934,14 @@ var VoiceCallOptions = class {
14888
14934
  /** Host aborts a running MAIN turn (barge-in). */
14889
14935
  abortTurn = () => {
14890
14936
  };
14937
+ /** Host keeps `note` for MAIN's next turn. With it (and `workReply`), what the user says while MAIN works is answered at
14938
+ * once by the fast model and MAIN is not aborted or restarted: a remark reaches MAIN as this note, a change or addition
14939
+ * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
14940
+ * barges in as before. */
14941
+ noteTurn;
14942
+ /** Writes that immediate answer (fastWorkReply). */
14943
+ workReply;
14944
+ workReplyBudgetMs = 1500;
14891
14945
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
14892
14946
  speak = () => false;
14893
14947
  /** Stop the in-flight fill line now (barge-in only). */
@@ -14920,6 +14974,13 @@ var VoiceCallOptions = class {
14920
14974
  now = () => performance.now();
14921
14975
  /** An aside (aside()) needs this long since the last one — a cue answered every time sounds scripted. */
14922
14976
  asideGapMs = 8e3;
14977
+ /** After a turn went out, new words this soon are the same turn going on (it gives way to the fuller one), if MAIN has
14978
+ * not started. Later ones are a new thing said over the work. */
14979
+ resumeMs = 3e3;
14980
+ /** Progress waits while the user spoke this recently. */
14981
+ userQuietMs = 800;
14982
+ /** A progress line starts being written this long before it is due. */
14983
+ progressLeadMs = 1e3;
14923
14984
  };
14924
14985
  var VoiceCall = class {
14925
14986
  constructor(options) {
@@ -14955,7 +15016,7 @@ var VoiceCall = class {
14955
15016
  cancel: () => o.cancel(),
14956
15017
  now: o.now
14957
15018
  });
14958
- this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
15019
+ 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 });
14959
15020
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
14960
15021
  this.gate = new TurnGate({
14961
15022
  now: o.now,
@@ -14982,6 +15043,7 @@ var VoiceCall = class {
14982
15043
  earlyHeard = null;
14983
15044
  // a fill line heard while that turn was still held
14984
15045
  progressTimer = null;
15046
+ lastUserAt = -Infinity;
14985
15047
  ended = false;
14986
15048
  get o() {
14987
15049
  return this.options;
@@ -14994,6 +15056,11 @@ var VoiceCall = class {
14994
15056
  get turn() {
14995
15057
  return this.cur && { id: this.cur.id, text: this.cur.text, running: this.cur.running };
14996
15058
  }
15059
+ /** MAIN is on this turn and has the floor to itself: nothing the user says now stops it, unless they ask it to. */
15060
+ get working() {
15061
+ const c = this.cur;
15062
+ return !!c && c.running && !c.closed && (!c.worded || c.open > 0);
15063
+ }
14997
15064
  /** The host STT's language (BCP-47): the current language until the user's words say otherwise. */
14998
15065
  setLanguage(tag) {
14999
15066
  const l = primaryLang(tag);
@@ -15006,13 +15073,16 @@ var VoiceCall = class {
15006
15073
  if (this.ended || !text.trim()) return;
15007
15074
  if (typeof aec === "boolean") this.fill.options.aec = aec;
15008
15075
  this.gate.speaking();
15009
- const c = this.cur;
15010
- if (this.o.mode === "live" && c?.running && !c.worded && newWords(text, c.text) >= 2) {
15076
+ this.lastUserAt = this.o.now();
15077
+ const c = this.cur, steers = !!this.o.noteTurn && this.working;
15078
+ const resumed = !steers || c.marks.mainFirst === void 0 && this.o.now() - c.at < this.o.resumeMs;
15079
+ if (this.o.mode === "live" && c?.running && !c.worded && resumed && newWords(text, c.text) >= 2) {
15011
15080
  log31.debug("user resumed before the reply \u2014 yielded");
15012
- this.barge();
15081
+ this.giveWay(c);
15013
15082
  this.gate.reopen(c.id);
15014
15083
  }
15015
15084
  this.follow(text);
15085
+ if (this.o.noteTurn && this.working) return;
15016
15086
  this.fill.onInterim(text);
15017
15087
  }
15018
15088
  /** STT final → TurnGate. `lastWordAgoMs`: how long ago the user's last word of it ended (the STT's word clock,
@@ -15071,6 +15141,8 @@ var VoiceCall = class {
15071
15141
  if (!c.streamed) {
15072
15142
  c.streamed = true;
15073
15143
  this.gate.replyStarted(c.id);
15144
+ }
15145
+ if (c.open <= 0) {
15074
15146
  this.progress.text();
15075
15147
  this.clearProgress();
15076
15148
  }
@@ -15079,9 +15151,17 @@ var VoiceCall = class {
15079
15151
  case "tool":
15080
15152
  c.marks.mainFirst ??= this.o.now();
15081
15153
  this.gate.replyStarted(c.id);
15082
- void this.onTool(c, ev.name ?? "", ev.args);
15154
+ c.open++;
15155
+ c.streamed = false;
15156
+ if (ev.name && !isPlumbing(ev.name)) {
15157
+ c.tool = ev.name;
15158
+ c.args = ev.args;
15159
+ }
15160
+ this.progress.tool();
15161
+ this.beat(c);
15083
15162
  return;
15084
15163
  case "tool_done":
15164
+ c.open = Math.max(0, c.open - 1);
15085
15165
  return;
15086
15166
  case "audio": {
15087
15167
  const at = this.o.now() + Math.max(0, inMs);
@@ -15103,11 +15183,28 @@ var VoiceCall = class {
15103
15183
  this.clearProgress();
15104
15184
  this.fill.onAgentState("idle");
15105
15185
  if (c.worded) this.close(c, "answered");
15186
+ if (c.next) {
15187
+ const next = c.next;
15188
+ c.next = void 0;
15189
+ this.onTurn(next);
15190
+ }
15106
15191
  return;
15107
15192
  }
15108
15193
  }
15109
15194
  /** The user barged in (hard): cut fill + MAIN audio (the host cuts its own), abort a running MAIN turn. */
15110
15195
  barge() {
15196
+ if (this.o.noteTurn && this.working) {
15197
+ this.fill.onBargeIn();
15198
+ try {
15199
+ this.o.cancel();
15200
+ } catch (e) {
15201
+ log31.warn(`cancel threw: ${e.message}`);
15202
+ }
15203
+ return;
15204
+ }
15205
+ this.giveWay();
15206
+ }
15207
+ giveWay(c = this.cur) {
15111
15208
  this.fill.onBargeIn();
15112
15209
  this.clearProgress();
15113
15210
  try {
@@ -15115,11 +15212,11 @@ var VoiceCall = class {
15115
15212
  } catch (e) {
15116
15213
  log31.warn(`cancel threw: ${e.message}`);
15117
15214
  }
15118
- if (this.cur?.running) {
15119
- this.cur.running = false;
15120
- this.o.abortTurn(this.cur.id);
15215
+ if (c?.running) {
15216
+ c.running = false;
15217
+ this.o.abortTurn(c.id);
15121
15218
  }
15122
- if (this.cur && !this.cur.worded) this.cur.end ??= "cut";
15219
+ if (c && !c.worded) c.end ??= "cut";
15123
15220
  }
15124
15221
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15125
15222
  async overlap(text) {
@@ -15165,6 +15262,7 @@ var VoiceCall = class {
15165
15262
  if (l) this.fill.setLanguage(l, true);
15166
15263
  }
15167
15264
  onTurn(t) {
15265
+ if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15168
15266
  const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
15169
15267
  const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
15170
15268
  const finalAt = this.finalAt || now3;
@@ -15173,7 +15271,7 @@ var VoiceCall = class {
15173
15271
  if (this.cur) this.close(this.cur, t.replaces === this.cur.id ? "replaced" : void 0);
15174
15272
  this.follow(t.text);
15175
15273
  this.clearProgress();
15176
- 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" };
15274
+ 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 };
15177
15275
  const early = this.earlyHeard;
15178
15276
  this.earlyHeard = null;
15179
15277
  if (early && early.at >= at) {
@@ -15205,12 +15303,14 @@ var VoiceCall = class {
15205
15303
  }
15206
15304
  if (r === false) return false;
15207
15305
  this.o.onMetric({ name: "fill", kind, text, lang: this.lang });
15306
+ if (kind !== "backchannel") this.progress.heard();
15208
15307
  const c = this.cur && !this.cur.closed ? this.cur : void 0;
15209
15308
  const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "filler" && c.running && !c.sounded);
15210
15309
  if (c && forTurn && c.marks.fill === void 0) {
15211
15310
  c.marks.fill = this.o.now();
15212
15311
  c.fillKind = kind;
15213
15312
  }
15313
+ if (c && kind === "bridge" && this.o.mode === "live" && echoesHeard(text, c.text)) this.beat(c);
15214
15314
  if (this.o.hostAudio) return r;
15215
15315
  this.lastAudibleAt = this.o.now();
15216
15316
  if (c && forTurn) {
@@ -15248,27 +15348,78 @@ var VoiceCall = class {
15248
15348
  for (const k of Object.keys(tl)) if (tl[k] === void 0) delete tl[k];
15249
15349
  this.o.onMetric({ name: "timeline", id: c.id, text: c.text, timeline: tl });
15250
15350
  }
15251
- async onTool(c, name, args) {
15252
- const lang = this.lang;
15253
- if (!lang || c.streamed) return;
15254
- const line = await this.progress.line(name, args, lang, this.o.mode === "live" ? c.text : "");
15255
- if (!line && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${name}` });
15256
- if (!line || this.cur !== c || c.streamed || !c.running || this.lang !== lang) return;
15351
+ /** The user spoke while MAIN works: the fast model answers now, the words reach MAIN as a note, MAIN keeps going. */
15352
+ async overWork(c, t) {
15353
+ const at = this.o.now();
15354
+ this.firstFinalAt = null;
15355
+ this.lastWordAt = null;
15356
+ this.follow(t.text);
15357
+ queueMicrotask(() => this.gate.replyStarted(t.id));
15358
+ this.o.onMetric({ name: "turn", id: t.id, kind: "aside", text: t.text });
15359
+ const ac = new AbortController(), late = setTimeout(() => ac.abort(), this.o.workReplyBudgetMs), lang = this.lang;
15360
+ const raw = lang ? await this.o.workReply({ request: c.text, heard: t.text, tool: c.tool, hint: argsHint(c.args), lang, avoid: this.progress.recent }, ac.signal).catch((e) => {
15361
+ log31.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15362
+ return "";
15363
+ }).finally(() => clearTimeout(late)) : "";
15364
+ const ack = workAck(raw, lang ?? "", this.o.gender), line = cleanWorkReply(raw, lang ?? "") || ack, stop = /^\s*stop\s*:/i.test(raw), change = !line || /^\s*work\s*:/i.test(raw);
15365
+ 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.]`;
15366
+ if (line && !this.ended) {
15367
+ for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
15368
+ if (i === 7) {
15369
+ this.o.onMetric({ name: "drop", id: t.id, kind: "aside unplayed", text: line });
15370
+ break;
15371
+ }
15372
+ await new Promise((r) => setTimeout(r, 250));
15373
+ }
15374
+ if (this.lastAudibleAt >= at) {
15375
+ this.progress.note(line);
15376
+ this.o.show(line, "aside");
15377
+ }
15378
+ } else if (!line) this.o.onMetric({ name: "drop", id: t.id, kind: "no aside line" });
15379
+ if (stop) {
15380
+ this.o.noteTurn(noted);
15381
+ c.next = void 0;
15382
+ if (this.working && this.cur === c) this.giveWay(c);
15383
+ return;
15384
+ }
15385
+ if (change && this.cur === c && c.running) {
15386
+ c.next = c.next ? { ...c.next, text: `${c.next.text} ${t.text}` } : { ...t, kind: "new" };
15387
+ return;
15388
+ }
15389
+ if (change) return this.onTurn({ ...t, kind: "new" });
15390
+ this.o.noteTurn(noted);
15391
+ }
15392
+ /** While MAIN's tools run: a progress line once nothing was heard for `silenceMs`, then every `gapMs`, written just ahead
15393
+ * so it plays on time. Ticks are local (no network) and stop with the turn. */
15394
+ beat(c) {
15257
15395
  this.clearProgress();
15258
- const tryNow = () => {
15396
+ const tick = () => {
15259
15397
  this.progressTimer = null;
15260
- if (this.ended || this.cur !== c || c.streamed || !c.running) return;
15261
- if (!this.progress.due(this.lastAudibleAt)) {
15262
- this.progressTimer = setTimeout(tryNow, 250);
15263
- return;
15398
+ if (this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0) return;
15399
+ const lang = this.lang, now3 = this.o.now();
15400
+ if (lang && !c.draft && !c.drafting && now3 - c.draftAt >= 1e3 && this.progress.due(this.lastAudibleAt, this.o.progressLeadMs, c.tool)) {
15401
+ c.drafting = true;
15402
+ void this.progress.line(c.tool, c.args, lang, this.o.mode === "live" ? c.text : "").then((l) => {
15403
+ c.drafting = false;
15404
+ c.draft = l;
15405
+ if (!l) c.draftAt = this.o.now();
15406
+ if (!l && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${c.tool}` });
15407
+ else sayDraft();
15408
+ });
15264
15409
  }
15265
- if (this.say(line, "progress") !== false) {
15266
- this.progress.spoke(line);
15410
+ sayDraft();
15411
+ this.progressTimer = setTimeout(tick, 250);
15412
+ };
15413
+ const sayDraft = () => {
15414
+ if (!c.draft || this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0 || this.o.now() - this.lastUserAt < this.o.userQuietMs || !this.progress.due(this.lastAudibleAt, 0, c.tool)) return;
15415
+ if (this.say(c.draft, "progress") !== false) {
15416
+ this.progress.spoke(c.draft, c.tool);
15267
15417
  this.fill.covered();
15268
- this.o.show(line, "progress");
15418
+ this.o.show(c.draft, "progress");
15419
+ c.draft = "";
15269
15420
  }
15270
15421
  };
15271
- tryNow();
15422
+ tick();
15272
15423
  }
15273
15424
  clearProgress() {
15274
15425
  if (this.progressTimer) {