@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/cli.js
CHANGED
|
@@ -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,6 +8291,7 @@ 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) {
|
|
@@ -8201,6 +8303,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8201
8303
|
else {
|
|
8202
8304
|
this.wordStarts.push(this.wordOrigin + s);
|
|
8203
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
|
}
|
|
@@ -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();
|
|
@@ -9871,8 +9996,8 @@ var SonioxSTTOptions = class {
|
|
|
9871
9996
|
/** `stt-rt-preview` was RETIRED (aliased to the two-generations-old v3 on 2025-10-31), so every
|
|
9872
9997
|
* caller that never set this was silently running an old model while the alias kept it working —
|
|
9873
9998
|
* the failure mode of a default that is a moving vendor pointer. Pin a real version instead;
|
|
9874
|
-
* `stt-rt-
|
|
9875
|
-
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";
|
|
9876
10001
|
languageHints = ["en"];
|
|
9877
10002
|
/** Opt-in Soniox language identification (`enable_language_identification`): every token is tagged with a
|
|
9878
10003
|
* `language` code, and onUtterance's 3rd arg reports the utterance's dominant one (by characters). */
|
|
@@ -9897,6 +10022,10 @@ var SonioxSTTOptions = class {
|
|
|
9897
10022
|
/** No-audio watchdog: if the mic source stops delivering chunks for this long, capture is dead →
|
|
9898
10023
|
* fire onFatal + stop (else Soniox idle-timeouts and reconnect-loops forever). 0 = disable. */
|
|
9899
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;
|
|
9900
10029
|
};
|
|
9901
10030
|
var SonioxSTT = class {
|
|
9902
10031
|
options;
|
|
@@ -9959,6 +10088,17 @@ var SonioxSTT = class {
|
|
|
9959
10088
|
constructor(options) {
|
|
9960
10089
|
this.options = { ...new SonioxSTTOptions(), ...options };
|
|
9961
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
|
+
}
|
|
9962
10102
|
get usingAec() {
|
|
9963
10103
|
return this.options.source?.aec ?? false;
|
|
9964
10104
|
}
|
|
@@ -9983,18 +10123,20 @@ var SonioxSTT = class {
|
|
|
9983
10123
|
...this.options.languageHintsStrict ? { language_hints_strict: true } : {},
|
|
9984
10124
|
...this.options.languageIdentification ? { enable_language_identification: true } : {},
|
|
9985
10125
|
...this.options.diarization ? { enable_speaker_diarization: true } : {},
|
|
9986
|
-
...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 } : {}
|
|
9987
10128
|
})
|
|
9988
10129
|
);
|
|
9989
10130
|
this.ws.onmessage = (ev) => this.handle(JSON.parse(String(ev.data)));
|
|
9990
10131
|
this.ws.onclose = (ev) => {
|
|
9991
|
-
if (this.stopped) return;
|
|
10132
|
+
if (this.stopped || this.failed) return;
|
|
9992
10133
|
log15.warn(`soniox ws closed (${ev.code} ${ev.reason || ""}) \u2014 reconnecting`);
|
|
9993
10134
|
this.diag("stt_ws_closed", { code: ev.code, reason: String(ev.reason || ""), reconnecting: true });
|
|
9994
10135
|
this.reset();
|
|
9995
10136
|
this.connectWs().catch((e) => {
|
|
9996
10137
|
log15.error(`soniox reconnect failed: ${e.message}`);
|
|
9997
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}).`);
|
|
9998
10140
|
});
|
|
9999
10141
|
};
|
|
10000
10142
|
}
|
|
@@ -10054,7 +10196,10 @@ var SonioxSTT = class {
|
|
|
10054
10196
|
handle(m) {
|
|
10055
10197
|
if (m.error_message) {
|
|
10056
10198
|
this.diag("stt_error", { message: String(m.error_message), code: m.error_code });
|
|
10057
|
-
|
|
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;
|
|
10058
10203
|
}
|
|
10059
10204
|
let endpoint = false;
|
|
10060
10205
|
const foreign = this.options.languageHintsStrict ? foreignScript(this.options.languageHints) : null;
|
|
@@ -10130,6 +10275,14 @@ var SonioxSTT = class {
|
|
|
10130
10275
|
this.firstTokenAt = 0;
|
|
10131
10276
|
this.lastWordEndMs = 0;
|
|
10132
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
|
+
}
|
|
10133
10286
|
stop() {
|
|
10134
10287
|
this.stopped = true;
|
|
10135
10288
|
if (this.endpointTimer) clearInterval(this.endpointTimer);
|
|
@@ -10139,6 +10292,15 @@ var SonioxSTT = class {
|
|
|
10139
10292
|
this.ws?.close();
|
|
10140
10293
|
}
|
|
10141
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
|
+
}
|
|
10142
10304
|
var SCRIPTS = {
|
|
10143
10305
|
he: ["Hebrew"],
|
|
10144
10306
|
yi: ["Hebrew"],
|