@zaofan/dsh-qqbot 1.11.28 → 1.11.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/client/qqbot-settings.js +1 -1
- package/dist/channel-tools.d.ts.map +1 -1
- package/dist/channel-tools.js +194 -134
- package/dist/channel-tools.js.map +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +35 -17
- package/dist/session/session-manager.js.map +1 -1
- package/package.json +1 -1
package/client/qqbot-settings.js
CHANGED
|
@@ -417,7 +417,7 @@ window.__ModuleLoader__.load({
|
|
|
417
417
|
{ k: 'groupAdmin.manageGroup', kw: '群管理 默认群 group_openid 目标群', t: 'str', label: '对话内默认管理群 group_openid(web 对话时群工具用它; QQ 群会话自动用当前群)', wide: true, def: '' },
|
|
418
418
|
{ k: 'groupAdmin.watchJoinRequests', kw: '入群申请 事件 提醒 订阅', t: 'bool', label: '实时接收"入群申请"事件并自动提醒(勾选后需重启才生效)', def: false },
|
|
419
419
|
{ k: 'groupAdmin.notifyInGroup', kw: '入群申请 提醒 群内 通知', t: 'bool', label: '收到入群申请时在该群内发提醒消息', def: true },
|
|
420
|
-
{ k: 'extMetaTool', kw: '扩展工具 元工具 gain 按需 领取 token 省', t: 'bool', label: '
|
|
420
|
+
{ k: 'extMetaTool', kw: '扩展工具 元工具 gain 按需 领取 token 省', t: 'bool', label: '扩展工具按需取用(默认开):expose:all 的工具注册在 QQ 会话侧,非 QQ 会话要先用 gain_qq_tools 领取;别的实例的工具同理(本实例自己的工具始终可见)。关掉 = 禁止领取,别的实例的工具一律不可见', def: true },
|
|
421
421
|
{ t: 'custom', render: function (ctx) { return h(GroupAdminPanel, { key: 'ga-' + (ctx.ns || 'main'), ns: ctx.ns || undefined }) } },
|
|
422
422
|
],
|
|
423
423
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-tools.d.ts","sourceRoot":"","sources":["../src/channel-tools.ts"],"names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GAAG,IAAI,CA+CtJ;AAsFD,2CAA2C;AAC3C,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAmEhF;AA2ND,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CA0K7D;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAwCjE;AA+ED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACvF,IAAI,CA4CN;AAID,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAsC1G;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA0CnI"}
|
package/dist/channel-tools.js
CHANGED
|
@@ -12,6 +12,7 @@ import { uploadMarkdownImage, listMarkdownImages, deleteMarkdownImage } from './
|
|
|
12
12
|
import { setMaterialTargetFactory } from './features/md-media-rewrite.js';
|
|
13
13
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
14
14
|
import { join, dirname } from 'node:path';
|
|
15
|
+
import { dataRootOf } from './gateway/data-root.js';
|
|
15
16
|
import { homedir } from 'node:os';
|
|
16
17
|
import { getStickerStore } from './features/sticker-store.js';
|
|
17
18
|
import { autoTagImage } from './features/sticker-tagger.js';
|
|
@@ -117,6 +118,16 @@ export const inject = ['tools'];
|
|
|
117
118
|
let channelBridges = [];
|
|
118
119
|
/** 全局懒扫节流(2026-10-10):ensureExtToolsGlobal 挂在"每 step 都触发"的钩子上,别每次都扫盘 */
|
|
119
120
|
let lastExtGlobAt = 0;
|
|
121
|
+
/**
|
|
122
|
+
* **插件 apply 时的 ctx** —— 普通扩展工具(apply 里的 `ctx.tools.register`)就注册在它上面,
|
|
123
|
+
* 所以只有 QQ 会话(插件的子 agent)继承得到,非 QQ 会话看不见。
|
|
124
|
+
*
|
|
125
|
+
* ★★ 2026-10-31(主人第三次纠正,要求"详查到底怎么注册的"):
|
|
126
|
+
* `expose:'all'` 以前注册到的是 **session-manager 传进来的 this.ctx**(中途还试过 `ctx.root`
|
|
127
|
+
* 和 `ctx.get('tools')`),跟"普通工具那个 ctx"根本不是同一个作用域对象 ⇒ 怎么改都还是全局可见。
|
|
128
|
+
* 现在统一用这个记下来的 apply ctx,与普通工具**同一个对象**。
|
|
129
|
+
*/
|
|
130
|
+
let pluginApplyCtx = undefined;
|
|
120
131
|
/**
|
|
121
132
|
* expose:'all' 全局注册的**专用诊断**(2026-10-10 排查用)。
|
|
122
133
|
* ⚠️ 无条件写:不走 diagWrite/diagLog 那套(那套默认关,害我以为"没跑",其实是"没记")。
|
|
@@ -536,6 +547,9 @@ function stickerStoreOf(exec) {
|
|
|
536
547
|
}
|
|
537
548
|
/** 装载本插件时把 qqChannel 一并注入(由 dsh-qqbot setup 提供) */
|
|
538
549
|
export async function apply(ctx) {
|
|
550
|
+
// ★★★ 2026-10-31:记住本插件的 apply ctx —— expose:'all' 的工具必须注册到**这个** ctx 上,
|
|
551
|
+
// 才能和普通扩展工具(下面的 `ctx.tools.register`)处在同一个作用域。
|
|
552
|
+
pluginApplyCtx = ctx;
|
|
539
553
|
const toolsAny = ctx.tools;
|
|
540
554
|
diag(`apply 调用: tools=${typeof toolsAny} register=${typeof toolsAny?.register} ctxKeys=${Object.keys(ctx).slice(0, 12).join(',')}`);
|
|
541
555
|
const sendMediaTool = defineTool({
|
|
@@ -3798,50 +3812,73 @@ export function applyExtToolVisibility(agentCtx, selfTag) {
|
|
|
3798
3812
|
const ctx = agentCtx;
|
|
3799
3813
|
if (!ctx || typeof ctx !== 'object')
|
|
3800
3814
|
return;
|
|
3801
|
-
// ⚠️ 2026-10-28(主人实测:enable 一个 standard 后,自己实例那 4 个被移除):
|
|
3802
|
-
// gain_qq_tools 内部调本函数时**不传 selfTag**,原来会把 ownSuffix 算成空串 ⇒
|
|
3803
|
-
// 连带把本实例自己的那份也 deny 掉。现在:不传就**沿用上次记住的 tag**。
|
|
3804
3815
|
const prevTag = extSeenCtx.get(ctx) ?? '';
|
|
3805
3816
|
const tag = selfTag !== undefined ? String(selfTag) : prevTag;
|
|
3806
3817
|
extSeenCtx.set(ctx, tag);
|
|
3807
|
-
|
|
3818
|
+
// ★★★ 2026-10-31(主人实测后的最终结论):**改成 per-agent 注册**。
|
|
3819
|
+
// 实测对照:同一次运行里
|
|
3820
|
+
// · ensureExtToolsGlobal 注册到 apply(ctx) → QQ 会话调不到(unknown tool)
|
|
3821
|
+
// · gain_qq_tools.enable 注册到 agent.ctx → 立刻可用 ✅
|
|
3822
|
+
// 说明只有**注册进 agent 自己的作用域**才算数。所以这里改成:
|
|
3823
|
+
// 该 agent 应有的 = 本实例自己的(__selfTag)+ 已领取的,逐个注册到它的 ctx;
|
|
3824
|
+
// 既不用 deny,也不用 root —— 非 QQ agent 不走这段,天然零泄漏。
|
|
3825
|
+
// ⚠️ 拿不到 tag 就什么都不做(否则会把"自己实例那份"也漏掉)。
|
|
3826
|
+
if (!tag) {
|
|
3827
|
+
traceToolReg('[ext-vis] 跳过(拿不到 selfTag)');
|
|
3828
|
+
return;
|
|
3829
|
+
}
|
|
3830
|
+
const all = [...extToolIndex.values()];
|
|
3808
3831
|
if (!all.length)
|
|
3809
|
-
return; //
|
|
3810
|
-
// ⚠️ 2026-10-28(主人纠正):开关**不是**"关=不剪枝、全可见"。
|
|
3811
|
-
// 关掉元工具 = "按需取用"这条通道整个关掉 ⇒ 别人实例 expose 的工具**永远不可见**
|
|
3812
|
-
// (没有 gain 入口,也就不该偷偷放出来)。所以无论开关开/关,都照常剪:
|
|
3813
|
-
// · 自己实例那份(xxx__本tag):始终放开
|
|
3814
|
-
// · 别人那份:始终 deny;开关开着时可通过 gain_qq_tools 临时放开
|
|
3815
|
-
// ★ 2026-10-28(主人实测:关了元工具,之前领取的工具还在):开关关掉时
|
|
3816
|
-
// **忽略并清空领取记录** —— 通道一关,别人的工具就该彻底消失,不能靠残留的 granted 续命。
|
|
3832
|
+
return; // 还没扫到东西:先不动
|
|
3817
3833
|
const metaOnNow = globalThis.__qqbotExtMetaOn !== false;
|
|
3818
3834
|
if (!metaOnNow)
|
|
3819
3835
|
extGrantSet.delete(ctx);
|
|
3820
3836
|
const granted = metaOnNow ? (extGrantSet.get(ctx) || new Set()) : new Set();
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
const
|
|
3824
|
-
|
|
3825
|
-
|
|
3837
|
+
const ownSuffix = '__' + tag;
|
|
3838
|
+
const want = new Map();
|
|
3839
|
+
for (const ent of all) {
|
|
3840
|
+
if (ent.full.endsWith(ownSuffix) || granted.has(ent.full))
|
|
3841
|
+
want.set(ent.full, ent);
|
|
3842
|
+
// 注:granted 里可能有别的实例的工具(gain 领取的),也一并注册进本 agent
|
|
3843
|
+
}
|
|
3844
|
+
const sig = (metaOnNow ? '1' : '0') + '|' + [...want.keys()].sort().join(',');
|
|
3826
3845
|
const st = extRestrictState2.get(ctx);
|
|
3827
3846
|
if (st && st.sig === sig)
|
|
3828
|
-
return;
|
|
3829
|
-
if (st?.dispose)
|
|
3830
|
-
liftRestriction(st.dispose);
|
|
3847
|
+
return; // 状态一致 → 不动(防抖)
|
|
3831
3848
|
const toolsObj = toolsOfScope(ctx);
|
|
3832
|
-
const
|
|
3833
|
-
if (typeof
|
|
3834
|
-
traceToolReg('[ext-vis]
|
|
3849
|
+
const reg = toolsObj?.register;
|
|
3850
|
+
if (!toolsObj || typeof reg !== 'function') {
|
|
3851
|
+
traceToolReg('[ext-vis] per-agent 注册失败: 拿不到 tools.register');
|
|
3835
3852
|
return;
|
|
3836
3853
|
}
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3854
|
+
// 先撤掉不再需要的
|
|
3855
|
+
const disposers = st?.disposers ?? new Map();
|
|
3856
|
+
for (const [name, d] of [...disposers]) {
|
|
3857
|
+
if (want.has(name))
|
|
3858
|
+
continue;
|
|
3859
|
+
try {
|
|
3860
|
+
d();
|
|
3861
|
+
}
|
|
3862
|
+
catch { /* ignore */ }
|
|
3863
|
+
disposers.delete(name);
|
|
3840
3864
|
}
|
|
3841
|
-
|
|
3842
|
-
const
|
|
3843
|
-
|
|
3844
|
-
|
|
3865
|
+
// 再补缺的
|
|
3866
|
+
for (const [full, ent] of want) {
|
|
3867
|
+
if (disposers.has(full))
|
|
3868
|
+
continue;
|
|
3869
|
+
try {
|
|
3870
|
+
const tool = buildExtTool(ent, pluginApplyCtx ?? ctx, (ctx.logger) ?? console);
|
|
3871
|
+
const d = reg.call(toolsObj, tool);
|
|
3872
|
+
if (typeof d === 'function')
|
|
3873
|
+
disposers.set(full, d);
|
|
3874
|
+
traceToolReg('[ext-vis] per-agent 注册 ' + full);
|
|
3875
|
+
}
|
|
3876
|
+
catch (e) {
|
|
3877
|
+
traceToolReg('[ext-vis] 注册失败 ' + full + ': ' + String(e?.message ?? e).slice(0, 100));
|
|
3878
|
+
}
|
|
3879
|
+
}
|
|
3880
|
+
extRestrictState2.set(ctx, { sig, dispose: undefined, disposers });
|
|
3881
|
+
traceToolReg('[ext-vis] per-agent 应注册=' + want.size + '(own=' + ownSuffix + ' granted=' + granted.size + ')');
|
|
3845
3882
|
}
|
|
3846
3883
|
catch (e) {
|
|
3847
3884
|
traceToolReg('[ext-vis] 异常: ' + String(e?.message ?? e).slice(0, 140));
|
|
@@ -3942,7 +3979,20 @@ function makeGainTool(globalCtx, logger) {
|
|
|
3942
3979
|
const wantTag = String(args?.tag ?? '').trim();
|
|
3943
3980
|
const limRaw = Number(args?.limit);
|
|
3944
3981
|
const lim = Math.max(1, Math.min(50, Number.isFinite(limRaw) && limRaw > 0 ? Math.trunc(limRaw) : 20));
|
|
3945
|
-
|
|
3982
|
+
// ★★ 2026-10-31(主人定):**不该看到自己的工具** —— 本实例那批 expose:'all' 的工具
|
|
3983
|
+
// 已经在 agent ctx 自动注册、随时可用,列进"可领取"里纯属噪音(还容易重复 enable)。
|
|
3984
|
+
// 非 QQ 会话拿不到 selfTag ⇒ 不过滤(能领所有已勾选实例的)。
|
|
3985
|
+
let selfTagOfCaller = '';
|
|
3986
|
+
try {
|
|
3987
|
+
const sess0 = findSessionRec(channelOf(exec), exec);
|
|
3988
|
+
const mgr0 = sess0?.ch?.manager;
|
|
3989
|
+
if (mgr0)
|
|
3990
|
+
selfTagOfCaller = instanceTagOfManager(mgr0);
|
|
3991
|
+
}
|
|
3992
|
+
catch { /* ignore */ }
|
|
3993
|
+
const rows = [...extToolIndex.values()]
|
|
3994
|
+
.filter((e) => !selfTagOfCaller || e.tag !== selfTagOfCaller)
|
|
3995
|
+
.filter((e) => (!wantTag || e.tag === wantTag));
|
|
3946
3996
|
try {
|
|
3947
3997
|
if (action === 'list' || action === 'search') {
|
|
3948
3998
|
const hit = action === 'search'
|
|
@@ -4116,18 +4166,27 @@ export function ensureExtToolsGlobal(globalCtx) {
|
|
|
4116
4166
|
try {
|
|
4117
4167
|
if (!globalCtx || typeof globalCtx !== 'object')
|
|
4118
4168
|
return;
|
|
4119
|
-
//
|
|
4120
|
-
//
|
|
4121
|
-
//
|
|
4122
|
-
//
|
|
4123
|
-
|
|
4124
|
-
|
|
4169
|
+
// ★★ 2026-10-31(主人第三次纠正,要求"详查到底怎么注册的"):
|
|
4170
|
+
// 普通扩展工具注册在 **`apply(ctx)` 的参数 ctx** 上(见本文件 apply 里的 `ctx.tools.register`),
|
|
4171
|
+
// 而 expose:'all' 这条一直用的是 **session-manager 传来的 this.ctx** —— 两者**不是同一个作用域对象**!
|
|
4172
|
+
// (中途还试过 `ctx.root`(根层)、`ctx.get('tools')`(向上查找到的根层服务),都会落到全局层。)
|
|
4173
|
+
// ⇒ 统一用 `pluginApplyCtx`(apply 时记下的那个),与普通工具**完全同一个对象**。
|
|
4174
|
+
const rootCtx = (pluginApplyCtx ?? globalCtx);
|
|
4175
|
+
extGlobDiag('scope=apply-ctx(同普通扩展工具)' + (pluginApplyCtx ? '' : '(未记录,退回传入 ctx)'));
|
|
4125
4176
|
const gctx = rootCtx;
|
|
4126
4177
|
let toolsObj;
|
|
4178
|
+
// ⚠️ 必须**优先 `ctx.tools`(属性访问 → 绑定本作用域)**;
|
|
4179
|
+
// `ctx.get('tools')` 是服务查找,会向上拿到**根层**的实例 ⇒ 注册等于挂全局。
|
|
4127
4180
|
try {
|
|
4128
|
-
toolsObj = gctx.
|
|
4181
|
+
toolsObj = gctx.tools;
|
|
4182
|
+
}
|
|
4183
|
+
catch { /* 未 inject 会抛 */ }
|
|
4184
|
+
if (!toolsObj || typeof toolsObj.register !== 'function') {
|
|
4185
|
+
try {
|
|
4186
|
+
toolsObj = gctx.get?.('tools');
|
|
4187
|
+
}
|
|
4188
|
+
catch { /* ignore */ }
|
|
4129
4189
|
}
|
|
4130
|
-
catch { /* ignore */ }
|
|
4131
4190
|
if (!toolsObj || typeof toolsObj.register !== 'function') {
|
|
4132
4191
|
extGlobDiag('FAIL 拿不到 tools 服务');
|
|
4133
4192
|
extDiag('[extglob] 拿不到 tools 服务, 跳过');
|
|
@@ -4135,39 +4194,46 @@ export function ensureExtToolsGlobal(globalCtx) {
|
|
|
4135
4194
|
}
|
|
4136
4195
|
// 2026-10-28:元工具**先注册**,且不依赖"有没有实例"——
|
|
4137
4196
|
// 上一版放在扫描末尾,若中途 early-return 就永远注册不上(实测:开了按需取用却连元工具都没有)。
|
|
4197
|
+
// ★★★ 2026-10-31(主人实测:关掉三号的勾选,非 QQ 会话的 gain 也被移除了)——
|
|
4198
|
+
// **只要有一个启动中的实例还勾着,gain_qq_tools 就必须在**。
|
|
4199
|
+
// 以前第 ① 步读的是 `managersOf()[0]`(通常是三号 standard),它一关就 return false,
|
|
4200
|
+
// 把 gain 整个摘掉 ⇒ 二号明明还开着,非 QQ 会话却没入口了。
|
|
4201
|
+
// 现在:遍历**所有实例**,任一勾选即 true(文件优先,config 兜底)。
|
|
4138
4202
|
const metaOn = (() => {
|
|
4139
|
-
|
|
4140
|
-
// settings-host 保存时写 {dataRoot}/.qqbot/ext-meta-tool.json,这里每次扫描现读;
|
|
4141
|
-
// 不依赖 config 快照,也不依赖 globalThis 有没有被写过。
|
|
4203
|
+
let anyOn = false;
|
|
4142
4204
|
try {
|
|
4143
|
-
const
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
if (
|
|
4147
|
-
|
|
4205
|
+
for (const m of managersOf()) {
|
|
4206
|
+
const mm = m;
|
|
4207
|
+
let dr = String(mm.dataRoot ?? '').trim();
|
|
4208
|
+
if (!dr) {
|
|
4209
|
+
try {
|
|
4210
|
+
dr = dataRootOf(mm.config);
|
|
4211
|
+
}
|
|
4212
|
+
catch {
|
|
4213
|
+
dr = '';
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
if (dr) {
|
|
4217
|
+
try {
|
|
4218
|
+
const o = JSON.parse(readFileSync(join(dr, '.qqbot', 'ext-meta-tool.json'), 'utf8'));
|
|
4219
|
+
if (o?.on === true)
|
|
4220
|
+
anyOn = true;
|
|
4221
|
+
continue; // 该实例有明确文件设置,按文件算
|
|
4222
|
+
}
|
|
4223
|
+
catch { /* 没文件,看 config */ }
|
|
4224
|
+
}
|
|
4225
|
+
if (mm.config?.extMetaTool === true)
|
|
4226
|
+
anyOn = true;
|
|
4148
4227
|
}
|
|
4149
4228
|
}
|
|
4150
|
-
catch { /* 文件不存在 = 还没设过,往下走 */ }
|
|
4151
|
-
// ② 进程级热标记:设置页保存时 settings-host 写入(config 是启动快照,不会自己变)。
|
|
4152
|
-
try {
|
|
4153
|
-
const live = globalThis.__qqbotExtMetaTool;
|
|
4154
|
-
if (typeof live === 'boolean')
|
|
4155
|
-
return live;
|
|
4156
|
-
}
|
|
4157
4229
|
catch { /* ignore */ }
|
|
4158
|
-
//
|
|
4159
|
-
// index.ts 的 'qqbot/settings-changed' 监听会 把
|
|
4160
|
-
// 保存值原地合并进当前实例的 config(这就是面板其它开关的热更路子);但只有**被保存的那个
|
|
4161
|
-
// 实例**里有这个字段,第一个 manager 未必是它 ⇒ 只看第 0 个会永远读到 undefined/false。
|
|
4230
|
+
// 进程级热标记:只在"刚保存为开"时补一票(绝不能因为它是 false 就否定别的实例)
|
|
4162
4231
|
try {
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
if (cfgM && cfgM.extMetaTool === true)
|
|
4166
|
-
return true;
|
|
4167
|
-
}
|
|
4232
|
+
if (globalThis.__qqbotExtMetaTool === true)
|
|
4233
|
+
anyOn = true;
|
|
4168
4234
|
}
|
|
4169
4235
|
catch { /* ignore */ }
|
|
4170
|
-
return
|
|
4236
|
+
return anyOn;
|
|
4171
4237
|
})();
|
|
4172
4238
|
// ★ 2026-10-28(主人急):**无条件注册元工具** —— 它是个极轻的入口,本来就不该被任何开关挡住。
|
|
4173
4239
|
// "开了按需取用却连 gain_qq_tools 都看不到" 这种状态毫无意义:要么两个都有,要么两个都没有。
|
|
@@ -4193,6 +4259,7 @@ export function ensureExtToolsGlobal(globalCtx) {
|
|
|
4193
4259
|
if (!g.__qqbotExtToolsGlobal)
|
|
4194
4260
|
g.__qqbotExtToolsGlobal = new Map();
|
|
4195
4261
|
const reg = g.__qqbotExtToolsGlobal;
|
|
4262
|
+
void reg; // 2026-10-31:全局注册表已弃用(改 per-agent 注册),保留键名只为兼容。
|
|
4196
4263
|
// 开关(默认开 = 按需取用):关掉后回到"扩展工具全部全局注册"的旧行为
|
|
4197
4264
|
// 2026-10-28(主人实测纠正):默认**保持旧行为**(全部 expose:'all' 全局注册)。
|
|
4198
4265
|
// 原因:第一版把默认值设成"按需取用",结果元工具没注册上 => 所有会话一个扩展工具都没有
|
|
@@ -4203,7 +4270,31 @@ export function ensureExtToolsGlobal(globalCtx) {
|
|
|
4203
4270
|
globalThis.__qqbotExtMetaOn = metaMode;
|
|
4204
4271
|
extGlobDiag('metaMode=' + String(metaMode));
|
|
4205
4272
|
// ── 阶段 1:扫描,**只填索引**(不注册)────────────────────────────
|
|
4273
|
+
// ★★ 2026-10-31(主人实测:关掉三号的开关,gain 还能列/领它的工具):
|
|
4274
|
+
// **只扫"勾了按需取用"的实例**。没勾的实例,它扩展目录里的 expose:'all'
|
|
4275
|
+
// 既不进索引、也就不会出现在 gain 的可领取列表里、更领不到。
|
|
4206
4276
|
for (const inst of insts) {
|
|
4277
|
+
const optIn = (() => {
|
|
4278
|
+
try {
|
|
4279
|
+
const o = JSON.parse(readFileSync(join(inst.dataRoot, '.qqbot', 'ext-meta-tool.json'), 'utf8'));
|
|
4280
|
+
if (typeof o?.on === 'boolean')
|
|
4281
|
+
return o.on;
|
|
4282
|
+
}
|
|
4283
|
+
catch { /* 没文件 → 看 config */ }
|
|
4284
|
+
try {
|
|
4285
|
+
for (const m of managersOf()) {
|
|
4286
|
+
const mm = m;
|
|
4287
|
+
if (String(mm.dataRoot ?? '') === inst.dataRoot && mm.config?.extMetaTool === true)
|
|
4288
|
+
return true;
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
catch { /* ignore */ }
|
|
4292
|
+
return false;
|
|
4293
|
+
})();
|
|
4294
|
+
if (!optIn) {
|
|
4295
|
+
extGlobDiag('SKIP not-opted-in: ' + inst.tag);
|
|
4296
|
+
continue;
|
|
4297
|
+
}
|
|
4207
4298
|
let defs = [];
|
|
4208
4299
|
try {
|
|
4209
4300
|
defs = await loadExtensionTools(inst.dataRoot, (gctx.logger ?? console));
|
|
@@ -4227,82 +4318,51 @@ export function ensureExtToolsGlobal(globalCtx) {
|
|
|
4227
4318
|
});
|
|
4228
4319
|
}
|
|
4229
4320
|
}
|
|
4321
|
+
// ★★ 2026-10-31(主人要求):**每个实例各自落一份清单**到自己的 dataRoot:
|
|
4322
|
+
// `{dataRoot}/.qqbot/ext-tools-index.json`,只列**自己 tag** 的 expose:'all' 工具。
|
|
4323
|
+
// 用途:① 非 QQ 会话的 gain_qq_tools 读它来"看见能领什么"并现场注册;
|
|
4324
|
+
// ② 重启后即使扫描还没跑,也能从文件读出名单。
|
|
4325
|
+
// 注意:注册行为与它无关(注册早已改成 per-agent,见 applyExtToolVisibility)。
|
|
4326
|
+
for (const inst of insts) {
|
|
4327
|
+
if (!inst || !inst.dataRoot)
|
|
4328
|
+
continue;
|
|
4329
|
+
try {
|
|
4330
|
+
const f = join(inst.dataRoot, '.qqbot', 'ext-tools-index.json');
|
|
4331
|
+
const mine = [...extToolIndex.values()].filter((e) => e.tag === inst.tag);
|
|
4332
|
+
const payload = {
|
|
4333
|
+
updatedAt: new Date().toISOString(),
|
|
4334
|
+
instance: inst.tag,
|
|
4335
|
+
dataRoot: inst.dataRoot,
|
|
4336
|
+
note: "expose:'all' 扩展工具清单(本实例;供 gain_qq_tools 查询与现场注册)",
|
|
4337
|
+
tools: mine.map((e) => ({
|
|
4338
|
+
full: e.full,
|
|
4339
|
+
tag: e.tag,
|
|
4340
|
+
baseName: e.baseName,
|
|
4341
|
+
description: String(e.description || '').slice(0, 200),
|
|
4342
|
+
dataRoot: e.inst?.dataRoot,
|
|
4343
|
+
cwd: e.inst?.cwd,
|
|
4344
|
+
})),
|
|
4345
|
+
};
|
|
4346
|
+
mkdirSync(dirname(f), { recursive: true });
|
|
4347
|
+
writeFileSync(f, JSON.stringify(payload, null, 2), 'utf8');
|
|
4348
|
+
extGlobDiag('清单已落盘: ' + f + ' (' + payload.tools.length + ' 件, ' + inst.tag + ')');
|
|
4349
|
+
}
|
|
4350
|
+
catch (e) {
|
|
4351
|
+
extGlobDiag('清单落盘失败(' + inst.tag + '): ' + ((e instanceof Error ? e.message : String(e)) || '').slice(0, 120));
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4230
4354
|
// ── 阶段 2:**先剪枝**(此时索引已完整)──────────────────────────
|
|
4231
4355
|
// ★ 2026-10-28(主人抓到抖动:"新增 7 个 → 下个 step 又移除 7 个"):
|
|
4232
4356
|
// 以前是「循环里边扫描边注册」⇒ 注册发生时 deny 名单还不完整 ⇒ 模型先看到一步、下一步才被剪掉。
|
|
4233
4357
|
// 现在顺序固定为 **扫描 → 剪枝 → 注册**:注册落地时 deny 已经就位,模型永远看不到那一步。
|
|
4234
4358
|
for (const [c, tg] of extSeenCtx)
|
|
4235
4359
|
applyExtToolVisibility(c, tg);
|
|
4236
|
-
// ── 阶段 3
|
|
4237
|
-
//
|
|
4238
|
-
//
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
continue;
|
|
4243
|
-
const def = ent.def;
|
|
4244
|
-
const inst = ent.inst;
|
|
4245
|
-
const full = ent.full;
|
|
4246
|
-
try {
|
|
4247
|
-
const tool = defineTool({
|
|
4248
|
-
name: full,
|
|
4249
|
-
description: String(def.description ?? '') + ' (用户扩展工具 · ' + inst.tag + ')',
|
|
4250
|
-
parameters: def.inputSchema,
|
|
4251
|
-
output: {
|
|
4252
|
-
schema: {
|
|
4253
|
-
type: 'object', additionalProperties: false,
|
|
4254
|
-
properties: { ok: { type: 'boolean', required: true }, msg: { type: 'string', required: true } },
|
|
4255
|
-
},
|
|
4256
|
-
render: (_a, v) => [{ type: 'text', text: v.ok ? v.msg : ('失败: ' + v.msg) }],
|
|
4257
|
-
},
|
|
4258
|
-
async execute(args, exec) {
|
|
4259
|
-
let pack;
|
|
4260
|
-
try {
|
|
4261
|
-
pack = buildWorkspaceQqPack(inst.tag, inst.dataRoot);
|
|
4262
|
-
}
|
|
4263
|
-
catch {
|
|
4264
|
-
pack = undefined;
|
|
4265
|
-
}
|
|
4266
|
-
const env = {
|
|
4267
|
-
cwd: inst.cwd || inst.dataRoot,
|
|
4268
|
-
exec,
|
|
4269
|
-
ctx: globalCtx,
|
|
4270
|
-
logger: gctx.logger,
|
|
4271
|
-
qq: pack,
|
|
4272
|
-
};
|
|
4273
|
-
try {
|
|
4274
|
-
const sess = findSessionRec(channelOf(exec), exec);
|
|
4275
|
-
if (sess) {
|
|
4276
|
-
env.manager = sess.ch.manager;
|
|
4277
|
-
env.sender = sess.ch.sender;
|
|
4278
|
-
env.replyTarget = sess.rec.replyTarget;
|
|
4279
|
-
}
|
|
4280
|
-
else if (pack) {
|
|
4281
|
-
env.sender = pack.sender;
|
|
4282
|
-
}
|
|
4283
|
-
}
|
|
4284
|
-
catch { /* ignore */ }
|
|
4285
|
-
try {
|
|
4286
|
-
const r = await def.run(args, env);
|
|
4287
|
-
if (r && typeof r === 'object')
|
|
4288
|
-
return { ok: r.ok === true, msg: String(r.msg ?? 'done') };
|
|
4289
|
-
return { ok: true, msg: r === undefined || r === null ? 'done' : String(r) };
|
|
4290
|
-
}
|
|
4291
|
-
catch (err) {
|
|
4292
|
-
return { ok: false, msg: err instanceof Error ? err.message : String(err) };
|
|
4293
|
-
}
|
|
4294
|
-
},
|
|
4295
|
-
});
|
|
4296
|
-
const d = toolsObj.register.call(toolsObj, tool);
|
|
4297
|
-
if (typeof d === 'function')
|
|
4298
|
-
reg.set(full, d);
|
|
4299
|
-
extGlobDiag('OK registered ' + full);
|
|
4300
|
-
}
|
|
4301
|
-
catch (e) {
|
|
4302
|
-
extGlobDiag('FAIL register ' + full + ' :: ' + ((e instanceof Error ? e.message : String(e)) || '').slice(0, 200));
|
|
4303
|
-
}
|
|
4304
|
-
}
|
|
4305
|
-
}
|
|
4360
|
+
// ── 阶段 3:**不再全局注册**(2026-10-31 实测定论)──────────────
|
|
4361
|
+
// 实测对照:注册到 apply(ctx) 后 QQ 会话调不到(unknown tool),
|
|
4362
|
+
// 而 gain_qq_tools.enable 用 agent.ctx 注册**立刻可用**。
|
|
4363
|
+
// ⇒ 注册一律走 per-agent(见 applyExtToolVisibility),这里只保留索引。
|
|
4364
|
+
void rootCtx;
|
|
4365
|
+
void toolsObj;
|
|
4306
4366
|
extGlobDiag('index=' + extToolIndex.size + ' 可领取');
|
|
4307
4367
|
}
|
|
4308
4368
|
catch (e) {
|