@livx.cc/agentx 0.99.156 → 0.99.157
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 +99 -61
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +81 -55
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -945,11 +945,13 @@ declare function formatCatalog(entries: CatalogEntry[], opts: CatalogOptions): s
|
|
|
945
945
|
* treats hold as cut. */
|
|
946
946
|
type OverlapVerdict = 'keep' | 'cut' | 'hold';
|
|
947
947
|
|
|
948
|
+
/** A short closing line ("ok bye", "thanks, see you", "ביי", "להתראות"). Long lines that merely contain "bye" are not. */
|
|
949
|
+
declare function isClosing(text: string): boolean;
|
|
950
|
+
|
|
948
951
|
/** Does the user's line stop mid-phrase (trailing connective / spelled punctuation / comma / slash)? Only the user's own
|
|
949
952
|
* words count — host notes appended after a newline ("[the user interrupted you…]") are ignored. */
|
|
950
953
|
declare function endsMidPhrase(text: string): boolean;
|
|
951
|
-
|
|
952
|
-
declare function isClosing(text: string): boolean;
|
|
954
|
+
|
|
953
955
|
interface GateTurn {
|
|
954
956
|
id: string;
|
|
955
957
|
/** The user's words, verbatim (several finals joined by a space when merged). */
|
|
@@ -1859,6 +1861,8 @@ declare class VoiceCallOptions {
|
|
|
1859
1861
|
speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
|
|
1860
1862
|
/** Stop the in-flight fill line now (barge-in only). */
|
|
1861
1863
|
cancel: () => void;
|
|
1864
|
+
/** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
|
|
1865
|
+
cutAudio: () => void;
|
|
1862
1866
|
/** Host caption — never history. */
|
|
1863
1867
|
show: (text: string, kind: FillKind) => void;
|
|
1864
1868
|
/** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
|
package/dist/index.js
CHANGED
|
@@ -6384,14 +6384,14 @@ function summarize(messages, focus) {
|
|
|
6384
6384
|
if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
|
|
6385
6385
|
if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
|
|
6386
6386
|
if (focus?.trim()) {
|
|
6387
|
-
const
|
|
6387
|
+
const words4 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
6388
6388
|
const kept = [];
|
|
6389
6389
|
const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
|
|
6390
6390
|
outer: for (const msg of ordered) {
|
|
6391
6391
|
if (msg.role === "tool") continue;
|
|
6392
6392
|
for (const line of contentText(msg.content).split("\n")) {
|
|
6393
6393
|
const l = line.toLowerCase();
|
|
6394
|
-
if (line.trim() &&
|
|
6394
|
+
if (line.trim() && words4.some((w) => l.includes(w))) {
|
|
6395
6395
|
kept.push(line.trim().slice(0, 200));
|
|
6396
6396
|
if (kept.length >= 12) break outer;
|
|
6397
6397
|
}
|
|
@@ -7663,13 +7663,13 @@ function isTranscriptComplete(text) {
|
|
|
7663
7663
|
const trimmed = text.trim();
|
|
7664
7664
|
if (!trimmed) return false;
|
|
7665
7665
|
if (/[.?!]$/.test(trimmed)) return true;
|
|
7666
|
-
const
|
|
7667
|
-
const lastWord =
|
|
7666
|
+
const words4 = trimmed.toLowerCase().split(/\s+/);
|
|
7667
|
+
const lastWord = words4[words4.length - 1];
|
|
7668
7668
|
if (COMPLETE_ENDINGS.has(lastWord)) return true;
|
|
7669
7669
|
if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
|
|
7670
7670
|
const lower2 = trimmed.toLowerCase();
|
|
7671
7671
|
for (const marker of CONTINUATION_MARKERS) if (lower2.endsWith(marker)) return false;
|
|
7672
|
-
if (
|
|
7672
|
+
if (words4.length <= 2) return false;
|
|
7673
7673
|
return true;
|
|
7674
7674
|
}
|
|
7675
7675
|
var MAX_HOLD_MS = 2e3;
|
|
@@ -7719,12 +7719,12 @@ var SpeakerRunsOptions = class {
|
|
|
7719
7719
|
/** A run shorter than this (a diarization flap) joins its neighbour — the previous run, or the next for a leading one. */
|
|
7720
7720
|
minRunWords = 2;
|
|
7721
7721
|
};
|
|
7722
|
-
function speakerRuns(
|
|
7722
|
+
function speakerRuns(words4, options) {
|
|
7723
7723
|
const { minRunWords } = { ...new SpeakerRunsOptions(), ...options };
|
|
7724
7724
|
let runs = [];
|
|
7725
|
-
for (const w of
|
|
7725
|
+
for (const w of words4) {
|
|
7726
7726
|
const last = runs[runs.length - 1];
|
|
7727
|
-
const spk = w.spk ?? last?.spk ??
|
|
7727
|
+
const spk = w.spk ?? last?.spk ?? words4.find((x) => x.spk != null)?.spk ?? "";
|
|
7728
7728
|
if (last?.spk === spk) last.words.push(w);
|
|
7729
7729
|
else runs.push({ spk, words: [w] });
|
|
7730
7730
|
}
|
|
@@ -8190,13 +8190,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8190
8190
|
};
|
|
8191
8191
|
if (this.options.revealMode === "word" || this.options.heardTimestamps) {
|
|
8192
8192
|
this.tts.wantTimestamps = true;
|
|
8193
|
-
this.tts.onTimestamps = (
|
|
8193
|
+
this.tts.onTimestamps = (words4, start) => {
|
|
8194
8194
|
if (this.interrupted) return;
|
|
8195
8195
|
start.forEach((s, i) => {
|
|
8196
|
-
if (this.wordAnchorPending) this.wordPending.push([
|
|
8196
|
+
if (this.wordAnchorPending) this.wordPending.push([words4[i] ?? "", s]);
|
|
8197
8197
|
else {
|
|
8198
8198
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8199
|
-
this.wordTexts.push(
|
|
8199
|
+
this.wordTexts.push(words4[i] ?? "");
|
|
8200
8200
|
}
|
|
8201
8201
|
});
|
|
8202
8202
|
};
|
|
@@ -8471,8 +8471,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8471
8471
|
while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
|
|
8472
8472
|
if (n !== this.revealedN) {
|
|
8473
8473
|
this.revealedN = n;
|
|
8474
|
-
const
|
|
8475
|
-
this.options.onReveal(
|
|
8474
|
+
const words4 = this.revealText.trim().split(/\s+/).filter(Boolean);
|
|
8475
|
+
this.options.onReveal(words4.slice(0, n).join(" "));
|
|
8476
8476
|
}
|
|
8477
8477
|
this.revealPoll = this.clock.setTimeout(tick, 60);
|
|
8478
8478
|
};
|
|
@@ -9318,7 +9318,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9318
9318
|
const names = lines.map((t) => this.options.speakerResolver.name(t.speaker, t));
|
|
9319
9319
|
return { out: formatTurns(lines, (t) => names[lines.indexOf(t)]), speakers: [...new Set(names)] };
|
|
9320
9320
|
}
|
|
9321
|
-
|
|
9321
|
+
/** `judged`: the host yielded to these very words (decideOverlap) — the user's, never our echo. */
|
|
9322
|
+
handleUtterance(text, langs, rawTurns, judged = false) {
|
|
9322
9323
|
let turns;
|
|
9323
9324
|
const cap = this.uttEcho;
|
|
9324
9325
|
this.uttEcho = void 0;
|
|
@@ -9352,12 +9353,23 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9352
9353
|
}
|
|
9353
9354
|
}
|
|
9354
9355
|
const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
|
|
9356
|
+
if (this.speaking && this.ctxOpen && !this.pausedAt && this.overlapCapable && !ownTail && this.options.overlapDecideMs > 0 && this.shortOverlap(text) && this.novelWords(text).length > 0 && this.novelWords(text).length * 2 >= this.words(text).length) {
|
|
9357
|
+
this.pausedAt = this.clock.now();
|
|
9358
|
+
this.player.pause();
|
|
9359
|
+
this.lastOverlapPartial = text;
|
|
9360
|
+
this.decideHeldFinal = text;
|
|
9361
|
+
addLangs(this.decideHeldLangs, langs);
|
|
9362
|
+
this.decideHeldTurns.push(...turns);
|
|
9363
|
+
this.diag("overlap_pause", { text: text.slice(0, 60), final: true });
|
|
9364
|
+
this.awaitOverlapDecision(text);
|
|
9365
|
+
return;
|
|
9366
|
+
}
|
|
9355
9367
|
if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
|
|
9356
9368
|
this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
|
|
9357
9369
|
this.stt.reset();
|
|
9358
9370
|
return;
|
|
9359
9371
|
}
|
|
9360
|
-
if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
|
|
9372
|
+
if (!judged && this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
|
|
9361
9373
|
this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
|
|
9362
9374
|
this.stt.reset();
|
|
9363
9375
|
return;
|
|
@@ -9514,7 +9526,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9514
9526
|
this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
|
|
9515
9527
|
this.interrupt();
|
|
9516
9528
|
this.options.onBargeIn(phase);
|
|
9517
|
-
if (held) this.handleUtterance(held, heldLangs, heldTurns);
|
|
9529
|
+
if (held) this.handleUtterance(held, heldLangs, heldTurns, trigger === "host_yield");
|
|
9518
9530
|
}
|
|
9519
9531
|
/** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
|
|
9520
9532
|
* was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
|
|
@@ -10100,8 +10112,8 @@ var SonioxSTT = class {
|
|
|
10100
10112
|
/** Per-speaker turns of the current utterance (diarization only; undefined otherwise or when Soniox tagged no speaker). */
|
|
10101
10113
|
turns(withPartials) {
|
|
10102
10114
|
if (!this.options.diarization) return void 0;
|
|
10103
|
-
const
|
|
10104
|
-
return
|
|
10115
|
+
const words4 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
|
|
10116
|
+
return words4.some((w) => w.spk != null) ? speakerRuns(words4) : void 0;
|
|
10105
10117
|
}
|
|
10106
10118
|
reset() {
|
|
10107
10119
|
this.finalToks = [];
|
|
@@ -10455,6 +10467,14 @@ import { AIClient, DecideClient, JevAdapter, LlmDecideAdapter } from "ai.libx.js
|
|
|
10455
10467
|
|
|
10456
10468
|
// src/voice/overlap.ts
|
|
10457
10469
|
init_logging();
|
|
10470
|
+
|
|
10471
|
+
// src/voice/closing.ts
|
|
10472
|
+
var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
10473
|
+
function isClosing(text) {
|
|
10474
|
+
return words(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
|
|
10475
|
+
}
|
|
10476
|
+
|
|
10477
|
+
// src/voice/overlap.ts
|
|
10458
10478
|
var log21 = forComponent("Overlap");
|
|
10459
10479
|
var norm2 = (s) => s.toLowerCase().replace(/[’']/g, "'").replace(/[^\p{L}\p{N}' -]+/gu, " ").replace(/\s+/g, " ").trim();
|
|
10460
10480
|
var HARD = /^(?:(?:stop|wait|no|nope|hold on|hang on|hold up|pause|cancel|quiet|enough|shut up|never ?mind)(?: |$))+$/;
|
|
@@ -10498,19 +10518,20 @@ function overlapRule(text) {
|
|
|
10498
10518
|
if (CONTINUE.test(norm2(text))) return "keep";
|
|
10499
10519
|
let t = norm2(text);
|
|
10500
10520
|
if (!t) return void 0;
|
|
10521
|
+
if (isClosing(text)) return "cut";
|
|
10501
10522
|
if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
|
|
10502
10523
|
for (const p of PHRASES) t = t.split(p).join(" ");
|
|
10503
|
-
const
|
|
10524
|
+
const words4 = t.split(/[\s-]+/).filter(Boolean);
|
|
10504
10525
|
const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
|
|
10505
|
-
if (
|
|
10506
|
-
const lead2 =
|
|
10507
|
-
if (lead2 >= 0 && LEADER.has(
|
|
10526
|
+
if (words4.every(ack)) return "keep";
|
|
10527
|
+
const lead2 = words4.findIndex((w) => !LEAD.has(w));
|
|
10528
|
+
if (lead2 >= 0 && LEADER.has(words4[lead2]) && !words4.some((w) => HARD.test(w + " ")) && words4.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
|
|
10508
10529
|
return void 0;
|
|
10509
10530
|
}
|
|
10510
10531
|
function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
|
|
10511
10532
|
return async (heard, signal) => {
|
|
10512
10533
|
const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
|
|
10513
|
-
Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it,
|
|
10534
|
+
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.
|
|
10514
10535
|
Answer yes (steering) or no (a reaction).`;
|
|
10515
10536
|
const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
10516
10537
|
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
|
|
@@ -10957,8 +10978,8 @@ function cleanLine(s, lang, maxWords = 6) {
|
|
|
10957
10978
|
const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
|
|
10958
10979
|
const raw = first.replace(LINE_TAG, " ").trim();
|
|
10959
10980
|
if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
|
|
10960
|
-
const
|
|
10961
|
-
return
|
|
10981
|
+
const words4 = cleanWords(raw, lang, maxWords);
|
|
10982
|
+
return words4 && tags ? `${tags} ${words4}` : words4;
|
|
10962
10983
|
}
|
|
10963
10984
|
var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
|
|
10964
10985
|
var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
|
|
@@ -11167,10 +11188,7 @@ function endsMidPhrase(text) {
|
|
|
11167
11188
|
if (TRAILING_PREPS.has(last)) return !QUESTION_START.test(t) && !PHRASAL_HOST.has(prev);
|
|
11168
11189
|
return MID_PHRASE_WORDS.has(last);
|
|
11169
11190
|
}
|
|
11170
|
-
var
|
|
11171
|
-
function isClosing(text) {
|
|
11172
|
-
return words(text).length <= 8 && /(?:^|[^\p{L}])(?:good ?bye|bye|see you|good ?night|talk (?:to you )?later|hang up|end (?:the )?call|ביי|להתראות|נתראה|לילה טוב|יאללה ביי)(?:$|[^\p{L}])/iu.test(text);
|
|
11173
|
-
}
|
|
11191
|
+
var words2 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
11174
11192
|
var TurnGateOptions = class {
|
|
11175
11193
|
holdMs = 1200;
|
|
11176
11194
|
/** A finished statement (not a question) waits this long for more speech before it is a turn. 0 = sent at once. */
|
|
@@ -11302,7 +11320,7 @@ var TurnGate = class {
|
|
|
11302
11320
|
}
|
|
11303
11321
|
refinal(last, t, key, sttId) {
|
|
11304
11322
|
if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
|
|
11305
|
-
const a =
|
|
11323
|
+
const a = words2(last.text), b = words2(t);
|
|
11306
11324
|
let i = 0;
|
|
11307
11325
|
while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
|
|
11308
11326
|
const extra = b.slice(i).join(" ");
|
|
@@ -11349,8 +11367,8 @@ function isFalseStart(sentence) {
|
|
|
11349
11367
|
return !!m && !/^(?:h+m+|u+m+|u+h+|o+h+|a+h+|well|so|er+m*)$/i.test(m[1]);
|
|
11350
11368
|
}
|
|
11351
11369
|
function wordOverlap(sentence, prior) {
|
|
11352
|
-
const
|
|
11353
|
-
const have = new Set(
|
|
11370
|
+
const words4 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
|
|
11371
|
+
const have = new Set(words4(prior)), ws = words4(sentence);
|
|
11354
11372
|
return ws.length ? ws.filter((w) => have.has(w)).length / ws.length : 0;
|
|
11355
11373
|
}
|
|
11356
11374
|
var DuplexAgentOptions = class {
|
|
@@ -13898,8 +13916,8 @@ var ConvoTree = class {
|
|
|
13898
13916
|
this.from = heardWords;
|
|
13899
13917
|
}
|
|
13900
13918
|
/** Posterior of a node after seeing its cue. */
|
|
13901
|
-
confidence(p,
|
|
13902
|
-
const l = p * (
|
|
13919
|
+
confidence(p, words4) {
|
|
13920
|
+
const l = p * (words4 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
|
|
13903
13921
|
return l / (l + 1 - p);
|
|
13904
13922
|
}
|
|
13905
13923
|
/** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
|
|
@@ -14322,10 +14340,10 @@ var SecondChannelOptions = class {
|
|
|
14322
14340
|
now = () => performance.now();
|
|
14323
14341
|
random = Math.random;
|
|
14324
14342
|
};
|
|
14325
|
-
var
|
|
14343
|
+
var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
14326
14344
|
var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
|
|
14327
14345
|
var onlyHesitation = (s) => {
|
|
14328
|
-
const w =
|
|
14346
|
+
const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
|
|
14329
14347
|
return !!w.length && w.every((x) => HESITATION.test(x));
|
|
14330
14348
|
};
|
|
14331
14349
|
function withBudget(p, ms, what, ac) {
|
|
@@ -14491,7 +14509,7 @@ var SecondChannel = class {
|
|
|
14491
14509
|
if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
|
|
14492
14510
|
if (!this.tree.empty) {
|
|
14493
14511
|
this.treeStep(t);
|
|
14494
|
-
if (!this.regrown &&
|
|
14512
|
+
if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
|
|
14495
14513
|
this.regrown = true;
|
|
14496
14514
|
this.requestTree(t);
|
|
14497
14515
|
}
|
|
@@ -14504,7 +14522,7 @@ var SecondChannel = class {
|
|
|
14504
14522
|
}
|
|
14505
14523
|
}
|
|
14506
14524
|
if (this.o.anticipate && !this.tree) {
|
|
14507
|
-
const n =
|
|
14525
|
+
const n = words3(t).length;
|
|
14508
14526
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
14509
14527
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
14510
14528
|
this.revised = true;
|
|
@@ -14517,7 +14535,7 @@ var SecondChannel = class {
|
|
|
14517
14535
|
this.bcTimer = null;
|
|
14518
14536
|
if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
|
|
14519
14537
|
}, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
|
|
14520
|
-
if (
|
|
14538
|
+
if (words3(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
|
|
14521
14539
|
}
|
|
14522
14540
|
/** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
|
|
14523
14541
|
onPause(ms) {
|
|
@@ -14612,7 +14630,7 @@ var SecondChannel = class {
|
|
|
14612
14630
|
this.heard = text.trim();
|
|
14613
14631
|
this.said = (heardCut ?? this.reply).trim();
|
|
14614
14632
|
this.lastWordAgo = Math.max(0, lastWordAgoMs);
|
|
14615
|
-
this.floorWords = this.carried +
|
|
14633
|
+
this.floorWords = this.carried + words3(this.heard).length;
|
|
14616
14634
|
this.lastUser = this.heard;
|
|
14617
14635
|
this.detect(this.heard);
|
|
14618
14636
|
this.main = "idle";
|
|
@@ -14671,7 +14689,7 @@ var SecondChannel = class {
|
|
|
14671
14689
|
return this.main === "first_audio" || this.main === "speaking";
|
|
14672
14690
|
}
|
|
14673
14691
|
tail() {
|
|
14674
|
-
return
|
|
14692
|
+
return words3(this.heard).slice(-this.o.microWords).join(" ");
|
|
14675
14693
|
}
|
|
14676
14694
|
/** Hard gates every line passes, whoever proposed it. */
|
|
14677
14695
|
allowed(k) {
|
|
@@ -14690,7 +14708,7 @@ var SecondChannel = class {
|
|
|
14690
14708
|
}
|
|
14691
14709
|
/** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
|
|
14692
14710
|
bridgeBlock() {
|
|
14693
|
-
const w =
|
|
14711
|
+
const w = words3(this.heard), intent = turnIntent(this.heard);
|
|
14694
14712
|
if (!this.lang) return "language unknown";
|
|
14695
14713
|
if (this.ownWords) return this.blocked("bridge");
|
|
14696
14714
|
if (intent === "closer") return "no answer due";
|
|
@@ -14713,7 +14731,7 @@ var SecondChannel = class {
|
|
|
14713
14731
|
}
|
|
14714
14732
|
/** 0ms rule: the candidate line for this trigger, or silence. */
|
|
14715
14733
|
rule(trigger, pauseMs = 0, breath = false, cue = null) {
|
|
14716
|
-
const w =
|
|
14734
|
+
const w = words3(this.heard);
|
|
14717
14735
|
if (!this.lang) return "silence";
|
|
14718
14736
|
if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
|
|
14719
14737
|
if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
|
|
@@ -14728,7 +14746,7 @@ var SecondChannel = class {
|
|
|
14728
14746
|
this.planning = true;
|
|
14729
14747
|
this.planTries++;
|
|
14730
14748
|
}
|
|
14731
|
-
const ctx = { agent: this.reply.trim(), user:
|
|
14749
|
+
const ctx = { agent: this.reply.trim(), user: words3(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
|
|
14732
14750
|
void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
|
|
14733
14751
|
if (p === null) ac.abort();
|
|
14734
14752
|
if (turn !== this.turnNo) return;
|
|
@@ -14750,7 +14768,7 @@ var SecondChannel = class {
|
|
|
14750
14768
|
const ctx = { talk: heard ? [...this.talk, `them (still talking): ${heard.slice(-240)}`] : [...this.talk], lang: detectLanguage(this.talk.join(" ").replace(/\b(them|you):/g, "")) ?? this.lang, recent: this.leaves.slice(-this.o.leafMemory), ...this.o.persona ? { persona: this.o.persona } : {} };
|
|
14751
14769
|
const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
|
|
14752
14770
|
void this.o.grow(ctx, ac.signal).then((r) => {
|
|
14753
|
-
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ?
|
|
14771
|
+
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words3(this.heard).length : 0);
|
|
14754
14772
|
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 } : {} });
|
|
14755
14773
|
}, (e) => {
|
|
14756
14774
|
log31.warn(`tree failed: ${e?.message ?? e}`);
|
|
@@ -14766,10 +14784,10 @@ var SecondChannel = class {
|
|
|
14766
14784
|
if (!hit) return;
|
|
14767
14785
|
if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
|
|
14768
14786
|
if (this.leafTimer) clearTimeout(this.leafTimer);
|
|
14769
|
-
const at =
|
|
14787
|
+
const at = words3(t).length;
|
|
14770
14788
|
this.leafTimer = setTimeout(() => {
|
|
14771
14789
|
this.leafTimer = null;
|
|
14772
|
-
if (this.userSpeaking &&
|
|
14790
|
+
if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
|
|
14773
14791
|
}, this.o.cuePauseMs);
|
|
14774
14792
|
}
|
|
14775
14793
|
/** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
|
|
@@ -14779,14 +14797,14 @@ var SecondChannel = class {
|
|
|
14779
14797
|
if (!this.o.pickLeaf || !this.o.aec) return;
|
|
14780
14798
|
this.breathTimer = setTimeout(() => {
|
|
14781
14799
|
this.breathTimer = null;
|
|
14782
|
-
const n =
|
|
14800
|
+
const n = words3(t).length, tree = this.tree;
|
|
14783
14801
|
if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
|
|
14784
14802
|
this.picking = true;
|
|
14785
14803
|
const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
|
|
14786
14804
|
void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
|
|
14787
14805
|
this.picking = false;
|
|
14788
14806
|
const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
|
|
14789
|
-
if (!hit || !this.userSpeaking ||
|
|
14807
|
+
if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
|
|
14790
14808
|
tree.take(hit.node, hit.conf);
|
|
14791
14809
|
this.playLeaf(hit, "interim", "backchannel");
|
|
14792
14810
|
});
|
|
@@ -14856,7 +14874,7 @@ var SecondChannel = class {
|
|
|
14856
14874
|
if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
|
|
14857
14875
|
return;
|
|
14858
14876
|
}
|
|
14859
|
-
const n0 =
|
|
14877
|
+
const n0 = words3(this.heard).length;
|
|
14860
14878
|
this.decidedAt = n0;
|
|
14861
14879
|
if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
|
|
14862
14880
|
const opts = this.options;
|
|
@@ -14872,7 +14890,7 @@ var SecondChannel = class {
|
|
|
14872
14890
|
this.busy = true;
|
|
14873
14891
|
const gen = this.gen, t0 = this.o.now();
|
|
14874
14892
|
const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
|
|
14875
|
-
const stale = () => gen !== this.gen ||
|
|
14893
|
+
const stale = () => gen !== this.gen || words3(this.heard).length - n0 >= this.o.staleWords;
|
|
14876
14894
|
try {
|
|
14877
14895
|
let kind = rule;
|
|
14878
14896
|
let choice;
|
|
@@ -14892,7 +14910,7 @@ var SecondChannel = class {
|
|
|
14892
14910
|
if (stale()) return ev({ choice, kind, text, acted: "stale" });
|
|
14893
14911
|
if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
|
|
14894
14912
|
const said = this.say(kind, text);
|
|
14895
|
-
if (said && cue) this.cueFrom =
|
|
14913
|
+
if (said && cue) this.cueFrom = words3(this.heard).length;
|
|
14896
14914
|
if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
|
|
14897
14915
|
ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
|
|
14898
14916
|
} finally {
|
|
@@ -14918,7 +14936,7 @@ var SecondChannel = class {
|
|
|
14918
14936
|
this.noLine = "";
|
|
14919
14937
|
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
|
|
14920
14938
|
const gen = this.gen, ac = new AbortController(), own = this.ownWords;
|
|
14921
|
-
const said = own ?
|
|
14939
|
+
const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
|
|
14922
14940
|
const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
|
|
14923
14941
|
log31.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
|
|
14924
14942
|
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) => {
|
|
@@ -14986,8 +15004,8 @@ var SecondChannel = class {
|
|
|
14986
15004
|
if (kind === "bridge") this.bridged = true;
|
|
14987
15005
|
this.recent = [...this.recent, text].slice(-this.o.avoidLines);
|
|
14988
15006
|
this.live = lineWords(text);
|
|
14989
|
-
const
|
|
14990
|
-
if (
|
|
15007
|
+
const words4 = this.live;
|
|
15008
|
+
if (words4) this.o.show(words4, kind);
|
|
14991
15009
|
const p = Promise.resolve(r).then(() => {
|
|
14992
15010
|
}, (e) => {
|
|
14993
15011
|
log31.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
@@ -15100,6 +15118,9 @@ var VoiceCallOptions = class {
|
|
|
15100
15118
|
/** Stop the in-flight fill line now (barge-in only). */
|
|
15101
15119
|
cancel = () => {
|
|
15102
15120
|
};
|
|
15121
|
+
/** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
|
|
15122
|
+
cutAudio = () => {
|
|
15123
|
+
};
|
|
15103
15124
|
/** Host caption — never history. */
|
|
15104
15125
|
show = () => {
|
|
15105
15126
|
};
|
|
@@ -15568,6 +15589,11 @@ var VoiceCall = class {
|
|
|
15568
15589
|
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;
|
|
15569
15590
|
this.gate.replyStarted(c.id);
|
|
15570
15591
|
const end = mv.kind === "say" && !!mv.end;
|
|
15592
|
+
if (end) try {
|
|
15593
|
+
this.o.cutAudio();
|
|
15594
|
+
} catch (e) {
|
|
15595
|
+
log32.warn(`cutAudio threw: ${e.message}`);
|
|
15596
|
+
}
|
|
15571
15597
|
const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
|
|
15572
15598
|
if (!played && !end) return this.close(c, "silent");
|
|
15573
15599
|
if (played) this.o.show(said, "reply");
|