dsh-chubby-whale 1.1.61 → 1.1.62
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/CHANGELOG.md +25 -0
- package/dist/client.js +65 -27
- package/dist/host/persona.js +8 -1
- package/dist/host/repos/pet.js +8 -1
- package/dist/host/voice/cloud-tts.js +116 -15
- package/docs//345/217/221/345/270/203/350/247/204/350/214/203.md +7 -7
- package/docs//345/276/205/351/207/215/345/220/257/347/224/237/346/225/210.md +21 -0
- package/docs//350/267/250/345/271/263/345/217/260/344/270/216/345/210/206/345/267/245.md +4 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
## [未发布]
|
|
6
6
|
|
|
7
|
+
## [1.1.62] - 2026-11-07
|
|
8
|
+
|
|
9
|
+
### 修复(B90 人格与云端语音分身)
|
|
10
|
+
- **阶段语气查表走原型链**:`STAGE_TONE[命名]` 用普通对象查表,`constructor`/`__proto__`/`toString` 都会命中——`buildSystemPrompt('constructor')` 会把 `function Object() { [native code] }` 拼进系统提示词。改为 `hasOwnProperty` 判定
|
|
11
|
+
- **云端 TTS 响应无体积上限**:11MB 假响应会被完整收下并解码(错误分支同样无上限),设计稿要求「每段带大小上限」。现在 16MB 上限,声明超限不读流、流式超限提前 cancel
|
|
12
|
+
- **云端成本熔断 fail-open**:`saveUsage` 的 `catch {}` 静默吞掉写盘失败,且预算只读磁盘 → 用量文件坏掉后每天字数限制彻底失效(实测连跑 3 次全部放行、`usage()` 恒 0)。现在写失败留 `CLOUD-USAGE-FAIL`,`usedChars = max(磁盘, 进程内)`
|
|
13
|
+
|
|
14
|
+
### 修复(B90 客户端粘合层分身)
|
|
15
|
+
- **点播路由劫持追问**:「换个说法 / 换个故事 / 换个声音 / 再来个人」被正则当成念诗,还会 abort 在途聊天;而纯函数层测试明确断言「换个故事」应交模型——两层口径冲突
|
|
16
|
+
- **带句末标点的整句指令失效**:「接着说。」「报书名!」「继续。」不再被识别
|
|
17
|
+
- **典故/成语播报与主人原话相反**:数据池叫 `chengyu` 就念「讲个成语」,讲典故反而说成语
|
|
18
|
+
- **APE 判停两类输入崩坏**:`NaN` 进噪声底后段落永不 commit;`-Infinity`/首帧 `-160` 哨兵让噪声底永远回不来(每段等满 6s);`steadyWindowFrames<8` 时永远判不出平稳
|
|
19
|
+
- **气泡状态字收不起来**:`dismissStatus` 用未 trim 的文本比对(「在想… 」带尾随空白就永远在)
|
|
20
|
+
- **`useLazyRef` 对假值反复重建**:工厂返回 `0/''/false/null` 时每次都重建(违反「只建一次」契约)
|
|
21
|
+
|
|
22
|
+
### 修复(主代理)
|
|
23
|
+
- **动作描写超过 60 字会被念出来**:`stripStageDirections` 的 `{1,60}` 上限去掉(否定字符类无回溯风险)
|
|
24
|
+
- **超长无标点一次念几百字**:`createSentenceBuffer` 的 `maxLen` 从「只做阈值」改为「也做硬上限」,按阈值切段且不劈代理对(`test-utils-pure` 契约同步)
|
|
25
|
+
- **语速读侧不 trim**:写侧有 trim、读侧没有,手改的 ` -10% ` 静默回默认
|
|
26
|
+
- **客户端情绪定时器不清理**:`setMood` 的回落定时器无 dispose、`holdMs` 为 NaN/负数会被 `setTimeout` 当 0;`bowls` 负数原样保留(成长档位按负经验算);`pet.setMood` 无白名单(任意字符串写进 `pet_state.json`)
|
|
27
|
+
|
|
28
|
+
### 测试
|
|
29
|
+
- 新增 `test-persona-cloud.mjs`(139+4 变异体)、`test-client-glue.mjs`(113+6 变异体),均接入 `npm test`
|
|
30
|
+
- 全链 **3400 项 0 失败**(`node tools/test-count.mjs`:47 个套件,失败 0,未识别 0)
|
|
31
|
+
|
|
7
32
|
## [1.1.61] - 2026-11-07
|
|
8
33
|
|
|
9
34
|
### 修复(B89 宿主 HTTP 层分身)
|
package/dist/client.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// src/client/version.ts
|
|
17
|
-
var VERSION = "1.1.
|
|
17
|
+
var VERSION = "1.1.62";
|
|
18
18
|
|
|
19
19
|
// src/client/styles.ts
|
|
20
20
|
var W = 240;
|
|
@@ -213,12 +213,17 @@
|
|
|
213
213
|
*/
|
|
214
214
|
steadyMaxAboveFloorDb: 20,
|
|
215
215
|
maxSegmentMs: 6e3,
|
|
216
|
+
/**
|
|
217
|
+
* 平稳性判别窗口(帧)。10 帧 × 60ms = 600ms。
|
|
218
|
+
* 注意:起判前至少采 8 帧再算起伏(见 step 里的 minFrames,窗口配得更小时按窗口本身算);
|
|
219
|
+
* 这里原来写「25 帧 = 1.5s」是旧稿注释,与取值不符,2026-11-07 按实际取值改正。
|
|
220
|
+
*/
|
|
216
221
|
steadyWindowFrames: 10,
|
|
217
|
-
// 25 帧 × 60ms = 1.5s
|
|
218
222
|
steadySpreadDb: 3,
|
|
219
223
|
steadyMs: 400
|
|
220
224
|
};
|
|
221
225
|
deepFreeze(APE_DEFAULTS);
|
|
226
|
+
var SENTINEL_DB = -160;
|
|
222
227
|
var Ape = class {
|
|
223
228
|
p;
|
|
224
229
|
floorDb = null;
|
|
@@ -254,20 +259,29 @@
|
|
|
254
259
|
floor() {
|
|
255
260
|
return this.floorDb === null ? -70 : this.floorDb;
|
|
256
261
|
}
|
|
257
|
-
step(
|
|
262
|
+
step(rawDb) {
|
|
258
263
|
const p = this.p;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
264
|
+
const valid = Number.isFinite(rawDb) && rawDb > SENTINEL_DB;
|
|
265
|
+
const db = valid ? rawDb : this.floor();
|
|
266
|
+
if (valid) {
|
|
267
|
+
if (this.floorDb === null) this.floorDb = db;
|
|
268
|
+
if (db > this.peakDb) this.peakDb = db;
|
|
269
|
+
else this.peakDb = Math.max(-160, this.peakDb - p.peakDecayDb);
|
|
270
|
+
}
|
|
271
|
+
const floorNow = this.floor();
|
|
272
|
+
const range = this.peakDb - floorNow;
|
|
263
273
|
const margin = Math.max(p.marginMinDb, Math.min(p.marginMaxDb, range * p.marginRatio));
|
|
264
|
-
const onsetTh =
|
|
265
|
-
const offsetTh =
|
|
274
|
+
const onsetTh = floorNow + margin;
|
|
275
|
+
const offsetTh = floorNow + p.offsetMarginDb;
|
|
266
276
|
this.elapsedMs += p.frameMs;
|
|
267
|
-
if (
|
|
277
|
+
if (!valid) {
|
|
278
|
+
this.quietMs += p.frameMs;
|
|
279
|
+
this.bandMs = 0;
|
|
280
|
+
} else if (db > onsetTh) {
|
|
268
281
|
this.steadyHist.push(db);
|
|
269
282
|
while (this.steadyHist.length > p.steadyWindowFrames) this.steadyHist.shift();
|
|
270
|
-
const
|
|
283
|
+
const minFrames = Math.max(2, Math.min(8, p.steadyWindowFrames));
|
|
284
|
+
const spread = this.steadyHist.length >= minFrames ? Math.max(...this.steadyHist) - Math.min(...this.steadyHist) : 99;
|
|
271
285
|
const nearFloor = db - this.floorDb <= p.steadyMaxAboveFloorDb;
|
|
272
286
|
const steadyNow = spread < p.steadySpreadDb && nearFloor;
|
|
273
287
|
if (steadyNow) {
|
|
@@ -329,7 +343,7 @@
|
|
|
329
343
|
}
|
|
330
344
|
return {
|
|
331
345
|
db,
|
|
332
|
-
floorDb: this.
|
|
346
|
+
floorDb: this.floor(),
|
|
333
347
|
onsetTh,
|
|
334
348
|
offsetTh,
|
|
335
349
|
speechMs: this.speechMs,
|
|
@@ -372,7 +386,7 @@
|
|
|
372
386
|
}
|
|
373
387
|
function chatRate() {
|
|
374
388
|
try {
|
|
375
|
-
const s = localStorage.getItem("chubby-chat-rate");
|
|
389
|
+
const s = String(localStorage.getItem("chubby-chat-rate") || "").trim();
|
|
376
390
|
if (s && CHAT_RATES.indexOf(s) >= 0) return s;
|
|
377
391
|
} catch (e) {
|
|
378
392
|
}
|
|
@@ -390,7 +404,7 @@
|
|
|
390
404
|
}
|
|
391
405
|
function narrationRate() {
|
|
392
406
|
try {
|
|
393
|
-
const s = localStorage.getItem("chubby-narration-rate");
|
|
407
|
+
const s = String(localStorage.getItem("chubby-narration-rate") || "").trim();
|
|
394
408
|
if (s && NARRATION_RATES.indexOf(s) >= 0) return s;
|
|
395
409
|
} catch (e) {
|
|
396
410
|
}
|
|
@@ -574,7 +588,7 @@
|
|
|
574
588
|
}
|
|
575
589
|
function stripStageDirections(raw) {
|
|
576
590
|
let t = str(raw);
|
|
577
|
-
t = t.replace(/[\**][^**\n]
|
|
591
|
+
t = t.replace(/[\**][^**\n]*[\**]/g, " ");
|
|
578
592
|
t = t.replace(/[\**]/g, " ");
|
|
579
593
|
t = t.replace(/([,。!?;:、])\s+/g, "$1");
|
|
580
594
|
return t.replace(/\s{2,}/g, " ").trim();
|
|
@@ -630,9 +644,19 @@
|
|
|
630
644
|
break;
|
|
631
645
|
}
|
|
632
646
|
if (force || tail.length + lead.length >= limit) {
|
|
633
|
-
const
|
|
647
|
+
const buf = lead + tail;
|
|
634
648
|
lead = "";
|
|
635
649
|
tail = "";
|
|
650
|
+
let rest = buf;
|
|
651
|
+
while (rest.length > limit) {
|
|
652
|
+
let cut = limit;
|
|
653
|
+
const code = rest.charCodeAt(cut - 1);
|
|
654
|
+
if (code >= 55296 && code <= 56319) cut += 1;
|
|
655
|
+
const seg2 = rest.slice(0, cut).trim();
|
|
656
|
+
if (seg2) out.push(seg2);
|
|
657
|
+
rest = rest.slice(cut);
|
|
658
|
+
}
|
|
659
|
+
const seg = rest.trim();
|
|
636
660
|
if (seg) out.push(seg);
|
|
637
661
|
}
|
|
638
662
|
return out;
|
|
@@ -5928,7 +5952,8 @@
|
|
|
5928
5952
|
const s = JSON.parse(raw);
|
|
5929
5953
|
return {
|
|
5930
5954
|
...base,
|
|
5931
|
-
|
|
5955
|
+
// 负数/NaN/小数一律归成非负整数:原来负数会原样保留,成长档位会按负经验算
|
|
5956
|
+
bowls: Math.max(0, Math.floor(Number(s.bowls) || 0)),
|
|
5932
5957
|
stageIndex: Number(s.stageIndex) || 0,
|
|
5933
5958
|
lastFeedAt: Number(s.lastFeedAt) || 0,
|
|
5934
5959
|
lastInteractAt: Number(s.lastInteractAt) || 0,
|
|
@@ -5993,9 +6018,12 @@
|
|
|
5993
6018
|
return state.mood;
|
|
5994
6019
|
}
|
|
5995
6020
|
let moodTimer = null;
|
|
6021
|
+
const MOOD_HOLD_MAX_MS = 60 * 1e3;
|
|
5996
6022
|
function setMood(m, holdMs = 5e3) {
|
|
5997
6023
|
state.mood = m;
|
|
5998
6024
|
clearT(moodTimer);
|
|
6025
|
+
const n = Number(holdMs);
|
|
6026
|
+
const ms2 = Number.isFinite(n) && n > 0 ? Math.min(n, MOOD_HOLD_MAX_MS) : 5e3;
|
|
5999
6027
|
moodTimer = setTimeout(() => {
|
|
6000
6028
|
moodTimer = null;
|
|
6001
6029
|
try {
|
|
@@ -6003,7 +6031,11 @@
|
|
|
6003
6031
|
refreshMood();
|
|
6004
6032
|
} catch (e) {
|
|
6005
6033
|
}
|
|
6006
|
-
},
|
|
6034
|
+
}, ms2);
|
|
6035
|
+
}
|
|
6036
|
+
function dispose() {
|
|
6037
|
+
clearT(moodTimer);
|
|
6038
|
+
moodTimer = null;
|
|
6007
6039
|
}
|
|
6008
6040
|
activeState = state;
|
|
6009
6041
|
activeMoodSource = () => refreshMood();
|
|
@@ -6074,6 +6106,7 @@
|
|
|
6074
6106
|
state,
|
|
6075
6107
|
refreshMood,
|
|
6076
6108
|
setMood,
|
|
6109
|
+
dispose,
|
|
6077
6110
|
line,
|
|
6078
6111
|
greeting,
|
|
6079
6112
|
feed,
|
|
@@ -6171,7 +6204,7 @@
|
|
|
6171
6204
|
if (!el) return;
|
|
6172
6205
|
const te = opts.textEl();
|
|
6173
6206
|
const txt = te ? String(te.textContent || "") : "";
|
|
6174
|
-
if (STATUS_TEXTS.indexOf(txt) >= 0) {
|
|
6207
|
+
if (STATUS_TEXTS.indexOf(txt.trim()) >= 0) {
|
|
6175
6208
|
clearTimer(el);
|
|
6176
6209
|
el.classList.remove("show");
|
|
6177
6210
|
}
|
|
@@ -6960,13 +6993,16 @@
|
|
|
6960
6993
|
}
|
|
6961
6994
|
function route(rawText) {
|
|
6962
6995
|
const t0 = String(rawText || "").trim();
|
|
6963
|
-
|
|
6996
|
+
const cmd = t0.replace(/[。..!!~~…]+$/, "");
|
|
6997
|
+
const again = /^(再来|再念|换)(一)?(首|个)([\s\S]*)$/.exec(cmd);
|
|
6998
|
+
const againTail = again ? again[4] : "";
|
|
6999
|
+
if (again && (againTail === "" || /^[吧啊呀哦嘛哈啦呗吖诗]+/.test(againTail))) {
|
|
6964
7000
|
takeOver();
|
|
6965
7001
|
host.bubble("(点播)好,再念一首", 3e3);
|
|
6966
7002
|
fetchPoem("", (p) => recitePoem(host, p));
|
|
6967
7003
|
return true;
|
|
6968
7004
|
}
|
|
6969
|
-
if (/^(继续|接着说|接着讲|往下讲)$/.test(
|
|
7005
|
+
if (/^(继续|接着说|接着讲|往下讲)$/.test(cmd)) {
|
|
6970
7006
|
takeOver();
|
|
6971
7007
|
host.bubble("(点播)接着说", 3e3);
|
|
6972
7008
|
try {
|
|
@@ -6977,7 +7013,7 @@
|
|
|
6977
7013
|
host.story.start(host.storyState.book.current || "");
|
|
6978
7014
|
return true;
|
|
6979
7015
|
}
|
|
6980
|
-
if (/^(报|说|列)(一下|下)?(书名|书单)$/.test(
|
|
7016
|
+
if (/^(报|说|列)(一下|下)?(书名|书单)$/.test(cmd)) {
|
|
6981
7017
|
takeOver();
|
|
6982
7018
|
host.bubble("(点播)本鲸数数书单…", 3e3);
|
|
6983
7019
|
getJson("/story/books", { cache: "no-store" }).then((d) => {
|
|
@@ -7004,7 +7040,8 @@
|
|
|
7004
7040
|
host.bubble("正在讲呢,稍等~", 2e3);
|
|
7005
7041
|
return true;
|
|
7006
7042
|
}
|
|
7007
|
-
|
|
7043
|
+
const saidIdiom = /成语/.test(t0);
|
|
7044
|
+
host.bubble(saidIdiom ? "(点播)讲个成语" : "(点播)讲个典故", 3e3);
|
|
7008
7045
|
getJson("/culture?type=" + type).then((d) => {
|
|
7009
7046
|
const it = d && d.ok && d.item ? d.item : null;
|
|
7010
7047
|
if (!it) {
|
|
@@ -7012,8 +7049,8 @@
|
|
|
7012
7049
|
return;
|
|
7013
7050
|
}
|
|
7014
7051
|
const body = collapseText(String(it.text || ""));
|
|
7015
|
-
host.bubble((
|
|
7016
|
-
host.speak((
|
|
7052
|
+
host.bubble((saidIdiom ? "成语·" : "典故·") + String(it.title || ""), 15e3);
|
|
7053
|
+
host.speak((saidIdiom ? "讲个成语——" : "讲个典故——") + String(it.title || "") + (it.src ? ",出自" + String(it.src) : "") + "。" + body, { rate: host.narrationRate() });
|
|
7017
7054
|
}).catch(() => host.bubble("这个没读到", 4e3));
|
|
7018
7055
|
return true;
|
|
7019
7056
|
}
|
|
@@ -7816,8 +7853,9 @@
|
|
|
7816
7853
|
}
|
|
7817
7854
|
function createHooks(R) {
|
|
7818
7855
|
function useLazyRef(factory) {
|
|
7819
|
-
const
|
|
7820
|
-
|
|
7856
|
+
const UNSET = {};
|
|
7857
|
+
const ref = R.useRef(UNSET);
|
|
7858
|
+
if (ref.current === UNSET) ref.current = factory();
|
|
7821
7859
|
return ref;
|
|
7822
7860
|
}
|
|
7823
7861
|
function usePersistentBool(key, fallback = true) {
|
package/dist/host/persona.js
CHANGED
|
@@ -26,5 +26,12 @@ const STAGE_TONE = {
|
|
|
26
26
|
};
|
|
27
27
|
/** 组装系统提示词:基础人设 + 当前成长阶段语气(未知阶段回落空串) */
|
|
28
28
|
export function buildSystemPrompt(stageName) {
|
|
29
|
-
|
|
29
|
+
const key = String(stageName || '');
|
|
30
|
+
// 只认自有键:STAGE_TONE 是普通对象字面量,`STAGE_TONE['constructor']` / `'__proto__'` /
|
|
31
|
+
// `'toString'` 会命中原型链,把函数源码或 "[object Object]" 拼进系统提示词
|
|
32
|
+
// (实测 buildSystemPrompt('constructor') 末尾多出 "function Object() { [native code] }",
|
|
33
|
+
// '__proto__' 多出 "[object Object]")。未知阶段仍回落空串,已知阶段名行为不变。
|
|
34
|
+
// 与 host/repos/growth.ts 里 EXP_SOURCE_CAP 的 hasOwnProperty 口径一致。
|
|
35
|
+
const tone = key && Object.prototype.hasOwnProperty.call(STAGE_TONE, key) ? STAGE_TONE[key] : '';
|
|
36
|
+
return SYSTEM_PROMPT + tone;
|
|
30
37
|
}
|
package/dist/host/repos/pet.js
CHANGED
|
@@ -16,6 +16,11 @@ import { writeJsonAtomic, isMissingFileError, quarantineFile, readTextNoBom } fr
|
|
|
16
16
|
const HUNGER_PER_HOUR = 3;
|
|
17
17
|
/** 饥饿到 70 算「饿了」,由 /pet 下发 hungry(客户端只认 happy/hungry/normal 三态) */
|
|
18
18
|
const HUNGRY_AT = 70;
|
|
19
|
+
/**
|
|
20
|
+
* 宠物情绪白名单:只接受这些值,其余按 idle。
|
|
21
|
+
* 为什么:`setMood` 原来把任意字符串写进 pet_state.json,客户端表情渲染落空、备份也会带走脏值。
|
|
22
|
+
*/
|
|
23
|
+
const PET_MOODS = ['idle', 'happy', 'hungry', 'sleepy', 'sulk', 'shy', 'excited'];
|
|
19
24
|
/** 喂食后心情保持 happy 的时长,与客户端 6 小时「该喂了」的阈值同口径 */
|
|
20
25
|
const HAPPY_WINDOW_MS = 6 * 3600 * 1000;
|
|
21
26
|
/** 饥饿统一夹到 [0, 100];非数字按 0 */
|
|
@@ -103,7 +108,9 @@ export function createPetRepo(dataDir) {
|
|
|
103
108
|
}
|
|
104
109
|
function setMood(mood) {
|
|
105
110
|
const p = loadPet();
|
|
106
|
-
|
|
111
|
+
// 只接受已知情绪:任意字符串写进 pet.json 会让客户端表情渲染落空(还会被备份带走)
|
|
112
|
+
const m = String(mood || '').trim();
|
|
113
|
+
p.mood = PET_MOODS.indexOf(m) >= 0 ? m : 'idle';
|
|
107
114
|
savePet(p);
|
|
108
115
|
}
|
|
109
116
|
return { loadPet, savePet, tickPet, feedPet, setMood };
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
*
|
|
13
13
|
* 成本控制:按「日合成字数」熔断(默认 5000 字/天,可在 config.cloudVoice.dailyChars 改);
|
|
14
14
|
* 超限直接抛错 -> 路由回退 edge-tts(免费)-> 客户端始终有声。
|
|
15
|
+
* 日用量落盘 ~/.dsh-chubby-whale/cloud-usage.json(重启/跨进程接着算);写盘失败时进程内
|
|
16
|
+
* 计数兜底并留 CLOUD-USAGE-FAIL,熔断不会因为一次 IO 失败就失效。
|
|
17
|
+
*
|
|
18
|
+
* 健壮性:单次响应体积上限 16MB(声明超限不读流、流式超限提前 cancel),坏响应吃不掉宿主内存;
|
|
19
|
+
* 超时(默认 15s,可注入)到点 abort,失败一律抛错交给路由回退,不记账。
|
|
15
20
|
*
|
|
16
21
|
* 安全:API Key 只从本地 config.json 读,不进包、不进备份导出。
|
|
17
22
|
*/
|
|
@@ -26,6 +31,19 @@ export const CLOUD_TTS_RESOURCE_ID = 'seed-tts-2.0';
|
|
|
26
31
|
export const CLOUD_TTS_DEFAULT_SPEAKER = 'zh_female_vv_uranus_bigtts';
|
|
27
32
|
/** 合成请求超时(云端 HTTP 单次,通常 0.2–0.5s) */
|
|
28
33
|
const CLOUD_TTS_TIMEOUT_MS = 15000;
|
|
34
|
+
/**
|
|
35
|
+
* 单次响应体积上限(字节,按 JSON 文本算:base64 比音频大约 4/3)。
|
|
36
|
+
*
|
|
37
|
+
* 为什么必须有:原来直接 `await res.text()`,chunked 流有多大就收多大——服务端 bug、
|
|
38
|
+
* 中间层塞回一个错误页/HTML、或响应被劫持时,宿主进程的内存没有任何护栏
|
|
39
|
+
* (实测 8MB 的假响应照收不误,再大也一样)。
|
|
40
|
+
*
|
|
41
|
+
* 上限怎么定:/tts 路由侧单段文本最多 6000 字(host/routes/tts.ts 的 MAX_TEXT),
|
|
42
|
+
* 按 24kHz mp3 估算约 5–10MB base64;正常请求(客户端按 ≤80 字分段)只有几十~一百多 KB。
|
|
43
|
+
* 取 16MB 既装得下最长的合法请求,又给坏响应一个硬天花板;超限一律抛错让路由回退
|
|
44
|
+
* edge-tts(免费兜底,客户端仍有声),不拿宿主内存赌对方一定守规矩。
|
|
45
|
+
*/
|
|
46
|
+
const CLOUD_TTS_MAX_BYTES = 16 * 1024 * 1024;
|
|
29
47
|
/** 从 pluginDir/config.json 读 cloudVoice 段(缺省/无 Key = 不启用) */
|
|
30
48
|
export function readCloudVoice(pluginDir) {
|
|
31
49
|
const empty = {
|
|
@@ -76,11 +94,73 @@ function readUsage(runtimeDir) {
|
|
|
76
94
|
return { day: todayKey(), chars: 0 };
|
|
77
95
|
}
|
|
78
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* 写日用量;失败返回 false(调用方记一行日志,绝不把异常抛进聊天链路)。
|
|
99
|
+
* 返回布尔而不是吞掉:熔断的全部依据就是这份计数,写不进去必须留痕。
|
|
100
|
+
*/
|
|
79
101
|
function saveUsage(runtimeDir, u) {
|
|
80
102
|
try {
|
|
81
103
|
writeJsonAtomic(join(runtimeDir, 'cloud-usage.json'), u);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 带体积上限地读完响应文本(成功与失败两条路都走这里)。
|
|
112
|
+
* · 声明了 content-length 且已超限:一个字节都不读,直接判超限;
|
|
113
|
+
* · 没声明或声明偏小:边读边累计,超限立刻 cancel 掉流再抛(不把整份坏响应收进内存);
|
|
114
|
+
* · 没有 body 流(离线测试里的假响应)时退回 res.text(),按 UTF-8 字节数补判上限。
|
|
115
|
+
*/
|
|
116
|
+
async function readResponseText(res, maxBytes) {
|
|
117
|
+
const declared = Number(res && res.headers && typeof res.headers.get === 'function'
|
|
118
|
+
? res.headers.get('content-length') : NaN);
|
|
119
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
120
|
+
throw new Error('cloud-tts 响应超限 ' + declared + ' > ' + maxBytes + ' 字节');
|
|
121
|
+
}
|
|
122
|
+
const body = res && res.body;
|
|
123
|
+
if (!body || typeof body.getReader !== 'function') {
|
|
124
|
+
const text = String(await res.text());
|
|
125
|
+
const bytes = Buffer.byteLength(text, 'utf8');
|
|
126
|
+
if (bytes > maxBytes)
|
|
127
|
+
throw new Error('cloud-tts 响应超限 ' + bytes + ' > ' + maxBytes + ' 字节');
|
|
128
|
+
return text;
|
|
129
|
+
}
|
|
130
|
+
const reader = body.getReader();
|
|
131
|
+
const chunks = [];
|
|
132
|
+
let total = 0;
|
|
133
|
+
try {
|
|
134
|
+
for (;;) {
|
|
135
|
+
const step = await reader.read();
|
|
136
|
+
if (!step || step.done)
|
|
137
|
+
break;
|
|
138
|
+
if (!step.value)
|
|
139
|
+
continue;
|
|
140
|
+
const buf = Buffer.from(step.value);
|
|
141
|
+
total += buf.length;
|
|
142
|
+
if (total > maxBytes)
|
|
143
|
+
throw new Error('cloud-tts 响应超限 >' + maxBytes + ' 字节');
|
|
144
|
+
chunks.push(buf);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
// 读取中途出错(含超时 abort / 超限):把流放掉,别让连接挂着
|
|
149
|
+
try {
|
|
150
|
+
if (typeof reader.cancel === 'function')
|
|
151
|
+
await reader.cancel();
|
|
152
|
+
}
|
|
153
|
+
catch { }
|
|
154
|
+
throw err;
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
try {
|
|
158
|
+
if (typeof reader.releaseLock === 'function')
|
|
159
|
+
reader.releaseLock();
|
|
160
|
+
}
|
|
161
|
+
catch { }
|
|
82
162
|
}
|
|
83
|
-
|
|
163
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
84
164
|
}
|
|
85
165
|
/**
|
|
86
166
|
* 创建云端 TTS 实例。synthesize 失败会抛错(路由据此回退 edge-tts);
|
|
@@ -89,10 +169,27 @@ function saveUsage(runtimeDir, u) {
|
|
|
89
169
|
export function createCloudTts(deps) {
|
|
90
170
|
const log = deps.log || (() => { });
|
|
91
171
|
const clock = deps.now || (() => new Date());
|
|
92
|
-
|
|
172
|
+
const timeoutRaw = Number(deps.timeoutMs);
|
|
173
|
+
const timeoutMs = Number.isFinite(timeoutRaw) && timeoutRaw > 0 ? timeoutRaw : CLOUD_TTS_TIMEOUT_MS;
|
|
174
|
+
/**
|
|
175
|
+
* 进程内兜底计数。
|
|
176
|
+
*
|
|
177
|
+
* 为什么需要:日用量原本只认磁盘上的 cloud-usage.json,而写盘失败(只读目录、磁盘满、
|
|
178
|
+
* 杀软占着句柄)被静默吞掉——实测把 cloud-usage.json 换成目录后,dailyChars=150 的额度
|
|
179
|
+
* 连跑 3 次 100 字的合成全部放行、usage() 还是 0,熔断彻底失效(花的是真金白银)。
|
|
180
|
+
* 现在成功一次就同时记内存与磁盘,取两者的最大值:磁盘写失败时进程内仍能挡住超额,
|
|
181
|
+
* 重启后才有丢计数的风险(写盘成功时磁盘自然追平,不会重复计数)。
|
|
182
|
+
*/
|
|
183
|
+
let memUsage = null;
|
|
184
|
+
/** 今天已用字数:磁盘与内存取大(磁盘可能是别的实例写的,内存是本进程的最低保障) */
|
|
185
|
+
function usedChars(today) {
|
|
93
186
|
const u = readUsage(deps.runtimeDir);
|
|
94
|
-
const
|
|
95
|
-
|
|
187
|
+
const fromDisk = u.day === today ? u.chars : 0;
|
|
188
|
+
const fromMem = memUsage && memUsage.day === today ? memUsage.chars : 0;
|
|
189
|
+
return Math.max(fromDisk, fromMem);
|
|
190
|
+
}
|
|
191
|
+
function budgetLeft(cfg, today) {
|
|
192
|
+
return cfg.dailyChars - usedChars(today);
|
|
96
193
|
}
|
|
97
194
|
return {
|
|
98
195
|
enabled() {
|
|
@@ -101,8 +198,8 @@ export function createCloudTts(deps) {
|
|
|
101
198
|
},
|
|
102
199
|
usage() {
|
|
103
200
|
const cfg = deps.config();
|
|
104
|
-
const
|
|
105
|
-
return { day:
|
|
201
|
+
const today = todayKey(clock());
|
|
202
|
+
return { day: today, chars: usedChars(today), limit: cfg.dailyChars };
|
|
106
203
|
},
|
|
107
204
|
async synthesize(text) {
|
|
108
205
|
const cfg = deps.config();
|
|
@@ -111,8 +208,9 @@ export function createCloudTts(deps) {
|
|
|
111
208
|
const body = String(text || '').trim();
|
|
112
209
|
if (!body)
|
|
113
210
|
throw new Error('cloud-tts 空文本');
|
|
211
|
+
const today = todayKey(clock());
|
|
114
212
|
// 日字数熔断:超了直接抛,路由回退 edge-tts
|
|
115
|
-
if (budgetLeft(cfg) < body.length) {
|
|
213
|
+
if (budgetLeft(cfg, today) < body.length) {
|
|
116
214
|
log('[tts] CLOUD-BUDGET 日字数超限(' + cfg.dailyChars + '),回退 edge-tts');
|
|
117
215
|
throw new Error('cloud-tts 日预算用尽');
|
|
118
216
|
}
|
|
@@ -120,7 +218,7 @@ export function createCloudTts(deps) {
|
|
|
120
218
|
const timer = setTimeout(() => { try {
|
|
121
219
|
ctl && ctl.abort();
|
|
122
220
|
}
|
|
123
|
-
catch { } },
|
|
221
|
+
catch { } }, timeoutMs);
|
|
124
222
|
try {
|
|
125
223
|
const res = await fetch(CLOUD_TTS_URL, {
|
|
126
224
|
method: 'POST',
|
|
@@ -140,11 +238,12 @@ export function createCloudTts(deps) {
|
|
|
140
238
|
signal: ctl ? ctl.signal : undefined,
|
|
141
239
|
});
|
|
142
240
|
if (!res.ok) {
|
|
143
|
-
|
|
241
|
+
// 错误页也走体积上限:有的网关会回一整页 HTML,读满内存才知道是 500
|
|
242
|
+
const t = await readResponseText(res, CLOUD_TTS_MAX_BYTES).catch(() => '');
|
|
144
243
|
throw new Error('cloud-tts HTTP ' + res.status + ' ' + t.slice(0, 200));
|
|
145
244
|
}
|
|
146
|
-
// 响应是 chunked
|
|
147
|
-
const raw = await res
|
|
245
|
+
// 响应是 chunked 行流;整段读完后按行解析(半行不会跨包被判成坏帧)
|
|
246
|
+
const raw = await readResponseText(res, CLOUD_TTS_MAX_BYTES);
|
|
148
247
|
const parts = [];
|
|
149
248
|
for (const line of raw.split('\n')) {
|
|
150
249
|
const s = line.trim();
|
|
@@ -168,10 +267,12 @@ export function createCloudTts(deps) {
|
|
|
168
267
|
const buf = Buffer.concat(parts);
|
|
169
268
|
if (!buf.length)
|
|
170
269
|
throw new Error('cloud-tts 没有返回音频');
|
|
171
|
-
//
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
saveUsage(deps.runtimeDir,
|
|
270
|
+
// 记账(成功才记):内存与磁盘同时记,磁盘写失败也不能让熔断瞎掉
|
|
271
|
+
const used = usedChars(today) + body.length;
|
|
272
|
+
memUsage = { day: today, chars: used };
|
|
273
|
+
if (!saveUsage(deps.runtimeDir, memUsage)) {
|
|
274
|
+
log('[tts] CLOUD-USAGE-FAIL 日用量写盘失败(进程内计数仍生效,重启后会丢):day=' + today + ' chars=' + used);
|
|
275
|
+
}
|
|
175
276
|
return buf;
|
|
176
277
|
}
|
|
177
278
|
finally {
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
| 项 | 值 |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| `package.json` version | 1.1.
|
|
16
|
-
| `src/client/version.ts` VERSION | 1.1.
|
|
17
|
-
| 最近 Gitee tag | `v1.1.
|
|
18
|
-
| Gitee `main` HEAD | `
|
|
19
|
-
| GitHub `main` | `
|
|
20
|
-
| npm latest | **1.1.
|
|
15
|
+
| `package.json` version | 1.1.62 |
|
|
16
|
+
| `src/client/version.ts` VERSION | 1.1.62(由 `scripts/gen-version.mjs` 生成) |
|
|
17
|
+
| 最近 Gitee tag | `v1.1.62`(见 `git tag --list`) |
|
|
18
|
+
| Gitee `main` HEAD | `git log -1` 实读 |
|
|
19
|
+
| GitHub `main` | 发布后 `node tools/gh-verify.mjs v1.1.62` 核对(脚本按 tag 名推期望版本) |
|
|
20
|
+
| npm latest | **1.1.62**(发布后轮询确认;202 受理到可见约 2–4 分钟) |
|
|
21
21
|
| README 版本 | 无硬编码版本号 |
|
|
22
|
-
| `npm test` | **
|
|
22
|
+
| `npm test` | **3400 项**(47 个套件,`node tools/test-count.mjs` 核准、失败 0) |
|
|
23
23
|
| `npm pack --dry-run` | **129 个文件 / 17.1 MB**(包);`data/cache`、运行数据、`config.json`、`src/`、`scripts/`、`tools/` 均不进包 |
|
|
24
24
|
## 一、版本号规则
|
|
25
25
|
|
|
@@ -323,3 +323,24 @@ Measure-Command { Invoke-RestMethod -Method Post -Uri http://127.0.0.1:3080/api/
|
|
|
323
323
|
2. 配了云端语音 Key 时,日志出现云端合成;
|
|
324
324
|
3. 念诗↔说书互不抢锁;待命关刷新后问候仍有声;
|
|
325
325
|
4. 快速连说两句只回一次(ASR 单飞生效)。
|
|
326
|
+
|
|
327
|
+
## 十八、2026-11-07 凌晨批次(B89–B90:1.1.61 → 1.1.62)待重启核对
|
|
328
|
+
|
|
329
|
+
> 覆盖:413 送达、BOM、SSE 非对象帧、点播意图、APE 判停、云端 TTS 成本熔断、情绪定时器。
|
|
330
|
+
> 客户端刷新(`Ctrl+F5`);宿主改动(http/body/respond/cloud-tts/persona/pet)需重启 dsh web。
|
|
331
|
+
|
|
332
|
+
| # | 改动 | 为什么 | 怎么验证 |
|
|
333
|
+
|---|------|--------|----------|
|
|
334
|
+
| 1 | 超限请求能收到 413 | 原来先 `destroy()` 再回包,客户端只看到连接重置 | 拖一个超大文件导入备份:应提示「太大」而不是网络错误 |
|
|
335
|
+
| 2 | 带 BOM 的 JSON 能解析 | `JSON.parse` 遇 BOM 必抛,带 BOM 的备份包被判 400 | 用 Windows 记事本另存的备份包导入:应成功 |
|
|
336
|
+
| 3 | 非对象 SSE 帧不再回退 | `data: null` 让客户端读 `.error` 抛错 → 白回退一轮 `/chat` | 正常对话不出现「白烧一轮」的延迟 |
|
|
337
|
+
| 4 | 点播意图收紧 | 「换个说法/换个故事/换个声音」被当成念诗 | 说「换个说法」:应回答而不是念诗 |
|
|
338
|
+
| 5 | 云端 TTS 成本熔断可靠 | 用量文件坏掉后限制彻底失效(fail-open) | 把 `cloud-usage.json` 改成目录后再请求:应仍受限并留 `CLOUD-USAGE-FAIL` |
|
|
339
|
+
| 6 | APE 判停不被哨兵带偏 | 首帧 -160 会让噪声底永远回不来(每段等满 6 秒) | 切「自适应」端点后正常说话:停顿应在 1–2 秒内收 |
|
|
340
|
+
| 7 | 情绪定时器可清理 | `setMood` 的回落定时器没有 dispose,组件销毁后还会改状态 | 刷新/卸载页面后不再有残留情绪切换 |
|
|
341
|
+
|
|
342
|
+
### 重启后自检(3 条)
|
|
343
|
+
|
|
344
|
+
1. 菜单版本显示 **1.1.62**;
|
|
345
|
+
2. 超大文件导入提示「太大」而不是网络错误;
|
|
346
|
+
3. 说「换个说法」不会被念诗打断。
|
|
@@ -134,3 +134,7 @@
|
|
|
134
134
|
| B89b | 2026-11-07 | 客户端网络分身:非对象 SSE 帧进 events(null 让 chat 读 `.error` 抛错白回退一轮)/ 恢复快捷键 keyCode 兜底越权;新增 `test-net-client.mjs`(122+4 变异体) | 双 tsc 0 / 3258 项 0 失败 | 见 git |
|
|
135
135
|
| B89c | 2026-11-07 | 纯函数工具分身:切句器句首标点卡死 / 书名劫持陈述 / 否定句反着做 / 脏 fallback 透传 TTS / `lock(0)` 闭麦 60s 与 expire 界线 / 对仗分类 trim;新增 `test-utils-pure.mjs`(153) | 双 tsc 0 / 3258 项 0 失败 | 见 git |
|
|
136
136
|
| B89d | 2026-11-07 | 主代理:`/chat` 超时补 `TimeoutError`(23) / endpoint 只留 setter 一个写入口 / 多文件拖入先提示「一次一张」+ `test-multidrop.mjs`(10) / 坑 49 两种超限语义 / story 超限注释改真 | 双 tsc 0 / 3258 项 0 失败 | 见 git |
|
|
137
|
+
| B90a | 2026-11-07 | 主代理:`stripStageDirections` 去掉 60 字上限 / `createSentenceBuffer` 硬切不劈代理对(契约同步)/ 语速读侧 trim | 双 tsc 0 / 3400 项 0 失败 | 见 git |
|
|
138
|
+
| B90b | 2026-11-07 | 人格与云端语音分身:阶段语气防原型链 / 云端响应 16MB 上限(声明·流式·错误页)/ 记账写盘失败不再 fail-open(进程内兜底);新增 `test-persona-cloud.mjs`(139+4 变异体) | 双 tsc 0 / 3400 项 0 失败 | 见 git |
|
|
139
|
+
| B90c | 2026-11-07 | 客户端粘合分身:点播劫持追问 / 句末标点整句失效 / 典故成语播报反了 / APE 判停 NaN 与 -160 哨兵 / `steadyWindowFrames` 写死 8 / 气泡 trim / `useLazyRef` 假值重建;新增 `test-client-glue.mjs`(113+6 变异体) | 双 tsc 0 / 3400 项 0 失败 | 见 git |
|
|
140
|
+
| B90d | 2026-11-07 | 主代理:客户端情绪定时器加 dispose 与 holdMs 夹紧 / 碗数负数归零 / `pet.setMood` 情绪白名单 | 双 tsc 0 / 3400 项 0 失败 | 见 git |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-chubby-whale",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.62",
|
|
4
4
|
"description": "DSH 网页版桌面宠物「肥鲸」——蓝发鲸鱼娘,固定在 harness 页面右下角:会眨眼、能拖拽、点击可聊天,支持语音对话、念诗说书、饭点提醒。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "node scripts/gen-version.mjs && node scripts/check-bom.mjs && tsc -p tsconfig.json && tsc -p tsconfig.client.json && esbuild src/client.ts --bundle --format=iife --external:react --charset=utf8 --outfile=dist/client.js",
|
|
76
76
|
"prepublishOnly": "npm run build",
|
|
77
|
-
"test": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/check-imports.mjs && node scripts/gen-module-index.mjs --check && node scripts/check-boundaries.mjs && node scripts/check-diag-keys.mjs && node scripts/check-text.mjs && node scripts/test.mjs && node scripts/test-chat-limits.mjs && node scripts/test-stream-ledger.mjs && node scripts/test-story-security.mjs && node scripts/test-behavior-regressions.mjs && node scripts/verify-voice.mjs && node scripts/smoke-client.mjs && node scripts/ape-bench.mjs && node scripts/smoke-host.mjs && node scripts/test-voice-queue.mjs && node scripts/test-tts-engine.mjs && node scripts/test-data-layer.mjs && node scripts/test-repos.mjs && node scripts/test-personality.mjs && node scripts/test-story-player.mjs && node scripts/test-chat-routes.mjs && node scripts/test-menu-actions.mjs && node scripts/test-story-client.mjs && node scripts/test-story-auto.mjs && node scripts/test-content-routes.mjs && node scripts/test-dataport-poem.mjs && node scripts/test-render-layer.mjs && node scripts/test-store-cache.mjs && node scripts/test-actions-rest.mjs && node scripts/test-misc-routes.mjs && node scripts/test-chat-client.mjs && node scripts/test-prefs-config.mjs && node scripts/test-media-reminders.mjs && node scripts/test-image-reader.mjs && node scripts/test-boundaries-guard.mjs && node scripts/test-assembly.mjs && node scripts/test-asr-concurrency.mjs && node scripts/test-host-http.mjs && node scripts/test-entry-narration.mjs && node scripts/test-poem-narration.mjs && node scripts/test-multidrop.mjs && node scripts/test-utils-pure.mjs && node scripts/test-net-client.mjs && node scripts/test-voice-bridge.mjs && node scripts/platform-check.mjs",
|
|
77
|
+
"test": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && node scripts/check-imports.mjs && node scripts/gen-module-index.mjs --check && node scripts/check-boundaries.mjs && node scripts/check-diag-keys.mjs && node scripts/check-text.mjs && node scripts/test.mjs && node scripts/test-chat-limits.mjs && node scripts/test-stream-ledger.mjs && node scripts/test-story-security.mjs && node scripts/test-behavior-regressions.mjs && node scripts/verify-voice.mjs && node scripts/smoke-client.mjs && node scripts/ape-bench.mjs && node scripts/smoke-host.mjs && node scripts/test-voice-queue.mjs && node scripts/test-tts-engine.mjs && node scripts/test-data-layer.mjs && node scripts/test-repos.mjs && node scripts/test-personality.mjs && node scripts/test-story-player.mjs && node scripts/test-chat-routes.mjs && node scripts/test-menu-actions.mjs && node scripts/test-story-client.mjs && node scripts/test-story-auto.mjs && node scripts/test-content-routes.mjs && node scripts/test-dataport-poem.mjs && node scripts/test-render-layer.mjs && node scripts/test-store-cache.mjs && node scripts/test-actions-rest.mjs && node scripts/test-misc-routes.mjs && node scripts/test-chat-client.mjs && node scripts/test-prefs-config.mjs && node scripts/test-media-reminders.mjs && node scripts/test-image-reader.mjs && node scripts/test-boundaries-guard.mjs && node scripts/test-assembly.mjs && node scripts/test-asr-concurrency.mjs && node scripts/test-host-http.mjs && node scripts/test-entry-narration.mjs && node scripts/test-poem-narration.mjs && node scripts/test-multidrop.mjs && node scripts/test-utils-pure.mjs && node scripts/test-net-client.mjs && node scripts/test-persona-cloud.mjs && node scripts/test-client-glue.mjs && node scripts/test-voice-bridge.mjs && node scripts/platform-check.mjs",
|
|
78
78
|
"version:check": "node tools/version-check.mjs",
|
|
79
79
|
"typecheck": "node scripts/gen-version.mjs && tsc -p tsconfig.json --noEmit && tsc -p tsconfig.client.json --noEmit",
|
|
80
80
|
"smoke:client": "node scripts/smoke-client.mjs",
|