@livx.cc/agentx 0.99.155 → 0.99.156

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
@@ -14431,9 +14431,17 @@ var ProgressOptions = class {
14431
14431
  now = () => performance.now();
14432
14432
  };
14433
14433
  function argsHint(args) {
14434
- if (!args || typeof args !== "object") return typeof args === "string" ? args.slice(0, 40) : "";
14435
- const s = Object.values(args).find((v) => typeof v === "string" && v.trim());
14436
- return typeof s === "string" ? s.trim().replace(/\s+/g, " ").slice(0, 40) : "";
14434
+ const s = !args || typeof args !== "object" ? args : Object.values(args).find((v) => typeof v === "string" && v.trim());
14435
+ return typeof s === "string" ? urlWords(s.trim()).replace(/\s+/g, " ").slice(0, 40).trim() : "";
14436
+ }
14437
+ function urlWords(s) {
14438
+ if (!/^https?:\/\/\S+$/i.test(s)) return s;
14439
+ try {
14440
+ const u = new URL(s), host = u.hostname.replace(/^www\./, "").split(".").slice(0, -1).filter((p) => p.length > 2);
14441
+ return [...host, ...decodeURIComponent(u.pathname).split(/[/._-]+/)].filter((w) => new RegExp("\\p{L}{2}", "u").test(w) && !/^(?:html?|php|aspx?|index)$/i.test(w)).join(" ");
14442
+ } catch {
14443
+ return s;
14444
+ }
14437
14445
  }
14438
14446
  var Progress = class {
14439
14447
  constructor(options) {
@@ -14516,13 +14524,17 @@ var Progress = class {
14516
14524
  return null;
14517
14525
  }), late]).finally(() => clearTimeout(t));
14518
14526
  const l = cleanLine(raw ?? "", lang, 5);
14519
- if (!l || about && !echoesHeard(l, hint) || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
14527
+ const why = raw === null ? "late or failed" : !l ? `unusable "${raw}"` : about && !echoesHeard(l, `${hint} ${about}`) ? `names nothing of "${hint}": "${l}"` : RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) ? `claims a result: "${l}"` : this.said.has(norm3(l)) ? `repeat: "${l}"` : this.streamed ? "reply streamed" : "";
14528
+ if (why) {
14529
+ log29.debug(`no line for ${tool || "(no tool)"}: ${why}`);
14530
+ return "";
14531
+ }
14520
14532
  return l;
14521
14533
  }
14522
14534
  };
14523
14535
  function fastProgressGenerator(ai, model, gender) {
14524
14536
  return async (tool, hint, lang, signal, avoid = []) => {
14525
- 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 ? 'Name what it works on the way a person would say it ("looking up that Astra post\u2026"), never a string of its keywords ("scanning Astra weights\u2026"). ' : ""}${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.`;
14537
+ const prompt = `An assistant on a live voice call is ${tool ? `running the tool "${tool}"` : "working on a request"}${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 ? 'Name what it works on the way a person would say it ("looking up that Astra post\u2026"), never a string of its keywords ("scanning Astra weights\u2026"). ' : ""}${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.`;
14526
14538
  return fastText(ai, { model, prompt, signal });
14527
14539
  };
14528
14540
  }
@@ -15478,6 +15490,9 @@ var VoiceCallOptions = class {
15478
15490
  /** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
15479
15491
  * cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
15480
15492
  quick;
15493
+ /** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
15494
+ * played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
15495
+ hangUp;
15481
15496
  /** Past this the turn goes to MAIN as before (the bridge covers it). */
15482
15497
  quickBudgetMs = 1800;
15483
15498
  /** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
@@ -15563,7 +15578,9 @@ var VoiceCall = class {
15563
15578
  cancel: () => o.cancel(),
15564
15579
  now: o.now
15565
15580
  });
15566
- 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 });
15581
+ const po = { ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500, gapMs: 5e3 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress };
15582
+ if (o.mode === "live") po.stageRepeatMs ??= po.gapMs;
15583
+ this.progress = new Progress(po);
15567
15584
  this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
15568
15585
  this.gate = new TurnGate({
15569
15586
  now: o.now,
@@ -15954,8 +15971,10 @@ var VoiceCall = class {
15954
15971
  }
15955
15972
  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;
15956
15973
  this.gate.replyStarted(c.id);
15957
- if (!await this.sayRetry(said, "reply", c.id)) return this.close(c, "silent");
15958
- this.o.show(said, "reply");
15974
+ const end = mv.kind === "say" && !!mv.end;
15975
+ const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
15976
+ if (!played && !end) return this.close(c, "silent");
15977
+ if (played) this.o.show(said, "reply");
15959
15978
  if (mv.kind === "resume") {
15960
15979
  this.cutRest = "";
15961
15980
  this.o.dropCut?.();
@@ -15965,6 +15984,17 @@ var VoiceCall = class {
15965
15984
  this.history.push({ who: "you", text: said });
15966
15985
  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.`);
15967
15986
  }
15987
+ if (end) {
15988
+ this.o.onMetric({ name: "hangup", id: c.id, text: said });
15989
+ if (played && (!this.o.hostAudio || c.worded)) this.quickWorded(c, this.lastAudibleAt);
15990
+ this.end();
15991
+ try {
15992
+ this.o.hangUp?.();
15993
+ } catch (e) {
15994
+ log31.warn(`hangUp threw: ${e.message}`);
15995
+ }
15996
+ return;
15997
+ }
15968
15998
  if (this.o.hostAudio && !c.worded) {
15969
15999
  c.quickWord = true;
15970
16000
  return;
@@ -15981,9 +16011,9 @@ var VoiceCall = class {
15981
16011
  }
15982
16012
  this.close(c, "answered");
15983
16013
  }
15984
- /** say(), retried while the host's player is busy (up to 2s). */
15985
- async sayRetry(line, kind, id) {
15986
- for (let i = 0; i < 8; i++) {
16014
+ /** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
16015
+ async sayRetry(line, kind, id, tries = 8) {
16016
+ for (let i = 0; i < tries; i++) {
15987
16017
  if (this.ended) return false;
15988
16018
  if (this.say(line, kind) !== false) return true;
15989
16019
  await new Promise((r) => setTimeout(r, 250));
@@ -18042,6 +18072,35 @@ var JsonlDiagSink = class {
18042
18072
 
18043
18073
  // src/voice/spokenFilter.ts
18044
18074
  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. Say only facts from this turn's tool results or this call, and keep a list in its source's order: "top" or "first" is its rank 1.`;
18075
+ var HANGUP = "[[hangup]]";
18076
+ var CALL_HANGUP = `When the user means to end the call \u2014 in any words or language: a goodbye ("okay, bye", "talk later"), or that they're done ("that's all, thanks") \u2014 say one short farewell and finish that reply with ${HANGUP}: the call hangs up once it has played. Judge the intent, not the word: "say bye to Dan" or "before I go, one more thing" keep the call. Never write ${HANGUP} otherwise.`;
18077
+ function markerStrip(marker) {
18078
+ let held2 = "", hit = false;
18079
+ return {
18080
+ get hit() {
18081
+ return hit;
18082
+ },
18083
+ push(t) {
18084
+ let s = held2 + t;
18085
+ held2 = "";
18086
+ for (let i; (i = s.indexOf(marker)) >= 0; ) {
18087
+ hit = true;
18088
+ s = s.slice(0, i) + s.slice(i + marker.length);
18089
+ }
18090
+ for (let k = Math.min(marker.length - 1, s.length); k > 0; k--) if (marker.startsWith(s.slice(-k))) {
18091
+ held2 = s.slice(-k);
18092
+ s = s.slice(0, -k);
18093
+ break;
18094
+ }
18095
+ return s;
18096
+ },
18097
+ flush() {
18098
+ const s = held2;
18099
+ held2 = "";
18100
+ return s;
18101
+ }
18102
+ };
18103
+ }
18045
18104
  var HEADS = ["sources", "source", "references", "citations", "links"];
18046
18105
  var MARKS = String.raw`[#*_>\s-]*`;
18047
18106
  var SOURCES = new RegExp(String.raw`(^|\n|[.!?…]\s)${MARKS}(?:${HEADS.join("|")})${MARKS}[::]`, "i");
@@ -18130,14 +18189,14 @@ init_logging();
18130
18189
  var log39 = forComponent("QuickLane");
18131
18190
  var SAY_WORDS = 30;
18132
18191
  var ACK_WORDS = 10;
18133
- var ACKS = { en: ["On it.", "Sure, one sec.", "Okay, looking.", "Got it, checking."], he: ["\u05E8\u05D2\u05E2 \u05D0\u05D7\u05D3.", "\u05D0\u05D5\u05E7\u05D9\u05D9, \u05E9\u05E0\u05D9\u05D9\u05D4.", "\u05E9\u05E0\u05D9\u05D9\u05D4."] };
18192
+ var ACKS = { en: ["On it.", "Sure, one sec.", "Okay.", "Alright."], he: ["\u05E8\u05D2\u05E2 \u05D0\u05D7\u05D3.", "\u05D0\u05D5\u05E7\u05D9\u05D9, \u05E9\u05E0\u05D9\u05D9\u05D4.", "\u05E9\u05E0\u05D9\u05D9\u05D4."] };
18134
18193
  function quickMove(raw, c) {
18135
18194
  const mv = rawMove(raw, c), owns = quickOwns(c.heard);
18136
18195
  if (owns === "reaction" && (!mv || mv.kind === "deep")) {
18137
18196
  const l = ownLine(ASIDES[c.lang]?.react, c);
18138
18197
  return l ? { kind: "say", line: l } : { kind: "quiet" };
18139
18198
  }
18140
- if (isClosing(c.heard) && (!mv || mv.kind !== "say")) {
18199
+ if (isClosing(c.heard) && (!mv || mv.kind === "quiet")) {
18141
18200
  const l = ownLine(BYES[c.lang], c);
18142
18201
  return l ? { kind: "say", line: l } : mv;
18143
18202
  }
@@ -18149,9 +18208,9 @@ var ownLine = (pool, c) => {
18149
18208
  return (pool ?? []).find((x) => !said.has(norm3(x))) ?? "";
18150
18209
  };
18151
18210
  function rawMove(raw, c) {
18152
- const m = /^\s*(SAY|DEEP|RESUME|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18211
+ const m = /^\s*(SAY|BYE|DEEP|RESUME|QUIET)\b\s*:?\s*(.*)$/im.exec(raw.trim());
18153
18212
  if (!m) return null;
18154
- const kind = m[1].toUpperCase(), body = m[2].trim();
18213
+ const bye = m[1].toUpperCase() === "BYE", kind = bye ? "SAY" : m[1].toUpperCase(), body = m[2].trim();
18155
18214
  const owns = quickOwns(c.heard);
18156
18215
  if (!owns && kind !== "DEEP") return { kind: "deep", ack: stockAck(c), brief: "" };
18157
18216
  if (kind === "QUIET") return { kind: "quiet" };
@@ -18161,22 +18220,22 @@ function rawMove(raw, c) {
18161
18220
  }
18162
18221
  if (kind === "DEEP") {
18163
18222
  const [ack = "", brief = ""] = body.split(body.includes("|") ? "|" : /\s+[—–-]\s+/).map((s) => s.trim());
18164
- const a = cleanLine(ack, c.lang, ACK_WORDS);
18223
+ const a = cleanLine(ack, c.lang, ACK_WORDS).replace(/[\s,;:—–-]+$/u, "");
18165
18224
  const said = new Set(c.history.filter((h) => h.who === "you").map((h) => norm3(h.text)));
18166
18225
  const ok = a && !said.has(norm3(a)) && !RESULT_CLAIM_RE.test(a) && !new RegExp("\\p{N}", "u").test(a);
18167
18226
  return { kind: "deep", ack: ok ? a : stockAck(c), brief };
18168
18227
  }
18169
18228
  const line = sayLine(body, c.lang);
18170
18229
  if (!line) return null;
18171
- if (parrots(line, c.heard)) return { kind: "quiet" };
18172
- if (c.history.some((h) => h.who === "you" && norm3(h.text) === norm3(line))) return { kind: "quiet" };
18230
+ if (!bye && parrots(line, c.heard)) return { kind: "quiet" };
18231
+ if (!bye && c.history.some((h) => h.who === "you" && norm3(h.text) === norm3(line))) return { kind: "quiet" };
18173
18232
  const facts = unknownFacts(line, c), novel = novelWords(line, c);
18174
18233
  const unknown = facts.length || novel.length >= 2 ? [...facts, ...novel] : [];
18175
18234
  if (unknown.length) {
18176
18235
  log39.debug(`quick line "${line}" names ${unknown.join(", ")} \u2014 not in the call: deep lane`);
18177
18236
  return { kind: "deep", ack: "", brief: "" };
18178
18237
  }
18179
- return { kind: "say", line };
18238
+ return bye && isClosing(c.heard) ? { kind: "say", line, end: true } : { kind: "say", line };
18180
18239
  }
18181
18240
  var stockAck = (c) => ownLine(ACKS[c.lang], c);
18182
18241
  function quickOwns(heard) {
@@ -18271,8 +18330,9 @@ They just said: "${c.heard}"
18271
18330
  ` + (c.rest ? `Your last answer was cut. Its unsaid rest: "${c.rest.slice(0, 300)}"
18272
18331
  ` : "") + `
18273
18332
  Reply with exactly ONE line, one of:
18274
- SAY: <your words> \u2014 ONLY a greeting or how-are-you, a short reaction ("wow", "really?"), a goodbye, or when they ask exactly to repeat something ALREADY said ("say that again", "which one was that?"). Any request ("tell me a story\u2026"), any question about content ("what is\u2026?", "wait, what?", "how long is it?") is DEEP, even if you could guess. Max two short sentences. Use only facts from the call above; never invent a name, number, news item or result.
18275
- DEEP: <a 2-8 word acknowledgement> | <what the colleague must do, names spelled right> \u2014 anything needing a lookup, current information, tools, files, or real thinking. The acknowledgement says you're on it ("Sure, checking Hacker News.") and never a result. The speech-to-text misspells names: fix them from context ("Haka News" \u2192 Hacker News).
18333
+ BYE: <a short farewell> \u2014 they mean to end the call ("no, thank you, bye", "okay, talk later"): the call hangs up after it. Judge the intent: "say bye to Dan" or "before I go, one more thing" is not an end.
18334
+ SAY: <your words> \u2014 ONLY a greeting or how-are-you, a short reaction ("wow", "really?"), or when they ask exactly to repeat something ALREADY said ("say that again", "which one was that?"). Any request ("tell me a story\u2026"), any question about content ("what is\u2026?", "wait, what?", "how long is it?") is DEEP, even if you could guess. Max two short sentences. Use only facts from the call above; never invent a name, number, news item or result.
18335
+ DEEP: <a 2-8 word acknowledgement> | <what the colleague must do, names spelled right> \u2014 anything needing a lookup, current information, tools, files, or real thinking. The acknowledgement is your natural first reaction to THIS kind of ask, in your own voice: a lookup says you're on it and names what you'll look at ("Sure, let me pull up the kitty changelog."); a story, joke or idea gets a reaction to the idea itself (a story about a dragon: "Ooh, a dragon story, okay\u2026"); a question about what was said gets a short "ah"-type reaction ("Ah, good question."). Say "checking" or "looking" only when something is actually looked up. Never a result. The speech-to-text misspells names: fix them from context ("Haka News" \u2192 Hacker News).
18276
18336
  QUIET \u2014 nothing is owed: a bare "okay", "mm-hm", or a reaction you already answered.
18277
18337
  "Wait" / "hold on" with nothing new: a brief SAY ("Sure.") \u2014 no work for the colleague. Vary your words: never reuse an acknowledgement or reaction already said in this call.
18278
18338
  A reaction ("wow", "really?") gets a short fitting reply in your own words ("I know, right?"), never their word back. Never repeat what was already said. Speak ${languageName(c.lang)}. ${personaHint(gender)} Output only the line.`;
@@ -23299,12 +23359,25 @@ async function repl(args, ai, cfg, cwd) {
23299
23359
  let callFastModel = "";
23300
23360
  let callReplyOpen = false;
23301
23361
  let spoken = new SpokenFilter();
23362
+ let hang = markerStrip(HANGUP);
23363
+ const hangUpCall = () => {
23364
+ voiceDiag?.push({ t: performance.now(), kind: "call_hangup" });
23365
+ call?.end();
23366
+ void (async () => {
23367
+ for (let i = 0; i < 60 && voiceIO; i++) {
23368
+ await voiceIO.awaitIdle();
23369
+ await new Promise((r) => setTimeout(r, 500));
23370
+ if (!voiceIO?.audible && !(voiceIO?.player?.drainMs() ?? 0)) break;
23371
+ }
23372
+ editorRef?.abort();
23373
+ })();
23374
+ };
23302
23375
  let greetNote = "";
23303
23376
  const callTurns = /* @__PURE__ */ new Map();
23304
23377
  const callTools = /* @__PURE__ */ new Set();
23305
23378
  if (args.call) {
23306
23379
  if (args.voice || args.voicePersona) agent.options.systemPrompt += "\n\n" + (args.voicePersona ?? CALL_PROMPT);
23307
- agent.options.systemPrompt += "\n\n" + CALL_WEB_PROMPT;
23380
+ agent.options.systemPrompt += "\n\n" + CALL_WEB_PROMPT + "\n\n" + CALL_HANGUP;
23308
23381
  if (args.voiceSystemPrompt) agent.options.systemPrompt += "\n\n" + args.voiceSystemPrompt;
23309
23382
  const fast = callFast(args, ai, cfg);
23310
23383
  for (const n of fast.notes) err(yellow(` \u26A0 ${n}
@@ -23316,6 +23389,8 @@ async function repl(args, ai, cfg, cwd) {
23316
23389
  // live: the quick lane owns the conversation, MAIN is its deep lane (#1331). Only here: its lines reach MAIN through
23317
23390
  // noteTurn, which a --channel-only host (Para) does not take yet.
23318
23391
  ...args.channelMode === "live" && process.env.AGENTX_QUICK_LANE !== "0" ? { quick: fastQuickLane(ai, fast.options.fastModel, args.voiceGender, args.voicePersona) } : {},
23392
+ // the quick lane's farewell to a goodbye ends the call, as an ExitSession 'quit' does: the line plays out, then exit
23393
+ hangUp: hangUpCall,
23319
23394
  show: (t, kind) => {
23320
23395
  err("\r\x1B[0J" + dim(` \u21B3 ${kind === "progress" ? "\u22EF " : ""}${t}
23321
23396
  `));
@@ -23362,6 +23437,7 @@ ${note}`;
23362
23437
  greetNote = "";
23363
23438
  callReplyOpen = false;
23364
23439
  spoken = new SpokenFilter();
23440
+ hang = markerStrip(HANGUP);
23365
23441
  try {
23366
23442
  const r = await dispatchLine(`${text}${note}
23367
23443
 
@@ -23376,14 +23452,18 @@ ${SPOKEN_TURN}`, { id });
23376
23452
  rec.running = false;
23377
23453
  call?.main({ type: "done", id });
23378
23454
  editorRef?.redrawNow();
23455
+ if (hang.hit) hangUpCall();
23379
23456
  }
23380
23457
  });
23381
23458
  }
23382
23459
  });
23383
23460
  const host = agent.options.host, notify = host.notify.bind(host);
23384
23461
  host.notify = (e) => {
23385
- if (e.kind === "text_delta" && typeof e.message === "string") call.main({ type: "text", text: e.message });
23386
- else if (e.kind === "tool_use") call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
23462
+ if (e.kind === "text_delta" && typeof e.message === "string") {
23463
+ e = { ...e, message: hang.push(e.message) };
23464
+ if (!e.message) return;
23465
+ call.main({ type: "text", text: e.message });
23466
+ } else if (e.kind === "tool_use") call.main({ type: "tool", name: String(e.name ?? ""), args: e.input });
23387
23467
  else if (e.kind === "tool_result") call.main({ type: "tool_done" });
23388
23468
  else if (e.kind === "tool_activity") {
23389
23469
  if (!callTools.has(e.id)) {
@@ -25676,7 +25756,9 @@ async function channelServe(args, ai, cfg) {
25676
25756
  out({ type: "resumed" });
25677
25757
  },
25678
25758
  // the rest was said: the host's cut note no longer holds
25679
- userLine: (text, how) => out({ type: "user_line", text, how })
25759
+ userLine: (text, how) => out({ type: "user_line", text, how }),
25760
+ hangUp: () => out({ type: "hangup" })
25761
+ // the farewell went out as a {type:'channel', kind:'reply'}: end the call once it played
25680
25762
  } : {},
25681
25763
  channel: { ...fast.channel, onTree: (e) => out({ type: "metric", name: "tree", ms: e.ms, kind: `${e.tokens ? `${e.tokens.input}/${e.tokens.output} tok ` : ""}${e.error ?? (e.lines ?? []).join(" | ")}` }), onLeaf: (e) => out({ type: "metric", name: "leaf", ms: e.ms, kind: `${e.moment} ${e.conf} ${e.acted}`, text: e.text }) },
25682
25764
  speak: (line, kind) => {