@leoqlin/openclaw-qqbot 1.6.10 → 1.6.11

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/src/api.d.ts CHANGED
@@ -27,7 +27,9 @@ export declare class ApiError extends Error {
27
27
  /** 回包中的原始 message 字段(用于向用户展示兜底文案) */
28
28
  bizMessage?: string | undefined);
29
29
  }
30
- export declare const PLUGIN_USER_AGENT: string;
30
+ /** setQQBotRuntime 调用,将 api.runtime.version 注入到 User-Agent */
31
+ export declare function setOpenClawVersion(version: string): void;
32
+ export declare function getPluginUserAgent(): string;
31
33
  /** 出站消息元信息(结构化存储,不做预格式化) */
32
34
  export interface OutboundMeta {
33
35
  /** 消息文本内容 */
@@ -102,7 +104,7 @@ export declare const UPLOAD_PREPARE_FALLBACK_CODE = 40093002;
102
104
  export declare function getGatewayUrl(accessToken: string): Promise<string>;
103
105
  /** 回应按钮交互(INTERACTION_CREATE),避免客户端按钮持续 loading */
104
106
  export declare function acknowledgeInteraction(accessToken: string, interactionId: string, code?: 0 | 1 | 2 | 3 | 4 | 5, data?: Record<string, unknown>): Promise<void>;
105
- /** 获取插件版本号(从 package.json 读取,和 PLUGIN_USER_AGENT 同源) */
107
+ /** 获取插件版本号(从 package.json 读取,和 getPluginUserAgent() 同源) */
106
108
  export declare function getApiPluginVersion(): string;
107
109
  export interface MessageResponse {
108
110
  id: string;
package/dist/src/api.js CHANGED
@@ -41,11 +41,20 @@ export class ApiError extends Error {
41
41
  const API_BASE = "https://api.sgroup.qq.com";
42
42
  const TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken";
43
43
  // ============ Plugin User-Agent ============
44
- // 格式: QQBotPlugin/{version} (Node/{nodeVersion}; {os})
45
- // 示例: QQBotPlugin/1.6.0 (Node/22.14.0; darwin)
44
+ // 格式: QQBotPlugin/{version} (Node/{nodeVersion}; {os}; OpenClaw/{openclawVersion})
45
+ // 示例: QQBotPlugin/1.6.0 (Node/22.14.0; darwin; OpenClaw/2026.3.31)
46
46
  import { getPackageVersion } from "./utils/pkg-version.js";
47
47
  const _pluginVersion = getPackageVersion(import.meta.url);
48
- export const PLUGIN_USER_AGENT = `QQBotPlugin/${_pluginVersion} (Node/${process.versions.node}; ${os.platform()})`;
48
+ // 初始值为 "unknown",由 setQQBotRuntime 注入后更新为真实版本
49
+ let _openclawVersion = "unknown";
50
+ /** 由 setQQBotRuntime 调用,将 api.runtime.version 注入到 User-Agent */
51
+ export function setOpenClawVersion(version) {
52
+ if (version)
53
+ _openclawVersion = version;
54
+ }
55
+ export function getPluginUserAgent() {
56
+ return `QQBotPlugin/${_pluginVersion} (Node/${process.versions.node}; ${os.platform()}; OpenClaw/${_openclawVersion})`;
57
+ }
49
58
  // 运行时配置
50
59
  let currentMarkdownSupport = false;
51
60
  let onMessageSentHook = null;
@@ -117,7 +126,7 @@ export async function getAccessToken(appId, clientSecret) {
117
126
  */
118
127
  async function doFetchToken(appId, clientSecret) {
119
128
  const requestBody = { appId, clientSecret };
120
- const requestHeaders = { "Content-Type": "application/json", "User-Agent": PLUGIN_USER_AGENT };
129
+ const requestHeaders = { "Content-Type": "application/json", "User-Agent": getPluginUserAgent() };
121
130
  // 打印请求信息(隐藏敏感信息)
122
131
  log.info(`[qqbot-api:${appId}] >>> POST ${TOKEN_URL} [secret: ${clientSecret.slice(0, 6)}...len=${clientSecret.length}]`);
123
132
  let response;
@@ -215,7 +224,7 @@ export async function apiRequest(accessToken, method, path, body, timeoutMs) {
215
224
  const headers = {
216
225
  Authorization: `QQBot ${accessToken}`,
217
226
  "Content-Type": "application/json",
218
- "User-Agent": PLUGIN_USER_AGENT,
227
+ "User-Agent": getPluginUserAgent(),
219
228
  };
220
229
  const isFileUpload = path.includes("/files");
221
230
  const timeout = timeoutMs ?? (isFileUpload ? FILE_UPLOAD_TIMEOUT : DEFAULT_API_TIMEOUT);
@@ -466,7 +475,7 @@ export async function getGatewayUrl(accessToken) {
466
475
  export async function acknowledgeInteraction(accessToken, interactionId, code = 0, data) {
467
476
  await apiRequest(accessToken, "PUT", `/interactions/${interactionId}`, { code, ...(data ? { data } : {}) });
468
477
  }
469
- /** 获取插件版本号(从 package.json 读取,和 PLUGIN_USER_AGENT 同源) */
478
+ /** 获取插件版本号(从 package.json 读取,和 getPluginUserAgent() 同源) */
470
479
  export function getApiPluginVersion() {
471
480
  return _pluginVersion;
472
481
  }
@@ -2,7 +2,7 @@ import WebSocket from "ws";
2
2
  import path from "node:path";
3
3
  import fs from "node:fs";
4
4
  import { MSG_TYPE_QUOTE } from "./types.js";
5
- import { getAccessToken, getGatewayUrl, sendC2CMessage, sendChannelMessage, sendGroupMessage, clearTokenCache, initApiConfig, startBackgroundTokenRefresh, stopBackgroundTokenRefresh, sendC2CInputNotify, onMessageSent, PLUGIN_USER_AGENT, acknowledgeInteraction, getApiPluginVersion, setApiLogger } from "./api.js";
5
+ import { getAccessToken, getGatewayUrl, sendC2CMessage, sendChannelMessage, sendGroupMessage, clearTokenCache, initApiConfig, startBackgroundTokenRefresh, stopBackgroundTokenRefresh, sendC2CInputNotify, onMessageSent, getPluginUserAgent, acknowledgeInteraction, getApiPluginVersion, setApiLogger } from "./api.js";
6
6
  import { loadSession, saveSession, clearSession } from "./session-store.js";
7
7
  import { recordKnownUser, flushKnownUsers } from "./known-users.js";
8
8
  import { getQQBotRuntime } from "./runtime.js";
@@ -591,7 +591,7 @@ export async function startGateway(ctx) {
591
591
  log?.info(`[qqbot:${account.accountId}] ✅ Access token obtained successfully`);
592
592
  const gatewayUrl = await getGatewayUrl(accessToken);
593
593
  log?.info(`[qqbot:${account.accountId}] Connecting to ${gatewayUrl}`);
594
- const ws = new WebSocket(gatewayUrl, { headers: { "User-Agent": PLUGIN_USER_AGENT } });
594
+ const ws = new WebSocket(gatewayUrl, { headers: { "User-Agent": getPluginUserAgent() } });
595
595
  currentWs = ws;
596
596
  const pluginRuntime = getQQBotRuntime();
597
597
  // 群历史消息缓存:非@消息写入此 Map,被@时一次性注入上下文后清空
@@ -1,6 +1,9 @@
1
+ import { setOpenClawVersion } from "./api.js";
1
2
  let runtime = null;
2
3
  export function setQQBotRuntime(next) {
3
4
  runtime = next;
5
+ // 将框架版本注入 User-Agent(runtime 注入后才能拿到准确版本)
6
+ setOpenClawVersion(next.version);
4
7
  }
5
8
  export function getQQBotRuntime() {
6
9
  if (!runtime) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leoqlin/openclaw-qqbot",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },