@livx.cc/agentx 0.99.147 → 0.99.148

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,7 +1668,7 @@ 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;
@@ -1681,21 +1681,39 @@ declare class Progress {
1681
1681
  private said;
1682
1682
  private lastAt;
1683
1683
  private streamed;
1684
+ private lines;
1684
1685
  constructor(options?: Partial<ProgressOptions> | undefined);
1685
1686
  private get o();
1686
1687
  /** A new MAIN turn started. */
1687
1688
  turn(): void;
1688
- /** MAIN's text streamed this turn: no more progress lines for it. */
1689
+ /** MAIN's text streamed this turn: no more progress lines, until a tool runs again. */
1689
1690
  text(): void;
1690
- /** May a line play now? (the caller passes when the user last heard anything) */
1691
- due(lastAudibleAt: number): boolean;
1691
+ /** A tool started: MAIN is working again. */
1692
+ tool(): void;
1693
+ /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
1694
+ due(lastAudibleAt: number, leadMs?: number): boolean;
1692
1695
  /** Mark `line` spoken. */
1693
1696
  spoke(line: string): void;
1697
+ /** A line the user heard from elsewhere (an aside): progress never repeats it. */
1698
+ note(line: string): void;
1699
+ /** The last lines heard, for a writer to avoid. */
1700
+ get recent(): string[];
1694
1701
  /** `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
1702
  line(tool: string, args: unknown, lang: string, about?: string): Promise<string>;
1696
1703
  }
1704
+ /** What the fast model knows when the user speaks over MAIN's work. */
1705
+ interface WorkContext {
1706
+ request: string;
1707
+ heard: string;
1708
+ tool: string;
1709
+ hint: string;
1710
+ lang: string;
1711
+ avoid: string[];
1712
+ }
1713
+ /** The spoken answer. `stop:` opens it when they called the work off, `work:` when they change or add to it. '' = silence. */
1714
+ type WorkReply = (c: WorkContext, signal: AbortSignal) => Promise<string>;
1697
1715
 
1698
- type FillKind = LineKind | 'progress';
1716
+ type FillKind = LineKind | 'progress' | 'aside';
1699
1717
  /** MAIN's stream as the host forwards it. `id` = the turn (sendTurn's id); absent → the current turn. */
1700
1718
  interface MainEvent {
1701
1719
  type: 'start' | 'text' | 'tool' | 'tool_done' | 'audio' | 'done' | 'error';
@@ -1749,6 +1767,14 @@ declare class VoiceCallOptions {
1749
1767
  }) => void;
1750
1768
  /** Host aborts a running MAIN turn (barge-in). */
1751
1769
  abortTurn: (id: string) => void;
1770
+ /** Host keeps `note` for MAIN's next turn. With it (and `workReply`), what the user says while MAIN works is answered at
1771
+ * once by the fast model and MAIN is not aborted or restarted: a remark reaches MAIN as this note, a change or addition
1772
+ * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
1773
+ * barges in as before. */
1774
+ noteTurn?: (note: string) => void;
1775
+ /** Writes that immediate answer (fastWorkReply). */
1776
+ workReply?: WorkReply;
1777
+ workReplyBudgetMs: number;
1752
1778
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
1753
1779
  speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
1754
1780
  /** Stop the in-flight fill line now (barge-in only). */
@@ -1778,6 +1804,13 @@ declare class VoiceCallOptions {
1778
1804
  now: () => number;
1779
1805
  /** An aside (aside()) needs this long since the last one — a cue answered every time sounds scripted. */
1780
1806
  asideGapMs: number;
1807
+ /** 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
1808
+ * not started. Later ones are a new thing said over the work. */
1809
+ resumeMs: number;
1810
+ /** Progress waits while the user spoke this recently. */
1811
+ userQuietMs: number;
1812
+ /** A progress line starts being written this long before it is due. */
1813
+ progressLeadMs: number;
1781
1814
  }
1782
1815
  declare class VoiceCall {
1783
1816
  options?: Partial<VoiceCallOptions> | undefined;
@@ -1793,6 +1826,7 @@ declare class VoiceCall {
1793
1826
  private lastWordAt;
1794
1827
  private earlyHeard;
1795
1828
  private progressTimer;
1829
+ private lastUserAt;
1796
1830
  private ended;
1797
1831
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1798
1832
  private get o();
@@ -1804,6 +1838,8 @@ declare class VoiceCall {
1804
1838
  text: string;
1805
1839
  running: boolean;
1806
1840
  } | undefined;
1841
+ /** MAIN is on this turn and has the floor to itself: nothing the user says now stops it, unless they ask it to. */
1842
+ get working(): boolean;
1807
1843
  /** The host STT's language (BCP-47): the current language until the user's words say otherwise. */
1808
1844
  setLanguage(tag: string): void;
1809
1845
  /** STT partial (the whole partial). */
@@ -1829,6 +1865,7 @@ declare class VoiceCall {
1829
1865
  main(ev: MainEvent, inMs?: number): void;
1830
1866
  /** The user barged in (hard): cut fill + MAIN audio (the host cuts its own), abort a running MAIN turn. */
1831
1867
  barge(): void;
1868
+ private giveWay;
1832
1869
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
1833
1870
  overlap(text: string): Promise<OverlapVerdict>;
1834
1871
  /** The fill channel's spoken aside for an overlap judged 'keep' ("yeah" → "Oh yeah, definitely."): the host plays it
@@ -1852,7 +1889,11 @@ declare class VoiceCall {
1852
1889
  /** The turn is over (answered + audible, replaced, the next turn, the call's end): its timeline, once. A turn whose MAIN
1853
1890
  * never became audible still reports first_word — with no ms and why (cut / replaced / silent) — so every turn has one. */
1854
1891
  private close;
1855
- private onTool;
1892
+ /** The user spoke while MAIN works: the fast model answers now, the words reach MAIN as a note, MAIN keeps going. */
1893
+ private overWork;
1894
+ /** While MAIN's tools run: a progress line once nothing was heard for `silenceMs`, then every `gapMs`, written just ahead
1895
+ * so it plays on time. Ticks are local (no network) and stop with the turn. */
1896
+ private beat;
1856
1897
  private clearProgress;
1857
1898
  }
1858
1899
 
package/dist/index.js CHANGED
@@ -13727,9 +13727,6 @@ init_logging();
13727
13727
  init_logging();
13728
13728
  init_models();
13729
13729
 
13730
- // src/voice/progress.ts
13731
- init_logging();
13732
-
13733
13730
  // src/voice/convoTree.ts
13734
13731
  init_logging();
13735
13732
 
@@ -13859,10 +13856,13 @@ var ConvoTree = class {
13859
13856
  };
13860
13857
 
13861
13858
  // src/voice/progress.ts
13859
+ init_logging();
13862
13860
  var log29 = forComponent("Progress");
13863
13861
  var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
13862
+ var PLUMBING = /toolsearch|^mcp__.*__(list_commands|call_info)$/;
13863
+ var isPlumbing = (tool) => PLUMBING.test(tool.toLowerCase());
13864
13864
  var TOPICS = [
13865
- [/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
13865
+ [PLUMBING, null],
13866
13866
  // tool plumbing — no line (and no generated one)
13867
13867
  [/kanban|board|card|\bkb\b|list_cards/, "board"],
13868
13868
  [/mail|gmail|inbox/, "mail"],
@@ -13962,6 +13962,7 @@ var Progress = class {
13962
13962
  said = /* @__PURE__ */ new Set();
13963
13963
  lastAt = -Infinity;
13964
13964
  streamed = false;
13965
+ lines = [];
13965
13966
  get o() {
13966
13967
  return this.options;
13967
13968
  }
@@ -13969,20 +13970,33 @@ var Progress = class {
13969
13970
  turn() {
13970
13971
  this.streamed = false;
13971
13972
  }
13972
- /** MAIN's text streamed this turn: no more progress lines for it. */
13973
+ /** MAIN's text streamed this turn: no more progress lines, until a tool runs again. */
13973
13974
  text() {
13974
13975
  this.streamed = true;
13975
13976
  }
13976
- /** May a line play now? (the caller passes when the user last heard anything) */
13977
- due(lastAudibleAt) {
13977
+ /** A tool started: MAIN is working again. */
13978
+ tool() {
13979
+ this.streamed = false;
13980
+ }
13981
+ /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
13982
+ due(lastAudibleAt, leadMs = 0) {
13978
13983
  const now3 = this.o.now();
13979
- return !this.streamed && now3 - lastAudibleAt >= this.o.silenceMs && now3 - this.lastAt >= this.o.gapMs;
13984
+ return !this.streamed && now3 - lastAudibleAt >= this.o.silenceMs - leadMs && now3 - this.lastAt >= this.o.gapMs - leadMs;
13980
13985
  }
13981
13986
  /** Mark `line` spoken. */
13982
13987
  spoke(line) {
13983
- this.said.add(norm3(line));
13988
+ this.note(line);
13984
13989
  this.lastAt = this.o.now();
13985
13990
  }
13991
+ /** A line the user heard from elsewhere (an aside): progress never repeats it. */
13992
+ note(line) {
13993
+ this.said.add(norm3(line));
13994
+ this.lines = [...this.lines, line].slice(-6);
13995
+ }
13996
+ /** The last lines heard, for a writer to avoid. */
13997
+ get recent() {
13998
+ return [...this.lines];
13999
+ }
13986
14000
  /** `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
14001
  async line(tool, args, lang, about = "") {
13988
14002
  if (this.streamed) return "";
@@ -14003,7 +14017,7 @@ var Progress = class {
14003
14017
  r(null);
14004
14018
  }, this.o.generateBudgetMs);
14005
14019
  });
14006
- const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal).catch((e) => {
14020
+ 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
14021
  log29.warn(`progress line failed: ${e?.message ?? e}`);
14008
14022
  return null;
14009
14023
  }), late]).finally(() => clearTimeout(t));
@@ -14013,13 +14027,17 @@ var Progress = class {
14013
14027
  }
14014
14028
  };
14015
14029
  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.`;
14030
+ return async (tool, hint, lang, signal, avoid = []) => {
14031
+ 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
14032
  const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14019
14033
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14020
14034
  return r.content ?? "";
14021
14035
  };
14022
14036
  }
14037
+ function cleanWorkReply(raw, lang) {
14038
+ const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14039
+ return RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? "" : l;
14040
+ }
14023
14041
 
14024
14042
  // src/voice/secondChannel.ts
14025
14043
  init_logging();
@@ -14611,7 +14629,7 @@ var SecondChannel = class {
14611
14629
  this.breathTimer = setTimeout(() => {
14612
14630
  this.breathTimer = null;
14613
14631
  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;
14632
+ if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
14615
14633
  this.picking = true;
14616
14634
  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
14635
  void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
@@ -14673,6 +14691,7 @@ var SecondChannel = class {
14673
14691
  * sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
14674
14692
  * "Check hacker news for recent news.", just before the final). */
14675
14693
  backchannelMoment(n, breath) {
14694
+ if (!cueWords(this.heard).some(isContent)) return false;
14676
14695
  if (/\?$/.test(this.heard) || pendingQuestion(this.heard)) return false;
14677
14696
  if (this.carried) n += this.carried;
14678
14697
  else if (n < this.o.requestHoldWords && requestOpener(this.heard)) return false;
@@ -14888,6 +14907,14 @@ var VoiceCallOptions = class {
14888
14907
  /** Host aborts a running MAIN turn (barge-in). */
14889
14908
  abortTurn = () => {
14890
14909
  };
14910
+ /** Host keeps `note` for MAIN's next turn. With it (and `workReply`), what the user says while MAIN works is answered at
14911
+ * once by the fast model and MAIN is not aborted or restarted: a remark reaches MAIN as this note, a change or addition
14912
+ * runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
14913
+ * barges in as before. */
14914
+ noteTurn;
14915
+ /** Writes that immediate answer (fastWorkReply). */
14916
+ workReply;
14917
+ workReplyBudgetMs = 1500;
14891
14918
  /** Host TTS (fill lane): resolves when played; `false` = could not play. */
14892
14919
  speak = () => false;
14893
14920
  /** Stop the in-flight fill line now (barge-in only). */
@@ -14920,6 +14947,13 @@ var VoiceCallOptions = class {
14920
14947
  now = () => performance.now();
14921
14948
  /** An aside (aside()) needs this long since the last one — a cue answered every time sounds scripted. */
14922
14949
  asideGapMs = 8e3;
14950
+ /** 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
14951
+ * not started. Later ones are a new thing said over the work. */
14952
+ resumeMs = 3e3;
14953
+ /** Progress waits while the user spoke this recently. */
14954
+ userQuietMs = 800;
14955
+ /** A progress line starts being written this long before it is due. */
14956
+ progressLeadMs = 1e3;
14923
14957
  };
14924
14958
  var VoiceCall = class {
14925
14959
  constructor(options) {
@@ -14955,7 +14989,7 @@ var VoiceCall = class {
14955
14989
  cancel: () => o.cancel(),
14956
14990
  now: o.now
14957
14991
  });
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 });
14992
+ 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
14993
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
14960
14994
  this.gate = new TurnGate({
14961
14995
  now: o.now,
@@ -14982,6 +15016,7 @@ var VoiceCall = class {
14982
15016
  earlyHeard = null;
14983
15017
  // a fill line heard while that turn was still held
14984
15018
  progressTimer = null;
15019
+ lastUserAt = -Infinity;
14985
15020
  ended = false;
14986
15021
  get o() {
14987
15022
  return this.options;
@@ -14994,6 +15029,11 @@ var VoiceCall = class {
14994
15029
  get turn() {
14995
15030
  return this.cur && { id: this.cur.id, text: this.cur.text, running: this.cur.running };
14996
15031
  }
15032
+ /** MAIN is on this turn and has the floor to itself: nothing the user says now stops it, unless they ask it to. */
15033
+ get working() {
15034
+ const c = this.cur;
15035
+ return !!c && c.running && !c.closed && (!c.worded || c.open > 0);
15036
+ }
14997
15037
  /** The host STT's language (BCP-47): the current language until the user's words say otherwise. */
14998
15038
  setLanguage(tag) {
14999
15039
  const l = primaryLang(tag);
@@ -15006,13 +15046,16 @@ var VoiceCall = class {
15006
15046
  if (this.ended || !text.trim()) return;
15007
15047
  if (typeof aec === "boolean") this.fill.options.aec = aec;
15008
15048
  this.gate.speaking();
15009
- const c = this.cur;
15010
- if (this.o.mode === "live" && c?.running && !c.worded && newWords(text, c.text) >= 2) {
15049
+ this.lastUserAt = this.o.now();
15050
+ const c = this.cur, steers = !!this.o.noteTurn && this.working;
15051
+ const resumed = !steers || c.marks.mainFirst === void 0 && this.o.now() - c.at < this.o.resumeMs;
15052
+ if (this.o.mode === "live" && c?.running && !c.worded && resumed && newWords(text, c.text) >= 2) {
15011
15053
  log31.debug("user resumed before the reply \u2014 yielded");
15012
- this.barge();
15054
+ this.giveWay(c);
15013
15055
  this.gate.reopen(c.id);
15014
15056
  }
15015
15057
  this.follow(text);
15058
+ if (this.o.noteTurn && this.working) return;
15016
15059
  this.fill.onInterim(text);
15017
15060
  }
15018
15061
  /** STT final → TurnGate. `lastWordAgoMs`: how long ago the user's last word of it ended (the STT's word clock,
@@ -15071,6 +15114,8 @@ var VoiceCall = class {
15071
15114
  if (!c.streamed) {
15072
15115
  c.streamed = true;
15073
15116
  this.gate.replyStarted(c.id);
15117
+ }
15118
+ if (c.open <= 0) {
15074
15119
  this.progress.text();
15075
15120
  this.clearProgress();
15076
15121
  }
@@ -15079,9 +15124,17 @@ var VoiceCall = class {
15079
15124
  case "tool":
15080
15125
  c.marks.mainFirst ??= this.o.now();
15081
15126
  this.gate.replyStarted(c.id);
15082
- void this.onTool(c, ev.name ?? "", ev.args);
15127
+ c.open++;
15128
+ c.streamed = false;
15129
+ if (ev.name && !isPlumbing(ev.name)) {
15130
+ c.tool = ev.name;
15131
+ c.args = ev.args;
15132
+ }
15133
+ this.progress.tool();
15134
+ this.beat(c);
15083
15135
  return;
15084
15136
  case "tool_done":
15137
+ c.open = Math.max(0, c.open - 1);
15085
15138
  return;
15086
15139
  case "audio": {
15087
15140
  const at = this.o.now() + Math.max(0, inMs);
@@ -15103,11 +15156,28 @@ var VoiceCall = class {
15103
15156
  this.clearProgress();
15104
15157
  this.fill.onAgentState("idle");
15105
15158
  if (c.worded) this.close(c, "answered");
15159
+ if (c.next) {
15160
+ const next = c.next;
15161
+ c.next = void 0;
15162
+ this.onTurn(next);
15163
+ }
15106
15164
  return;
15107
15165
  }
15108
15166
  }
15109
15167
  /** The user barged in (hard): cut fill + MAIN audio (the host cuts its own), abort a running MAIN turn. */
15110
15168
  barge() {
15169
+ if (this.o.noteTurn && this.working) {
15170
+ this.fill.onBargeIn();
15171
+ try {
15172
+ this.o.cancel();
15173
+ } catch (e) {
15174
+ log31.warn(`cancel threw: ${e.message}`);
15175
+ }
15176
+ return;
15177
+ }
15178
+ this.giveWay();
15179
+ }
15180
+ giveWay(c = this.cur) {
15111
15181
  this.fill.onBargeIn();
15112
15182
  this.clearProgress();
15113
15183
  try {
@@ -15115,11 +15185,11 @@ var VoiceCall = class {
15115
15185
  } catch (e) {
15116
15186
  log31.warn(`cancel threw: ${e.message}`);
15117
15187
  }
15118
- if (this.cur?.running) {
15119
- this.cur.running = false;
15120
- this.o.abortTurn(this.cur.id);
15188
+ if (c?.running) {
15189
+ c.running = false;
15190
+ this.o.abortTurn(c.id);
15121
15191
  }
15122
- if (this.cur && !this.cur.worded) this.cur.end ??= "cut";
15192
+ if (c && !c.worded) c.end ??= "cut";
15123
15193
  }
15124
15194
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15125
15195
  async overlap(text) {
@@ -15165,6 +15235,7 @@ var VoiceCall = class {
15165
15235
  if (l) this.fill.setLanguage(l, true);
15166
15236
  }
15167
15237
  onTurn(t) {
15238
+ if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
15168
15239
  const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
15169
15240
  const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
15170
15241
  const finalAt = this.finalAt || now3;
@@ -15173,7 +15244,7 @@ var VoiceCall = class {
15173
15244
  if (this.cur) this.close(this.cur, t.replaces === this.cur.id ? "replaced" : void 0);
15174
15245
  this.follow(t.text);
15175
15246
  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" };
15247
+ 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
15248
  const early = this.earlyHeard;
15178
15249
  this.earlyHeard = null;
15179
15250
  if (early && early.at >= at) {
@@ -15211,6 +15282,7 @@ var VoiceCall = class {
15211
15282
  c.marks.fill = this.o.now();
15212
15283
  c.fillKind = kind;
15213
15284
  }
15285
+ if (c && kind === "bridge" && this.o.mode === "live" && echoesHeard(text, c.text)) this.beat(c);
15214
15286
  if (this.o.hostAudio) return r;
15215
15287
  this.lastAudibleAt = this.o.now();
15216
15288
  if (c && forTurn) {
@@ -15248,27 +15320,78 @@ var VoiceCall = class {
15248
15320
  for (const k of Object.keys(tl)) if (tl[k] === void 0) delete tl[k];
15249
15321
  this.o.onMetric({ name: "timeline", id: c.id, text: c.text, timeline: tl });
15250
15322
  }
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;
15323
+ /** The user spoke while MAIN works: the fast model answers now, the words reach MAIN as a note, MAIN keeps going. */
15324
+ async overWork(c, t) {
15325
+ const at = this.o.now();
15326
+ this.firstFinalAt = null;
15327
+ this.lastWordAt = null;
15328
+ this.follow(t.text);
15329
+ queueMicrotask(() => this.gate.replyStarted(t.id));
15330
+ this.o.onMetric({ name: "turn", id: t.id, kind: "aside", text: t.text });
15331
+ const ac = new AbortController(), late = setTimeout(() => ac.abort(), this.o.workReplyBudgetMs), lang = this.lang;
15332
+ 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) => {
15333
+ log31.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15334
+ return "";
15335
+ }).finally(() => clearTimeout(late)) : "";
15336
+ const line = cleanWorkReply(raw, lang ?? ""), stop = /^\s*stop\s*:/i.test(raw), change = !line || /^\s*work\s*:/i.test(raw);
15337
+ 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.]`;
15338
+ if (line && !this.ended) {
15339
+ for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
15340
+ if (i === 7) {
15341
+ this.o.onMetric({ name: "drop", id: t.id, kind: "aside unplayed", text: line });
15342
+ break;
15343
+ }
15344
+ await new Promise((r) => setTimeout(r, 250));
15345
+ }
15346
+ if (this.lastAudibleAt >= at) {
15347
+ this.progress.note(line);
15348
+ this.o.show(line, "aside");
15349
+ }
15350
+ } else if (!line) this.o.onMetric({ name: "drop", id: t.id, kind: "no aside line" });
15351
+ if (stop) {
15352
+ this.o.noteTurn(noted);
15353
+ c.next = void 0;
15354
+ if (this.working && this.cur === c) this.giveWay(c);
15355
+ return;
15356
+ }
15357
+ if (change && this.cur === c && c.running) {
15358
+ c.next = c.next ? { ...c.next, text: `${c.next.text} ${t.text}` } : { ...t, kind: "new" };
15359
+ return;
15360
+ }
15361
+ if (change) return this.onTurn({ ...t, kind: "new" });
15362
+ this.o.noteTurn(noted);
15363
+ }
15364
+ /** While MAIN's tools run: a progress line once nothing was heard for `silenceMs`, then every `gapMs`, written just ahead
15365
+ * so it plays on time. Ticks are local (no network) and stop with the turn. */
15366
+ beat(c) {
15257
15367
  this.clearProgress();
15258
- const tryNow = () => {
15368
+ const tick = () => {
15259
15369
  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;
15370
+ if (this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0) return;
15371
+ const lang = this.lang, now3 = this.o.now();
15372
+ if (lang && !c.draft && !c.drafting && now3 - c.draftAt >= 1e3 && this.progress.due(this.lastAudibleAt, this.o.progressLeadMs)) {
15373
+ c.drafting = true;
15374
+ void this.progress.line(c.tool, c.args, lang, this.o.mode === "live" ? c.text : "").then((l) => {
15375
+ c.drafting = false;
15376
+ c.draft = l;
15377
+ if (!l) c.draftAt = this.o.now();
15378
+ if (!l && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${c.tool}` });
15379
+ else sayDraft();
15380
+ });
15264
15381
  }
15265
- if (this.say(line, "progress") !== false) {
15266
- this.progress.spoke(line);
15382
+ sayDraft();
15383
+ this.progressTimer = setTimeout(tick, 250);
15384
+ };
15385
+ const sayDraft = () => {
15386
+ 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)) return;
15387
+ if (this.say(c.draft, "progress") !== false) {
15388
+ this.progress.spoke(c.draft);
15267
15389
  this.fill.covered();
15268
- this.o.show(line, "progress");
15390
+ this.o.show(c.draft, "progress");
15391
+ c.draft = "";
15269
15392
  }
15270
15393
  };
15271
- tryNow();
15394
+ tick();
15272
15395
  }
15273
15396
  clearProgress() {
15274
15397
  if (this.progressTimer) {