@53ai/53ai-openclaw 1.0.8 → 1.1.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.
@@ -14,6 +14,12 @@ export declare const WS_RECONNECT_BASE_DELAY_MS = 1000;
14
14
  export declare const TEXT_CHUNK_LIMIT = 4000;
15
15
  /** 消息处理超时(毫秒) */
16
16
  export declare const MESSAGE_PROCESS_TIMEOUT_MS = 120000;
17
+ /**
18
+ * 消息缓存 TTL(毫秒)
19
+ * 设为 35 分钟,确保覆盖最大重连时间(约 28.5 分钟)+ 缓冲
20
+ * @see WS_MAX_RECONNECT_ATTEMPTS - 60 次,指数退避最大 30s
21
+ */
22
+ export declare const MESSAGE_CACHE_TTL_MS: number;
17
23
  /** 默认媒体大小上限(MB) */
18
24
  export declare const DEFAULT_MEDIA_MAX_MB = 20;
19
25
  /** 图片下载超时(毫秒) */
@@ -0,0 +1,119 @@
1
+ import type { RuntimeEnv } from "openclaw/plugin-sdk";
2
+ import type { WebSocket } from "ws";
3
+ /**
4
+ * 缓存的消息条目
5
+ */
6
+ interface CachedMessage {
7
+ /** 缓存唯一 key */
8
+ cacheKey: string;
9
+ /** 消息 ID */
10
+ reqId: string;
11
+ /** 目标聊天 ID */
12
+ toChatId: string;
13
+ /** 消息内容 */
14
+ text: string;
15
+ /** 是否为最终消息 */
16
+ finish: boolean;
17
+ /** 是否为错误消息 */
18
+ isError?: boolean;
19
+ /** 错误码 */
20
+ errorCode?: string;
21
+ /** 错误详情 */
22
+ errorDetails?: string;
23
+ /** 是否为思考消息 */
24
+ isThinking?: boolean;
25
+ /** 创建时间戳 */
26
+ createdAt: number;
27
+ /** 重试次数 */
28
+ retryCount: number;
29
+ }
30
+ /**
31
+ * 消息缓存配置
32
+ */
33
+ interface MessageCacheConfig {
34
+ maxEntries: number;
35
+ ttlMs: number;
36
+ maxRetries: number;
37
+ }
38
+ /**
39
+ * 按 accountId 隔离的消息缓存管理器
40
+ */
41
+ declare class MessageCache {
42
+ private cache;
43
+ private config;
44
+ private accountId;
45
+ private runtime;
46
+ constructor(accountId: string, config?: Partial<MessageCacheConfig>, runtime?: RuntimeEnv);
47
+ /**
48
+ * 生成唯一缓存 key
49
+ */
50
+ private generateCacheKey;
51
+ /**
52
+ * 添加消息到缓存,返回缓存 key
53
+ */
54
+ add(params: {
55
+ reqId: string;
56
+ toChatId: string;
57
+ text: string;
58
+ finish: boolean;
59
+ isError?: boolean;
60
+ errorCode?: string;
61
+ errorDetails?: string;
62
+ isThinking?: boolean;
63
+ }): string;
64
+ /**
65
+ * 获取所有待重试的消息,返回 cacheKey + entry
66
+ */
67
+ getPendingMessages(): CachedMessage[];
68
+ /**
69
+ * 按 cacheKey 标记消息为已发送
70
+ */
71
+ markSent(cacheKey: string): void;
72
+ /**
73
+ * 按 cacheKey 增加重试计数
74
+ */
75
+ incrementRetry(cacheKey: string): void;
76
+ /**
77
+ * 清理过期条目
78
+ */
79
+ private prune;
80
+ size(): number;
81
+ clear(): void;
82
+ }
83
+ /**
84
+ * 获取或创建按账号隔离的缓存实例
85
+ */
86
+ export declare function getMessageCache(accountId: string, runtime?: RuntimeEnv): MessageCache;
87
+ /**
88
+ * 清理指定账号的缓存
89
+ */
90
+ export declare function clearAccountCache(accountId: string): void;
91
+ /**
92
+ * 发送消息参数(与 sendReply 兼容)
93
+ */
94
+ export interface CachedSendParams {
95
+ wsClient: WebSocket;
96
+ text: string;
97
+ toChatId: string;
98
+ replyToMsgId?: string;
99
+ runtime: RuntimeEnv;
100
+ finish: boolean;
101
+ streamId: string;
102
+ isError?: boolean;
103
+ errorCode?: string;
104
+ errorDetails?: string;
105
+ isThinking?: boolean;
106
+ }
107
+ /**
108
+ * 缓存感知的消息发送器
109
+ * 返回 [success, cacheKey?] - 成功时 cacheKey 为 undefined,失败时返回缓存 key
110
+ */
111
+ export declare function sendWithCache(accountId: string, params: CachedSendParams, sendFn: (params: CachedSendParams) => Promise<void>): Promise<{
112
+ success: boolean;
113
+ cacheKey?: string;
114
+ }>;
115
+ /**
116
+ * 重放缓存的消息
117
+ */
118
+ export declare function replayCachedMessages(accountId: string, wsClient: WebSocket, runtime: RuntimeEnv, sendFn: (params: CachedSendParams) => Promise<void>): Promise<number>;
119
+ export {};
@@ -13,5 +13,5 @@ export declare function setLastMsgIdForChat(chatId: string, msgId: string, accou
13
13
  export declare function getLastMsgIdForChat(chatId: string, accountId?: string): string | undefined;
14
14
  export declare function warmupReqIdStore(accountId?: string, log?: (msg: string) => void): Promise<number>;
15
15
  export declare function flushReqIdStore(accountId?: string): Promise<void>;
16
- export declare function cleanupAccount(accountId: string): Promise<void>;
16
+ export declare function cleanupAccount(accountId: string, clearCache?: boolean): Promise<void>;
17
17
  export declare function cleanupAll(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@53ai/53ai-openclaw",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -41,7 +41,7 @@
41
41
  "bugs": {
42
42
  "url": "https://github.com/53AI/53ai-openclaw/issues"
43
43
  },
44
- "homepage": "https://github.com/53AI/53ai-openclaw#readme",
44
+ "homepage": "https://www.53ai.com",
45
45
  "dependencies": {
46
46
  "ws": "^8.16.0"
47
47
  },