@livx.cc/agentx 0.99.160 → 0.99.162

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
@@ -1002,6 +1002,9 @@ declare class TurnGate {
1002
1002
  text: string;
1003
1003
  started: boolean;
1004
1004
  } | undefined;
1005
+ /** The user's own line is not over: a fragment is held, or the last turn went out mid-phrase ("where is the—") within
1006
+ * `withinMs`. Their next words finish it — never a reaction to the reply. */
1007
+ unfinished(withinMs: number): boolean;
1005
1008
  /** An STT final. */
1006
1009
  final(text: string, sttId?: string): void;
1007
1010
  /** The user kept talking after turn `id` went out and before its reply made a sound: it was not over. Its words go back
@@ -1010,6 +1013,10 @@ declare class TurnGate {
1010
1013
  /** The user is speaking again (a partial — `text`, the whole partial): a held fragment waits for the rest. A partial
1011
1014
  * with words the held text lacks is more speech under way: the hold lasts until its final (≤ talkingMaxMs). */
1012
1015
  speaking(text?: string): void;
1016
+ /** A turn judge says the held `text` is a whole turn: send it now (not while they are mid-line). */
1017
+ release(text: string): boolean;
1018
+ /** A turn judge says they are not done: the held `text` waits the long hold (more speech still merges in). */
1019
+ extend(text: string): void;
1013
1020
  /** The hold's quiet ran out: send it — unless the user is mid-line (a partial with no final yet). */
1014
1021
  private settle;
1015
1022
  /** MAIN started replying to turn `id` (its first text/tool/audio): a later re-final only adds its new words. */
@@ -1693,6 +1700,12 @@ interface LaneLine {
1693
1700
  cut?: boolean;
1694
1701
  }
1695
1702
  interface QuickContext {
1703
+ /** we placed the call (fastQuickLane caller) */
1704
+ caller?: boolean;
1705
+ /** the turn judge's read of how to react (Jev: answer | ack_then_answer | backchannel | silence) */
1706
+ hint?: string;
1707
+ /** the caller's plan (CallPlan.text): opener, asks, IF <reply>: <line>, close */
1708
+ plan?: string;
1696
1709
  /** The call so far, oldest first (the turn being decided is `heard`, not in here). */
1697
1710
  history: LaneLine[];
1698
1711
  /** The user's turn, verbatim from the STT. */
@@ -1714,6 +1727,11 @@ type QuickMove =
1714
1727
  } | {
1715
1728
  kind: 'resume';
1716
1729
  line: string;
1730
+ }
1731
+ /** A quick question about the answer they just cut ("where do they sit?"), answered from its words, then the rest plays. */
1732
+ | {
1733
+ kind: 'clarify';
1734
+ line: string;
1717
1735
  } | {
1718
1736
  kind: 'quiet';
1719
1737
  };
@@ -1815,7 +1833,7 @@ interface TurnTimeline {
1815
1833
  end?: 'answered' | 'cut' | 'replaced' | 'silent';
1816
1834
  }
1817
1835
  interface CallMetric {
1818
- name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup';
1836
+ name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup' | 'judge';
1819
1837
  id?: string;
1820
1838
  /** ms from the user's last word (see TurnTimeline) */
1821
1839
  ms?: number;
@@ -1870,6 +1888,12 @@ declare class VoiceCallOptions {
1870
1888
  userLine: (text: string, how: 'quick' | 'aside' | 'kept') => void;
1871
1889
  /** The fast model (lines, banks, progress) — used only with `ai`. */
1872
1890
  fastModel: string;
1891
+ /** The turn-end judge (Instinct.turnEnd over Jev): a held final goes out at once or waits, and its read of how to
1892
+ * react reaches the quick lane. Absent → the gate's timers alone. */
1893
+ turnJudge?: (heard: string, state: Record<string, unknown>) => Promise<{
1894
+ choice: string;
1895
+ ms: number;
1896
+ } | null>;
1873
1897
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
1874
1898
  ai?: ChatLike;
1875
1899
  /** Cache dir for per-language banks (ChannelBanks). */
@@ -1921,6 +1945,9 @@ declare class VoiceCall {
1921
1945
  private cutTurn?;
1922
1946
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1923
1947
  private get o();
1948
+ /** The turn judge's last read (choice for `text`): the quick lane's hint for that turn. */
1949
+ private hint?;
1950
+ private judgeHold;
1924
1951
  /** The language the fill channel speaks right now (null = unknown → silent). */
1925
1952
  get language(): string | null;
1926
1953
  /** The MAIN turn in flight (or the last one). */
package/dist/index.js CHANGED
@@ -10664,6 +10664,9 @@ var ASIDES = {
10664
10664
  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?"] }
10665
10665
  };
10666
10666
  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;
10667
+ var WH_LEAD = "^(?:(?:oh|and|so|wait|but|ok|okay|um|uh|sorry)\\s+)*";
10668
+ var WH_QUESTION = new RegExp(WH_LEAD + "(?:who|whom|whose|where|which|why|how|when|what|\u05DE\u05D9|\u05D0\u05D9\u05E4\u05D4|\u05DC\u05DE\u05D4|\u05D0\u05D9\u05DA|\u05DE\u05EA\u05D9|\u05DE\u05D4)\\s+\\S", "u");
10669
+ var WH_EXCLAIM = new RegExp(WH_LEAD + "(?:what an? |how (?:cool|nice|fun|sweet|sad|funny|weird|crazy|strange|interesting|beautiful|lovely|cute|amazing|awesome)\\b)", "u");
10667
10670
  var isReaction = (text) => {
10668
10671
  const t = norm2(text);
10669
10672
  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"), ""));
@@ -10682,6 +10685,7 @@ function overlapRule(text) {
10682
10685
  if (!t) return void 0;
10683
10686
  if (isClosing(text)) return "cut";
10684
10687
  if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
10688
+ if (WH_QUESTION.test(t) && !REACT.test(t) && !WH_EXCLAIM.test(t)) return "cut";
10685
10689
  for (const p of PHRASES) t = t.split(p).join(" ");
10686
10690
  const words4 = t.split(/[\s-]+/).filter(Boolean);
10687
10691
  const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
@@ -10693,7 +10697,7 @@ function overlapRule(text) {
10693
10697
  function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
10694
10698
  return async (heard, signal) => {
10695
10699
  const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
10696
- Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, telling it to stop, or saying goodbye? A reaction is not steering: surprise, disbelief, "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10700
+ Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it, telling it to stop, or saying goodbye? A question about what it said ("who did that?", "where?", "which one?") IS steering. A reaction is not steering: surprise, disbelief, a lone "what?", "really?", "you're serious?", "that's serious", agreement, a laugh \u2014 the assistant just carries on.
10697
10701
  Answer yes (steering) or no (a reaction).`;
10698
10702
  const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
10699
10703
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
@@ -11134,18 +11138,18 @@ function fitsLanguage(line, lang) {
11134
11138
  return !ws.some((w) => !mine?.has(w) && Object.entries(STOP3).some(([l, s]) => l !== lang && s.has(w)));
11135
11139
  }
11136
11140
  var norm3 = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}' ]/gu, "").replace(/\s+/g, " ").trim();
11137
- function cleanLine(s, lang, maxWords = 6) {
11141
+ function cleanLine(s, lang, maxWords = 6, maxChars = 60) {
11138
11142
  if (/^(?:gasp|quiet|laughter)[.!?…]*$/i.test(s.trim())) return "";
11139
11143
  const first = s.trim().split("\n")[0];
11140
11144
  const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
11141
11145
  const raw = first.replace(LINE_TAG, " ").trim();
11142
11146
  if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
11143
- const words4 = cleanWords(raw, lang, maxWords);
11147
+ const words4 = cleanWords(raw, lang, maxWords, maxChars);
11144
11148
  return words4 && tags ? `${tags} ${words4}` : words4;
11145
11149
  }
11146
11150
  var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
11147
11151
  var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
11148
- function cleanWords(raw, lang, maxWords) {
11152
+ function cleanWords(raw, lang, maxWords, maxChars = 60) {
11149
11153
  const l = raw.replace(/^[-*•\d.)\s]+/, "").replace(/^["'“”«»]+|["'“”«»]+$/g, "").replace(new RegExp("^\\p{L}+:\\s*", "u"), "").trim();
11150
11154
  if (!l || isLeakSuspect(raw) || isLeakSuspect(l)) {
11151
11155
  if (l) log24.debug(`line "${raw}" reads as meta \u2014 rejected`);
@@ -11155,7 +11159,7 @@ function cleanWords(raw, lang, maxWords) {
11155
11159
  log24.debug(`line "${l}" is not ${lang} \u2014 rejected`);
11156
11160
  return "";
11157
11161
  }
11158
- return l.split(/\s+/).length > maxWords || l.length > 60 ? "" : l;
11162
+ return l.split(/\s+/).length > maxWords || l.length > maxChars ? "" : l;
11159
11163
  }
11160
11164
  var SPEAKER_FILLER = /^(?:so|well|actually|basically|anyway|anyways|like|you know|i mean|kind of|sort of|literally|honestly|and|but|because|then|the thing is)\b/i;
11161
11165
  function validateBank(raw, lang, minPerKind = 3) {
@@ -11401,6 +11405,11 @@ var TurnGate = class {
11401
11405
  get lastTurn() {
11402
11406
  return this.last && { id: this.last.id, text: this.last.text, started: this.last.started };
11403
11407
  }
11408
+ /** The user's own line is not over: a fragment is held, or the last turn went out mid-phrase ("where is the—") within
11409
+ * `withinMs`. Their next words finish it — never a reaction to the reply. */
11410
+ unfinished(withinMs) {
11411
+ return !!this.held || !!this.last && endsMidPhrase(this.last.text) && this.o.now() - this.last.at < withinMs;
11412
+ }
11404
11413
  /** An STT final. */
11405
11414
  final(text, sttId) {
11406
11415
  let t = text.trim(), replaces;
@@ -11447,6 +11456,21 @@ var TurnGate = class {
11447
11456
  clearTimeout(h.timer);
11448
11457
  h.timer = setTimeout(() => this.settle(), h.ms);
11449
11458
  }
11459
+ /** A turn judge says the held `text` is a whole turn: send it now (not while they are mid-line). */
11460
+ release(text) {
11461
+ const h = this.held;
11462
+ if (!h || h.talking || norm3(h.text) !== norm3(text)) return false;
11463
+ this.flush();
11464
+ return true;
11465
+ }
11466
+ /** A turn judge says they are not done: the held `text` waits the long hold (more speech still merges in). */
11467
+ extend(text) {
11468
+ const h = this.held;
11469
+ if (!h || norm3(h.text) !== norm3(text) || h.ms >= this.o.holdMs) return;
11470
+ h.ms = this.o.holdMs;
11471
+ clearTimeout(h.timer);
11472
+ h.timer = setTimeout(() => this.settle(), h.ms);
11473
+ }
11450
11474
  /** The hold's quiet ran out: send it — unless the user is mid-line (a partial with no final yet). */
11451
11475
  settle() {
11452
11476
  const h = this.held;
@@ -11481,7 +11505,7 @@ var TurnGate = class {
11481
11505
  }
11482
11506
  }
11483
11507
  refinal(last, t, key, sttId) {
11484
- if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
11508
+ if (!last.started || endsMidPhrase(last.text)) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
11485
11509
  const a = words2(last.text), b = words2(t);
11486
11510
  let i = 0;
11487
11511
  while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
@@ -14530,6 +14554,7 @@ var SecondChannel = class {
14530
14554
  const preset = CHANNEL_MODES[options?.mode ?? "normal"] ?? {};
14531
14555
  const base = new SecondChannelOptions();
14532
14556
  this.options = { ...base, ...preset, ...options };
14557
+ if (process.env.AGENTX_CALL_ROLE === "caller") this.options.kinds = (this.options.kinds ?? []).filter((k) => k === "backchannel");
14533
14558
  for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
14534
14559
  this.startedAt = this.o.now();
14535
14560
  if (this.o.lang) this.setLanguage(this.o.lang, true);
@@ -15292,6 +15317,9 @@ var VoiceCallOptions = class {
15292
15317
  };
15293
15318
  /** The fast model (lines, banks, progress) — used only with `ai`. */
15294
15319
  fastModel = latestClaude("haiku");
15320
+ /** The turn-end judge (Instinct.turnEnd over Jev): a held final goes out at once or waits, and its read of how to
15321
+ * react reaches the quick lane. Absent → the gate's timers alone. */
15322
+ turnJudge;
15295
15323
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
15296
15324
  ai;
15297
15325
  /** Cache dir for per-language banks (ChannelBanks). */
@@ -15367,7 +15395,10 @@ var VoiceCall = class {
15367
15395
  ...o.gate,
15368
15396
  onTurn: (t) => this.onTurn(t),
15369
15397
  onDrop: (text, why) => this.onDrop(text, why),
15370
- onHold: (text) => o.onMetric({ name: "hold", text })
15398
+ onHold: (text) => {
15399
+ o.onMetric({ name: "hold", text });
15400
+ this.judgeHold(text);
15401
+ }
15371
15402
  });
15372
15403
  }
15373
15404
  options;
@@ -15396,6 +15427,20 @@ var VoiceCall = class {
15396
15427
  get o() {
15397
15428
  return this.options;
15398
15429
  }
15430
+ /** The turn judge's last read (choice for `text`): the quick lane's hint for that turn. */
15431
+ hint;
15432
+ judgeHold(text) {
15433
+ const j = this.o.turnJudge;
15434
+ if (!j || this.ended) return;
15435
+ const said = [...this.history].reverse().find((h) => h.who === "you")?.text;
15436
+ j(text, { agent_last_said: said ?? null, agent_speaking: !!this.cur?.running }).then((d) => {
15437
+ if (!d) return;
15438
+ this.hint = { text, choice: d.choice };
15439
+ const go = d.choice === "answer" || d.choice === "ack_then_answer" || d.choice === "silence";
15440
+ const acted = go ? this.gate.release(text) ? "released" : "late" : (this.gate.extend(text), "extended");
15441
+ this.o.onMetric({ name: "judge", ms: d.ms, kind: `${d.choice} ${acted}`, text });
15442
+ }).catch((e) => log32.warn(`turn judge failed \u2014 the gate's timers decide: ${e?.message ?? e}`));
15443
+ }
15399
15444
  /** The language the fill channel speaks right now (null = unknown → silent). */
15400
15445
  get language() {
15401
15446
  return this.lang;
@@ -15581,6 +15626,10 @@ var VoiceCall = class {
15581
15626
  }
15582
15627
  /** Soft barge-in: keep (a listener cue — no turn) or cut (→ barge()). */
15583
15628
  async overlap(text) {
15629
+ if (this.gate.unfinished(UNFINISHED_MS)) {
15630
+ this.barge();
15631
+ return "cut";
15632
+ }
15584
15633
  if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
15585
15634
  const d = await this.judge.judge(text);
15586
15635
  if (d.verdict === "cut") this.barge();
@@ -15716,7 +15765,7 @@ var VoiceCall = class {
15716
15765
  const ac = new AbortController(), t0 = this.o.now(), lang = this.lang, rest = this.cutRest;
15717
15766
  c.ask = ac;
15718
15767
  const late = setTimeout(() => ac.abort(), this.o.quickBudgetMs);
15719
- const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest }, ac.signal).catch((e) => {
15768
+ const mv = lang ? await this.o.quick({ history: this.history.slice(0, -1), heard: t.text, lang, rest, ...this.hint && t.text.includes(this.hint.text) ? { hint: this.hint.choice } : {} }, ac.signal).catch((e) => {
15720
15769
  if (this.cur === c) log32.warn(`quick lane ${ac.signal.aborted ? `late (${this.o.quickBudgetMs}ms)` : `failed: ${e?.message ?? e}`} \u2014 deep lane`);
15721
15770
  return null;
15722
15771
  }).finally(() => clearTimeout(late)) : null;
@@ -15748,7 +15797,8 @@ var VoiceCall = class {
15748
15797
  c.due = false;
15749
15798
  return this.close(c, "silent");
15750
15799
  }
15751
- 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;
15800
+ const cutAt = () => cutSentence([...this.history].reverse().find((h) => h.who === "you" && h.cut)?.text ?? "");
15801
+ const said = mv.kind === "resume" ? `${mv.line} ${cutAt()} ${rest}`.replace(/\s+/g, " ").trim() : mv.kind === "clarify" ? `${mv.line} ${lang && BACK_TO[lang] || ""} ${cutAt()} ${rest}`.replace(/\s+/g, " ").trim() : mv.line;
15752
15802
  this.gate.replyStarted(c.id);
15753
15803
  const end = mv.kind === "say" && !!mv.end;
15754
15804
  if (end) try {
@@ -15764,6 +15814,11 @@ var VoiceCall = class {
15764
15814
  this.o.dropCut?.();
15765
15815
  this.history.push({ who: "you", text: rest });
15766
15816
  note(`They asked you to go on, and you continued your cut answer aloud: "${rest}". All of it has now been said.`);
15817
+ } else if (mv.kind === "clarify") {
15818
+ this.cutRest = "";
15819
+ this.o.dropCut?.();
15820
+ this.history.push({ who: "you", text: mv.line }, { who: "you", text: rest });
15821
+ note(`They cut your answer to ask "${t.text}". You (the call's quick voice) answered aloud "${mv.line}" and then continued your cut answer: "${rest}". All of it has now been said.`);
15767
15822
  } else {
15768
15823
  this.history.push({ who: "you", text: said });
15769
15824
  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.`);
@@ -15952,6 +16007,8 @@ var VoiceCall = class {
15952
16007
  }
15953
16008
  }
15954
16009
  };
16010
+ var UNFINISHED_MS = 8e3;
16011
+ var BACK_TO = { en: "Anyway,", he: "\u05D1\u05DB\u05DC \u05DE\u05E7\u05E8\u05D4," };
15955
16012
  function cutSentence(heard) {
15956
16013
  const tail = heard.trim().split(/(?<=[.!?…])\s+/).at(-1) ?? "";
15957
16014
  if (!tail || /[.!?…]["'”’)]*$/.test(tail)) return "";