@livx.cc/agentx 0.99.151 → 0.99.153
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.d.ts +1 -1
- package/dist/cli.js +254 -157
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +121 -47
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel--iqPHPO_.d.ts → secondChannel-CR3xWWB_.d.ts} +12 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel
|
|
2
|
-
export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel
|
|
1
|
+
import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel-CR3xWWB_.js';
|
|
2
|
+
export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel-CR3xWWB_.js';
|
|
3
3
|
export { MODEL_ALIASES, ModelSwitch, ResolveModelSwitchOpts, latestClaude, modelShortLabel, resolveModelAlias, resolveModelSwitch } from './models.js';
|
|
4
4
|
import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
|
|
5
5
|
export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
|
|
@@ -972,6 +972,10 @@ declare class TurnGateOptions {
|
|
|
972
972
|
* 20261103-114604, "Okay." settled 700ms into "What will the…" and MAIN started, was aborted twice and merged. The
|
|
973
973
|
* rest's final merges in; capped at this long from the hold (an STT that never finalizes a partial). */
|
|
974
974
|
talkingMaxMs: number;
|
|
975
|
+
/** With settleMs: a final of acknowledgement words only ("Ok Okay.") waits this long. No answer is due, and it is
|
|
976
|
+
* mostly the start of the turn: live 20261103-210433, "Ok Okay." settled at 700ms, the rest began 1s after it, and
|
|
977
|
+
* MAIN was started and aborted. Quiet past this sends it as it was. */
|
|
978
|
+
openerMs: number;
|
|
975
979
|
onTurn: (t: GateTurn) => void;
|
|
976
980
|
onDrop: (text: string, why: GateDrop) => void;
|
|
977
981
|
/** A final is being held (ends mid-phrase) — the fill channel may cover it with a filler, never a bridge. */
|
|
@@ -1010,6 +1014,9 @@ declare class TurnGate {
|
|
|
1010
1014
|
replyStarted(id: string): void;
|
|
1011
1015
|
/** Send a held fragment now (e.g. the call ends). */
|
|
1012
1016
|
flush(): void;
|
|
1017
|
+
/** Only acknowledgement words ("Ok Okay.", "Alright.") and no goodbye: no answer is due, and it usually opens what
|
|
1018
|
+
* comes next. */
|
|
1019
|
+
private opener;
|
|
1013
1020
|
end(): void;
|
|
1014
1021
|
private refinal;
|
|
1015
1022
|
private send;
|
|
@@ -1788,6 +1795,9 @@ declare class VoiceCallOptions {
|
|
|
1788
1795
|
* runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
|
|
1789
1796
|
* barges in as before. */
|
|
1790
1797
|
noteTurn?: (note: string) => void;
|
|
1798
|
+
/** What the user HEARD of MAIN's reply a barge just cut (a peek — the host still takes the cut for MAIN), else null:
|
|
1799
|
+
* a live bridge echoes what their "that" points at. */
|
|
1800
|
+
heardCut?: () => string | null;
|
|
1791
1801
|
/** Writes that immediate answer (fastWorkReply). */
|
|
1792
1802
|
workReply?: WorkReply;
|
|
1793
1803
|
workReplyBudgetMs: number;
|
|
@@ -1869,6 +1879,7 @@ declare class VoiceCall {
|
|
|
1869
1879
|
lang?: string;
|
|
1870
1880
|
}): void;
|
|
1871
1881
|
private finalAt;
|
|
1882
|
+
private floor;
|
|
1872
1883
|
private sttLang;
|
|
1873
1884
|
/** The host's player started a line's audio now (or in `inMs`): `fill`/`progress` = the fill channel's, `main` = MAIN's
|
|
1874
1885
|
* reply (as main({type:'audio'})). With hostAudio this is what first_sound counts. */
|
package/dist/index.js
CHANGED
|
@@ -10442,12 +10442,14 @@ var LEADER = /* @__PURE__ */ new Set(["yeah", "yea", "yes", "yep", "yup", "ok",
|
|
|
10442
10442
|
var PHRASES = ["got it", "i see", "makes sense", "of course", "for sure", "all right", "that's right", "that's true", "thats right", "thats true", "love it", "i know", "me too", "uh huh"];
|
|
10443
10443
|
var CONTINUE = /^(?:(?:and|so|oh) )?(?:and|so|really|seriously|then what|and then|go on|keep going|ואז|באמת|נו)$/;
|
|
10444
10444
|
var AGREE = new Set("yeah yea yes yep yup right sure true totally exactly definitely absolutely agreed correct indeed \u05DB\u05DF \u05E0\u05DB\u05D5\u05DF \u05D1\u05D3\u05D9\u05D5\u05E7 \u05D1\u05E8\u05D5\u05E8 \u05D1\u05D8\u05D7 \u05D0\u05DB\u05DF \u05DC\u05D2\u05DE\u05E8\u05D9 \u05DE\u05E1\u05DB\u05D9\u05DD \u05DE\u05E1\u05DB\u05D9\u05DE\u05D4 \u05DE\u05DE\u05E9".split(" "));
|
|
10445
|
+
var DOUBT = /^(?:(?:and|so|oh|wait|but) )*(?:really|seriously|are|is|was|were|do|does|did|you|no way|באמת|בטוח|בטוחה|רצינית?)(?=\s|$)/u;
|
|
10445
10446
|
var AGREE_PHRASES = ["of course", "for sure", "that's right", "that's true", "thats right", "thats true", "makes sense", "i agree"];
|
|
10446
10447
|
var HE_ACK = new Set("\u05DB\u05DF \u05E0\u05DB\u05D5\u05DF \u05D1\u05D3\u05D9\u05D5\u05E7 \u05D1\u05E8\u05D5\u05E8 \u05D1\u05D8\u05D7 \u05D0\u05DB\u05DF \u05DC\u05D2\u05DE\u05E8\u05D9 \u05DE\u05DE\u05E9 \u05D0\u05D5\u05E7\u05D9\u05D9 \u05D0\u05D5\u05E7\u05D9 \u05E1\u05D1\u05D1\u05D4 \u05D9\u05E4\u05D4 \u05DE\u05E2\u05D5\u05DC\u05D4 \u05D5\u05D5\u05D0\u05D5 \u05D0\u05D4\u05D4 \u05D0\u05D4 \u05D4\u05DE\u05DE \u05DE\u05DE\u05DE".split(" "));
|
|
10447
10448
|
function cueKind(text) {
|
|
10448
10449
|
const t = norm2(text);
|
|
10449
10450
|
if (!t) return null;
|
|
10450
10451
|
if (CONTINUE.test(t)) return "continue";
|
|
10452
|
+
if (/\?/.test(text) || DOUBT.test(t)) return null;
|
|
10451
10453
|
let r = t;
|
|
10452
10454
|
for (const p of AGREE_PHRASES) if (r.includes(p)) return "agree";
|
|
10453
10455
|
r = r.split(/[\s-]+/).filter((w) => !LEAD.has(w)).join(" ");
|
|
@@ -10587,13 +10589,17 @@ var INTENT_ACK_OVER = {
|
|
|
10587
10589
|
resume: ["agreement", "silent"],
|
|
10588
10590
|
aside: []
|
|
10589
10591
|
};
|
|
10590
|
-
function
|
|
10592
|
+
function heardAt(cut) {
|
|
10593
|
+
const at = Math.min(cut.heard.length, cut.full.length);
|
|
10594
|
+
return /\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "") ? cut.full.lastIndexOf(" ", at) + 1 : at;
|
|
10595
|
+
}
|
|
10596
|
+
function interruptionNote(cut, intent, hold = true) {
|
|
10591
10597
|
const full = cut.full.trim();
|
|
10592
|
-
|
|
10593
|
-
if (/\S/.test(cut.full[at] ?? "") && /\S/.test(cut.full[at - 1] ?? "")) at = cut.full.lastIndexOf(" ", at) + 1;
|
|
10598
|
+
const at = heardAt(cut);
|
|
10594
10599
|
const heardWords = cut.full.slice(0, at).trim().split(/\s+/).filter(Boolean).length;
|
|
10595
10600
|
const unheard = cut.full.slice(at).trim();
|
|
10596
|
-
const
|
|
10601
|
+
const lastWords = cut.full.slice(0, at).trim().split(/\s+/).slice(-8).join(" ");
|
|
10602
|
+
const landed = heardWords < 4 ? "They cut in almost at once \u2014 treat all of it as unsaid." : `They heard everything before this part. They missed the rest of it: "${unheard}". The last words they heard were "\u2026${lastWords}" \u2014 a "that"/"it"/"this" in their words means the thing those words were naming, never anything in the missed part.`;
|
|
10597
10603
|
const how = {
|
|
10598
10604
|
resume: "They did not ask anything new. Carry on with the part they missed \u2014 no restart, no apology.",
|
|
10599
10605
|
aside: "It was an aside. Answer it briefly FIRST, then finish the part they missed, adjusted to anything they just said. Say each point once: skip whatever they already heard and whatever your answer just covered.",
|
|
@@ -10602,7 +10608,7 @@ function interruptionNote(cut, intent) {
|
|
|
10602
10608
|
unknown: "Decide like a person would: if it was an aside, answer it and then finish your point; if they steered away, follow them and drop or adapt the rest."
|
|
10603
10609
|
};
|
|
10604
10610
|
return `
|
|
10605
|
-
[the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back
|
|
10611
|
+
[the user interrupted you mid-speech. You were saying: "${full}" ${landed} ${how[intent ?? "unknown"]} Just talk, like a person picking the thread back up: never tell them what they heard or missed, never say where you were cut off, and never quote your earlier words back.` + (hold ? " If their words are still an unfinished fragment, call Hold instead of answering." : "") + "]";
|
|
10606
10612
|
}
|
|
10607
10613
|
|
|
10608
10614
|
// src/voice/unsaid.ts
|
|
@@ -11150,6 +11156,10 @@ var TurnGateOptions = class {
|
|
|
11150
11156
|
* 20261103-114604, "Okay." settled 700ms into "What will the…" and MAIN started, was aborted twice and merged. The
|
|
11151
11157
|
* rest's final merges in; capped at this long from the hold (an STT that never finalizes a partial). */
|
|
11152
11158
|
talkingMaxMs = 6e3;
|
|
11159
|
+
/** With settleMs: a final of acknowledgement words only ("Ok Okay.") waits this long. No answer is due, and it is
|
|
11160
|
+
* mostly the start of the turn: live 20261103-210433, "Ok Okay." settled at 700ms, the rest began 1s after it, and
|
|
11161
|
+
* MAIN was started and aborted. Quiet past this sends it as it was. */
|
|
11162
|
+
openerMs = 2e3;
|
|
11153
11163
|
onTurn = () => {
|
|
11154
11164
|
};
|
|
11155
11165
|
onDrop = () => {
|
|
@@ -11207,7 +11217,7 @@ var TurnGate = class {
|
|
|
11207
11217
|
if (this.closed && isClosing(t)) return this.o.onDrop(t, "goodbye");
|
|
11208
11218
|
const mid = endsMidPhrase(t);
|
|
11209
11219
|
if (mid || this.o.settleMs && !/\?["')\]]*$/.test(t)) {
|
|
11210
|
-
const ms = mid ? this.o.holdMs : this.o.settleMs;
|
|
11220
|
+
const ms = mid ? this.o.holdMs : this.o.settleMs && this.opener(t) ? Math.max(this.o.settleMs, this.o.openerMs) : this.o.settleMs;
|
|
11211
11221
|
this.held = { text: t, sttId, ms, replaces, since: now3, timer: setTimeout(() => this.settle(), ms) };
|
|
11212
11222
|
return this.o.onHold(t);
|
|
11213
11223
|
}
|
|
@@ -11252,6 +11262,11 @@ var TurnGate = class {
|
|
|
11252
11262
|
if (this.closed && isClosing(h.text)) return this.o.onDrop(h.text, "goodbye");
|
|
11253
11263
|
this.send(h.text, norm3(h.text), h.sttId, "new", h.replaces);
|
|
11254
11264
|
}
|
|
11265
|
+
/** Only acknowledgement words ("Ok Okay.", "Alright.") and no goodbye: no answer is due, and it usually opens what
|
|
11266
|
+
* comes next. */
|
|
11267
|
+
opener(t) {
|
|
11268
|
+
return turnIntent(t) === "closer" && !isClosing(t);
|
|
11269
|
+
}
|
|
11255
11270
|
end() {
|
|
11256
11271
|
if (this.held) {
|
|
11257
11272
|
clearTimeout(this.held.timer);
|
|
@@ -13777,15 +13792,40 @@ function matchCue(plan, heard, from = 0) {
|
|
|
13777
13792
|
return null;
|
|
13778
13793
|
}
|
|
13779
13794
|
|
|
13795
|
+
// src/voice/fastText.ts
|
|
13796
|
+
init_logging();
|
|
13797
|
+
var log28 = forComponent("FastText");
|
|
13798
|
+
var isReasoningFast = (model) => /gpt-oss/.test(model);
|
|
13799
|
+
async function fastText(ai, o) {
|
|
13800
|
+
const reasons = isReasoningFast(o.model);
|
|
13801
|
+
const r = await ai.chat({
|
|
13802
|
+
model: o.model,
|
|
13803
|
+
messages: [{ role: "user", content: o.prompt }],
|
|
13804
|
+
stream: false,
|
|
13805
|
+
...o.signal ? { signal: o.signal } : {},
|
|
13806
|
+
maxTokens: reasons ? Math.max(o.maxTokens ?? 0, 400) : o.maxTokens ?? 150,
|
|
13807
|
+
...o.temperature !== void 0 ? { temperature: o.temperature } : {},
|
|
13808
|
+
...reasons ? { providerOptions: { reasoning_effort: "low" } } : {}
|
|
13809
|
+
});
|
|
13810
|
+
if (reasons && r.finishReason === "length") {
|
|
13811
|
+
log28.debug(`${o.model} hit its token cap \u2014 no answer: ${(r.content ?? "").slice(0, 80)}`);
|
|
13812
|
+
return "";
|
|
13813
|
+
}
|
|
13814
|
+
return r.content ?? "";
|
|
13815
|
+
}
|
|
13816
|
+
|
|
13780
13817
|
// src/voice/convoTree.ts
|
|
13781
|
-
var
|
|
13818
|
+
var log29 = forComponent("ConvoTree");
|
|
13782
13819
|
var SOFT_CUE = "~";
|
|
13783
13820
|
var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
|
|
13784
13821
|
var isContent = (w) => w.length >= 4 && !STOP4.has(w);
|
|
13785
13822
|
function echoesHeard(line, heard) {
|
|
13786
|
-
const said =
|
|
13787
|
-
return cueWords(lineWords(line)).some((w) =>
|
|
13823
|
+
const said = cueWords(heard).map(stem).filter(echoable);
|
|
13824
|
+
return cueWords(lineWords(line)).map(stem).filter(echoable).some((w) => said.some((h) => h === w || Math.min(h.length, w.length) >= 4 && (h.startsWith(w) || w.startsWith(h))));
|
|
13788
13825
|
}
|
|
13826
|
+
var stem = (w) => w.replace(/['’]s$/, "").replace(new RegExp("(?<=\\p{L}{3})s$", "u"), "");
|
|
13827
|
+
var SHORT_STOP = new Set("the and you are was for not but has had his her its our who why how can did get got let may one out see she two use way yes all any new now off old own say too him hey huh ooh wow yep".split(" "));
|
|
13828
|
+
var echoable = (w) => isContent(w) || w.length === 3 && !SHORT_STOP.has(w) && !new RegExp("^\\p{N}+$", "u").test(w);
|
|
13789
13829
|
var leafKey = (line) => cueWords(lineWords(line)).join(" ");
|
|
13790
13830
|
var ConvoTreeOptions = class {
|
|
13791
13831
|
/** A leaf plays at this confidence or above. */
|
|
@@ -13885,7 +13925,7 @@ var ConvoTree = class {
|
|
|
13885
13925
|
|
|
13886
13926
|
// src/voice/progress.ts
|
|
13887
13927
|
init_logging();
|
|
13888
|
-
var
|
|
13928
|
+
var log30 = forComponent("Progress");
|
|
13889
13929
|
var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
|
|
13890
13930
|
var PLUMBING = /toolsearch|^mcp__.*__(list_commands|call_info)$/;
|
|
13891
13931
|
var isPlumbing = (tool) => PLUMBING.test(tool.toLowerCase());
|
|
@@ -14060,7 +14100,7 @@ var Progress = class {
|
|
|
14060
14100
|
});
|
|
14061
14101
|
const hint = argsHint(args) || about.slice(-80);
|
|
14062
14102
|
const raw = await Promise.race([this.o.generate(tool, hint, lang, ac.signal, this.lines).catch((e) => {
|
|
14063
|
-
|
|
14103
|
+
log30.warn(`progress line failed: ${e?.message ?? e}`);
|
|
14064
14104
|
return null;
|
|
14065
14105
|
}), late]).finally(() => clearTimeout(t));
|
|
14066
14106
|
const l = cleanLine(raw ?? "", lang, 5);
|
|
@@ -14071,9 +14111,7 @@ var Progress = class {
|
|
|
14071
14111
|
function fastProgressGenerator(ai, model, gender) {
|
|
14072
14112
|
return async (tool, hint, lang, signal, avoid = []) => {
|
|
14073
14113
|
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.`;
|
|
14074
|
-
|
|
14075
|
-
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
|
|
14076
|
-
return r.content ?? "";
|
|
14114
|
+
return fastText(ai, { model, prompt, signal });
|
|
14077
14115
|
};
|
|
14078
14116
|
}
|
|
14079
14117
|
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;
|
|
@@ -14090,7 +14128,7 @@ function workAck(raw, lang, gender = "") {
|
|
|
14090
14128
|
|
|
14091
14129
|
// src/voice/secondChannel.ts
|
|
14092
14130
|
init_logging();
|
|
14093
|
-
var
|
|
14131
|
+
var log31 = forComponent("SecondChannel");
|
|
14094
14132
|
var CHANNEL_MODES = {
|
|
14095
14133
|
turn: { kinds: ["bridge"], bridgeDelayMs: 1500 },
|
|
14096
14134
|
normal: {},
|
|
@@ -14255,15 +14293,15 @@ function withBudget(p, ms, what, ac) {
|
|
|
14255
14293
|
let t;
|
|
14256
14294
|
const late = new Promise((r) => {
|
|
14257
14295
|
t = setTimeout(() => {
|
|
14258
|
-
|
|
14296
|
+
log31.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
|
|
14259
14297
|
ac?.abort();
|
|
14260
14298
|
r(null);
|
|
14261
14299
|
}, ms);
|
|
14262
14300
|
});
|
|
14263
14301
|
return Promise.race([p.catch((e) => {
|
|
14264
14302
|
const msg = String(e?.message ?? e);
|
|
14265
|
-
if (e?.name === "AbortError" || /aborted/i.test(msg))
|
|
14266
|
-
else
|
|
14303
|
+
if (e?.name === "AbortError" || /aborted/i.test(msg)) log31.debug(`${what}: aborted after its budget`);
|
|
14304
|
+
else log31.warn(`${what} failed \u2014 falling back: ${msg}`);
|
|
14267
14305
|
return null;
|
|
14268
14306
|
}), late]).finally(() => clearTimeout(t));
|
|
14269
14307
|
}
|
|
@@ -14307,10 +14345,14 @@ var SecondChannel = class {
|
|
|
14307
14345
|
// a bridge generated ahead, used only if ready in time
|
|
14308
14346
|
bridgeReady = Promise.resolve();
|
|
14309
14347
|
// live: that draft settled
|
|
14348
|
+
noLine = "";
|
|
14349
|
+
// live: why that draft gave no line
|
|
14310
14350
|
askLeaf = null;
|
|
14311
14351
|
// live: this turn's ask leaf
|
|
14312
14352
|
barged = false;
|
|
14313
14353
|
// the user cut in since their last turn: that turn is a steer, not a story to react to
|
|
14354
|
+
said = "";
|
|
14355
|
+
// live: what the user heard the assistant say last (the cut's heard part, else the last reply)
|
|
14314
14356
|
leafReady = Promise.resolve();
|
|
14315
14357
|
// live: the turn-end leaf pick settled
|
|
14316
14358
|
recent = [];
|
|
@@ -14366,7 +14408,7 @@ var SecondChannel = class {
|
|
|
14366
14408
|
if (host) this.pinned = true;
|
|
14367
14409
|
const lang = primaryLang(tag);
|
|
14368
14410
|
if (!lang || lang === this.lang) return;
|
|
14369
|
-
|
|
14411
|
+
log31.debug(`language ${this.lang} \u2192 ${lang}`);
|
|
14370
14412
|
this.lang = lang;
|
|
14371
14413
|
this.recent = [];
|
|
14372
14414
|
this.picks.clear();
|
|
@@ -14516,9 +14558,20 @@ var SecondChannel = class {
|
|
|
14516
14558
|
}, Math.max(late, wait + 1));
|
|
14517
14559
|
}
|
|
14518
14560
|
}
|
|
14561
|
+
/** The STT closed the user's line (a final that ends a sentence), before it is a turn (the host may still hold it): a
|
|
14562
|
+
* listener cue armed on its last words is late now. Replay of 20261103-210433: "oh wow" played 330ms after "…and
|
|
14563
|
+
* hacker news." while the gate held the turn, and spaced the request's own line to 1.5s. */
|
|
14564
|
+
onLineEnd() {
|
|
14565
|
+
this.userSpeaking = false;
|
|
14566
|
+
for (const k of ["bcTimer", "leafTimer", "breathTimer"]) {
|
|
14567
|
+
if (this[k]) clearTimeout(this[k]);
|
|
14568
|
+
this[k] = null;
|
|
14569
|
+
}
|
|
14570
|
+
}
|
|
14519
14571
|
/** The user's final line was dispatched to the main agent (its words are the bridge's micro-context). */
|
|
14520
|
-
onUserTurn(text, lastWordAgoMs = 0) {
|
|
14572
|
+
onUserTurn(text, lastWordAgoMs = 0, heardCut) {
|
|
14521
14573
|
this.heard = text.trim();
|
|
14574
|
+
this.said = (heardCut ?? this.reply).trim();
|
|
14522
14575
|
this.lastWordAgo = Math.max(0, lastWordAgoMs);
|
|
14523
14576
|
this.floorWords = this.carried + words2(this.heard).length;
|
|
14524
14577
|
this.lastUser = this.heard;
|
|
@@ -14551,7 +14604,7 @@ var SecondChannel = class {
|
|
|
14551
14604
|
try {
|
|
14552
14605
|
this.o.cancel();
|
|
14553
14606
|
} catch (e) {
|
|
14554
|
-
|
|
14607
|
+
log31.warn(`cancel threw: ${e.message}`);
|
|
14555
14608
|
}
|
|
14556
14609
|
}
|
|
14557
14610
|
}
|
|
@@ -14661,7 +14714,7 @@ var SecondChannel = class {
|
|
|
14661
14714
|
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words2(this.heard).length : 0);
|
|
14662
14715
|
this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: r.nodes.length, lines: r.nodes.flatMap((n) => [n.line, ...n.next.map((k) => k.line)]), ...r.tokens ? { tokens: r.tokens } : {} });
|
|
14663
14716
|
}, (e) => {
|
|
14664
|
-
|
|
14717
|
+
log31.warn(`tree failed: ${e?.message ?? e}`);
|
|
14665
14718
|
this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: 0, error: String(e?.message ?? e) });
|
|
14666
14719
|
}).finally(() => {
|
|
14667
14720
|
clearTimeout(late);
|
|
@@ -14715,7 +14768,7 @@ var SecondChannel = class {
|
|
|
14715
14768
|
if (gen === this.gen && echoesHeard(hit.node.line, heard)) this.askLeaf = { gen, text: hit.node.line };
|
|
14716
14769
|
return;
|
|
14717
14770
|
}
|
|
14718
|
-
if (hit && steer) return;
|
|
14771
|
+
if (hit && (steer || turnIntent(heard) === "ask")) return;
|
|
14719
14772
|
if (hit && gen === this.gen && (this.main === "queued" || this.main === "thinking")) {
|
|
14720
14773
|
this.playLeaf(hit, "working", "bridge");
|
|
14721
14774
|
if (this.lastKind === "bridge" && this.bridged) {
|
|
@@ -14770,7 +14823,7 @@ var SecondChannel = class {
|
|
|
14770
14823
|
const opts = this.options;
|
|
14771
14824
|
if (opts.mode === "chatty" && !opts.aec && !this.degradedLogged) {
|
|
14772
14825
|
this.degradedLogged = true;
|
|
14773
|
-
|
|
14826
|
+
log31.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
|
|
14774
14827
|
}
|
|
14775
14828
|
const rule = this.rule(trigger, pauseMs, breath, cue);
|
|
14776
14829
|
if (rule === "silence") {
|
|
@@ -14789,14 +14842,14 @@ var SecondChannel = class {
|
|
|
14789
14842
|
const d = await withBudget(this.o.decide(this.tail(), { ...this.state(pauseMs), rule }, ac.signal), this.o.decisionBudgetMs, "channel decision", ac);
|
|
14790
14843
|
choice = d?.choice;
|
|
14791
14844
|
if (choice && choice in CHANNEL_ACTIONS && (choice === "silence" || this.allowed(choice))) kind = choice;
|
|
14792
|
-
else if (choice && choice in CHANNEL_ACTIONS)
|
|
14845
|
+
else if (choice && choice in CHANNEL_ACTIONS) log31.debug(`decider chose ${choice} for a ${rule} moment \u2014 the rule stands`);
|
|
14793
14846
|
}
|
|
14794
14847
|
if (kind === "silence") return ev({ choice, acted: "silence" });
|
|
14795
14848
|
if (stale()) return ev({ choice, kind, acted: "stale" });
|
|
14796
14849
|
if (!this.allowed(kind)) return ev({ choice, kind, acted: "gated" });
|
|
14797
14850
|
const react = kind === "backchannel" && !this.answeringUs && this.o.now() - this.lastReactAt >= this.o.reactionGapMs;
|
|
14798
14851
|
const text = cue && react && !this.recent.some((r) => norm3(r) === norm3(cue.line)) ? cue.line : await this.line(kind, react);
|
|
14799
|
-
if (!text) return ev({ choice, kind, acted: "no_bank" });
|
|
14852
|
+
if (!text) return ev({ choice, kind, acted: "no_bank", ...kind === "bridge" && this.ownWords ? { reason: this.noLine || (gen !== this.gen ? "turn moved on" : "no line") } : {} });
|
|
14800
14853
|
if (stale()) return ev({ choice, kind, text, acted: "stale" });
|
|
14801
14854
|
if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
|
|
14802
14855
|
const said = this.say(kind, text);
|
|
@@ -14823,13 +14876,17 @@ var SecondChannel = class {
|
|
|
14823
14876
|
this.bridgeDraft = null;
|
|
14824
14877
|
this.askLeaf = null;
|
|
14825
14878
|
this.bridgeReady = Promise.resolve();
|
|
14879
|
+
this.noLine = "";
|
|
14826
14880
|
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
|
|
14827
|
-
const gen = this.gen, ac = new AbortController(), own = this.ownWords
|
|
14828
|
-
const
|
|
14881
|
+
const gen = this.gen, ac = new AbortController(), own = this.ownWords;
|
|
14882
|
+
const said = own ? words2(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
|
|
14883
|
+
const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
|
|
14884
|
+
log31.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
|
|
14829
14885
|
this.bridgeReady = withBudget(this.o.generate(ctx, ac.signal), own ? this.o.bridgeBudgetMs : Math.max(this.o.generateBudgetMs, this.o.bridgeDelayMs), "bridge generate", ac).then((raw) => {
|
|
14830
|
-
const
|
|
14831
|
-
if (text && gen === this.gen &&
|
|
14832
|
-
|
|
14886
|
+
const none = own && /^\s*none\b/i.test(raw ?? ""), text = none ? "" : cleanLine(raw ?? "", ctx.lang), echoes = !own || echoesHeard(text, heard);
|
|
14887
|
+
if (text && gen === this.gen && echoes) this.bridgeDraft = { gen, text };
|
|
14888
|
+
else if (gen === this.gen) this.noLine = raw === null ? "fast model late or failed" : none ? "fast model: none" : !text ? "fast model line unusable" : `line names nothing heard: "${text}"`;
|
|
14889
|
+
}).catch((e) => log31.debug(`bridge prefetch failed: ${e?.message ?? e}`));
|
|
14833
14890
|
}
|
|
14834
14891
|
async line(kind, react = true) {
|
|
14835
14892
|
if (kind === "bridge" && this.ownWords) {
|
|
@@ -14856,7 +14913,7 @@ var SecondChannel = class {
|
|
|
14856
14913
|
if (raw === null) ac.abort();
|
|
14857
14914
|
const text = cleanLine(raw ?? "", this.lang);
|
|
14858
14915
|
if (text && !this.recent.some((r) => norm3(r) === norm3(text))) return text;
|
|
14859
|
-
if (text)
|
|
14916
|
+
if (text) log31.debug(`generated "${text}" repeats a recent line \u2014 canned`);
|
|
14860
14917
|
}
|
|
14861
14918
|
return this.pick(kind);
|
|
14862
14919
|
}
|
|
@@ -14880,7 +14937,7 @@ var SecondChannel = class {
|
|
|
14880
14937
|
try {
|
|
14881
14938
|
r = this.o.speak(text, kind);
|
|
14882
14939
|
} catch (e) {
|
|
14883
|
-
|
|
14940
|
+
log31.warn(`speak threw \u2014 line dropped: ${e.message}`);
|
|
14884
14941
|
return false;
|
|
14885
14942
|
}
|
|
14886
14943
|
if (r === false) return false;
|
|
@@ -14894,7 +14951,7 @@ var SecondChannel = class {
|
|
|
14894
14951
|
if (words3) this.o.show(words3, kind);
|
|
14895
14952
|
const p = Promise.resolve(r).then(() => {
|
|
14896
14953
|
}, (e) => {
|
|
14897
|
-
|
|
14954
|
+
log31.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
14898
14955
|
}).finally(() => {
|
|
14899
14956
|
if (this.inflight === p) this.inflight = null;
|
|
14900
14957
|
});
|
|
@@ -14932,20 +14989,28 @@ var KIND_HINT2 = {
|
|
|
14932
14989
|
};
|
|
14933
14990
|
var REACT_HINT = 'a short reaction to their LAST words instead: feeling ("oh no", "ha, nice", "ugh"), surprise ("wait, really?", "huh"), a light laugh if they joke or laugh ("ha!"), or an echo of their key word ("the deploy?") \u2014 still never asks for an answer or takes the turn; if nothing there deserves a reaction, a plain "mm-hm"';
|
|
14934
14991
|
var TAG_HINT = 'Real listeners often react without words: the line may be, or begin with, [laughter] or [gasp], and [quiet] before words breathes them under the voice ("[gasp]", "[laughter]", "[gasp] [quiet] no way"). Use a sound when it fits what they said.';
|
|
14992
|
+
function askPrompt(c, gender) {
|
|
14993
|
+
const last = c.said ? c.said.split(/(?<=[.!?])\s+/).filter((x) => /\w/.test(x)).pop() : "";
|
|
14994
|
+
const said = !c.said ? "" : c.cut ? `You (the assistant) were saying: "\u2026${c.said}" \u2014 they cut you off there, so the last thing they heard was "${last}". Their "that"/"it" means THAT last thing.
|
|
14995
|
+
` : `You (the assistant) last said: "\u2026${c.said}"
|
|
14996
|
+
`;
|
|
14997
|
+
return `A live voice call. ${said}The user just said: "${c.heard}"
|
|
14998
|
+
Your full answer takes a few seconds. Write ONE spoken line of 2-5 words in ${languageName(c.lang)} to say at once, in their or your own words:
|
|
14999
|
+
- they ask you to look up, check, find or do something \u2192 name the thing and say you are on it ("Hacker News, one sec.")
|
|
15000
|
+
- they ask about something you said ("that", "it", "who", "why") \u2192 echo the thing they mean as a short question ("the OpenAI one?", "the Postman thing?") or a quick reaction to it
|
|
15001
|
+
Never state a fact, a name or an answer that was not already said. If it is a closer, thanks, an ok/yes, small talk or a remark that needs no answer, write: none
|
|
15002
|
+
${personaHint(gender)} Output only the line.`;
|
|
15003
|
+
}
|
|
14935
15004
|
function fastLineGenerator(ai, model, gender) {
|
|
14936
15005
|
return async (c, signal) => {
|
|
14937
|
-
const prompt = c.ask ? `
|
|
14938
|
-
If this asks you to look up, check, find or do something that takes a while, write ONE spoken line of 2-5 words in ${languageName(c.lang)} that names the thing in their own words and says you are on it ("Hacker News, one sec."). If it is small talk, a statement, or something you can answer at once, write: none
|
|
14939
|
-
${personaHint(gender)} Output only the line.` : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
|
|
15006
|
+
const prompt = c.ask ? askPrompt(c, gender) : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
|
|
14940
15007
|
` + (c.react ? `Here the line may be ${REACT_HINT}.
|
|
14941
15008
|
` : "") + (c.tags ? `${TAG_HINT}
|
|
14942
15009
|
` : "") + `The user just said: "${c.heard}"
|
|
14943
15010
|
The assistant is: ${c.state}.
|
|
14944
15011
|
` + (c.avoid.length ? `Do not reuse any of: ${c.avoid.map((a) => `"${a}"`).join(", ")}.
|
|
14945
15012
|
` : "") + `React to their actual words, casually, in ${languageName(c.lang)}. ${personaHint(gender)} Output only the line.`;
|
|
14946
|
-
|
|
14947
|
-
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
|
|
14948
|
-
return r.content ?? "";
|
|
15013
|
+
return fastText(ai, { model, prompt, signal });
|
|
14949
15014
|
};
|
|
14950
15015
|
}
|
|
14951
15016
|
function closedQuestion(reply) {
|
|
@@ -14956,7 +15021,7 @@ function closedQuestion(reply) {
|
|
|
14956
15021
|
}
|
|
14957
15022
|
|
|
14958
15023
|
// src/voice/call.ts
|
|
14959
|
-
var
|
|
15024
|
+
var log32 = forComponent("VoiceCall");
|
|
14960
15025
|
function newWords(text, turn) {
|
|
14961
15026
|
const said = new Set(norm3(turn).split(" "));
|
|
14962
15027
|
return norm3(text).split(" ").filter((w) => w && !said.has(w)).length;
|
|
@@ -14973,6 +15038,9 @@ var VoiceCallOptions = class {
|
|
|
14973
15038
|
* runs as MAIN's next turn. Not injected mid-run: that makes MAIN run again just to hear a remark. Absent: such a line
|
|
14974
15039
|
* barges in as before. */
|
|
14975
15040
|
noteTurn;
|
|
15041
|
+
/** What the user HEARD of MAIN's reply a barge just cut (a peek — the host still takes the cut for MAIN), else null:
|
|
15042
|
+
* a live bridge echoes what their "that" points at. */
|
|
15043
|
+
heardCut;
|
|
14976
15044
|
/** Writes that immediate answer (fastWorkReply). */
|
|
14977
15045
|
workReply;
|
|
14978
15046
|
workReplyBudgetMs = 1500;
|
|
@@ -15111,7 +15179,7 @@ var VoiceCall = class {
|
|
|
15111
15179
|
const c = this.cur, steers = !!this.o.noteTurn && this.working;
|
|
15112
15180
|
const resumed = !steers || c.marks.mainFirst === void 0 && this.o.now() - c.at < this.o.resumeMs;
|
|
15113
15181
|
if (this.o.mode === "live" && c?.running && !c.worded && resumed && newWords(text, c.text) >= 2) {
|
|
15114
|
-
|
|
15182
|
+
log32.debug("user resumed before the reply \u2014 yielded");
|
|
15115
15183
|
this.giveWay(c);
|
|
15116
15184
|
this.gate.reopen(c.id);
|
|
15117
15185
|
}
|
|
@@ -15130,9 +15198,13 @@ var VoiceCall = class {
|
|
|
15130
15198
|
this.sttLang = o.lang ? primaryLang(o.lang) : null;
|
|
15131
15199
|
this.lastWordAt = typeof lastWordAgoMs === "number" && lastWordAgoMs >= 0 ? now3 - lastWordAgoMs : null;
|
|
15132
15200
|
this.finalAt = now3;
|
|
15201
|
+
this.floor = `${this.floor} ${text}`.trim();
|
|
15202
|
+
if (!endsMidPhrase(text) && turnIntent(this.floor) !== "say") this.fill.onLineEnd();
|
|
15133
15203
|
this.gate.final(text, sttId);
|
|
15134
15204
|
}
|
|
15135
15205
|
finalAt = 0;
|
|
15206
|
+
floor = "";
|
|
15207
|
+
// the finals said since the last turn went out
|
|
15136
15208
|
sttLang = null;
|
|
15137
15209
|
// the STT's language for the final being followed
|
|
15138
15210
|
/** The host's player started a line's audio now (or in `inMs`): `fill`/`progress` = the fill channel's, `main` = MAIN's
|
|
@@ -15232,7 +15304,7 @@ var VoiceCall = class {
|
|
|
15232
15304
|
try {
|
|
15233
15305
|
this.o.cancel();
|
|
15234
15306
|
} catch (e) {
|
|
15235
|
-
|
|
15307
|
+
log32.warn(`cancel threw: ${e.message}`);
|
|
15236
15308
|
}
|
|
15237
15309
|
return;
|
|
15238
15310
|
}
|
|
@@ -15244,7 +15316,7 @@ var VoiceCall = class {
|
|
|
15244
15316
|
try {
|
|
15245
15317
|
this.o.cancel();
|
|
15246
15318
|
} catch (e) {
|
|
15247
|
-
|
|
15319
|
+
log32.warn(`cancel threw: ${e.message}`);
|
|
15248
15320
|
}
|
|
15249
15321
|
if (c?.running) {
|
|
15250
15322
|
c.running = false;
|
|
@@ -15296,6 +15368,7 @@ var VoiceCall = class {
|
|
|
15296
15368
|
if (l) this.fill.setLanguage(l, true);
|
|
15297
15369
|
}
|
|
15298
15370
|
onTurn(t) {
|
|
15371
|
+
this.floor = "";
|
|
15299
15372
|
if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
|
|
15300
15373
|
const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
|
|
15301
15374
|
const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
|
|
@@ -15315,13 +15388,14 @@ var VoiceCall = class {
|
|
|
15315
15388
|
this.progress.turn();
|
|
15316
15389
|
this.o.onMetric({ name: "turn", id: t.id, kind: t.kind, text: t.text });
|
|
15317
15390
|
this.o.sendTurn(t.text, { id: t.id, ...t.replaces ? { replaces: t.replaces } : {} });
|
|
15318
|
-
if (t.kind === "new") this.fill.onUserTurn(t.text, now3 - at);
|
|
15391
|
+
if (t.kind === "new") this.fill.onUserTurn(t.text, now3 - at, this.o.heardCut?.() ?? void 0);
|
|
15319
15392
|
}
|
|
15320
15393
|
onDrop(text, why) {
|
|
15321
15394
|
if (!this.gate.holding) {
|
|
15322
15395
|
this.firstFinalAt = null;
|
|
15323
15396
|
this.lastWordAt = null;
|
|
15324
15397
|
this.earlyHeard = null;
|
|
15398
|
+
this.floor = "";
|
|
15325
15399
|
}
|
|
15326
15400
|
this.o.onMetric({ name: "drop", kind: why, text });
|
|
15327
15401
|
}
|
|
@@ -15332,7 +15406,7 @@ var VoiceCall = class {
|
|
|
15332
15406
|
try {
|
|
15333
15407
|
r = this.o.speak(text, kind);
|
|
15334
15408
|
} catch (e) {
|
|
15335
|
-
|
|
15409
|
+
log32.warn(`speak threw: ${e.message}`);
|
|
15336
15410
|
return false;
|
|
15337
15411
|
}
|
|
15338
15412
|
if (r === false) return false;
|
|
@@ -15392,7 +15466,7 @@ var VoiceCall = class {
|
|
|
15392
15466
|
this.o.onMetric({ name: "turn", id: t.id, kind: "aside", text: t.text });
|
|
15393
15467
|
const ac = new AbortController(), late = setTimeout(() => ac.abort(), this.o.workReplyBudgetMs), lang = this.lang;
|
|
15394
15468
|
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) => {
|
|
15395
|
-
|
|
15469
|
+
log32.warn(`work reply failed \u2014 MAIN only: ${e?.message ?? e}`);
|
|
15396
15470
|
return "";
|
|
15397
15471
|
}).finally(() => clearTimeout(late)) : "";
|
|
15398
15472
|
const own = cleanWorkReply(raw, lang ?? ""), answer = own || workAck(raw, lang ?? "", this.o.gender);
|