@livx.cc/agentx 0.99.155 → 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 +206 -86
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.js +122 -66
- 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). */
|
|
@@ -1699,9 +1701,12 @@ interface QuickContext {
|
|
|
1699
1701
|
/** The unsaid rest of an answer the user just cut ('' = none). */
|
|
1700
1702
|
rest?: string;
|
|
1701
1703
|
}
|
|
1702
|
-
type QuickMove =
|
|
1704
|
+
type QuickMove =
|
|
1705
|
+
/** `end`: a farewell to someone ending the call — the host hangs up once it has played. */
|
|
1706
|
+
{
|
|
1703
1707
|
kind: 'say';
|
|
1704
1708
|
line: string;
|
|
1709
|
+
end?: true;
|
|
1705
1710
|
} | {
|
|
1706
1711
|
kind: 'deep';
|
|
1707
1712
|
ack: string;
|
|
@@ -1810,7 +1815,7 @@ interface TurnTimeline {
|
|
|
1810
1815
|
end?: 'answered' | 'cut' | 'replaced' | 'silent';
|
|
1811
1816
|
}
|
|
1812
1817
|
interface CallMetric {
|
|
1813
|
-
name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane';
|
|
1818
|
+
name: 'first_sound' | 'first_word' | 'turn' | 'drop' | 'hold' | 'fill' | 'lang' | 'timeline' | 'lane' | 'hangup';
|
|
1814
1819
|
id?: string;
|
|
1815
1820
|
/** ms from the user's last word (see TurnTimeline) */
|
|
1816
1821
|
ms?: number;
|
|
@@ -1843,6 +1848,9 @@ declare class VoiceCallOptions {
|
|
|
1843
1848
|
/** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
|
|
1844
1849
|
* cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
|
|
1845
1850
|
quick?: QuickDecider;
|
|
1851
|
+
/** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
|
|
1852
|
+
* played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
|
|
1853
|
+
hangUp?: () => void;
|
|
1846
1854
|
/** Past this the turn goes to MAIN as before (the bridge covers it). */
|
|
1847
1855
|
quickBudgetMs: number;
|
|
1848
1856
|
/** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
|
|
@@ -1853,6 +1861,8 @@ declare class VoiceCallOptions {
|
|
|
1853
1861
|
speak: (text: string, kind: FillKind) => Promise<unknown> | boolean;
|
|
1854
1862
|
/** Stop the in-flight fill line now (barge-in only). */
|
|
1855
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;
|
|
1856
1866
|
/** Host caption — never history. */
|
|
1857
1867
|
show: (text: string, kind: FillKind) => void;
|
|
1858
1868
|
/** The user's words that start no MAIN turn — the host's transcript shows them (sendTurn shows the rest): `quick` = a
|
|
@@ -1979,7 +1989,7 @@ declare class VoiceCall {
|
|
|
1979
1989
|
private quickTurn;
|
|
1980
1990
|
/** The quick lane's answer became audible at `at`: the turn's first word, and it is answered. */
|
|
1981
1991
|
private quickWorded;
|
|
1982
|
-
/** say(), retried while the host's player is busy (
|
|
1992
|
+
/** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
|
|
1983
1993
|
private sayRetry;
|
|
1984
1994
|
private onDrop;
|
|
1985
1995
|
/** Every fill/progress line passes here: only in the turn's known language, never after the call ended. */
|
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
|
|
@@ -14046,9 +14064,17 @@ var ProgressOptions = class {
|
|
|
14046
14064
|
now = () => performance.now();
|
|
14047
14065
|
};
|
|
14048
14066
|
function argsHint(args) {
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
|
|
14067
|
+
const s = !args || typeof args !== "object" ? args : Object.values(args).find((v) => typeof v === "string" && v.trim());
|
|
14068
|
+
return typeof s === "string" ? urlWords(s.trim()).replace(/\s+/g, " ").slice(0, 40).trim() : "";
|
|
14069
|
+
}
|
|
14070
|
+
function urlWords(s) {
|
|
14071
|
+
if (!/^https?:\/\/\S+$/i.test(s)) return s;
|
|
14072
|
+
try {
|
|
14073
|
+
const u = new URL(s), host = u.hostname.replace(/^www\./, "").split(".").slice(0, -1).filter((p) => p.length > 2);
|
|
14074
|
+
return [...host, ...decodeURIComponent(u.pathname).split(/[/._-]+/)].filter((w) => new RegExp("\\p{L}{2}", "u").test(w) && !/^(?:html?|php|aspx?|index)$/i.test(w)).join(" ");
|
|
14075
|
+
} catch {
|
|
14076
|
+
return s;
|
|
14077
|
+
}
|
|
14052
14078
|
}
|
|
14053
14079
|
var Progress = class {
|
|
14054
14080
|
constructor(options) {
|
|
@@ -14131,13 +14157,17 @@ var Progress = class {
|
|
|
14131
14157
|
return null;
|
|
14132
14158
|
}), late]).finally(() => clearTimeout(t));
|
|
14133
14159
|
const l = cleanLine(raw ?? "", lang, 5);
|
|
14134
|
-
|
|
14160
|
+
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" : "";
|
|
14161
|
+
if (why) {
|
|
14162
|
+
log30.debug(`no line for ${tool || "(no tool)"}: ${why}`);
|
|
14163
|
+
return "";
|
|
14164
|
+
}
|
|
14135
14165
|
return l;
|
|
14136
14166
|
}
|
|
14137
14167
|
};
|
|
14138
14168
|
function fastProgressGenerator(ai, model, gender) {
|
|
14139
14169
|
return async (tool, hint, lang, signal, avoid = []) => {
|
|
14140
|
-
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.`;
|
|
14170
|
+
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.`;
|
|
14141
14171
|
return fastText(ai, { model, prompt, signal });
|
|
14142
14172
|
};
|
|
14143
14173
|
}
|
|
@@ -14310,10 +14340,10 @@ var SecondChannelOptions = class {
|
|
|
14310
14340
|
now = () => performance.now();
|
|
14311
14341
|
random = Math.random;
|
|
14312
14342
|
};
|
|
14313
|
-
var
|
|
14343
|
+
var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
14314
14344
|
var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
|
|
14315
14345
|
var onlyHesitation = (s) => {
|
|
14316
|
-
const w =
|
|
14346
|
+
const w = words3(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
|
|
14317
14347
|
return !!w.length && w.every((x) => HESITATION.test(x));
|
|
14318
14348
|
};
|
|
14319
14349
|
function withBudget(p, ms, what, ac) {
|
|
@@ -14479,7 +14509,7 @@ var SecondChannel = class {
|
|
|
14479
14509
|
if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
|
|
14480
14510
|
if (!this.tree.empty) {
|
|
14481
14511
|
this.treeStep(t);
|
|
14482
|
-
if (!this.regrown &&
|
|
14512
|
+
if (!this.regrown && words3(t).length >= this.o.regrowAtWords) {
|
|
14483
14513
|
this.regrown = true;
|
|
14484
14514
|
this.requestTree(t);
|
|
14485
14515
|
}
|
|
@@ -14492,7 +14522,7 @@ var SecondChannel = class {
|
|
|
14492
14522
|
}
|
|
14493
14523
|
}
|
|
14494
14524
|
if (this.o.anticipate && !this.tree) {
|
|
14495
|
-
const n =
|
|
14525
|
+
const n = words3(t).length;
|
|
14496
14526
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
14497
14527
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
14498
14528
|
this.revised = true;
|
|
@@ -14505,7 +14535,7 @@ var SecondChannel = class {
|
|
|
14505
14535
|
this.bcTimer = null;
|
|
14506
14536
|
if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
|
|
14507
14537
|
}, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
|
|
14508
|
-
if (
|
|
14538
|
+
if (words3(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
|
|
14509
14539
|
}
|
|
14510
14540
|
/** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
|
|
14511
14541
|
onPause(ms) {
|
|
@@ -14600,7 +14630,7 @@ var SecondChannel = class {
|
|
|
14600
14630
|
this.heard = text.trim();
|
|
14601
14631
|
this.said = (heardCut ?? this.reply).trim();
|
|
14602
14632
|
this.lastWordAgo = Math.max(0, lastWordAgoMs);
|
|
14603
|
-
this.floorWords = this.carried +
|
|
14633
|
+
this.floorWords = this.carried + words3(this.heard).length;
|
|
14604
14634
|
this.lastUser = this.heard;
|
|
14605
14635
|
this.detect(this.heard);
|
|
14606
14636
|
this.main = "idle";
|
|
@@ -14659,7 +14689,7 @@ var SecondChannel = class {
|
|
|
14659
14689
|
return this.main === "first_audio" || this.main === "speaking";
|
|
14660
14690
|
}
|
|
14661
14691
|
tail() {
|
|
14662
|
-
return
|
|
14692
|
+
return words3(this.heard).slice(-this.o.microWords).join(" ");
|
|
14663
14693
|
}
|
|
14664
14694
|
/** Hard gates every line passes, whoever proposed it. */
|
|
14665
14695
|
allowed(k) {
|
|
@@ -14678,7 +14708,7 @@ var SecondChannel = class {
|
|
|
14678
14708
|
}
|
|
14679
14709
|
/** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
|
|
14680
14710
|
bridgeBlock() {
|
|
14681
|
-
const w =
|
|
14711
|
+
const w = words3(this.heard), intent = turnIntent(this.heard);
|
|
14682
14712
|
if (!this.lang) return "language unknown";
|
|
14683
14713
|
if (this.ownWords) return this.blocked("bridge");
|
|
14684
14714
|
if (intent === "closer") return "no answer due";
|
|
@@ -14701,7 +14731,7 @@ var SecondChannel = class {
|
|
|
14701
14731
|
}
|
|
14702
14732
|
/** 0ms rule: the candidate line for this trigger, or silence. */
|
|
14703
14733
|
rule(trigger, pauseMs = 0, breath = false, cue = null) {
|
|
14704
|
-
const w =
|
|
14734
|
+
const w = words3(this.heard);
|
|
14705
14735
|
if (!this.lang) return "silence";
|
|
14706
14736
|
if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
|
|
14707
14737
|
if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
|
|
@@ -14716,7 +14746,7 @@ var SecondChannel = class {
|
|
|
14716
14746
|
this.planning = true;
|
|
14717
14747
|
this.planTries++;
|
|
14718
14748
|
}
|
|
14719
|
-
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 };
|
|
14720
14750
|
void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
|
|
14721
14751
|
if (p === null) ac.abort();
|
|
14722
14752
|
if (turn !== this.turnNo) return;
|
|
@@ -14738,7 +14768,7 @@ var SecondChannel = class {
|
|
|
14738
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 } : {} };
|
|
14739
14769
|
const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
|
|
14740
14770
|
void this.o.grow(ctx, ac.signal).then((r) => {
|
|
14741
|
-
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);
|
|
14742
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 } : {} });
|
|
14743
14773
|
}, (e) => {
|
|
14744
14774
|
log31.warn(`tree failed: ${e?.message ?? e}`);
|
|
@@ -14754,10 +14784,10 @@ var SecondChannel = class {
|
|
|
14754
14784
|
if (!hit) return;
|
|
14755
14785
|
if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
|
|
14756
14786
|
if (this.leafTimer) clearTimeout(this.leafTimer);
|
|
14757
|
-
const at =
|
|
14787
|
+
const at = words3(t).length;
|
|
14758
14788
|
this.leafTimer = setTimeout(() => {
|
|
14759
14789
|
this.leafTimer = null;
|
|
14760
|
-
if (this.userSpeaking &&
|
|
14790
|
+
if (this.userSpeaking && words3(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
|
|
14761
14791
|
}, this.o.cuePauseMs);
|
|
14762
14792
|
}
|
|
14763
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
|
|
@@ -14767,14 +14797,14 @@ var SecondChannel = class {
|
|
|
14767
14797
|
if (!this.o.pickLeaf || !this.o.aec) return;
|
|
14768
14798
|
this.breathTimer = setTimeout(() => {
|
|
14769
14799
|
this.breathTimer = null;
|
|
14770
|
-
const n =
|
|
14800
|
+
const n = words3(t).length, tree = this.tree;
|
|
14771
14801
|
if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
|
|
14772
14802
|
this.picking = true;
|
|
14773
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 }));
|
|
14774
14804
|
void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
|
|
14775
14805
|
this.picking = false;
|
|
14776
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;
|
|
14777
|
-
if (!hit || !this.userSpeaking ||
|
|
14807
|
+
if (!hit || !this.userSpeaking || words3(this.heard).length - n >= this.o.leafStaleWords) return;
|
|
14778
14808
|
tree.take(hit.node, hit.conf);
|
|
14779
14809
|
this.playLeaf(hit, "interim", "backchannel");
|
|
14780
14810
|
});
|
|
@@ -14844,7 +14874,7 @@ var SecondChannel = class {
|
|
|
14844
14874
|
if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
|
|
14845
14875
|
return;
|
|
14846
14876
|
}
|
|
14847
|
-
const n0 =
|
|
14877
|
+
const n0 = words3(this.heard).length;
|
|
14848
14878
|
this.decidedAt = n0;
|
|
14849
14879
|
if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
|
|
14850
14880
|
const opts = this.options;
|
|
@@ -14860,7 +14890,7 @@ var SecondChannel = class {
|
|
|
14860
14890
|
this.busy = true;
|
|
14861
14891
|
const gen = this.gen, t0 = this.o.now();
|
|
14862
14892
|
const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
|
|
14863
|
-
const stale = () => gen !== this.gen ||
|
|
14893
|
+
const stale = () => gen !== this.gen || words3(this.heard).length - n0 >= this.o.staleWords;
|
|
14864
14894
|
try {
|
|
14865
14895
|
let kind = rule;
|
|
14866
14896
|
let choice;
|
|
@@ -14880,7 +14910,7 @@ var SecondChannel = class {
|
|
|
14880
14910
|
if (stale()) return ev({ choice, kind, text, acted: "stale" });
|
|
14881
14911
|
if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
|
|
14882
14912
|
const said = this.say(kind, text);
|
|
14883
|
-
if (said && cue) this.cueFrom =
|
|
14913
|
+
if (said && cue) this.cueFrom = words3(this.heard).length;
|
|
14884
14914
|
if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
|
|
14885
14915
|
ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
|
|
14886
14916
|
} finally {
|
|
@@ -14906,7 +14936,7 @@ var SecondChannel = class {
|
|
|
14906
14936
|
this.noLine = "";
|
|
14907
14937
|
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
|
|
14908
14938
|
const gen = this.gen, ac = new AbortController(), own = this.ownWords;
|
|
14909
|
-
const said = own ?
|
|
14939
|
+
const said = own ? words3(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
|
|
14910
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 } : {} };
|
|
14911
14941
|
log31.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
|
|
14912
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) => {
|
|
@@ -14974,8 +15004,8 @@ var SecondChannel = class {
|
|
|
14974
15004
|
if (kind === "bridge") this.bridged = true;
|
|
14975
15005
|
this.recent = [...this.recent, text].slice(-this.o.avoidLines);
|
|
14976
15006
|
this.live = lineWords(text);
|
|
14977
|
-
const
|
|
14978
|
-
if (
|
|
15007
|
+
const words4 = this.live;
|
|
15008
|
+
if (words4) this.o.show(words4, kind);
|
|
14979
15009
|
const p = Promise.resolve(r).then(() => {
|
|
14980
15010
|
}, (e) => {
|
|
14981
15011
|
log31.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
@@ -15074,6 +15104,9 @@ var VoiceCallOptions = class {
|
|
|
15074
15104
|
/** Live: the quick lane (fastQuickLane) owns the conversation — each turn it answers, acks + hands to MAIN, resumes a
|
|
15075
15105
|
* cut answer, or stays quiet. Absent (or another mode): every turn goes to MAIN as before. */
|
|
15076
15106
|
quick;
|
|
15107
|
+
/** The quick lane said a farewell to someone ending the call (QuickMove `end`): the host hangs up once that line has
|
|
15108
|
+
* played (as Para's [[hangup]] marker does for MAIN). The call takes no more turns after it. */
|
|
15109
|
+
hangUp;
|
|
15077
15110
|
/** Past this the turn goes to MAIN as before (the bridge covers it). */
|
|
15078
15111
|
quickBudgetMs = 1800;
|
|
15079
15112
|
/** The unsaid rest of MAIN's reply a barge just cut (a peek, like heardCut), else null — what a resume says. */
|
|
@@ -15085,6 +15118,9 @@ var VoiceCallOptions = class {
|
|
|
15085
15118
|
/** Stop the in-flight fill line now (barge-in only). */
|
|
15086
15119
|
cancel = () => {
|
|
15087
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
|
+
};
|
|
15088
15124
|
/** Host caption — never history. */
|
|
15089
15125
|
show = () => {
|
|
15090
15126
|
};
|
|
@@ -15159,7 +15195,9 @@ var VoiceCall = class {
|
|
|
15159
15195
|
cancel: () => o.cancel(),
|
|
15160
15196
|
now: o.now
|
|
15161
15197
|
});
|
|
15162
|
-
|
|
15198
|
+
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 };
|
|
15199
|
+
if (o.mode === "live") po.stageRepeatMs ??= po.gapMs;
|
|
15200
|
+
this.progress = new Progress(po);
|
|
15163
15201
|
this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
|
|
15164
15202
|
this.gate = new TurnGate({
|
|
15165
15203
|
now: o.now,
|
|
@@ -15550,8 +15588,15 @@ var VoiceCall = class {
|
|
|
15550
15588
|
}
|
|
15551
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;
|
|
15552
15590
|
this.gate.replyStarted(c.id);
|
|
15553
|
-
|
|
15554
|
-
|
|
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
|
+
}
|
|
15597
|
+
const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
|
|
15598
|
+
if (!played && !end) return this.close(c, "silent");
|
|
15599
|
+
if (played) this.o.show(said, "reply");
|
|
15555
15600
|
if (mv.kind === "resume") {
|
|
15556
15601
|
this.cutRest = "";
|
|
15557
15602
|
this.o.dropCut?.();
|
|
@@ -15561,6 +15606,17 @@ var VoiceCall = class {
|
|
|
15561
15606
|
this.history.push({ who: "you", text: said });
|
|
15562
15607
|
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.`);
|
|
15563
15608
|
}
|
|
15609
|
+
if (end) {
|
|
15610
|
+
this.o.onMetric({ name: "hangup", id: c.id, text: said });
|
|
15611
|
+
if (played && (!this.o.hostAudio || c.worded)) this.quickWorded(c, this.lastAudibleAt);
|
|
15612
|
+
this.end();
|
|
15613
|
+
try {
|
|
15614
|
+
this.o.hangUp?.();
|
|
15615
|
+
} catch (e) {
|
|
15616
|
+
log32.warn(`hangUp threw: ${e.message}`);
|
|
15617
|
+
}
|
|
15618
|
+
return;
|
|
15619
|
+
}
|
|
15564
15620
|
if (this.o.hostAudio && !c.worded) {
|
|
15565
15621
|
c.quickWord = true;
|
|
15566
15622
|
return;
|
|
@@ -15577,9 +15633,9 @@ var VoiceCall = class {
|
|
|
15577
15633
|
}
|
|
15578
15634
|
this.close(c, "answered");
|
|
15579
15635
|
}
|
|
15580
|
-
/** say(), retried while the host's player is busy (
|
|
15581
|
-
async sayRetry(line, kind, id) {
|
|
15582
|
-
for (let i = 0; i <
|
|
15636
|
+
/** say(), retried while the host's player is busy (`tries` × 250ms: 2s). */
|
|
15637
|
+
async sayRetry(line, kind, id, tries = 8) {
|
|
15638
|
+
for (let i = 0; i < tries; i++) {
|
|
15583
15639
|
if (this.ended) return false;
|
|
15584
15640
|
if (this.say(line, kind) !== false) return true;
|
|
15585
15641
|
await new Promise((r) => setTimeout(r, 250));
|