@openclaw/qqbot 2026.5.14-beta.1 → 2026.5.14-beta.2
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/api.js +6 -6
- package/dist/channel-nG7HntSR.js +1102 -0
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.setup-DWWV_GAa.js → channel.setup-D_8Ryfln.js} +1 -2
- package/dist/{config-DiBiPtf4.js → config-schema-BE5YP0NG.js} +316 -12
- package/dist/{gateway-DEJhmN-p.js → gateway-Bz_nu9BP.js} +5 -8
- package/dist/{handler-runtime-COWL4RMq.js → handler-runtime-DMMHU4NC.js} +3 -3
- package/dist/{outbound-BdQEr78b.js → outbound-DTQUASKu.js} +2 -2
- package/dist/{request-context-Betw4nJr.js → request-context-DiWgzdpn.js} +2 -2
- package/dist/{sender-BeE_CBbN.js → runtime-BFcYWYuk.js} +17 -1
- package/dist/runtime-api.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/package.json +5 -5
- package/dist/channel-BYNY5Nwb.js +0 -606
- package/dist/config-schema-BeJQUheK.js +0 -308
- package/dist/exec-approvals-Deww_EGt.js +0 -238
- package/dist/narrowing-Bj4eMufj.js +0 -25
- package/dist/runtime-B-cqLImu.js +0 -18
- package/dist/target-parser-ByU3srDK.js +0 -245
package/dist/channel-BYNY5Nwb.js
DELETED
|
@@ -1,606 +0,0 @@
|
|
|
1
|
-
import { t as asOptionalObjectRecord } from "./string-normalize-C46CS-F1.js";
|
|
2
|
-
import { a as resolveQQBotAccount, f as ensurePlatformAdapter, n as applyQQBotAccountConfig, p as getBridgeLogger, t as DEFAULT_ACCOUNT_ID$1 } from "./config-DiBiPtf4.js";
|
|
3
|
-
import { a as shouldHandleQQBotExecApprovalRequest, i as resolveQQBotExecApprovalConfig, n as isQQBotExecApprovalClientEnabled, r as matchesQQBotApprovalAccount, t as authorizeQQBotApprovalAction, u as resolveApprovalTarget } from "./exec-approvals-Deww_EGt.js";
|
|
4
|
-
import { a as qqbotSetupAdapterShared, i as qqbotMeta, n as qqbotSetupWizard, r as qqbotConfigAdapter, t as qqbotChannelConfigSchema } from "./config-schema-BeJQUheK.js";
|
|
5
|
-
import { n as writeOpenClawConfigThroughRuntime, t as toGatewayAccount } from "./narrowing-Bj4eMufj.js";
|
|
6
|
-
import { t as getQQBotRuntime } from "./runtime-B-cqLImu.js";
|
|
7
|
-
import { n as normalizeTarget, s as getQQBotDataPath, t as looksLikeQQBotTarget } from "./target-parser-ByU3srDK.js";
|
|
8
|
-
import { getExecApprovalReplyMetadata } from "openclaw/plugin-sdk/approval-runtime";
|
|
9
|
-
import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter } from "openclaw/plugin-sdk/channel-message";
|
|
10
|
-
import { createChannelApprovalCapability } from "openclaw/plugin-sdk/approval-delivery-runtime";
|
|
11
|
-
import { createLazyChannelApprovalNativeRuntimeAdapter } from "openclaw/plugin-sdk/approval-handler-adapter-runtime";
|
|
12
|
-
import { resolveApprovalRequestSessionConversation } from "openclaw/plugin-sdk/approval-native-runtime";
|
|
13
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
14
|
-
import fs from "node:fs";
|
|
15
|
-
import { replaceFileAtomicSync } from "openclaw/plugin-sdk/security-runtime";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
|
|
18
|
-
//#region extensions/qqbot/src/bridge/approval/capability.ts
|
|
19
|
-
/**
|
|
20
|
-
* QQ Bot Approval Capability — entry point.
|
|
21
|
-
*
|
|
22
|
-
* QQBot uses a simpler approval model than Telegram/Slack: when no
|
|
23
|
-
* approver list is configured, the bot sends the approval message to the
|
|
24
|
-
* originating conversation and any participant can approve from there.
|
|
25
|
-
*
|
|
26
|
-
* When `execApprovals` IS configured, it gates which requests are
|
|
27
|
-
* handled natively and who is authorized. When it is NOT configured,
|
|
28
|
-
* QQBot falls back to "always handle, anyone can approve".
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* When `execApprovals` is configured, delegate to the profile-based
|
|
32
|
-
* check. Otherwise fall back to target-resolvability plus the shared
|
|
33
|
-
* per-account ownership rule in `matchesQQBotApprovalAccount` so that
|
|
34
|
-
* each QQBot account handler only delivers approvals that originated
|
|
35
|
-
* from its own account (openids are account-scoped — cross-account
|
|
36
|
-
* delivery fails with 500 on the QQ Bot API).
|
|
37
|
-
*/
|
|
38
|
-
function shouldHandleRequest(params) {
|
|
39
|
-
if (hasExecApprovalConfig(params)) return shouldHandleQQBotExecApprovalRequest(params);
|
|
40
|
-
if (!canResolveTarget(params.request)) return false;
|
|
41
|
-
return matchesQQBotApprovalAccount({
|
|
42
|
-
cfg: params.cfg,
|
|
43
|
-
accountId: params.accountId,
|
|
44
|
-
request: params.request
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function hasExecApprovalConfig(params) {
|
|
48
|
-
return resolveQQBotExecApprovalConfig(params) !== void 0;
|
|
49
|
-
}
|
|
50
|
-
function isNativeDeliveryEnabled(params) {
|
|
51
|
-
if (hasExecApprovalConfig(params)) return isQQBotExecApprovalClientEnabled(params);
|
|
52
|
-
const account = resolveQQBotAccount(params.cfg, params.accountId);
|
|
53
|
-
return account.enabled && account.secretSource !== "none";
|
|
54
|
-
}
|
|
55
|
-
function canResolveTarget(request) {
|
|
56
|
-
if (resolveApprovalTarget(request.request.sessionKey ?? null, request.request.turnSourceTo ?? null)) return true;
|
|
57
|
-
return resolveApprovalRequestSessionConversation({
|
|
58
|
-
request,
|
|
59
|
-
channel: "qqbot",
|
|
60
|
-
bundledFallback: true
|
|
61
|
-
})?.id != null;
|
|
62
|
-
}
|
|
63
|
-
function createQQBotApprovalCapability() {
|
|
64
|
-
return createChannelApprovalCapability({
|
|
65
|
-
authorizeActorAction: ({ cfg, accountId, senderId, approvalKind }) => authorizeQQBotApprovalAction({
|
|
66
|
-
cfg,
|
|
67
|
-
accountId,
|
|
68
|
-
senderId,
|
|
69
|
-
approvalKind
|
|
70
|
-
}),
|
|
71
|
-
getActionAvailabilityState: ({ cfg, accountId }) => {
|
|
72
|
-
return isNativeDeliveryEnabled({
|
|
73
|
-
cfg,
|
|
74
|
-
accountId
|
|
75
|
-
}) ? { kind: "enabled" } : { kind: "disabled" };
|
|
76
|
-
},
|
|
77
|
-
getExecInitiatingSurfaceState: ({ cfg, accountId }) => {
|
|
78
|
-
return isNativeDeliveryEnabled({
|
|
79
|
-
cfg,
|
|
80
|
-
accountId
|
|
81
|
-
}) ? { kind: "enabled" } : { kind: "disabled" };
|
|
82
|
-
},
|
|
83
|
-
describeExecApprovalSetup: ({ accountId }) => {
|
|
84
|
-
return `QQBot native exec approvals are enabled by default. To restrict who can approve, configure \`${accountId && accountId !== "default" ? `channels.qqbot.accounts.${accountId}` : "channels.qqbot"}.execApprovals.approvers\` with QQ user OpenIDs.`;
|
|
85
|
-
},
|
|
86
|
-
delivery: {
|
|
87
|
-
hasConfiguredDmRoute: () => true,
|
|
88
|
-
shouldSuppressForwardingFallback: (input) => {
|
|
89
|
-
const channel = normalizeOptionalString(input.target?.channel);
|
|
90
|
-
if (channel !== "qqbot") return false;
|
|
91
|
-
const accountId = normalizeOptionalString(input.target?.accountId) ?? normalizeOptionalString(input.request?.request?.turnSourceAccountId);
|
|
92
|
-
const result = isNativeDeliveryEnabled({
|
|
93
|
-
cfg: input.cfg,
|
|
94
|
-
accountId
|
|
95
|
-
});
|
|
96
|
-
getBridgeLogger().debug?.(`[qqbot:approval] shouldSuppressForwardingFallback channel=${channel} accountId=${accountId} → ${result}`);
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
native: {
|
|
101
|
-
describeDeliveryCapabilities: ({ cfg, accountId }) => ({
|
|
102
|
-
enabled: isNativeDeliveryEnabled({
|
|
103
|
-
cfg,
|
|
104
|
-
accountId
|
|
105
|
-
}),
|
|
106
|
-
preferredSurface: "origin",
|
|
107
|
-
supportsOriginSurface: true,
|
|
108
|
-
supportsApproverDmSurface: false,
|
|
109
|
-
notifyOriginWhenDmOnly: false
|
|
110
|
-
}),
|
|
111
|
-
resolveOriginTarget: ({ request }) => {
|
|
112
|
-
const target = resolveApprovalTarget(request.request.sessionKey ?? null, request.request.turnSourceTo ?? null);
|
|
113
|
-
if (target) return { to: `${target.type}:${target.id}` };
|
|
114
|
-
const sessionConversation = resolveApprovalRequestSessionConversation({
|
|
115
|
-
request,
|
|
116
|
-
channel: "qqbot",
|
|
117
|
-
bundledFallback: true
|
|
118
|
-
});
|
|
119
|
-
if (sessionConversation?.id) return { to: `${sessionConversation.kind === "group" ? "group" : "c2c"}:${sessionConversation.id}` };
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
nativeRuntime: createLazyChannelApprovalNativeRuntimeAdapter({
|
|
124
|
-
eventKinds: ["exec", "plugin"],
|
|
125
|
-
isConfigured: ({ cfg, accountId }) => {
|
|
126
|
-
const result = isNativeDeliveryEnabled({
|
|
127
|
-
cfg,
|
|
128
|
-
accountId
|
|
129
|
-
});
|
|
130
|
-
getBridgeLogger().debug?.(`[qqbot:approval] nativeRuntime.isConfigured accountId=${accountId} → ${result}`);
|
|
131
|
-
return result;
|
|
132
|
-
},
|
|
133
|
-
shouldHandle: ({ cfg, accountId, request }) => {
|
|
134
|
-
const result = shouldHandleRequest({
|
|
135
|
-
cfg,
|
|
136
|
-
accountId,
|
|
137
|
-
request
|
|
138
|
-
});
|
|
139
|
-
getBridgeLogger().debug?.(`[qqbot:approval] nativeRuntime.shouldHandle accountId=${accountId} → ${result}`);
|
|
140
|
-
return result;
|
|
141
|
-
},
|
|
142
|
-
load: async () => {
|
|
143
|
-
ensurePlatformAdapter();
|
|
144
|
-
return (await import("./handler-runtime-COWL4RMq.js")).qqbotApprovalNativeRuntime;
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const qqbotApprovalCapability = createQQBotApprovalCapability();
|
|
150
|
-
let _cachedCapability;
|
|
151
|
-
function getQQBotApprovalCapability() {
|
|
152
|
-
_cachedCapability ??= qqbotApprovalCapability;
|
|
153
|
-
return _cachedCapability;
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region extensions/qqbot/src/engine/utils/data-paths.ts
|
|
157
|
-
/**
|
|
158
|
-
* Centralised filename helpers for persisted QQBot state.
|
|
159
|
-
*
|
|
160
|
-
* Every persistence module routes file paths through these helpers so the
|
|
161
|
-
* naming convention stays in sync and legacy migrations are handled
|
|
162
|
-
* consistently.
|
|
163
|
-
*
|
|
164
|
-
* Key design decisions:
|
|
165
|
-
* - Credential backup is keyed only by `accountId` because recovery runs
|
|
166
|
-
* exactly when the appId is missing from config.
|
|
167
|
-
*/
|
|
168
|
-
/**
|
|
169
|
-
* Normalise an identifier so it is safe to embed in a filename.
|
|
170
|
-
* Keeps alphanumerics, dot, underscore, dash; everything else becomes `_`.
|
|
171
|
-
*/
|
|
172
|
-
function safeName(id) {
|
|
173
|
-
return id.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Per-accountId credential backup file. Not keyed by appId because the
|
|
177
|
-
* whole point of this file is to recover credentials when appId is
|
|
178
|
-
* missing from the live config.
|
|
179
|
-
*/
|
|
180
|
-
function getCredentialBackupFile(accountId) {
|
|
181
|
-
return path.join(getQQBotDataPath("data"), `credential-backup-${safeName(accountId)}.json`);
|
|
182
|
-
}
|
|
183
|
-
/** Legacy single-file credential backup (pre-multi-account-isolation). */
|
|
184
|
-
function getLegacyCredentialBackupFile() {
|
|
185
|
-
return path.join(getQQBotDataPath("data"), "credential-backup.json");
|
|
186
|
-
}
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region extensions/qqbot/src/engine/config/credential-backup.ts
|
|
189
|
-
/**
|
|
190
|
-
* Credential backup & recovery.
|
|
191
|
-
* 凭证暂存与恢复。
|
|
192
|
-
*
|
|
193
|
-
* Solves the "hot-upgrade interrupted, appId/secret vanished from
|
|
194
|
-
* openclaw.json" failure mode.
|
|
195
|
-
*
|
|
196
|
-
* Mechanics:
|
|
197
|
-
* - After each successful gateway start we snapshot the currently
|
|
198
|
-
* resolved `appId` / `clientSecret` to a per-account backup file.
|
|
199
|
-
* - During plugin startup, if the live config has an empty appId or
|
|
200
|
-
* secret, the gateway consults the backup and restores the values
|
|
201
|
-
* via the config mutation API.
|
|
202
|
-
* - Backups live under `~/.openclaw/qqbot/data/` so they survive
|
|
203
|
-
* plugin directory replacement.
|
|
204
|
-
*
|
|
205
|
-
* Safety notes:
|
|
206
|
-
* - Only restore when credentials are **actually empty** — never
|
|
207
|
-
* overwrite a user's intentional config change.
|
|
208
|
-
* - Atomic write (temp file + rename) to avoid torn files.
|
|
209
|
-
* - Per-account file: `credential-backup-<accountId>.json`. We do
|
|
210
|
-
* **not** also key by appId because recovery happens precisely
|
|
211
|
-
* when appId is unknown.
|
|
212
|
-
* - Legacy single `credential-backup.json` is migrated automatically
|
|
213
|
-
* when the stored accountId matches the caller.
|
|
214
|
-
*/
|
|
215
|
-
/** Persist a credential snapshot (called once gateway reaches READY). */
|
|
216
|
-
function saveCredentialBackup(accountId, appId, clientSecret) {
|
|
217
|
-
if (!appId || !clientSecret) return;
|
|
218
|
-
try {
|
|
219
|
-
const backupPath = getCredentialBackupFile(accountId);
|
|
220
|
-
const data = {
|
|
221
|
-
accountId,
|
|
222
|
-
appId,
|
|
223
|
-
clientSecret,
|
|
224
|
-
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
225
|
-
};
|
|
226
|
-
replaceFileAtomicSync({
|
|
227
|
-
filePath: backupPath,
|
|
228
|
-
content: `${JSON.stringify(data, null, 2)}\n`,
|
|
229
|
-
tempPrefix: ".qqbot-credential-backup"
|
|
230
|
-
});
|
|
231
|
-
} catch {}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Load a credential snapshot for `accountId`.
|
|
235
|
-
*
|
|
236
|
-
* Consults the new per-account file first; falls back to the legacy
|
|
237
|
-
* global backup file and migrates it when the embedded `accountId`
|
|
238
|
-
* matches the request. Returns `null` when no usable backup exists.
|
|
239
|
-
*/
|
|
240
|
-
function loadCredentialBackup(accountId) {
|
|
241
|
-
try {
|
|
242
|
-
if (accountId) {
|
|
243
|
-
const data = loadJsonFile(getCredentialBackupFile(accountId));
|
|
244
|
-
if (data?.appId && data.clientSecret) return data;
|
|
245
|
-
}
|
|
246
|
-
const legacy = getLegacyCredentialBackupFile();
|
|
247
|
-
const data = loadJsonFile(legacy);
|
|
248
|
-
if (data) {
|
|
249
|
-
if (!data?.appId || !data?.clientSecret) return null;
|
|
250
|
-
if (accountId && data.accountId !== accountId) return null;
|
|
251
|
-
if (data.accountId) try {
|
|
252
|
-
replaceFileAtomicSync({
|
|
253
|
-
filePath: getCredentialBackupFile(data.accountId),
|
|
254
|
-
content: `${JSON.stringify(data, null, 2)}\n`,
|
|
255
|
-
tempPrefix: ".qqbot-credential-backup"
|
|
256
|
-
});
|
|
257
|
-
fs.unlinkSync(legacy);
|
|
258
|
-
} catch {}
|
|
259
|
-
return data;
|
|
260
|
-
}
|
|
261
|
-
} catch {}
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region extensions/qqbot/src/engine/config/credentials.ts
|
|
266
|
-
/**
|
|
267
|
-
* QQBot credential management (pure logic layer).
|
|
268
|
-
* QQBot 凭证管理(纯逻辑层)。
|
|
269
|
-
*
|
|
270
|
-
* Credential clearing and field-level cleanup for logout and setup
|
|
271
|
-
* flows. All functions operate on plain objects (Record<string, unknown>)
|
|
272
|
-
* and stay framework-agnostic.
|
|
273
|
-
*/
|
|
274
|
-
/**
|
|
275
|
-
* Remove clientSecret / clientSecretFile from a QQBot account config.
|
|
276
|
-
*
|
|
277
|
-
* Returns a shallow-cloned config with credentials removed, plus flags
|
|
278
|
-
* indicating whether anything actually changed.
|
|
279
|
-
*/
|
|
280
|
-
function clearAccountCredentials(cfg, accountId) {
|
|
281
|
-
const nextCfg = { ...cfg };
|
|
282
|
-
const channels = asOptionalObjectRecord(cfg.channels);
|
|
283
|
-
const nextQQBot = channels?.qqbot ? { ...asOptionalObjectRecord(channels.qqbot) } : void 0;
|
|
284
|
-
let cleared = false;
|
|
285
|
-
let changed = false;
|
|
286
|
-
if (nextQQBot) {
|
|
287
|
-
const qqbot = nextQQBot;
|
|
288
|
-
if (accountId === "default") {
|
|
289
|
-
if (qqbot.clientSecret) {
|
|
290
|
-
delete qqbot.clientSecret;
|
|
291
|
-
cleared = true;
|
|
292
|
-
changed = true;
|
|
293
|
-
}
|
|
294
|
-
if (qqbot.clientSecretFile) {
|
|
295
|
-
delete qqbot.clientSecretFile;
|
|
296
|
-
cleared = true;
|
|
297
|
-
changed = true;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const accounts = qqbot.accounts;
|
|
301
|
-
if (accounts && accountId in accounts) {
|
|
302
|
-
const entry = accounts[accountId];
|
|
303
|
-
if (entry && "clientSecret" in entry) {
|
|
304
|
-
delete entry.clientSecret;
|
|
305
|
-
cleared = true;
|
|
306
|
-
changed = true;
|
|
307
|
-
}
|
|
308
|
-
if (entry && "clientSecretFile" in entry) {
|
|
309
|
-
delete entry.clientSecretFile;
|
|
310
|
-
cleared = true;
|
|
311
|
-
changed = true;
|
|
312
|
-
}
|
|
313
|
-
if (entry && Object.keys(entry).length === 0) {
|
|
314
|
-
delete accounts[accountId];
|
|
315
|
-
changed = true;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if (changed && nextQQBot) nextCfg.channels = {
|
|
320
|
-
...channels,
|
|
321
|
-
qqbot: nextQQBot
|
|
322
|
-
};
|
|
323
|
-
return {
|
|
324
|
-
nextCfg,
|
|
325
|
-
cleared,
|
|
326
|
-
changed
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
//#endregion
|
|
330
|
-
//#region extensions/qqbot/src/channel.ts
|
|
331
|
-
let gatewayModulePromise;
|
|
332
|
-
function loadGatewayModule() {
|
|
333
|
-
gatewayModulePromise ??= import("./gateway-DEJhmN-p.js");
|
|
334
|
-
return gatewayModulePromise;
|
|
335
|
-
}
|
|
336
|
-
function createQQBotSendReceipt(params) {
|
|
337
|
-
const messageId = params.messageId?.trim();
|
|
338
|
-
return createMessageReceiptFromOutboundResults({
|
|
339
|
-
results: messageId ? [{
|
|
340
|
-
channel: "qqbot",
|
|
341
|
-
messageId,
|
|
342
|
-
conversationId: params.target
|
|
343
|
-
}] : [],
|
|
344
|
-
threadId: params.target,
|
|
345
|
-
kind: params.kind
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
async function sendQQBotText(params) {
|
|
349
|
-
await loadGatewayModule();
|
|
350
|
-
const account = resolveQQBotAccount(params.cfg, params.accountId);
|
|
351
|
-
const { sendText } = await import("./outbound-BdQEr78b.js").then((n) => n.t);
|
|
352
|
-
const result = await sendText({
|
|
353
|
-
to: params.to,
|
|
354
|
-
text: params.text,
|
|
355
|
-
accountId: params.accountId,
|
|
356
|
-
replyToId: params.replyToId,
|
|
357
|
-
account: toGatewayAccount(account)
|
|
358
|
-
});
|
|
359
|
-
return {
|
|
360
|
-
channel: "qqbot",
|
|
361
|
-
messageId: result.messageId ?? "",
|
|
362
|
-
receipt: createQQBotSendReceipt({
|
|
363
|
-
messageId: result.messageId,
|
|
364
|
-
target: params.to,
|
|
365
|
-
kind: "text"
|
|
366
|
-
}),
|
|
367
|
-
meta: result.error ? { error: result.error } : void 0
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
async function sendQQBotMedia(params) {
|
|
371
|
-
await loadGatewayModule();
|
|
372
|
-
const account = resolveQQBotAccount(params.cfg, params.accountId);
|
|
373
|
-
const { sendMedia } = await import("./outbound-BdQEr78b.js").then((n) => n.t);
|
|
374
|
-
const result = await sendMedia({
|
|
375
|
-
to: params.to,
|
|
376
|
-
text: params.text ?? "",
|
|
377
|
-
mediaUrl: params.mediaUrl ?? "",
|
|
378
|
-
accountId: params.accountId,
|
|
379
|
-
replyToId: params.replyToId,
|
|
380
|
-
account: toGatewayAccount(account)
|
|
381
|
-
});
|
|
382
|
-
return {
|
|
383
|
-
channel: "qqbot",
|
|
384
|
-
messageId: result.messageId ?? "",
|
|
385
|
-
receipt: createQQBotSendReceipt({
|
|
386
|
-
messageId: result.messageId,
|
|
387
|
-
target: params.to,
|
|
388
|
-
kind: "media"
|
|
389
|
-
}),
|
|
390
|
-
meta: result.error ? { error: result.error } : void 0
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
function toQQBotMessageSendResult(result) {
|
|
394
|
-
return {
|
|
395
|
-
messageId: result.messageId,
|
|
396
|
-
receipt: result.receipt
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
const qqbotMessageAdapter = defineChannelMessageAdapter({
|
|
400
|
-
id: "qqbot",
|
|
401
|
-
durableFinal: { capabilities: {
|
|
402
|
-
text: true,
|
|
403
|
-
media: true,
|
|
404
|
-
replyTo: true
|
|
405
|
-
} },
|
|
406
|
-
send: {
|
|
407
|
-
text: async (ctx) => toQQBotMessageSendResult(await sendQQBotText({
|
|
408
|
-
cfg: ctx.cfg,
|
|
409
|
-
to: ctx.to,
|
|
410
|
-
text: ctx.text,
|
|
411
|
-
accountId: ctx.accountId,
|
|
412
|
-
replyToId: ctx.replyToId
|
|
413
|
-
})),
|
|
414
|
-
media: async (ctx) => toQQBotMessageSendResult(await sendQQBotMedia({
|
|
415
|
-
cfg: ctx.cfg,
|
|
416
|
-
to: ctx.to,
|
|
417
|
-
text: ctx.text,
|
|
418
|
-
mediaUrl: ctx.mediaUrl,
|
|
419
|
-
accountId: ctx.accountId,
|
|
420
|
-
replyToId: ctx.replyToId
|
|
421
|
-
}))
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
const EXEC_APPROVAL_COMMAND_RE = /\/approve(?:@[^\s]+)?\s+[A-Za-z0-9][A-Za-z0-9._:-]*\s+(?:allow-once|allow-always|always|deny)\b/i;
|
|
425
|
-
function persistAccountCredentialSnapshot(account) {
|
|
426
|
-
if (account.appId && account.clientSecret) saveCredentialBackup(account.accountId, account.appId, account.clientSecret);
|
|
427
|
-
}
|
|
428
|
-
function shouldSuppressLocalQQBotApprovalPrompt(params) {
|
|
429
|
-
if (params.hint?.kind !== "approval-pending" || params.hint.approvalKind !== "exec") return false;
|
|
430
|
-
const account = resolveQQBotAccount(params.cfg, params.accountId);
|
|
431
|
-
if (!account.enabled || account.secretSource === "none") return false;
|
|
432
|
-
if (getExecApprovalReplyMetadata(params.payload)) return true;
|
|
433
|
-
const text = typeof params.payload.text === "string" ? params.payload.text : "";
|
|
434
|
-
return EXEC_APPROVAL_COMMAND_RE.test(text);
|
|
435
|
-
}
|
|
436
|
-
const qqbotPlugin = {
|
|
437
|
-
id: "qqbot",
|
|
438
|
-
setupWizard: qqbotSetupWizard,
|
|
439
|
-
meta: { ...qqbotMeta },
|
|
440
|
-
capabilities: {
|
|
441
|
-
chatTypes: ["direct", "group"],
|
|
442
|
-
media: true,
|
|
443
|
-
reactions: false,
|
|
444
|
-
threads: false,
|
|
445
|
-
blockStreaming: true
|
|
446
|
-
},
|
|
447
|
-
reload: { configPrefixes: ["channels.qqbot"] },
|
|
448
|
-
configSchema: qqbotChannelConfigSchema,
|
|
449
|
-
config: {
|
|
450
|
-
...qqbotConfigAdapter,
|
|
451
|
-
/**
|
|
452
|
-
* Treat an account as configured when either the live config has
|
|
453
|
-
* credentials OR a recoverable credential backup exists. This mirrors
|
|
454
|
-
* the standalone plugin and lets the gateway survive a hot upgrade
|
|
455
|
-
* that wiped openclaw.json mid-flight.
|
|
456
|
-
*/
|
|
457
|
-
isConfigured: (account) => {
|
|
458
|
-
if (qqbotConfigAdapter.isConfigured(account)) return true;
|
|
459
|
-
if (!account) return false;
|
|
460
|
-
const backup = loadCredentialBackup(account.accountId);
|
|
461
|
-
return Boolean(backup?.appId && backup?.clientSecret);
|
|
462
|
-
}
|
|
463
|
-
},
|
|
464
|
-
setup: { ...qqbotSetupAdapterShared },
|
|
465
|
-
approvalCapability: getQQBotApprovalCapability(),
|
|
466
|
-
message: qqbotMessageAdapter,
|
|
467
|
-
messaging: {
|
|
468
|
-
targetPrefixes: ["qqbot"],
|
|
469
|
-
/** Normalize common QQ Bot target formats into the canonical qqbot:... form. */
|
|
470
|
-
normalizeTarget,
|
|
471
|
-
targetResolver: {
|
|
472
|
-
/** Return true when the id looks like a QQ Bot target. */
|
|
473
|
-
looksLikeId: looksLikeQQBotTarget,
|
|
474
|
-
hint: "QQ Bot target format: qqbot:c2c:openid (direct) or qqbot:group:groupid (group)"
|
|
475
|
-
}
|
|
476
|
-
},
|
|
477
|
-
outbound: {
|
|
478
|
-
deliveryMode: "direct",
|
|
479
|
-
chunker: (text, limit) => getQQBotRuntime().channel.text.chunkMarkdownText(text, limit),
|
|
480
|
-
chunkerMode: "markdown",
|
|
481
|
-
textChunkLimit: 5e3,
|
|
482
|
-
shouldSuppressLocalPayloadPrompt: ({ cfg, accountId, payload, hint }) => shouldSuppressLocalQQBotApprovalPrompt({
|
|
483
|
-
cfg,
|
|
484
|
-
accountId,
|
|
485
|
-
payload,
|
|
486
|
-
hint
|
|
487
|
-
}),
|
|
488
|
-
sendText: async ({ to, text, accountId, replyToId, cfg }) => await sendQQBotText({
|
|
489
|
-
cfg,
|
|
490
|
-
to,
|
|
491
|
-
text,
|
|
492
|
-
accountId,
|
|
493
|
-
replyToId
|
|
494
|
-
}),
|
|
495
|
-
sendMedia: async ({ to, text, mediaUrl, accountId, replyToId, cfg }) => await sendQQBotMedia({
|
|
496
|
-
cfg,
|
|
497
|
-
to,
|
|
498
|
-
text,
|
|
499
|
-
mediaUrl,
|
|
500
|
-
accountId,
|
|
501
|
-
replyToId
|
|
502
|
-
})
|
|
503
|
-
},
|
|
504
|
-
gateway: {
|
|
505
|
-
startAccount: async (ctx) => {
|
|
506
|
-
let { account, cfg } = ctx;
|
|
507
|
-
const { abortSignal, log } = ctx;
|
|
508
|
-
if (!account.appId || !account.clientSecret) {
|
|
509
|
-
const backup = loadCredentialBackup(account.accountId);
|
|
510
|
-
if (backup?.appId && backup?.clientSecret) try {
|
|
511
|
-
const nextCfg = applyQQBotAccountConfig(cfg, account.accountId, {
|
|
512
|
-
appId: backup.appId,
|
|
513
|
-
clientSecret: backup.clientSecret
|
|
514
|
-
});
|
|
515
|
-
await writeOpenClawConfigThroughRuntime(getQQBotRuntime(), nextCfg);
|
|
516
|
-
cfg = nextCfg;
|
|
517
|
-
account = resolveQQBotAccount(nextCfg, account.accountId);
|
|
518
|
-
log?.info(`[qqbot:${account.accountId}] Restored credentials from backup (appId=${account.appId})`);
|
|
519
|
-
} catch (err) {
|
|
520
|
-
log?.error(`[qqbot:${account.accountId}] Failed to restore credentials from backup: ${err instanceof Error ? err.message : String(err)}`);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
const { startGateway } = await loadGatewayModule();
|
|
524
|
-
log?.info(`[qqbot:${account.accountId}] Starting gateway — appId=${account.appId}, enabled=${account.enabled}, name=${account.name ?? "unnamed"}`);
|
|
525
|
-
await startGateway({
|
|
526
|
-
account,
|
|
527
|
-
abortSignal,
|
|
528
|
-
cfg,
|
|
529
|
-
log,
|
|
530
|
-
channelRuntime: ctx.channelRuntime,
|
|
531
|
-
onReady: () => {
|
|
532
|
-
log?.info(`[qqbot:${account.accountId}] Gateway ready`);
|
|
533
|
-
ctx.setStatus({
|
|
534
|
-
...ctx.getStatus(),
|
|
535
|
-
running: true,
|
|
536
|
-
connected: true,
|
|
537
|
-
lastConnectedAt: Date.now()
|
|
538
|
-
});
|
|
539
|
-
persistAccountCredentialSnapshot(account);
|
|
540
|
-
},
|
|
541
|
-
onResumed: () => {
|
|
542
|
-
log?.info(`[qqbot:${account.accountId}] Gateway resumed`);
|
|
543
|
-
ctx.setStatus({
|
|
544
|
-
...ctx.getStatus(),
|
|
545
|
-
running: true,
|
|
546
|
-
connected: true,
|
|
547
|
-
lastConnectedAt: Date.now()
|
|
548
|
-
});
|
|
549
|
-
persistAccountCredentialSnapshot(account);
|
|
550
|
-
},
|
|
551
|
-
onError: (error) => {
|
|
552
|
-
log?.error(`[qqbot:${account.accountId}] Gateway error: ${error.message}`);
|
|
553
|
-
ctx.setStatus({
|
|
554
|
-
...ctx.getStatus(),
|
|
555
|
-
lastError: error.message
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
},
|
|
560
|
-
logoutAccount: async ({ accountId, cfg }) => {
|
|
561
|
-
const { nextCfg, cleared, changed } = clearAccountCredentials(cfg, accountId);
|
|
562
|
-
if (changed) await writeOpenClawConfigThroughRuntime(getQQBotRuntime(), nextCfg);
|
|
563
|
-
const loggedOut = resolveQQBotAccount(changed ? nextCfg : cfg, accountId).secretSource === "none";
|
|
564
|
-
return {
|
|
565
|
-
ok: true,
|
|
566
|
-
cleared,
|
|
567
|
-
envToken: Boolean(process.env.QQBOT_CLIENT_SECRET),
|
|
568
|
-
loggedOut
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
},
|
|
572
|
-
status: {
|
|
573
|
-
defaultRuntime: {
|
|
574
|
-
accountId: DEFAULT_ACCOUNT_ID$1,
|
|
575
|
-
running: false,
|
|
576
|
-
connected: false,
|
|
577
|
-
lastConnectedAt: null,
|
|
578
|
-
lastError: null,
|
|
579
|
-
lastInboundAt: null,
|
|
580
|
-
lastOutboundAt: null
|
|
581
|
-
},
|
|
582
|
-
buildChannelSummary: ({ snapshot }) => ({
|
|
583
|
-
configured: snapshot.configured ?? false,
|
|
584
|
-
tokenSource: snapshot.tokenSource ?? "none",
|
|
585
|
-
running: snapshot.running ?? false,
|
|
586
|
-
connected: snapshot.connected ?? false,
|
|
587
|
-
lastConnectedAt: snapshot.lastConnectedAt ?? null,
|
|
588
|
-
lastError: snapshot.lastError ?? null
|
|
589
|
-
}),
|
|
590
|
-
buildAccountSnapshot: ({ account, runtime }) => ({
|
|
591
|
-
accountId: account?.accountId ?? DEFAULT_ACCOUNT_ID$1,
|
|
592
|
-
name: account?.name,
|
|
593
|
-
enabled: account?.enabled ?? false,
|
|
594
|
-
configured: Boolean(account?.appId && account?.clientSecret),
|
|
595
|
-
tokenSource: account?.secretSource,
|
|
596
|
-
running: runtime?.running ?? false,
|
|
597
|
-
connected: runtime?.connected ?? false,
|
|
598
|
-
lastConnectedAt: runtime?.lastConnectedAt ?? null,
|
|
599
|
-
lastError: runtime?.lastError ?? null,
|
|
600
|
-
lastInboundAt: runtime?.lastInboundAt ?? null,
|
|
601
|
-
lastOutboundAt: runtime?.lastOutboundAt ?? null
|
|
602
|
-
})
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
//#endregion
|
|
606
|
-
export { qqbotPlugin as t };
|