@livx.cc/agentx 0.99.144 → 0.99.146
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/README.md +2 -2
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +660 -213
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +392 -62
- package/dist/index.js.map +1 -1
- package/dist/{secondChannel--Iv3ZQ69.d.ts → secondChannel-CJ1eYZKA.d.ts} +119 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10127,7 +10127,17 @@ function fitsLanguage(line, lang) {
|
|
|
10127
10127
|
}
|
|
10128
10128
|
var norm3 = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}' ]/gu, "").replace(/\s+/g, " ").trim();
|
|
10129
10129
|
function cleanLine(s, lang, maxWords = 6) {
|
|
10130
|
-
|
|
10130
|
+
if (/^(?:gasp|quiet|laughter)[.!?…]*$/i.test(s.trim())) return "";
|
|
10131
|
+
const first = s.trim().split("\n")[0];
|
|
10132
|
+
const tags = [...first.matchAll(LINE_TAG)].map((m) => `[${m[1].toLowerCase()}]`).filter((t, i, a) => a.indexOf(t) === i).join(" ");
|
|
10133
|
+
const raw = first.replace(LINE_TAG, " ").trim();
|
|
10134
|
+
if (tags && !/[\p{L}\p{N}]/u.test(raw)) return /laughter|gasp/.test(tags) ? tags : "";
|
|
10135
|
+
const words3 = cleanWords(raw, lang, maxWords);
|
|
10136
|
+
return words3 && tags ? `${tags} ${words3}` : words3;
|
|
10137
|
+
}
|
|
10138
|
+
var LINE_TAG = /\[(laughter|gasp|quiet)\]/gi;
|
|
10139
|
+
var lineWords = (line) => line.replace(LINE_TAG, " ").trim();
|
|
10140
|
+
function cleanWords(raw, lang, maxWords) {
|
|
10131
10141
|
const l = raw.replace(/^[-*•\d.)\s]+/, "").replace(/^["'“”«»]+|["'“”«»]+$/g, "").replace(new RegExp("^\\p{L}+:\\s*", "u"), "").trim();
|
|
10132
10142
|
if (!l || isLeakSuspect(raw) || isLeakSuspect(l)) {
|
|
10133
10143
|
if (l) log24.debug(`line "${raw}" reads as meta \u2014 rejected`);
|
|
@@ -12930,7 +12940,137 @@ init_models();
|
|
|
12930
12940
|
|
|
12931
12941
|
// src/voice/progress.ts
|
|
12932
12942
|
init_logging();
|
|
12933
|
-
|
|
12943
|
+
|
|
12944
|
+
// src/voice/convoTree.ts
|
|
12945
|
+
init_logging();
|
|
12946
|
+
|
|
12947
|
+
// src/voice/backchannelPlan.ts
|
|
12948
|
+
init_logging();
|
|
12949
|
+
var log27 = forComponent("BackchannelPlan");
|
|
12950
|
+
var silentTurn = (p) => p.density === "none" || p.turn === "short_command" || p.turn === "question";
|
|
12951
|
+
var cueWords = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}'\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
12952
|
+
function matchCue(plan, heard, from = 0) {
|
|
12953
|
+
if (!plan || silentTurn(plan)) return null;
|
|
12954
|
+
const w = cueWords(heard);
|
|
12955
|
+
for (let i = Math.max(0, from); i < w.length; i++) {
|
|
12956
|
+
for (const c of plan.cues) {
|
|
12957
|
+
for (const p of c.when) {
|
|
12958
|
+
const pw = p.split(" ");
|
|
12959
|
+
if (i + pw.length <= w.length && pw.every((x, j) => w[i + j] === x)) return c;
|
|
12960
|
+
}
|
|
12961
|
+
}
|
|
12962
|
+
}
|
|
12963
|
+
return null;
|
|
12964
|
+
}
|
|
12965
|
+
|
|
12966
|
+
// src/voice/convoTree.ts
|
|
12967
|
+
var log28 = forComponent("ConvoTree");
|
|
12968
|
+
var SOFT_CUE = "~";
|
|
12969
|
+
var STOP4 = new Set("about after again also always been before being could does doing down even every from going have here into just know like look make many more most much must never only other over really right same should some still such sure take than that their them then there these they thing think this those through very want well were what when where which while will with would your yeah okay".split(" "));
|
|
12970
|
+
var isContent = (w) => w.length >= 4 && !STOP4.has(w);
|
|
12971
|
+
function echoesHeard(line, heard) {
|
|
12972
|
+
const said = new Set(cueWords(heard));
|
|
12973
|
+
return cueWords(lineWords(line)).some((w) => isContent(w) && said.has(w));
|
|
12974
|
+
}
|
|
12975
|
+
var leafKey = (line) => cueWords(lineWords(line)).join(" ");
|
|
12976
|
+
var ConvoTreeOptions = class {
|
|
12977
|
+
/** A leaf plays at this confidence or above. */
|
|
12978
|
+
threshold = 0.5;
|
|
12979
|
+
/** How much more likely a cue of one word / of two or more is if its branch is the true one. */
|
|
12980
|
+
cueEvidence = 3;
|
|
12981
|
+
phraseEvidence = 8;
|
|
12982
|
+
/** A hit weakens each sibling by this factor. */
|
|
12983
|
+
siblingDecay = 0.5;
|
|
12984
|
+
/** A cue counts only within the newest N words: older ones have passed, a reaction to them would be late. */
|
|
12985
|
+
cueWindow = 4;
|
|
12986
|
+
};
|
|
12987
|
+
var namesHeard = (n, said) => (n.names ?? []).every((w) => said.has(w));
|
|
12988
|
+
function echoHeard(node, heard) {
|
|
12989
|
+
if (node.when[0] === SOFT_CUE) return true;
|
|
12990
|
+
const said = new Set(cueWords(heard));
|
|
12991
|
+
return node.when.flatMap((w) => w.split(" ")).some((w) => isContent(w) && said.has(w)) && namesHeard(node, said);
|
|
12992
|
+
}
|
|
12993
|
+
var ConvoTree = class {
|
|
12994
|
+
// a turn_end leaf waiting for the turn to end
|
|
12995
|
+
constructor(options) {
|
|
12996
|
+
this.options = options;
|
|
12997
|
+
this.options = { ...new ConvoTreeOptions(), ...options };
|
|
12998
|
+
}
|
|
12999
|
+
options;
|
|
13000
|
+
live = [];
|
|
13001
|
+
from = 0;
|
|
13002
|
+
// word index after the last hit
|
|
13003
|
+
armed = null;
|
|
13004
|
+
get o() {
|
|
13005
|
+
return this.options;
|
|
13006
|
+
}
|
|
13007
|
+
get nodes() {
|
|
13008
|
+
return this.live;
|
|
13009
|
+
}
|
|
13010
|
+
get empty() {
|
|
13011
|
+
return !this.live.length;
|
|
13012
|
+
}
|
|
13013
|
+
/** A fresh tree. `heardWords`: words already said this turn (a tree grown mid-turn matches only what comes next). */
|
|
13014
|
+
grow(nodes, heardWords = 0) {
|
|
13015
|
+
this.live = nodes.map((n) => ({ ...n }));
|
|
13016
|
+
this.armed = null;
|
|
13017
|
+
this.from = heardWords;
|
|
13018
|
+
}
|
|
13019
|
+
/** Posterior of a node after seeing its cue. */
|
|
13020
|
+
confidence(p, words3) {
|
|
13021
|
+
const l = p * (words3 > 1 ? this.o.phraseEvidence : this.o.cueEvidence);
|
|
13022
|
+
return l / (l + 1 - p);
|
|
13023
|
+
}
|
|
13024
|
+
/** The partial's newest evidence: the strongest new cue hit (its children open, its siblings fade), or null. A turn_end
|
|
13025
|
+
* hit is armed for endTurn; the caller plays the others. Hits under the threshold still sharpen the tree. */
|
|
13026
|
+
step(heard) {
|
|
13027
|
+
const w = cueWords(heard), said = new Set(w);
|
|
13028
|
+
let best = null;
|
|
13029
|
+
for (let i = Math.max(this.from, w.length - this.o.cueWindow); i < w.length; i++) {
|
|
13030
|
+
for (const node2 of this.live) for (const cue of node2.when) {
|
|
13031
|
+
const pw = cue.split(" ");
|
|
13032
|
+
if (!namesHeard(node2, said) || i + pw.length > w.length || !pw.every((x, j) => w[i + j] === x)) continue;
|
|
13033
|
+
const conf2 = this.confidence(node2.p, pw.length);
|
|
13034
|
+
if (!best || conf2 > best.conf) best = { node: node2, conf: conf2, end: i + pw.length };
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
if (!best) return null;
|
|
13038
|
+
const { node, conf } = best;
|
|
13039
|
+
this.from = best.end;
|
|
13040
|
+
this.take(node, conf);
|
|
13041
|
+
const hit = { node, conf };
|
|
13042
|
+
if ((node.moment === "turn_end" || node.moment === "ask") && conf >= (this.armed?.conf ?? 0)) {
|
|
13043
|
+
this.armed = hit;
|
|
13044
|
+
return null;
|
|
13045
|
+
}
|
|
13046
|
+
return conf >= this.o.threshold ? hit : null;
|
|
13047
|
+
}
|
|
13048
|
+
/** A node happened: it leaves the live set, its siblings fade, its children open. */
|
|
13049
|
+
take(node, conf) {
|
|
13050
|
+
this.live = [...this.live.filter((n) => n !== node).map((n) => ({ ...n, p: n.p * this.o.siblingDecay })), ...node.next.map((n) => ({ ...n, p: Math.min(1, n.p * Math.max(conf, 0.5) * 1.5) }))];
|
|
13051
|
+
}
|
|
13052
|
+
/** The turn ended: the armed leaf if it clears the threshold. The live set stays for a picker; `advance` clears it. */
|
|
13053
|
+
turnLeaf() {
|
|
13054
|
+
const a = this.armed;
|
|
13055
|
+
return a && a.conf >= this.o.threshold ? a : null;
|
|
13056
|
+
}
|
|
13057
|
+
/** A quick model named a node at the turn's end: its evidence counts as a phrase. Null when under the threshold. */
|
|
13058
|
+
picked(i, heard = "") {
|
|
13059
|
+
const node = this.live[i];
|
|
13060
|
+
if (!node || !echoHeard(node, heard)) return null;
|
|
13061
|
+
const conf = this.confidence(node.p, 2);
|
|
13062
|
+
return conf >= this.o.threshold ? { node, conf } : null;
|
|
13063
|
+
}
|
|
13064
|
+
/** Next turn: what followed a played/armed branch stays live until a fresh tree lands; the rest is gone. */
|
|
13065
|
+
advance() {
|
|
13066
|
+
this.live = this.live.filter((n) => n.p >= 0.05);
|
|
13067
|
+
this.armed = null;
|
|
13068
|
+
this.from = 0;
|
|
13069
|
+
}
|
|
13070
|
+
};
|
|
13071
|
+
|
|
13072
|
+
// src/voice/progress.ts
|
|
13073
|
+
var log29 = forComponent("Progress");
|
|
12934
13074
|
var HE_RESULT_CLAIM = /(?:^|\s)(?:מצאתי|סיימתי|בוצע|הנה|אין)(?=\s|$|[.,!…])/u;
|
|
12935
13075
|
var TOPICS = [
|
|
12936
13076
|
[/toolsearch|^mcp__.*__(list_commands|call_info)$/, null],
|
|
@@ -13054,8 +13194,8 @@ var Progress = class {
|
|
|
13054
13194
|
this.said.add(norm3(line));
|
|
13055
13195
|
this.lastAt = this.o.now();
|
|
13056
13196
|
}
|
|
13057
|
-
/** The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
|
|
13058
|
-
async line(tool, args, lang) {
|
|
13197
|
+
/** `about`: the user's request, for a generated line. The line for this tool call in `lang`, or '' (no template and no/late/invalid generation, a repeat, a result claim). */
|
|
13198
|
+
async line(tool, args, lang, about = "") {
|
|
13059
13199
|
if (this.streamed) return "";
|
|
13060
13200
|
const name = tool.toLowerCase();
|
|
13061
13201
|
const hit = TOPICS.find(([re]) => re.test(name));
|
|
@@ -13074,18 +13214,18 @@ var Progress = class {
|
|
|
13074
13214
|
r(null);
|
|
13075
13215
|
}, this.o.generateBudgetMs);
|
|
13076
13216
|
});
|
|
13077
|
-
const raw = await Promise.race([this.o.generate(tool, argsHint(args), lang, ac.signal).catch((e) => {
|
|
13078
|
-
|
|
13217
|
+
const raw = await Promise.race([this.o.generate(tool, [about.slice(-80), argsHint(args)].filter(Boolean).join("; "), lang, ac.signal).catch((e) => {
|
|
13218
|
+
log29.warn(`progress line failed: ${e?.message ?? e}`);
|
|
13079
13219
|
return null;
|
|
13080
13220
|
}), late]).finally(() => clearTimeout(t));
|
|
13081
13221
|
const l = cleanLine(raw ?? "", lang, 5);
|
|
13082
|
-
if (!l || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
|
|
13222
|
+
if (!l || about && !echoesHeard(l, `${about} ${argsHint(args)}`) || RESULT_CLAIM_RE.test(l) || HE_RESULT_CLAIM.test(l) || this.said.has(norm3(l)) || this.streamed) return "";
|
|
13083
13223
|
return l;
|
|
13084
13224
|
}
|
|
13085
13225
|
};
|
|
13086
13226
|
function fastProgressGenerator(ai, model, gender) {
|
|
13087
13227
|
return async (tool, hint, lang, signal) => {
|
|
13088
|
-
const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
|
|
13228
|
+
const prompt = `An assistant on a live voice call is running the tool "${tool}"${hint ? ` (about: "${hint}")` : ""}. Write ONE spoken line of 2-5 words, in ${languageName(lang)}, saying what it is doing right now (like "checking the board\u2026"). ${hint ? "Use the words of what it is about. " : ""}Never state a result or a finding. ${personaHint(gender)} Output only the line.`;
|
|
13089
13229
|
const reasoning = /gpt-oss/.test(model) ? { providerOptions: { reasoning_effort: "low" } } : {};
|
|
13090
13230
|
const r = await ai.chat({ model, messages: [{ role: "user", content: prompt }], stream: false, signal, maxTokens: 150, ...reasoning });
|
|
13091
13231
|
return r.content ?? "";
|
|
@@ -13094,28 +13234,7 @@ function fastProgressGenerator(ai, model, gender) {
|
|
|
13094
13234
|
|
|
13095
13235
|
// src/voice/secondChannel.ts
|
|
13096
13236
|
init_logging();
|
|
13097
|
-
|
|
13098
|
-
// src/voice/backchannelPlan.ts
|
|
13099
|
-
init_logging();
|
|
13100
|
-
var log28 = forComponent("BackchannelPlan");
|
|
13101
|
-
var silentTurn = (p) => p.density === "none" || p.turn === "short_command" || p.turn === "question";
|
|
13102
|
-
var cueWords = (s) => s.toLowerCase().replace(/[^\p{L}\p{N}'\s]+/gu, " ").split(/\s+/).filter(Boolean);
|
|
13103
|
-
function matchCue(plan, heard, from = 0) {
|
|
13104
|
-
if (!plan || silentTurn(plan)) return null;
|
|
13105
|
-
const w = cueWords(heard);
|
|
13106
|
-
for (let i = Math.max(0, from); i < w.length; i++) {
|
|
13107
|
-
for (const c of plan.cues) {
|
|
13108
|
-
for (const p of c.when) {
|
|
13109
|
-
const pw = p.split(" ");
|
|
13110
|
-
if (i + pw.length <= w.length && pw.every((x, j) => w[i + j] === x)) return c;
|
|
13111
|
-
}
|
|
13112
|
-
}
|
|
13113
|
-
}
|
|
13114
|
-
return null;
|
|
13115
|
-
}
|
|
13116
|
-
|
|
13117
|
-
// src/voice/secondChannel.ts
|
|
13118
|
-
var log29 = forComponent("SecondChannel");
|
|
13237
|
+
var log30 = forComponent("SecondChannel");
|
|
13119
13238
|
var CHANNEL_MODES = {
|
|
13120
13239
|
turn: { kinds: ["bridge"], bridgeDelayMs: 1500 },
|
|
13121
13240
|
normal: {},
|
|
@@ -13134,10 +13253,10 @@ var CHANNEL_MODES = {
|
|
|
13134
13253
|
maxPerWindow: 6
|
|
13135
13254
|
},
|
|
13136
13255
|
live: {
|
|
13137
|
-
kinds: ["backchannel"],
|
|
13256
|
+
kinds: ["backchannel", "bridge"],
|
|
13138
13257
|
anticipate: true,
|
|
13139
13258
|
cueOnly: false,
|
|
13140
|
-
generateFor: ["backchannel"],
|
|
13259
|
+
generateFor: ["backchannel", "bridge"],
|
|
13141
13260
|
reactionGapMs: 0,
|
|
13142
13261
|
generateBudgetMs: 400,
|
|
13143
13262
|
backchannelMinWords: 3,
|
|
@@ -13187,6 +13306,8 @@ var SecondChannelOptions = class {
|
|
|
13187
13306
|
decideEveryWords = 3;
|
|
13188
13307
|
decisionBudgetMs = 300;
|
|
13189
13308
|
generateBudgetMs = 500;
|
|
13309
|
+
/** `live`: how long the fast model may take on a bridge line; later = silence. */
|
|
13310
|
+
bridgeBudgetMs = 1200;
|
|
13190
13311
|
minGapMs = 2500;
|
|
13191
13312
|
/** Backchannel after backchannel needs this gap (~4-6 cues in a 30s monologue — Para phone call 2026-10-13: 5s left
|
|
13192
13313
|
* one cue in a long statement). */
|
|
@@ -13240,6 +13361,31 @@ var SecondChannelOptions = class {
|
|
|
13240
13361
|
cueOnly = true;
|
|
13241
13362
|
onPlan = () => {
|
|
13242
13363
|
};
|
|
13364
|
+
/** `live` only (convoTree.ts): grows the prediction tree after each reply. Once a tree is up it is the only source of
|
|
13365
|
+
* lines while the user talks: a leaf above its threshold, or silence. No tree yet / a failed one: the reactive path. */
|
|
13366
|
+
grow;
|
|
13367
|
+
/** The quick model at a turn's end with no cue hit: names a leaf or none, inside `pickBudgetMs`. */
|
|
13368
|
+
pickLeaf;
|
|
13369
|
+
pickBudgetMs = 700;
|
|
13370
|
+
growBudgetMs = 15e3;
|
|
13371
|
+
tree = {};
|
|
13372
|
+
/** The tree grower's persona (who is speaking). */
|
|
13373
|
+
persona = "";
|
|
13374
|
+
/** Lines of talk the grower sees. */
|
|
13375
|
+
talkLines = 8;
|
|
13376
|
+
/** Mid-turn: at this many words the tree regrows once from what they are saying now. */
|
|
13377
|
+
regrowAtWords = 6;
|
|
13378
|
+
/** A leaf is dropped once the talk moved this many words past its cue. */
|
|
13379
|
+
leafStaleWords = 3;
|
|
13380
|
+
/** Interims stop this long: the quick model may pick a leaf (shorter than the ~400ms word cadence, so most gaps count; leafGated spaces the calls). */
|
|
13381
|
+
leafBreathMs = 200;
|
|
13382
|
+
/** Played leaves the grower must avoid, and how many lines pass before a tag may play again. */
|
|
13383
|
+
leafMemory = 16;
|
|
13384
|
+
tagEvery = 4;
|
|
13385
|
+
onTree = () => {
|
|
13386
|
+
};
|
|
13387
|
+
onLeaf = () => {
|
|
13388
|
+
};
|
|
13243
13389
|
now = () => performance.now();
|
|
13244
13390
|
random = Math.random;
|
|
13245
13391
|
};
|
|
@@ -13248,15 +13394,15 @@ function withBudget(p, ms, what, ac) {
|
|
|
13248
13394
|
let t;
|
|
13249
13395
|
const late = new Promise((r) => {
|
|
13250
13396
|
t = setTimeout(() => {
|
|
13251
|
-
|
|
13397
|
+
log30.debug(`${what}: over the ${ms}ms budget \u2014 dropped`);
|
|
13252
13398
|
ac?.abort();
|
|
13253
13399
|
r(null);
|
|
13254
13400
|
}, ms);
|
|
13255
13401
|
});
|
|
13256
13402
|
return Promise.race([p.catch((e) => {
|
|
13257
13403
|
const msg = String(e?.message ?? e);
|
|
13258
|
-
if (e?.name === "AbortError" || /aborted/i.test(msg))
|
|
13259
|
-
else
|
|
13404
|
+
if (e?.name === "AbortError" || /aborted/i.test(msg)) log30.debug(`${what}: aborted after its budget`);
|
|
13405
|
+
else log30.warn(`${what} failed \u2014 falling back: ${msg}`);
|
|
13260
13406
|
return null;
|
|
13261
13407
|
}), late]).finally(() => clearTimeout(t));
|
|
13262
13408
|
}
|
|
@@ -13269,6 +13415,7 @@ var SecondChannel = class {
|
|
|
13269
13415
|
for (const k of Object.keys(preset)) if (!options || !(k in options)) this.normalTiming[k] = base[k];
|
|
13270
13416
|
this.startedAt = this.o.now();
|
|
13271
13417
|
if (this.o.lang) this.setLanguage(this.o.lang, true);
|
|
13418
|
+
if (this.o.mode === "live" && this.o.grow) this.tree = new ConvoTree(this.o.tree);
|
|
13272
13419
|
}
|
|
13273
13420
|
options;
|
|
13274
13421
|
heard = "";
|
|
@@ -13297,6 +13444,12 @@ var SecondChannel = class {
|
|
|
13297
13444
|
// one bridge per main turn
|
|
13298
13445
|
bridgeDraft = null;
|
|
13299
13446
|
// a bridge generated ahead, used only if ready in time
|
|
13447
|
+
bridgeReady = Promise.resolve();
|
|
13448
|
+
// live: that draft settled
|
|
13449
|
+
askLeaf = null;
|
|
13450
|
+
// live: this turn's ask leaf
|
|
13451
|
+
leafReady = Promise.resolve();
|
|
13452
|
+
// live: the turn-end leaf pick settled
|
|
13300
13453
|
recent = [];
|
|
13301
13454
|
picks = /* @__PURE__ */ new Map();
|
|
13302
13455
|
inflight = null;
|
|
@@ -13324,6 +13477,21 @@ var SecondChannel = class {
|
|
|
13324
13477
|
normalTiming = {};
|
|
13325
13478
|
// chatty without aec: the preset's keys back at their defaults
|
|
13326
13479
|
degradedLogged = false;
|
|
13480
|
+
tree = null;
|
|
13481
|
+
// live with a grower only
|
|
13482
|
+
growing = false;
|
|
13483
|
+
growTries = 0;
|
|
13484
|
+
// per turn
|
|
13485
|
+
replyGrown = false;
|
|
13486
|
+
// one tree per reply (idle comes more than once)
|
|
13487
|
+
talk = [];
|
|
13488
|
+
leaves = [];
|
|
13489
|
+
// leaves played this call
|
|
13490
|
+
sinceTag = Infinity;
|
|
13491
|
+
regrown = false;
|
|
13492
|
+
picking = false;
|
|
13493
|
+
breathTimer = null;
|
|
13494
|
+
leafTimer = null;
|
|
13327
13495
|
/** The language lines are spoken in (detected from the user's words, or set by the host). */
|
|
13328
13496
|
get language() {
|
|
13329
13497
|
return this.lang;
|
|
@@ -13335,7 +13503,7 @@ var SecondChannel = class {
|
|
|
13335
13503
|
if (host) this.pinned = true;
|
|
13336
13504
|
const lang = primaryLang(tag);
|
|
13337
13505
|
if (!lang || lang === this.lang) return;
|
|
13338
|
-
|
|
13506
|
+
log30.debug(`language ${this.lang} \u2192 ${lang}`);
|
|
13339
13507
|
this.lang = lang;
|
|
13340
13508
|
this.recent = [];
|
|
13341
13509
|
this.picks.clear();
|
|
@@ -13348,6 +13516,10 @@ var SecondChannel = class {
|
|
|
13348
13516
|
const l = detectLanguage(text, !!this.lang);
|
|
13349
13517
|
if (l) this.setLanguage(l);
|
|
13350
13518
|
}
|
|
13519
|
+
/** `live` speaks no stock bridge/filler, with or without aec. */
|
|
13520
|
+
get ownWords() {
|
|
13521
|
+
return this.options.mode === "live";
|
|
13522
|
+
}
|
|
13351
13523
|
get bank() {
|
|
13352
13524
|
return this.lang ? this.o.banks ? this.o.banks.get(this.lang) : this.lang === "en" ? EN_BANK : null : null;
|
|
13353
13525
|
}
|
|
@@ -13371,7 +13543,23 @@ var SecondChannel = class {
|
|
|
13371
13543
|
this.onPause(this.o.fillerPauseMs);
|
|
13372
13544
|
}, this.o.fillerPauseMs);
|
|
13373
13545
|
let cue = null;
|
|
13374
|
-
if (this.
|
|
13546
|
+
if (this.tree) {
|
|
13547
|
+
if (this.tree.empty && !this.growing && this.growTries < 2) this.requestTree();
|
|
13548
|
+
if (!this.tree.empty) {
|
|
13549
|
+
this.treeStep(t);
|
|
13550
|
+
if (!this.regrown && words2(t).length >= this.o.regrowAtWords) {
|
|
13551
|
+
this.regrown = true;
|
|
13552
|
+
this.requestTree(t);
|
|
13553
|
+
}
|
|
13554
|
+
this.armBreath(t);
|
|
13555
|
+
if (this.bcTimer) {
|
|
13556
|
+
clearTimeout(this.bcTimer);
|
|
13557
|
+
this.bcTimer = null;
|
|
13558
|
+
}
|
|
13559
|
+
return;
|
|
13560
|
+
}
|
|
13561
|
+
}
|
|
13562
|
+
if (this.o.anticipate && !this.tree) {
|
|
13375
13563
|
const n = words2(t).length;
|
|
13376
13564
|
if (!this.plan && !this.planning && this.planTries < 2) this.requestPlan();
|
|
13377
13565
|
else if (this.plan && !this.revised && n >= this.o.reviseAtWords) {
|
|
@@ -13416,11 +13604,24 @@ var SecondChannel = class {
|
|
|
13416
13604
|
this.decidedAt = 0;
|
|
13417
13605
|
this.bridged = false;
|
|
13418
13606
|
this.cueFrom = 0;
|
|
13419
|
-
if (this.
|
|
13607
|
+
if (this.tree) {
|
|
13608
|
+
if (this.reply.trim() && !this.replyGrown) {
|
|
13609
|
+
this.replyGrown = true;
|
|
13610
|
+
this.noteTalk("you", this.reply);
|
|
13611
|
+
this.requestTree();
|
|
13612
|
+
}
|
|
13613
|
+
} else if (this.o.anticipate && this.reply.trim() && !this.plan && !this.planning) this.requestPlan();
|
|
13420
13614
|
return;
|
|
13421
13615
|
}
|
|
13422
13616
|
if (s === "queued") {
|
|
13423
13617
|
this.turnNo++;
|
|
13618
|
+
this.growTries = 0;
|
|
13619
|
+
this.replyGrown = false;
|
|
13620
|
+
this.regrown = false;
|
|
13621
|
+
if (this.breathTimer) {
|
|
13622
|
+
clearTimeout(this.breathTimer);
|
|
13623
|
+
this.breathTimer = null;
|
|
13624
|
+
}
|
|
13424
13625
|
this.plan = null;
|
|
13425
13626
|
this.planning = false;
|
|
13426
13627
|
this.planTries = 0;
|
|
@@ -13434,7 +13635,7 @@ var SecondChannel = class {
|
|
|
13434
13635
|
if (this[k]) clearTimeout(this[k]);
|
|
13435
13636
|
this[k] = null;
|
|
13436
13637
|
}
|
|
13437
|
-
if (this.o.instantBridge) this.prefetchBridge();
|
|
13638
|
+
if (this.o.instantBridge || this.ownWords) this.prefetchBridge();
|
|
13438
13639
|
const wait = Math.max(this.o.bridgeDelayMs, this.o.minGapMs - (this.o.now() - this.lastAt));
|
|
13439
13640
|
if (wait > 0) this.bridgeTimer = setTimeout(() => {
|
|
13440
13641
|
this.bridgeTimer = null;
|
|
@@ -13461,6 +13662,10 @@ var SecondChannel = class {
|
|
|
13461
13662
|
this.detect(this.heard);
|
|
13462
13663
|
this.main = "idle";
|
|
13463
13664
|
this.onAgentState("queued");
|
|
13665
|
+
if (this.tree) {
|
|
13666
|
+
this.noteTalk("them", this.heard);
|
|
13667
|
+
this.leafReady = this.turnEndLeaf();
|
|
13668
|
+
}
|
|
13464
13669
|
}
|
|
13465
13670
|
/** The main answer's streamed text (before its audio): channel-1 is responding — no bridge from here on. */
|
|
13466
13671
|
onMainTokens(text) {
|
|
@@ -13480,7 +13685,7 @@ var SecondChannel = class {
|
|
|
13480
13685
|
try {
|
|
13481
13686
|
this.o.cancel();
|
|
13482
13687
|
} catch (e) {
|
|
13483
|
-
|
|
13688
|
+
log30.warn(`cancel threw: ${e.message}`);
|
|
13484
13689
|
}
|
|
13485
13690
|
}
|
|
13486
13691
|
}
|
|
@@ -13491,6 +13696,10 @@ var SecondChannel = class {
|
|
|
13491
13696
|
this.cutLine = null;
|
|
13492
13697
|
return !!c && c === text.trim();
|
|
13493
13698
|
}
|
|
13699
|
+
/** Another fill line (progress) already covers this turn's wait: no bridge after it. */
|
|
13700
|
+
covered() {
|
|
13701
|
+
this.bridged = true;
|
|
13702
|
+
}
|
|
13494
13703
|
/** Resolves when the in-flight line finished playing (immediately when none) — hosts enqueue channel-1 audio behind it. */
|
|
13495
13704
|
drain() {
|
|
13496
13705
|
return this.inflight ?? Promise.resolve();
|
|
@@ -13570,6 +13779,106 @@ var SecondChannel = class {
|
|
|
13570
13779
|
this.o.onPlan(p, !!heard, Math.round(this.o.now() - t0));
|
|
13571
13780
|
});
|
|
13572
13781
|
}
|
|
13782
|
+
noteTalk(who, text) {
|
|
13783
|
+
this.talk = [...this.talk, `${who}: ${text.trim().slice(-300)}`].slice(-this.o.talkLines);
|
|
13784
|
+
}
|
|
13785
|
+
/** Grow the tree off the hot path. A tree that lands after its turn is still the best guess: it replaces what is live. */
|
|
13786
|
+
requestTree(heard) {
|
|
13787
|
+
if (!this.tree || !this.o.grow || !this.lang || this.growing) return;
|
|
13788
|
+
this.growing = true;
|
|
13789
|
+
this.growTries++;
|
|
13790
|
+
const t0 = this.o.now(), ac = new AbortController(), tree = this.tree;
|
|
13791
|
+
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 } : {} };
|
|
13792
|
+
const late = setTimeout(() => ac.abort(), this.o.growBudgetMs);
|
|
13793
|
+
void this.o.grow(ctx, ac.signal).then((r) => {
|
|
13794
|
+
if (r.nodes.length) tree.grow(r.nodes, this.userSpeaking ? words2(this.heard).length : 0);
|
|
13795
|
+
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 } : {} });
|
|
13796
|
+
}, (e) => {
|
|
13797
|
+
log30.warn(`tree failed: ${e?.message ?? e}`);
|
|
13798
|
+
this.o.onTree({ ms: Math.round(this.o.now() - t0), branches: 0, error: String(e?.message ?? e) });
|
|
13799
|
+
}).finally(() => {
|
|
13800
|
+
clearTimeout(late);
|
|
13801
|
+
this.growing = false;
|
|
13802
|
+
});
|
|
13803
|
+
}
|
|
13804
|
+
/** Text match on the partial (no model). barge_in plays now, in_between at the next breath; turn_end waits in the tree. */
|
|
13805
|
+
treeStep(t) {
|
|
13806
|
+
const hit = this.tree.step(t);
|
|
13807
|
+
if (!hit) return;
|
|
13808
|
+
if (hit.node.moment === "barge_in") return this.playLeaf(hit, "interim", "backchannel");
|
|
13809
|
+
if (this.leafTimer) clearTimeout(this.leafTimer);
|
|
13810
|
+
const at = words2(t).length;
|
|
13811
|
+
this.leafTimer = setTimeout(() => {
|
|
13812
|
+
this.leafTimer = null;
|
|
13813
|
+
if (this.userSpeaking && words2(this.heard).length - at < this.o.leafStaleWords) this.playLeaf(hit, "interim", "backchannel");
|
|
13814
|
+
}, this.o.cuePauseMs);
|
|
13815
|
+
}
|
|
13816
|
+
/** A breath with no cue hit: the quick model may name the leaf that fits the words just said. Its answer plays only if
|
|
13817
|
+
* they have not moved on. */
|
|
13818
|
+
armBreath(t) {
|
|
13819
|
+
if (this.breathTimer) clearTimeout(this.breathTimer);
|
|
13820
|
+
if (!this.o.pickLeaf || !this.o.aec) return;
|
|
13821
|
+
this.breathTimer = setTimeout(() => {
|
|
13822
|
+
this.breathTimer = null;
|
|
13823
|
+
const n = words2(t).length, tree = this.tree;
|
|
13824
|
+
if (n < this.o.backchannelMinWords || this.heard !== t || this.leafTimer || this.picking || tree.empty || this.leafGated()) return;
|
|
13825
|
+
this.picking = true;
|
|
13826
|
+
const ac = new AbortController(), nodes = tree.nodes.filter((x) => x.moment !== "ask"), lines = nodes.map((x, i) => ({ i, line: x.line, when: x.when }));
|
|
13827
|
+
void withBudget(this.o.pickLeaf(t, lines, ac.signal), this.o.pickBudgetMs, "breath pick", ac).then((i) => {
|
|
13828
|
+
this.picking = false;
|
|
13829
|
+
const node = typeof i === "number" ? nodes[i] : void 0, hit = node && tree.nodes.includes(node) ? tree.picked(tree.nodes.indexOf(node), this.heard) : null;
|
|
13830
|
+
if (!hit || !this.userSpeaking || words2(this.heard).length - n >= this.o.leafStaleWords) return;
|
|
13831
|
+
tree.take(hit.node, hit.conf);
|
|
13832
|
+
this.playLeaf(hit, "interim", "backchannel");
|
|
13833
|
+
});
|
|
13834
|
+
}, this.o.leafBreathMs);
|
|
13835
|
+
}
|
|
13836
|
+
/** The user's turn went to MAIN: the armed leaf at once, else the quick model may name one in time. It plays only while
|
|
13837
|
+
* MAIN is still silent, as the turn's first sound. */
|
|
13838
|
+
async turnEndLeaf() {
|
|
13839
|
+
const tree = this.tree, gen = this.gen, heard = this.heard;
|
|
13840
|
+
let hit = tree.turnLeaf();
|
|
13841
|
+
if (!hit && this.o.pickLeaf && !tree.empty) {
|
|
13842
|
+
const ac = new AbortController(), lines = tree.nodes.map((n, i2) => ({ i: i2, line: n.line, when: n.when }));
|
|
13843
|
+
const i = await withBudget(this.o.pickLeaf(heard, lines, ac.signal), this.o.pickBudgetMs, "leaf pick", ac);
|
|
13844
|
+
if (typeof i === "number" && i >= 0) hit = tree.picked(i, heard);
|
|
13845
|
+
}
|
|
13846
|
+
tree.advance();
|
|
13847
|
+
if (hit?.node.moment === "ask") {
|
|
13848
|
+
if (gen === this.gen && echoesHeard(hit.node.line, heard)) this.askLeaf = { gen, text: hit.node.line };
|
|
13849
|
+
return;
|
|
13850
|
+
}
|
|
13851
|
+
if (hit && gen === this.gen && (this.main === "queued" || this.main === "thinking")) {
|
|
13852
|
+
this.playLeaf(hit, "working", "bridge");
|
|
13853
|
+
if (this.lastKind === "bridge" && this.bridged) {
|
|
13854
|
+
this.bridged = false;
|
|
13855
|
+
this.lastKind = null;
|
|
13856
|
+
if (this.bridgeTimer) clearTimeout(this.bridgeTimer);
|
|
13857
|
+
this.bridgeTimer = setTimeout(() => {
|
|
13858
|
+
this.bridgeTimer = null;
|
|
13859
|
+
void this.consider("working");
|
|
13860
|
+
}, this.o.minGapMs);
|
|
13861
|
+
}
|
|
13862
|
+
}
|
|
13863
|
+
}
|
|
13864
|
+
leafGated() {
|
|
13865
|
+
return !this.lang || this.audioLocked || !!this.inflight || this.o.now() - this.lastAt < this.o.minGapMs || this.capped();
|
|
13866
|
+
}
|
|
13867
|
+
/** A leaf's gates: never over MAIN's audio or another line, spaced, capped; never a repeat. */
|
|
13868
|
+
playLeaf(hit, trigger, kind) {
|
|
13869
|
+
const { moment } = hit.node, conf = Math.round(hit.conf * 100) / 100;
|
|
13870
|
+
const tagged = hit.node.line !== lineWords(hit.node.line);
|
|
13871
|
+
const line = tagged && this.sinceTag < this.o.tagEvery ? lineWords(hit.node.line) : hit.node.line;
|
|
13872
|
+
const gated = !line || this.leafGated() || this.leaves.includes(leafKey(line));
|
|
13873
|
+
const said = !gated && this.say(kind, line);
|
|
13874
|
+
if (said) {
|
|
13875
|
+
this.leaves = [...this.leaves, leafKey(line)].slice(-this.o.leafMemory);
|
|
13876
|
+
this.sinceTag = line === hit.node.line && tagged ? 0 : this.sinceTag + 1;
|
|
13877
|
+
}
|
|
13878
|
+
const e = { trigger, rule: kind, kind, text: line, ms: 0, moment, conf, acted: gated ? "gated" : said ? "spoken" : "skipped" };
|
|
13879
|
+
this.o.onEvent(e);
|
|
13880
|
+
this.o.onLeaf(e);
|
|
13881
|
+
}
|
|
13573
13882
|
/** A clause boundary mid-floor: a breath or a comma-like close. Not a question (it wants the answer, not "mm-hm"), and a
|
|
13574
13883
|
* sentence end only deep into a story — a short request's end is the end of their turn (replay: "mm-hm" right after
|
|
13575
13884
|
* "Check hacker news for recent news.", just before the final). */
|
|
@@ -13592,7 +13901,7 @@ var SecondChannel = class {
|
|
|
13592
13901
|
const opts = this.options;
|
|
13593
13902
|
if (opts.mode === "chatty" && !opts.aec && !this.degradedLogged) {
|
|
13594
13903
|
this.degradedLogged = true;
|
|
13595
|
-
|
|
13904
|
+
log30.info("chatty mode without echo cancellation \u2014 normal timing (our lines would re-trigger the mic)");
|
|
13596
13905
|
}
|
|
13597
13906
|
const rule = this.rule(trigger, pauseMs, breath, cue);
|
|
13598
13907
|
if (rule === "silence") {
|
|
@@ -13611,7 +13920,7 @@ var SecondChannel = class {
|
|
|
13611
13920
|
const d = await withBudget(this.o.decide(this.tail(), { ...this.state(pauseMs), rule }, ac.signal), this.o.decisionBudgetMs, "channel decision", ac);
|
|
13612
13921
|
choice = d?.choice;
|
|
13613
13922
|
if (choice && choice in CHANNEL_ACTIONS && (choice === "silence" || this.allowed(choice))) kind = choice;
|
|
13614
|
-
else if (choice && choice in CHANNEL_ACTIONS)
|
|
13923
|
+
else if (choice && choice in CHANNEL_ACTIONS) log30.debug(`decider chose ${choice} for a ${rule} moment \u2014 the rule stands`);
|
|
13615
13924
|
}
|
|
13616
13925
|
if (kind === "silence") return ev({ choice, acted: "silence" });
|
|
13617
13926
|
if (stale()) return ev({ choice, kind, acted: "stale" });
|
|
@@ -13643,15 +13952,28 @@ var SecondChannel = class {
|
|
|
13643
13952
|
/** Start writing this turn's bridge now, so it may be ready by bridgeDelayMs. The bridge never waits for it. */
|
|
13644
13953
|
prefetchBridge() {
|
|
13645
13954
|
this.bridgeDraft = null;
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13955
|
+
this.askLeaf = null;
|
|
13956
|
+
this.bridgeReady = Promise.resolve();
|
|
13957
|
+
if (!this.o.generate || !(this.ownWords || this.o.generateFor.includes("bridge")) || !this.lang || !this.heard || this.ownWords && turnIntent(this.heard) !== "ask" && !requestOpener(this.heard)) return;
|
|
13958
|
+
const gen = this.gen, ac = new AbortController(), own = this.ownWords, heard = this.heard;
|
|
13959
|
+
const ctx = { kind: "bridge", heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...own ? { ask: true } : {} };
|
|
13960
|
+
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) => {
|
|
13961
|
+
const text = own && /^\s*none\b/i.test(raw ?? "") ? "" : cleanLine(raw ?? "", ctx.lang);
|
|
13962
|
+
if (text && gen === this.gen && (!own || echoesHeard(text, heard))) this.bridgeDraft = { gen, text };
|
|
13963
|
+
}).catch((e) => log30.debug(`bridge prefetch failed: ${e?.message ?? e}`));
|
|
13653
13964
|
}
|
|
13654
13965
|
async line(kind, react = true) {
|
|
13966
|
+
if (kind === "bridge" && this.ownWords) {
|
|
13967
|
+
const gen = this.gen;
|
|
13968
|
+
await Promise.all([this.leafReady, this.bridgeReady]);
|
|
13969
|
+
if (gen !== this.gen) return "";
|
|
13970
|
+
const leaf = this.askLeaf?.gen === gen ? this.askLeaf.text : "", d = this.bridgeDraft?.gen === gen ? this.bridgeDraft.text : "";
|
|
13971
|
+
if (leaf && !this.leaves.includes(leafKey(leaf))) {
|
|
13972
|
+
this.leaves = [...this.leaves, leafKey(leaf)].slice(-this.o.leafMemory);
|
|
13973
|
+
return leaf;
|
|
13974
|
+
}
|
|
13975
|
+
return d && !this.recent.some((r) => norm3(r) === norm3(d)) ? d : "";
|
|
13976
|
+
}
|
|
13655
13977
|
if (kind === "bridge" && this.o.instantBridge) {
|
|
13656
13978
|
const d = this.bridgeDraft?.gen === this.gen ? this.bridgeDraft.text : "";
|
|
13657
13979
|
this.bridgeDraft = null;
|
|
@@ -13660,18 +13982,19 @@ var SecondChannel = class {
|
|
|
13660
13982
|
}
|
|
13661
13983
|
if (this.o.generate && this.o.generateFor.includes(kind) && (kind !== "backchannel" || react)) {
|
|
13662
13984
|
const ac = new AbortController();
|
|
13663
|
-
const ctx = { kind, heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...kind === "backchannel" && this.o.reactionGapMs ? { react: true } : {} };
|
|
13985
|
+
const ctx = { kind, heard: this.tail(), state: this.main, avoid: [...this.recent], lang: this.lang, ...kind === "backchannel" && this.o.reactionGapMs ? { react: true } : {}, ...kind === "backchannel" && this.o.mode === "live" ? { tags: true } : {} };
|
|
13664
13986
|
const raw = await withBudget(this.o.generate(ctx, ac.signal), this.o.generateBudgetMs, `${kind} generate`);
|
|
13665
13987
|
if (raw === null) ac.abort();
|
|
13666
13988
|
const text = cleanLine(raw ?? "", this.lang);
|
|
13667
13989
|
if (text && !this.recent.some((r) => norm3(r) === norm3(text))) return text;
|
|
13668
|
-
if (text)
|
|
13990
|
+
if (text) log30.debug(`generated "${text}" repeats a recent line \u2014 canned`);
|
|
13669
13991
|
}
|
|
13670
13992
|
return this.pick(kind);
|
|
13671
13993
|
}
|
|
13672
13994
|
/** Canned rotation in the user's language: never one of the last `bankExclude` picks of this kind, nor a recent
|
|
13673
13995
|
* line. '' = no bank for this language yet (silence). */
|
|
13674
13996
|
pick(kind) {
|
|
13997
|
+
if (this.ownWords && kind !== "backchannel") return "";
|
|
13675
13998
|
const pool = this.bank?.[kind] ?? [];
|
|
13676
13999
|
if (!pool.length) return "";
|
|
13677
14000
|
const hist = this.picks.get(kind) ?? [];
|
|
@@ -13687,7 +14010,7 @@ var SecondChannel = class {
|
|
|
13687
14010
|
try {
|
|
13688
14011
|
r = this.o.speak(text, kind);
|
|
13689
14012
|
} catch (e) {
|
|
13690
|
-
|
|
14013
|
+
log30.warn(`speak threw \u2014 line dropped: ${e.message}`);
|
|
13691
14014
|
return false;
|
|
13692
14015
|
}
|
|
13693
14016
|
if (r === false) return false;
|
|
@@ -13696,11 +14019,12 @@ var SecondChannel = class {
|
|
|
13696
14019
|
if (kind === "backchannel") this.bcTimes.push(this.lastAt);
|
|
13697
14020
|
if (kind === "bridge") this.bridged = true;
|
|
13698
14021
|
this.recent = [...this.recent, text].slice(-this.o.avoidLines);
|
|
13699
|
-
this.live = text
|
|
13700
|
-
this.
|
|
14022
|
+
this.live = lineWords(text);
|
|
14023
|
+
const words3 = this.live;
|
|
14024
|
+
if (words3) this.o.show(words3, kind);
|
|
13701
14025
|
const p = Promise.resolve(r).then(() => {
|
|
13702
14026
|
}, (e) => {
|
|
13703
|
-
|
|
14027
|
+
log30.warn(`channel line playback failed: ${e?.message ?? e}`);
|
|
13704
14028
|
}).finally(() => {
|
|
13705
14029
|
if (this.inflight === p) this.inflight = null;
|
|
13706
14030
|
});
|
|
@@ -13737,10 +14061,14 @@ var KIND_HINT2 = {
|
|
|
13737
14061
|
bridge: 'a neutral one-moment cue while the answer is prepared ("let me see\u2026", "one sec\u2026") \u2014 never the start of a statement or opinion ("the thing is", "well actually")'
|
|
13738
14062
|
};
|
|
13739
14063
|
var REACT_HINT = 'a short reaction to their LAST words instead: feeling ("oh no", "ha, nice", "ugh"), surprise ("wait, really?", "huh"), a light laugh if they joke or laugh ("ha!"), or an echo of their key word ("the deploy?") \u2014 still never asks for an answer or takes the turn; if nothing there deserves a reaction, a plain "mm-hm"';
|
|
14064
|
+
var TAG_HINT = 'Real listeners often react without words: the line may be, or begin with, [laughter] or [gasp], and [quiet] before words breathes them under the voice ("[gasp]", "[laughter]", "[gasp] [quiet] no way"). Use a sound when it fits what they said.';
|
|
13740
14065
|
function fastLineGenerator(ai, model, gender) {
|
|
13741
14066
|
return async (c, signal) => {
|
|
13742
|
-
const prompt =
|
|
14067
|
+
const prompt = c.ask ? `A live voice call. The user just said: "${c.heard}"
|
|
14068
|
+
If this asks you to look up, check, find or do something that takes a while, write ONE spoken line of 2-5 words in ${languageName(c.lang)} that names the thing in their own words and says you are on it ("Hacker News, one sec."). If it is small talk, a statement, or something you can answer at once, write: none
|
|
14069
|
+
${personaHint(gender)} Output only the line.` : `You voice the tiny side-sounds of a live spoken conversation. Write ONE line of 1-5 words: ${KIND_HINT2[c.kind]}.
|
|
13743
14070
|
` + (c.react ? `Here the line may be ${REACT_HINT}.
|
|
14071
|
+
` : "") + (c.tags ? `${TAG_HINT}
|
|
13744
14072
|
` : "") + `The user just said: "${c.heard}"
|
|
13745
14073
|
The assistant is: ${c.state}.
|
|
13746
14074
|
` + (c.avoid.length ? `Do not reuse any of: ${c.avoid.map((a) => `"${a}"`).join(", ")}.
|
|
@@ -13758,7 +14086,7 @@ function closedQuestion(reply) {
|
|
|
13758
14086
|
}
|
|
13759
14087
|
|
|
13760
14088
|
// src/voice/call.ts
|
|
13761
|
-
var
|
|
14089
|
+
var log31 = forComponent("VoiceCall");
|
|
13762
14090
|
var VoiceCallOptions = class {
|
|
13763
14091
|
/** Host runs MAIN with exactly `text` (a replace: roll the `replaces` turn back first). */
|
|
13764
14092
|
sendTurn = () => {
|
|
@@ -13833,7 +14161,7 @@ var VoiceCall = class {
|
|
|
13833
14161
|
cancel: () => o.cancel(),
|
|
13834
14162
|
now: o.now
|
|
13835
14163
|
});
|
|
13836
|
-
this.progress = new Progress({ ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
|
|
14164
|
+
this.progress = new Progress({ ...o.mode === "live" ? { templates: {}, generateBudgetMs: 1500 } : {}, ...ai ? { generate: fastProgressGenerator(ai, o.fastModel, o.gender) } : {}, gender: o.gender, now: o.now, ...o.progress });
|
|
13837
14165
|
this.judge = new OverlapJudge({ ...ai ? { model: overlapModelFor(ai) } : {}, now: o.now });
|
|
13838
14166
|
this.gate = new TurnGate({
|
|
13839
14167
|
now: o.now,
|
|
@@ -13886,7 +14214,7 @@ var VoiceCall = class {
|
|
|
13886
14214
|
this.gate.speaking();
|
|
13887
14215
|
const c = this.cur;
|
|
13888
14216
|
if (this.o.mode === "live" && c?.running && !c.worded && text.trim().split(/\s+/).length >= 2) {
|
|
13889
|
-
|
|
14217
|
+
log31.debug("user resumed before the reply \u2014 yielded");
|
|
13890
14218
|
this.barge();
|
|
13891
14219
|
}
|
|
13892
14220
|
this.follow(text);
|
|
@@ -13990,7 +14318,7 @@ var VoiceCall = class {
|
|
|
13990
14318
|
try {
|
|
13991
14319
|
this.o.cancel();
|
|
13992
14320
|
} catch (e) {
|
|
13993
|
-
|
|
14321
|
+
log31.warn(`cancel threw: ${e.message}`);
|
|
13994
14322
|
}
|
|
13995
14323
|
if (this.cur?.running) {
|
|
13996
14324
|
this.cur.running = false;
|
|
@@ -14077,7 +14405,7 @@ var VoiceCall = class {
|
|
|
14077
14405
|
try {
|
|
14078
14406
|
r = this.o.speak(text, kind);
|
|
14079
14407
|
} catch (e) {
|
|
14080
|
-
|
|
14408
|
+
log31.warn(`speak threw: ${e.message}`);
|
|
14081
14409
|
return false;
|
|
14082
14410
|
}
|
|
14083
14411
|
if (r === false) return false;
|
|
@@ -14128,7 +14456,8 @@ var VoiceCall = class {
|
|
|
14128
14456
|
async onTool(c, name, args) {
|
|
14129
14457
|
const lang = this.lang;
|
|
14130
14458
|
if (!lang || c.streamed) return;
|
|
14131
|
-
const line = await this.progress.line(name, args, lang);
|
|
14459
|
+
const line = await this.progress.line(name, args, lang, this.o.mode === "live" ? c.text : "");
|
|
14460
|
+
if (!line && this.o.mode === "live") this.o.onMetric({ name: "drop", id: c.id, kind: `no progress line: ${name}` });
|
|
14132
14461
|
if (!line || this.cur !== c || c.streamed || !c.running || this.lang !== lang) return;
|
|
14133
14462
|
this.clearProgress();
|
|
14134
14463
|
const tryNow = () => {
|
|
@@ -14140,6 +14469,7 @@ var VoiceCall = class {
|
|
|
14140
14469
|
}
|
|
14141
14470
|
if (this.say(line, "progress") !== false) {
|
|
14142
14471
|
this.progress.spoke(line);
|
|
14472
|
+
this.fill.covered();
|
|
14143
14473
|
this.o.show(line, "progress");
|
|
14144
14474
|
}
|
|
14145
14475
|
};
|