@livx.cc/agentx 0.99.157 → 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 +173 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.js +173 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7753,6 +7753,105 @@ function formatTurns(turns, name = (t) => `Speaker ${t.speaker}`) {
|
|
|
7753
7753
|
return turns.map((t) => `${name(t)}: ${t.text}`).join("\n");
|
|
7754
7754
|
}
|
|
7755
7755
|
|
|
7756
|
+
// node_modules/@bod.ee/voice/src/core/agent-text-feed.ts
|
|
7757
|
+
var AgentTextFeedOptions = class {
|
|
7758
|
+
/** Deliver a piece (`text` may be '' with `endOfSegment`). */
|
|
7759
|
+
send = () => {
|
|
7760
|
+
};
|
|
7761
|
+
clock;
|
|
7762
|
+
/** Playback clock of the current turn (ms) — the same one word timestamps are anchored on. */
|
|
7763
|
+
playedMs = () => 0;
|
|
7764
|
+
/** Send this far ahead of playback (docs: 500 ms–1 s). */
|
|
7765
|
+
leadMs = 700;
|
|
7766
|
+
/** Speech-rate estimate without word timestamps. */
|
|
7767
|
+
charsPerSec = 15;
|
|
7768
|
+
tickMs = 50;
|
|
7769
|
+
};
|
|
7770
|
+
var AgentTextFeed = class {
|
|
7771
|
+
options;
|
|
7772
|
+
open = false;
|
|
7773
|
+
byWords = false;
|
|
7774
|
+
words = [];
|
|
7775
|
+
// [word, start sec on the playback clock]
|
|
7776
|
+
wordsSent = 0;
|
|
7777
|
+
chars = "";
|
|
7778
|
+
charsSent = 0;
|
|
7779
|
+
originMs = -1;
|
|
7780
|
+
// char clock: playback position of the turn's first audio byte (-1 = no audio yet)
|
|
7781
|
+
timer = null;
|
|
7782
|
+
constructor(options) {
|
|
7783
|
+
this.options = { ...new AgentTextFeedOptions(), ...options };
|
|
7784
|
+
}
|
|
7785
|
+
get active() {
|
|
7786
|
+
return this.open;
|
|
7787
|
+
}
|
|
7788
|
+
/** A spoken turn starts (closes a previous one still open — a gapless handoff plays it out). */
|
|
7789
|
+
begin(byWords) {
|
|
7790
|
+
if (this.open) this.end();
|
|
7791
|
+
this.open = true;
|
|
7792
|
+
this.byWords = byWords;
|
|
7793
|
+
this.words = [];
|
|
7794
|
+
this.wordsSent = 0;
|
|
7795
|
+
this.chars = "";
|
|
7796
|
+
this.charsSent = 0;
|
|
7797
|
+
this.originMs = -1;
|
|
7798
|
+
this.schedule();
|
|
7799
|
+
}
|
|
7800
|
+
/** Text handed to the TTS (char clock only). */
|
|
7801
|
+
text(t) {
|
|
7802
|
+
if (this.open && !this.byWords) this.chars += t;
|
|
7803
|
+
}
|
|
7804
|
+
/** The turn's first audio byte lands at this playback position (char clock only). */
|
|
7805
|
+
audioAt(ms) {
|
|
7806
|
+
if (this.open && this.originMs < 0) this.originMs = ms;
|
|
7807
|
+
}
|
|
7808
|
+
/** A TTS word timestamp on the playback clock (word clock only). */
|
|
7809
|
+
word(w, startSec) {
|
|
7810
|
+
if (this.open && this.byWords && w) this.words.push([w, startSec]);
|
|
7811
|
+
}
|
|
7812
|
+
/** The turn's audio finished playing: send the rest, close the segment. */
|
|
7813
|
+
end() {
|
|
7814
|
+
if (!this.open) return;
|
|
7815
|
+
this.flush(Infinity, true);
|
|
7816
|
+
}
|
|
7817
|
+
/** Barge-in: send only what was already due, close the segment. */
|
|
7818
|
+
cut() {
|
|
7819
|
+
if (!this.open) return;
|
|
7820
|
+
this.flush(this.options.playedMs() + this.options.leadMs, true);
|
|
7821
|
+
}
|
|
7822
|
+
schedule() {
|
|
7823
|
+
this.timer = this.options.clock.setTimeout(() => {
|
|
7824
|
+
this.timer = null;
|
|
7825
|
+
if (!this.open) return;
|
|
7826
|
+
this.flush(this.options.playedMs() + this.options.leadMs, false);
|
|
7827
|
+
if (this.open) this.schedule();
|
|
7828
|
+
}, this.options.tickMs);
|
|
7829
|
+
}
|
|
7830
|
+
flush(dueMs, close) {
|
|
7831
|
+
let piece = "";
|
|
7832
|
+
if (this.byWords) {
|
|
7833
|
+
let n = this.wordsSent;
|
|
7834
|
+
while (n < this.words.length && this.words[n][1] * 1e3 <= dueMs) n++;
|
|
7835
|
+
piece = this.words.slice(this.wordsSent, n).map(([w]) => w + " ").join("");
|
|
7836
|
+
this.wordsSent = n;
|
|
7837
|
+
} else if (this.originMs >= 0 || dueMs === Infinity) {
|
|
7838
|
+
const n = dueMs === Infinity ? this.chars.length : Math.min(this.chars.length, Math.floor((dueMs - this.originMs) / 1e3 * this.options.charsPerSec));
|
|
7839
|
+
if (n > this.charsSent) {
|
|
7840
|
+
piece = this.chars.slice(this.charsSent, n);
|
|
7841
|
+
this.charsSent = n;
|
|
7842
|
+
}
|
|
7843
|
+
}
|
|
7844
|
+
if (close) {
|
|
7845
|
+
this.open = false;
|
|
7846
|
+
if (this.timer) {
|
|
7847
|
+
this.options.clock.clearTimeout(this.timer);
|
|
7848
|
+
this.timer = null;
|
|
7849
|
+
}
|
|
7850
|
+
}
|
|
7851
|
+
if (piece || close) this.options.send(piece, close);
|
|
7852
|
+
}
|
|
7853
|
+
};
|
|
7854
|
+
|
|
7756
7855
|
// node_modules/@bod.ee/voice/src/core/engine.ts
|
|
7757
7856
|
var log15 = forComponent2("VoiceEngine");
|
|
7758
7857
|
var addLangs = (to, from) => {
|
|
@@ -8045,6 +8144,8 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8045
8144
|
// leading timestamped words that are the ack spoken on this turn's context, not the reply
|
|
8046
8145
|
revealedN = 0;
|
|
8047
8146
|
revealPoll = null;
|
|
8147
|
+
agentText = null;
|
|
8148
|
+
// stt.agentTextInput: our spoken text, paced to playback
|
|
8048
8149
|
// Sub-turn timestamp anchoring. A TTS context emits word starts relative to ITS OWN audio start, so
|
|
8049
8150
|
// `wordStarts` (one flat turn timeline) is only valid while the turn stays on one context. It does
|
|
8050
8151
|
// not: `subturnBoundary()` rotates the context, and Cartesia ALSO rotates it on its own (~5s idle
|
|
@@ -8186,6 +8287,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8186
8287
|
this.tts.onAudio = (c) => {
|
|
8187
8288
|
if (!this.speaking && !this.bcActive) return;
|
|
8188
8289
|
if (this.wordAnchorPending && this.speaking) this.anchorSubturn();
|
|
8290
|
+
if (this.speaking) this.agentText?.audioAt(this.player.endMs());
|
|
8189
8291
|
this.player.write(c);
|
|
8190
8292
|
};
|
|
8191
8293
|
if (this.options.revealMode === "word" || this.options.heardTimestamps) {
|
|
@@ -8197,6 +8299,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8197
8299
|
else {
|
|
8198
8300
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8199
8301
|
this.wordTexts.push(words4[i] ?? "");
|
|
8302
|
+
this.agentText?.word(words4[i] ?? "", this.wordOrigin + s);
|
|
8200
8303
|
}
|
|
8201
8304
|
});
|
|
8202
8305
|
};
|
|
@@ -8222,6 +8325,18 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8222
8325
|
this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
|
|
8223
8326
|
};
|
|
8224
8327
|
this.stt.onLevel = (rms) => this.handleLevel(rms);
|
|
8328
|
+
const stt = this.stt;
|
|
8329
|
+
this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
|
|
8330
|
+
clock: this.clock,
|
|
8331
|
+
playedMs: () => Math.max(0, this.player.playedMs()),
|
|
8332
|
+
send: (text, end) => {
|
|
8333
|
+
try {
|
|
8334
|
+
stt.sendAgentText(text, end);
|
|
8335
|
+
} catch (e) {
|
|
8336
|
+
log15.warn(`sendAgentText threw: ${e instanceof Error ? e.message : e}`);
|
|
8337
|
+
}
|
|
8338
|
+
}
|
|
8339
|
+
}) : null;
|
|
8225
8340
|
await Promise.all([
|
|
8226
8341
|
this.tts.connect(),
|
|
8227
8342
|
this.stt.start(),
|
|
@@ -8327,10 +8442,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8327
8442
|
this.lineBefore = new Set(this.echoWords);
|
|
8328
8443
|
this.tts.newContext();
|
|
8329
8444
|
this.clause = "";
|
|
8445
|
+
this.agentText?.begin(!!this.tts.wantTimestamps);
|
|
8330
8446
|
this.clearAckTimer("new_turn");
|
|
8331
8447
|
if (ack && this.options.ackPhrase) {
|
|
8332
8448
|
this.diag("ack_fired", { phrase: this.options.ackPhrase, adaptive: false });
|
|
8333
|
-
this.
|
|
8449
|
+
this.say(this.options.ackPhrase + " ");
|
|
8334
8450
|
this.spokeDeltas = true;
|
|
8335
8451
|
this.ackAt = this.clock.now();
|
|
8336
8452
|
this.lastAck = this.options.ackPhrase;
|
|
@@ -8402,13 +8518,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8402
8518
|
}
|
|
8403
8519
|
for (const w of this.words(this.reply)) this.echoWords.add(w);
|
|
8404
8520
|
const cut = this.options.flushFirstClause && this.clause !== null && this.tts.flush ? speech.search(/[,.;:!?…](?=\s|$)/) : -1;
|
|
8405
|
-
if (cut < 0) this.
|
|
8521
|
+
if (cut < 0) this.say(forSpeech(speech));
|
|
8406
8522
|
else {
|
|
8407
|
-
this.
|
|
8523
|
+
this.say(forSpeech(speech.slice(0, cut + 1)));
|
|
8408
8524
|
this.clause = null;
|
|
8409
8525
|
this.tts.flush();
|
|
8410
8526
|
this.diag("tts_first_clause_flush", {});
|
|
8411
|
-
if (speech.slice(cut + 1)) this.
|
|
8527
|
+
if (speech.slice(cut + 1)) this.say(forSpeech(speech.slice(cut + 1)));
|
|
8412
8528
|
}
|
|
8413
8529
|
if (!this.spokeDeltas && this.turnStartAt) log15.debug(`ttft: ${Math.round(this.clock.now() - this.turnStartAt)}ms`);
|
|
8414
8530
|
this.spokeDeltas = true;
|
|
@@ -8449,6 +8565,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8449
8565
|
for (const [w, s] of this.wordPending) {
|
|
8450
8566
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8451
8567
|
this.wordTexts.push(w);
|
|
8568
|
+
this.agentText?.word(w, this.wordOrigin + s);
|
|
8452
8569
|
}
|
|
8453
8570
|
this.wordPending = [];
|
|
8454
8571
|
}
|
|
@@ -8491,6 +8608,11 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8491
8608
|
if (full) this.options.onReveal(full);
|
|
8492
8609
|
}
|
|
8493
8610
|
}
|
|
8611
|
+
/** Speech on the open turn's TTS context — also fed to the STT's agent text input (when on). */
|
|
8612
|
+
say(text) {
|
|
8613
|
+
this.agentText?.text(text);
|
|
8614
|
+
this.tts.speak(text, true);
|
|
8615
|
+
}
|
|
8494
8616
|
/** close the spoken turn (idempotent); stays audible until ALL audio arrived AND playback drains */
|
|
8495
8617
|
endSpeech() {
|
|
8496
8618
|
this.interrupted = false;
|
|
@@ -8510,7 +8632,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8510
8632
|
const t = this.emo.flush();
|
|
8511
8633
|
this.emo = null;
|
|
8512
8634
|
if (t.prose) this.reply += t.prose;
|
|
8513
|
-
if (t.speech) this.
|
|
8635
|
+
if (t.speech) this.say(forSpeech(t.speech));
|
|
8514
8636
|
}
|
|
8515
8637
|
if (this.reply) this.prevReply = this.reply;
|
|
8516
8638
|
const settle = () => {
|
|
@@ -8524,6 +8646,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8524
8646
|
}
|
|
8525
8647
|
this.drainTimer = null;
|
|
8526
8648
|
this.speaking = false;
|
|
8649
|
+
this.agentText?.end();
|
|
8527
8650
|
this.stopWordReveal(true);
|
|
8528
8651
|
if (this.turnStartAt) log15.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
|
|
8529
8652
|
this.echoUntil = this.clock.now() + 2500;
|
|
@@ -8639,7 +8762,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8639
8762
|
return;
|
|
8640
8763
|
}
|
|
8641
8764
|
this.diag("ack_fired", { phrase, adaptive: true, waitedMs: this.options.adaptiveAckMs, ...picked ? { picked } : {} });
|
|
8642
|
-
this.
|
|
8765
|
+
this.say(phrase + " ");
|
|
8643
8766
|
this.spokeDeltas = true;
|
|
8644
8767
|
this.ackAt = this.clock.now();
|
|
8645
8768
|
this.lastAck = phrase;
|
|
@@ -8725,6 +8848,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8725
8848
|
this.interrupted = true;
|
|
8726
8849
|
this.suspectUntil = 0;
|
|
8727
8850
|
this.echoUntil = this.clock.now() + Math.max(2500, this.player.drainMs() + 3e3);
|
|
8851
|
+
this.agentText?.cut();
|
|
8728
8852
|
this.tts.cancel();
|
|
8729
8853
|
this.player.kill();
|
|
8730
8854
|
if (!this.usingAec) this.echoHead = true;
|
|
@@ -8755,6 +8879,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8755
8879
|
if (this.specTimer) this.clock.clearTimeout(this.specTimer);
|
|
8756
8880
|
this.bcSupersede();
|
|
8757
8881
|
this.cancelAside("stop");
|
|
8882
|
+
this.agentText?.cut();
|
|
8758
8883
|
this.stt.stop();
|
|
8759
8884
|
this.player.kill();
|
|
8760
8885
|
this.tts.close();
|
|
@@ -9867,8 +9992,8 @@ var SonioxSTTOptions = class {
|
|
|
9867
9992
|
/** `stt-rt-preview` was RETIRED (aliased to the two-generations-old v3 on 2025-10-31), so every
|
|
9868
9993
|
* caller that never set this was silently running an old model while the alias kept it working —
|
|
9869
9994
|
* the failure mode of a default that is a moving vendor pointer. Pin a real version instead;
|
|
9870
|
-
* `stt-rt-
|
|
9871
|
-
model = "stt-rt-
|
|
9995
|
+
* `stt-rt-v6` (2026-11-03) replaced v5, deprecated and removed 2026-12-15 (docs.soniox.com/stt/models). */
|
|
9996
|
+
model = "stt-rt-v6";
|
|
9872
9997
|
languageHints = ["en"];
|
|
9873
9998
|
/** Opt-in Soniox language identification (`enable_language_identification`): every token is tagged with a
|
|
9874
9999
|
* `language` code, and onUtterance's 3rd arg reports the utterance's dominant one (by characters). */
|
|
@@ -9893,6 +10018,10 @@ var SonioxSTTOptions = class {
|
|
|
9893
10018
|
/** No-audio watchdog: if the mic source stops delivering chunks for this long, capture is dead →
|
|
9894
10019
|
* fire onFatal + stop (else Soniox idle-timeouts and reconnect-loops forever). 0 = disable. */
|
|
9895
10020
|
noAudioTimeoutMs = 1e4;
|
|
10021
|
+
/** Opt-in Soniox agent text input (`enable_agent_text_input`, stt-rt-v6 only): the assistant's spoken text goes on the
|
|
10022
|
+
* same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
|
|
10023
|
+
* of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
|
|
10024
|
+
agentTextInput = false;
|
|
9896
10025
|
};
|
|
9897
10026
|
var SonioxSTT = class {
|
|
9898
10027
|
options;
|
|
@@ -9955,6 +10084,17 @@ var SonioxSTT = class {
|
|
|
9955
10084
|
constructor(options) {
|
|
9956
10085
|
this.options = { ...new SonioxSTTOptions(), ...options };
|
|
9957
10086
|
}
|
|
10087
|
+
get agentTextInput() {
|
|
10088
|
+
return this.options.agentTextInput;
|
|
10089
|
+
}
|
|
10090
|
+
/** Send the next not-yet-sent piece of what the assistant is saying (`agent_text`); `endOfSegment` closes the
|
|
10091
|
+
* assistant's turn (finished or interrupted). Spaces are kept as given. No-op unless `agentTextInput` is on and the
|
|
10092
|
+
* socket is open (a reconnect starts a fresh stream; text sent before it is not re-sent). */
|
|
10093
|
+
sendAgentText(text, endOfSegment = false) {
|
|
10094
|
+
if (!this.options.agentTextInput || this.stopped || this.ws?.readyState !== WebSocket.OPEN) return;
|
|
10095
|
+
if (!text && !endOfSegment) return;
|
|
10096
|
+
this.ws.send(JSON.stringify({ type: "agent_text", text, ...endOfSegment ? { end_of_segment: true } : {} }));
|
|
10097
|
+
}
|
|
9958
10098
|
get usingAec() {
|
|
9959
10099
|
return this.options.source?.aec ?? false;
|
|
9960
10100
|
}
|
|
@@ -9979,18 +10119,20 @@ var SonioxSTT = class {
|
|
|
9979
10119
|
...this.options.languageHintsStrict ? { language_hints_strict: true } : {},
|
|
9980
10120
|
...this.options.languageIdentification ? { enable_language_identification: true } : {},
|
|
9981
10121
|
...this.options.diarization ? { enable_speaker_diarization: true } : {},
|
|
9982
|
-
...this.options.terms?.length ? { context: { terms: this.options.terms } } : {}
|
|
10122
|
+
...this.options.terms?.length ? { context: { terms: this.options.terms } } : {},
|
|
10123
|
+
...this.options.agentTextInput ? { enable_agent_text_input: true } : {}
|
|
9983
10124
|
})
|
|
9984
10125
|
);
|
|
9985
10126
|
this.ws.onmessage = (ev) => this.handle(JSON.parse(String(ev.data)));
|
|
9986
10127
|
this.ws.onclose = (ev) => {
|
|
9987
|
-
if (this.stopped) return;
|
|
10128
|
+
if (this.stopped || this.failed) return;
|
|
9988
10129
|
log16.warn(`soniox ws closed (${ev.code} ${ev.reason || ""}) \u2014 reconnecting`);
|
|
9989
10130
|
this.diag("stt_ws_closed", { code: ev.code, reason: String(ev.reason || ""), reconnecting: true });
|
|
9990
10131
|
this.reset();
|
|
9991
10132
|
this.connectWs().catch((e) => {
|
|
9992
10133
|
log16.error(`soniox reconnect failed: ${e.message}`);
|
|
9993
10134
|
this.diag("stt_reconnect_failed", { message: e.message });
|
|
10135
|
+
this.fail(`Speech-to-text (Soniox) lost its connection and could not reconnect (${e.message}).`);
|
|
9994
10136
|
});
|
|
9995
10137
|
};
|
|
9996
10138
|
}
|
|
@@ -10050,7 +10192,10 @@ var SonioxSTT = class {
|
|
|
10050
10192
|
handle(m) {
|
|
10051
10193
|
if (m.error_message) {
|
|
10052
10194
|
this.diag("stt_error", { message: String(m.error_message), code: m.error_code });
|
|
10053
|
-
|
|
10195
|
+
log16.error(`soniox: ${m.error_message}`);
|
|
10196
|
+
const fatal = sonioxFatal(m.error_code, String(m.error_message));
|
|
10197
|
+
if (fatal) this.fail(fatal);
|
|
10198
|
+
return;
|
|
10054
10199
|
}
|
|
10055
10200
|
let endpoint = false;
|
|
10056
10201
|
const foreign = this.options.languageHintsStrict ? foreignScript(this.options.languageHints) : null;
|
|
@@ -10126,6 +10271,14 @@ var SonioxSTT = class {
|
|
|
10126
10271
|
this.firstTokenAt = 0;
|
|
10127
10272
|
this.lastWordEndMs = 0;
|
|
10128
10273
|
}
|
|
10274
|
+
/** Unrecoverable: tell the host once, then stop (no reconnect loop). */
|
|
10275
|
+
failed = false;
|
|
10276
|
+
fail(message) {
|
|
10277
|
+
if (this.failed || this.stopped) return;
|
|
10278
|
+
this.failed = true;
|
|
10279
|
+
this.onFatal(message);
|
|
10280
|
+
this.stop();
|
|
10281
|
+
}
|
|
10129
10282
|
stop() {
|
|
10130
10283
|
this.stopped = true;
|
|
10131
10284
|
if (this.endpointTimer) clearInterval(this.endpointTimer);
|
|
@@ -10135,6 +10288,15 @@ var SonioxSTT = class {
|
|
|
10135
10288
|
this.ws?.close();
|
|
10136
10289
|
}
|
|
10137
10290
|
};
|
|
10291
|
+
function sonioxFatal(code, message) {
|
|
10292
|
+
const c = Number(code);
|
|
10293
|
+
if (c === 402 || /balance|autopay|add funds|payment required/i.test(message))
|
|
10294
|
+
return `Speech-to-text is out of credit (Soniox): ${message} Add funds at console.soniox.com.`;
|
|
10295
|
+
if (c === 401 || c === 403 || /api key|unauthori[sz]ed|forbidden/i.test(message))
|
|
10296
|
+
return `Speech-to-text (Soniox) rejected the API key: ${message}`;
|
|
10297
|
+
if (c === 400) return `Speech-to-text (Soniox) rejected the request: ${message}`;
|
|
10298
|
+
return null;
|
|
10299
|
+
}
|
|
10138
10300
|
var SCRIPTS = {
|
|
10139
10301
|
he: ["Hebrew"],
|
|
10140
10302
|
yi: ["Hebrew"],
|