@livx.cc/agentx 0.99.165 → 0.99.167
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.d.ts +5 -1
- package/dist/cli.js +581 -188
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +204 -32
- package/dist/index.js.map +1 -1
- package/dist/native/mic-aec.swift +44 -1
- package/dist/{secondChannel-BNDDJv6d.d.ts → secondChannel-DLB-hDny.d.ts} +5 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel-
|
|
2
|
-
export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel-
|
|
1
|
+
import { c as AgentOptions, H as Hooks, x as RunResult, k as Decider, b as Agent, q as PermissionPolicy, G as Gender, L as LineKind, d as ChannelMode, y as SecondChannelOptions, S as SecondChannel } from './secondChannel-DLB-hDny.js';
|
|
2
|
+
export { A as ADVISE_LIMIT, a as AdvisorSetup, C as CC_WRITE_TOOLS, e as ChatFragment, f as ChatUsage, g as Classification, h as Classifier, i as CompactResult, j as ContextFileSpec, D as DEFAULT_MUTATING, l as Decision, M as ModelRouter, m as ModelRouterOptions, P as PLANNER_BLOCKED, n as PLANNER_REFUSAL, o as PLAN_FIRST, p as PermissionOptions, r as PermissionRule, s as PreToolUseDecision, R as ReasoningEffort, t as RecordingHooks, u as RecordingLifecycle, v as RouteDecision, w as RouterState, T as Tier, z as ToolUse, B as ToolUseMeta, W as WRITE_TOOLS, E as advisorFor, F as advisorPrompt, I as ccModeOptions, J as claudeCodeDisallowedTools, K as composeHooks, N as delegatePrompt, O as delegateTools, Q as delegateWorkerFor, U as estimateTokens, V as jevAvailable, X as jevClassifier, Y as loadContextFiles, Z as loadInstructions, _ as makeAdvisor, $ as meterWorkers, a0 as pickTier, a1 as planMode, a2 as plannerBlocks, a3 as reasoningToChatFragment } from './secondChannel-DLB-hDny.js';
|
|
3
3
|
export { MODEL_ALIASES, ModelSwitch, ResolveModelSwitchOpts, latestClaude, modelShortLabel, resolveModelAlias, resolveModelSwitch } from './models.js';
|
|
4
4
|
import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
|
|
5
5
|
export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
|
package/dist/index.js
CHANGED
|
@@ -3195,6 +3195,23 @@ function ccToolServer(name, tools, call) {
|
|
|
3195
3195
|
return { type: "sdk", name, instance };
|
|
3196
3196
|
}
|
|
3197
3197
|
|
|
3198
|
+
// src/runtimes.ts
|
|
3199
|
+
var RUNTIMES = {
|
|
3200
|
+
"claude-code": { keyless: true, ownsTools: true },
|
|
3201
|
+
cursor: { keyless: false, ownsTools: false }
|
|
3202
|
+
// host tools are bridged in through its toolExecutor
|
|
3203
|
+
};
|
|
3204
|
+
function runtimeOf(model) {
|
|
3205
|
+
const p = (model ?? "").split("/")[0];
|
|
3206
|
+
return (model ?? "").includes("/") && p in RUNTIMES ? p : void 0;
|
|
3207
|
+
}
|
|
3208
|
+
var isClaudeCode = (model) => runtimeOf(model) === "claude-code";
|
|
3209
|
+
var isCursor = (model) => runtimeOf(model) === "cursor";
|
|
3210
|
+
var ownsTools = (model) => {
|
|
3211
|
+
const r = runtimeOf(model);
|
|
3212
|
+
return !!r && RUNTIMES[r].ownsTools;
|
|
3213
|
+
};
|
|
3214
|
+
|
|
3198
3215
|
// src/Agent.ts
|
|
3199
3216
|
init_llm();
|
|
3200
3217
|
init_tools();
|
|
@@ -3980,7 +3997,11 @@ var PermissionPolicy = class {
|
|
|
3980
3997
|
preToolUse: async (call) => {
|
|
3981
3998
|
const d = this.decide(call);
|
|
3982
3999
|
if (d === "allow") return;
|
|
3983
|
-
if (d === "deny")
|
|
4000
|
+
if (d === "deny") {
|
|
4001
|
+
const reason = `denied by permission policy (${call.name})`;
|
|
4002
|
+
this.options.onDeny?.(call, reason);
|
|
4003
|
+
return { block: true, reason };
|
|
4004
|
+
}
|
|
3984
4005
|
if (this.options.ask) {
|
|
3985
4006
|
const r = await this.options.ask(call);
|
|
3986
4007
|
const decision = r?.decision ?? "deny";
|
|
@@ -4629,7 +4650,7 @@ function pairOk(kind, main, other) {
|
|
|
4629
4650
|
log8.warn(`${kind} off: both sides are ${main}`);
|
|
4630
4651
|
return false;
|
|
4631
4652
|
}
|
|
4632
|
-
if (main
|
|
4653
|
+
if (isCursor(main) || isCursor(other)) {
|
|
4633
4654
|
log8.warn(`${kind} off: cursor models are not supported (${main} / ${other})`);
|
|
4634
4655
|
return false;
|
|
4635
4656
|
}
|
|
@@ -5032,6 +5053,9 @@ var AgentOptions = class {
|
|
|
5032
5053
|
* caps, MCP soft timeout) live on `JobRegistryOptions`. Completion notices reach the model via `inject` unless
|
|
5033
5054
|
* the host set its own `onExit`. */
|
|
5034
5055
|
jobs;
|
|
5056
|
+
/** Called after every `inject()` (a background job's completion notice, a host steer). A REPL uses it to wake an
|
|
5057
|
+
* IDLE session — between turns nothing drains the queue, so a finished job would otherwise wait for the next prompt. */
|
|
5058
|
+
onInject;
|
|
5035
5059
|
/** Plan mode: block mutating tools until the agent calls `ExitPlanMode` (host-approved). */
|
|
5036
5060
|
planMode = false;
|
|
5037
5061
|
/** Permission policy gating each tool call (allow / ask / deny). */
|
|
@@ -5189,6 +5213,7 @@ var Agent = class _Agent {
|
|
|
5189
5213
|
* Pushing onto `transcript` directly from outside would race the loop — this drains inside it. */
|
|
5190
5214
|
inject(content) {
|
|
5191
5215
|
this.pendingInjections.push(content);
|
|
5216
|
+
this.options.onInject?.();
|
|
5192
5217
|
}
|
|
5193
5218
|
/** Drop any queued-but-unconsumed injections. The REPL calls this after a LOCAL command (/cmd, !bash)
|
|
5194
5219
|
* — which runs no send() to drain them — so a mid-command steer can't leak into the next real turn. */
|
|
@@ -5202,7 +5227,7 @@ var Agent = class _Agent {
|
|
|
5202
5227
|
/** claude-code/*: the providerOptions every step adds (and prewarm, so the session it starts is the one step 1 reuses). */
|
|
5203
5228
|
claudeCodePo() {
|
|
5204
5229
|
const o = this.options;
|
|
5205
|
-
if (!o.model
|
|
5230
|
+
if (!isClaudeCode(o.model)) return void 0;
|
|
5206
5231
|
const po = { steer: () => this.drainPendingSteers() };
|
|
5207
5232
|
const mode = ccModeOptions(this.modeKind, o.providerOptions?.hooks, () => this.adv?.used() ?? 0);
|
|
5208
5233
|
const bridged = (t) => o.ccBridge === "all" || CC_BRIDGED.has(t.name) || mode.bridge.has(t.name);
|
|
@@ -5232,7 +5257,7 @@ var Agent = class _Agent {
|
|
|
5232
5257
|
async prewarm() {
|
|
5233
5258
|
const o = this.options;
|
|
5234
5259
|
const api = o.model.startsWith("anthropic/") && o.promptCache;
|
|
5235
|
-
if (!api && (!o.model
|
|
5260
|
+
if (!api && (!isClaudeCode(o.model) || !o.providerOptions?.claudeCodeSession)) return;
|
|
5236
5261
|
await this.ensureFs();
|
|
5237
5262
|
const systemPrompt = await this.prepare(), startCtx = await this.fireSessionStart();
|
|
5238
5263
|
const sys = { role: "system", content: systemPrompt + (startCtx ? "\n\n" + startCtx : "") };
|
|
@@ -5549,8 +5574,8 @@ var Agent = class _Agent {
|
|
|
5549
5574
|
let res;
|
|
5550
5575
|
let sent = this.trimContext();
|
|
5551
5576
|
const frag = reasoningToChatFragment(o.model, o.reasoning);
|
|
5552
|
-
const sentTools = o.model
|
|
5553
|
-
const isCursorWithTools = o.model
|
|
5577
|
+
const sentTools = ownsTools(o.model) ? [] : wireTools;
|
|
5578
|
+
const isCursorWithTools = isCursor(o.model) && wireTools.length > 0;
|
|
5554
5579
|
const hostToolTimeoutMs = o.providerOptions?.toolTimeoutMs;
|
|
5555
5580
|
const derivedToolTimeoutMs = Math.max(TRANSPORT_TOOL_TIMEOUT_FLOOR_MS, ...this.activeTools.map(transportHeadroomMs));
|
|
5556
5581
|
const effectiveToolTimeoutMs = typeof hostToolTimeoutMs === "number" ? Math.max(hostToolTimeoutMs, derivedToolTimeoutMs) : derivedToolTimeoutMs;
|
|
@@ -5580,8 +5605,8 @@ var Agent = class _Agent {
|
|
|
5580
5605
|
const cursorPo = isCursorWithTools ? { toolTimeoutMs: effectiveToolTimeoutMs, toolExecutor: hostExec } : void 0;
|
|
5581
5606
|
const claudeSteerPo = this.claudeCodePo();
|
|
5582
5607
|
if (this.ccServer) this.ccExec = hostExec;
|
|
5583
|
-
const cursorDeny = o.model
|
|
5584
|
-
if (o.model
|
|
5608
|
+
const cursorDeny = isCursor(o.model) ? o.permissions?.denyRules(true) ?? [] : [];
|
|
5609
|
+
if (isCursor(o.model) && o.permissions?.options.default === "deny")
|
|
5585
5610
|
throw new Error("cursor/* cannot enforce --onlyTools: its native tools bypass it. Refusing to run \u2014 use a claude-code/* or API model.");
|
|
5586
5611
|
if (cursorDeny.length)
|
|
5587
5612
|
throw new Error(`cursor/* cannot enforce --disallowedTools (${cursorDeny.join(", ")}): its native tools bypass them. Refusing to run \u2014 use a claude-code/* or API model, or drop --disallowedTools.`);
|
|
@@ -8149,6 +8174,9 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8149
8174
|
// bumps on every aside start/cancel — a late aside of a dead hold never plays
|
|
8150
8175
|
speaking = false;
|
|
8151
8176
|
// audible (deltas flowing OR audio draining)
|
|
8177
|
+
speechStartAt = 0;
|
|
8178
|
+
// clock time `speaking` last turned on / off
|
|
8179
|
+
speechEndAt = 0;
|
|
8152
8180
|
ctxOpen = false;
|
|
8153
8181
|
// the current TTS context still accepts deltas (false once end-frame sent)
|
|
8154
8182
|
interrupted = false;
|
|
@@ -8346,11 +8374,13 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8346
8374
|
this.handleUtterance(k.text, language ? { [language]: k.text.length } : void 0, k.turns);
|
|
8347
8375
|
};
|
|
8348
8376
|
this.stt.onLevel = (rms) => this.handleLevel(rms);
|
|
8377
|
+
this.stt.isAudible = (agoMs = 0) => this.speakingAt(this.clock.now() - agoMs);
|
|
8349
8378
|
const stt = this.stt;
|
|
8350
8379
|
this.agentText = stt.agentTextInput && stt.sendAgentText ? new AgentTextFeed({
|
|
8351
8380
|
clock: this.clock,
|
|
8352
8381
|
playedMs: () => Math.max(0, this.player.playedMs()),
|
|
8353
8382
|
send: (text, end) => {
|
|
8383
|
+
this.diag("agent_text", { text: text.slice(0, 80), ...end ? { end: true } : {} });
|
|
8354
8384
|
try {
|
|
8355
8385
|
stt.sendAgentText(text, end);
|
|
8356
8386
|
} catch (e) {
|
|
@@ -8442,7 +8472,10 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8442
8472
|
}
|
|
8443
8473
|
this.diag("tts_turn_begin", { ack, gapless: this.speaking });
|
|
8444
8474
|
const gapless = this.speaking;
|
|
8445
|
-
if (!this.speaking)
|
|
8475
|
+
if (!this.speaking) {
|
|
8476
|
+
this.player.markTurn();
|
|
8477
|
+
this.speechStartAt = this.clock.now();
|
|
8478
|
+
}
|
|
8446
8479
|
this.speaking = true;
|
|
8447
8480
|
this.ctxOpen = true;
|
|
8448
8481
|
this.spokeDeltas = false;
|
|
@@ -8667,6 +8700,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8667
8700
|
}
|
|
8668
8701
|
this.drainTimer = null;
|
|
8669
8702
|
this.speaking = false;
|
|
8703
|
+
this.speechEndAt = this.clock.now();
|
|
8670
8704
|
this.agentText?.end();
|
|
8671
8705
|
this.stopWordReveal(true);
|
|
8672
8706
|
if (this.turnStartAt) log15.debug(`turn: ${Math.round(this.clock.now() - this.turnStartAt)}ms (incl. playback)`);
|
|
@@ -8865,6 +8899,7 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8865
8899
|
if (this.reply || droppedQueued) this.lastInterrupted = { full: this.reply, heard, exact, queued, queuedTurn: this.queuedTurn };
|
|
8866
8900
|
if (heard.length < this.reply.length || droppedQueued) this.bargedSinceDispatch = true;
|
|
8867
8901
|
this.speaking = false;
|
|
8902
|
+
this.speechEndAt = this.clock.now();
|
|
8868
8903
|
this.ctxOpen = false;
|
|
8869
8904
|
this.interrupted = true;
|
|
8870
8905
|
this.suspectUntil = 0;
|
|
@@ -8974,6 +9009,14 @@ var VoiceEngine = class _VoiceEngine {
|
|
|
8974
9009
|
novelWords(text) {
|
|
8975
9010
|
return this.words(text).filter((w) => !this.echoWords.has(w));
|
|
8976
9011
|
}
|
|
9012
|
+
/** Was the assistant speaking at clock time `t` (+ PHANTOM_TAIL_MS)? Narrower than echoActive's multi-second echo
|
|
9013
|
+
* tail on purpose: the STT phantom guard drops low-confidence short finals here, and a real "Yes." said right after
|
|
9014
|
+
* a question must not land inside it. speechEndAt already trails the audio by the settle margin (~300ms). */
|
|
9015
|
+
speakingAt(t) {
|
|
9016
|
+
if (t < this.speechStartAt) return false;
|
|
9017
|
+
return this.speaking || t < this.speechEndAt + _VoiceEngine.PHANTOM_TAIL_MS;
|
|
9018
|
+
}
|
|
9019
|
+
static PHANTOM_TAIL_MS = 300;
|
|
8977
9020
|
echoActive() {
|
|
8978
9021
|
return this.speaking || this.clock.now() < this.echoUntil;
|
|
8979
9022
|
}
|
|
@@ -10043,7 +10086,18 @@ var SonioxSTTOptions = class {
|
|
|
10043
10086
|
* same socket (`sendAgentText`, which VoiceEngine drives paced to playback), so Soniox filters the leftover echo
|
|
10044
10087
|
* of our own voice out of the transcript. Complements AEC — keep echo cancellation on. */
|
|
10045
10088
|
agentTextInput = false;
|
|
10089
|
+
/** Phantom guard: when its last word fell while the assistant was speaking (`isAudible`, wired by VoiceEngine), drop a
|
|
10090
|
+
* final of at most `phantomMaxWords` words, all listener tokens (`phantomTokens`), whose least-sure token is below
|
|
10091
|
+
* `phantomMinConfidence`. stt-rt-v6 makes up backchannels ("Okay.", "Yeah.", "Mm-hmm.") from echo residue under our
|
|
10092
|
+
* own voice: all at confMin 0.33-0.78 (agentx session 20261111-124649). Confidence alone can't separate them from a
|
|
10093
|
+
* real word said over our voice — `say` clips into live Soniox under a reply's residue: 12/19 soft interjections fell
|
|
10094
|
+
* below 0.8 — so words that act ("Stop.", "No.", "Yes.", "Wait.") always pass; a listener token over our own speech
|
|
10095
|
+
* is a no-op anyway. 0 = off. */
|
|
10096
|
+
phantomMinConfidence = 0.8;
|
|
10097
|
+
phantomMaxWords = 2;
|
|
10098
|
+
phantomTokens = /^(?:okay|ok|yeah|yep|yup|mm-?hmm|mhm|hmm+|mm+|uh-?huh|oh|ah|right)$/i;
|
|
10046
10099
|
};
|
|
10100
|
+
var STD_TOKEN_KEYS = /* @__PURE__ */ new Set(["text", "start_ms", "end_ms", "confidence", "is_final", "language", "speaker"]);
|
|
10047
10101
|
var SonioxSTT = class {
|
|
10048
10102
|
options;
|
|
10049
10103
|
ws;
|
|
@@ -10068,6 +10122,9 @@ var SonioxSTT = class {
|
|
|
10068
10122
|
* loop). The host tears voice down instead of spinning forever. */
|
|
10069
10123
|
onFatal = () => {
|
|
10070
10124
|
};
|
|
10125
|
+
/** Was the assistant speaking `agoMs` ago (+ a short tail)? Set by VoiceEngine; gates the phantom guard, asked for the
|
|
10126
|
+
* moment the utterance's last word was said (not when its final landed, ~1s later). */
|
|
10127
|
+
isAudible = () => false;
|
|
10071
10128
|
/** Diagnostic tap (provider errors, ws reconnects, no-audio watchdog). Fire-and-forget: a throwing
|
|
10072
10129
|
* handler disables itself — never affects transcription. Wired by VoiceIO / the lab bridge. */
|
|
10073
10130
|
onDiag = () => {
|
|
@@ -10102,6 +10159,12 @@ var SonioxSTT = class {
|
|
|
10102
10159
|
finalToks = [];
|
|
10103
10160
|
// diarization only: finalized tokens of the current utterance
|
|
10104
10161
|
partialToks = [];
|
|
10162
|
+
uttToks = [];
|
|
10163
|
+
// stt_final diag: finalized tokens of the current utterance
|
|
10164
|
+
uttPartials = [];
|
|
10165
|
+
// stt_final diag: its current partial tokens
|
|
10166
|
+
levels = [];
|
|
10167
|
+
// stt_final diag: recent mic RMS per chunk (~12s)
|
|
10105
10168
|
constructor(options) {
|
|
10106
10169
|
this.options = { ...new SonioxSTTOptions(), ...options };
|
|
10107
10170
|
}
|
|
@@ -10165,10 +10228,7 @@ var SonioxSTT = class {
|
|
|
10165
10228
|
const combined = (this.finalText + this.partialText).trim();
|
|
10166
10229
|
if (!combined || now() - this.lastChangeAt < this.options.silenceEndpointMs) return;
|
|
10167
10230
|
if (this.firstTokenAt) log16.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192silence-endpoint, "${combined.slice(0, 60)}"`);
|
|
10168
|
-
|
|
10169
|
-
const turns = this.turns(true), ago = this.lastWordAgoMs();
|
|
10170
|
-
this.reset();
|
|
10171
|
-
this.onUtterance(this.stray(combined), now(), language, turns, ago);
|
|
10231
|
+
this.emit(combined, "silence");
|
|
10172
10232
|
}, 120);
|
|
10173
10233
|
this.endpointTimer.unref?.();
|
|
10174
10234
|
this.startedChunksAt = now();
|
|
@@ -10194,7 +10254,10 @@ var SonioxSTT = class {
|
|
|
10194
10254
|
const v = view.getInt16(i, true);
|
|
10195
10255
|
sum += v * v;
|
|
10196
10256
|
}
|
|
10197
|
-
|
|
10257
|
+
const rms = Math.sqrt(sum / (chunk.byteLength / 2));
|
|
10258
|
+
this.levels.push({ at: this.lastChunkAt, rms });
|
|
10259
|
+
if (this.levels.length > 120) this.levels.shift();
|
|
10260
|
+
this.onLevel(rms);
|
|
10198
10261
|
if (this.ws.readyState === WebSocket.OPEN) {
|
|
10199
10262
|
this.ws.send(chunk);
|
|
10200
10263
|
const at = this.sentBytes / 2 / STT_SAMPLE_RATE * 1e3;
|
|
@@ -10225,6 +10288,7 @@ var SonioxSTT = class {
|
|
|
10225
10288
|
if (t.text !== "<end>" && typeof t.end_ms === "number" && String(t.text).trim() && t.end_ms > this.lastWordEndMs) this.lastWordEndMs = t.end_ms;
|
|
10226
10289
|
if (t.text === "<end>") endpoint = true;
|
|
10227
10290
|
else if (t.is_final) {
|
|
10291
|
+
this.uttToks.push(t);
|
|
10228
10292
|
this.finalText += t.text;
|
|
10229
10293
|
this.countLang(this.finalLangChars, t);
|
|
10230
10294
|
if (this.options.diarization) this.finalToks.push(t);
|
|
@@ -10235,6 +10299,7 @@ var SonioxSTT = class {
|
|
|
10235
10299
|
this.partialLangChars = {};
|
|
10236
10300
|
for (const t of partials) this.countLang(this.partialLangChars, t);
|
|
10237
10301
|
if (this.options.diarization) this.partialToks = partials;
|
|
10302
|
+
this.uttPartials = partials;
|
|
10238
10303
|
const combined = this.finalText + this.partialText;
|
|
10239
10304
|
if (combined !== this.lastCombined) {
|
|
10240
10305
|
this.lastCombined = combined;
|
|
@@ -10245,10 +10310,32 @@ var SonioxSTT = class {
|
|
|
10245
10310
|
if (endpoint && this.finalText.trim()) {
|
|
10246
10311
|
const utterance = this.finalText.trim();
|
|
10247
10312
|
if (this.firstTokenAt) log16.debug(`stt: ${Math.round(now() - this.firstTokenAt)}ms first-token\u2192endpoint, "${utterance.slice(0, 60)}"`);
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10313
|
+
this.emit(utterance, "end");
|
|
10314
|
+
}
|
|
10315
|
+
}
|
|
10316
|
+
/** Close the current utterance: diag, reset, then hand it to onUtterance — unless the phantom guard drops it. */
|
|
10317
|
+
emit(text, endpoint) {
|
|
10318
|
+
const withPartials = endpoint === "silence";
|
|
10319
|
+
const language = this.language(withPartials);
|
|
10320
|
+
const turns = this.turns(withPartials), ago = this.lastWordAgoMs();
|
|
10321
|
+
const confMin = this.finalDiag(text, endpoint, ago);
|
|
10322
|
+
this.reset();
|
|
10323
|
+
if (this.phantom(text, confMin, ago)) {
|
|
10324
|
+
this.diag("stt_phantom_dropped", { text: text.slice(0, 80), confMin, lastWordAgoMs: ago });
|
|
10325
|
+
return;
|
|
10326
|
+
}
|
|
10327
|
+
this.onUtterance(this.stray(text), now(), language, turns, ago);
|
|
10328
|
+
}
|
|
10329
|
+
phantom(text, confMin, agoMs) {
|
|
10330
|
+
const { phantomMinConfidence: min, phantomMaxWords: max, phantomTokens: listener } = this.options;
|
|
10331
|
+
if (!min || confMin === void 0 || confMin >= min) return false;
|
|
10332
|
+
const words4 = text.split(/[\s,.!?…]+/).filter(Boolean);
|
|
10333
|
+
if (!words4.length || words4.length > max || !words4.every((w) => listener.test(w))) return false;
|
|
10334
|
+
try {
|
|
10335
|
+
return this.isAudible(agoMs ?? 0);
|
|
10336
|
+
} catch (e) {
|
|
10337
|
+
log16.warn(`isAudible threw: ${e instanceof Error ? e.message : e}`);
|
|
10338
|
+
return false;
|
|
10252
10339
|
}
|
|
10253
10340
|
}
|
|
10254
10341
|
/** How long ago (ms, now) the utterance's last spoken word ended: the audio sent so far minus that token's end_ms on
|
|
@@ -10281,7 +10368,29 @@ var SonioxSTT = class {
|
|
|
10281
10368
|
const words4 = sonioxWords(withPartials ? [...this.finalToks, ...this.partialToks] : this.finalToks);
|
|
10282
10369
|
return words4.some((w) => w.spk != null) ? speakerRuns(words4) : void 0;
|
|
10283
10370
|
}
|
|
10371
|
+
/** One `stt_final` diag per utterance: how sure Soniox was, the mic level over it, and any token fields beyond the
|
|
10372
|
+
* usual ones — to tell words the user said from ones the STT made up (a phantom "Okay." heard 186× over our own
|
|
10373
|
+
* speech, agentx session 20261111-105859). */
|
|
10374
|
+
finalDiag(text, endpoint, lastWordAgoMs) {
|
|
10375
|
+
const toks = [...this.uttToks, ...endpoint === "silence" ? this.uttPartials : []].filter((t) => String(t.text).trim());
|
|
10376
|
+
const conf = toks.map((t) => t.confidence).filter((c) => typeof c === "number");
|
|
10377
|
+
const since = (this.firstTokenAt || now()) - 1500;
|
|
10378
|
+
const rms = this.levels.filter((l) => l.at >= since).map((l) => l.rms).sort((a, b) => a - b);
|
|
10379
|
+
const extra = [...new Set(toks.flatMap((t) => Object.keys(t).filter((k) => !STD_TOKEN_KEYS.has(k))))];
|
|
10380
|
+
this.diag("stt_final", {
|
|
10381
|
+
text: text.slice(0, 80),
|
|
10382
|
+
endpoint,
|
|
10383
|
+
lastWordAgoMs,
|
|
10384
|
+
...conf.length ? { confMin: +Math.min(...conf).toFixed(3), confAvg: +(conf.reduce((a, b) => a + b, 0) / conf.length).toFixed(3) } : {},
|
|
10385
|
+
...rms.length ? { rmsPeak: Math.round(rms[rms.length - 1]), rmsMed: Math.round(rms[rms.length >> 1]) } : {},
|
|
10386
|
+
...toks.length ? { startMs: toks[0].start_ms, endMs: toks[toks.length - 1].end_ms } : {},
|
|
10387
|
+
...extra.length ? { tokenKeys: extra } : {}
|
|
10388
|
+
});
|
|
10389
|
+
return conf.length ? Math.min(...conf) : void 0;
|
|
10390
|
+
}
|
|
10284
10391
|
reset() {
|
|
10392
|
+
this.uttToks = [];
|
|
10393
|
+
this.uttPartials = [];
|
|
10285
10394
|
this.finalToks = [];
|
|
10286
10395
|
this.partialToks = [];
|
|
10287
10396
|
this.finalLangChars = {};
|
|
@@ -10384,7 +10493,7 @@ var now2 = () => performance.now();
|
|
|
10384
10493
|
var CartesiaTTSOptions = class {
|
|
10385
10494
|
auth = "";
|
|
10386
10495
|
voiceId = "";
|
|
10387
|
-
model = "sonic-3.
|
|
10496
|
+
model = "sonic-3.6";
|
|
10388
10497
|
/** 'apiKey' (server/CLI) → `api_key=` URL param; 'token' (browser, BE-minted) → `access_token=`. */
|
|
10389
10498
|
authMode = "apiKey";
|
|
10390
10499
|
/** Cartesia `language` code ('en', 'he', …). Unset → field omitted (provider default). Mutable:
|
|
@@ -10486,6 +10595,16 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10486
10595
|
};
|
|
10487
10596
|
this.ws.onmessage = (ev) => {
|
|
10488
10597
|
const m = JSON.parse(String(ev.data));
|
|
10598
|
+
const pr = m.context_id && this.priming.get(m.context_id);
|
|
10599
|
+
if (pr) {
|
|
10600
|
+
if (m.type === "chunk" && m.data) pr.chunks.push(base64ToBytes(m.data));
|
|
10601
|
+
else if (m.type === "done" || m.type === "error") {
|
|
10602
|
+
this.priming.delete(m.context_id);
|
|
10603
|
+
if (m.type === "done") this.primed.set(pr.key, pr.chunks);
|
|
10604
|
+
else this.primed.delete(pr.key);
|
|
10605
|
+
}
|
|
10606
|
+
return;
|
|
10607
|
+
}
|
|
10489
10608
|
if (m.context_id && m.context_id !== this.ctxId) return;
|
|
10490
10609
|
if (m.type === "chunk" && m.data) {
|
|
10491
10610
|
this.consecutiveErrors = 0;
|
|
@@ -10543,7 +10662,40 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10543
10662
|
this.newContext();
|
|
10544
10663
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame("Ok.", false));
|
|
10545
10664
|
}
|
|
10665
|
+
/** Phrases synthesized ahead (prime): key → audio (null = still generating). */
|
|
10666
|
+
primed = /* @__PURE__ */ new Map();
|
|
10667
|
+
priming = /* @__PURE__ */ new Map();
|
|
10668
|
+
/** This context began with a primed phrase: its audio played from the cache; more text is synthesized after it. */
|
|
10669
|
+
ctxCached = false;
|
|
10670
|
+
ctxRest = "";
|
|
10671
|
+
ctxSent = false;
|
|
10672
|
+
static key(t) {
|
|
10673
|
+
return t.trim().replace(/[\s.,!?…]+$/u, "").replace(/\s+/g, " ");
|
|
10674
|
+
}
|
|
10675
|
+
/** Synthesize `text` now, in this voice and language, and keep its audio: a later utterance that is exactly this text
|
|
10676
|
+
* plays at once, with no TTS round trip (a call's planned opener — live: ~470ms to its first audio). */
|
|
10677
|
+
prime(text) {
|
|
10678
|
+
const key = _CartesiaTTS.key(text);
|
|
10679
|
+
if (!key || this.primed.has(key) || this.down) return;
|
|
10680
|
+
this.primed.set(key, null);
|
|
10681
|
+
const id = `prime-${++this.ctxSeq}`;
|
|
10682
|
+
const send = () => {
|
|
10683
|
+
const cur = this.ctxId, lang = this.ctxLanguage;
|
|
10684
|
+
this.ctxId = id;
|
|
10685
|
+
this.ctxLanguage = this.options.language;
|
|
10686
|
+
const f = this.frame(text, false);
|
|
10687
|
+
this.ctxId = cur;
|
|
10688
|
+
this.ctxLanguage = lang;
|
|
10689
|
+
this.priming.set(id, { key, chunks: [] });
|
|
10690
|
+
this.ws.send(f);
|
|
10691
|
+
};
|
|
10692
|
+
if (this.ws?.readyState === WebSocket.OPEN) send();
|
|
10693
|
+
else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && send());
|
|
10694
|
+
}
|
|
10546
10695
|
newContext() {
|
|
10696
|
+
this.ctxCached = false;
|
|
10697
|
+
this.ctxRest = "";
|
|
10698
|
+
this.ctxSent = false;
|
|
10547
10699
|
this.ctxId = `ctx-${++this.ctxSeq}`;
|
|
10548
10700
|
this.firstAudioAt = 0;
|
|
10549
10701
|
this.ctxLanguage = this.options.language;
|
|
@@ -10569,6 +10721,19 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10569
10721
|
if (this.down) return;
|
|
10570
10722
|
text = cont ? this.say.feed(text) : this.say.feed(text) + this.say.flush();
|
|
10571
10723
|
if (cont && !text) return;
|
|
10724
|
+
const hit = !this.firstAudioAt && !this.ctxCached && this.primed.get(_CartesiaTTS.key(text));
|
|
10725
|
+
if (hit) {
|
|
10726
|
+
this.ctxCached = true;
|
|
10727
|
+
this.firstAudioAt = now2();
|
|
10728
|
+
this.diag("tts_primed", { chars: text.length });
|
|
10729
|
+
for (const c of hit) this.onAudio(c);
|
|
10730
|
+
return;
|
|
10731
|
+
}
|
|
10732
|
+
if (this.ctxCached) {
|
|
10733
|
+
this.ctxRest += text;
|
|
10734
|
+
return;
|
|
10735
|
+
}
|
|
10736
|
+
this.ctxSent = true;
|
|
10572
10737
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(text, cont));
|
|
10573
10738
|
else void this.ensureConnected().then(() => this.ws?.readyState === WebSocket.OPEN && this.ws.send(this.frame(text, cont)));
|
|
10574
10739
|
}
|
|
@@ -10582,11 +10747,27 @@ var CartesiaTTS = class _CartesiaTTS {
|
|
|
10582
10747
|
this.ws.send(JSON.stringify({ ...JSON.parse(this.frame("", true)), flush: true }));
|
|
10583
10748
|
}
|
|
10584
10749
|
end() {
|
|
10585
|
-
|
|
10750
|
+
let held = this.say.flush();
|
|
10586
10751
|
if (this.down) {
|
|
10587
10752
|
this.onDone();
|
|
10588
10753
|
return;
|
|
10589
10754
|
}
|
|
10755
|
+
const hit = !this.ctxSent && !this.ctxCached && !this.firstAudioAt && this.primed.get(_CartesiaTTS.key(held));
|
|
10756
|
+
if (hit) {
|
|
10757
|
+
this.diag("tts_primed", { chars: held.length });
|
|
10758
|
+
this.firstAudioAt = now2();
|
|
10759
|
+
for (const c of hit) this.onAudio(c);
|
|
10760
|
+
queueMicrotask(() => this.onDone());
|
|
10761
|
+
return;
|
|
10762
|
+
}
|
|
10763
|
+
if (this.ctxCached) {
|
|
10764
|
+
held = (this.ctxRest + held).trim();
|
|
10765
|
+
this.ctxRest = "";
|
|
10766
|
+
if (!held) {
|
|
10767
|
+
queueMicrotask(() => this.onDone());
|
|
10768
|
+
return;
|
|
10769
|
+
}
|
|
10770
|
+
}
|
|
10590
10771
|
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(this.frame(held, false));
|
|
10591
10772
|
}
|
|
10592
10773
|
cancel() {
|
|
@@ -10688,8 +10869,6 @@ var REACT = /^(?:(?:oh|and|so|wait|but|ok|okay|yeah)\s+)*(?:wow|whoa|woah|really
|
|
|
10688
10869
|
var WH_LEAD = "^(?:(?:oh|and|so|wait|but|ok|okay|um|uh|sorry)\\s+)*";
|
|
10689
10870
|
var WH_QUESTION = new RegExp(WH_LEAD + "(?:who|whom|whose|where|which|why|how|when|what|\u05DE\u05D9|\u05D0\u05D9\u05E4\u05D4|\u05DC\u05DE\u05D4|\u05D0\u05D9\u05DA|\u05DE\u05EA\u05D9|\u05DE\u05D4)\\s+\\S", "u");
|
|
10690
10871
|
var WH_EXCLAIM = new RegExp(WH_LEAD + "(?:what an? |how (?:cool|nice|fun|sweet|sad|funny|weird|crazy|strange|interesting|beautiful|lovely|cute|amazing|awesome)\\b)", "u");
|
|
10691
|
-
var BARE = /* @__PURE__ */ new Set(["yeah", "yea", "yes", "yep", "yup", "ok", "okay", "k", "right", "sure", "mm", "mmm", "hmm", "mhm", "mm-hm", "mm-hmm", "uh-huh", "um", "uh", "ah", "oh"]);
|
|
10692
|
-
var isBareCue = (text) => BARE.has(norm2(text).replace(/^-+|-+$/g, ""));
|
|
10693
10872
|
var isReaction = (text) => {
|
|
10694
10873
|
const t = norm2(text);
|
|
10695
10874
|
return REACT.test(t) || new RegExp("\\s\\p{L}{1,3}$", "u").test(t) && REACT.test(t.replace(new RegExp("\\s\\p{L}{1,3}$", "u"), ""));
|
|
@@ -11935,7 +12114,7 @@ ${nowLine()}. Anchor every relative or time-sensitive reference \u2014 "today",
|
|
|
11935
12114
|
* no other MCP server — the reflex only talks and routes; real work still goes through Act and its policy. */
|
|
11936
12115
|
claudeCodeReflex() {
|
|
11937
12116
|
const o = this.options;
|
|
11938
|
-
if (!o.reflexModel
|
|
12117
|
+
if (!isClaudeCode(o.reflexModel)) return {};
|
|
11939
12118
|
const po = o.providerOptionsFor?.(o.reflexModel) ?? {};
|
|
11940
12119
|
return {
|
|
11941
12120
|
ccBridge: "all",
|
|
@@ -15653,10 +15832,6 @@ var VoiceCall = class {
|
|
|
15653
15832
|
this.barge();
|
|
15654
15833
|
return "cut";
|
|
15655
15834
|
}
|
|
15656
|
-
if (isBareCue(text)) {
|
|
15657
|
-
this.o.onMetric({ name: "drop", kind: "bare cue", text });
|
|
15658
|
-
return "keep";
|
|
15659
|
-
}
|
|
15660
15835
|
if (this.o.mode === "live" && isReaction(text)) return this.kept(text), "keep";
|
|
15661
15836
|
const d = await this.judge.judge(text);
|
|
15662
15837
|
if (d.verdict === "cut") this.barge();
|
|
@@ -15701,7 +15876,7 @@ var VoiceCall = class {
|
|
|
15701
15876
|
* fill line: never MAIN history. */
|
|
15702
15877
|
aside(text) {
|
|
15703
15878
|
const now3 = this.o.now();
|
|
15704
|
-
if (
|
|
15879
|
+
if (now3 - this.lastAside.at < this.o.asideGapMs) return null;
|
|
15705
15880
|
const line = overlapAside(text, this.lang, this.lastAside.text, void 0, this.o.mode === "live");
|
|
15706
15881
|
if (!line) return null;
|
|
15707
15882
|
this.lastAside = { text: line, at: now3 };
|
|
@@ -15740,10 +15915,7 @@ var VoiceCall = class {
|
|
|
15740
15915
|
onTurn(t) {
|
|
15741
15916
|
this.floor = "";
|
|
15742
15917
|
this.flushKept(t.text);
|
|
15743
|
-
if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text))
|
|
15744
|
-
if (isBareCue(t.text)) return void this.o.onMetric({ name: "drop", id: t.id, kind: "bare cue", text: t.text });
|
|
15745
|
-
return void this.overWork(this.cur, t);
|
|
15746
|
-
}
|
|
15918
|
+
if (this.o.noteTurn && this.o.workReply && t.kind !== "replace" && this.working && !isClosing(t.text)) return void this.overWork(this.cur, t);
|
|
15747
15919
|
const prev = this.cur, quick = this.quickOn && !this.working && (t.kind === "new" || prev?.lane !== "deep");
|
|
15748
15920
|
const now3 = this.o.now(), lastWord = this.lastWordAt !== null;
|
|
15749
15921
|
const at = this.lastWordAt ?? this.firstFinalAt ?? now3;
|