qq-bot-roost 1.1.6 → 1.1.8

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.
Files changed (43) hide show
  1. package/README.md +44 -13
  2. package/docs/AI/345/256/277/344/270/273/346/216/245/345/205/245.md +1 -1
  3. package/docs/DSH/346/216/245/345/205/245.md +3 -3
  4. package/docs//345/217/221/347/211/210/346/270/205/345/215/225.md +41 -30
  5. package/docs//345/256/277/344/270/273/345/215/217/350/256/256v1.md +19 -0
  6. package/docs//345/274/200/346/224/276/345/271/263/345/217/260/346/216/245/345/217/243.md +17 -0
  7. package/docs//346/217/222/344/273/266/345/274/200/345/217/221/350/247/204/350/214/203.md +1 -1
  8. package/docs//346/236/266/346/236/204/350/257/264/346/230/216.md +45 -1
  9. package/docs//351/205/215/347/275/256/345/217/202/350/200/203.md +5 -0
  10. package/package.json +7 -6
  11. package/src/api.js +40 -4
  12. package/src/bot.js +45 -8
  13. package/src/check.js +141 -0
  14. package/src/delivery.js +5 -3
  15. package/src/dev/browser.js +81 -0
  16. package/src/dev/platform.js +96 -0
  17. package/src/doctor.js +26 -8
  18. package/src/gateway.js +26 -0
  19. package/src/gitee.js +6 -3
  20. package/src/host/dispatch.js +5 -0
  21. package/src/host/methods.js +26 -1
  22. package/src/host/ops.js +14 -23
  23. package/src/ledger.js +69 -9
  24. package/src/mail/verify.js +3 -0
  25. package/src/main.js +29 -4
  26. package/src/message.js +11 -1
  27. package/src/mirror.js +7 -4
  28. package/src/onebot/actions.js +8 -0
  29. package/src/onebot/ids.js +33 -16
  30. package/src/outbound.js +108 -21
  31. package/src/plugin/api-record.js +2 -0
  32. package/src/plugin/market.js +11 -48
  33. package/src/proxy.js +14 -1
  34. package/src/repo.js +22 -0
  35. package/src/storage/events-schema.js +32 -1
  36. package/src/storage/schema.js +29 -1
  37. package/src/trust.js +7 -5
  38. package/src/updater.js +6 -6
  39. package/src/web/server.js +40 -41
  40. package/web/app.js +965 -159
  41. package/web/index.html +131 -37
  42. package/web/style.css +534 -193
  43. package/web/theme-boot.js +56 -5
package/README.md CHANGED
@@ -8,11 +8,11 @@
8
8
 
9
9
  <img src="https://img.shields.io/badge/Node.js-22.13%2B-339933?logo=node.js&logoColor=white" alt="Node.js 22.13+">
10
10
  <img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="零依赖">
11
- <img src="https://img.shields.io/badge/tests-1307%20passed-brightgreen" alt="测试 1307 项">
11
+ <img src="https://img.shields.io/badge/tests-1338%20passed-brightgreen" alt="测试 1338 项">
12
12
  <img src="https://img.shields.io/badge/plugins-JS%20%7C%20Python%20%7C%20Go%20%7C%20any-blue" alt="多语言插件">
13
- <img src="https://img.shields.io/badge/version-1.1.6-blueviolet" alt="版本 1.1.6">
13
+ <img src="https://img.shields.io/badge/version-1.1.8-blueviolet" alt="版本 1.1.8">
14
14
  <img src="https://img.shields.io/badge/license-AGPL--3.0--only-blue" alt="AGPL-3.0-only">
15
- <a href="https://github.com/tdcq9594/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/tdcq9594/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
15
+ <a href="https://github.com/roost-qq/qq-bot-roost/actions"><img src="https://img.shields.io/github/actions/workflow/status/roost-qq/qq-bot-roost/ci.yml?branch=master" alt="CI"></a>
16
16
 
17
17
  [快速开始](#3-分钟跑起来) | [写插件](docs/插件开发规范.md) | [外部插件协议](docs/插件协议.md) | [配置参考](docs/配置参考.md) | [常见问题](docs/常见问题.md) | [贡献](CONTRIBUTING.md)
18
18
 
@@ -106,7 +106,7 @@
106
106
 
107
107
  **插件系统**
108
108
 
109
- - **插件不在本仓库**:全部放在 [qq-bot-roost-plugins](https://github.com/tdcq9594/qq-bot-roost-plugins),
109
+ - **插件不在本仓库**:全部放在 [qq-bot-roost-plugins](https://github.com/roost-qq/qq-bot-roost-plugins),
110
110
  面板「插件 → 市场」一键安装,**有新版会自动提示、一键更新**
111
111
  - **下载源可换**:国内直连 GitHub 经常超时,面板里能选 GitHub 官方 / Gitee 镜像
112
112
  (作者维护,内容逐字节相同)/ 自建前缀,**带一键测速**;`auto` 模式直连失败会
@@ -221,7 +221,7 @@ INFO [webui] 可视化面板: http://127.0.0.1:15207/
221
221
  想在服务器 / NAS 上跑,用容器更省事:
222
222
 
223
223
  ```bash
224
- git clone https://github.com/tdcq9594/qq-bot-roost.git
224
+ git clone https://github.com/roost-qq/qq-bot-roost.git
225
225
  cd qq-bot-roost
226
226
  cp config/bot.example.json config/bot.json # 首次,然后填 AppID / AppSecret
227
227
  docker compose up -d
@@ -252,6 +252,37 @@ docker compose up -d
252
252
 
253
253
  ---
254
254
 
255
+ ## 网络与代理
256
+
257
+ 框架只在**下载类**出站上走代理:插件市场索引与包、框架更新、镜像测速、Gitee 拉取。
258
+ QQ 官方接口、扫码登录、文件预签名上传**一律直连**——这些是国内地址,
259
+ 套一层本地代理只会更慢,甚至被对端拒掉。
260
+
261
+ 配置在 `config/bot.json` 的 `network.proxy`,三个取值:
262
+
263
+ | 值 | 行为 |
264
+ |---|---|
265
+ | `auto`(默认) | 先读 Windows 系统代理,再读环境变量 |
266
+ | `off` | 全部直连,不读任何代理设置 |
267
+ | `http://127.0.0.1:7890` | 只用这一个,不再猜(也接受不带 `http://` 的写法) |
268
+
269
+ `auto` 的顺序是**系统代理优先**(Clash / v2rayN 那个「系统代理」开关改的就是它),
270
+ 其次 `HTTPS_PROXY` / `HTTP_PROXY`,例外列表取 `NO_PROXY`。反过来(环境变量优先)
271
+ 在桌面场景更容易踩坑:机器上留着一个早就失效的 `HTTPS_PROXY`,框架会一直用那个坏的。
272
+ 只支持 http / https 代理,SOCKS 请用 Clash 之类的混合端口。
273
+
274
+ Windows 上读系统代理靠 `reg query`。企业策略、安全软件或沙箱可能直接拦掉 `reg.exe`,
275
+ 表现是「浏览器能打开、框架连不上」。设 `ROOST_NO_SYSTEM_PROXY=1` 绕开:
276
+
277
+ ```bash
278
+ ROOST_NO_SYSTEM_PROXY=1 node src/main.js
279
+ ```
280
+
281
+ 设了它就完全不碰注册表,只认 `network.proxy` / 环境变量 / 直连。当前实际生效的代理
282
+ 及其来源(系统设置 / 环境变量 / 手动)在面板**「插件管理」页 →「插件市场」卡片**里能直接看到。
283
+
284
+ ---
285
+
255
286
  ## 收事件:WebSocket 还是 Webhook
256
287
 
257
288
  官方两种都支持,框架都实现了:
@@ -461,7 +492,7 @@ bot/
461
492
  │ ├── web/server.js 面板服务端(REST + SSE)
462
493
  │ └── plugin/ 插件加载、配置、依赖、子进程宿主、面板页面注册
463
494
  ├── test/
464
- │ ├── selftest.mjs 框架自检(686 项)
495
+ │ ├── selftest.mjs 框架自检(689 项)
465
496
  │ ├── e2e.mjs 端到端测试(253 项,起真实服务打接口)
466
497
  │ ├── qrlogin.mjs 扫码建机器人(8 项)
467
498
  │ └── deps.mjs 插件依赖安装(11 项)
@@ -497,21 +528,21 @@ openid 完全不同。共享 `roles.json` 等于所有权限记录全部对不
497
528
 
498
529
  | 仓库 | 说明 |
499
530
  |------|------|
500
- | [qq-bot-roost-plugins](https://github.com/tdcq9594/qq-bot-roost-plugins) | 插件市场源,面板「插件 → 市场」从这里装 |
501
- | [dsh-roost](https://github.com/tdcq9594/dsh-roost) | DSH 插件:让 AI 通过本框架住进 QQ(走官方接口,不 hook 客户端) |
531
+ | [qq-bot-roost-plugins](https://github.com/roost-qq/qq-bot-roost-plugins) | 插件市场源,面板「插件 → 市场」从这里装 |
532
+ | [dsh-roost](https://github.com/roost-qq/dsh-roost) | DSH 插件:让 AI 通过本框架住进 QQ(走官方接口,不 hook 客户端) |
502
533
 
503
534
  ---
504
535
 
505
536
  ## 开发
506
537
 
507
538
  ```bash
508
- npm test # 自检 686 + qrlogin 8 + deps 11 + npm-registry 12 + deps-external 4,另跑 53 个 node:test 文件(共 568 项)
539
+ npm test # 自检 689 + qrlogin 8 + deps 11 + npm-registry 12 + deps-external 4,另跑 57 个 node:test 文件(共 614 项)
509
540
  npm run test:e2e # 端到端 253 项(起 mock 服务打全部接口,跑在临时目录)
510
- npm run test:all # 全量约 1542 项:自检 + 扫码 + 依赖 + e2e(真机驱动要真机,没配就跳过)
541
+ npm run test:all # 全量约 1591 项:自检 + 扫码 + 依赖 + e2e(真机驱动要真机,没配就跳过)
511
542
  npm run check:secrets # 扫硬编码凭据(CI 也跑这个,提交前建议过一遍)
512
543
  node src/main.js --mock # 不连 QQ,命令行发假消息调插件
513
544
  node src/main.js --mock --serve # 只开面板,调界面
514
- node src/main.js --check # 只验证凭证和网关
545
+ node src/main.js --check # 只体检:凭证 + 网关 + intents / 面板暴露面 / 插件目录,不启动机器人
515
546
  ```
516
547
 
517
548
  > **真凭据不要写进代码**,放 `config/bot.json`(已在 .gitignore 里)。
@@ -615,7 +646,7 @@ mock 模式下:直接输入文本 = 模拟一条群 @ 消息;`!as <openid>`
615
646
 
616
647
  ## 许可
617
648
 
618
- 本项目采用 **GNU Affero General Public License v3.0 only(AGPL-3.0-only)**,是 OSI 认证的开源许可证。完整条款见 [LICENSE](LICENSE)。版权持有人另有明确授权的场景,见 [LICENSE-EXCEPTIONS.md](LICENSE-EXCEPTIONS.md);未列出的场景仍按 AGPL 处理。
649
+ 本项目采用 **GNU Affero General Public License v3.0 only(AGPL-3.0-only)**,是 OSI 认证的开源许可证。完整条款见 [LICENSE](LICENSE)。
619
650
 
620
651
  | 场景 | 允许? |
621
652
  |------|--------|
@@ -623,7 +654,7 @@ mock 模式下:直接输入文本 = 模拟一条群 @ 消息;`!as <openid>`
623
654
  | 商业使用、收费分发、集成进商业产品 | ✅ 允许,但受下列条件约束 |
624
655
  | 分发源码或二进制给他人 | ✅ 必须同样以 AGPL-3.0-only 授权、保留声明并提供完整对应源码 |
625
656
  | 修改后通过网络向用户提供服务 | ✅ 视为分发,须向使用者提供对应源码(AGPL 第 13 条) |
626
- | 改用更宽松许可、闭源再分发 | ❌ 不允许(除 [LICENSE-EXCEPTIONS.md](LICENSE-EXCEPTIONS.md) 明确列出的场景) |
657
+ | 改用更宽松许可、闭源再分发 | ❌ 不允许 |
627
658
 
628
659
  两点要说明白:
629
660
 
@@ -3,7 +3,7 @@
3
3
  Roost 可以被**外部 AI 宿主**驱动:它收消息、发消息、调官方接口,
4
4
  宿主(DeepSeek Harness 等)只管想和说。
5
5
 
6
- 这条通道最初是为 [dsh-roost](https://github.com/tdcq9594/dsh-roost) 做的,
6
+ 这条通道最初是为 [dsh-roost](https://github.com/roost-qq/dsh-roost) 做的,
7
7
  但它是通用的——任何能发 HTTP 的程序都能接。
8
8
 
9
9
  > 本文是**接入指南**(怎么连、怎么调、常见错)。方法表、握手、scope、补拉语义的
@@ -88,14 +88,14 @@ npx @deepseek-ai/dsh plugin --profile desktop add dsh-roost
88
88
  ### 方式三:从 GitHub
89
89
 
90
90
  ```bash
91
- npx @deepseek-ai/dsh plugin --profile desktop add github:tdcq9594/qq-bot-roost
91
+ npx @deepseek-ai/dsh plugin --profile desktop add github:roost-qq/qq-bot-roost
92
92
  ```
93
93
 
94
94
  **这条目前装不了。** 原因:`dsh plugin add github:...` 会把整个仓库当插件包,
95
95
  但插件的 `package.json` 在 `integrations/dsh-roost/` 子目录里,
96
96
  而 pnpm 的 git 依赖没有可靠的「指定子目录」语法。
97
97
 
98
- 要支持这种方式,得把插件拆成独立仓库(`tdcq9594/dsh-roost`)。
98
+ 要支持这种方式,得把插件拆成独立仓库(`roost-qq/dsh-roost`)。
99
99
  **在拆之前,用方式一。**
100
100
 
101
101
  ---
@@ -237,7 +237,7 @@ AI 看到后者只会瞎猜,看到前者才知道该建议你启动 Roost。
237
237
  ## 后续
238
238
 
239
239
  - [ ] 发到 npm,让 `dsh plugin add dsh-roost` 可用
240
- - [ ] 拆独立仓库,支持 `github:tdcq9594/dsh-roost`
240
+ - [ ] 拆独立仓库,支持 `github:roost-qq/dsh-roost`
241
241
  - [ ] 提交到 DSH 插件市场收录
242
242
 
243
243
  ---
@@ -6,17 +6,19 @@
6
6
 
7
7
  ## 0. 总流程(先看这个)
8
8
 
9
- 1. 从 master 拉分支,改代码 + bump 版本 + 写 notes + 重生成指纹(下面 1–3 步)
10
- 2. 开 PR → CI 全绿(框架仓 8 项必需检查)→ 合并进 master
11
- 3. 合并触发 `release.yml`,两个 job:
12
- - **发版前校验**:版本必须递增、notes 顶部段版本 = package.json、指纹与内容一致
13
- - **建 tag / 验签 / Release / 发 npm / 发后自检**:**停下等你点 Approve**(`Release` environment),
14
- 批准后自动做:CI 代签 → 验签门禁 → 建 tag → 建 Release → 上传 `SHA256SUMS`+`.sig` 附件
15
- → 发 npm → 发后自检 → `beta` 对齐
9
+ 1. 从 master 拉分支,跑 **`npm run release:prepare <版本>`**(bump + 两处徽章 + 文档测试数 +
10
+ 指纹一次做完),再补 `RELEASE_NOTES.md` 顶部段的正文(下面 1–3 步)
11
+ 2. 开 PR → **给 PR 打 `release` 标签** → CI 全绿(框架仓 8 项必需检查)→ 合并进 master
12
+ 3. 合并即触发 `release.yml`,两个 job 全自动、**不需要点任何 Approve**:
13
+ - **发版前校验**:版本必须递增、notes 顶部段版本 = package.json、指纹与内容一致、
14
+ 关联 PR 必须带 `release` 标签
15
+ - **建 tag / 验签 / Release / 发 npm / 发后自检**:CI 代签 → 验签门禁 → 建 tag → 建 Release
16
+ → 上传 `SHA256SUMS`+`.sig` 附件 → 发 npm → 发后自检 → `beta` 对齐
16
17
  4. 核对两端(第 6 步)——CI 已经自动核对过的项目,这里只是二次确认
17
18
 
18
19
  关键变化:**不再手动推 tag、不再本地签名、不再本地发 npm、不再本地对 beta**。
19
- 人只决定版本号和 notes,其余由 CI 串起来。
20
+ 人只决定**版本号**和 **notes 正文**,其余由 `release:prepare` 与 CI 串起来。
21
+ **发版开关是 PR 上的 `release` 标签**(2026-11-21 起,environment 审批已删):合并即发。
20
22
  分支保护已开(require PR + CI 检查),直接 push master/main 会被拒(管理员可绕过,但日常别用)。
21
23
 
22
24
  ## 1. 改完代码、跑测试
@@ -26,14 +28,20 @@
26
28
 
27
29
  > 指纹**不要在这一步跑**,见第 2 步。
28
30
 
29
- ## 2. 改版本号与文档(必须先 bump,再生成指纹)
31
+ ## 2. 改版本号与文档(`npm run release:prepare <版本>` 会一次做完这一整节)
32
+
33
+ > 手工做的话顺序是:先 bump 再生成指纹。自动化就一条命令:
34
+ > `npm run release:prepare 1.1.8`(`--dry-run` 只看要改什么,`--no-test` 跳过测试统计)。
35
+ > 它**不写 notes 正文、不提交**,这两件事仍由人做。
30
36
 
31
37
  - [ ] `package.json` 的 `version` —— **先改这个**
32
- - [ ] `RELEASE_NOTES.md`:新版本段落写在**最上面**
33
- - [ ] **`README.md` 里会过期的数字都要对一遍**:
38
+ - [ ] `RELEASE_NOTES.md`:新版本段落写在**最上面**(`release:prepare` 只插骨架,正文要人写)
39
+ - [ ] **`README.md` 里会过期的数字都要对一遍**(`release:prepare` 会按实测值自动改):
34
40
  - 版本徽章(`badge/version-x.y.z`)——**这是硬门禁**:`ci.yml` 的 `版本徽章` job
35
41
  已进必需检查,徽章和 `package.json` 不一致,PR 直接过不了
36
- - 测试数量徽章(`431/431` 这种,改了测试就会变)
42
+ - 测试数量徽章(`1337 passed` 这种,改了测试就会变)
43
+ - 目录树里的「框架自检(N 项)」「端到端测试(N 项)」
44
+ - 命令速查里的「自检 N + qrlogin N + …,另跑 N 个 node:test 文件(共 N 项)」和「全量约 N 项」
37
45
  - 官方接口数量、插件数量、文档里写死的行号/文件名
38
46
  - 这些是硬编码的,代码改了不跟着改就会挂一个错的数字在上面
39
47
  - [ ] 其他提到版本号的文档(`docs/*.md` 里的「当前版本」段)
@@ -71,7 +79,7 @@
71
79
 
72
80
  - [ ] **什么都不用做**。`SIGN_IN_CI=true` 已开,发版 job 会自己签:
73
81
  - 私钥来自 `Release` environment 的 secret `TRUST_PRIVATE_PEM`,
74
- 只有人工批准 environment 之后才注入,用完立即从 runner 删除
82
+ 只在发版 job 里注入(审批规则 2026-11-21 已删,合并即发),用完立即从 runner 删除
75
83
  - `SHA256SUMS` 变了就重签,签名仍有效则跳过(重跑幂等)
76
84
  - 签完用内嵌公钥验一遍(**验签门禁**),私钥公钥不配对直接红,不发版
77
85
  - 最后把 `SHA256SUMS` 和 `.sig` **成对挂到 Release 附件**——
@@ -89,35 +97,38 @@
89
97
  否则验签门禁会因为「没有签名文件」直接红。
90
98
  产出与 CI 签的字节完全相同(Ed25519 是确定性签名),只是换谁执行
91
99
 
92
- ### 插件仓:仍需本地签
100
+ ### 插件仓:发框架版时不用碰
101
+
102
+ 2026-11-19 起**插件市场索引不再签名**(`index.json.sig` / `trust-public.pem` /
103
+ `sign-index.mjs` / 手动签名 workflow 全部删除)。本节以前的「插件仓仍需本地签、
104
+ 漏签会让框架自更新被拒」是错的:插件索引签名和框架自更新的 `SHA256SUMS.sig`
105
+ 是两套独立的签名,互不干涉。
93
106
 
94
- - [ ] **插件仓**:`ROOST_TRUST_KEY=<私钥路径> node scripts/build-index.mjs`
95
- - 生成索引时顺手签名,产出 `index.json.sig`
96
- - 只补签:`node scripts/sign-index.mjs --key <私钥>`
97
- - 校验:`node scripts/sign-index.mjs --verify`
98
- - [ ] 确认 `.sig` 已进提交(`git status` 里能看到)
99
- - 漏了会怎样:等面板「插件来源校验」开关打开后,**用户装不了插件、也更新不了框架**
100
- (`bad` 直接拒,`unsigned` 不在白名单也拒)。开关默认关,所以漏了不会立刻出事,
101
- 但下一版打开时就是全体事故
107
+ 插件内容完整性仍由 `index.json` 里每个插件的 `sha256` 保证,安装时重算比对;
108
+ 索引由维护者合并投稿后用 `node scripts/build-index.mjs` 重建。
102
109
 
103
110
  ## 4. 开 PR 并合并(不再手动推 tag)
104
111
 
105
112
  - [ ] `git add -A && git commit`(确认 `SHA256SUMS` 进了提交;框架仓 `.sig` 由 CI 生成,不必带)
106
- - [ ] `git push` 推分支 → 开 PR → 等 CI 全绿 → 合并进 master
113
+ - [ ] `git push` 推分支 → 开 PR → **给 PR 打 `release` 标签** → 等 CI 全绿 → 合并进 master
114
+ - **标签是唯一的发版开关**(2026-11-21 起):没打标签的 PR 合并后 `release.yml` 判 `skip`,
115
+ 只进代码不发版;summary 里会写明是「缺 release 标签」
107
116
  - **不要手动 `git tag` / `git push origin v<版本>`**——tag 由 CI 建,手动推会造成「tag 存在 but 内容没校验」的坏状态
108
117
  - [ ] 合并后看 `发版`(release.yml)这个 workflow:
109
- - `发版前校验` job:指纹与内容一致、notes 顶部段版本 = package.json 版本,任一不过就红且不发版
110
- - `建 tag / 验签 / Release / 发 npm / 发后自检` job:**会停在等待 `Release` environment 批准**——这是设计的闸门(把「提交前先问」变成系统强制),你去 Actions 页点 Approve 才继续
118
+ - `发版前校验` job:版本递增、notes 顶部段版本 = package.json、指纹与内容一致、
119
+ 关联 PR 带 `release` 标签,任一不过就红且不发版
120
+ - 校验通过后**直接发**:`Release` environment 的审批规则已在 2026-11-21 删除,
121
+ **不需要再去 Actions 页点 Approve**(environment 本身保留——私钥 secret 与 npm OIDC 环境名挂在上面)
111
122
 
112
- - [ ] 点批准后,确认该 job 依次完成:验签门禁 → 建 tag `v<版本>` → 建 GitHub Release
113
- → 上传 `SHA256SUMS` + `.sig` 附件 → 发 npm → 发后自检
114
- (只看「有没有触发」不算数,要看每一步都绿;发后自检会核对
115
- `releases/latest`、npm 版本、以及两个附件是否真的挂上去了)
123
+ - [ ] 确认该 job 依次完成:验签门禁 → 建 tag `v<版本>` → 建 GitHub Release
124
+ → 上传 `SHA256SUMS` + `.sig` 附件 → 发 npm → 发后自检 → `beta` 对齐
125
+ (只看「有没有触发」不算数,要看每一步都绿;发后自检会核对
126
+ `releases/latest`、npm 版本、以及两个附件是否真的挂上去了)
116
127
 
117
128
  ### ⚠️ GitHub Release 由 CI 自动建(但要核对)
118
129
 
119
130
  PR 合并后 `release.yml` 的 `建 tag / 验签 / Release / 发 npm / 发后自检` job 会**自动建 Release**,不用再手工建。
120
- 前提:notes 顶部段版本 = 版本号、指纹校验都通过、且你批准了 `Release` environment;
131
+ 前提:notes 顶部段版本 = 版本号、指纹校验都通过、关联 PR 带 `release` 标签;
121
132
  不通过 CI 会红且**不建**,这时要先修 notes/指纹再重发 PR,别手工硬建绕过校验。
122
133
 
123
134
  只推 tag **不建 Release** 的话,框架的检查更新就失效了:
@@ -193,6 +193,25 @@ data: {"at":1731400000000}
193
193
  用 `msg.get` 查。`notice` 事件是 `{seq, at, event, data}`,`data` 是框架
194
194
  回调原样传入的对象。
195
195
 
196
+ ### 账本行的 `source` 字段(v4)
197
+
198
+ `msg.get` / `ledger.recent` / `ledger.context` 返回的行都带 `source`,说明
199
+ **这条是从哪个口子进来的或出去的**,和 `plugin`(谁说的)是两个维度:
200
+
201
+ | `source` | 含义 |
202
+ |---|---|
203
+ | `gateway` / `webhook` | 入站:官方 WebSocket 网关 / Webhook 回调 |
204
+ | `plugin` | 出站:框架内插件发起(具体是谁看 `plugin`),含 `msg.replyStream` |
205
+ | `host` | 出站:自有宿主协议(本协议 `msg.send` / `msg.stream`) |
206
+ | `onebot` | 出站:OneBot v11 兼容层(客户端 `send_msg` 等) |
207
+ | `api` / `mock` / `dev` / `import` | 内部直连兜底 / 模拟消息 / 面板注入 / 导入补录 |
208
+ | `''` | 早于 v4 的老记录。**空串表示「不知道」,不要当入站判据** |
209
+
210
+ 宿主侧最常用的一条:写记忆时想区分「用户说的」和「机器人/第三方客户端说的」,
211
+ **正向判入站**(`source === 'gateway' || source === 'webhook'`),别反向用
212
+ `source !== ...` —— 老行和内部兜底都是空串,反过来会把它们误判成入站。
213
+ 只要第三方客户端发的,按 `source === 'onebot'` 过滤。
214
+
196
215
  ## 4. 方法表
197
216
 
198
217
  `system.capabilities` 会返回完整清单(含每个方法所需 scope),这里列分组。
@@ -94,10 +94,26 @@ GET /api/dev/session?verify=1
94
94
  - 无头跑不起来的环境(远程桌面 / 安全软件拦 / 老旧内核):`ROOST_DEV_REFRESH_MODE=window`
95
95
  换成可见窗口,只作排障用。
96
96
  - 面板回显在 `GET /api/dev/status` 的 `autoRelogin.last`(`ok` / `reason` / `message`)。
97
+ - **登录成功即翻篇**:扫码 / 粘 cURL 验通过时把上一轮的换票结论清掉(退避归零、
98
+ 排定的补拉撤掉),面板不会在「已登录」下面继续挂一条「自动换票没成功」。
99
+ 典型场景是扫码过程中 `verify` 撞了 401,续期跑去换票只拿到半份票——人其实已经
100
+ 登上了,那条红字却要挂 3 分钟。前端还兜了一刀:票比那次失败新,就不显示失败。
97
101
 
98
102
  > profile 里的登录态也过期了(比如你手动退出过),续期会在 25 秒后收窗并报
99
103
  > `timeout`,此时只能重新扫码——自动续期不会把人架在「等一个永远不会成功的窗口」上。
100
104
 
105
+ ### 手动检查登录状态(面板上的兜底按钮)
106
+
107
+ 自动检测有自己的节奏:校验失败要退避(最慢 15 秒一轮),限频更慢;页面登录慢
108
+ 半拍、票刚种上又被刷掉、窗口被随手关掉,都会让面板停在「等待扫码」。
109
+
110
+ `POST /api/dev/login/recheck` 就是给人点的那一下:
111
+
112
+ - 窗口还开着 → 立刻读一次 cookie,**够用才发校验**(半份票不认,抢跑会 401),
113
+ 通过就把状态推到 `ok`;
114
+ - 窗口已经关了但手里还有票 → 拿这张票真发一次 `list_bots`,至少给个明确结论;
115
+ - 什么都没 → 直说「窗口里还没有登录态」,让人重新扫码,而不是干等。
116
+
101
117
  ---
102
118
 
103
119
  ## 二、HTTP 接口
@@ -110,6 +126,7 @@ GET /api/dev/session?verify=1
110
126
  | POST | `/api/dev/login/scan` | 起扫码窗口(同步等窗口就绪,1–3 秒) |
111
127
  | GET | `/api/dev/login/scan` | 轮询扫码进度 |
112
128
  | POST | `/api/dev/login/scan/cancel` | 取消扫码并关窗 |
129
+ | POST | `/api/dev/login/recheck` | 手动核一次登录态(扫完码面板没反应时点):窗口还在就先读票再校验,窗口没了就拿手里的票真发一次 `list_bots` |
113
130
  | POST | `/api/dev/login/import` | 备选:粘 cURL / cookie |
114
131
  | POST | `/api/dev/remember` | 登录后改「要不要记住」:立刻写盘 / 删盘,不用重登 |
115
132
  | POST | `/api/dev/logout` | 清票据(连扫码窗口 profile 一起删) |
@@ -697,7 +697,7 @@ export default {
697
697
  - 存档结构变更时,考虑在 `setup()` 里做一次迁移,而不是让旧数据变孤儿
698
698
 
699
699
  完整的发布流程、版本比较规则、更新时会发生什么,见插件仓库的
700
- [插件更新规范](https://github.com/tdcq9594/qq-bot-roost-plugins/blob/main/docs/插件更新规范.md)。
700
+ [插件更新规范](https://github.com/roost-qq/qq-bot-roost-plugins/blob/main/docs/插件更新规范.md)。
701
701
 
702
702
  ### 5.4 其他
703
703
 
@@ -175,6 +175,50 @@ const roles = rt.roles;
175
175
 
176
176
  SSE 用 `Map<res, botId>` 记录每个连接在看哪个机器人,各自推各自的状态。
177
177
 
178
+ ### 面板配色:黑夜固定黑白,白天可调
179
+
180
+ 「外观」页(`data-tab="appearance"`,在「系统」组)分两块,边界很清楚:
181
+
182
+ | | 黑夜 | 白天 |
183
+ |---|---|---|
184
+ | 配色 | **固定黑白**,不提供任何换色入口 | 10 套预设(5 套内置手挑 + 5 套按主色派生)+ 自定义主色 |
185
+ | 背景图 | 生效 | 生效 |
186
+
187
+ 为什么黑夜不给换色(参考 `KunMoe/kun-galgame-forum` 的做法):暗底上的品牌色
188
+ 不是发脏就是刺眼,选项越多越难选对,不如只给一套中性色。所以 CSS 里
189
+ `[data-theme="dark"]` 没有任何 `[data-palette]` 覆盖,浅色配色块与派生块都带
190
+ `:not([data-theme="dark"])`——`data-palette` 在黑夜下不参与渲染。
191
+
192
+ > 踩过的坑:`:root[data-palette="b"]` 的特异性是 (0,2,0),**压得过** `[data-theme="dark"]`
193
+ > 的 (0,1,0)。只删暗色覆盖块、不给浅色块加 `:not([data-theme="dark"])`,结果就是
194
+ > 「换过底色之后,黑夜仍然是白的」。改配色相关的选择器时先算特异性。
195
+
196
+ 变量三层:
197
+
198
+ | 层 | 变量 | 谁能改 |
199
+ |---|---|---|
200
+ | 种子 | `--seed-light` / `--ink-light` | **用户**(仅浅色;深色不读) |
201
+ | 派生 | `--primary`(文字/描边)/ `--primary-fill`(实心填充)/ `--primary-fill-hover` / `--primary-soft` / `--primary-border` / `--primary-ring` / `--primary-ink` / `--primary-text` | CSS 自动算(`@supports (color: oklch(from …))` 内) |
202
+ | 语义 | `--ok` / `--warn` / `--err` / `--c-*` | **锁死内置**:红=失败是信息语义,不是审美 |
203
+
204
+ 几条硬规则:
205
+
206
+ - **浅色的实心填充**:L 定 0.55、色度 ×1.15(上限 0.22),白字对比 4.6–5.2:1 —— 这档是照
207
+ GitHub Primer `#1f6feb`、VS Code `#0078D4`、Radix `#6e56cf` 的暗色主按钮量出来的。
208
+ - **黑夜的按钮是白底黑字**(`--primary-fill: #ededed` / `--primary-ink: #0a0a0a`)。
209
+ - 内置五套配色(`data-palette="a|b|c|d|w"`:琥珀 / 靛蓝 / 青 / 紫罗兰 / 默认)**不参与派生**——
210
+ 它们的手挑值在 CSS 里,加 `data-appearance="custom"` 反而会漂移(实测 Δ7–24)。
211
+ 其余 5 套(玫红 / 姜黄 / 松绿 / 品红 / 浅蓝)+ 自定义统一走 `data-colorway="derived"`,
212
+ 连**底色**都按主色色相现算(`--bg` / `--panel-solid` / `--border` / 文字全套),
213
+ 所以 8 个配色不会出现「换个配色底色没变」——那正是早期只有 4 套底色导致的问题。
214
+ - **背景图存 IndexedDB**(`roost-ui/kv/background` 的 Blob),不进 localStorage:
215
+ 一张 1080p JPEG 转 base64 就 2–4 MB,而 localStorage 上限 5 MB 且同步读取,
216
+ `theme-boot.js` 首屏前读会卡。渲染走 `URL.createObjectURL`,铺在 `html::before` 上,
217
+ 主要表面转半透明(`--surface-alpha`)+ 背景模糊,文字才压得住底图。
218
+ - 用户偏好存 `localStorage["qqbot_appearance"]`(`{mode,preset,base,seed,ink,bg}`),
219
+ **不进 `config/`**:换浏览器就回默认,这是明确的取舍。
220
+ - 插件 iframe 的主题变量由服务端 `PAGE_THEME` 注入,只有亮/暗两套,**不跟随自定义主色**。
221
+
178
222
  ---
179
223
 
180
224
  ## 八、设计取舍记录
@@ -305,7 +349,7 @@ SSE 用 `Map<res, botId>` 记录每个连接在看哪个机器人,各自推各
305
349
  ### `plugins/`(本地,不入库)
306
350
 
307
351
  插件代码**不属于框架**,`plugins/` 已加 `.gitignore`。官方插件在
308
- [qq-bot-roost-plugins](https://github.com/tdcq9594/qq-bot-roost-plugins),
352
+ [qq-bot-roost-plugins](https://github.com/roost-qq/qq-bot-roost-plugins),
309
353
  面板「插件 → 市场」一键安装。本地现有的四个是示例/自用:
310
354
  `dice`(参数解析)、`echo`(消息监听 + 运行数据示例)、`hello-py`(外部 Python)、
311
355
  `kun`(完整玩法)。
@@ -282,6 +282,11 @@ Node 低于 22.5 或没编译 sqlite 时,`enabled` 设成什么都不影响—
282
282
 
283
283
  > 多机器人下环境变量容易串,**建议只用来做临时调试**,正式配置写文件。
284
284
 
285
+ 面板 / Webhook / 日志 / 代理这些**运行态**变量不对应任何配置字段,所以不在上表里:
286
+ `ROOST_WEBUI_HOST` / `ROOST_WEBUI_PORT` / `ROOST_WEBUI_KEY`、`ROOST_WEBHOOK_ENABLED` /
287
+ `ROOST_WEBHOOK_PORT`、`ROOST_LOG_LEVEL`、`ROOST_NO_SYSTEM_PROXY`。前几个见 README
288
+ 「Docker 部署」,`ROOST_NO_SYSTEM_PROXY` 见 README「网络与代理」。
289
+
285
290
  ---
286
291
 
287
292
  ## 从旧版本升级
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "qq-bot-roost",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
6
6
  "license": "AGPL-3.0-only",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/tdcq9594/qq-bot-roost.git"
9
+ "url": "git+https://github.com/roost-qq/qq-bot-roost.git"
10
10
  },
11
11
  "bugs": {
12
- "url": "https://github.com/tdcq9594/qq-bot-roost/issues"
12
+ "url": "https://github.com/roost-qq/qq-bot-roost/issues"
13
13
  },
14
- "homepage": "https://github.com/tdcq9594/qq-bot-roost#readme",
14
+ "homepage": "https://github.com/roost-qq/qq-bot-roost#readme",
15
15
  "keywords": [
16
16
  "qq-bot",
17
17
  "qqbot",
@@ -29,9 +29,10 @@
29
29
  "start": "node src/main.js",
30
30
  "mock": "node src/main.js --mock",
31
31
  "check": "node src/main.js --check",
32
- "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/market-source.mjs",
32
+ "release:prepare": "node scripts/release-prepare.mjs",
33
+ "test": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node --test test/plugin-observability.mjs && node --test test/outbound-dry.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/gateway-interaction-ack.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/market-source.mjs",
33
34
  "test:e2e": "node test/e2e.mjs",
34
- "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/market-source.mjs",
35
+ "test:all": "node test/selftest.mjs && node test/qrlogin.mjs && node test/deps.mjs && node test/npm-registry.mjs && node test/deps-external.mjs && node --test test/trust.mjs && node --test test/manifest.mjs && node --test test/market-cache.mjs && node --test test/market-kind.mjs && node --test test/instance-proc.mjs && node --test test/proxy.mjs && node --test test/trace.mjs && node --test test/fuzz-tar.mjs && node --test test/group-name.mjs && node --test test/message-fields.mjs && node --test test/people-list.mjs && node --test test/ledger-people.mjs && node --test test/ledger-search.mjs && node --test test/people-search.mjs && node --test test/host-ledger.mjs && node --test test/sync-beta-tag.mjs && node --test test/identity.mjs && node --test test/identity-commands.mjs && node --test test/mail.mjs && node --test test/ledger-outbound.mjs && node --test test/api-record.mjs && node --test test/transport-regressions.mjs && node --test test/check-mode.mjs && node --test test/reply-auto.mjs && node test/e2e.mjs && node test/live-driver.mjs && node --test test/ext-deps-migrate.mjs && node --test test/onebot-keep.mjs && node --test test/onebot-deps.mjs && node --test test/onebot-config.mjs && node --test test/onebot-segments.mjs && node --test test/onebot-outbound-at.mjs && node --test test/onebot-translate.mjs && node --test test/onebot-voice.mjs && node --test test/onebot-loopback.mjs && node --test test/host-protocol.mjs && node --test test/host-config.mjs && node --test test/host-tool-methods.mjs && node --test test/host-ext-bridge.mjs && node --test test/web-token-echo.mjs && node --test test/group-manage.mjs && node --test test/wakeup-payload.mjs && node --test test/typing.mjs && node --test test/media-convert.mjs && node --test test/host-dev.mjs && node --test test/dev-browser.mjs && node --test test/dev-cooldown.mjs && node --test test/onebot-profile.mjs && node --test test/dev-remember.mjs && node --test test/dev-scope.mjs && node --test test/dev-renew.mjs && node --test test/dev-ticket.mjs && node --test test/nickname.mjs && node --test test/url-guard.mjs && node --test test/plugin-update.mjs && node --test test/market-source.mjs",
35
36
  "check:secrets": "node scripts/check-secrets.mjs",
36
37
  "create": "node scripts/create-plugin.mjs",
37
38
  "test:plugin": "node scripts/test-plugin.mjs",
package/src/api.js CHANGED
@@ -368,7 +368,15 @@ export class QQApi {
368
368
  */
369
369
  if (!retried && isSafeToRetryNetworkError(code)) {
370
370
  log.warn(`连接没建起来,重试一次:${method} ${path}(${code})`);
371
- return this.#request(method, path, body, { retried: true, headers });
371
+ /**
372
+ * `multipart` 必须一起透传。
373
+ *
374
+ * 漏掉它的后果不是「多发一条」,而是**把带附件的请求变成 JSON**:
375
+ * 报文里 `file_image` 是 Buffer,`JSON.stringify` 后成了
376
+ * `{"type":"Buffer","data":[…]}`,平台必然 400 —— 重试等于白打一次,
377
+ * 还把真正的错误(连接没建起来)盖成一条看不懂的 400。
378
+ */
379
+ return this.#request(method, path, body, { retried: true, headers, multipart });
372
380
  }
373
381
  throw new Error(`网络错误 ${method} ${path}: ${reason}`);
374
382
  }
@@ -381,7 +389,7 @@ export class QQApi {
381
389
  const stale = this.tokens.token;
382
390
  log.warn('接口返回 401,刷新访问凭证');
383
391
  await this.tokens.refresh(stale);
384
- if (method === 'GET') return this.#request(method, path, body, { retried: true, headers });
392
+ if (method === 'GET') return this.#request(method, path, body, { retried: true, headers, multipart });
385
393
  throw new Error(`HTTP 401 ${method} ${path}: 凭证已刷新,但写请求不自动重试(避免重复发送)`);
386
394
  }
387
395
 
@@ -636,7 +644,14 @@ export class QQApi {
636
644
  }
637
645
  if (!res.ok) {
638
646
  const detail = await res.text().catch(() => '');
639
- throw new Error(`分片 PUT 失败 HTTP ${res.status}${detail ? `:${detail.slice(0, 200)}` : ''}`);
647
+ const err = new Error(`分片 PUT 失败 HTTP ${res.status}${detail ? `:${detail.slice(0, 200)}` : ''}`);
648
+ /**
649
+ * 把状态码挂出来。调用方(`uploadLocalFileSharded`)要靠它区分
650
+ * 「签名过期 / 413 超限」(重试无意义)和「5xx / 网络抖动」(值得重试)。
651
+ * 只给一句 message 的话,只能靠正则猜,迟早猜错。
652
+ */
653
+ err.status = res.status;
654
+ throw err;
640
655
  }
641
656
  return res.headers?.get('etag') ?? '';
642
657
  }
@@ -761,7 +776,22 @@ export class QQApi {
761
776
  return;
762
777
  } catch (e) {
763
778
  lastErr = e;
764
- if (Number(e?.qqCode) === 40093002) throw e; // 日配额,重试无用
779
+ /**
780
+ * 只有**明确可重试**的才继续等:
781
+ * · `40093001`:官方点名「BDH 通道异常」,给了 `retry_timeout`;
782
+ * · 网络层抖动 / 5xx:可能下一次就好。
783
+ *
784
+ * 以前除 `40093002` 外一律重试,于是 presigned URL 过期(403)、
785
+ * 413 超限、404 这类**重试一万次也不会变**的错,会按默认
786
+ * `retry_timeout=300s` 一片一片耗完——用户看到的是「发文件卡死五分钟」。
787
+ */
788
+ const qqCode = Number(e?.qqCode ?? 0);
789
+ const status = Number(e?.status ?? 0);
790
+ if (qqCode === 40093002) throw e; // 日配额,重试无用
791
+ const retriable = qqCode === 40093001
792
+ || status >= 500
793
+ || (!status && /timeout|timed out|超时|ECONNRESET|EPIPE|socket hang up|fetch failed|网络错误/i.test(String(e?.message ?? '')));
794
+ if (!retriable) throw e;
765
795
  await new Promise((r) => setTimeout(r, retryDelayMs));
766
796
  }
767
797
  }
@@ -1259,6 +1289,8 @@ export class QQApi {
1259
1289
 
1260
1290
  const hit = this.roleCache.get(key);
1261
1291
  if (hit && Date.now() - hit.at < maxAgeMs) return hit.value;
1292
+ // 过期就删键,别让它只在读时跳过、键却永久留着(群一多就是只增不减)。
1293
+ if (hit) this.roleCache.delete(key);
1262
1294
 
1263
1295
  let value;
1264
1296
  try {
@@ -1278,6 +1310,10 @@ export class QQApi {
1278
1310
 
1279
1311
  // 失败结果也缓存,避免每次调用都去撞一次 11253
1280
1312
  this.roleCache.set(key, { at: Date.now(), value });
1313
+ // 群数有上限,但查询过的历史群数没有;封顶,淘汰最早插入的(同 seqMap 写法)。
1314
+ if (this.roleCache.size > 2000) {
1315
+ this.roleCache.delete(this.roleCache.keys().next().value);
1316
+ }
1281
1317
  return value;
1282
1318
  }
1283
1319