@tencent-connect/openclaw-qqbot 1.5.7 → 1.6.0-alpha.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.
Files changed (63) hide show
  1. package/README.md +9 -2
  2. package/README.zh.md +7 -2
  3. package/package.json +1 -1
  4. package/scripts/upgrade-via-npm.sh +85 -115
  5. package/scripts/upgrade-via-source.sh +203 -35
  6. package/skills/qqbot-cron/SKILL.md +46 -423
  7. package/skills/qqbot-media/SKILL.md +29 -182
  8. package/src/api.ts +16 -5
  9. package/src/channel.ts +6 -7
  10. package/src/gateway.ts +510 -525
  11. package/src/image-server.ts +72 -10
  12. package/src/openclaw-plugin-sdk.d.ts +1 -1
  13. package/src/outbound.ts +571 -611
  14. package/src/ref-index-store.ts +1 -1
  15. package/src/slash-commands.ts +425 -0
  16. package/src/types.ts +18 -1
  17. package/src/update-checker.ts +102 -0
  18. package/src/user-messages.ts +73 -0
  19. package/src/utils/audio-convert.ts +69 -4
  20. package/src/utils/media-tags.ts +46 -4
  21. package/dist/AI/345/210/233/346/226/260/345/272/224/347/224/250/345/245/226_/347/224/263/346/212/245/344/271/246.md +0 -211
  22. package/dist/index.d.ts +0 -17
  23. package/dist/index.js +0 -22
  24. package/dist/src/api.d.ts +0 -138
  25. package/dist/src/api.js +0 -525
  26. package/dist/src/channel.d.ts +0 -3
  27. package/dist/src/channel.js +0 -337
  28. package/dist/src/config.d.ts +0 -25
  29. package/dist/src/config.js +0 -161
  30. package/dist/src/gateway.d.ts +0 -18
  31. package/dist/src/gateway.js +0 -2468
  32. package/dist/src/image-server.d.ts +0 -62
  33. package/dist/src/image-server.js +0 -401
  34. package/dist/src/known-users.d.ts +0 -100
  35. package/dist/src/known-users.js +0 -263
  36. package/dist/src/onboarding.d.ts +0 -10
  37. package/dist/src/onboarding.js +0 -203
  38. package/dist/src/outbound.d.ts +0 -150
  39. package/dist/src/outbound.js +0 -1175
  40. package/dist/src/proactive.d.ts +0 -170
  41. package/dist/src/proactive.js +0 -399
  42. package/dist/src/runtime.d.ts +0 -3
  43. package/dist/src/runtime.js +0 -10
  44. package/dist/src/session-store.d.ts +0 -52
  45. package/dist/src/session-store.js +0 -254
  46. package/dist/src/slash-commands.d.ts +0 -48
  47. package/dist/src/slash-commands.js +0 -212
  48. package/dist/src/types.d.ts +0 -146
  49. package/dist/src/types.js +0 -1
  50. package/dist/src/utils/audio-convert.d.ts +0 -73
  51. package/dist/src/utils/audio-convert.js +0 -645
  52. package/dist/src/utils/file-utils.d.ts +0 -46
  53. package/dist/src/utils/file-utils.js +0 -107
  54. package/dist/src/utils/image-size.d.ts +0 -51
  55. package/dist/src/utils/image-size.js +0 -234
  56. package/dist/src/utils/media-tags.d.ts +0 -14
  57. package/dist/src/utils/media-tags.js +0 -120
  58. package/dist/src/utils/payload.d.ts +0 -112
  59. package/dist/src/utils/payload.js +0 -186
  60. package/dist/src/utils/platform.d.ts +0 -126
  61. package/dist/src/utils/platform.js +0 -358
  62. package/dist/src/utils/upload-cache.d.ts +0 -34
  63. package/dist/src/utils/upload-cache.js +0 -93
@@ -1,93 +0,0 @@
1
- /**
2
- * file_info 缓存 — 借鉴 Telegram file_id 机制
3
- *
4
- * QQ Bot API 上传文件后返回 file_info + ttl,在 TTL 内相同文件可直接复用 file_info
5
- * 避免重复上传同一文件,节省带宽和时间。
6
- *
7
- * 缓存 key = md5(fileContent) + targetType(c2c/group) + targetId + fileType
8
- */
9
- import * as crypto from "node:crypto";
10
- // 内存缓存,key 格式:`${contentHash}:${scope}:${targetId}:${fileType}`
11
- const cache = new Map();
12
- // 最大缓存条目数,防止内存泄漏
13
- const MAX_CACHE_SIZE = 500;
14
- /**
15
- * 计算文件内容的 MD5 hash(用于缓存 key)
16
- * 对于 Base64 数据直接 hash,对于文件路径读取后 hash
17
- */
18
- export function computeFileHash(data) {
19
- const content = typeof data === "string" ? data : data;
20
- return crypto.createHash("md5").update(content).digest("hex");
21
- }
22
- /**
23
- * 构建缓存 key
24
- * @param contentHash - 文件内容 hash
25
- * @param scope - "c2c" | "group"
26
- * @param targetId - 用户 openid 或群 openid
27
- * @param fileType - 1=IMAGE, 2=VIDEO, 3=VOICE, 4=FILE
28
- */
29
- function buildCacheKey(contentHash, scope, targetId, fileType) {
30
- return `${contentHash}:${scope}:${targetId}:${fileType}`;
31
- }
32
- /**
33
- * 从缓存获取 file_info
34
- * @returns file_info 字符串,未命中或已过期返回 null
35
- */
36
- export function getCachedFileInfo(contentHash, scope, targetId, fileType) {
37
- const key = buildCacheKey(contentHash, scope, targetId, fileType);
38
- const entry = cache.get(key);
39
- if (!entry)
40
- return null;
41
- // 检查是否过期
42
- if (Date.now() >= entry.expiresAt) {
43
- cache.delete(key);
44
- return null;
45
- }
46
- console.log(`[upload-cache] Cache HIT: key=${key.slice(0, 40)}..., fileUuid=${entry.fileUuid}`);
47
- return entry.fileInfo;
48
- }
49
- /**
50
- * 将上传结果写入缓存
51
- * @param ttl - API 返回的 TTL(秒),缓存会提前 60 秒失效
52
- */
53
- export function setCachedFileInfo(contentHash, scope, targetId, fileType, fileInfo, fileUuid, ttl) {
54
- // 清理过期条目(惰性清理)
55
- if (cache.size >= MAX_CACHE_SIZE) {
56
- const now = Date.now();
57
- for (const [k, v] of cache) {
58
- if (now >= v.expiresAt) {
59
- cache.delete(k);
60
- }
61
- }
62
- // 如果清理后仍然超限,删除最早的一半
63
- if (cache.size >= MAX_CACHE_SIZE) {
64
- const keys = Array.from(cache.keys());
65
- for (let i = 0; i < keys.length / 2; i++) {
66
- cache.delete(keys[i]);
67
- }
68
- }
69
- }
70
- const key = buildCacheKey(contentHash, scope, targetId, fileType);
71
- // 提前 60 秒失效,避免临界点过期
72
- const safetyMargin = 60;
73
- const effectiveTtl = Math.max(ttl - safetyMargin, 10);
74
- cache.set(key, {
75
- fileInfo,
76
- fileUuid,
77
- expiresAt: Date.now() + effectiveTtl * 1000,
78
- });
79
- console.log(`[upload-cache] Cache SET: key=${key.slice(0, 40)}..., ttl=${effectiveTtl}s, uuid=${fileUuid}`);
80
- }
81
- /**
82
- * 获取缓存统计
83
- */
84
- export function getUploadCacheStats() {
85
- return { size: cache.size, maxSize: MAX_CACHE_SIZE };
86
- }
87
- /**
88
- * 清除所有缓存
89
- */
90
- export function clearUploadCache() {
91
- cache.clear();
92
- console.log(`[upload-cache] Cache cleared`);
93
- }