dsh-fish-soul 0.19.28 → 0.19.30
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 +1 -1
- package/lib/client.models.js +11 -1
- package/lib/config-schema.js +4 -1
- package/lib/data-dir.js +68 -15
- package/lib/douyin-social-pure.js +344 -0
- package/lib/douyin-social.js +2 -331
- package/lib/index-context.js +97 -0
- package/lib/index.js +2 -88
- package/lib/routes-v07.js +3 -1
- package/lib/routes.js +30 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/client.models.js
CHANGED
|
@@ -484,6 +484,12 @@ window.__ModuleLoader__.load({
|
|
|
484
484
|
if (r?.ok) load();
|
|
485
485
|
else notify(r?.error ?? "保存失败");
|
|
486
486
|
}
|
|
487
|
+
const [petToken, setPetToken] = react.useState(null); // generate 当次返回的明文,只留到用户复制走
|
|
488
|
+
async function petTokenAction(action) { // 桌面宠物互通令牌:generate / revoke
|
|
489
|
+
const r = await api("POST", "/desktop/pet-token", { action });
|
|
490
|
+
if (r?.ok) { setPetToken(action === "generate" ? (r.token ?? null) : null); load(); }
|
|
491
|
+
else notify(r?.error ?? "操作失败");
|
|
492
|
+
}
|
|
487
493
|
async function test() {
|
|
488
494
|
setBusy(true); setResult(null);
|
|
489
495
|
const r = await api("POST", "/web/test", { query: "今天有什么新闻" });
|
|
@@ -515,7 +521,11 @@ window.__ModuleLoader__.load({
|
|
|
515
521
|
{ value: "memory", label: "只记忆+上网" }, { value: "master", label: "只对主人放开" }, { value: "all", label: "全放开" }
|
|
516
522
|
] })),
|
|
517
523
|
Row({ title: "桌面会话继承主人身份", desc: "开着时任何 DSH 桌面会话都被当成主人,recall 能读到全部私聊记忆。同一台机器既跑工作会话又跑 QQ 人格时建议关掉" },
|
|
518
|
-
h(Switch, { label: "桌面会话继承主人身份", checked: w.desktopAsMaster !== false, onChange: (v) => saveDesktopAsMaster(v) }))
|
|
524
|
+
h(Switch, { label: "桌面会话继承主人身份", checked: w.desktopAsMaster !== false, onChange: (v) => saveDesktopAsMaster(v) })),
|
|
525
|
+
Row({ title: "桌面宠物互通令牌", desc: (data.desktopPet?.hasToken ? `桌宠端调用 /life/* 需带这个令牌(Authorization: Bearer …)。${petToken ? "请复制到桌宠端配置 —— 它只显示这一次" : "已配置"}` : "未启用鉴权(同机进程可调用)") },
|
|
526
|
+
data.desktopPet?.hasToken ? State("done", petToken ?? data.desktopPet?.tokenMasked ?? "") : null,
|
|
527
|
+
Button({ onClick: () => petTokenAction("generate") }, data.desktopPet?.hasToken ? "重新生成" : "生成令牌"),
|
|
528
|
+
data.desktopPet?.hasToken ? Button({ onClick: () => petTokenAction("revoke") }, "撤销") : null)));
|
|
519
529
|
}
|
|
520
530
|
|
|
521
531
|
/** 语音:听 QQ 语音 + 发语音 */
|
package/lib/config-schema.js
CHANGED
|
@@ -132,7 +132,10 @@ export function fishSoulConfigSchema(z) {
|
|
|
132
132
|
sessionAllow: z.string().default('memory'),
|
|
133
133
|
// #255:桌面会话(channel=dsh)是否继承主人身份(默认 true 保持现行为)。
|
|
134
134
|
// 关掉后 dsh 会话 ownerId 保持 UNKNOWN,recall 不返回私聊记忆。
|
|
135
|
-
desktopAsMaster: z.boolean().default(true)
|
|
135
|
+
desktopAsMaster: z.boolean().default(true),
|
|
136
|
+
// 桌面宠物互通令牌(/life/context、/life/interaction 的 Bearer 校验)。
|
|
137
|
+
// 空 = 不启用鉴权(向后兼容,同机任意进程可调用);非空 = 必须带 Authorization: Bearer <token>。
|
|
138
|
+
desktopPetToken: z.string().default('')
|
|
136
139
|
}).default({}),
|
|
137
140
|
onboarding: z.object({ dismissed: z.boolean().default(false) }).default({}),
|
|
138
141
|
storage: z.object({ auto: z.boolean().default(true), keep: z.number().default(10), warnMB: z.number().default(1024), freeMB: z.number().default(512) }).default({}),
|
package/lib/data-dir.js
CHANGED
|
@@ -11,12 +11,40 @@
|
|
|
11
11
|
* 通过才改名成目标,旧目录改名 `fish-moved-<时间>` 留档;
|
|
12
12
|
* - 任何一步失败 → **回退旧目录继续跑,绝不空库启动**(半份数据比没有更糟)。
|
|
13
13
|
*/
|
|
14
|
-
import { cp, mkdir, readdir, rename, rm, stat } from 'node:fs/promises';
|
|
15
|
-
import { existsSync } from 'node:fs';
|
|
14
|
+
import { cp, mkdir, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
16
16
|
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
17
|
-
import { dshHome, configuredDataDir, setActiveDataDir, getKv, setKv } from './db.js';
|
|
17
|
+
import { dshHome, configPath, configuredDataDir, setActiveDataDir, getKv, setKv } from './db.js';
|
|
18
18
|
import { stampLocal } from './time-util.js';
|
|
19
19
|
|
|
20
|
+
/** 配置文件里「上次生效的数据目录」的键名(搬完家写回,下次启动据此判断从哪搬)。 */
|
|
21
|
+
const ACTIVE_KEY = 'dataDirActive';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 读配置文件原文(JSON 对象;读不到 / 不是对象 → `{}`)。
|
|
25
|
+
* 写回时必须保留用户其它键,不能整份覆盖。
|
|
26
|
+
*/
|
|
27
|
+
function readConfig() {
|
|
28
|
+
try {
|
|
29
|
+
const v = JSON.parse(readFileSync(configPath(), 'utf8').replace(/^\uFEFF/, ''));
|
|
30
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
31
|
+
} catch { return {}; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 把配置写回去(保留其它键;写不进去只影响下次启动从哪搬,不影响本次)。 */
|
|
35
|
+
async function writeConfig(patch) {
|
|
36
|
+
const next = { ...readConfig(), ...patch };
|
|
37
|
+
try { await writeFile(configPath(), JSON.stringify(next, null, '\t'), 'utf8'); } catch { /* 同上 */ }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 上次生效的数据目录(配置文件里记的;没记 / 记的目录已不在 → `''`)。 */
|
|
41
|
+
function lastActiveDir() {
|
|
42
|
+
const v = String(readConfig()[ACTIVE_KEY] ?? '').trim();
|
|
43
|
+
if (v === '') return '';
|
|
44
|
+
// 目录已不在:当作没记(用户手删了留档、或换了机器),否则会试图从空处搬家
|
|
45
|
+
return existsSync(v) ? resolve(v) : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
20
48
|
/** 目录里有东西吗(跳过点开头的残留文件)。 */
|
|
21
49
|
async function hasContent(dir) {
|
|
22
50
|
try {
|
|
@@ -57,29 +85,51 @@ export async function verifyCopy(from, to) {
|
|
|
57
85
|
}
|
|
58
86
|
|
|
59
87
|
/**
|
|
60
|
-
*
|
|
88
|
+
* 启动时决定数据放哪,必要时把数据搬到新目录。
|
|
61
89
|
*
|
|
62
90
|
* 必须在 `openDatabase()` 之前调用 —— 库路径就是这里钉下去的。
|
|
91
|
+
*
|
|
92
|
+
* 「从哪搬」不再只看默认目录:配置文件里记着上次生效的目录(`dataDirActive`),
|
|
93
|
+
* 所以 自定义→默认、自定义A→自定义B 都能搬。没记(老安装)就按默认目录算。
|
|
63
94
|
* @returns {Promise<{dir: string, moved: boolean, archived: string}>} archived = 旧目录改成的留档路径(没搬为空)
|
|
64
95
|
*/
|
|
65
96
|
export async function ensureDataDir({ log = () => {}, copy = cp } = {}) {
|
|
66
|
-
const
|
|
97
|
+
const last = lastActiveDir();
|
|
98
|
+
const from = last || join(dshHome(), 'fish-soul');
|
|
67
99
|
const want = configuredDataDir();
|
|
100
|
+
if (want === null && last !== '' && resolve(last) !== resolve(join(dshHome(), 'fish-soul'))) {
|
|
101
|
+
// 用户清空了配置 = 「搬回默认目录」。默认目录就是目标,走下面同一条搬家流程。
|
|
102
|
+
return moveTo(join(dshHome(), 'fish-soul'), { from, log, copy, back: true });
|
|
103
|
+
}
|
|
68
104
|
if (want === null || resolve(want) === resolve(from)) {
|
|
69
|
-
//
|
|
105
|
+
// 没配(或配成上次在用的目录)时**不缓存**:让 fishSoulDir() 每次现拼 dshHome(),
|
|
70
106
|
// 否则测试里换 DSH_HOME 会全部串到第一个 home 上(smoke 第 20 组就是这么挂的)。
|
|
71
|
-
|
|
72
|
-
|
|
107
|
+
// ⚠️ 只有「回到默认」才清缓存;配的正好是上次在用的自定义目录时要钉住它。
|
|
108
|
+
if (want === null) setActiveDataDir(null);
|
|
109
|
+
else setActiveDataDir(want);
|
|
110
|
+
return { dir: want ?? from, moved: false, archived: '' };
|
|
73
111
|
}
|
|
112
|
+
return moveTo(want, { from, log, copy });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 把数据从 `from` 搬到 `want`(目标已确认是空的或不存在)。
|
|
117
|
+
* `back: true` 表示搬回默认目录 —— 成功后不写 dataDirActive(默认目录不需要记)。
|
|
118
|
+
*/
|
|
119
|
+
async function moveTo(want, { from, log, copy, back = false }) {
|
|
74
120
|
if (await hasContent(want)) {
|
|
75
|
-
|
|
76
|
-
|
|
121
|
+
// 目标已经有东西(上次搬过 / 用户自己搬过)→ 直接用。顺手把「上次生效」钉过去,
|
|
122
|
+
// 这样下次再改目录才知道从这搬。
|
|
123
|
+
if (!back) await writeConfig({ [ACTIVE_KEY]: resolve(want) });
|
|
124
|
+
setActiveDataDir(back ? null : want);
|
|
125
|
+
return { dir: want, moved: false, archived: '' };
|
|
77
126
|
}
|
|
78
127
|
if (!(await hasContent(from))) {
|
|
79
128
|
// 全新安装:直接在新位置起,没有可搬的东西
|
|
80
129
|
await mkdir(want, { recursive: true });
|
|
81
|
-
|
|
82
|
-
|
|
130
|
+
if (!back) await writeConfig({ [ACTIVE_KEY]: resolve(want) });
|
|
131
|
+
setActiveDataDir(back ? null : want);
|
|
132
|
+
return { dir: want, moved: false, archived: '' };
|
|
83
133
|
}
|
|
84
134
|
|
|
85
135
|
log('info', `[fish-soul] 数据目录搬家:${from} → ${want}`);
|
|
@@ -96,7 +146,8 @@ export async function ensureDataDir({ log = () => {}, copy = cp } = {}) {
|
|
|
96
146
|
} catch (error) {
|
|
97
147
|
// 半份数据不能留下 —— 下次启动会被当成「已经有内容」直接用
|
|
98
148
|
try { await rm(incoming, { recursive: true, force: true }); } catch { /* 删不掉也不影响回退 */ }
|
|
99
|
-
|
|
149
|
+
// 回退到「上次在用的目录」:可能是默认目录(老安装),也可能是上一个自定义目录(A→B 失败)
|
|
150
|
+
setActiveDataDir(lastActiveDir() === '' ? null : from);
|
|
100
151
|
const msg = error instanceof Error ? error.message : String(error);
|
|
101
152
|
log('error', `[fish-soul] 数据目录搬家失败,继续用 ${from}:${msg}`);
|
|
102
153
|
throw error;
|
|
@@ -112,7 +163,9 @@ export async function ensureDataDir({ log = () => {}, copy = cp } = {}) {
|
|
|
112
163
|
// 改名失败不影响使用:数据已经在新位置了,旧目录当成多余的副本
|
|
113
164
|
log('warn', `[fish-soul] 旧数据目录改名失败(不影响使用):${error instanceof Error ? error.message : String(error)}`);
|
|
114
165
|
}
|
|
115
|
-
|
|
166
|
+
if (!back) await writeConfig({ [ACTIVE_KEY]: resolve(want) });
|
|
167
|
+
else await writeConfig({ [ACTIVE_KEY]: '' });
|
|
168
|
+
setActiveDataDir(back ? null : want);
|
|
116
169
|
// 留档路径同时记进新库(openDatabase 之后才调 importArchives),这样面板能列出来删
|
|
117
170
|
return { dir: want, moved: true, archived };
|
|
118
171
|
}
|
|
@@ -175,7 +228,7 @@ export async function removeArchived(db, dir) {
|
|
|
175
228
|
export function checkDataDir(value, current) {
|
|
176
229
|
const raw = String(value ?? '').trim();
|
|
177
230
|
if (raw === '') return ''; // 空 = 用默认,永远合法
|
|
178
|
-
if (!isAbsolute(raw)) return '请填完整路径,比如 D
|
|
231
|
+
if (!isAbsolute(raw)) return '请填完整路径,比如 D:\\fish-soul-data';
|
|
179
232
|
const next = resolve(raw);
|
|
180
233
|
const cur = resolve(String(current ?? ''));
|
|
181
234
|
if (next === cur) return ''; // 没变,允许(保存等于什么都没做)
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* douyin-social-pure.js —— 从 douyin-social.js 拆出的纯函数与常量(2026-12-03)。
|
|
3
|
+
*
|
|
4
|
+
* 时间预算表 / 心情主题 / 评论键 / 图片边界 / deadline 等不碰页面的部分。
|
|
5
|
+
* 主文件保留 re-export,外部 import 路径不变。
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { statSync, lstatSync, realpathSync } from 'node:fs';
|
|
9
|
+
import { extname, join, resolve } from 'node:path';
|
|
10
|
+
import { sleep } from './time-util.js';
|
|
11
|
+
import { isInside } from './gateway-util.js';
|
|
12
|
+
|
|
13
|
+
export const PAGE_TIMING = {
|
|
14
|
+
evalTimeoutMs: 12_000, // 单次 eval 的上限
|
|
15
|
+
waitBudgetMs: 60_000, // waitFor 的总预算
|
|
16
|
+
// 🔴 下限不是拍脑袋:单次导航上限(browser.mjs 内写死 15000)
|
|
17
|
+
// + 导航后等待(最多 2500)+ settle 尾段(最多 5500)= 23000。
|
|
18
|
+
// 给 15000 ⇒ 慢网(导航 >6.5s)时页面明明跳成功了,settle 却挤不进预算、
|
|
19
|
+
// 被误判成「导航超时:settle 没睡完」(2026-11-22 看评论真机报错)。
|
|
20
|
+
gotoTimeoutMs: 24_000, // 单次导航的上限(含 settle,见上面推导)
|
|
21
|
+
|
|
22
|
+
openWorkBudgetMs: 30_000, // openWork 整操作的总预算
|
|
23
|
+
replyBudgetMs: 30_000, // reply 整操作的总预算
|
|
24
|
+
// 转码单独给预算:视频传上去后要等抖音转码,实测 180 秒都还没转完。
|
|
25
|
+
// 「上传中」那行字不消**不代表**没好,所以只能等 video 元素真能播。
|
|
26
|
+
// 🔴 预算不能贴着观测到的最坏值:180 秒 == 实测最坏值 ⇒ 慢的日子必然
|
|
27
|
+
// TRANSCODE_TIMEOUT,而钱那时**已经花出去了**(重试要再生成一条 = 花两次钱)
|
|
28
|
+
// ⇒ 抬到 5 分钟,留一倍余量。
|
|
29
|
+
transcodeBudgetMs: 300_000,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 浏览器锁比转码预算多留的余量:从页面环节各自的最坏超时**推导**,不写死常量。
|
|
34
|
+
*
|
|
35
|
+
* 锁里除了转码,还有探活(≈11s)/ 导航 / 填表几次 eval / 发布确认 —— 每一段都有
|
|
36
|
+
* 自己的超时上限,全部加总才是锁真正要扛的最坏耗时。写死一个数 = 改了上面某个
|
|
37
|
+
* 超时忘了改这里 ⇒ 锁提前超时(exclusive 超时只报错**不放锁**,锁要等 fn 真 settle
|
|
38
|
+
* ⇒ 后面所有页面操作排队,主人还以为视频没发出去)。
|
|
39
|
+
*/
|
|
40
|
+
export const VIDEO_LOCK_MARGIN_MS = PAGE_TIMING.gotoTimeoutMs + PAGE_TIMING.waitBudgetMs + 5 * PAGE_TIMING.evalTimeoutMs + 60_000;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 整操作的总预算(终点)。
|
|
44
|
+
*
|
|
45
|
+
* 终点同时管三件事:单次 eval 的超时、轮次之间的等待、还要不要发起下一次 eval。
|
|
46
|
+
* 只在轮次之间查时间是没用的 —— 页面卡死时 eval 自己就挂死(永不回包)。
|
|
47
|
+
*
|
|
48
|
+
* @param {number} totalMs 总预算(毫秒)
|
|
49
|
+
*/
|
|
50
|
+
export function deadline(totalMs) {
|
|
51
|
+
const end = Date.now() + totalMs;
|
|
52
|
+
const left = () => end - Date.now();
|
|
53
|
+
return {
|
|
54
|
+
left,
|
|
55
|
+
/** 到点了没 */
|
|
56
|
+
expired: () => left() <= 0,
|
|
57
|
+
/** 这次 eval 给多少超时:不超过上限,也不越过终点 */
|
|
58
|
+
timeoutFor: (cap) => Math.max(1, Math.min(cap, left())),
|
|
59
|
+
/** 这次该等多久:不超过原时长,也不越过终点 */
|
|
60
|
+
waitFor: (ms) => Math.max(0, Math.min(ms, left()))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const oneLine = (s, n) => String(s ?? '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
65
|
+
export const errText = (e) => String(e instanceof Error ? e.message : e);
|
|
66
|
+
|
|
67
|
+
export const IMAGE_EXT = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp']);
|
|
68
|
+
export const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 评论图片只能取工作区 `_stickers/` 里的图。
|
|
72
|
+
*
|
|
73
|
+
* 路径是模型写的 = 不可信:`..` 能拼出工作区外的文件,软链接 / junction 能把
|
|
74
|
+
* `_stickers/` 里的一项指到别处。所以边界收在**真实路径**上 ——
|
|
75
|
+
* 目录、软链接/junction 逃逸、非图片格式、超大图一律不发(关掉,不抛)。
|
|
76
|
+
*
|
|
77
|
+
* 信任根本身也要先验:`_stickers` 必须是普通目录 —— 它自己是 junction / 软链接的话,
|
|
78
|
+
* 真实路径整个落到工作区外,只拿 `realRoot` 去比是拦不住的。
|
|
79
|
+
*
|
|
80
|
+
* @param {string} rel `_stickers/xxx` 形状的相对路径
|
|
81
|
+
* @param {string} root 工作区里的 `_stickers` 目录
|
|
82
|
+
* @param {(level: string, msg: string) => void} log
|
|
83
|
+
* @returns {string|null} 校验过的真实路径;不合格返回 null
|
|
84
|
+
*/
|
|
85
|
+
export function safeStickerImagePath(rel, root, log) {
|
|
86
|
+
const deny = () => {
|
|
87
|
+
log('warn', `[fish-soul] 抖音评论图片越界,已忽略:${rel}`);
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
let rootStat;
|
|
91
|
+
try { rootStat = lstatSync(root); } catch { return null; } // 没有 _stickers 目录 = 没有可发的图
|
|
92
|
+
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
93
|
+
log('warn', `[fish-soul] 抖音评论图片根目录不可信(_stickers 不是普通目录),已拒绝:${rel}`);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const abs = resolve(root, rel.slice('_stickers/'.length));
|
|
97
|
+
if (!isInside(root, abs)) return deny();
|
|
98
|
+
if (!IMAGE_EXT.has(extname(abs).toLowerCase())) return null;
|
|
99
|
+
let realRoot, real;
|
|
100
|
+
try {
|
|
101
|
+
realRoot = realpathSync.native(root);
|
|
102
|
+
real = realpathSync.native(abs);
|
|
103
|
+
} catch { return null; }
|
|
104
|
+
if (!isInside(realRoot, real)) return deny();
|
|
105
|
+
try {
|
|
106
|
+
const st = statSync(real);
|
|
107
|
+
if (!st.isFile() || st.size > MAX_IMAGE_BYTES) return null;
|
|
108
|
+
} catch { return null; }
|
|
109
|
+
return real;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 文字卡片(1080×1440 PNG,base64)。 */
|
|
113
|
+
export function cardJs(text, foot, theme) {
|
|
114
|
+
return `(async () => {
|
|
115
|
+
const text = ${JSON.stringify(text)};
|
|
116
|
+
const foot = ${JSON.stringify(foot)};
|
|
117
|
+
const themes = [['#FFF6E5', '#5B4636'], ['#EAF4FF', '#2F4A66'], ['#F3EEFF', '#4A3A6B'], ['#EAF7EE', '#2F5A3E'], ['#FFEFF1', '#6B3A44']];
|
|
118
|
+
const [bg, fg] = themes[${Number(theme) || 0} % themes.length];
|
|
119
|
+
const W = 1080, H = 1440;
|
|
120
|
+
const c = new OffscreenCanvas(W, H);
|
|
121
|
+
const g = c.getContext('2d');
|
|
122
|
+
g.fillStyle = bg; g.fillRect(0, 0, W, H);
|
|
123
|
+
g.fillStyle = fg; g.textBaseline = 'top';
|
|
124
|
+
const size = text.length > 80 ? 52 : text.length > 40 ? 62 : 76;
|
|
125
|
+
const font = (px) => px + 'px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif';
|
|
126
|
+
g.font = font(size);
|
|
127
|
+
const maxW = W - 200;
|
|
128
|
+
const lines = [];
|
|
129
|
+
for (const para of text.split('\\n')) {
|
|
130
|
+
let cur = '';
|
|
131
|
+
for (const ch of para) {
|
|
132
|
+
if (g.measureText(cur + ch).width > maxW && cur !== '') { lines.push(cur); cur = ch; } else cur += ch;
|
|
133
|
+
}
|
|
134
|
+
lines.push(cur);
|
|
135
|
+
}
|
|
136
|
+
const lh = Math.round(size * 1.6);
|
|
137
|
+
let y = Math.max(120, Math.round((H - lines.length * lh) / 2) - 40);
|
|
138
|
+
for (const l of lines) { g.fillText(l, 100, y); y += lh; }
|
|
139
|
+
g.globalAlpha = 0.55; g.font = font(34);
|
|
140
|
+
g.fillText(foot, 100, H - 150);
|
|
141
|
+
const blob = await c.convertToBlob({ type: 'image/png' });
|
|
142
|
+
const u = new Uint8Array(await blob.arrayBuffer());
|
|
143
|
+
let s = '';
|
|
144
|
+
for (let i = 0; i < u.length; i += 0x8000) s += String.fromCharCode.apply(null, u.subarray(i, i + 0x8000));
|
|
145
|
+
return btoa(s);
|
|
146
|
+
})()`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 心情 → cardJs themes 的下标(顺序:米黄暖 / 浅蓝丧 / 淡紫梦 / 浅绿清 / 粉甜)。 */
|
|
150
|
+
export const MOOD_THEME = { warm: 0, blue: 1, dream: 2, fresh: 3, pink: 4 };
|
|
151
|
+
export const MOOD_LIST = 'warm 暖/治愈、blue 丧/低落、dream 梦幻/恍惚、fresh 清新/日常、pink 甜/开心';
|
|
152
|
+
|
|
153
|
+
/** 让模型给文案配心情,返回 {theme, reason};解析不出来就随机一个主题,不耽误发布。 */
|
|
154
|
+
export function pickMoodTheme(raw, random = Math.random) {
|
|
155
|
+
const fallback = { theme: Math.floor(random() * 5), reason: '' };
|
|
156
|
+
const m = String(raw ?? '').match(/\{[^{}]*\}/s);
|
|
157
|
+
if (!m) return fallback;
|
|
158
|
+
let j;
|
|
159
|
+
try { j = JSON.parse(m[0]); } catch { return fallback; }
|
|
160
|
+
const mood = String(j?.mood ?? '').toLowerCase().trim();
|
|
161
|
+
const theme = Object.hasOwn(MOOD_THEME, mood) ? MOOD_THEME[mood] : fallback.theme;
|
|
162
|
+
return { theme, reason: String(j?.reason ?? '').trim().slice(0, 40) };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 从抖音推荐的歌里挑一首(只能挑列表里的,模型编的名字不算);挑不出来返回 ''。 */
|
|
166
|
+
export function pickRecommendedSong(raw, songs) {
|
|
167
|
+
const list = (Array.isArray(songs) ? songs : []).map((s) => String(s ?? '').trim()).filter(Boolean);
|
|
168
|
+
if (!list.length) return '';
|
|
169
|
+
const out = String(raw ?? '').trim().replace(/^["'「『\s]+|["'」』\s]+$/g, '');
|
|
170
|
+
if (!out) return '';
|
|
171
|
+
if (list.includes(out)) return out;
|
|
172
|
+
return [...list].sort((a, b) => b.length - a.length).find((s) => out.includes(s)) ?? '';
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 评论去重用的 id:作品 + 谁 + 说了什么。 */
|
|
176
|
+
export function commentKey(workId, author, content) {
|
|
177
|
+
return `${workId}:${createHash('sha1').update(`${author}\n${content}`).digest('hex').slice(0, 16)}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 评论去重 id:优先用评论自己的 cid(`作品:cid:xxx`),没有 cid 才落回文本哈希。
|
|
182
|
+
*
|
|
183
|
+
* 文本 key 的毛病:作者改了评论,正文变了 → key 变了 → 同一条评论被当成新的又回一遍
|
|
184
|
+
* (在真实账号上回两遍)。cid 是抖音给的评论 id,不随正文变。
|
|
185
|
+
*
|
|
186
|
+
* @param {string} workId 作品 id
|
|
187
|
+
* @param {string} cid 评论 id(没有就空串)
|
|
188
|
+
* @param {string} author 作者昵称
|
|
189
|
+
* @param {string} content 评论正文
|
|
190
|
+
* @returns {string} 去重 id
|
|
191
|
+
*/
|
|
192
|
+
export function commentId(workId, cid, author, content) {
|
|
193
|
+
const c = String(cid ?? '').trim();
|
|
194
|
+
if (c !== '') return `${workId}:cid:${c}`;
|
|
195
|
+
return commentKey(workId, author, content);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ───────────── 页面脚本 ─────────────
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
export async function realClick(br, x, y, timeoutMs) {
|
|
202
|
+
for (const type of ['mousePressed', 'mouseReleased']) {
|
|
203
|
+
await br.send('Input.dispatchMouseEvent', { type, x, y, button: 'left', clickCount: 1, buttons: type === 'mousePressed' ? 1 : 0 }, br.sessionId, timeoutMs);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 找「使用」按钮,并用**引用**取它的几何。
|
|
209
|
+
*
|
|
210
|
+
* 为什么不继续用 `[class*="apply-btn"]`:那是抖音的构建哈希类名,改版就断。
|
|
211
|
+
* 无障碍树里它叫 `button` / name=`使用`,是页面**语义**的一部分,稳得多。
|
|
212
|
+
*
|
|
213
|
+
* 两道保险:
|
|
214
|
+
* ① 元素可能已被页面换掉 —— `DOM.getBoxModel` 对失效引用**报错**,
|
|
215
|
+
* 而 `getBoundingClientRect()` 会静默返回 0×0(以前就点过 (0,0))。
|
|
216
|
+
* ② 拿不到语义节点 / 几何 ⇒ 明确返回「没找到」,由调用方报「没有出现使用按钮」。
|
|
217
|
+
*
|
|
218
|
+
* 真机依据(2026-11-20,创作者中心发布图文页):hover 之后
|
|
219
|
+
* `Accessibility.queryAXTree(root, {accessibleName:'使用', role:'button'})` 精确命中 1 个,
|
|
220
|
+
* backendNodeId → getBoxModel 的几何与 getBoundingClientRect 一致。
|
|
221
|
+
*
|
|
222
|
+
* @returns {Promise<{ok:boolean, x?:number, y?:number}>}
|
|
223
|
+
*/
|
|
224
|
+
export async function findApplyButton(br, timing, hoverAt) {
|
|
225
|
+
const sid = br.sessionId;
|
|
226
|
+
// 每一轮都重新 hover:按钮靠 CSS :hover 才从 visibility:hidden 变可见,
|
|
227
|
+
// 而 getBoxModel 对 hidden 元素照样返回几何 ⇒ 不 hover 就会「找到坐标但点空」。
|
|
228
|
+
if (hoverAt) await br.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: hoverAt.x, y: hoverAt.y }, sid).catch(() => {});
|
|
229
|
+
// depth:0 —— 只要 root 的 nodeId;拉整棵 DOM 在 40 万节点的页面上要 5 秒 / 100MB。
|
|
230
|
+
const doc = await br.send('DOM.getDocument', { depth: 0 }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
231
|
+
const rootId = doc?.root?.nodeId;
|
|
232
|
+
if (!rootId) return { ok: false, reason: 'read-failed', error: '读不到页面根节点(CDP 无响应?)' };
|
|
233
|
+
const q = await br.send('Accessibility.queryAXTree', { nodeId: rootId, accessibleName: '使用', role: 'button' }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
234
|
+
if (!q) return { ok: false, reason: 'read-failed', error: '无障碍树查询失败(CDP 无响应?)' };
|
|
235
|
+
// ⚠️ 可能命中多个:页面别处也可能有可见的「使用」。全都要,交给调用方按归属筛。
|
|
236
|
+
const nodes = (q.nodes || []).filter((n) => n.backendDOMNodeId);
|
|
237
|
+
if (!nodes.length) return { ok: false, reason: 'not-found' };
|
|
238
|
+
const candidates = [];
|
|
239
|
+
for (const n of nodes) {
|
|
240
|
+
const box = await br.send('DOM.getBoxModel', { backendNodeId: n.backendDOMNodeId }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
241
|
+
const quad = box?.model?.content;
|
|
242
|
+
if (!quad || quad.length < 8) continue;
|
|
243
|
+
const x = Math.round((quad[0] + quad[2] + quad[4] + quad[6]) / 4);
|
|
244
|
+
const y = Math.round((quad[1] + quad[3] + quad[5] + quad[7]) / 4);
|
|
245
|
+
if (x > 0 && y > 0) candidates.push({ x, y, backendNodeId: n.backendDOMNodeId });
|
|
246
|
+
}
|
|
247
|
+
return candidates.length ? { ok: true, candidates } : { ok: false, reason: 'not-found' };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* 这个按钮节点(或坐标上的元素),是不是落在「某个含该歌名的歌卡」里面?
|
|
252
|
+
*
|
|
253
|
+
* 为什么要这一步:AX 查询的范围是**整棵树**,命中的是 DOM 顺序第一个可见的「使用」。
|
|
254
|
+
* 页面别处只要有一个可见的「使用」按钮,就会点到它 —— 而且后续歌名确认会失败,
|
|
255
|
+
* 报出来的却是「已点击使用,但编辑页未确认显示歌名」,把错误指向了别处。
|
|
256
|
+
* 旧代码用「在目标卡的子树里找按钮」天然避开了这件事,换成语义定位后必须显式补回来。
|
|
257
|
+
*
|
|
258
|
+
* 🔴 优先直接用 AX 节点的 `backendNodeId` 往上查祖先链:
|
|
259
|
+
* 不用 `DOM.getNodeForLocation(x, y)` 去反查 —— 真机上音乐抽屉是 fixed 浮层,
|
|
260
|
+
* 鼠标移开或 hover 抖动的一帧里按钮可能短暂变成 `visibility: hidden` / `pointer-events: none`,
|
|
261
|
+
* 或者被子层盖住,`getNodeForLocation` 就会打穿到抽屉底板或背景层,误报「不在选中的那首歌上」。
|
|
262
|
+
*
|
|
263
|
+
* @returns {Promise<boolean>} 读失败也返回 false(宁可这次不发,也不点错)
|
|
264
|
+
*/
|
|
265
|
+
export async function pointBelongsToCard(br, cand, music, timing) {
|
|
266
|
+
let backendNodeId = cand?.backendNodeId;
|
|
267
|
+
if (!backendNodeId && Number.isFinite(cand?.x) && Number.isFinite(cand?.y)) {
|
|
268
|
+
const hit = await br.send('DOM.getNodeForLocation', { x: cand.x, y: cand.y, includeUserAgentShadowDOM: false }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
269
|
+
backendNodeId = hit?.backendNodeId;
|
|
270
|
+
}
|
|
271
|
+
if (!backendNodeId) return false;
|
|
272
|
+
// describeNode 拿不到父链,改用 Runtime 从该节点往上走。
|
|
273
|
+
const resolved = await br.send('DOM.resolveNode', { backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
274
|
+
const objectId = resolved?.object?.objectId;
|
|
275
|
+
if (!objectId) return false;
|
|
276
|
+
try {
|
|
277
|
+
const r = await br.send('Runtime.callFunctionOn', {
|
|
278
|
+
objectId,
|
|
279
|
+
functionDeclaration: `function (want) {
|
|
280
|
+
const norm = (s) => String(s || '').replace(/\\s+/g, '');
|
|
281
|
+
const target = norm(want);
|
|
282
|
+
const songSel = '[class*="song-name"]';
|
|
283
|
+
for (let p = this; p && p !== document.body; p = p.parentElement) {
|
|
284
|
+
if (!p.querySelectorAll) continue;
|
|
285
|
+
const names = p.querySelectorAll(songSel);
|
|
286
|
+
if (names.length === 1) {
|
|
287
|
+
const sn = names[0];
|
|
288
|
+
const text = norm(sn.innerText || sn.textContent || '');
|
|
289
|
+
if (text === target || (target.length >= 2 && text.includes(target))) return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
}`,
|
|
294
|
+
arguments: [{ value: music }],
|
|
295
|
+
returnByValue: true,
|
|
296
|
+
}, br.sessionId, timing.evalTimeoutMs);
|
|
297
|
+
return r?.result?.value === true;
|
|
298
|
+
} catch {
|
|
299
|
+
return false;
|
|
300
|
+
} finally {
|
|
301
|
+
await br.send('Runtime.releaseObject', { objectId }, br.sessionId, timing.evalTimeoutMs).catch(() => {});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** 预算到期的哨兵:区分「没等到」和「等到的是假值」。 */
|
|
305
|
+
const BUDGET_OUT = Symbol('budget-out');
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 等 fn 出结果,最长等 budgetMs。
|
|
309
|
+
*
|
|
310
|
+
* 🔴 预算必须**包住 fn 这一次调用** —— 页面 renderer 卡死时 fn 自己就挂死
|
|
311
|
+
* (Runtime.evaluate 永不回包),只在轮次之间查时间没用:
|
|
312
|
+
* 配乐 6 轮 × 60 秒 = 锁被占 6 分钟(2026-11-15 巡检 P2)。
|
|
313
|
+
*
|
|
314
|
+
* @param {Function} fn 每轮调用一次;返回假值 / 抛错 = 还没等到
|
|
315
|
+
* @param {object} opts
|
|
316
|
+
* @param {number} opts.tries 最多试几轮
|
|
317
|
+
* @param {number} opts.gapMs 两轮之间隔多久
|
|
318
|
+
* @param {number} opts.budgetMs 总预算(毫秒);到点直接返回 null(非正数 = 不等,直接返回 null)
|
|
319
|
+
* @returns {Promise<any>} 等到的值;没等到返回 null
|
|
320
|
+
*/
|
|
321
|
+
export async function waitFor(fn, { tries = 10, gapMs = 1000, budgetMs = PAGE_TIMING.waitBudgetMs } = {}) {
|
|
322
|
+
const end = Date.now() + budgetMs;
|
|
323
|
+
for (let i = 0; i < tries; i++) {
|
|
324
|
+
const left = end - Date.now();
|
|
325
|
+
if (left <= 0) return null;
|
|
326
|
+
let timer;
|
|
327
|
+
const v = await Promise.race([
|
|
328
|
+
fn().catch(() => null),
|
|
329
|
+
new Promise((resolve) => { timer = setTimeout(() => resolve(BUDGET_OUT), left); timer.unref?.(); }),
|
|
330
|
+
]).finally(() => clearTimeout(timer));
|
|
331
|
+
if (v === BUDGET_OUT) return null;
|
|
332
|
+
if (v) return v;
|
|
333
|
+
const rest = end - Date.now();
|
|
334
|
+
if (rest <= 0) return null;
|
|
335
|
+
await sleep(Math.min(gapMs, rest));
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** 点编辑页上的「选择音乐」入口(真点,不是 JS click),返回点了没。 */
|
|
341
|
+
/** 页面活性检测(导出供测试)。renderer 卡死时 eval 会永远 pending,必须带超时竞速。
|
|
342
|
+
* 不通就 reload 一次再试;还不通返回 false,调用方别再往死页面上发操作。
|
|
343
|
+
* (2026-11-15 真机实录:创作者中心页挂着验证码 iframe 后整页 hung 死,
|
|
344
|
+
* Runtime.evaluate / Page.navigate 全部无响应,配乐两次报错的根因。) */
|
package/lib/douyin-social.js
CHANGED
|
@@ -73,338 +73,9 @@ const SEND_PATH = 'M17.5 30C23.851 30';
|
|
|
73
73
|
*
|
|
74
74
|
* 导出:浏览器锁的时长要从这里的转码预算推导(见 publishVideoWork),测试也要拿它核对。
|
|
75
75
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
waitBudgetMs: 60_000, // waitFor 的总预算
|
|
79
|
-
// 🔴 下限不是拍脑袋:单次导航上限(browser.mjs 内写死 15000)
|
|
80
|
-
// + 导航后等待(最多 2500)+ settle 尾段(最多 5500)= 23000。
|
|
81
|
-
// 给 15000 ⇒ 慢网(导航 >6.5s)时页面明明跳成功了,settle 却挤不进预算、
|
|
82
|
-
// 被误判成「导航超时:settle 没睡完」(2026-11-22 看评论真机报错)。
|
|
83
|
-
gotoTimeoutMs: 24_000, // 单次导航的上限(含 settle,见上面推导)
|
|
76
|
+
import { PAGE_TIMING, VIDEO_LOCK_MARGIN_MS, MOOD_THEME, pickMoodTheme, pickRecommendedSong, commentKey, commentId, deadline, oneLine, errText, IMAGE_EXT, MAX_IMAGE_BYTES, safeStickerImagePath, cardJs, waitFor, MOOD_LIST, realClick, findApplyButton, pointBelongsToCard } from './douyin-social-pure.js';
|
|
77
|
+
export { PAGE_TIMING, VIDEO_LOCK_MARGIN_MS, MOOD_THEME, pickMoodTheme, pickRecommendedSong, commentKey, commentId } from './douyin-social-pure.js';
|
|
84
78
|
|
|
85
|
-
openWorkBudgetMs: 30_000, // openWork 整操作的总预算
|
|
86
|
-
replyBudgetMs: 30_000, // reply 整操作的总预算
|
|
87
|
-
// 转码单独给预算:视频传上去后要等抖音转码,实测 180 秒都还没转完。
|
|
88
|
-
// 「上传中」那行字不消**不代表**没好,所以只能等 video 元素真能播。
|
|
89
|
-
// 🔴 预算不能贴着观测到的最坏值:180 秒 == 实测最坏值 ⇒ 慢的日子必然
|
|
90
|
-
// TRANSCODE_TIMEOUT,而钱那时**已经花出去了**(重试要再生成一条 = 花两次钱)
|
|
91
|
-
// ⇒ 抬到 5 分钟,留一倍余量。
|
|
92
|
-
transcodeBudgetMs: 300_000,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 浏览器锁比转码预算多留的余量:从页面环节各自的最坏超时**推导**,不写死常量。
|
|
97
|
-
*
|
|
98
|
-
* 锁里除了转码,还有探活(≈11s)/ 导航 / 填表几次 eval / 发布确认 —— 每一段都有
|
|
99
|
-
* 自己的超时上限,全部加总才是锁真正要扛的最坏耗时。写死一个数 = 改了上面某个
|
|
100
|
-
* 超时忘了改这里 ⇒ 锁提前超时(exclusive 超时只报错**不放锁**,锁要等 fn 真 settle
|
|
101
|
-
* ⇒ 后面所有页面操作排队,主人还以为视频没发出去)。
|
|
102
|
-
*/
|
|
103
|
-
export const VIDEO_LOCK_MARGIN_MS = PAGE_TIMING.gotoTimeoutMs + PAGE_TIMING.waitBudgetMs + 5 * PAGE_TIMING.evalTimeoutMs + 60_000;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 整操作的总预算(终点)。
|
|
107
|
-
*
|
|
108
|
-
* 终点同时管三件事:单次 eval 的超时、轮次之间的等待、还要不要发起下一次 eval。
|
|
109
|
-
* 只在轮次之间查时间是没用的 —— 页面卡死时 eval 自己就挂死(永不回包)。
|
|
110
|
-
*
|
|
111
|
-
* @param {number} totalMs 总预算(毫秒)
|
|
112
|
-
*/
|
|
113
|
-
function deadline(totalMs) {
|
|
114
|
-
const end = Date.now() + totalMs;
|
|
115
|
-
const left = () => end - Date.now();
|
|
116
|
-
return {
|
|
117
|
-
left,
|
|
118
|
-
/** 到点了没 */
|
|
119
|
-
expired: () => left() <= 0,
|
|
120
|
-
/** 这次 eval 给多少超时:不超过上限,也不越过终点 */
|
|
121
|
-
timeoutFor: (cap) => Math.max(1, Math.min(cap, left())),
|
|
122
|
-
/** 这次该等多久:不超过原时长,也不越过终点 */
|
|
123
|
-
waitFor: (ms) => Math.max(0, Math.min(ms, left()))
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const oneLine = (s, n) => String(s ?? '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
128
|
-
const errText = (e) => String(e instanceof Error ? e.message : e);
|
|
129
|
-
|
|
130
|
-
const IMAGE_EXT = new Set(['.png', '.jpg', '.jpeg', '.gif', '.webp']);
|
|
131
|
-
const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 评论图片只能取工作区 `_stickers/` 里的图。
|
|
135
|
-
*
|
|
136
|
-
* 路径是模型写的 = 不可信:`..` 能拼出工作区外的文件,软链接 / junction 能把
|
|
137
|
-
* `_stickers/` 里的一项指到别处。所以边界收在**真实路径**上 ——
|
|
138
|
-
* 目录、软链接/junction 逃逸、非图片格式、超大图一律不发(关掉,不抛)。
|
|
139
|
-
*
|
|
140
|
-
* 信任根本身也要先验:`_stickers` 必须是普通目录 —— 它自己是 junction / 软链接的话,
|
|
141
|
-
* 真实路径整个落到工作区外,只拿 `realRoot` 去比是拦不住的。
|
|
142
|
-
*
|
|
143
|
-
* @param {string} rel `_stickers/xxx` 形状的相对路径
|
|
144
|
-
* @param {string} root 工作区里的 `_stickers` 目录
|
|
145
|
-
* @param {(level: string, msg: string) => void} log
|
|
146
|
-
* @returns {string|null} 校验过的真实路径;不合格返回 null
|
|
147
|
-
*/
|
|
148
|
-
function safeStickerImagePath(rel, root, log) {
|
|
149
|
-
const deny = () => {
|
|
150
|
-
log('warn', `[fish-soul] 抖音评论图片越界,已忽略:${rel}`);
|
|
151
|
-
return null;
|
|
152
|
-
};
|
|
153
|
-
let rootStat;
|
|
154
|
-
try { rootStat = lstatSync(root); } catch { return null; } // 没有 _stickers 目录 = 没有可发的图
|
|
155
|
-
if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) {
|
|
156
|
-
log('warn', `[fish-soul] 抖音评论图片根目录不可信(_stickers 不是普通目录),已拒绝:${rel}`);
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
const abs = resolve(root, rel.slice('_stickers/'.length));
|
|
160
|
-
if (!isInside(root, abs)) return deny();
|
|
161
|
-
if (!IMAGE_EXT.has(extname(abs).toLowerCase())) return null;
|
|
162
|
-
let realRoot, real;
|
|
163
|
-
try {
|
|
164
|
-
realRoot = realpathSync.native(root);
|
|
165
|
-
real = realpathSync.native(abs);
|
|
166
|
-
} catch { return null; }
|
|
167
|
-
if (!isInside(realRoot, real)) return deny();
|
|
168
|
-
try {
|
|
169
|
-
const st = statSync(real);
|
|
170
|
-
if (!st.isFile() || st.size > MAX_IMAGE_BYTES) return null;
|
|
171
|
-
} catch { return null; }
|
|
172
|
-
return real;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** 文字卡片(1080×1440 PNG,base64)。 */
|
|
176
|
-
function cardJs(text, foot, theme) {
|
|
177
|
-
return `(async () => {
|
|
178
|
-
const text = ${JSON.stringify(text)};
|
|
179
|
-
const foot = ${JSON.stringify(foot)};
|
|
180
|
-
const themes = [['#FFF6E5', '#5B4636'], ['#EAF4FF', '#2F4A66'], ['#F3EEFF', '#4A3A6B'], ['#EAF7EE', '#2F5A3E'], ['#FFEFF1', '#6B3A44']];
|
|
181
|
-
const [bg, fg] = themes[${Number(theme) || 0} % themes.length];
|
|
182
|
-
const W = 1080, H = 1440;
|
|
183
|
-
const c = new OffscreenCanvas(W, H);
|
|
184
|
-
const g = c.getContext('2d');
|
|
185
|
-
g.fillStyle = bg; g.fillRect(0, 0, W, H);
|
|
186
|
-
g.fillStyle = fg; g.textBaseline = 'top';
|
|
187
|
-
const size = text.length > 80 ? 52 : text.length > 40 ? 62 : 76;
|
|
188
|
-
const font = (px) => px + 'px "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif';
|
|
189
|
-
g.font = font(size);
|
|
190
|
-
const maxW = W - 200;
|
|
191
|
-
const lines = [];
|
|
192
|
-
for (const para of text.split('\\n')) {
|
|
193
|
-
let cur = '';
|
|
194
|
-
for (const ch of para) {
|
|
195
|
-
if (g.measureText(cur + ch).width > maxW && cur !== '') { lines.push(cur); cur = ch; } else cur += ch;
|
|
196
|
-
}
|
|
197
|
-
lines.push(cur);
|
|
198
|
-
}
|
|
199
|
-
const lh = Math.round(size * 1.6);
|
|
200
|
-
let y = Math.max(120, Math.round((H - lines.length * lh) / 2) - 40);
|
|
201
|
-
for (const l of lines) { g.fillText(l, 100, y); y += lh; }
|
|
202
|
-
g.globalAlpha = 0.55; g.font = font(34);
|
|
203
|
-
g.fillText(foot, 100, H - 150);
|
|
204
|
-
const blob = await c.convertToBlob({ type: 'image/png' });
|
|
205
|
-
const u = new Uint8Array(await blob.arrayBuffer());
|
|
206
|
-
let s = '';
|
|
207
|
-
for (let i = 0; i < u.length; i += 0x8000) s += String.fromCharCode.apply(null, u.subarray(i, i + 0x8000));
|
|
208
|
-
return btoa(s);
|
|
209
|
-
})()`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** 心情 → cardJs themes 的下标(顺序:米黄暖 / 浅蓝丧 / 淡紫梦 / 浅绿清 / 粉甜)。 */
|
|
213
|
-
export const MOOD_THEME = { warm: 0, blue: 1, dream: 2, fresh: 3, pink: 4 };
|
|
214
|
-
const MOOD_LIST = 'warm 暖/治愈、blue 丧/低落、dream 梦幻/恍惚、fresh 清新/日常、pink 甜/开心';
|
|
215
|
-
|
|
216
|
-
/** 让模型给文案配心情,返回 {theme, reason};解析不出来就随机一个主题,不耽误发布。 */
|
|
217
|
-
export function pickMoodTheme(raw, random = Math.random) {
|
|
218
|
-
const fallback = { theme: Math.floor(random() * 5), reason: '' };
|
|
219
|
-
const m = String(raw ?? '').match(/\{[^{}]*\}/s);
|
|
220
|
-
if (!m) return fallback;
|
|
221
|
-
let j;
|
|
222
|
-
try { j = JSON.parse(m[0]); } catch { return fallback; }
|
|
223
|
-
const mood = String(j?.mood ?? '').toLowerCase().trim();
|
|
224
|
-
const theme = Object.hasOwn(MOOD_THEME, mood) ? MOOD_THEME[mood] : fallback.theme;
|
|
225
|
-
return { theme, reason: String(j?.reason ?? '').trim().slice(0, 40) };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** 从抖音推荐的歌里挑一首(只能挑列表里的,模型编的名字不算);挑不出来返回 ''。 */
|
|
229
|
-
export function pickRecommendedSong(raw, songs) {
|
|
230
|
-
const list = (Array.isArray(songs) ? songs : []).map((s) => String(s ?? '').trim()).filter(Boolean);
|
|
231
|
-
if (!list.length) return '';
|
|
232
|
-
const out = String(raw ?? '').trim().replace(/^["'「『\s]+|["'」』\s]+$/g, '');
|
|
233
|
-
if (!out) return '';
|
|
234
|
-
if (list.includes(out)) return out;
|
|
235
|
-
return [...list].sort((a, b) => b.length - a.length).find((s) => out.includes(s)) ?? '';
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/** 评论去重用的 id:作品 + 谁 + 说了什么。 */
|
|
239
|
-
export function commentKey(workId, author, content) {
|
|
240
|
-
return `${workId}:${createHash('sha1').update(`${author}\n${content}`).digest('hex').slice(0, 16)}`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* 评论去重 id:优先用评论自己的 cid(`作品:cid:xxx`),没有 cid 才落回文本哈希。
|
|
245
|
-
*
|
|
246
|
-
* 文本 key 的毛病:作者改了评论,正文变了 → key 变了 → 同一条评论被当成新的又回一遍
|
|
247
|
-
* (在真实账号上回两遍)。cid 是抖音给的评论 id,不随正文变。
|
|
248
|
-
*
|
|
249
|
-
* @param {string} workId 作品 id
|
|
250
|
-
* @param {string} cid 评论 id(没有就空串)
|
|
251
|
-
* @param {string} author 作者昵称
|
|
252
|
-
* @param {string} content 评论正文
|
|
253
|
-
* @returns {string} 去重 id
|
|
254
|
-
*/
|
|
255
|
-
export function commentId(workId, cid, author, content) {
|
|
256
|
-
const c = String(cid ?? '').trim();
|
|
257
|
-
if (c !== '') return `${workId}:cid:${c}`;
|
|
258
|
-
return commentKey(workId, author, content);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// ───────────── 页面脚本 ─────────────
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
async function realClick(br, x, y, timeoutMs) {
|
|
265
|
-
for (const type of ['mousePressed', 'mouseReleased']) {
|
|
266
|
-
await br.send('Input.dispatchMouseEvent', { type, x, y, button: 'left', clickCount: 1, buttons: type === 'mousePressed' ? 1 : 0 }, br.sessionId, timeoutMs);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* 找「使用」按钮,并用**引用**取它的几何。
|
|
272
|
-
*
|
|
273
|
-
* 为什么不继续用 `[class*="apply-btn"]`:那是抖音的构建哈希类名,改版就断。
|
|
274
|
-
* 无障碍树里它叫 `button` / name=`使用`,是页面**语义**的一部分,稳得多。
|
|
275
|
-
*
|
|
276
|
-
* 两道保险:
|
|
277
|
-
* ① 元素可能已被页面换掉 —— `DOM.getBoxModel` 对失效引用**报错**,
|
|
278
|
-
* 而 `getBoundingClientRect()` 会静默返回 0×0(以前就点过 (0,0))。
|
|
279
|
-
* ② 拿不到语义节点 / 几何 ⇒ 明确返回「没找到」,由调用方报「没有出现使用按钮」。
|
|
280
|
-
*
|
|
281
|
-
* 真机依据(2026-11-20,创作者中心发布图文页):hover 之后
|
|
282
|
-
* `Accessibility.queryAXTree(root, {accessibleName:'使用', role:'button'})` 精确命中 1 个,
|
|
283
|
-
* backendNodeId → getBoxModel 的几何与 getBoundingClientRect 一致。
|
|
284
|
-
*
|
|
285
|
-
* @returns {Promise<{ok:boolean, x?:number, y?:number}>}
|
|
286
|
-
*/
|
|
287
|
-
async function findApplyButton(br, timing, hoverAt) {
|
|
288
|
-
const sid = br.sessionId;
|
|
289
|
-
// 每一轮都重新 hover:按钮靠 CSS :hover 才从 visibility:hidden 变可见,
|
|
290
|
-
// 而 getBoxModel 对 hidden 元素照样返回几何 ⇒ 不 hover 就会「找到坐标但点空」。
|
|
291
|
-
if (hoverAt) await br.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: hoverAt.x, y: hoverAt.y }, sid).catch(() => {});
|
|
292
|
-
// depth:0 —— 只要 root 的 nodeId;拉整棵 DOM 在 40 万节点的页面上要 5 秒 / 100MB。
|
|
293
|
-
const doc = await br.send('DOM.getDocument', { depth: 0 }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
294
|
-
const rootId = doc?.root?.nodeId;
|
|
295
|
-
if (!rootId) return { ok: false, reason: 'read-failed', error: '读不到页面根节点(CDP 无响应?)' };
|
|
296
|
-
const q = await br.send('Accessibility.queryAXTree', { nodeId: rootId, accessibleName: '使用', role: 'button' }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
297
|
-
if (!q) return { ok: false, reason: 'read-failed', error: '无障碍树查询失败(CDP 无响应?)' };
|
|
298
|
-
// ⚠️ 可能命中多个:页面别处也可能有可见的「使用」。全都要,交给调用方按归属筛。
|
|
299
|
-
const nodes = (q.nodes || []).filter((n) => n.backendDOMNodeId);
|
|
300
|
-
if (!nodes.length) return { ok: false, reason: 'not-found' };
|
|
301
|
-
const candidates = [];
|
|
302
|
-
for (const n of nodes) {
|
|
303
|
-
const box = await br.send('DOM.getBoxModel', { backendNodeId: n.backendDOMNodeId }, sid, timing.evalTimeoutMs).catch(() => null);
|
|
304
|
-
const quad = box?.model?.content;
|
|
305
|
-
if (!quad || quad.length < 8) continue;
|
|
306
|
-
const x = Math.round((quad[0] + quad[2] + quad[4] + quad[6]) / 4);
|
|
307
|
-
const y = Math.round((quad[1] + quad[3] + quad[5] + quad[7]) / 4);
|
|
308
|
-
if (x > 0 && y > 0) candidates.push({ x, y, backendNodeId: n.backendDOMNodeId });
|
|
309
|
-
}
|
|
310
|
-
return candidates.length ? { ok: true, candidates } : { ok: false, reason: 'not-found' };
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* 这个按钮节点(或坐标上的元素),是不是落在「某个含该歌名的歌卡」里面?
|
|
315
|
-
*
|
|
316
|
-
* 为什么要这一步:AX 查询的范围是**整棵树**,命中的是 DOM 顺序第一个可见的「使用」。
|
|
317
|
-
* 页面别处只要有一个可见的「使用」按钮,就会点到它 —— 而且后续歌名确认会失败,
|
|
318
|
-
* 报出来的却是「已点击使用,但编辑页未确认显示歌名」,把错误指向了别处。
|
|
319
|
-
* 旧代码用「在目标卡的子树里找按钮」天然避开了这件事,换成语义定位后必须显式补回来。
|
|
320
|
-
*
|
|
321
|
-
* 🔴 优先直接用 AX 节点的 `backendNodeId` 往上查祖先链:
|
|
322
|
-
* 不用 `DOM.getNodeForLocation(x, y)` 去反查 —— 真机上音乐抽屉是 fixed 浮层,
|
|
323
|
-
* 鼠标移开或 hover 抖动的一帧里按钮可能短暂变成 `visibility: hidden` / `pointer-events: none`,
|
|
324
|
-
* 或者被子层盖住,`getNodeForLocation` 就会打穿到抽屉底板或背景层,误报「不在选中的那首歌上」。
|
|
325
|
-
*
|
|
326
|
-
* @returns {Promise<boolean>} 读失败也返回 false(宁可这次不发,也不点错)
|
|
327
|
-
*/
|
|
328
|
-
async function pointBelongsToCard(br, cand, music, timing) {
|
|
329
|
-
let backendNodeId = cand?.backendNodeId;
|
|
330
|
-
if (!backendNodeId && Number.isFinite(cand?.x) && Number.isFinite(cand?.y)) {
|
|
331
|
-
const hit = await br.send('DOM.getNodeForLocation', { x: cand.x, y: cand.y, includeUserAgentShadowDOM: false }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
332
|
-
backendNodeId = hit?.backendNodeId;
|
|
333
|
-
}
|
|
334
|
-
if (!backendNodeId) return false;
|
|
335
|
-
// describeNode 拿不到父链,改用 Runtime 从该节点往上走。
|
|
336
|
-
const resolved = await br.send('DOM.resolveNode', { backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
337
|
-
const objectId = resolved?.object?.objectId;
|
|
338
|
-
if (!objectId) return false;
|
|
339
|
-
try {
|
|
340
|
-
const r = await br.send('Runtime.callFunctionOn', {
|
|
341
|
-
objectId,
|
|
342
|
-
functionDeclaration: `function (want) {
|
|
343
|
-
const norm = (s) => String(s || '').replace(/\\s+/g, '');
|
|
344
|
-
const target = norm(want);
|
|
345
|
-
const songSel = '[class*="song-name"]';
|
|
346
|
-
for (let p = this; p && p !== document.body; p = p.parentElement) {
|
|
347
|
-
if (!p.querySelectorAll) continue;
|
|
348
|
-
const names = p.querySelectorAll(songSel);
|
|
349
|
-
if (names.length === 1) {
|
|
350
|
-
const sn = names[0];
|
|
351
|
-
const text = norm(sn.innerText || sn.textContent || '');
|
|
352
|
-
if (text === target || (target.length >= 2 && text.includes(target))) return true;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
}`,
|
|
357
|
-
arguments: [{ value: music }],
|
|
358
|
-
returnByValue: true,
|
|
359
|
-
}, br.sessionId, timing.evalTimeoutMs);
|
|
360
|
-
return r?.result?.value === true;
|
|
361
|
-
} catch {
|
|
362
|
-
return false;
|
|
363
|
-
} finally {
|
|
364
|
-
await br.send('Runtime.releaseObject', { objectId }, br.sessionId, timing.evalTimeoutMs).catch(() => {});
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
/** 预算到期的哨兵:区分「没等到」和「等到的是假值」。 */
|
|
368
|
-
const BUDGET_OUT = Symbol('budget-out');
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* 等 fn 出结果,最长等 budgetMs。
|
|
372
|
-
*
|
|
373
|
-
* 🔴 预算必须**包住 fn 这一次调用** —— 页面 renderer 卡死时 fn 自己就挂死
|
|
374
|
-
* (Runtime.evaluate 永不回包),只在轮次之间查时间没用:
|
|
375
|
-
* 配乐 6 轮 × 60 秒 = 锁被占 6 分钟(2026-11-15 巡检 P2)。
|
|
376
|
-
*
|
|
377
|
-
* @param {Function} fn 每轮调用一次;返回假值 / 抛错 = 还没等到
|
|
378
|
-
* @param {object} opts
|
|
379
|
-
* @param {number} opts.tries 最多试几轮
|
|
380
|
-
* @param {number} opts.gapMs 两轮之间隔多久
|
|
381
|
-
* @param {number} opts.budgetMs 总预算(毫秒);到点直接返回 null(非正数 = 不等,直接返回 null)
|
|
382
|
-
* @returns {Promise<any>} 等到的值;没等到返回 null
|
|
383
|
-
*/
|
|
384
|
-
async function waitFor(fn, { tries = 10, gapMs = 1000, budgetMs = PAGE_TIMING.waitBudgetMs } = {}) {
|
|
385
|
-
const end = Date.now() + budgetMs;
|
|
386
|
-
for (let i = 0; i < tries; i++) {
|
|
387
|
-
const left = end - Date.now();
|
|
388
|
-
if (left <= 0) return null;
|
|
389
|
-
let timer;
|
|
390
|
-
const v = await Promise.race([
|
|
391
|
-
fn().catch(() => null),
|
|
392
|
-
new Promise((resolve) => { timer = setTimeout(() => resolve(BUDGET_OUT), left); timer.unref?.(); }),
|
|
393
|
-
]).finally(() => clearTimeout(timer));
|
|
394
|
-
if (v === BUDGET_OUT) return null;
|
|
395
|
-
if (v) return v;
|
|
396
|
-
const rest = end - Date.now();
|
|
397
|
-
if (rest <= 0) return null;
|
|
398
|
-
await sleep(Math.min(gapMs, rest));
|
|
399
|
-
}
|
|
400
|
-
return null;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/** 点编辑页上的「选择音乐」入口(真点,不是 JS click),返回点了没。 */
|
|
404
|
-
/** 页面活性检测(导出供测试)。renderer 卡死时 eval 会永远 pending,必须带超时竞速。
|
|
405
|
-
* 不通就 reload 一次再试;还不通返回 false,调用方别再往死页面上发操作。
|
|
406
|
-
* (2026-11-15 真机实录:创作者中心页挂着验证码 iframe 后整页 hung 死,
|
|
407
|
-
* Runtime.evaluate / Page.navigate 全部无响应,配乐两次报错的根因。) */
|
|
408
79
|
export async function ensurePageAlive(br, { timeoutMs = 3000, reload = true } = {}) {
|
|
409
80
|
const probe = () => Promise.race([
|
|
410
81
|
br.eval('1').then(() => true, () => false),
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.js 拆出的纯函数与常量(2026-12-03)。
|
|
3
|
+
* 配置读写 / schema / 解析 / 常量表 —— 不依赖宿主 ctx,可以独立测试。
|
|
4
|
+
* index.js 只留宿主入口(apply / inject / Config / testHooks)与装配(startup)。
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
7
|
+
import { configPath } from './db.js';
|
|
8
|
+
|
|
9
|
+
export function deepMerge(base, over) {
|
|
10
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
11
|
+
if (!isObj(base)) return isObj(over) ? { ...over } : (over === undefined ? base : over);
|
|
12
|
+
const out = { ...base };
|
|
13
|
+
if (!isObj(over)) return out;
|
|
14
|
+
for (const [k, v] of Object.entries(over)) {
|
|
15
|
+
if (v === undefined) continue;
|
|
16
|
+
out[k] = isObj(v) && isObj(out[k]) ? deepMerge(out[k], v) : v;
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 读 fish-soul-config.json。去掉 BOM(Windows 记事本 / PowerShell 存的 UTF-8 常带),
|
|
23
|
+
* 读不懂时返回 { ok: false }——以前当成 {} 处理,设置页一保存就只剩这次改的那几项,别的(accessToken、key…)全丢(#26)。
|
|
24
|
+
*/
|
|
25
|
+
export function readConfigFile(path = configPath()) {
|
|
26
|
+
if (!existsSync(path)) return { ok: true, value: {} };
|
|
27
|
+
let text;
|
|
28
|
+
try { text = readFileSync(path, 'utf8'); } catch (error) { return { ok: false, error: String(error instanceof Error ? error.message : error) }; }
|
|
29
|
+
text = text.replace(/^\uFEFF/, '');
|
|
30
|
+
if (text.trim() === '') return { ok: true, value: {} };
|
|
31
|
+
try {
|
|
32
|
+
const value = JSON.parse(text);
|
|
33
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return { ok: false, error: '最外层不是 { }' };
|
|
34
|
+
return { ok: true, value };
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return { ok: false, error: String(error instanceof Error ? error.message : error) };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function loadConfigFile() {
|
|
41
|
+
const r = readConfigFile();
|
|
42
|
+
return r.ok ? r.value : {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 合并写回。文件读不懂就拒绝写(抛错,设置页会提示),免得把整份设置覆盖成只剩这次的改动;写入先写临时文件再改名。 */
|
|
46
|
+
export function saveConfigFile(patch, path = configPath()) {
|
|
47
|
+
const cur = readConfigFile(path);
|
|
48
|
+
if (!cur.ok) throw new Error(`fish-soul-config.json 格式不对,没保存(${cur.error})。先把文件改对(或删掉重新设置),再保存`);
|
|
49
|
+
const next = deepMerge(cur.value, patch);
|
|
50
|
+
const tmp = `${path}.tmp`;
|
|
51
|
+
writeFileSync(tmp, JSON.stringify(next, null, 2), 'utf8');
|
|
52
|
+
renameSync(tmp, path);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 把扁平参数描述转成标准 JSON Schema(宿主 defineTool 校验 additionalProperties)。 */
|
|
56
|
+
export function objectSchema(props) {
|
|
57
|
+
const properties = {};
|
|
58
|
+
const required = [];
|
|
59
|
+
for (const [k, v] of Object.entries(props)) {
|
|
60
|
+
const { required: req, ...rest } = v;
|
|
61
|
+
properties[k] = rest;
|
|
62
|
+
if (req === true) required.push(k);
|
|
63
|
+
}
|
|
64
|
+
return { type: 'object', properties, required, additionalProperties: false };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 把"YYYY-MM-DDTHH:mm"这类无时区 ISO 视为角色时区(UTC+8),而不是宿主机本地时区。 */
|
|
68
|
+
export function parseRoleIso(iso) {
|
|
69
|
+
const s = String(iso).trim();
|
|
70
|
+
const hasZone = /([zZ]|[+-]\d{2}:?\d{2})$/.test(s);
|
|
71
|
+
const parsed = Date.parse(hasZone ? s : `${s.length === 10 ? `${s}T09:00:00` : s}+08:00`);
|
|
72
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const UNKNOWN_OWNER = 'user:unknown';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 抖音自带表情里**确认存在**的兜底名字。
|
|
79
|
+
*
|
|
80
|
+
* 🔴 以前这里写的是 `[比心] [捂脸]` —— 而 `[捂脸]` **不在抖音表情面板里**(2026-11-09 实测)。
|
|
81
|
+
* 后果不是报错:`sendEmoji` 找不到就退回 `sendText`,把 `[捂脸]` 当**纯文字**发出去,
|
|
82
|
+
* 对方看到一串方括号。模型被提示词引到一个不存在的名字上,锅在提示词这边。
|
|
83
|
+
*
|
|
84
|
+
* 下面这几个都来自 2026-11-09 真机抓的面板(`emojiNames` 为空时的兜底):
|
|
85
|
+
* 续火花 比心 在干嘛 笑死 麻了 躺平 摇骰子 猜拳 开心 嗨 吹泡泡 黑人问号
|
|
86
|
+
* 早上好 晚上好 早点睡 爱心 便便 戳一戳 绝了 已阅 生日祝福
|
|
87
|
+
* 挑的是**语义通用、不挑场合**的几个;`[摇骰子]` 那种只在特定场景才合适,不放进来。
|
|
88
|
+
* ⚠️ 这份清单要跟面板对得上 —— `test/douyin-emoji-fallback.mjs` 会核对。
|
|
89
|
+
*/
|
|
90
|
+
export const DOUYIN_EMOJI_FALLBACK = ['比心', '笑死', '绝了', '爱心'];
|
|
91
|
+
|
|
92
|
+
/** 启动步骤(顺序即 apply 里的顺序),日志和 503 里的"第 N 步"按这个数。 */
|
|
93
|
+
export const STARTUP_STEPS = [
|
|
94
|
+
'底座(soul.db / 虚拟钟)', '检索', 'QQ 渠道', '人格', 'B站', '给主人的提醒', '抖音', '自走层', '上网查',
|
|
95
|
+
'会话上下文', '语音 / 表情包 / 群里的说法', '聊完自动记', '心情 / 日记', '备份 / 聊天记录导入', '挂路由',
|
|
96
|
+
'会话事件 / 工具护栏', '工具'
|
|
97
|
+
];
|
package/lib/index.js
CHANGED
|
@@ -94,95 +94,9 @@ export const inject = ['webServer', 'tools', 'systemPrompt', 'llm', 'agents', 'w
|
|
|
94
94
|
export const Config = z === null ? undefined : fishSoulConfigSchema(z);
|
|
95
95
|
|
|
96
96
|
/** 深合并:over 中的普通对象递归合并,其余值(含数组)整体覆盖;undefined 不覆盖。 */
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!isObj(base)) return isObj(over) ? { ...over } : (over === undefined ? base : over);
|
|
100
|
-
const out = { ...base };
|
|
101
|
-
if (!isObj(over)) return out;
|
|
102
|
-
for (const [k, v] of Object.entries(over)) {
|
|
103
|
-
if (v === undefined) continue;
|
|
104
|
-
out[k] = isObj(v) && isObj(out[k]) ? deepMerge(out[k], v) : v;
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 读 fish-soul-config.json。去掉 BOM(Windows 记事本 / PowerShell 存的 UTF-8 常带),
|
|
111
|
-
* 读不懂时返回 { ok: false }——以前当成 {} 处理,设置页一保存就只剩这次改的那几项,别的(accessToken、key…)全丢(#26)。
|
|
112
|
-
*/
|
|
113
|
-
export function readConfigFile(path = configPath()) {
|
|
114
|
-
if (!existsSync(path)) return { ok: true, value: {} };
|
|
115
|
-
let text;
|
|
116
|
-
try { text = readFileSync(path, 'utf8'); } catch (error) { return { ok: false, error: String(error instanceof Error ? error.message : error) }; }
|
|
117
|
-
text = text.replace(/^\uFEFF/, '');
|
|
118
|
-
if (text.trim() === '') return { ok: true, value: {} };
|
|
119
|
-
try {
|
|
120
|
-
const value = JSON.parse(text);
|
|
121
|
-
if (value === null || typeof value !== 'object' || Array.isArray(value)) return { ok: false, error: '最外层不是 { }' };
|
|
122
|
-
return { ok: true, value };
|
|
123
|
-
} catch (error) {
|
|
124
|
-
return { ok: false, error: String(error instanceof Error ? error.message : error) };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function loadConfigFile() {
|
|
129
|
-
const r = readConfigFile();
|
|
130
|
-
return r.ok ? r.value : {};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** 合并写回。文件读不懂就拒绝写(抛错,设置页会提示),免得把整份设置覆盖成只剩这次的改动;写入先写临时文件再改名。 */
|
|
134
|
-
export function saveConfigFile(patch, path = configPath()) {
|
|
135
|
-
const cur = readConfigFile(path);
|
|
136
|
-
if (!cur.ok) throw new Error(`fish-soul-config.json 格式不对,没保存(${cur.error})。先把文件改对(或删掉重新设置),再保存`);
|
|
137
|
-
const next = deepMerge(cur.value, patch);
|
|
138
|
-
const tmp = `${path}.tmp`;
|
|
139
|
-
writeFileSync(tmp, JSON.stringify(next, null, 2), 'utf8');
|
|
140
|
-
renameSync(tmp, path);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** 把扁平参数描述转成标准 JSON Schema(宿主 defineTool 校验 additionalProperties)。 */
|
|
144
|
-
function objectSchema(props) {
|
|
145
|
-
const properties = {};
|
|
146
|
-
const required = [];
|
|
147
|
-
for (const [k, v] of Object.entries(props)) {
|
|
148
|
-
const { required: req, ...rest } = v;
|
|
149
|
-
properties[k] = rest;
|
|
150
|
-
if (req === true) required.push(k);
|
|
151
|
-
}
|
|
152
|
-
return { type: 'object', properties, required, additionalProperties: false };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** 把"YYYY-MM-DDTHH:mm"这类无时区 ISO 视为角色时区(UTC+8),而不是宿主机本地时区。 */
|
|
156
|
-
function parseRoleIso(iso) {
|
|
157
|
-
const s = String(iso).trim();
|
|
158
|
-
const hasZone = /([zZ]|[+-]\d{2}:?\d{2})$/.test(s);
|
|
159
|
-
const parsed = Date.parse(hasZone ? s : `${s.length === 10 ? `${s}T09:00:00` : s}+08:00`);
|
|
160
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const UNKNOWN_OWNER = 'user:unknown';
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 抖音自带表情里**确认存在**的兜底名字。
|
|
167
|
-
*
|
|
168
|
-
* 🔴 以前这里写的是 `[比心] [捂脸]` —— 而 `[捂脸]` **不在抖音表情面板里**(2026-11-09 实测)。
|
|
169
|
-
* 后果不是报错:`sendEmoji` 找不到就退回 `sendText`,把 `[捂脸]` 当**纯文字**发出去,
|
|
170
|
-
* 对方看到一串方括号。模型被提示词引到一个不存在的名字上,锅在提示词这边。
|
|
171
|
-
*
|
|
172
|
-
* 下面这几个都来自 2026-11-09 真机抓的面板(`emojiNames` 为空时的兜底):
|
|
173
|
-
* 续火花 比心 在干嘛 笑死 麻了 躺平 摇骰子 猜拳 开心 嗨 吹泡泡 黑人问号
|
|
174
|
-
* 早上好 晚上好 早点睡 爱心 便便 戳一戳 绝了 已阅 生日祝福
|
|
175
|
-
* 挑的是**语义通用、不挑场合**的几个;`[摇骰子]` 那种只在特定场景才合适,不放进来。
|
|
176
|
-
* ⚠️ 这份清单要跟面板对得上 —— `test/douyin-emoji-fallback.mjs` 会核对。
|
|
177
|
-
*/
|
|
178
|
-
const DOUYIN_EMOJI_FALLBACK = ['比心', '笑死', '绝了', '爱心'];
|
|
97
|
+
export { readConfigFile, saveConfigFile } from './index-context.js';
|
|
98
|
+
import { deepMerge, readConfigFile, saveConfigFile, loadConfigFile, objectSchema, parseRoleIso, UNKNOWN_OWNER, DOUYIN_EMOJI_FALLBACK, STARTUP_STEPS } from './index-context.js';
|
|
179
99
|
|
|
180
|
-
/** 启动步骤(顺序即 apply 里的顺序),日志和 503 里的"第 N 步"按这个数。 */
|
|
181
|
-
const STARTUP_STEPS = [
|
|
182
|
-
'底座(soul.db / 虚拟钟)', '检索', 'QQ 渠道', '人格', 'B站', '给主人的提醒', '抖音', '自走层', '上网查',
|
|
183
|
-
'会话上下文', '语音 / 表情包 / 群里的说法', '聊完自动记', '心情 / 日记', '备份 / 聊天记录导入', '挂路由',
|
|
184
|
-
'会话事件 / 工具护栏', '工具'
|
|
185
|
-
];
|
|
186
100
|
|
|
187
101
|
export async function apply(ctx, config) {
|
|
188
102
|
const log = (level, msg) => ctx.logger?.[level]?.(msg);
|
package/lib/routes-v07.js
CHANGED
|
@@ -152,7 +152,9 @@ export async function handleV07Route({ method, path, url, req, res, send, readBo
|
|
|
152
152
|
ok: true, providers, features, hostDefault: llmRouter.hostDefault(), prices: cfg.modelPrices ?? {},
|
|
153
153
|
usage7: llmRouter.usage(7), usage30: llmRouter.usage(30), lastError: llmRouter.lastError || '',
|
|
154
154
|
modelStatus: llmRouter.modelStatus(), budget: llmRouter.budgetConfig(), todayUsage: llmRouter.todayUsage(),
|
|
155
|
-
web: webState()
|
|
155
|
+
web: webState(),
|
|
156
|
+
// 桌面宠物互通令牌状态(面板渲染「生成 / 重新生成 / 撤销」的依据;只给 masked,不明文)
|
|
157
|
+
desktopPet: (() => { const t = cfg.tools?.desktopPetToken ?? ''; return { hasToken: t !== '', tokenMasked: maskKey(t) }; })()
|
|
156
158
|
});
|
|
157
159
|
return true;
|
|
158
160
|
}
|
package/lib/routes.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* 聊天记录导入在 routes-soul.js;v0.7 的模型 / 用量 / 语音 / 表情包 / 群里的说法 / 首次引导在 routes-v07.js(UI 文档契约 21~31)。
|
|
8
8
|
*/
|
|
9
9
|
import { readFileSync, existsSync } from 'node:fs';
|
|
10
|
+
import { randomBytes } from 'node:crypto';
|
|
10
11
|
import { readVecMeta, writeVecMeta, listChatSessions, ensureMasterPerson, getProfile, setKv } from './db.js';
|
|
11
12
|
import { douyinState, handleDouyinRoute } from './routes-douyin.js';
|
|
12
13
|
import { douyinSessionHealth } from './douyin-http.js';
|
|
@@ -89,6 +90,19 @@ function sameOrigin(req) {
|
|
|
89
90
|
return headers['sec-fetch-site'] === 'same-origin' || headers['sec-fetch-site'] === 'none';
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* 桌面宠物互通端点(/life/context、/life/interaction)的共享密钥闸。
|
|
95
|
+
* tools.desktopPetToken 为空 = 不启用鉴权(向后兼容,同机任意进程可调用);
|
|
96
|
+
* 非空 = 必须带 Authorization: Bearer <token>,不符 401。
|
|
97
|
+
* 为什么放在 sameOrigin 之外另算:sameOrigin 只认浏览器头(sec-fetch-site),
|
|
98
|
+
* 桌宠端 / curl 这类同机进程不带那个头,sameOrigin 一律放行 —— 那层管不了它们。
|
|
99
|
+
*/
|
|
100
|
+
function lifeAuthed(req, getConfig) {
|
|
101
|
+
const token = getConfig()?.tools?.desktopPetToken ?? '';
|
|
102
|
+
if (token === '') return true; // 未配置 = 兼容旧行为,放行
|
|
103
|
+
return req.headers?.authorization === `Bearer ${token}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
|
|
93
107
|
/**
|
|
94
108
|
* @param {object} deps
|
|
@@ -1025,6 +1039,7 @@ export function registerRoutes(ctx, deps) {
|
|
|
1025
1039
|
|
|
1026
1040
|
// ── 桌面宠物 v1 互通:上下文(人格 / 画像 / 主人关系 / 最近记忆)──
|
|
1027
1041
|
if (method === 'GET' && path === '/life/context') {
|
|
1042
|
+
if (!lifeAuthed(req, getConfig)) return send(401, { ok: false, error: 'unauthorized' });
|
|
1028
1043
|
const nowVirtual = clock.now();
|
|
1029
1044
|
const personaRaw = typeof persona === 'function' ? persona() : (persona ?? {});
|
|
1030
1045
|
const master = ensureMasterPerson(db, nowVirtual);
|
|
@@ -1064,6 +1079,7 @@ export function registerRoutes(ctx, deps) {
|
|
|
1064
1079
|
// ── 桌面宠物 v1 互通:互动回传(点击 / 拖拽 / 聊天 / 语音 / 唤醒)──
|
|
1065
1080
|
if (method === 'POST' && path === '/life/interaction') {
|
|
1066
1081
|
if (!sameOrigin(req)) return send(403, { ok: false, reason: 'forbidden' });
|
|
1082
|
+
if (!lifeAuthed(req, getConfig)) return send(401, { ok: false, error: 'unauthorized' });
|
|
1067
1083
|
let body;
|
|
1068
1084
|
try { body = JSON.parse(await readBody(req, logger) || '{}'); } catch { return send(400, { ok: false, reason: 'invalid-json' }); }
|
|
1069
1085
|
const type = String(body.type ?? '');
|
|
@@ -1094,6 +1110,20 @@ export function registerRoutes(ctx, deps) {
|
|
|
1094
1110
|
return send(200, { ok: true, apiVersion: 1, interaction: { type, petId, at: nowVirtual, memoryId } });
|
|
1095
1111
|
}
|
|
1096
1112
|
|
|
1113
|
+
// ── 桌面宠物互通令牌管理:generate 当次返回一次明文(要复制给桌宠端),其余一律 masked ──
|
|
1114
|
+
if (method === 'POST' && path === '/desktop/pet-token') {
|
|
1115
|
+
if (!sameOrigin(req)) return send(403, { ok: false, error: 'forbidden' });
|
|
1116
|
+
let body;
|
|
1117
|
+
try { body = JSON.parse(await readBody(req, logger) || '{}'); } catch { return send(400, { ok: false, error: 'invalid-json' }); }
|
|
1118
|
+
const action = String(body.action ?? '');
|
|
1119
|
+
if (action !== 'generate' && action !== 'revoke') return send(400, { ok: false, error: 'bad-request' });
|
|
1120
|
+
const tools = getConfig()?.tools ?? {};
|
|
1121
|
+
const desktopPetToken = action === 'generate' ? randomBytes(24).toString('base64url') : '';
|
|
1122
|
+
saveConfig({ tools: { ...tools, desktopPetToken } });
|
|
1123
|
+
const hasToken = desktopPetToken !== '';
|
|
1124
|
+
return send(200, { ok: true, hasToken, tokenMasked: maskKey(desktopPetToken), ...(action === 'generate' ? { token: desktopPetToken } : {}) });
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1097
1127
|
return send(404, { ok: false, error: 'not found' });
|
|
1098
1128
|
} catch (error) {
|
|
1099
1129
|
logger('error', `[fish-soul] 路由异常:${String(error instanceof Error ? error.message : error)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-fish-soul",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.30",
|
|
4
4
|
"description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
|
-
"test": "node test/check-test-chain.mjs && node test/config-shape-contract.mjs && node test/affected-suites-clean.mjs && node test/new-export-gate-rule.mjs && node test/check-commit-author.mjs && node test/check-docs-version-refs.mjs && node test/affected-suites-test.mjs && node test/check-commit-author-rule.mjs && node test/check-commit-author-wire.mjs && node test/check-docs-version-refs-rule.mjs && node test/check-docs-version-refs-wire.mjs && node test/check-release-version.mjs && node test/wire-helper.mjs && node test/marker-audit.mjs && node test/douyin-send.mjs && node test/douyin-mechanism.mjs && node test/douyin-route.mjs && node test/douyin-adapter.mjs && node test/douyin-contract.mjs && node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-push-poll-dedupe.mjs && node test/douyin-share-card-dedupe.mjs && node test/douyin-share-card-dom.mjs && node test/douyin-inline-share.mjs && node test/douyin-short-link.mjs && node test/douyin-inline-ledger.mjs && node test/douyin-group-chat.mjs && node test/douyin-group-read.mjs && node test/douyin-group-reply.mjs && node test/session-overflow-recycle.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-meta-lines.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-live-fails.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-note-upload-poll.mjs && node test/douyin-post-jobs.mjs && node test/douyin-video-post.mjs && node test/douyin-video-trigger.mjs && node test/douyin-video-driver.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/prompts.mjs && node test/prompts-route.mjs && node test/diary-topics-217.mjs && node test/smoke.mjs && node test/life-context-interaction.mjs && node test/life-clock-refresh.mjs && node test/browser-launch-early-exit.mjs && node test/douyin-browser.mjs && node test/douyin-crash-restore.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/douyin-ax-button.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/slang-global.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/retrieval-tier-weights.mjs && node test/retrieval-tier-weights-route.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/llm-roomy-budget.mjs && node test/llm-failure-backoff.mjs && node test/llm-budget-and-social-backoff.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/dsh-desktop-as-master.mjs && node test/desktop-as-master-switch.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/diag-douyin-running.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/repeat-guard-cross-turn.mjs && node test/voice-paragraph-split.mjs && node test/voice-paragraph-split-wire.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/douyin-panel-width-threshold.mjs && node test/douyin-emoji-panel-close.mjs && node test/relay-other-platform.mjs && node test/relay-to-friend.mjs && node test/relay-sender-id.mjs && node test/data-dir.mjs && node test/data-dir-panel.mjs && node test/dsh-home-guard.mjs && node test/relay-config-route.mjs && node test/share-fallback.mjs && node test/share-quota-refund.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/outbound-quote-and-images.mjs && node test/sticker-bracket-fallback.mjs && node test/dream-transcript-scope.mjs && node test/memory-date-context.mjs && node test/memory-time-dedupe.mjs && node test/context-source-platform.mjs && node test/memory-source-label.mjs && node test/issue-239-maxtokens-wire.mjs && node test/issue-239-maxtokens.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs && node test/qq-mention-only-echo.mjs && node test/bili-panel-pagination.mjs && node test/bili-comment-link.mjs && node test/bili-comment-visibility.mjs && node test/bili-allowlist.mjs && node test/douyin-master-uid-mismatch.mjs && node test/vision-model.mjs && node test/image-inbound-fail.mjs && node test/group-backlog-images.mjs && node test/group-master-tag.mjs && node test/check-route-guard.mjs && node test/check-client-imports.mjs && node test/chat-archive-fts.mjs && node test/chat-search-tool.mjs && node test/memory-invalidate-kind.mjs && node test/dream-merge-duplicates.mjs && node test/mood-guard.mjs && node test/time-awareness.mjs && node test/tts-strip-emoji.mjs && node test/session-reset-route.mjs && node test/check-secrets.mjs && node test/check-secrets-nickname.mjs && node test/check-docs-freshness.mjs && node test/check-package-json-format.mjs && node test/wire-limits.mjs && node test/check-chromium-suites.mjs && node test/check-no-stash-scripts.mjs && node test/douyin-video-wire.mjs && node test/douyin-self-uid.mjs && node test/douyin-group-cursor.mjs && node test/douyin-dom-text.mjs && node test/video-gen.mjs && node test/scheduled-tasks.mjs && node test/scheduled-tasks-ui.mjs && node test/douyin-wave12-fixes.mjs && node test/prefetch-vec-await.mjs && node test/wave2-token-optimizations.mjs && node test/wave3-memory-retrieval.mjs && node test/rc5-token-inflation.mjs && node test/pending-surfaced-closure.mjs && node test/memory-digest-retry-239.mjs && node test/issue-244-paragraph-split.mjs && node test/issue-244-cleanout-e2e.mjs && node test/issue-269-qq-split-budget.mjs && node test/voice-mention-guard.mjs && node test/issue-247-media-url.mjs && node test/check-fork-pr-gate.mjs && node test/check-pr-hygiene.mjs && node test/check-import-cycles.mjs && node test/check-file-size-budget.mjs && node test/check-file-size-budget-rule.mjs && node test/check-silent-catch.mjs && node test/check-silent-catch-rule.mjs && node test/douyin-cookie-refresh.mjs && node test/douyin-back-to-list.mjs && node test/douyin-fastpath.mjs && node test/douyin-post-id-backfill.mjs && node test/douyin-canary-panel.mjs && node test/douyin-note-text.mjs && node test/bili-playback.mjs && node test/prompts-diary.mjs && node test/interject-interest.mjs && node test/transcript-master-only.mjs && node test/usage-visualization.mjs && node test/douyin-media-id-dedupe.mjs",
|
|
67
|
+
"test": "node test/check-test-chain.mjs && node test/config-shape-contract.mjs && node test/affected-suites-clean.mjs && node test/new-export-gate-rule.mjs && node test/check-commit-author.mjs && node test/check-docs-version-refs.mjs && node test/affected-suites-test.mjs && node test/check-commit-author-rule.mjs && node test/check-commit-author-wire.mjs && node test/check-docs-version-refs-rule.mjs && node test/check-docs-version-refs-wire.mjs && node test/check-release-version.mjs && node test/wire-helper.mjs && node test/marker-audit.mjs && node test/douyin-send.mjs && node test/douyin-mechanism.mjs && node test/douyin-route.mjs && node test/douyin-adapter.mjs && node test/douyin-contract.mjs && node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-push-poll-dedupe.mjs && node test/douyin-share-card-dedupe.mjs && node test/douyin-share-card-dom.mjs && node test/douyin-inline-share.mjs && node test/douyin-short-link.mjs && node test/douyin-inline-ledger.mjs && node test/douyin-group-chat.mjs && node test/douyin-group-read.mjs && node test/douyin-group-reply.mjs && node test/session-overflow-recycle.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-meta-lines.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-live-fails.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-note-upload-poll.mjs && node test/douyin-post-jobs.mjs && node test/douyin-video-post.mjs && node test/douyin-video-trigger.mjs && node test/douyin-video-driver.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/prompts.mjs && node test/prompts-route.mjs && node test/diary-topics-217.mjs && node test/smoke.mjs && node test/life-context-interaction.mjs && node test/life-pet-token.mjs && node test/desktop-pet-token-panel.mjs && node test/life-clock-refresh.mjs && node test/browser-launch-early-exit.mjs && node test/douyin-browser.mjs && node test/douyin-crash-restore.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/douyin-ax-button.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/slang-global.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/retrieval-tier-weights.mjs && node test/retrieval-tier-weights-route.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/llm-roomy-budget.mjs && node test/llm-failure-backoff.mjs && node test/llm-budget-and-social-backoff.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/dsh-desktop-as-master.mjs && node test/desktop-as-master-switch.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/diag-douyin-running.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/repeat-guard-cross-turn.mjs && node test/voice-paragraph-split.mjs && node test/voice-paragraph-split-wire.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/douyin-panel-width-threshold.mjs && node test/douyin-emoji-panel-close.mjs && node test/relay-other-platform.mjs && node test/relay-to-friend.mjs && node test/relay-sender-id.mjs && node test/data-dir.mjs && node test/data-dir-panel.mjs && node test/dsh-home-guard.mjs && node test/relay-config-route.mjs && node test/share-fallback.mjs && node test/share-quota-refund.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/outbound-quote-and-images.mjs && node test/sticker-bracket-fallback.mjs && node test/dream-transcript-scope.mjs && node test/memory-date-context.mjs && node test/memory-time-dedupe.mjs && node test/context-source-platform.mjs && node test/memory-source-label.mjs && node test/issue-239-maxtokens-wire.mjs && node test/issue-239-maxtokens.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs && node test/qq-mention-only-echo.mjs && node test/bili-panel-pagination.mjs && node test/bili-comment-link.mjs && node test/bili-comment-visibility.mjs && node test/bili-allowlist.mjs && node test/douyin-master-uid-mismatch.mjs && node test/vision-model.mjs && node test/image-inbound-fail.mjs && node test/group-backlog-images.mjs && node test/group-master-tag.mjs && node test/check-route-guard.mjs && node test/check-client-imports.mjs && node test/chat-archive-fts.mjs && node test/chat-search-tool.mjs && node test/memory-invalidate-kind.mjs && node test/dream-merge-duplicates.mjs && node test/mood-guard.mjs && node test/time-awareness.mjs && node test/tts-strip-emoji.mjs && node test/session-reset-route.mjs && node test/check-secrets.mjs && node test/check-secrets-nickname.mjs && node test/check-docs-freshness.mjs && node test/check-package-json-format.mjs && node test/wire-limits.mjs && node test/check-chromium-suites.mjs && node test/check-no-stash-scripts.mjs && node test/douyin-video-wire.mjs && node test/douyin-self-uid.mjs && node test/douyin-group-cursor.mjs && node test/douyin-dom-text.mjs && node test/video-gen.mjs && node test/scheduled-tasks.mjs && node test/scheduled-tasks-ui.mjs && node test/douyin-wave12-fixes.mjs && node test/prefetch-vec-await.mjs && node test/wave2-token-optimizations.mjs && node test/wave3-memory-retrieval.mjs && node test/rc5-token-inflation.mjs && node test/pending-surfaced-closure.mjs && node test/memory-digest-retry-239.mjs && node test/issue-244-paragraph-split.mjs && node test/issue-244-cleanout-e2e.mjs && node test/issue-269-qq-split-budget.mjs && node test/voice-mention-guard.mjs && node test/issue-247-media-url.mjs && node test/check-fork-pr-gate.mjs && node test/check-pr-hygiene.mjs && node test/check-import-cycles.mjs && node test/check-file-size-budget.mjs && node test/check-file-size-budget-rule.mjs && node test/check-silent-catch.mjs && node test/check-silent-catch-rule.mjs && node test/douyin-cookie-refresh.mjs && node test/douyin-back-to-list.mjs && node test/douyin-fastpath.mjs && node test/douyin-post-id-backfill.mjs && node test/douyin-canary-panel.mjs && node test/douyin-note-text.mjs && node test/bili-playback.mjs && node test/prompts-diary.mjs && node test/interject-interest.mjs && node test/transcript-master-only.mjs && node test/usage-visualization.mjs && node test/douyin-media-id-dedupe.mjs",
|
|
68
68
|
"test:douyin": "node test/parallel.mjs 4 --only douyin",
|
|
69
69
|
"test:fast": "node test/parallel.mjs 4 --skip \"douyin|browser\"",
|
|
70
70
|
"typecheck": "npx --yes -p typescript tsc -p tsconfig.check.json"
|