agentdev 0.1.8 → 0.1.9
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/dist/BasicAgent-UWXLSZP2.js +13 -0
- package/dist/ExplorerAgent-LCM3JQS4.js +13 -0
- package/dist/{chunk-LQTEETML.js → chunk-5T4C2XRT.js} +12 -7
- package/dist/chunk-5T4C2XRT.js.map +1 -0
- package/dist/{chunk-OBOU27DM.js → chunk-A354ZCZF.js} +6735 -1822
- package/dist/chunk-A354ZCZF.js.map +1 -0
- package/dist/{chunk-TSASFMRF.js → chunk-BAP2GCYH.js} +1 -1
- package/dist/chunk-BAP2GCYH.js.map +1 -0
- package/dist/{chunk-3BPSNNK3.js → chunk-EECW6PYP.js} +11 -9
- package/dist/chunk-EECW6PYP.js.map +1 -0
- package/dist/chunk-G5ECPY4K.js +551 -0
- package/dist/chunk-G5ECPY4K.js.map +1 -0
- package/dist/{chunk-LLV3W326.js → chunk-NORTAQIL.js} +67 -20
- package/dist/chunk-NORTAQIL.js.map +1 -0
- package/dist/{chunk-F3PR7UTL.js → chunk-QFHPUAUQ.js} +5 -3
- package/dist/{chunk-F3PR7UTL.js.map → chunk-QFHPUAUQ.js.map} +1 -1
- package/dist/cli/server.js +2 -2
- package/dist/cli/viewer.js +2 -2
- package/dist/features/shell/templates/bash.render.d.ts +1 -1
- package/dist/features/websearch/templates/web-fetch.render.d.ts +1 -1
- package/dist/index.d.ts +1733 -500
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/dist/{notification-3VEAP7YF.js → notification-NWVOS2WR.js} +3 -3
- package/dist/tools-LDR3LIJP.js +14 -0
- package/dist/tools-LDR3LIJP.js.map +1 -0
- package/dist/{types-DUKIIntb.d.ts → types-CF5UsxD9.d.ts} +3 -0
- package/node_modules/@sliverp/qqbot/LICENSE +21 -0
- package/node_modules/@sliverp/qqbot/README.md +427 -0
- package/node_modules/@sliverp/qqbot/README.standalone.zh.md +77 -0
- package/node_modules/@sliverp/qqbot/README.zh.md +423 -0
- package/node_modules/@sliverp/qqbot/bin/qqbot-cli.js +227 -0
- package/node_modules/@sliverp/qqbot/clawdbot.plugin.json +16 -0
- package/node_modules/@sliverp/qqbot/dist/index.d.ts +20 -0
- package/node_modules/@sliverp/qqbot/dist/index.js +25 -0
- package/node_modules/@sliverp/qqbot/dist/src/agent.d.ts +76 -0
- package/node_modules/@sliverp/qqbot/dist/src/agent.js +36 -0
- package/node_modules/@sliverp/qqbot/dist/src/api.d.ts +138 -0
- package/node_modules/@sliverp/qqbot/dist/src/api.js +523 -0
- package/node_modules/@sliverp/qqbot/dist/src/channel.d.ts +3 -0
- package/node_modules/@sliverp/qqbot/dist/src/channel.js +349 -0
- package/node_modules/@sliverp/qqbot/dist/src/config.d.ts +25 -0
- package/node_modules/@sliverp/qqbot/dist/src/config.js +156 -0
- package/node_modules/@sliverp/qqbot/dist/src/demo-standalone.d.ts +1 -0
- package/node_modules/@sliverp/qqbot/dist/src/demo-standalone.js +125 -0
- package/node_modules/@sliverp/qqbot/dist/src/gateway.d.ts +20 -0
- package/node_modules/@sliverp/qqbot/dist/src/gateway.js +2156 -0
- package/node_modules/@sliverp/qqbot/dist/src/image-server.d.ts +62 -0
- package/node_modules/@sliverp/qqbot/dist/src/image-server.js +401 -0
- package/node_modules/@sliverp/qqbot/dist/src/known-users.d.ts +100 -0
- package/node_modules/@sliverp/qqbot/dist/src/known-users.js +263 -0
- package/node_modules/@sliverp/qqbot/dist/src/onboarding.d.ts +10 -0
- package/node_modules/@sliverp/qqbot/dist/src/onboarding.js +203 -0
- package/node_modules/@sliverp/qqbot/dist/src/openclaw-agent-adapter.d.ts +2 -0
- package/node_modules/@sliverp/qqbot/dist/src/openclaw-agent-adapter.js +155 -0
- package/node_modules/@sliverp/qqbot/dist/src/outbound.d.ts +150 -0
- package/node_modules/@sliverp/qqbot/dist/src/outbound.js +1175 -0
- package/node_modules/@sliverp/qqbot/dist/src/proactive.d.ts +170 -0
- package/node_modules/@sliverp/qqbot/dist/src/proactive.js +399 -0
- package/node_modules/@sliverp/qqbot/dist/src/runtime.d.ts +5 -0
- package/node_modules/@sliverp/qqbot/dist/src/runtime.js +16 -0
- package/node_modules/@sliverp/qqbot/dist/src/session-store.d.ts +52 -0
- package/node_modules/@sliverp/qqbot/dist/src/session-store.js +254 -0
- package/node_modules/@sliverp/qqbot/dist/src/types.d.ts +145 -0
- package/node_modules/@sliverp/qqbot/dist/src/types.js +1 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/audio-convert.d.ts +73 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/audio-convert.js +645 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/file-utils.d.ts +46 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/file-utils.js +107 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/image-size.d.ts +51 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/image-size.js +234 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/media-tags.d.ts +14 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/media-tags.js +120 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/payload.d.ts +112 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/payload.js +186 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/platform.d.ts +126 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/platform.js +358 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/upload-cache.d.ts +34 -0
- package/node_modules/@sliverp/qqbot/dist/src/utils/upload-cache.js +93 -0
- package/node_modules/@sliverp/qqbot/dist/standalone.d.ts +6 -0
- package/node_modules/@sliverp/qqbot/dist/standalone.js +6 -0
- package/node_modules/@sliverp/qqbot/index.ts +30 -0
- package/node_modules/@sliverp/qqbot/moltbot.plugin.json +16 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/LICENSE +201 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/README.md +134 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/browser.js +17 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/cjs/browser.js +16 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/cjs/node.js +219 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/index.d.ts +4 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/node.js +223 -0
- package/node_modules/@sliverp/qqbot/node_modules/@eshaz/web-worker/package.json +54 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/index.js +5 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/package.json +36 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderCommon.js +231 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderWorker.js +129 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/puff/README +67 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/puff/build_puff.js +31 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/puff/puff.c +863 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/puff/puff.h +35 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/src/utilities.js +3 -0
- package/node_modules/@sliverp/qqbot/node_modules/@wasm-audio-decoders/common/types.d.ts +7 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/README.md +265 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js +185 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js.map +1 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/index.js +8 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/package.json +58 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/src/EmscriptenWasm.js +464 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/src/MPEGDecoder.js +200 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/src/MPEGDecoderWebWorker.js +21 -0
- package/node_modules/@sliverp/qqbot/node_modules/mpg123-decoder/types.d.ts +30 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/LICENSE +21 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/README.md +85 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/lib/index.cjs +16 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/lib/index.d.ts +70 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/lib/index.mjs +16 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/lib/silk.wasm +0 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/lib/utils.d.ts +4 -0
- package/node_modules/@sliverp/qqbot/node_modules/silk-wasm/package.json +39 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/.github/FUNDING.yml +1 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/.prettierignore +1 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/LICENSE +7 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/README.md +163 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/dist/esm.js +1 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/dist/index.js +1 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/package.json +50 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/rollup.config.js +27 -0
- package/node_modules/@sliverp/qqbot/node_modules/simple-yenc/src/simple-yenc.js +302 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/LICENSE +20 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/README.md +548 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/browser.js +8 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/index.js +13 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/websocket-server.js +554 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/lib/websocket.js +1393 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/package.json +69 -0
- package/node_modules/@sliverp/qqbot/node_modules/ws/wrapper.mjs +8 -0
- package/node_modules/@sliverp/qqbot/openclaw.plugin.json +16 -0
- package/node_modules/@sliverp/qqbot/package.json +81 -0
- package/node_modules/@sliverp/qqbot/skills/qqbot-cron/SKILL.md +513 -0
- package/node_modules/@sliverp/qqbot/skills/qqbot-media/SKILL.md +194 -0
- package/node_modules/@sliverp/qqbot/src/agent.ts +133 -0
- package/node_modules/@sliverp/qqbot/src/api.ts +704 -0
- package/node_modules/@sliverp/qqbot/src/channel.ts +380 -0
- package/node_modules/@sliverp/qqbot/src/config.ts +182 -0
- package/node_modules/@sliverp/qqbot/src/demo-standalone.ts +144 -0
- package/node_modules/@sliverp/qqbot/src/gateway.ts +2285 -0
- package/node_modules/@sliverp/qqbot/src/image-server.ts +474 -0
- package/node_modules/@sliverp/qqbot/src/known-users.ts +353 -0
- package/node_modules/@sliverp/qqbot/src/onboarding.ts +274 -0
- package/node_modules/@sliverp/qqbot/src/openclaw-agent-adapter.ts +168 -0
- package/node_modules/@sliverp/qqbot/src/openclaw-plugin-sdk.d.ts +483 -0
- package/node_modules/@sliverp/qqbot/src/outbound.ts +1301 -0
- package/node_modules/@sliverp/qqbot/src/proactive.ts +530 -0
- package/node_modules/@sliverp/qqbot/src/runtime.ts +22 -0
- package/node_modules/@sliverp/qqbot/src/session-store.ts +303 -0
- package/node_modules/@sliverp/qqbot/src/types.ts +153 -0
- package/node_modules/@sliverp/qqbot/src/utils/audio-convert.ts +738 -0
- package/node_modules/@sliverp/qqbot/src/utils/file-utils.ts +122 -0
- package/node_modules/@sliverp/qqbot/src/utils/image-size.ts +266 -0
- package/node_modules/@sliverp/qqbot/src/utils/media-tags.ts +134 -0
- package/node_modules/@sliverp/qqbot/src/utils/payload.ts +265 -0
- package/node_modules/@sliverp/qqbot/src/utils/platform.ts +404 -0
- package/node_modules/@sliverp/qqbot/src/utils/upload-cache.ts +128 -0
- package/node_modules/@sliverp/qqbot/standalone.ts +6 -0
- package/node_modules/@sliverp/qqbot/tsconfig.json +16 -0
- package/package.json +9 -1
- package/dist/BasicAgent-QWEYCLV5.js +0 -12
- package/dist/ExplorerAgent-4IT22VB7.js +0 -12
- package/dist/chunk-3BPSNNK3.js.map +0 -1
- package/dist/chunk-LLV3W326.js.map +0 -1
- package/dist/chunk-LQTEETML.js.map +0 -1
- package/dist/chunk-OBOU27DM.js.map +0 -1
- package/dist/chunk-TSASFMRF.js.map +0 -1
- /package/dist/{BasicAgent-QWEYCLV5.js.map → BasicAgent-UWXLSZP2.js.map} +0 -0
- /package/dist/{ExplorerAgent-4IT22VB7.js.map → ExplorerAgent-LCM3JQS4.js.map} +0 -0
- /package/dist/{notification-3VEAP7YF.js.map → notification-NWVOS2WR.js.map} +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ChannelPlugin,
|
|
3
|
+
type OpenClawConfig,
|
|
4
|
+
applyAccountNameToChannelSection,
|
|
5
|
+
deleteAccountFromConfigSection,
|
|
6
|
+
setAccountEnabledInConfigSection,
|
|
7
|
+
} from "openclaw/plugin-sdk";
|
|
8
|
+
|
|
9
|
+
import type { ResolvedQQBotAccount } from "./types.js";
|
|
10
|
+
import { DEFAULT_ACCOUNT_ID, listQQBotAccountIds, resolveQQBotAccount, applyQQBotAccountConfig, resolveDefaultQQBotAccountId } from "./config.js";
|
|
11
|
+
import { sendText, sendMedia } from "./outbound.js";
|
|
12
|
+
import { startGateway } from "./gateway.js";
|
|
13
|
+
import { qqbotOnboardingAdapter } from "./onboarding.js";
|
|
14
|
+
import { getQQBotRuntime } from "./runtime.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 简单的文本分块函数
|
|
18
|
+
* 用于预先分块长文本
|
|
19
|
+
*/
|
|
20
|
+
function chunkText(text: string, limit: number): string[] {
|
|
21
|
+
if (text.length <= limit) return [text];
|
|
22
|
+
|
|
23
|
+
const chunks: string[] = [];
|
|
24
|
+
let remaining = text;
|
|
25
|
+
|
|
26
|
+
while (remaining.length > 0) {
|
|
27
|
+
if (remaining.length <= limit) {
|
|
28
|
+
chunks.push(remaining);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 尝试在换行处分割
|
|
33
|
+
let splitAt = remaining.lastIndexOf("\n", limit);
|
|
34
|
+
if (splitAt <= 0 || splitAt < limit * 0.5) {
|
|
35
|
+
// 没找到合适的换行,尝试在空格处分割
|
|
36
|
+
splitAt = remaining.lastIndexOf(" ", limit);
|
|
37
|
+
}
|
|
38
|
+
if (splitAt <= 0 || splitAt < limit * 0.5) {
|
|
39
|
+
// 还是没找到,强制在 limit 处分割
|
|
40
|
+
splitAt = limit;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
chunks.push(remaining.slice(0, splitAt));
|
|
44
|
+
remaining = remaining.slice(splitAt).trimStart();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return chunks;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const qqbotPlugin: ChannelPlugin<ResolvedQQBotAccount> = {
|
|
51
|
+
id: "qqbot",
|
|
52
|
+
meta: {
|
|
53
|
+
id: "qqbot",
|
|
54
|
+
label: "QQ Bot",
|
|
55
|
+
selectionLabel: "QQ Bot",
|
|
56
|
+
docsPath: "/docs/channels/qqbot",
|
|
57
|
+
blurb: "Connect to QQ via official QQ Bot API",
|
|
58
|
+
order: 50,
|
|
59
|
+
},
|
|
60
|
+
capabilities: {
|
|
61
|
+
chatTypes: ["direct", "group"],
|
|
62
|
+
media: true,
|
|
63
|
+
reactions: false,
|
|
64
|
+
threads: false,
|
|
65
|
+
/**
|
|
66
|
+
* blockStreaming: true 表示该 Channel 支持块流式
|
|
67
|
+
* 框架会收集流式响应,然后通过 deliver 回调发送
|
|
68
|
+
*/
|
|
69
|
+
blockStreaming: false,
|
|
70
|
+
},
|
|
71
|
+
reload: { configPrefixes: ["channels.qqbot"] },
|
|
72
|
+
// CLI onboarding wizard
|
|
73
|
+
onboarding: qqbotOnboardingAdapter,
|
|
74
|
+
|
|
75
|
+
config: {
|
|
76
|
+
listAccountIds: (cfg) => {
|
|
77
|
+
const ids = listQQBotAccountIds(cfg);
|
|
78
|
+
console.log(`[qqbot:channel] listAccountIds: ${JSON.stringify(ids)}`);
|
|
79
|
+
return ids;
|
|
80
|
+
},
|
|
81
|
+
resolveAccount: (cfg, accountId) => {
|
|
82
|
+
const account = resolveQQBotAccount(cfg, accountId);
|
|
83
|
+
console.log(`[qqbot:channel] resolveAccount: input=${accountId} → resolved=${account.accountId}, appId=${account.appId}, enabled=${account.enabled}`);
|
|
84
|
+
return account;
|
|
85
|
+
},
|
|
86
|
+
defaultAccountId: (cfg) => {
|
|
87
|
+
const id = resolveDefaultQQBotAccountId(cfg);
|
|
88
|
+
console.log(`[qqbot:channel] defaultAccountId: ${id}`);
|
|
89
|
+
return id;
|
|
90
|
+
},
|
|
91
|
+
// 新增:设置账户启用状态
|
|
92
|
+
setAccountEnabled: ({ cfg, accountId, enabled }) =>
|
|
93
|
+
setAccountEnabledInConfigSection({
|
|
94
|
+
cfg,
|
|
95
|
+
sectionKey: "qqbot",
|
|
96
|
+
accountId,
|
|
97
|
+
enabled,
|
|
98
|
+
allowTopLevel: true,
|
|
99
|
+
}),
|
|
100
|
+
// 新增:删除账户
|
|
101
|
+
deleteAccount: ({ cfg, accountId }) =>
|
|
102
|
+
deleteAccountFromConfigSection({
|
|
103
|
+
cfg,
|
|
104
|
+
sectionKey: "qqbot",
|
|
105
|
+
accountId,
|
|
106
|
+
clearBaseFields: ["appId", "clientSecret", "clientSecretFile", "name"],
|
|
107
|
+
}),
|
|
108
|
+
isConfigured: (account) => Boolean(account?.appId && account?.clientSecret),
|
|
109
|
+
describeAccount: (account) => ({
|
|
110
|
+
accountId: account?.accountId ?? DEFAULT_ACCOUNT_ID,
|
|
111
|
+
name: account?.name,
|
|
112
|
+
enabled: account?.enabled ?? false,
|
|
113
|
+
configured: Boolean(account?.appId && account?.clientSecret),
|
|
114
|
+
tokenSource: account?.secretSource,
|
|
115
|
+
}),
|
|
116
|
+
// 关键:解析 allowFrom 配置,用于命令授权
|
|
117
|
+
resolveAllowFrom: ({ cfg, accountId }: { cfg: OpenClawConfig; accountId?: string }) => {
|
|
118
|
+
const account = resolveQQBotAccount(cfg, accountId);
|
|
119
|
+
const allowFrom = account.config?.allowFrom ?? [];
|
|
120
|
+
console.log(`[qqbot] resolveAllowFrom: accountId=${accountId}, allowFrom=${JSON.stringify(allowFrom)}`);
|
|
121
|
+
return allowFrom.map((entry: string | number) => String(entry));
|
|
122
|
+
},
|
|
123
|
+
// 格式化 allowFrom 条目(移除 qqbot: 前缀,统一大写)
|
|
124
|
+
formatAllowFrom: ({ allowFrom }: { allowFrom: Array<string | number> }) =>
|
|
125
|
+
allowFrom
|
|
126
|
+
.map((entry: string | number) => String(entry).trim())
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.map((entry: string) => entry.replace(/^qqbot:/i, ""))
|
|
129
|
+
.map((entry: string) => entry.toUpperCase()), // QQ openid 是大写的
|
|
130
|
+
},
|
|
131
|
+
setup: {
|
|
132
|
+
// 新增:规范化账户 ID
|
|
133
|
+
resolveAccountId: ({ accountId }) => accountId?.trim().toLowerCase() || DEFAULT_ACCOUNT_ID,
|
|
134
|
+
// 新增:应用账户名称
|
|
135
|
+
applyAccountName: ({ cfg, accountId, name }) =>
|
|
136
|
+
applyAccountNameToChannelSection({
|
|
137
|
+
cfg,
|
|
138
|
+
channelKey: "qqbot",
|
|
139
|
+
accountId,
|
|
140
|
+
name,
|
|
141
|
+
}),
|
|
142
|
+
validateInput: ({ input }) => {
|
|
143
|
+
if (!input.token && !input.tokenFile && !input.useEnv) {
|
|
144
|
+
return "QQBot requires --token (format: appId:clientSecret) or --use-env";
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
},
|
|
148
|
+
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
149
|
+
let appId = "";
|
|
150
|
+
let clientSecret = "";
|
|
151
|
+
|
|
152
|
+
if (input.token) {
|
|
153
|
+
const parts = input.token.split(":");
|
|
154
|
+
if (parts.length === 2) {
|
|
155
|
+
appId = parts[0];
|
|
156
|
+
clientSecret = parts[1];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return applyQQBotAccountConfig(cfg, accountId, {
|
|
161
|
+
appId,
|
|
162
|
+
clientSecret,
|
|
163
|
+
clientSecretFile: input.tokenFile,
|
|
164
|
+
name: input.name,
|
|
165
|
+
imageServerBaseUrl: input.imageServerBaseUrl,
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
// Messaging 配置:用于解析目标地址
|
|
170
|
+
messaging: {
|
|
171
|
+
/**
|
|
172
|
+
* 规范化目标地址
|
|
173
|
+
* 支持以下格式:
|
|
174
|
+
* - qqbot:c2c:openid -> 私聊
|
|
175
|
+
* - qqbot:group:groupid -> 群聊
|
|
176
|
+
* - qqbot:channel:channelid -> 频道
|
|
177
|
+
* - c2c:openid -> 私聊
|
|
178
|
+
* - group:groupid -> 群聊
|
|
179
|
+
* - channel:channelid -> 频道
|
|
180
|
+
* - 纯 openid(32位十六进制)-> 私聊
|
|
181
|
+
*/
|
|
182
|
+
normalizeTarget: (target: string) => {
|
|
183
|
+
// 去掉 qqbot: 前缀(如果有)
|
|
184
|
+
const id = target.replace(/^qqbot:/i, "");
|
|
185
|
+
|
|
186
|
+
// 检查是否是已知格式
|
|
187
|
+
if (id.startsWith("c2c:") || id.startsWith("group:") || id.startsWith("channel:")) {
|
|
188
|
+
return { ok: true, to: `qqbot:${id}` };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 检查是否是纯 openid(32位十六进制,不带连字符)
|
|
192
|
+
// QQ Bot OpenID 格式类似: 207A5B8339D01F6582911C014668B77B
|
|
193
|
+
const openIdHexPattern = /^[0-9a-fA-F]{32}$/;
|
|
194
|
+
if (openIdHexPattern.test(id)) {
|
|
195
|
+
return { ok: true, to: `qqbot:c2c:${id}` };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 检查是否是 UUID 格式的 openid(带连字符)
|
|
199
|
+
const openIdUuidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
200
|
+
if (openIdUuidPattern.test(id)) {
|
|
201
|
+
return { ok: true, to: `qqbot:c2c:${id}` };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 不认识的格式,返回 undefined
|
|
205
|
+
return { ok: false, error: `Unrecognized QQBot target: ${target}` };
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* 目标解析器配置
|
|
209
|
+
* 用于判断一个目标 ID 是否看起来像 QQ Bot 的格式
|
|
210
|
+
*/
|
|
211
|
+
targetResolver: {
|
|
212
|
+
/**
|
|
213
|
+
* 判断目标 ID 是否可能是 QQ Bot 格式
|
|
214
|
+
* 支持以下格式:
|
|
215
|
+
* - qqbot:c2c:xxx
|
|
216
|
+
* - qqbot:group:xxx
|
|
217
|
+
* - qqbot:channel:xxx
|
|
218
|
+
* - c2c:xxx
|
|
219
|
+
* - group:xxx
|
|
220
|
+
* - channel:xxx
|
|
221
|
+
* - UUID 格式的 openid
|
|
222
|
+
*/
|
|
223
|
+
looksLikeId: (id: string): boolean => {
|
|
224
|
+
// 带 qqbot: 前缀的格式
|
|
225
|
+
if (/^qqbot:(c2c|group|channel):/i.test(id)) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
// 不带前缀但有类型标识
|
|
229
|
+
if (/^(c2c|group|channel):/i.test(id)) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
// 32位十六进制 openid(不带连字符)
|
|
233
|
+
if (/^[0-9a-fA-F]{32}$/.test(id)) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
// UUID 格式的 openid(带连字符)
|
|
237
|
+
const openIdPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
238
|
+
return openIdPattern.test(id);
|
|
239
|
+
},
|
|
240
|
+
hint: "QQ Bot 目标格式: qqbot:c2c:openid (私聊) 或 qqbot:group:groupid (群聊)",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
outbound: {
|
|
244
|
+
deliveryMode: "direct",
|
|
245
|
+
chunker: chunkText,
|
|
246
|
+
chunkerMode: "markdown",
|
|
247
|
+
textChunkLimit: 2000,
|
|
248
|
+
sendText: async ({ to, text, accountId, replyToId, cfg }) => {
|
|
249
|
+
console.log(`[qqbot:channel] sendText called — accountId=${accountId}, to=${to}, replyToId=${replyToId}, text.length=${text?.length ?? 0}`);
|
|
250
|
+
console.log(`[qqbot:channel] sendText text preview: ${text?.slice(0, 100)}${(text?.length ?? 0) > 100 ? "..." : ""}`);
|
|
251
|
+
const account = resolveQQBotAccount(cfg, accountId);
|
|
252
|
+
console.log(`[qqbot:channel] sendText resolved account: id=${account.accountId}, appId=${account.appId}, enabled=${account.enabled}`);
|
|
253
|
+
const result = await sendText({ to, text, accountId, replyToId, account });
|
|
254
|
+
console.log(`[qqbot:channel] sendText result: messageId=${result.messageId}, error=${result.error ?? "none"}`);
|
|
255
|
+
return {
|
|
256
|
+
channel: "qqbot",
|
|
257
|
+
messageId: result.messageId,
|
|
258
|
+
error: result.error ? new Error(result.error) : undefined,
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
sendMedia: async ({ to, text, mediaUrl, accountId, replyToId, cfg }) => {
|
|
262
|
+
console.log(`[qqbot:channel] sendMedia called — accountId=${accountId}, to=${to}, replyToId=${replyToId}, mediaUrl=${mediaUrl?.slice(0, 80)}, text.length=${text?.length ?? 0}`);
|
|
263
|
+
const account = resolveQQBotAccount(cfg, accountId);
|
|
264
|
+
console.log(`[qqbot:channel] sendMedia resolved account: id=${account.accountId}, appId=${account.appId}, enabled=${account.enabled}`);
|
|
265
|
+
const result = await sendMedia({ to, text: text ?? "", mediaUrl: mediaUrl ?? "", accountId, replyToId, account });
|
|
266
|
+
console.log(`[qqbot:channel] sendMedia result: messageId=${result.messageId}, error=${result.error ?? "none"}`);
|
|
267
|
+
return {
|
|
268
|
+
channel: "qqbot",
|
|
269
|
+
messageId: result.messageId,
|
|
270
|
+
error: result.error ? new Error(result.error) : undefined,
|
|
271
|
+
};
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
gateway: {
|
|
275
|
+
startAccount: async (ctx) => {
|
|
276
|
+
const { account, abortSignal, log, cfg } = ctx;
|
|
277
|
+
|
|
278
|
+
log?.info(`[qqbot:${account.accountId}] Starting gateway — appId=${account.appId}, enabled=${account.enabled}, name=${account.name ?? "unnamed"}`);
|
|
279
|
+
console.log(`[qqbot:channel] startAccount: accountId=${account.accountId}, appId=${account.appId}, secretSource=${account.secretSource}`);
|
|
280
|
+
|
|
281
|
+
await startGateway({
|
|
282
|
+
account,
|
|
283
|
+
abortSignal,
|
|
284
|
+
cfg,
|
|
285
|
+
log,
|
|
286
|
+
onReady: () => {
|
|
287
|
+
log?.info(`[qqbot:${account.accountId}] Gateway ready`);
|
|
288
|
+
ctx.setStatus({
|
|
289
|
+
...ctx.getStatus(),
|
|
290
|
+
running: true,
|
|
291
|
+
connected: true,
|
|
292
|
+
lastConnectedAt: Date.now(),
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
onError: (error) => {
|
|
296
|
+
log?.error(`[qqbot:${account.accountId}] Gateway error: ${error.message}`);
|
|
297
|
+
ctx.setStatus({
|
|
298
|
+
...ctx.getStatus(),
|
|
299
|
+
lastError: error.message,
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
// 新增:登出账户(清除配置中的凭证)
|
|
305
|
+
logoutAccount: async ({ accountId, cfg }) => {
|
|
306
|
+
const nextCfg = { ...cfg } as OpenClawConfig;
|
|
307
|
+
const nextQQBot = cfg.channels?.qqbot ? { ...cfg.channels.qqbot } : undefined;
|
|
308
|
+
let cleared = false;
|
|
309
|
+
let changed = false;
|
|
310
|
+
|
|
311
|
+
if (nextQQBot) {
|
|
312
|
+
const qqbot = nextQQBot as Record<string, unknown>;
|
|
313
|
+
if (accountId === DEFAULT_ACCOUNT_ID && qqbot.clientSecret) {
|
|
314
|
+
delete qqbot.clientSecret;
|
|
315
|
+
cleared = true;
|
|
316
|
+
changed = true;
|
|
317
|
+
}
|
|
318
|
+
const accounts = qqbot.accounts as Record<string, Record<string, unknown>> | undefined;
|
|
319
|
+
if (accounts && accountId in accounts) {
|
|
320
|
+
const entry = accounts[accountId] as Record<string, unknown> | undefined;
|
|
321
|
+
if (entry && "clientSecret" in entry) {
|
|
322
|
+
delete entry.clientSecret;
|
|
323
|
+
cleared = true;
|
|
324
|
+
changed = true;
|
|
325
|
+
}
|
|
326
|
+
if (entry && Object.keys(entry).length === 0) {
|
|
327
|
+
delete accounts[accountId];
|
|
328
|
+
changed = true;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (changed && nextQQBot) {
|
|
334
|
+
nextCfg.channels = { ...nextCfg.channels, qqbot: nextQQBot };
|
|
335
|
+
const runtime = getQQBotRuntime();
|
|
336
|
+
const configApi = runtime.config as { writeConfigFile: (cfg: OpenClawConfig) => Promise<void> };
|
|
337
|
+
await configApi.writeConfigFile(nextCfg);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const resolved = resolveQQBotAccount(changed ? nextCfg : cfg, accountId);
|
|
341
|
+
const loggedOut = resolved.secretSource === "none";
|
|
342
|
+
const envToken = Boolean(process.env.QQBOT_CLIENT_SECRET);
|
|
343
|
+
|
|
344
|
+
return { ok: true, cleared, envToken, loggedOut };
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
status: {
|
|
348
|
+
defaultRuntime: {
|
|
349
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
350
|
+
running: false,
|
|
351
|
+
connected: false,
|
|
352
|
+
lastConnectedAt: null,
|
|
353
|
+
lastError: null,
|
|
354
|
+
lastInboundAt: null,
|
|
355
|
+
lastOutboundAt: null,
|
|
356
|
+
},
|
|
357
|
+
// 新增:构建通道摘要
|
|
358
|
+
buildChannelSummary: ({ snapshot }: { snapshot: Record<string, unknown> }) => ({
|
|
359
|
+
configured: snapshot.configured ?? false,
|
|
360
|
+
tokenSource: snapshot.tokenSource ?? "none",
|
|
361
|
+
running: snapshot.running ?? false,
|
|
362
|
+
connected: snapshot.connected ?? false,
|
|
363
|
+
lastConnectedAt: snapshot.lastConnectedAt ?? null,
|
|
364
|
+
lastError: snapshot.lastError ?? null,
|
|
365
|
+
}),
|
|
366
|
+
buildAccountSnapshot: ({ account, runtime }: { account?: ResolvedQQBotAccount; runtime?: Record<string, unknown> }) => ({
|
|
367
|
+
accountId: account?.accountId ?? DEFAULT_ACCOUNT_ID,
|
|
368
|
+
name: account?.name,
|
|
369
|
+
enabled: account?.enabled ?? false,
|
|
370
|
+
configured: Boolean(account?.appId && account?.clientSecret),
|
|
371
|
+
tokenSource: account?.secretSource,
|
|
372
|
+
running: runtime?.running ?? false,
|
|
373
|
+
connected: runtime?.connected ?? false,
|
|
374
|
+
lastConnectedAt: runtime?.lastConnectedAt ?? null,
|
|
375
|
+
lastError: runtime?.lastError ?? null,
|
|
376
|
+
lastInboundAt: runtime?.lastInboundAt ?? null,
|
|
377
|
+
lastOutboundAt: runtime?.lastOutboundAt ?? null,
|
|
378
|
+
}),
|
|
379
|
+
},
|
|
380
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { ResolvedQQBotAccount, QQBotAccountConfig } from "./types.js";
|
|
2
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_ACCOUNT_ID = "default";
|
|
5
|
+
|
|
6
|
+
interface QQBotChannelConfig extends QQBotAccountConfig {
|
|
7
|
+
accounts?: Record<string, QQBotAccountConfig>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 列出所有 QQBot 账户 ID
|
|
12
|
+
*/
|
|
13
|
+
export function listQQBotAccountIds(cfg: OpenClawConfig): string[] {
|
|
14
|
+
const ids = new Set<string>();
|
|
15
|
+
const qqbot = cfg.channels?.qqbot as QQBotChannelConfig | undefined;
|
|
16
|
+
|
|
17
|
+
if (qqbot?.appId) {
|
|
18
|
+
ids.add(DEFAULT_ACCOUNT_ID);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (qqbot?.accounts) {
|
|
22
|
+
for (const accountId of Object.keys(qqbot.accounts)) {
|
|
23
|
+
if (qqbot.accounts[accountId]?.appId) {
|
|
24
|
+
ids.add(accountId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Array.from(ids);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 获取默认账户 ID
|
|
34
|
+
*/
|
|
35
|
+
export function resolveDefaultQQBotAccountId(cfg: OpenClawConfig): string {
|
|
36
|
+
const qqbot = cfg.channels?.qqbot as QQBotChannelConfig | undefined;
|
|
37
|
+
// 如果有默认账户配置,返回 default
|
|
38
|
+
if (qqbot?.appId) {
|
|
39
|
+
return DEFAULT_ACCOUNT_ID;
|
|
40
|
+
}
|
|
41
|
+
// 否则返回第一个配置的账户
|
|
42
|
+
if (qqbot?.accounts) {
|
|
43
|
+
const ids = Object.keys(qqbot.accounts);
|
|
44
|
+
if (ids.length > 0) {
|
|
45
|
+
return ids[0];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return DEFAULT_ACCOUNT_ID;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 解析 QQBot 账户配置
|
|
53
|
+
*/
|
|
54
|
+
export function resolveQQBotAccount(
|
|
55
|
+
cfg: OpenClawConfig,
|
|
56
|
+
accountId?: string | null
|
|
57
|
+
): ResolvedQQBotAccount {
|
|
58
|
+
const resolvedAccountId = accountId ?? DEFAULT_ACCOUNT_ID;
|
|
59
|
+
const qqbot = cfg.channels?.qqbot as QQBotChannelConfig | undefined;
|
|
60
|
+
|
|
61
|
+
// 基础配置
|
|
62
|
+
let accountConfig: QQBotAccountConfig = {};
|
|
63
|
+
let appId = "";
|
|
64
|
+
let clientSecret = "";
|
|
65
|
+
let secretSource: "config" | "file" | "env" | "none" = "none";
|
|
66
|
+
|
|
67
|
+
if (resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
68
|
+
// 默认账户从顶层读取
|
|
69
|
+
accountConfig = {
|
|
70
|
+
enabled: qqbot?.enabled,
|
|
71
|
+
name: qqbot?.name,
|
|
72
|
+
appId: qqbot?.appId,
|
|
73
|
+
clientSecret: qqbot?.clientSecret,
|
|
74
|
+
clientSecretFile: qqbot?.clientSecretFile,
|
|
75
|
+
dmPolicy: qqbot?.dmPolicy,
|
|
76
|
+
allowFrom: qqbot?.allowFrom,
|
|
77
|
+
systemPrompt: qqbot?.systemPrompt,
|
|
78
|
+
imageServerBaseUrl: qqbot?.imageServerBaseUrl,
|
|
79
|
+
markdownSupport: qqbot?.markdownSupport ?? true,
|
|
80
|
+
};
|
|
81
|
+
appId = qqbot?.appId ?? "";
|
|
82
|
+
} else {
|
|
83
|
+
// 命名账户从 accounts 读取
|
|
84
|
+
const account = qqbot?.accounts?.[resolvedAccountId];
|
|
85
|
+
accountConfig = account ?? {};
|
|
86
|
+
appId = account?.appId ?? "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 解析 clientSecret
|
|
90
|
+
if (accountConfig.clientSecret) {
|
|
91
|
+
clientSecret = accountConfig.clientSecret;
|
|
92
|
+
secretSource = "config";
|
|
93
|
+
} else if (accountConfig.clientSecretFile) {
|
|
94
|
+
// 从文件读取(运行时处理)
|
|
95
|
+
secretSource = "file";
|
|
96
|
+
} else if (process.env.QQBOT_CLIENT_SECRET && resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
97
|
+
clientSecret = process.env.QQBOT_CLIENT_SECRET;
|
|
98
|
+
secretSource = "env";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// AppId 也可以从环境变量读取
|
|
102
|
+
if (!appId && process.env.QQBOT_APP_ID && resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
103
|
+
appId = process.env.QQBOT_APP_ID;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
accountId: resolvedAccountId,
|
|
108
|
+
name: accountConfig.name,
|
|
109
|
+
enabled: accountConfig.enabled !== false,
|
|
110
|
+
appId,
|
|
111
|
+
clientSecret,
|
|
112
|
+
secretSource,
|
|
113
|
+
systemPrompt: accountConfig.systemPrompt,
|
|
114
|
+
imageServerBaseUrl: accountConfig.imageServerBaseUrl || process.env.QQBOT_IMAGE_SERVER_BASE_URL,
|
|
115
|
+
markdownSupport: accountConfig.markdownSupport !== false,
|
|
116
|
+
config: accountConfig,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 应用账户配置
|
|
122
|
+
*/
|
|
123
|
+
export function applyQQBotAccountConfig(
|
|
124
|
+
cfg: OpenClawConfig,
|
|
125
|
+
accountId: string,
|
|
126
|
+
input: { appId?: string; clientSecret?: string; clientSecretFile?: string; name?: string; imageServerBaseUrl?: string }
|
|
127
|
+
): OpenClawConfig {
|
|
128
|
+
const next = { ...cfg };
|
|
129
|
+
|
|
130
|
+
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
131
|
+
// 如果没有设置过 allowFrom,默认设置为 ["*"]
|
|
132
|
+
const existingConfig = (next.channels?.qqbot as QQBotChannelConfig) || {};
|
|
133
|
+
const allowFrom = existingConfig.allowFrom ?? ["*"];
|
|
134
|
+
|
|
135
|
+
next.channels = {
|
|
136
|
+
...next.channels,
|
|
137
|
+
qqbot: {
|
|
138
|
+
...(next.channels?.qqbot as Record<string, unknown> || {}),
|
|
139
|
+
enabled: true,
|
|
140
|
+
allowFrom,
|
|
141
|
+
...(input.appId ? { appId: input.appId } : {}),
|
|
142
|
+
...(input.clientSecret
|
|
143
|
+
? { clientSecret: input.clientSecret }
|
|
144
|
+
: input.clientSecretFile
|
|
145
|
+
? { clientSecretFile: input.clientSecretFile }
|
|
146
|
+
: {}),
|
|
147
|
+
...(input.name ? { name: input.name } : {}),
|
|
148
|
+
...(input.imageServerBaseUrl ? { imageServerBaseUrl: input.imageServerBaseUrl } : {}),
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
// 如果没有设置过 allowFrom,默认设置为 ["*"]
|
|
153
|
+
const existingAccountConfig = (next.channels?.qqbot as QQBotChannelConfig)?.accounts?.[accountId] || {};
|
|
154
|
+
const allowFrom = existingAccountConfig.allowFrom ?? ["*"];
|
|
155
|
+
|
|
156
|
+
next.channels = {
|
|
157
|
+
...next.channels,
|
|
158
|
+
qqbot: {
|
|
159
|
+
...(next.channels?.qqbot as Record<string, unknown> || {}),
|
|
160
|
+
enabled: true,
|
|
161
|
+
accounts: {
|
|
162
|
+
...((next.channels?.qqbot as QQBotChannelConfig)?.accounts || {}),
|
|
163
|
+
[accountId]: {
|
|
164
|
+
...((next.channels?.qqbot as QQBotChannelConfig)?.accounts?.[accountId] || {}),
|
|
165
|
+
enabled: true,
|
|
166
|
+
allowFrom,
|
|
167
|
+
...(input.appId ? { appId: input.appId } : {}),
|
|
168
|
+
...(input.clientSecret
|
|
169
|
+
? { clientSecret: input.clientSecret }
|
|
170
|
+
: input.clientSecretFile
|
|
171
|
+
? { clientSecretFile: input.clientSecretFile }
|
|
172
|
+
: {}),
|
|
173
|
+
...(input.name ? { name: input.name } : {}),
|
|
174
|
+
...(input.imageServerBaseUrl ? { imageServerBaseUrl: input.imageServerBaseUrl } : {}),
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return next;
|
|
182
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { createQQBotAgentAdapter } from "../standalone.js";
|
|
3
|
+
import { startGateway } from "../standalone.js";
|
|
4
|
+
import { sendText } from "../standalone.js";
|
|
5
|
+
import type { ResolvedQQBotAccount } from "../standalone.js";
|
|
6
|
+
|
|
7
|
+
function createAccountFromEnv(): ResolvedQQBotAccount {
|
|
8
|
+
const appId = process.env.QQBOT_APP_ID || "";
|
|
9
|
+
const clientSecret = process.env.QQBOT_CLIENT_SECRET || "";
|
|
10
|
+
|
|
11
|
+
if (!appId || !clientSecret) {
|
|
12
|
+
throw new Error("Missing QQBOT_APP_ID or QQBOT_CLIENT_SECRET");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
accountId: "default",
|
|
17
|
+
enabled: true,
|
|
18
|
+
appId,
|
|
19
|
+
clientSecret,
|
|
20
|
+
secretSource: "env",
|
|
21
|
+
markdownSupport: process.env.QQBOT_MARKDOWN_SUPPORT !== "false",
|
|
22
|
+
imageServerBaseUrl: process.env.QQBOT_IMAGE_SERVER_BASE_URL,
|
|
23
|
+
config: {
|
|
24
|
+
allowFrom: ["*"],
|
|
25
|
+
markdownSupport: process.env.QQBOT_MARKDOWN_SUPPORT !== "false",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function main(): Promise<void> {
|
|
31
|
+
const account = createAccountFromEnv();
|
|
32
|
+
const abortController = new AbortController();
|
|
33
|
+
|
|
34
|
+
const agentAdapter = createQQBotAgentAdapter(async (request) => {
|
|
35
|
+
const stamp = new Date(request.timestamp).toLocaleString("zh-CN", { hour12: false });
|
|
36
|
+
console.log("");
|
|
37
|
+
console.log("[inbound]", JSON.stringify({
|
|
38
|
+
when: stamp,
|
|
39
|
+
chatType: request.chatType,
|
|
40
|
+
senderId: request.senderId,
|
|
41
|
+
senderName: request.senderName,
|
|
42
|
+
text: request.text,
|
|
43
|
+
from: request.from,
|
|
44
|
+
attachments: request.attachments,
|
|
45
|
+
}, null, 2));
|
|
46
|
+
|
|
47
|
+
if (request.text.trim() === "/help") {
|
|
48
|
+
return [
|
|
49
|
+
"这是一个独立 TS demo,当前机器人已收到你的消息。",
|
|
50
|
+
"电脑控制台支持命令: send <target> <message>",
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return `回声: ${request.text}`;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const gatewayPromise = startGateway({
|
|
58
|
+
account,
|
|
59
|
+
cfg: {},
|
|
60
|
+
abortSignal: abortController.signal,
|
|
61
|
+
agentAdapter,
|
|
62
|
+
log: console,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const rl = createInterface({
|
|
66
|
+
input: process.stdin,
|
|
67
|
+
output: process.stdout,
|
|
68
|
+
terminal: true,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log("QQBot standalone demo started.");
|
|
72
|
+
console.log("Commands:");
|
|
73
|
+
console.log(" send <target> <message>");
|
|
74
|
+
console.log(" help");
|
|
75
|
+
console.log(" quit");
|
|
76
|
+
console.log("Target examples:");
|
|
77
|
+
console.log(" 32位私聊 openid");
|
|
78
|
+
console.log(" group:<group_openid>");
|
|
79
|
+
console.log(" channel:<channel_id>");
|
|
80
|
+
|
|
81
|
+
rl.on("line", async (line) => {
|
|
82
|
+
const input = line.trim();
|
|
83
|
+
if (!input) return;
|
|
84
|
+
|
|
85
|
+
if (input === "quit" || input === "exit") {
|
|
86
|
+
abortController.abort();
|
|
87
|
+
rl.close();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (input === "help") {
|
|
92
|
+
console.log("send <target> <message>");
|
|
93
|
+
console.log("quit");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (input.startsWith("send ")) {
|
|
98
|
+
const rest = input.slice(5).trim();
|
|
99
|
+
const firstSpace = rest.indexOf(" ");
|
|
100
|
+
if (firstSpace <= 0) {
|
|
101
|
+
console.log("Usage: send <target> <message>");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const target = rest.slice(0, firstSpace).trim();
|
|
106
|
+
const message = rest.slice(firstSpace + 1).trim();
|
|
107
|
+
|
|
108
|
+
if (!message) {
|
|
109
|
+
console.log("Message cannot be empty.");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const result = await sendText({
|
|
115
|
+
to: target,
|
|
116
|
+
text: message,
|
|
117
|
+
account,
|
|
118
|
+
});
|
|
119
|
+
console.log("[outbound]", JSON.stringify(result, null, 2));
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("[outbound-error]", error);
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log("Unknown command. Type help.");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
process.on("SIGINT", () => {
|
|
130
|
+
abortController.abort();
|
|
131
|
+
rl.close();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await gatewayPromise;
|
|
136
|
+
} finally {
|
|
137
|
+
rl.close();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
main().catch((error) => {
|
|
142
|
+
console.error("[demo-startup-error]", error instanceof Error ? error.message : error);
|
|
143
|
+
process.exitCode = 1;
|
|
144
|
+
});
|