@sliverp/qqbot 1.3.0
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/README.md +231 -0
- package/clawdbot.plugin.json +16 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +22 -0
- package/dist/src/api.d.ts +194 -0
- package/dist/src/api.js +555 -0
- package/dist/src/channel.d.ts +3 -0
- package/dist/src/channel.js +146 -0
- package/dist/src/config.d.ts +25 -0
- package/dist/src/config.js +148 -0
- package/dist/src/gateway.d.ts +17 -0
- package/dist/src/gateway.js +722 -0
- package/dist/src/image-server.d.ts +62 -0
- package/dist/src/image-server.js +401 -0
- package/dist/src/known-users.d.ts +100 -0
- package/dist/src/known-users.js +264 -0
- package/dist/src/onboarding.d.ts +10 -0
- package/dist/src/onboarding.js +190 -0
- package/dist/src/outbound.d.ts +149 -0
- package/dist/src/outbound.js +476 -0
- package/dist/src/proactive.d.ts +170 -0
- package/dist/src/proactive.js +398 -0
- package/dist/src/runtime.d.ts +3 -0
- package/dist/src/runtime.js +10 -0
- package/dist/src/session-store.d.ts +49 -0
- package/dist/src/session-store.js +242 -0
- package/dist/src/types.d.ts +116 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils/image-size.d.ts +51 -0
- package/dist/src/utils/image-size.js +234 -0
- package/dist/src/utils/payload.d.ts +112 -0
- package/dist/src/utils/payload.js +186 -0
- package/index.ts +27 -0
- package/moltbot.plugin.json +16 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +13 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +554 -0
- package/node_modules/ws/lib/websocket.js +1393 -0
- package/node_modules/ws/package.json +69 -0
- package/node_modules/ws/wrapper.mjs +8 -0
- package/openclaw.plugin.json +16 -0
- package/package.json +38 -0
- package/qqbot-1.3.0.tgz +0 -0
- package/scripts/proactive-api-server.ts +346 -0
- package/scripts/send-proactive.ts +273 -0
- package/scripts/upgrade.sh +106 -0
- package/skills/qqbot-cron/SKILL.md +490 -0
- package/skills/qqbot-media/SKILL.md +138 -0
- package/src/api.ts +752 -0
- package/src/channel.ts +303 -0
- package/src/config.ts +172 -0
- package/src/gateway.ts +1588 -0
- package/src/image-server.ts +474 -0
- package/src/known-users.ts +358 -0
- package/src/onboarding.ts +254 -0
- package/src/openclaw-plugin-sdk.d.ts +483 -0
- package/src/outbound.ts +571 -0
- package/src/proactive.ts +528 -0
- package/src/runtime.ts +14 -0
- package/src/session-store.ts +292 -0
- package/src/types.ts +123 -0
- package/src/utils/image-size.ts +266 -0
- package/src/utils/payload.ts +265 -0
- package/tsconfig.json +16 -0
- package/upgrade-and-run.sh +89 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ResolvedQQBotAccount } from "./types.js";
|
|
2
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
3
|
+
export declare const DEFAULT_ACCOUNT_ID = "default";
|
|
4
|
+
/**
|
|
5
|
+
* 列出所有 QQBot 账户 ID
|
|
6
|
+
*/
|
|
7
|
+
export declare function listQQBotAccountIds(cfg: OpenClawConfig): string[];
|
|
8
|
+
/**
|
|
9
|
+
* 获取默认账户 ID
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveDefaultQQBotAccountId(cfg: OpenClawConfig): string;
|
|
12
|
+
/**
|
|
13
|
+
* 解析 QQBot 账户配置
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveQQBotAccount(cfg: OpenClawConfig, accountId?: string | null): ResolvedQQBotAccount;
|
|
16
|
+
/**
|
|
17
|
+
* 应用账户配置
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyQQBotAccountConfig(cfg: OpenClawConfig, accountId: string, input: {
|
|
20
|
+
appId?: string;
|
|
21
|
+
clientSecret?: string;
|
|
22
|
+
clientSecretFile?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
imageServerBaseUrl?: string;
|
|
25
|
+
}): OpenClawConfig;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export const DEFAULT_ACCOUNT_ID = "default";
|
|
2
|
+
/**
|
|
3
|
+
* 列出所有 QQBot 账户 ID
|
|
4
|
+
*/
|
|
5
|
+
export function listQQBotAccountIds(cfg) {
|
|
6
|
+
const ids = new Set();
|
|
7
|
+
const qqbot = cfg.channels?.qqbot;
|
|
8
|
+
if (qqbot?.appId) {
|
|
9
|
+
ids.add(DEFAULT_ACCOUNT_ID);
|
|
10
|
+
}
|
|
11
|
+
if (qqbot?.accounts) {
|
|
12
|
+
for (const accountId of Object.keys(qqbot.accounts)) {
|
|
13
|
+
if (qqbot.accounts[accountId]?.appId) {
|
|
14
|
+
ids.add(accountId);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Array.from(ids);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取默认账户 ID
|
|
22
|
+
*/
|
|
23
|
+
export function resolveDefaultQQBotAccountId(cfg) {
|
|
24
|
+
const qqbot = cfg.channels?.qqbot;
|
|
25
|
+
// 如果有默认账户配置,返回 default
|
|
26
|
+
if (qqbot?.appId) {
|
|
27
|
+
return DEFAULT_ACCOUNT_ID;
|
|
28
|
+
}
|
|
29
|
+
// 否则返回第一个配置的账户
|
|
30
|
+
if (qqbot?.accounts) {
|
|
31
|
+
const ids = Object.keys(qqbot.accounts);
|
|
32
|
+
if (ids.length > 0) {
|
|
33
|
+
return ids[0];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return DEFAULT_ACCOUNT_ID;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 解析 QQBot 账户配置
|
|
40
|
+
*/
|
|
41
|
+
export function resolveQQBotAccount(cfg, accountId) {
|
|
42
|
+
const resolvedAccountId = accountId ?? DEFAULT_ACCOUNT_ID;
|
|
43
|
+
const qqbot = cfg.channels?.qqbot;
|
|
44
|
+
// 基础配置
|
|
45
|
+
let accountConfig = {};
|
|
46
|
+
let appId = "";
|
|
47
|
+
let clientSecret = "";
|
|
48
|
+
let secretSource = "none";
|
|
49
|
+
if (resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
50
|
+
// 默认账户从顶层读取
|
|
51
|
+
accountConfig = {
|
|
52
|
+
enabled: qqbot?.enabled,
|
|
53
|
+
name: qqbot?.name,
|
|
54
|
+
appId: qqbot?.appId,
|
|
55
|
+
clientSecret: qqbot?.clientSecret,
|
|
56
|
+
clientSecretFile: qqbot?.clientSecretFile,
|
|
57
|
+
dmPolicy: qqbot?.dmPolicy,
|
|
58
|
+
allowFrom: qqbot?.allowFrom,
|
|
59
|
+
systemPrompt: qqbot?.systemPrompt,
|
|
60
|
+
imageServerBaseUrl: qqbot?.imageServerBaseUrl,
|
|
61
|
+
markdownSupport: qqbot?.markdownSupport,
|
|
62
|
+
};
|
|
63
|
+
appId = qqbot?.appId ?? "";
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// 命名账户从 accounts 读取
|
|
67
|
+
const account = qqbot?.accounts?.[resolvedAccountId];
|
|
68
|
+
accountConfig = account ?? {};
|
|
69
|
+
appId = account?.appId ?? "";
|
|
70
|
+
}
|
|
71
|
+
// 解析 clientSecret
|
|
72
|
+
if (accountConfig.clientSecret) {
|
|
73
|
+
clientSecret = accountConfig.clientSecret;
|
|
74
|
+
secretSource = "config";
|
|
75
|
+
}
|
|
76
|
+
else if (accountConfig.clientSecretFile) {
|
|
77
|
+
// 从文件读取(运行时处理)
|
|
78
|
+
secretSource = "file";
|
|
79
|
+
}
|
|
80
|
+
else if (process.env.QQBOT_CLIENT_SECRET && resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
81
|
+
clientSecret = process.env.QQBOT_CLIENT_SECRET;
|
|
82
|
+
secretSource = "env";
|
|
83
|
+
}
|
|
84
|
+
// AppId 也可以从环境变量读取
|
|
85
|
+
if (!appId && process.env.QQBOT_APP_ID && resolvedAccountId === DEFAULT_ACCOUNT_ID) {
|
|
86
|
+
appId = process.env.QQBOT_APP_ID;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
accountId: resolvedAccountId,
|
|
90
|
+
name: accountConfig.name,
|
|
91
|
+
enabled: accountConfig.enabled !== false,
|
|
92
|
+
appId,
|
|
93
|
+
clientSecret,
|
|
94
|
+
secretSource,
|
|
95
|
+
systemPrompt: accountConfig.systemPrompt,
|
|
96
|
+
imageServerBaseUrl: accountConfig.imageServerBaseUrl || process.env.QQBOT_IMAGE_SERVER_BASE_URL,
|
|
97
|
+
markdownSupport: accountConfig.markdownSupport,
|
|
98
|
+
config: accountConfig,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 应用账户配置
|
|
103
|
+
*/
|
|
104
|
+
export function applyQQBotAccountConfig(cfg, accountId, input) {
|
|
105
|
+
const next = { ...cfg };
|
|
106
|
+
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
107
|
+
next.channels = {
|
|
108
|
+
...next.channels,
|
|
109
|
+
qqbot: {
|
|
110
|
+
...(next.channels?.qqbot || {}),
|
|
111
|
+
enabled: true,
|
|
112
|
+
...(input.appId ? { appId: input.appId } : {}),
|
|
113
|
+
...(input.clientSecret
|
|
114
|
+
? { clientSecret: input.clientSecret }
|
|
115
|
+
: input.clientSecretFile
|
|
116
|
+
? { clientSecretFile: input.clientSecretFile }
|
|
117
|
+
: {}),
|
|
118
|
+
...(input.name ? { name: input.name } : {}),
|
|
119
|
+
...(input.imageServerBaseUrl ? { imageServerBaseUrl: input.imageServerBaseUrl } : {}),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
next.channels = {
|
|
125
|
+
...next.channels,
|
|
126
|
+
qqbot: {
|
|
127
|
+
...(next.channels?.qqbot || {}),
|
|
128
|
+
enabled: true,
|
|
129
|
+
accounts: {
|
|
130
|
+
...(next.channels?.qqbot?.accounts || {}),
|
|
131
|
+
[accountId]: {
|
|
132
|
+
...(next.channels?.qqbot?.accounts?.[accountId] || {}),
|
|
133
|
+
enabled: true,
|
|
134
|
+
...(input.appId ? { appId: input.appId } : {}),
|
|
135
|
+
...(input.clientSecret
|
|
136
|
+
? { clientSecret: input.clientSecret }
|
|
137
|
+
: input.clientSecretFile
|
|
138
|
+
? { clientSecretFile: input.clientSecretFile }
|
|
139
|
+
: {}),
|
|
140
|
+
...(input.name ? { name: input.name } : {}),
|
|
141
|
+
...(input.imageServerBaseUrl ? { imageServerBaseUrl: input.imageServerBaseUrl } : {}),
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return next;
|
|
148
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ResolvedQQBotAccount } from "./types.js";
|
|
2
|
+
export interface GatewayContext {
|
|
3
|
+
account: ResolvedQQBotAccount;
|
|
4
|
+
abortSignal: AbortSignal;
|
|
5
|
+
cfg: unknown;
|
|
6
|
+
onReady?: (data: unknown) => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
log?: {
|
|
9
|
+
info: (msg: string) => void;
|
|
10
|
+
error: (msg: string) => void;
|
|
11
|
+
debug?: (msg: string) => void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 启动 Gateway WebSocket 连接(带自动重连)
|
|
16
|
+
*/
|
|
17
|
+
export declare function startGateway(ctx: GatewayContext): Promise<void>;
|