@livx.cc/agentx 0.99.156 → 0.99.158
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 +272 -72
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +254 -66
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -6493,14 +6493,14 @@ function summarize(messages, focus) {
|
|
|
6493
6493
|
if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
|
|
6494
6494
|
if (carried.length) lines.push("earlier recap:", ...carried.map((l) => ` ${l}`));
|
|
6495
6495
|
if (focus?.trim()) {
|
|
6496
|
-
const
|
|
6496
|
+
const words5 = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
6497
6497
|
const kept = [];
|
|
6498
6498
|
const ordered = [...messages.filter((m) => !isSyntheticSummary(m)), ...messages.filter(isSyntheticSummary)];
|
|
6499
6499
|
outer: for (const msg of ordered) {
|
|
6500
6500
|
if (msg.role === "tool") continue;
|
|
6501
6501
|
for (const line of contentText(msg.content).split("\n")) {
|
|
6502
6502
|
const l = line.toLowerCase();
|
|
6503
|
-
if (line.trim() &&
|
|
6503
|
+
if (line.trim() && words5.some((w) => l.includes(w))) {
|
|
6504
6504
|
kept.push(line.trim().slice(0, 200));
|
|
6505
6505
|
if (kept.length >= 12) break outer;
|
|
6506
6506
|
}
|
|
@@ -7667,13 +7667,13 @@ function isTranscriptComplete(text) {
|
|
|
7667
7667
|
const trimmed = text.trim();
|
|
7668
7668
|
if (!trimmed) return false;
|
|
7669
7669
|
if (/[.?!]$/.test(trimmed)) return true;
|
|
7670
|
-
const
|
|
7671
|
-
const lastWord =
|
|
7670
|
+
const words5 = trimmed.toLowerCase().split(/\s+/);
|
|
7671
|
+
const lastWord = words5[words5.length - 1];
|
|
7672
7672
|
if (COMPLETE_ENDINGS.has(lastWord)) return true;
|
|
7673
7673
|
if (INCOMPLETE_ENDINGS.has(lastWord)) return false;
|
|
7674
7674
|
const lower2 = trimmed.toLowerCase();
|
|
7675
7675
|
for (const marker of CONTINUATION_MARKERS) if (lower2.endsWith(marker)) return false;
|
|
7676
|
-
if (
|
|
7676
|
+
if (words5.length <= 2) return false;
|
|
7677
7677
|
return true;
|
|
7678
7678
|
}
|
|
7679
7679
|
var MAX_HOLD_MS = 2e3;
|
|
@@ -7723,12 +7723,12 @@ var SpeakerRunsOptions = class {
|
|
|
7723
7723
|
/** A run shorter than this (a diarization flap) joins its neighbour — the previous run, or the next for a leading one. */
|
|
7724
7724
|
minRunWords = 2;
|
|
7725
7725
|
};
|
|
7726
|
-
function speakerRuns(
|
|
7726
|
+
function speakerRuns(words5, options) {
|
|
7727
7727
|
const { minRunWords } = { ...new SpeakerRunsOptions(), ...options };
|
|
7728
7728
|
let runs = [];
|
|
7729
|
-
for (const w of
|
|
7729
|
+
for (const w of words5) {
|
|
7730
7730
|
const last = runs[runs.length - 1];
|
|
7731
|
-
const spk = w.spk ?? last?.spk ??
|
|
7731
|
+
const spk = w.spk ?? last?.spk ?? words5.find((x) => x.spk != null)?.spk ?? "";
|
|
7732
7732
|
if (last?.spk === spk) last.words.push(w);
|
|
7733
7733
|
else runs.push({ spk, words: [w] });
|
|
7734
7734
|
}
|
|
@@ -7757,6 +7757,105 @@ function formatTurns(turns, name = (t) => `Speaker ${t.speaker}`) {
|
|
|
7757
7757
|
return turns.map((t) => `${name(t)}: ${t.text}`).join("\n");
|
|
7758
7758
|
}
|
|
7759
7759
|
|
|
7760
|
+
// node_modules/@bod.ee/voice/src/core/agent-text-feed.ts
|
|
7761
|
+
var AgentTextFeedOptions = class {
|
|
7762
|
+
/** Deliver a piece (`text` may be '' with `endOfSegment`). */
|
|
7763
|
+
send = () => {
|
|
7764
|
+
};
|
|
7765
|
+
clock;
|
|
7766
|
+
/** Playback clock of the current turn (ms) — the same one word timestamps are anchored on. */
|
|
7767
|
+
playedMs = () => 0;
|
|
7768
|
+
/** Send this far ahead of playback (docs: 500 ms–1 s). */
|
|
7769
|
+
leadMs = 700;
|
|
7770
|
+
/** Speech-rate estimate without word timestamps. */
|
|
7771
|
+
charsPerSec = 15;
|
|
7772
|
+
tickMs = 50;
|
|
7773
|
+
};
|
|
7774
|
+
var AgentTextFeed = class {
|
|
7775
|
+
options;
|
|
7776
|
+
open = false;
|
|
7777
|
+
byWords = false;
|
|
7778
|
+
words = [];
|
|
7779
|
+
// [word, start sec on the playback clock]
|
|
7780
|
+
wordsSent = 0;
|
|
7781
|
+
chars = "";
|
|
7782
|
+
charsSent = 0;
|
|
7783
|
+
originMs = -1;
|
|
7784
|
+
// char clock: playback position of the turn's first audio byte (-1 = no audio yet)
|
|
7785
|
+
timer = null;
|
|
7786
|
+
constructor(options) {
|
|
7787
|
+
this.options = { ...new AgentTextFeedOptions(), ...options };
|
|
7788
|
+
}
|
|
7789
|
+
get active() {
|
|
7790
|
+
return this.open;
|
|
7791
|
+
}
|
|
7792
|
+
/** A spoken turn starts (closes a previous one still open — a gapless handoff plays it out). */
|
|
7793
|
+
begin(byWords) {
|
|
7794
|
+
if (this.open) this.end();
|
|
7795
|
+
this.open = true;
|
|
7796
|
+
this.byWords = byWords;
|
|
7797
|
+
this.words = [];
|
|
7798
|
+
this.wordsSent = 0;
|
|
7799
|
+
this.chars = "";
|
|
7800
|
+
this.charsSent = 0;
|
|
7801
|
+
this.originMs = -1;
|
|
7802
|
+
this.schedule();
|
|
7803
|
+
}
|
|
7804
|
+
/** Text handed to the TTS (char clock only). */
|
|
7805
|
+
text(t) {
|
|
7806
|
+
if (this.open && !this.byWords) this.chars += t;
|
|
7807
|
+
}
|
|
7808
|
+
/** The turn's first audio byte lands at this playback position (char clock only). */
|
|
7809
|
+
audioAt(ms) {
|
|
7810
|
+
if (this.open && this.originMs < 0) this.originMs = ms;
|
|
7811
|
+
}
|
|
7812
|
+
/** A TTS word timestamp on the playback clock (word clock only). */
|
|
7813
|
+
word(w, startSec) {
|
|
7814
|
+
if (this.open && this.byWords && w) this.words.push([w, startSec]);
|
|
7815
|
+
}
|
|
7816
|
+
/** The turn's audio finished playing: send the rest, close the segment. */
|
|
7817
|
+
end() {
|
|
7818
|
+
if (!this.open) return;
|
|
7819
|
+
this.flush(Infinity, true);
|
|
7820
|
+
}
|
|
7821
|
+
/** Barge-in: send only what was already due, close the segment. */
|
|
7822
|
+
cut() {
|
|
7823
|
+
if (!this.open) return;
|
|
7824
|
+
this.flush(this.options.playedMs() + this.options.leadMs, true);
|
|
7825
|
+
}
|
|
7826
|
+
schedule() {
|
|
7827
|
+
this.timer = this.options.clock.setTimeout(() => {
|
|
7828
|
+
this.timer = null;
|
|
7829
|
+
if (!this.open) return;
|
|
7830
|
+
this.flush(this.options.playedMs() + this.options.leadMs, false);
|
|
7831
|
+
if (this.open) this.schedule();
|
|
7832
|
+
}, this.options.tickMs);
|
|
7833
|
+
}
|
|
7834
|
+
flush(dueMs, close) {
|
|
7835
|
+
let piece = "";
|
|
7836
|
+
if (this.byWords) {
|
|
7837
|
+
let n = this.wordsSent;
|
|
7838
|
+
while (n < this.words.length && this.words[n][1] * 1e3 <= dueMs) n++;
|
|
7839
|
+
piece = this.words.slice(this.wordsSent, n).map(([w]) => w + " ").join("");
|
|
7840
|
+
this.wordsSent = n;
|
|
7841
|
+
} else if (this.originMs >= 0 || dueMs === Infinity) {
|
|
7842
|
+
const n = dueMs === Infinity ? this.chars.length : Math.min(this.chars.length, Math.floor((dueMs - this.originMs) / 1e3 * this.options.charsPerSec));
|
|
7843
|
+
if (n > this.charsSent) {
|
|
7844
|
+
piece = this.chars.slice(this.charsSent, n);
|
|
7845
|
+
this.charsSent = n;
|
|
7846
|
+
}
|
|
7847
|
+
}
|
|
7848
|
+
if (close) {
|
|
7849
|
+
this.open = false;
|
|
7850
|
+
if (this.timer) {
|
|
7851
|
+
this.options.clock.clearTimeout(this.timer);
|
|
7852
|
+
this.timer = null;
|
|
7853
|
+
}
|
|
7854
|
+
}
|
|
7855
|
+
if (piece || close) this.options.send(piece, close);
|
|
7856
|
+
}
|
|
7857
|
+
};
|
|
7858
|
+
|
|
7760
7859
|
// node_modules/@bod.ee/voice/src/core/engine.ts
|
|
7761
7860
|
var log14 = forComponent2("VoiceEngine");
|
|
7762
7861
|
var addLangs = (to, from) => {
|
|
@@ -8049,6 +8148,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8049
8148
|
// leading timestamped words that are the ack spoken on this turn's context, not the reply
|
|
8050
8149
|
revealedN = 0;
|
|
8051
8150
|
revealPoll = null;
|
|
8151
|
+
agentText = null;
|
|
8152
|
+
// stt.agentTextInput: our spoken text, paced to playback
|
|
8052
8153
|
// Sub-turn timestamp anchoring. A TTS context emits word starts relative to ITS OWN audio start, so
|
|
8053
8154
|
// `wordStarts` (one flat turn timeline) is only valid while the turn stays on one context. It does
|
|
8054
8155
|
// not: `subturnBoundary()` rotates the context, and Cartesia ALSO rotates it on its own (~5s idle
|
|
@@ -8190,17 +8291,19 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8190
8291
|
this.tts.onAudio = (c) => {
|
|
8191
8292
|
if (!this.speaking && !this.bcActive) return;
|
|
8192
8293
|
if (this.wordAnchorPending && this.speaking) this.anchorSubturn();
|
|
8294
|
+
if (this.speaking) this.agentText?.audioAt(this.player.endMs());
|
|
8193
8295
|
this.player.write(c);
|
|
8194
8296
|
};
|
|
8195
8297
|
if (this.options.revealMode === "word" || this.options.heardTimestamps) {
|
|
8196
8298
|
this.tts.wantTimestamps = true;
|
|
8197
|
-
this.tts.onTimestamps = (
|
|
8299
|
+
this.tts.onTimestamps = (words5, start) => {
|
|
8198
8300
|
if (this.interrupted) return;
|
|
8199
8301
|
start.forEach((s, i) => {
|
|
8200
|
-
if (this.wordAnchorPending) this.wordPending.push([
|
|
8302
|
+
if (this.wordAnchorPending) this.wordPending.push([words5[i] ?? "", s]);
|
|
8201
8303
|
else {
|
|
8202
8304
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8203
|
-
this.wordTexts.push(
|
|
8305
|
+
this.wordTexts.push(words5[i] ?? "");
|
|
8306
|
+
this.agentText?.word(words5[i] ?? "", this.wordOrigin + s);
|
|
8204
8307
|
}
|
|
8205
8308
|
});
|
|
8206
8309
|
};
|
|
@@ -8226,6 +8329,18 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8226
8329
|
this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
|
|
8227
8330
|
};
|
|
8228
8331
|
this.stt.onLevel = (rms) => this.handleLevel(rms);
|
|
8332
|
+
const stt = this.stt;
|
|
8333
|
+
this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
|
|
8334
|
+
clock: this.clock,
|
|
8335
|
+
playedMs: () => Math.max(0, this.player.playedMs()),
|
|
8336
|
+
send: (text, end) => {
|
|
8337
|
+
try {
|
|
8338
|
+
stt.sendAgentText(text, end);
|
|
8339
|
+
} catch (e) {
|
|
8340
|
+
log14.warn(`sendAgentText threw: ${e instanceof Error ? e.message : e}`);
|
|
8341
|
+
}
|
|
8342
|
+
}
|
|
8343
|
+
}) : null;
|
|
8229
8344
|
await Promise.all([
|
|
8230
8345
|
this.tts.connect(),
|
|
8231
8346
|
this.stt.start(),
|
|
@@ -8331,10 +8446,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8331
8446
|
this.lineBefore = new Set(this.echoWords);
|
|
8332
8447
|
this.tts.newContext();
|
|
8333
8448
|
this.clause = "";
|
|
8449
|
+
this.agentText?.begin(!!this.tts.wantTimestamps);
|
|
8334
8450
|
this.clearAckTimer("new_turn");
|
|
8335
8451
|
if (ack && this.options.ackPhrase) {
|
|
8336
8452
|
this.diag("ack_fired", { phrase: this.options.ackPhrase, adaptive: false });
|
|
8337
|
-
this.
|
|
8453
|
+
this.say(this.options.ackPhrase + " ");
|
|
8338
8454
|
this.spokeDeltas = true;
|
|
8339
8455
|
this.ackAt = this.clock.now();
|
|
8340
8456
|
this.lastAck = this.options.ackPhrase;
|
|
@@ -8406,13 +8522,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8406
8522
|
}
|
|
8407
8523
|
for (const w of this.words(this.reply)) this.echoWords.add(w);
|
|
8408
8524
|
const cut = this.options.flushFirstClause && this.clause !== null && this.tts.flush ? speech.search(/[,.;:!?…](?=\s|$)/) : -1;
|
|
8409
|
-
if (cut < 0) this.
|
|
8525
|
+
if (cut < 0) this.say(forSpeech(speech));
|
|
8410
8526
|
else {
|
|
8411
|
-
this.
|
|
8527
|
+
this.say(forSpeech(speech.slice(0, cut + 1)));
|
|
8412
8528
|
this.clause = null;
|
|
8413
8529
|
this.tts.flush();
|
|
8414
8530
|
this.diag("tts_first_clause_flush", {});
|
|
8415
|
-
if (speech.slice(cut + 1)) this.
|
|
8531
|
+
if (speech.slice(cut + 1)) this.say(forSpeech(speech.slice(cut + 1)));
|
|
8416
8532
|
}
|
|
8417
8533
|
if (!this.spokeDeltas && this.turnStartAt) log14.debug(`ttft: ${Math.round(this.clock.now() - this.turnStartAt)}ms`);
|
|
8418
8534
|
this.spokeDeltas = true;
|
|
@@ -8453,6 +8569,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8453
8569
|
for (const [w, s] of this.wordPending) {
|
|
8454
8570
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8455
8571
|
this.wordTexts.push(w);
|
|
8572
|
+
this.agentText?.word(w, this.wordOrigin + s);
|
|
8456
8573
|
}
|
|
8457
8574
|
this.wordPending = [];
|
|
8458
8575
|
}
|
|
@@ -8475,8 +8592,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8475
8592
|
while (n < this.wordStarts.length && this.wordStarts[n] <= playedSec) n++;
|
|
8476
8593
|
if (n !== this.revealedN) {
|
|
8477
8594
|
this.revealedN = n;
|
|
8478
|
-
const
|
|
8479
|
-
this.options.onReveal(
|
|
8595
|
+
const words5 = this.revealText.trim().split(/\s+/).filter(Boolean);
|
|
8596
|
+
this.options.onReveal(words5.slice(0, n).join(" "));
|
|
8480
8597
|
}
|
|
8481
8598
|
this.revealPoll = this.clock.setTimeout(tick, 60);
|
|
8482
8599
|
};
|
|
@@ -8495,6 +8612,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8495
8612
|
if (full) this.options.onReveal(full);
|
|
8496
8613
|
}
|
|
8497
8614
|
}
|
|
8615
|
+
/** Speech on the open turn's TTS context — also fed to the STT's agent text input (when on). */
|
|
8616
|
+
say(text) {
|
|
8617
|
+
this.agentText?.text(text);
|
|
8618
|
+
this.tts.speak(text, true);
|
|
8619
|
+
}
|
|
8498
8620
|
/** close the spoken turn (idempotent); stays audible until ALL audio arrived AND playback drains */
|
|
8499
8621
|
endSpeech() {
|
|
8500
8622
|
this.interrupted = false;
|
|
@@ -8514,7 +8636,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8514
8636
|
const t = this.emo.flush();
|
|
8515
8637
|
this.emo = null;
|
|
8516
8638
|
if (t.prose) this.reply += t.prose;
|
|
8517
|
-
if (t.speech) this.
|
|
8639
|
+
if (t.speech) this.say(forSpeech(t.speech));
|
|
8518
8640
|
}
|
|
8519
8641
|
if (this.reply) this.prevReply = this.reply;
|
|
8520
8642
|
const settle = () => {
|
|
@@ -8528,6 +8650,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8528
8650
|
}
|
|
8529
8651
|
this.drainTimer = null;
|
|
8530
8652
|
this.speaking = false;
|
|
8653
|
+
this.agentText?.end();
|
|
8531
8654
|
this.stopWordReveal(true);
|
|
8532
8655
|
if (this.turnStartAt) log14.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
|
|
8533
8656
|
this.echoUntil = this.clock.now() + 2500;
|
|
@@ -8643,7 +8766,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8643
8766
|
return;
|
|
8644
8767
|
}
|
|
8645
8768
|
this.diag("ack_fired", { phrase, adaptive: true, waitedMs: this.options.adaptiveAckMs, ...picked ? { picked } : {} });
|
|
8646
|
-
this.
|
|
8769
|
+
this.say(phrase + " ");
|
|
8647
8770
|
this.spokeDeltas = true;
|
|
8648
8771
|
this.ackAt = this.clock.now();
|
|
8649
8772
|
this.lastAck = phrase;
|
|
@@ -8729,6 +8852,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8729
8852
|
this.interrupted = true;
|
|
8730
8853
|
this.suspectUntil = 0;
|
|
8731
8854
|
this.echoUntil = this.clock.now() + Math.max(2500, this.player.drainMs() + 3e3);
|
|
8855
|
+
this.agentText?.cut();
|
|
8732
8856
|
this.tts.cancel();
|
|
8733
8857
|
this.player.kill();
|
|
8734
8858
|
if (!this.usingAec) this.echoHead = true;
|
|
@@ -8759,6 +8883,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8759
8883
|
if (this.specTimer) this.clock.clearTimeout(this.specTimer);
|
|
8760
8884
|
this.bcSupersede();
|
|
8761
8885
|
this.cancelAside("stop");
|
|
8886
|
+
this.agentText?.cut();
|
|
8762
8887
|
this.stt.stop();
|
|
8763
8888
|
this.player.kill();
|
|
8764
8889
|
this.tts.close();
|
|
@@ -9322,7 +9447,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9322
9447
|
const names = lines.map((t) => this.options.speakerResolver.name(t.speaker, t));
|
|
9323
9448
|
return { out: formatTurns(lines, (t) => names[lines.indexOf(t)]), speakers: [...new Set(names)] };
|
|
9324
9449
|
}
|
|
9325
|
-
|
|
9450
|
+
/** `judged`: the host yielded to these very words (decideOverlap) — the user's, never our echo. */
|
|
9451
|
+
handleUtterance(text, langs, rawTurns, judged = false) {
|
|
9326
9452
|
let turns;
|
|
9327
9453
|
const cap = this.uttEcho;
|
|
9328
9454
|
this.uttEcho = void 0;
|
|
@@ -9356,12 +9482,23 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9356
9482
|
}
|
|
9357
9483
|
}
|
|
9358
9484
|
const ownTail = !this.pausedAt && (this.clock.now() < this.bargeGraceUntil || this.refinalizes(text));
|
|
9485
|
+
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) {
|
|
9486
|
+
this.pausedAt = this.clock.now();
|
|
9487
|
+
this.player.pause();
|
|
9488
|
+
this.lastOverlapPartial = text;
|
|
9489
|
+
this.decideHeldFinal = text;
|
|
9490
|
+
addLangs(this.decideHeldLangs, langs);
|
|
9491
|
+
this.decideHeldTurns.push(...turns);
|
|
9492
|
+
this.diag("overlap_pause", { text: text.slice(0, 60), final: true });
|
|
9493
|
+
this.awaitOverlapDecision(text);
|
|
9494
|
+
return;
|
|
9495
|
+
}
|
|
9359
9496
|
if (this.speaking && (this.ctxOpen || this.pausedAt) && this.overlapCapable && !ownTail) {
|
|
9360
9497
|
this.diag("utterance_drop", { reason: "overlap_noise", text: text.slice(0, 60) });
|
|
9361
9498
|
this.stt.reset();
|
|
9362
9499
|
return;
|
|
9363
9500
|
}
|
|
9364
|
-
if (this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
|
|
9501
|
+
if (!judged && this.echoActive() && (!this.options.bargeIn || (this.usingAec ? this.echoFinal(text, audible) : this.novelWords(text).length < 2))) {
|
|
9365
9502
|
this.diag("echo_swallow", { guard: "echo_gate", text: text.slice(0, 60) });
|
|
9366
9503
|
this.stt.reset();
|
|
9367
9504
|
return;
|
|
@@ -9518,7 +9655,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
9518
9655
|
this.diag("barge_in", { phase, trigger, novel: this.novelWords(txt).length, total: this.words(txt).length });
|
|
9519
9656
|
this.interrupt();
|
|
9520
9657
|
this.options.onBargeIn(phase);
|
|
9521
|
-
if (held2) this.handleUtterance(held2, heldLangs, heldTurns);
|
|
9658
|
+
if (held2) this.handleUtterance(held2, heldLangs, heldTurns, trigger === "host_yield");
|
|
9522
9659
|
}
|
|
9523
9660
|
/** Wait (bounded) for the host's verdict. `fresh` = a re-decision on grown text: it gets its own window — the host
|
|
9524
9661
|
* was only just asked about it (live: "Oh," → "Oh, that" → "Oh, that— that's new" outgrew every verdict, and the
|
|
@@ -9859,8 +9996,8 @@ var SonioxSTTOptions = class {
|
|
|
9859
9996
|
/** `stt-rt-preview` was RETIRED (aliased to the two-generations-old v3 on 2025-10-31), so every
|
|
9860
9997
|
* caller that never set this was silently running an old model while the alias kept it working —
|
|
9861
9998
|
* the failure mode of a default that is a moving vendor pointer. Pin a real version instead;
|
|
9862
|
-
* `stt-rt-
|
|
9863
|
-
model = "stt-rt-
|
|
9999
|
+
* `stt-rt-v6` (2026-11-03) replaced v5, deprecated and removed 2026-12-15 (docs.soniox.com/stt/models). */
|
|
10000
|
+
model = "stt-rt-v6";
|
|
9864
10001
|
languageHints = ["en"];
|
|
9865
10002
|
/** Opt-in Soniox language identification (`enable_language_identification`): every token is tagged with a
|
|
9866
10003
|
* `language` code, and onUtterance's 3rd arg reports the utterance's dominant one (by characters). */
|
|
@@ -9885,6 +10022,10 @@ var SonioxSTTOptions = class {
|
|
|
9885
10022
|
/** No-audio watchdog: if the mic source stops delivering chunks for this long, capture is dead →
|
|
9886
10023
|
* fire onFatal + stop (else Soniox idle-timeouts and reconnect-loops forever). 0 = disable. */
|
|
9887
10024
|
noAudioTimeoutMs = 1e4;
|
|
10025
|
+
/** Opt-in Soniox agent text input (`enable_agent_text_input`, stt-rt-v6 only): the assistant's spoken text goes on the
|
|
10026
|
+
* same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
|
|
10027
|
+
* of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
|
|
10028
|
+
agentTextInput = false;
|
|
9888
10029
|
};
|
|
9889
10030
|
var SonioxSTT = class {
|
|
9890
10031
|
options;
|
|
@@ -9947,6 +10088,17 @@ var SonioxSTT = class {
|
|
|
9947
10088
|
constructor(options) {
|
|
9948
10089
|
this.options = { ...new SonioxSTTOptions(), ...options };
|
|
9949
10090
|
}
|
|
10091
|
+
get agentTextInput() {
|
|
10092
|
+
return this.options.agentTextInput;
|
|
10093
|
+
}
|
|
10094
|
+
/** Send the next not-yet-sent piece of what the assistant is saying (`agent_text`); `endOfSegment` closes the
|
|
10095
|
+
* assistant's turn (finished or interrupted). Spaces are kept as given. No-op unless `agentTextInput` is on and the
|
|
10096
|
+
* socket is open (a reconnect starts a fresh stream; text sent before it is not re-sent). */
|
|
10097
|
+
sendAgentText(text, endOfSegment = false) {
|
|
10098
|
+
if (!this.options.agentTextInput || this.stopped || this.ws?.readyState !== WebSocket.OPEN) return;
|
|
10099
|
+
if (!text && !endOfSegment) return;
|
|
10100
|
+
this.ws.send(JSON.stringify({ type: "agent_text", text, ...endOfSegment ? { end_of_segment: true } : {} }));
|
|
10101
|
+
}
|
|
9950
10102
|
get usingAec() {
|
|
9951
10103
|
return this.options.source?.aec ?? false;
|
|
9952
10104
|
}
|
|
@@ -9971,18 +10123,20 @@ var SonioxSTT = class {
|
|
|
9971
10123
|
...this.options.languageHintsStrict ? { language_hints_strict: true } : {},
|
|
9972
10124
|
...this.options.languageIdentification ? { enable_language_identification: true } : {},
|
|
9973
10125
|
...this.options.diarization ? { enable_speaker_diarization: true } : {},
|
|
9974
|
-
...this.options.terms?.length ? { context: { terms: this.options.terms } } : {}
|
|
10126
|
+
...this.options.terms?.length ? { context: { terms: this.options.terms } } : {},
|
|
10127
|
+
...this.options.agentTextInput ? { enable_agent_text_input: true } : {}
|
|
9975
10128
|
})
|
|
9976
10129
|
);
|
|
9977
10130
|
this.ws.onmessage = (ev) => this.handle(JSON.parse(String(ev.data)));
|
|
9978
10131
|
this.ws.onclose = (ev) => {
|
|
9979
|
-
if (this.stopped) return;
|
|
10132
|
+
if (this.stopped || this.failed) return;
|
|
9980
10133
|
log15.warn(`soniox ws closed (${ev.code} ${ev.reason || ""}) \u2014 reconnecting`);
|
|
9981
10134
|
this.diag("stt_ws_closed", { code: ev.code, reason: String(ev.reason || ""), reconnecting: true });
|
|
9982
10135
|
this.reset();
|
|
9983
10136
|
this.connectWs().catch((e) => {
|
|
9984
10137
|
log15.error(`soniox reconnect failed: ${e.message}`);
|
|
9985
10138
|
this.diag("stt_reconnect_failed", { message: e.message });
|
|
10139
|
+
this.fail(`Speech-to-text (Soniox) lost its connection and could not reconnect (${e.message}).`);
|
|
9986
10140
|
});
|
|
9987
10141
|
};
|
|
9988
10142
|
}
|
|
@@ -10042,7 +10196,10 @@ var SonioxSTT = class {
|
|
|
10042
10196
|
handle(m) {
|
|
10043
10197
|
if (m.error_message) {
|
|
10044
10198
|
this.diag("stt_error", { message: String(m.error_message), code: m.error_code });
|
|
10045
|
-
|
|
10199
|
+
log15.error(`soniox: ${m.error_message}`);
|
|
10200
|
+
const fatal = sonioxFatal(m.error_code, String(m.error_message));
|
|
10201
|
+
if (fatal) this.fail(fatal);
|
|
10202
|
+
return;
|
|
10046
10203
|
}
|
|
10047
10204
|
let endpoint = false;
|
|
10048
10205
|
const foreign = this.options.languageHintsStrict ? foreignScript(this.options.languageHints) : null;
|
|
@@ -10104,8 +10261,8 @@ var SonioxSTT = class {
|
|
|
10104
10261
|
/** Per-speaker turns of the current utterance (diarization only; undefined otherwise or when Soniox tagged no speaker). */
|
|
10105
10262
|
turns(withPartials) {
|
|
10106
10263
|
if (!this.options.diarization) return void 0;
|
|
10107
|
-
const
|
|
10108
|
-
return
|
|
10264
|
+
const words5 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
|
|
10265
|
+
return words5.some((w) => w.spk != null) ? speakerRuns(words5) : void 0;
|
|
10109
10266
|
}
|
|
10110
10267
|
reset() {
|
|
10111
10268
|
this.finalToks = [];
|
|
@@ -10118,6 +10275,14 @@ var SonioxSTT = class {
|
|
|
10118
10275
|
this.firstTokenAt = 0;
|
|
10119
10276
|
this.lastWordEndMs = 0;
|
|
10120
10277
|
}
|
|
10278
|
+
/** Unrecoverable: tell the host once, then stop (no reconnect loop). */
|
|
10279
|
+
failed = false;
|
|
10280
|
+
fail(message) {
|
|
10281
|
+
if (this.failed || this.stopped) return;
|
|
10282
|
+
this.failed = true;
|
|
10283
|
+
this.onFatal(message);
|
|
10284
|
+
this.stop();
|
|
10285
|
+
}
|
|
10121
10286
|
stop() {
|
|
10122
10287
|
this.stopped = true;
|
|
10123
10288
|
if (this.endpointTimer) clearInterval(this.endpointTimer);
|
|
@@ -10127,6 +10292,15 @@ var SonioxSTT = class {
|
|
|
10127
10292
|
this.ws?.close();
|
|
10128
10293
|
}
|
|
10129
10294
|
};
|
|
10295
|
+
function sonioxFatal(code, message) {
|
|
10296
|
+
const c = Number(code);
|
|
10297
|
+
if (c === 402 || /balance|autopay|add funds|payment required/i.test(message))
|
|
10298
|
+
return `Speech-to-text is out of credit (Soniox): ${message} Add funds at console.soniox.com.`;
|
|
10299
|
+
if (c === 401 || c === 403 || /api key|unauthori[sz]ed|forbidden/i.test(message))
|
|
10300
|
+
return `Speech-to-text (Soniox) rejected the API key: ${message}`;
|
|
10301
|
+
if (c === 400) return `Speech-to-text (Soniox) rejected the request: ${message}`;
|
|
10302
|
+
return null;
|
|
10303
|
+
}
|
|
10130
10304
|
var SCRIPTS = {
|
|
10131
10305
|
he: ["Hebrew"],
|
|
10132
10306
|
yi: ["Hebrew"],
|
|
@@ -10459,6 +10633,14 @@ import { AIClient, DecideClient, JevAdapter, LlmDecideAdapter } from "ai.libx.js
|
|
|
10459
10633
|
|
|
10460
10634
|
// src/voice/overlap.ts
|
|
10461
10635
|
init_logging();
|
|
10636
|
+
|
|
10637
|
+
// src/voice/closing.ts
|
|
10638
|
+
var words = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
10639
|
+
function isClosing(text) {
|
|
10640
|
+
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);
|
|
10641
|
+
}
|
|
10642
|
+
|
|
10643
|
+
// src/voice/overlap.ts
|
|
10462
10644
|
var log20 = forComponent("Overlap");
|
|
10463
10645
|
var norm2 = (s) => s.toLowerCase().replace(/[’']/g, "'").replace(/[^\p{L}\p{N}' -]+/gu, " ").replace(/\s+/g, " ").trim();
|
|
10464
10646
|
var HARD = /^(?:(?:stop|wait|no|nope|hold on|hang on|hold up|pause|cancel|quiet|enough|shut up|never ?mind)(?: |$))+$/;
|
|
@@ -10502,19 +10684,20 @@ function overlapRule(text) {
|
|
|
10502
10684
|
if (CONTINUE.test(norm2(text))) return "keep";
|
|
10503
10685
|
let t = norm2(text);
|
|
10504
10686
|
if (!t) return void 0;
|
|
10687
|
+
if (isClosing(text)) return "cut";
|
|
10505
10688
|
if (HARD.test(t + " ")) return t.includes(" ") ? "cut" : "hold";
|
|
10506
10689
|
for (const p of PHRASES) t = t.split(p).join(" ");
|
|
10507
|
-
const
|
|
10690
|
+
const words5 = t.split(/[\s-]+/).filter(Boolean);
|
|
10508
10691
|
const ack = (w) => ACK.has(w) || HE_ACK.has(w) || /^(?:ha)+h?$|^(?:he)+h?$|^m+(?:hm+)?$|^h?m+$/.test(w);
|
|
10509
|
-
if (
|
|
10510
|
-
const lead2 =
|
|
10511
|
-
if (lead2 >= 0 && LEADER.has(
|
|
10692
|
+
if (words5.every(ack)) return "keep";
|
|
10693
|
+
const lead2 = words5.findIndex((w) => !LEAD.has(w));
|
|
10694
|
+
if (lead2 >= 0 && LEADER.has(words5[lead2]) && !words5.some((w) => HARD.test(w + " ")) && words5.slice(lead2).filter((w) => !ack(w) && !LEAD.has(w)).length <= 1) return "keep";
|
|
10512
10695
|
return void 0;
|
|
10513
10696
|
}
|
|
10514
10697
|
function fastOverlapModel(ai, model = "groq/qwen/qwen3.8-27b") {
|
|
10515
10698
|
return async (heard, signal) => {
|
|
10516
10699
|
const prompt = 'Live voice call. The assistant is mid-sentence and the user just said this over it: "' + heard + `"
|
|
10517
|
-
Are they STEERING \u2014 asking for something new, asking a real question about it, correcting it,
|
|
10700
|
+
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.
|
|
10518
10701
|
Answer yes (steering) or no (a reaction).`;
|
|
10519
10702
|
const reasoning = /qwen/.test(model) ? { providerOptions: { reasoning_effort: "none" } } : /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
10520
10703
|
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, temperature: 0, maxTokens: /gpt-oss/.test(model) ? 200 : 3, ...reasoning });
|
|
@@ -10719,7 +10902,7 @@ function interruptionNote(cut, intent, hold = true) {
|
|
|
10719
10902
|
}
|
|
10720
10903
|
var FRAME = "You are the instinct of a warm, attentive human in a live spoken conversation. Decide what a natural human would do THIS instant \u2014 the way people do without thinking. ";
|
|
10721
10904
|
var acted = (what, r) => r === false ? `${what}_skipped` : what;
|
|
10722
|
-
var
|
|
10905
|
+
var words2 = (s) => s.trim() ? s.trim().split(/\s+/).length : 0;
|
|
10723
10906
|
var Instinct = class {
|
|
10724
10907
|
constructor(options) {
|
|
10725
10908
|
this.options = options;
|
|
@@ -10764,7 +10947,7 @@ var Instinct = class {
|
|
|
10764
10947
|
this.turnStart = 0;
|
|
10765
10948
|
}
|
|
10766
10949
|
async consult(heard) {
|
|
10767
|
-
if (this.inflight ||
|
|
10950
|
+
if (this.inflight || words2(heard) < this.o.minWords) return;
|
|
10768
10951
|
this.inflight = true;
|
|
10769
10952
|
try {
|
|
10770
10953
|
const now4 = this.o.now();
|
|
@@ -10778,7 +10961,7 @@ var Instinct = class {
|
|
|
10778
10961
|
interject: "cut in now with a short correction, the word they are reaching for, or an answer"
|
|
10779
10962
|
});
|
|
10780
10963
|
if (!d) return;
|
|
10781
|
-
if (!this.partial ||
|
|
10964
|
+
if (!this.partial || words2(this.partial) - words2(heard) >= this.o.staleWords) return this.o.onDecision({ ...d, acted: "stale" });
|
|
10782
10965
|
const p = d.probabilities, t = this.o.now();
|
|
10783
10966
|
if (d.choice === "interject" && p.interject >= this.o.interjectMin && t - this.lastInterjectAt > this.o.interjectGapMs) {
|
|
10784
10967
|
this.lastInterjectAt = t;
|
|
@@ -11272,8 +11455,8 @@ function cleanLine(s, lang, maxWords = 6) {
|
|
|
11272
11455
|
const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
|
|
11273
11456
|
const raw = first.replace(LINE_TAG, " ").trim();
|
|
11274
11457
|
if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
|
|
11275
|
-
const
|
|
11276
|
-
return
|
|
11458
|
+
const words5 = cleanWords(raw, lang, maxWords);
|
|
11459
|
+
return words5 && tags ? `${tags} ${words5}` : words5;
|
|
11277
11460
|
}
|
|
11278
11461
|
var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
|
|
11279
11462
|
var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
|
|
@@ -11482,10 +11665,7 @@ function endsMidPhrase(text) {
|
|
|
11482
11665
|
if (TRAILING_PREPS.has(last)) return !QUESTION_START.test(t) && !PHRASAL_HOST.has(prev);
|
|
11483
11666
|
return MID_PHRASE_WORDS.has(last);
|
|
11484
11667
|
}
|
|
11485
|
-
var
|
|
11486
|
-
function isClosing(text) {
|
|
11487
|
-
return words2(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);
|
|
11488
|
-
}
|
|
11668
|
+
var words3 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
11489
11669
|
var TurnGateOptions = class {
|
|
11490
11670
|
holdMs = 1200;
|
|
11491
11671
|
/** A finished statement (not a question) waits this long for more speech before it is a turn. 0 = sent at once. */
|
|
@@ -11617,7 +11797,7 @@ var TurnGate = class {
|
|
|
11617
11797
|
}
|
|
11618
11798
|
refinal(last, t, key, sttId) {
|
|
11619
11799
|
if (!last.started) return this.send(t, key, sttId ?? last.sttId, "replace", last.id);
|
|
11620
|
-
const a =
|
|
11800
|
+
const a = words3(last.text), b = words3(t);
|
|
11621
11801
|
let i = 0;
|
|
11622
11802
|
while (i < a.length && i < b.length && norm3(a[i]) === norm3(b[i])) i++;
|
|
11623
11803
|
const extra = b.slice(i).join(" ");
|
|
@@ -11664,8 +11844,8 @@ function isFalseStart(sentence) {
|
|
|
11664
11844
|
return !!m && !/^(?:h+m+|u+m+|u+h+|o+h+|a+h+|well|so|er+m*)$/i.test(m[1]);
|
|
11665
11845
|
}
|
|
11666
11846
|
function wordOverlap(sentence, prior) {
|
|
11667
|
-
const
|
|
11668
|
-
const have = new Set(
|
|
11847
|
+
const words5 = (x) => x.replace(/\[[^\]]*\]/g, " ").toLowerCase().replace(/['’]/g, "").match(new RegExp("\\p{L}{4,}", "gu")) ?? [];
|
|
11848
|
+
const have = new Set(words5(prior)), ws = words5(sentence);
|
|
11669
11849
|
return ws.length ? ws.filter((w) => have.has(w)).length / ws.length : 0;
|
|
11670
11850
|
}
|
|
11671
11851
|
var DuplexAgentOptions = class {
|
|
@@ -14236,8 +14416,8 @@ var ConvoTree = class {
|
|
|
14236
14416
|
this.from = heardWords;
|
|
14237
14417
|
}
|
|
14238
14418
|
/** Posterior of a node after seeing its cue. */
|
|
14239
|
-
confidence(p,
|
|
14240
|
-
const l = p * (
|
|
14419
|
+
confidence(p, words5) {
|
|
14420
|
+
const l = p * (words5 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
|
|
14241
14421
|
return l / (l + 1 - p);
|
|
14242
14422
|
}
|
|
14243
14423
|
/** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
|
|
@@ -14722,10 +14902,10 @@ var SecondChannelOptions = class {
|
|
|
14722
14902
|
now = () => performance.now();
|
|
14723
14903
|
random = Math.random;
|
|
14724
14904
|
};
|
|
14725
|
-
var
|
|
14905
|
+
var words4 = (s) => s.trim() ? s.trim().split(/\s+/) : [];
|
|
14726
14906
|
var HESITATION = /^(?:a+y*|a+i|e+[hr]*|erm+|u+[hm]*|h?m+|o+h+|ooh|like|so|well|אה+|אמ+|אה?ם+|ממ+)$/u;
|
|
14727
14907
|
var onlyHesitation = (s) => {
|
|
14728
|
-
const w =
|
|
14908
|
+
const w = words4(s).slice(-3).map((x) => x.toLowerCase().replace(/[^\p{L}]/gu, "")).filter(Boolean);
|
|
14729
14909
|
return !!w.length && w.every((x) => HESITATION.test(x));
|
|
14730
14910
|
};
|
|
14731
14911
|
function withBudget(p, ms, what, ac) {
|
|
@@ -14891,7 +15071,7 @@ var SecondChannel = class {
|
|
|
14891
15071
|
if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
|
|
14892
15072
|
if (!this.tree.empty) {
|
|
14893
15073
|
this.treeStep(t);
|
|
14894
|
-
if (!this.regrown &&
|
|
15074
|
+
if (!this.regrown && words4(t).length >= this.o.regrowAtWords) {
|
|
14895
15075
|
this.regrown = true;
|
|
14896
15076
|
this.requestTree(t);
|
|
14897
15077
|
}
|
|
@@ -14904,7 +15084,7 @@ var SecondChannel = class {
|
|
|
14904
15084
|
}
|
|
14905
15085
|
}
|
|
14906
15086
|
if (this.o.anticipate && !this.tree) {
|
|
14907
|
-
const n =
|
|
15087
|
+
const n = words4(t).length;
|
|
14908
15088
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
14909
15089
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
14910
15090
|
this.revised = true;
|
|
@@ -14917,7 +15097,7 @@ var SecondChannel = class {
|
|
|
14917
15097
|
this.bcTimer = null;
|
|
14918
15098
|
if (this.userSpeaking && this.heard === t) void this.consider("interim", 0, true, cue);
|
|
14919
15099
|
}, cue ? this.o.cuePauseMs : this.o.backchannelPauseMs) : null;
|
|
14920
|
-
if (
|
|
15100
|
+
if (words4(t).length - this.decidedAt >= this.o.decideEveryWords) void this.consider("interim");
|
|
14921
15101
|
}
|
|
14922
15102
|
/** The user went quiet for `ms` (host VAD/STT pause, or the internal interim timer). */
|
|
14923
15103
|
onPause(ms) {
|
|
@@ -15012,7 +15192,7 @@ var SecondChannel = class {
|
|
|
15012
15192
|
this.heard = text.trim();
|
|
15013
15193
|
this.said = (heardCut ?? this.reply).trim();
|
|
15014
15194
|
this.lastWordAgo = Math.max(0, lastWordAgoMs);
|
|
15015
|
-
this.floorWords = this.carried +
|
|
15195
|
+
this.floorWords = this.carried + words4(this.heard).length;
|
|
15016
15196
|
this.lastUser = this.heard;
|
|
15017
15197
|
this.detect(this.heard);
|
|
15018
15198
|
this.main = "idle";
|
|
@@ -15071,7 +15251,7 @@ var SecondChannel = class {
|
|
|
15071
15251
|
return this.main === "first_audio" || this.main === "speaking";
|
|
15072
15252
|
}
|
|
15073
15253
|
tail() {
|
|
15074
|
-
return
|
|
15254
|
+
return words4(this.heard).slice(-this.o.microWords).join(" ");
|
|
15075
15255
|
}
|
|
15076
15256
|
/** Hard gates every line passes, whoever proposed it. */
|
|
15077
15257
|
allowed(k) {
|
|
@@ -15090,7 +15270,7 @@ var SecondChannel = class {
|
|
|
15090
15270
|
}
|
|
15091
15271
|
/** Why this turn gets no bridge by rule ('' = it may) — language, a quick/phatic turn, or blocked(). */
|
|
15092
15272
|
bridgeBlock() {
|
|
15093
|
-
const w =
|
|
15273
|
+
const w = words4(this.heard), intent = turnIntent(this.heard);
|
|
15094
15274
|
if (!this.lang) return "language unknown";
|
|
15095
15275
|
if (this.ownWords) return this.blocked("bridge");
|
|
15096
15276
|
if (intent === "closer") return "no answer due";
|
|
@@ -15113,7 +15293,7 @@ var SecondChannel = class {
|
|
|
15113
15293
|
}
|
|
15114
15294
|
/** 0ms rule: the candidate line for this trigger, or silence. */
|
|
15115
15295
|
rule(trigger, pauseMs = 0, breath = false, cue = null) {
|
|
15116
|
-
const w =
|
|
15296
|
+
const w = words4(this.heard);
|
|
15117
15297
|
if (!this.lang) return "silence";
|
|
15118
15298
|
if (trigger === "working") return this.bridgeBlock() ? "silence" : "bridge";
|
|
15119
15299
|
if (w.length <= this.o.shortTurnWords || w.length <= 6 && isPhatic(this.heard, this.bank)) return "silence";
|
|
@@ -15128,7 +15308,7 @@ var SecondChannel = class {
|
|
|
15128
15308
|
this.planning = true;
|
|
15129
15309
|
this.planTries++;
|
|
15130
15310
|
}
|
|
15131
|
-
const ctx = { agent: this.reply.trim(), user:
|
|
15311
|
+
const ctx = { agent: this.reply.trim(), user: words4(this.lastUser).slice(-30).join(" "), recent: [...this.recent], lang: this.lang, heard };
|
|
15132
15312
|
void withBudget(this.o.plan(ctx, ac.signal), this.o.planBudgetMs, heard ? "plan revision" : "plan").then((p) => {
|
|
15133
15313
|
if (p === null) ac.abort();
|
|
15134
15314
|
if (turn !== this.turnNo) return;
|
|
@@ -15150,7 +15330,7 @@ var SecondChannel = class {
|
|
|
15150
15330
|
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 } : {} };
|
|
15151
15331
|
const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
|
|
15152
15332
|
void this.o.grow(ctx, ac.signal).then((r) => {
|
|
15153
|
-
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ?
|
|
15333
|
+
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words4(this.heard).length : 0);
|
|
15154
15334
|
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 } : {} });
|
|
15155
15335
|
}, (e) => {
|
|
15156
15336
|
log30.warn(`tree failed: ${e?.message ?? e}`);
|
|
@@ -15166,10 +15346,10 @@ var SecondChannel = class {
|
|
|
15166
15346
|
if (!hit) return;
|
|
15167
15347
|
if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
|
|
15168
15348
|
if (this.leafTimer) clearTimeout(this.leafTimer);
|
|
15169
|
-
const at =
|
|
15349
|
+
const at = words4(t).length;
|
|
15170
15350
|
this.leafTimer = setTimeout(() => {
|
|
15171
15351
|
this.leafTimer = null;
|
|
15172
|
-
if (this.userSpeaking &&
|
|
15352
|
+
if (this.userSpeaking && words4(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
|
|
15173
15353
|
}, this.o.cuePauseMs);
|
|
15174
15354
|
}
|
|
15175
15355
|
/** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
|
|
@@ -15179,14 +15359,14 @@ var SecondChannel = class {
|
|
|
15179
15359
|
if (!this.o.pickLeaf || !this.o.aec) return;
|
|
15180
15360
|
this.breathTimer = setTimeout(() => {
|
|
15181
15361
|
this.breathTimer = null;
|
|
15182
|
-
const n =
|
|
15362
|
+
const n = words4(t).length, tree = this.tree;
|
|
15183
15363
|
if (!this.backchannelMoment(n, true) || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
|
|
15184
15364
|
this.picking = true;
|
|
15185
15365
|
const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
|
|
15186
15366
|
void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
|
|
15187
15367
|
this.picking = false;
|
|
15188
15368
|
const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
|
|
15189
|
-
if (!hit || !this.userSpeaking ||
|
|
15369
|
+
if (!hit || !this.userSpeaking || words4(this.heard).length - n >= this.o.leafStaleWords) return;
|
|
15190
15370
|
tree.take(hit.node, hit.conf);
|
|
15191
15371
|
this.playLeaf(hit, "interim", "backchannel");
|
|
15192
15372
|
});
|
|
@@ -15256,7 +15436,7 @@ var SecondChannel = class {
|
|
|
15256
15436
|
if (trigger === "working") this.o.onEvent({ trigger, rule: "silence", ms: 0, acted: "silence", reason: "deciding another line" });
|
|
15257
15437
|
return;
|
|
15258
15438
|
}
|
|
15259
|
-
const n0 =
|
|
15439
|
+
const n0 = words4(this.heard).length;
|
|
15260
15440
|
this.decidedAt = n0;
|
|
15261
15441
|
if (!(this.o.anticipate && this.plan && trigger === "interim")) cue = null;
|
|
15262
15442
|
const opts = this.options;
|
|
@@ -15272,7 +15452,7 @@ var SecondChannel = class {
|
|
|
15272
15452
|
this.busy = true;
|
|
15273
15453
|
const gen = this.gen, t0 = this.o.now();
|
|
15274
15454
|
const ev = (e) => this.o.onEvent({ trigger, rule, ms: Math.round(this.o.now() - t0), ...cue ? { cue: cue.line } : {}, ...e });
|
|
15275
|
-
const stale = () => gen !== this.gen ||
|
|
15455
|
+
const stale = () => gen !== this.gen || words4(this.heard).length - n0 >= this.o.staleWords;
|
|
15276
15456
|
try {
|
|
15277
15457
|
let kind = rule;
|
|
15278
15458
|
let choice;
|
|
@@ -15292,7 +15472,7 @@ var SecondChannel = class {
|
|
|
15292
15472
|
if (stale()) return ev({ choice, kind, text, acted: "stale" });
|
|
15293
15473
|
if (!this.allowed(kind)) return ev({ choice, kind, text, acted: "gated" });
|
|
15294
15474
|
const said = this.say(kind, text);
|
|
15295
|
-
if (said && cue) this.cueFrom =
|
|
15475
|
+
if (said && cue) this.cueFrom = words4(this.heard).length;
|
|
15296
15476
|
if (said && kind === "backchannel" && this.o.reactionGapMs && !this.bank?.backchannel.some((b) => norm3(b) === norm3(text))) this.lastReactAt = this.o.now();
|
|
15297
15477
|
ev({ choice, kind, text, acted: said ? "spoken" : "skipped" });
|
|
15298
15478
|
} finally {
|
|
@@ -15318,7 +15498,7 @@ var SecondChannel = class {
|
|
|
15318
15498
|
this.noLine = "";
|
|
15319
15499
|
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard) return;
|
|
15320
15500
|
const gen = this.gen, ac = new AbortController(), own = this.ownWords;
|
|
15321
|
-
const said = own ?
|
|
15501
|
+
const said = own ? words4(this.said.replace(/\[[^\]]*\]/g, " ")).slice(-this.o.microWords).join(" ") : "", heard = `${this.heard} ${said}`;
|
|
15322
15502
|
const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {}, ...said ? { said, cut: this.barged } : {} };
|
|
15323
15503
|
log30.debug(`bridge ctx: said=${JSON.stringify(ctx.said ?? "")} cut=${!!ctx.cut}`);
|
|
15324
15504
|
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) => {
|
|
@@ -15386,8 +15566,8 @@ var SecondChannel = class {
|
|
|
15386
15566
|
if (kind === "bridge") this.bridged = true;
|
|
15387
15567
|
this.recent = [...this.recent, text].slice(-this.o.avoidLines);
|
|
15388
15568
|
this.live = lineWords(text);
|
|
15389
|
-
const
|
|
15390
|
-
if (
|
|
15569
|
+
const words5 = this.live;
|
|
15570
|
+
if (words5) this.o.show(words5, kind);
|
|
15391
15571
|
const p = Promise.resolve(r).then(() => {
|
|
15392
15572
|
}, (e) => {
|
|
15393
15573
|
log30.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
@@ -15504,6 +15684,9 @@ var VoiceCallOptions = class {
|
|
|
15504
15684
|
/** Stop the in-flight fill line now (barge-in only). */
|
|
15505
15685
|
cancel = () => {
|
|
15506
15686
|
};
|
|
15687
|
+
/** Cut whatever the host is playing now (MAIN's reply draining): a farewell is said over nothing, then the call hangs up. */
|
|
15688
|
+
cutAudio = () => {
|
|
15689
|
+
};
|
|
15507
15690
|
/** Host caption — never history. */
|
|
15508
15691
|
show = () => {
|
|
15509
15692
|
};
|
|
@@ -15972,6 +16155,11 @@ var VoiceCall = class {
|
|
|
15972
16155
|
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;
|
|
15973
16156
|
this.gate.replyStarted(c.id);
|
|
15974
16157
|
const end = mv.kind === "say" && !!mv.end;
|
|
16158
|
+
if (end) try {
|
|
16159
|
+
this.o.cutAudio();
|
|
16160
|
+
} catch (e) {
|
|
16161
|
+
log31.warn(`cutAudio threw: ${e.message}`);
|
|
16162
|
+
}
|
|
15975
16163
|
const played = await this.sayRetry(said, "reply", c.id, end ? 240 : 8);
|
|
15976
16164
|
if (!played && !end) return this.close(c, "silent");
|
|
15977
16165
|
if (played) this.o.show(said, "reply");
|
|
@@ -17580,8 +17768,8 @@ var CutInAbsorber = class {
|
|
|
17580
17768
|
const cut = this.cut || (meta?.supersedes !== void 0 && meta.supersedes === this.absorbed?.text ? this.absorbed.cut : "");
|
|
17581
17769
|
this.cut = "";
|
|
17582
17770
|
this.absorbed = void 0;
|
|
17583
|
-
const
|
|
17584
|
-
if (!cut ||
|
|
17771
|
+
const words5 = (s) => s.trim().split(/\s+/).filter(Boolean).length;
|
|
17772
|
+
if (!cut || words5(text) - words5(cut) >= 3) return false;
|
|
17585
17773
|
this.absorbed = { text, cut };
|
|
17586
17774
|
return true;
|
|
17587
17775
|
}
|
|
@@ -17765,6 +17953,9 @@ function bindVoiceCall(v, call, live, decideMs = 900) {
|
|
|
17765
17953
|
};
|
|
17766
17954
|
call.options.cancel = () => {
|
|
17767
17955
|
};
|
|
17956
|
+
call.options.cutAudio = () => {
|
|
17957
|
+
if (v.audible) v.interrupt();
|
|
17958
|
+
};
|
|
17768
17959
|
}
|
|
17769
17960
|
function keepHeard(transcript, cut) {
|
|
17770
17961
|
const full = cut.full.trim(), heard = cut.heard.trim();
|
|
@@ -17935,10 +18126,12 @@ function fakeVoiceParts(uttFile) {
|
|
|
17935
18126
|
function fakeTape(heardFile, saidFile) {
|
|
17936
18127
|
const CHAR = TTS_SAMPLE_RATE * 2 / 15;
|
|
17937
18128
|
const makeTts = () => {
|
|
18129
|
+
let at = 0;
|
|
17938
18130
|
const t = {
|
|
17939
18131
|
connect() {
|
|
17940
18132
|
},
|
|
17941
18133
|
newContext() {
|
|
18134
|
+
at = 0;
|
|
17942
18135
|
},
|
|
17943
18136
|
cancel() {
|
|
17944
18137
|
},
|
|
@@ -17950,6 +18143,13 @@ function fakeTape(heardFile, saidFile) {
|
|
|
17950
18143
|
},
|
|
17951
18144
|
speak(text, more = true) {
|
|
17952
18145
|
if (saidFile) appendFileSync(saidFile, JSON.stringify({ t: Date.now(), speak: text }) + "\n");
|
|
18146
|
+
const words5 = [], start = [];
|
|
18147
|
+
for (const m of text.matchAll(/\S+/g)) {
|
|
18148
|
+
words5.push(m[0]);
|
|
18149
|
+
start.push((at + m.index) / 15);
|
|
18150
|
+
}
|
|
18151
|
+
at += text.length;
|
|
18152
|
+
if (t.wantTimestamps && words5.length) setTimeout(() => t.onTimestamps?.(words5, start), 5);
|
|
17953
18153
|
const pcm = new Uint8Array(text.length * CHAR), v = new DataView(pcm.buffer);
|
|
17954
18154
|
for (let i = 0; i < text.length; i++) for (let b = 0; b < CHAR; b += 2) v.setUint16(i * CHAR + b, text.charCodeAt(i), true);
|
|
17955
18155
|
setTimeout(() => {
|
|
@@ -18198,7 +18398,7 @@ function quickMove(raw, c) {
|
|
|
18198
18398
|
}
|
|
18199
18399
|
if (isClosing(c.heard) && (!mv || mv.kind === "quiet")) {
|
|
18200
18400
|
const l = ownLine(BYES[c.lang], c);
|
|
18201
|
-
return l ? { kind: "say", line: l } : mv;
|
|
18401
|
+
return l ? { kind: "say", line: l, end: true } : mv;
|
|
18202
18402
|
}
|
|
18203
18403
|
return mv;
|
|
18204
18404
|
}
|