@zaofan/dsh-qqbot 1.13.6 → 1.13.12
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/client/qqbot-settings.js +41 -14
- package/dist/channel-tools.d.ts.map +1 -1
- package/dist/channel-tools.js +3 -2
- package/dist/channel-tools.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/gateway/bootstrap.d.ts.map +1 -1
- package/dist/gateway/bootstrap.js +4 -1
- package/dist/gateway/bootstrap.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +4 -1
- package/dist/session/session-manager.js.map +1 -1
- package/dist/shared/root-ctx.d.ts +6 -0
- package/dist/shared/root-ctx.d.ts.map +1 -0
- package/dist/shared/root-ctx.js +66 -0
- package/dist/shared/root-ctx.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 读取 cordis 的**根 ctx**(跨版本兼容)—— 2026-11-16(issue #64)。
|
|
3
|
+
*
|
|
4
|
+
* ## 背景
|
|
5
|
+
*
|
|
6
|
+
* `cordis@4.0.0-rc.12` 起**移除了 `ctx.root`**。上游迁移说明
|
|
7
|
+
* (deepseek-harness `docs/upgrade-guide/v0.2.2-rc.2/cordis-root-and-intercept-metadata/guide.md`):
|
|
8
|
+
*
|
|
9
|
+
* > `ctx.root` no longer exists. The root context is `ctx[Context.root]`;
|
|
10
|
+
* > `Context.root` is a symbol exported on the `Context` class. Inside a plugin,
|
|
11
|
+
* > reading `ctx.root` throws `cannot get property "root" without inject`.
|
|
12
|
+
*
|
|
13
|
+
* ## 为什么 `?? ctx` / `|| ctx` 救不了
|
|
14
|
+
*
|
|
15
|
+
* 我们的插件 `index.ts` 声明的是 `inject = ['agents', 'systemPrompt']`,`root` 不在其中,
|
|
16
|
+
* 于是 cordis 的代理对象在**属性读取那一刻直接 throw** —— 不是返回 `undefined`。
|
|
17
|
+
* 所以 `ctx.root ?? ctx` 和 `ctx.root || ctx` 里那个兜底**永远不会执行**:
|
|
18
|
+
* 异常直接冒出去,把整段调用栈打断。
|
|
19
|
+
*
|
|
20
|
+
* 实际后果(issue #64 实测):
|
|
21
|
+
* - `gateway/bootstrap.ts` 那处抛在 WebSocket 建立**之前** ⇒ 网关完全起不来
|
|
22
|
+
* (`Bot ready` 从不打印、`online=false`,但 REST 心跳照发、`api.sgroup.qq.com` 零连接);
|
|
23
|
+
* - `channel-tools.ts` 两处 ⇒ 元工具注册失败刷屏、`expose:'all'` 挂到错误层;
|
|
24
|
+
* - `session-manager.ts` 一处 ⇒ 被 `?.catch?.(()=>{})` 吞掉,群守则/工具表注入**静默失效**。
|
|
25
|
+
*
|
|
26
|
+
* ## 正确读法
|
|
27
|
+
*
|
|
28
|
+
* 纯 JS 不需要 import:`ctx[Symbol.for('cordis.root')]`。
|
|
29
|
+
* 但为了**同时兼容旧版 cordis**(那里只有 `ctx.root`、且读它不抛),这里按顺序两种都试:
|
|
30
|
+
* **先读符号**(新版有值、旧版拿不到),符号没有才 try 读 `.root`(新版会抛 → 被 catch 吃掉)。
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ 不要退回"只用 try/catch 读 `.root`":那在新版上会一路落到**非根 ctx**,
|
|
33
|
+
* 进程不崩了,但审批监听、群守则注入、全局工具注册全都静默降级 —— 比崩更难查。
|
|
34
|
+
*/
|
|
35
|
+
const ROOT_SYMBOL = Symbol.for('cordis.root');
|
|
36
|
+
/**
|
|
37
|
+
* 取根 ctx;取不到就返回传入的那个(与旧行为一致,绝不抛)。
|
|
38
|
+
* @param c 任意 ctx(可能是根,也可能是插件 ctx)
|
|
39
|
+
*/
|
|
40
|
+
export function rootOf(c) {
|
|
41
|
+
if (c === null || c === undefined)
|
|
42
|
+
return c;
|
|
43
|
+
const t = typeof c;
|
|
44
|
+
if (t !== 'object' && t !== 'function')
|
|
45
|
+
return c;
|
|
46
|
+
// ① cordis ≥ 4.0.0-rc.12:根 ctx 挂在 Symbol.for('cordis.root') 上
|
|
47
|
+
try {
|
|
48
|
+
const bySymbol = c[ROOT_SYMBOL];
|
|
49
|
+
if (bySymbol)
|
|
50
|
+
return bySymbol;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
/* 读符号理论上不会抛;真抛了也只是少一条路,继续走 ② */
|
|
54
|
+
}
|
|
55
|
+
// ② cordis < 4.0.0-rc.12:老字段 `ctx.root`(新版读它会抛,catch 吃掉)
|
|
56
|
+
try {
|
|
57
|
+
const legacy = c.root;
|
|
58
|
+
if (legacy)
|
|
59
|
+
return legacy;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
/* 新版 cordis 的正常路径:没有符号也没有 .root 可读 → 用自己 */
|
|
63
|
+
}
|
|
64
|
+
return c;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=root-ctx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-ctx.js","sourceRoot":"","sources":["../../src/shared/root-ctx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAI,CAAI;IAC5B,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IAC5C,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC;IACnB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,UAAU;QAAE,OAAO,CAAC,CAAC;IAEjD,8DAA8D;IAC9D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAI,CAAwC,CAAC,WAAW,CAAC,CAAC;QACxE,IAAI,QAAQ;YAAE,OAAO,QAAa,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,gCAAgC;IAClC,CAAC;IAED,yDAAyD;IACzD,IAAI,CAAC;QACH,MAAM,MAAM,GAAI,CAAmC,CAAC,IAAI,CAAC;QACzD,IAAI,MAAM;YAAE,OAAO,MAAW,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,4CAA4C;IAC9C,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
|