@livx.cc/agentx 0.99.148 → 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/cli.js CHANGED
@@ -10515,6 +10515,7 @@ var OverlapJudge = class {
10515
10515
  };
10516
10516
  const rule = overlapRule(heard);
10517
10517
  if (rule) return done(rule, "rule");
10518
+ if (norm2(heard).split(/[\s-]+/).filter(Boolean).length < 2) return done("keep", "lone");
10518
10519
  if (!this.o.model) return done("cut", "none");
10519
10520
  const ctl = new AbortController();
10520
10521
  let timer;
@@ -14328,8 +14329,10 @@ var ProgressOptions = class {
14328
14329
  generateBudgetMs = 800;
14329
14330
  /** Speak only when nothing has been audible for this long. */
14330
14331
  silenceMs = 3e3;
14331
- /** At most one progress line per this long. */
14332
+ /** At most one spoken work line (progress, bridge or aside) per this long. */
14332
14333
  gapMs = 4e3;
14334
+ /** One stage (a tool's topic) gets one line; a stage still running after this long may get another. 0 = 3 × gapMs. */
14335
+ stageRepeatMs = 0;
14333
14336
  now = () => performance.now();
14334
14337
  };
14335
14338
  function argsHint(args) {
@@ -14347,6 +14350,7 @@ var Progress = class {
14347
14350
  lastAt = -Infinity;
14348
14351
  streamed = false;
14349
14352
  lines = [];
14353
+ stages = /* @__PURE__ */ new Map();
14350
14354
  get o() {
14351
14355
  return this.options;
14352
14356
  }
@@ -14363,15 +14367,25 @@ var Progress = class {
14363
14367
  this.streamed = false;
14364
14368
  }
14365
14369
  /** May a line play now, or `leadMs` from now? (the caller passes when the user last heard anything) */
14366
- due(lastAudibleAt, leadMs = 0) {
14367
- const now4 = this.o.now();
14370
+ due(lastAudibleAt, leadMs = 0, tool = "") {
14371
+ const now4 = this.o.now(), spoken = tool ? this.stages.get(this.stage(tool)) : void 0;
14372
+ if (spoken !== void 0 && now4 - spoken < (this.o.stageRepeatMs || 3 * this.o.gapMs) - leadMs) return false;
14368
14373
  return !this.streamed && now4 - lastAudibleAt >= this.o.silenceMs - leadMs && now4 - this.lastAt >= this.o.gapMs - leadMs;
14369
14374
  }
14370
- /** Mark `line` spoken. */
14371
- spoke(line) {
14375
+ /** Mark `line` spoken, for `tool`'s stage. */
14376
+ spoke(line, tool = "") {
14372
14377
  this.note(line);
14378
+ this.heard();
14379
+ if (tool) this.stages.set(this.stage(tool), this.o.now());
14380
+ }
14381
+ /** A work line played from elsewhere (a bridge, an aside): the same thought, so the gap counts from it. */
14382
+ heard() {
14373
14383
  this.lastAt = this.o.now();
14374
14384
  }
14385
+ stage(tool) {
14386
+ const n = tool.toLowerCase();
14387
+ return TOPICS.find(([re]) => re.test(n))?.[1] ?? n;
14388
+ }
14375
14389
  /** A line the user heard from elsewhere (an aside): progress never repeats it. */
14376
14390
  note(line) {
14377
14391
  this.said.add(norm3(line));
@@ -14418,9 +14432,16 @@ function fastProgressGenerator(ai, model, gender) {
14418
14432
  return r.content ?? "";
14419
14433
  };
14420
14434
  }
14435
+ 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;
14436
+ var claimsResult = (l) => RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || WORK_CLAIM.test(l);
14421
14437
  function cleanWorkReply(raw, lang) {
14422
14438
  const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14423
- return RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? "" : l;
14439
+ return claimsResult(l) ? "" : l;
14440
+ }
14441
+ function workAck(raw, lang, gender = "") {
14442
+ const l = cleanLine(raw.replace(/^\s*(?:stop|work)\s*:/i, ""), lang, 8);
14443
+ if (!l || !claimsResult(l)) return "";
14444
+ return (PROGRESS_TEMPLATES[gender ? `${lang}-${gender[0]}` : lang] ?? PROGRESS_TEMPLATES[lang])?.delegate[1] ?? "";
14424
14445
  }
14425
14446
  function fastWorkReply(ai, model, gender, persona = "") {
14426
14447
  return async (c, signal) => {
@@ -14428,7 +14449,7 @@ function fastWorkReply(ai, model, gender, persona = "") {
14428
14449
  ${persona.slice(0, 500)}
14429
14450
 
14430
14451
  ` : ""}You are on a live voice call, in the middle of doing this for them: "${c.request.slice(-160)}"${c.tool ? ` (right now: ${c.tool}${c.hint ? ` on ${c.hint}` : ""})` : ""}. They just said, while you work: "${c.heard.slice(-200)}"
14431
- Answer them at once with ONE short spoken line of 2-7 words in ${languageName(c.lang)}, the way a person busy on it would ("yeah, looking now"). You have no results yet: state none, promise none. ` + (c.avoid.length ? `Do not reuse: ${c.avoid.map((a) => `"${a}"`).join(", ")}. ` : "") + `If they tell you to stop or drop the work, start the line with "stop:". If they change the request or add to it, start it with "work:". ${personaHint(gender)} Output only the line, no tone tag.`;
14452
+ Answer them at once with ONE short spoken line of 2-7 words in ${languageName(c.lang)}, the way a person busy on it would ("yeah, looking now"). You have NO results yet and cannot know any: only acknowledge the work, never say what was or was not found, not even "nothing yet" or "none so far". ` + (c.avoid.length ? `Do not reuse: ${c.avoid.map((a) => `"${a}"`).join(", ")}. ` : "") + `If they tell you to stop or drop the work, start the line with "stop:". If they change the request or add to it, start it with "work:". ${personaHint(gender)} Output only the line, no tone tag.`;
14432
14453
  const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
14433
14454
  const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
14434
14455
  return r.content ?? "";
@@ -14598,6 +14619,11 @@ var SecondChannelOptions = class {
14598
14619
  random = Math.random;
14599
14620
  };
14600
14621
  var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
14622
+ var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
14623
+ var onlyHesitation = (s) => {
14624
+ const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
14625
+ return !!w.length && w.every((x) => HESITATION.test(x));
14626
+ };
14601
14627
  function withBudget(p, ms, what, ac) {
14602
14628
  let t;
14603
14629
  const late = new Promise((r) => {
@@ -15216,6 +15242,7 @@ var SecondChannel = class {
15216
15242
  return p;
15217
15243
  }
15218
15244
  say(kind, text) {
15245
+ if (kind === "backchannel" && onlyHesitation(this.heard)) return false;
15219
15246
  let r;
15220
15247
  try {
15221
15248
  r = this.o.speak(text, kind);
@@ -15681,6 +15708,7 @@ var VoiceCall = class {
15681
15708
  }
15682
15709
  if (r === false) return false;
15683
15710
  this.o.onMetric({ name: "fill", kind, text, lang: this.lang });
15711
+ if (kind !== "backchannel") this.progress.heard();
15684
15712
  const c = this.cur && !this.cur.closed ? this.cur : void 0;
15685
15713
  const forTurn = !!c && (kind === "bridge" || kind === "progress" || kind === "filler" && c.running && !c.sounded);
15686
15714
  if (c && forTurn && c.marks.fill === void 0) {
@@ -15738,7 +15766,7 @@ var VoiceCall = class {
15738
15766
  log30.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
15739
15767
  return "";
15740
15768
  }).finally(() => clearTimeout(late)) : "";
15741
- const line = cleanWorkReply(raw, lang ?? ""), stop = /^\s*stop\s*:/i.test(raw), change = !line || /^\s*work\s*:/i.test(raw);
15769
+ 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);
15742
15770
  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.]`;
15743
15771
  if (line && !this.ended) {
15744
15772
  for (let i = 0; i < 8 && this.say(line, "aside") === false; i++) {
@@ -15774,7 +15802,7 @@ var VoiceCall = class {
15774
15802
  this.progressTimer = null;
15775
15803
  if (this.ended || this.cur !== c || !c.running || c.streamed && c.open <= 0) return;
15776
15804
  const lang = this.lang, now4 = this.o.now();
15777
- if (lang && !c.draft && !c.drafting && now4 - c.draftAt >= 1e3 && this.progress.due(this.lastAudibleAt, this.o.progressLeadMs)) {
15805
+ if (lang && !c.draft && !c.drafting && now4 - c.draftAt >= 1e3 && this.progress.due(this.lastAudibleAt, this.o.progressLeadMs, c.tool)) {
15778
15806
  c.drafting = true;
15779
15807
  void this.progress.line(c.tool, c.args, lang, this.o.mode === "live" ? c.text : "").then((l) => {
15780
15808
  c.drafting = false;
@@ -15788,9 +15816,9 @@ var VoiceCall = class {
15788
15816
  this.progressTimer = setTimeout(tick, 250);
15789
15817
  };
15790
15818
  const sayDraft = () => {
15791
- 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;
15819
+ 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;
15792
15820
  if (this.say(c.draft, "progress") !== false) {
15793
- this.progress.spoke(c.draft);
15821
+ this.progress.spoke(c.draft, c.tool);
15794
15822
  this.fill.covered();
15795
15823
  this.o.show(c.draft, "progress");
15796
15824
  c.draft = "";
@@ -17451,7 +17479,7 @@ var VoiceIO = class extends VoiceEngine {
17451
17479
  ...o,
17452
17480
  stt: o.stt ?? new SonioxSTT({ auth: o.sonioxApiKey, source: duplex ?? new NodeMicSource(), terms: o.sttTerms }),
17453
17481
  tts: o.tts ?? new CartesiaTTS({ auth: o.cartesiaApiKey, voiceId: o.cartesiaVoiceId }),
17454
- asideTts: o.tts ? null : new CartesiaTTS({ auth: o.cartesiaApiKey, voiceId: o.cartesiaVoiceId }),
17482
+ asideTts: o.tts ? o.asideTts : new CartesiaTTS({ auth: o.cartesiaApiKey, voiceId: o.cartesiaVoiceId }),
17455
17483
  // asides (VoiceCall.aside): a 2nd client — the reply's context may still stream
17456
17484
  player: o.player ?? duplex ?? new Player(),
17457
17485
  bargeRmsMult: Number(process.env.BARGE_RMS_MULT || o.bargeRmsMult),
@@ -17529,8 +17557,89 @@ function fakeVoiceParts(uttFile) {
17529
17557
  }, write() {
17530
17558
  }, drainMs: () => 0, playedMs: () => 0, kill() {
17531
17559
  } };
17560
+ if (process.env.AGENTX_VOICE_FAKE_TAPE) return { stt, ...fakeTape(process.env.AGENTX_VOICE_FAKE_TAPE, said) };
17532
17561
  return { stt, tts, player };
17533
17562
  }
17563
+ function fakeTape(heardFile, saidFile) {
17564
+ const CHAR = TTS_SAMPLE_RATE * 2 * 60 / 1e3;
17565
+ const makeTts = () => {
17566
+ const t = {
17567
+ connect() {
17568
+ },
17569
+ newContext() {
17570
+ },
17571
+ cancel() {
17572
+ },
17573
+ close() {
17574
+ },
17575
+ onAudio: (_) => {
17576
+ },
17577
+ onDone: () => {
17578
+ },
17579
+ speak(text, more = true) {
17580
+ if (saidFile) appendFileSync(saidFile, JSON.stringify({ t: Date.now(), speak: text }) + "\n");
17581
+ const pcm = new Uint8Array(text.length * CHAR), v = new DataView(pcm.buffer);
17582
+ for (let i = 0; i < text.length; i++) for (let b = 0; b < CHAR; b += 2) v.setUint16(i * CHAR + b, text.charCodeAt(i), true);
17583
+ setTimeout(() => {
17584
+ t.onAudio(pcm);
17585
+ if (!more) t.end();
17586
+ }, 5);
17587
+ },
17588
+ end() {
17589
+ setTimeout(() => t.onDone?.(), 20);
17590
+ }
17591
+ };
17592
+ return t;
17593
+ };
17594
+ let q2 = new Uint8Array(0), played = 0, paused = false, last = -1;
17595
+ const mark = (m) => appendFileSync(heardFile, m);
17596
+ const flush = () => {
17597
+ q2 = new Uint8Array(0);
17598
+ played = 0;
17599
+ paused = false;
17600
+ last = -1;
17601
+ };
17602
+ setInterval(() => {
17603
+ if (paused || !q2.length) return;
17604
+ const n = Math.min(TTS_SAMPLE_RATE * 2 * 20 / 1e3, q2.length);
17605
+ let out = "", p = played;
17606
+ for (let i = 0; i < n; i += 2, p += 2) if (Math.floor(p / CHAR) !== last) {
17607
+ last = Math.floor(p / CHAR);
17608
+ out += String.fromCharCode(q2[i] | q2[i + 1] << 8);
17609
+ }
17610
+ q2 = q2.subarray(n);
17611
+ played += n;
17612
+ if (out) mark(out);
17613
+ }, 20).unref();
17614
+ const player = {
17615
+ markTurn() {
17616
+ if (q2.length) mark("\u2702");
17617
+ flush();
17618
+ mark("\n");
17619
+ },
17620
+ write(c) {
17621
+ const a = new Uint8Array(q2.length + c.length);
17622
+ a.set(q2);
17623
+ a.set(c, q2.length);
17624
+ q2 = a;
17625
+ },
17626
+ drainMs: () => q2.length / (TTS_SAMPLE_RATE * 2 / 1e3),
17627
+ playedMs: () => played / (TTS_SAMPLE_RATE * 2 / 1e3),
17628
+ kill() {
17629
+ if (q2.length) mark("\u2702");
17630
+ flush();
17631
+ },
17632
+ pause() {
17633
+ paused = true;
17634
+ mark("\u23F8");
17635
+ },
17636
+ resume() {
17637
+ if (paused) mark("\u25B6");
17638
+ paused = false;
17639
+ }
17640
+ };
17641
+ return { tts: makeTts(), asideTts: makeTts(), player };
17642
+ }
17534
17643
 
17535
17644
  // src/voice/diagSink.ts
17536
17645
  init_logging();
@@ -17589,6 +17698,60 @@ var JsonlDiagSink = class {
17589
17698
  }
17590
17699
  };
17591
17700
 
17701
+ // src/voice/spokenFilter.ts
17702
+ var SPOKEN_TURN = "Your reply is spoken aloud: answer in one to three short plain sentences \u2014 no markdown, headings, lists, links or code, and no sources line even when a tool asks you to cite them (offer to send them if asked) \u2014 and offer more detail only if asked.";
17703
+ var HEADS = ["sources", "source", "references", "citations", "links"];
17704
+ var MARKS = String.raw`[#*_>\s-]*`;
17705
+ var SOURCES = new RegExp(String.raw`(^|\n|[.!?…]\s)${MARKS}(?:${HEADS.join("|")})${MARKS}[::]`, "i");
17706
+ var LINK = /\[([^\]\n]*)\]\([^)\s]*\)/g;
17707
+ var URL_RE = /(?:https?:\/\/|www\.)[^\s)\]]+/gi;
17708
+ var OPEN_LINK = /\[[^\]\n]*(?:\](?:\([^)\s]*)?)?$/;
17709
+ var OPEN_URL = /(?:^|\s)(?:h|ht|htt|http|https|https?:|https?:\/?|w|ww|www|(?:https?:\/\/|www\.)\S*)$/i;
17710
+ var OPEN_HEAD = new RegExp(String.raw`(?:^|\n|[.!?…]\s)${MARKS}([a-z]*)${MARKS}$`, "i");
17711
+ var SpokenFilter = class {
17712
+ held = "";
17713
+ ended = false;
17714
+ boundary = true;
17715
+ // what was spoken so far stops at a sentence or line end
17716
+ /** The next delta's speakable part ('' = nothing yet). */
17717
+ push(delta) {
17718
+ if (this.ended) return "";
17719
+ const text = this.held + delta;
17720
+ const sourced = this.scrub(text).match(SOURCES);
17721
+ if (sourced && (sourced[1] || this.boundary)) {
17722
+ this.ended = true;
17723
+ this.held = "";
17724
+ return this.spoke(this.scrub(text).slice(0, sourced.index + sourced[1].trimEnd().length));
17725
+ }
17726
+ const hold = this.holdFrom(text);
17727
+ this.held = text.slice(hold);
17728
+ return this.spoke(this.scrub(text.slice(0, hold)));
17729
+ }
17730
+ /** The reply ended: what was held, as far as it may be said. */
17731
+ end() {
17732
+ const rest = this.held;
17733
+ this.held = "";
17734
+ return this.ended ? "" : this.scrub(rest);
17735
+ }
17736
+ scrub(s) {
17737
+ return s.replace(LINK, "$1").replace(URL_RE, "");
17738
+ }
17739
+ spoke(s) {
17740
+ if (s.trim()) this.boundary = /[\n.!?…]\s*$/.test(s);
17741
+ return s;
17742
+ }
17743
+ holdFrom(s) {
17744
+ let at = s.length;
17745
+ const link2 = s.match(OPEN_LINK);
17746
+ if (link2) at = Math.min(at, link2.index);
17747
+ const url = s.match(OPEN_URL);
17748
+ if (url) at = Math.min(at, url.index);
17749
+ const head = s.match(OPEN_HEAD);
17750
+ if (head && (head[1] ? HEADS.some((h) => h.startsWith(head[1].toLowerCase())) : /[*_#>-]$/.test(s)) && (head.index > 0 || this.boundary)) at = Math.min(at, head.index);
17751
+ return at;
17752
+ }
17753
+ };
17754
+
17592
17755
  // src/voice/greeting.ts
17593
17756
  init_logging();
17594
17757
  var log37 = forComponent("CallGreeting");
@@ -22636,6 +22799,7 @@ async function repl(args, ai, cfg, cwd) {
22636
22799
  let callChain = Promise.resolve();
22637
22800
  let callFastModel = "";
22638
22801
  let callReplyOpen = false;
22802
+ let spoken = new SpokenFilter();
22639
22803
  let greetNote = "";
22640
22804
  const callTurns = /* @__PURE__ */ new Map();
22641
22805
  const callTools = /* @__PURE__ */ new Set();
@@ -22676,7 +22840,7 @@ ${note}`;
22676
22840
  }
22677
22841
  const rec = { skip: false, running: false };
22678
22842
  callTurns.set(id, rec);
22679
- err(`\r\x1B[K ${bold(cyan("\u{1F3A4} \u203A"))} ${text}
22843
+ err(`\r\x1B[0J ${bold(cyan("\u{1F3A4} \u203A"))} ${text}
22680
22844
  `);
22681
22845
  callChain = callChain.then(async () => {
22682
22846
  if (old?.before !== void 0) face.transcript.splice(old.before);
@@ -22688,8 +22852,11 @@ ${note}`;
22688
22852
  const note = greetNote;
22689
22853
  greetNote = "";
22690
22854
  callReplyOpen = false;
22855
+ spoken = new SpokenFilter();
22691
22856
  try {
22692
- const r = await dispatchLine(text + note, { id });
22857
+ const r = await dispatchLine(`${text}${note}
22858
+
22859
+ ${SPOKEN_TURN}`, { id });
22693
22860
  if (r === "quit") {
22694
22861
  await voiceIO?.awaitIdle();
22695
22862
  editorRef?.abort();
@@ -22723,12 +22890,18 @@ ${note}`;
22723
22890
  callReplyOpen = true;
22724
22891
  voiceIO.beginSpeech();
22725
22892
  }
22726
- const echo = voiceIO.speakDelta(e.message);
22893
+ const say = spoken.push(e.message);
22894
+ if (!say) return;
22895
+ const echo = voiceIO.speakDelta(say);
22727
22896
  editorRef?.suspend();
22728
22897
  voiceEcho(echo);
22729
22898
  return;
22730
22899
  }
22731
22900
  if (voiceIO && (e.kind === "turn_start" || e.kind === "thinking_delta")) return;
22901
+ if (voiceIO) {
22902
+ voiceEchoEnd();
22903
+ editorRef?.suspend();
22904
+ }
22732
22905
  return notify(e);
22733
22906
  };
22734
22907
  }
@@ -23074,6 +23247,10 @@ ${task}`;
23074
23247
  task = t;
23075
23248
  }
23076
23249
  const r = await runTurn(face, store, session, task, duplex ? void 0 : checkpoints, cwd, sendVia ? (c) => sendVia(c, opts) : routeVia);
23250
+ if (call && voiceIO) {
23251
+ const rest = spoken.end();
23252
+ if (rest) voiceEcho(voiceIO.speakDelta(rest));
23253
+ }
23077
23254
  if (voiceIO) {
23078
23255
  voiceReasonEnd();
23079
23256
  voiceEchoEnd();