qq-bot-roost 1.1.2 → 1.1.3

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.
@@ -125,6 +125,23 @@ npm publish --userconfig "$TEMP/.npmrc-pub" --access public
125
125
  - [ ] 等 registry 传播(通常几分钟):`npm view <包名> version`
126
126
  - 重发同版本会报 `403 previously published` —— **那说明已经写进去了**,别换版本号重发
127
127
 
128
+ ## 5.5 `beta` 标签对齐(每版都跑,幂等)
129
+
130
+ 规则(2026-11-17 主人定):**正式版版本号比 beta 高,就把 beta 指到最新版**。
131
+ 否则 `npm i <包名>@beta` 一直装着旧的预发布版。beta 比 latest 新时**不动**——
132
+ 那是真正的测试通道。
133
+
134
+ ```bash
135
+ # 在 bot 仓根目录跑(要读 config/bot.json 的 token)
136
+ # 本机系统代理经常是坏的,显式指定:
137
+ ROOST_NPM_PROXY=http://127.0.0.1:7892 node scripts/sync-beta-tag.mjs --dry-run
138
+ ROOST_NPM_PROXY=http://127.0.0.1:7892 node scripts/sync-beta-tag.mjs
139
+ ```
140
+
141
+ - 默认检查 `qq-bot-roost` 与 `dsh-roost`,也可以只传一个包名
142
+ - 输出 `beta=X 不低于 latest=Y,不动` 就是正常
143
+ - [ ] `npm view <包名> dist-tags` 里 `beta` 应指向新版本
144
+
128
145
  ## 6. 三端核对
129
146
 
130
147
  - [ ] GitHub:`git ls-remote origin refs/tags/v<版本>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qq-bot-roost",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "栖 Roost:零依赖的 QQ 官方机器人框架,填 AppID/AppSecret 即连,插件可写任意语言",
6
6
  "license": "AGPL-3.0-only",
@@ -29,9 +29,9 @@
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/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-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",
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-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",
33
33
  "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/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-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",
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-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",
35
35
  "check:secrets": "node scripts/check-secrets.mjs",
36
36
  "create": "node scripts/create-plugin.mjs",
37
37
  "test:plugin": "node scripts/test-plugin.mjs",
package/src/host/index.js CHANGED
@@ -31,6 +31,36 @@ import { serializeMessage, serializeNotice } from './serialize.js';
31
31
 
32
32
  const log = createLogger('host');
33
33
 
34
+ /**
35
+ * rpc 失败的统一序列化。
36
+ *
37
+ * 抽成纯函数是为了能单测:这里出过一次真事故——`api.js` 把官方业务码放在
38
+ * `err.qqCode` 上(11253 没权限 / 503004 发帖太频 / 304018 没连上网关),
39
+ * 而这里只序列化 `code` + `message`,**业务码在跨进程那一步被丢掉**。
40
+ * 后果是宿主只能看到「HTTP 400 PUT …: 中文描述」,没法区分「去开放平台勾权限」
41
+ * 和「等十分钟再发」,只能把原文甩给用户。
42
+ *
43
+ * 没有业务码时**不加这个字段**:老客户端读到 undefined 等同于「没有」。
44
+ *
45
+ * @param {Error & { code?: string, http?: number, qqCode?: number }} e
46
+ * @returns {{ code: string, http: number, error: { code: string, message: string, qqCode?: number } }}
47
+ */
48
+ export function serializeRpcError(e) {
49
+ const code = e instanceof HostError ? e.code : 'INTERNAL';
50
+ const http = Number(e?.http) || (code === 'NO_SCOPE' ? 403 : code === 'NOT_FOUND' ? 404
51
+ : code === 'NOT_READY' ? 503 : code === 'INTERNAL' ? 500 : 400);
52
+ const qqCode = Number(e?.qqCode);
53
+ return {
54
+ code,
55
+ http,
56
+ error: {
57
+ code,
58
+ message: String(e?.message ?? e),
59
+ ...(Number.isFinite(qqCode) && qqCode > 0 ? { qqCode } : {}),
60
+ },
61
+ };
62
+ }
63
+
34
64
  /** 与 OneBot 的 6700–6799 分开,方便面板上两个出口各写各的端口 */
35
65
  const PORT_BASE = 6800;
36
66
  const PORT_SPAN = 100;
@@ -321,13 +351,8 @@ export class HostBridge {
321
351
  return { id, ok: true, data: data ?? null, http: 200 };
322
352
  } catch (e) {
323
353
  this.counters.fail += 1;
324
- const code = e instanceof HostError ? e.code : 'INTERNAL';
325
- const http = Number(e?.http) || (code === 'NO_SCOPE' ? 403 : code === 'NOT_FOUND' ? 404
326
- : code === 'NOT_READY' ? 503 : code === 'INTERNAL' ? 500 : 400);
327
- return {
328
- id, ok: false, http,
329
- error: { code, message: String(e?.message ?? e) },
330
- };
354
+ const s = serializeRpcError(e);
355
+ return { id, ok: false, http: s.http, error: s.error };
331
356
  }
332
357
  }
333
358
 
package/src/host/ops.js CHANGED
@@ -18,6 +18,8 @@
18
18
  import fs from 'node:fs/promises';
19
19
  import path from 'node:path';
20
20
  import { DIRS } from '../paths.js';
21
+ /** 二维码:扫码登录和面板画「资料卡链接」共用同一套实现,不各写一份 */
22
+ import { toSvg as qrToSvg } from '../qq/qrsvg.js';
21
23
  import { saveBotConfig } from '../config.js';
22
24
  import { FILE_TYPE } from '../api.js';
23
25
  import {
@@ -188,6 +190,20 @@ export function registerOps(def, { R, err, log = () => {} }) {
188
190
  stats: R.delivery?.stats?.() ?? { available: false },
189
191
  }));
190
192
 
193
+ /**
194
+ * 把一段短文本画成二维码 SVG。
195
+ *
196
+ * 只在服务端画:前端(DSH 插件)只有一个 client.js 入口,塞 QR 库既占体积
197
+ * 又要改加载方式。`src/qq/qrsvg.js` 本来就在给扫码登录用,这里把它暴露出来,
198
+ * 面板画「机器人资料卡链接」就不用再实现一遍。
199
+ */
200
+ def('qr.svg', 'read', '把一段短文本画成二维码 SVG(登录码、资料卡链接共用一套实现)', async (p) => {
201
+ const text = str(p.text).trim();
202
+ if (!text) throw err.bad('要给 text');
203
+ if (text.length > 300) throw err.bad('文本太长(最多 300 字)');
204
+ return { svg: qrToSvg(text) };
205
+ }),
206
+
191
207
  def('roles.resolve', 'read', '算发送者权限档位 bucket/level/role(ai-chat senderInfo 等价)', async (p) => {
192
208
  const userId = str(p.userId).trim();
193
209
  if (!userId) throw err.bad('要给 userId(openid)');