@livx.cc/agentx 0.99.159 → 0.99.161

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
@@ -1010,6 +1010,10 @@ declare class TurnGate {
1010
1010
  /** The user is speaking again (a partial — `text`, the whole partial): a held fragment waits for the rest. A partial
1011
1011
  * with words the held text lacks is more speech under way: the hold lasts until its final (≤ talkingMaxMs). */
1012
1012
  speaking(text?: string): void;
1013
+ /** A turn judge says the held `text` is a whole turn: send it now (not while they are mid-line). */
1014
+ release(text: string): boolean;
1015
+ /** A turn judge says they are not done: the held `text` waits the long hold (more speech still merges in). */
1016
+ extend(text: string): void;
1013
1017
  /** The hold's quiet ran out: send it — unless the user is mid-line (a partial with no final yet). */
1014
1018
  private settle;
1015
1019
  /** MAIN started replying to turn `id` (its first text/tool/audio): a later re-final only adds its new words. */
@@ -1693,6 +1697,12 @@ interface LaneLine {
1693
1697
  cut?: boolean;
1694
1698
  }
1695
1699
  interface QuickContext {
1700
+ /** we placed the call (fastQuickLane caller) */
1701
+ caller?: boolean;
1702
+ /** the turn judge's read of how to react (Jev: answer | ack_then_answer | backchannel | silence) */
1703
+ hint?: string;
1704
+ /** the caller's plan (CallPlan.text): opener, asks, IF <reply>: <line>, close */
1705
+ plan?: string;
1696
1706
  /** The call so far, oldest first (the turn being decided is `heard`, not in here). */
1697
1707
  history: LaneLine[];
1698
1708
  /** The user's turn, verbatim from the STT. */
@@ -1714,6 +1724,11 @@ type QuickMove =
1714
1724
  } | {
1715
1725
  kind: 'resume';
1716
1726
  line: string;
1727
+ }
1728
+ /** A quick question about the answer they just cut ("where do they sit?"), answered from its words, then the rest plays. */
1729
+ | {
1730
+ kind: 'clarify';
1731
+ line: string;
1717
1732
  } | {
1718
1733
  kind: 'quiet';
1719
1734
  };
@@ -1815,7 +1830,7 @@ interface TurnTimeline {
1815
1830
  end?: 'answered' | 'cut' | 'replaced' | 'silent';
1816
1831
  }
1817
1832
  interface CallMetric {
1818
- name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup';
1833
+ name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup' | 'judge';
1819
1834
  id?: string;
1820
1835
  /** ms from the user's last word (see TurnTimeline) */
1821
1836
  ms?: number;
@@ -1870,6 +1885,12 @@ declare class VoiceCallOptions {
1870
1885
  userLine: (text: string, how: 'quick' | 'aside' | 'kept') => void;
1871
1886
  /** The fast model (lines, banks, progress) — used only with `ai`. */
1872
1887
  fastModel: string;
1888
+ /** The turn-end judge (Instinct.turnEnd over Jev): a held final goes out at once or waits, and its read of how to
1889
+ * react reaches the quick lane. Absent → the gate's timers alone. */
1890
+ turnJudge?: (heard: string, state: Record<string, unknown>) => Promise<{
1891
+ choice: string;
1892
+ ms: number;
1893
+ } | null>;
1873
1894
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
1874
1895
  ai?: ChatLike;
1875
1896
  /** Cache dir for per-language banks (ChannelBanks). */
@@ -1921,6 +1942,9 @@ declare class VoiceCall {
1921
1942
  private cutTurn?;
1922
1943
  constructor(options?: Partial<VoiceCallOptions> | undefined);
1923
1944
  private get o();
1945
+ /** The turn judge's last read (choice for `text`): the quick lane's hint for that turn. */
1946
+ private hint?;
1947
+ private judgeHold;
1924
1948
  /** The language the fill channel speaks right now (null = unknown → silent). */
1925
1949
  get language(): string | null;
1926
1950
  /** The MAIN turn in flight (or the last one). */
package/dist/index.js CHANGED
@@ -3955,7 +3955,7 @@ var PermissionPolicy = class {
3955
3955
  if (this.options.default !== "deny") return void 0;
3956
3956
  const gate = async (input) => {
3957
3957
  const t = input?.tool_input ?? {}, path = t.file_path ?? t.notebook_path ?? t.path;
3958
- const d = this.decide({ name: String(input?.tool_name ?? ""), args: { ...t, ...typeof path === "string" ? { path } : {} } });
3958
+ const d = this.decide({ name: String(input?.tool_name ?? "").replace(/^mcp__agentx__/, ""), args: { ...t, ...typeof path === "string" ? { path } : {} } });
3959
3959
  return d === "allow" ? {} : { hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: `not on this run's tool allow-list (${input?.tool_name})` } };
3960
3960
  };
3961
3961
  return { PreToolUse: [{ hooks: [gate] }] };
@@ -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) {
@@ -11447,6 +11451,21 @@ var TurnGate = class {
11447
11451
  clearTimeout(h.timer);
11448
11452
  h.timer = setTimeout(() => this.settle(), h.ms);
11449
11453
  }
11454
+ /** A turn judge says the held `text` is a whole turn: send it now (not while they are mid-line). */
11455
+ release(text) {
11456
+ const h = this.held;
11457
+ if (!h || h.talking || norm3(h.text) !== norm3(text)) return false;
11458
+ this.flush();
11459
+ return true;
11460
+ }
11461
+ /** A turn judge says they are not done: the held `text` waits the long hold (more speech still merges in). */
11462
+ extend(text) {
11463
+ const h = this.held;
11464
+ if (!h || norm3(h.text) !== norm3(text) || h.ms >= this.o.holdMs) return;
11465
+ h.ms = this.o.holdMs;
11466
+ clearTimeout(h.timer);
11467
+ h.timer = setTimeout(() => this.settle(), h.ms);
11468
+ }
11450
11469
  /** The hold's quiet ran out: send it — unless the user is mid-line (a partial with no final yet). */
11451
11470
  settle() {
11452
11471
  const h = this.held;
@@ -14530,6 +14549,7 @@ var SecondChannel = class {
14530
14549
  const preset = CHANNEL_MODES[options?.mode ?? "normal"] ?? {};
14531
14550
  const base = new SecondChannelOptions();
14532
14551
  this.options = { ...base, ...preset, ...options };
14552
+ if (process.env.AGENTX_CALL_ROLE === "caller") this.options.kinds = (this.options.kinds ?? []).filter((k) => k === "backchannel");
14533
14553
  for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
14534
14554
  this.startedAt = this.o.now();
14535
14555
  if (this.o.lang) this.setLanguage(this.o.lang, true);
@@ -15292,6 +15312,9 @@ var VoiceCallOptions = class {
15292
15312
  };
15293
15313
  /** The fast model (lines, banks, progress) — used only with `ai`. */
15294
15314
  fastModel = latestClaude("haiku");
15315
+ /** The turn-end judge (Instinct.turnEnd over Jev): a held final goes out at once or waits, and its read of how to
15316
+ * react reaches the quick lane. Absent → the gate's timers alone. */
15317
+ turnJudge;
15295
15318
  /** Model client for the fast model + the channel decider / overlap judge. Absent → canned lines and rules only. */
15296
15319
  ai;
15297
15320
  /** Cache dir for per-language banks (ChannelBanks). */
@@ -15367,7 +15390,10 @@ var VoiceCall = class {
15367
15390
  ...o.gate,
15368
15391
  onTurn: (t) => this.onTurn(t),
15369
15392
  onDrop: (text, why) => this.onDrop(text, why),
15370
- onHold: (text) => o.onMetric({ name: "hold", text })
15393
+ onHold: (text) => {
15394
+ o.onMetric({ name: "hold", text });
15395
+ this.judgeHold(text);
15396
+ }
15371
15397
  });
15372
15398
  }
15373
15399
  options;
@@ -15396,6 +15422,20 @@ var VoiceCall = class {
15396
15422
  get o() {
15397
15423
  return this.options;
15398
15424
  }
15425
+ /** The turn judge's last read (choice for `text`): the quick lane's hint for that turn. */
15426
+ hint;
15427
+ judgeHold(text) {
15428
+ const j = this.o.turnJudge;
15429
+ if (!j || this.ended) return;
15430
+ const said = [...this.history].reverse().find((h) => h.who === "you")?.text;
15431
+ j(text, { agent_last_said: said ?? null, agent_speaking: !!this.cur?.running }).then((d) => {
15432
+ if (!d) return;
15433
+ this.hint = { text, choice: d.choice };
15434
+ const go = d.choice === "answer" || d.choice === "ack_then_answer" || d.choice === "silence";
15435
+ const acted = go ? this.gate.release(text) ? "released" : "late" : (this.gate.extend(text), "extended");
15436
+ this.o.onMetric({ name: "judge", ms: d.ms, kind: `${d.choice} ${acted}`, text });
15437
+ }).catch((e) => log32.warn(`turn judge failed \u2014 the gate's timers decide: ${e?.message ?? e}`));
15438
+ }
15399
15439
  /** The language the fill channel speaks right now (null = unknown → silent). */
15400
15440
  get language() {
15401
15441
  return this.lang;
@@ -15716,7 +15756,7 @@ var VoiceCall = class {
15716
15756
  const ac = new AbortController(), t0 = this.o.now(), lang = this.lang, rest = this.cutRest;
15717
15757
  c.ask = ac;
15718
15758
  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) => {
15759
+ 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
15760
  if (this.cur === c) log32.warn(`quick lane ${ac.signal.aborted ? `late (${this.o.quickBudgetMs}ms)` : `failed: ${e?.message ?? e}`} \u2014 deep lane`);
15721
15761
  return null;
15722
15762
  }).finally(() => clearTimeout(late)) : null;
@@ -15748,7 +15788,8 @@ var VoiceCall = class {
15748
15788
  c.due = false;
15749
15789
  return this.close(c, "silent");
15750
15790
  }
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;
15791
+ const cutAt = () => cutSentence([...this.history].reverse().find((h) => h.who === "you" && h.cut)?.text ?? "");
15792
+ 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
15793
  this.gate.replyStarted(c.id);
15753
15794
  const end = mv.kind === "say" && !!mv.end;
15754
15795
  if (end) try {
@@ -15764,6 +15805,11 @@ var VoiceCall = class {
15764
15805
  this.o.dropCut?.();
15765
15806
  this.history.push({ who: "you", text: rest });
15766
15807
  note(`They asked you to go on, and you continued your cut answer aloud: "${rest}". All of it has now been said.`);
15808
+ } else if (mv.kind === "clarify") {
15809
+ this.cutRest = "";
15810
+ this.o.dropCut?.();
15811
+ this.history.push({ who: "you", text: mv.line }, { who: "you", text: rest });
15812
+ 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
15813
  } else {
15768
15814
  this.history.push({ who: "you", text: said });
15769
15815
  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 +15998,7 @@ var VoiceCall = class {
15952
15998
  }
15953
15999
  }
15954
16000
  };
16001
+ var BACK_TO = { en: "Anyway,", he: "\u05D1\u05DB\u05DC \u05DE\u05E7\u05E8\u05D4," };
15955
16002
  function cutSentence(heard) {
15956
16003
  const tail = heard.trim().split(/(?<=[.!?…])\s+/).at(-1) ?? "";
15957
16004
  if (!tail || /[.!?…]["'”’)]*$/.test(tail)) return "";