claw-subagent-service 0.0.79 → 0.0.80

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -174,11 +174,22 @@ class RongyunMessageSender {
174
174
  timestamp: Math.floor(Date.now() / 1000),
175
175
  };
176
176
 
177
- const result = await this.rongcloudClient.sendMessage(
178
- targetId,
179
- JSON.stringify(messagePayload),
180
- 1 // PRIVATE
181
- );
177
+ // 优先使用自定义消息类型发送 P2P 消息
178
+ let result;
179
+ if (this.rongcloudClient.SystemServiceMessage) {
180
+ result = await this.rongcloudClient.sendCustomMessage(
181
+ targetId,
182
+ messagePayload,
183
+ 1 // PRIVATE
184
+ );
185
+ } else {
186
+ // 回退到文本消息(兼容旧版本)
187
+ result = await this.rongcloudClient.sendMessage(
188
+ targetId,
189
+ JSON.stringify(messagePayload),
190
+ 1 // PRIVATE
191
+ );
192
+ }
182
193
 
183
194
  return result;
184
195
  } catch (err) {
@@ -39,6 +39,18 @@ class RongCloudClient {
39
39
  this.log?.info('[RongCloudClient] 初始化 SDK...');
40
40
  RongIMLib.init({ appkey: this.config.appKey });
41
41
 
42
+ // 注册 system_service 自定义消息类型(与前端对齐)
43
+ try {
44
+ if (typeof RongIMLib.registerMessageType === 'function') {
45
+ this.SystemServiceMessage = RongIMLib.registerMessageType('system_service', true, false);
46
+ this.log?.info('[RongCloudClient] system_service 自定义消息类型已注册');
47
+ } else {
48
+ this.log?.warn('[RongCloudClient] SDK 不支持 registerMessageType');
49
+ }
50
+ } catch (err) {
51
+ this.log?.warn(`[RongCloudClient] 注册 system_service 消息类型失败: ${err.message}`);
52
+ }
53
+
42
54
  this.log?.info(`[RongCloudClient] SDK Events: ${JSON.stringify(Object.keys(RongIMLib.Events || {}))}`);
43
55
  this.log?.info(`[RongCloudClient] has addEventListener: ${typeof RongIMLib.addEventListener === 'function'}`);
44
56
  this.log?.info(`[RongCloudClient] has sendReadReceiptMessage: ${typeof RongIMLib.sendReadReceiptMessage === 'function'}`);
@@ -257,6 +269,50 @@ class RongCloudClient {
257
269
  }
258
270
  }
259
271
 
272
+ async sendCustomMessage(targetId, content, conversationType, customType = 'system_service') {
273
+ if (!this.isConnected) {
274
+ this.log?.error('[RongCloudClient] 未连接,无法发送自定义消息');
275
+ return false;
276
+ }
277
+
278
+ if (!this.SystemServiceMessage) {
279
+ this.log?.error('[RongCloudClient] system_service 消息类型未注册');
280
+ return false;
281
+ }
282
+
283
+ try {
284
+ const convType = conversationType === ConversationType.GROUP
285
+ ? (RongIMLib.ConversationType?.GROUP || ConversationType.GROUP)
286
+ : (RongIMLib.ConversationType?.PRIVATE || ConversationType.PRIVATE);
287
+
288
+ const messageContent = typeof content === 'string' ? JSON.parse(content) : content;
289
+ const customMsg = new this.SystemServiceMessage(messageContent);
290
+
291
+ const result = await RongIMLib.sendMessage(
292
+ { conversationType: convType, targetId },
293
+ customMsg
294
+ );
295
+
296
+ if (result.code === 0 || result.code === 200) {
297
+ const sentUId = result.data?.messageUId;
298
+ if (sentUId) {
299
+ this.sentMessageUIds.add(sentUId);
300
+ if (this.sentMessageUIds.size > this.sentMessageDedupMaxSize) {
301
+ const first = this.sentMessageUIds.values().next().value;
302
+ this.sentMessageUIds.delete(first);
303
+ }
304
+ }
305
+ return true;
306
+ } else {
307
+ this.log?.error(`[RongCloudClient] 自定义消息发送失败, code: ${result.code}`);
308
+ return false;
309
+ }
310
+ } catch (err) {
311
+ this.log?.error(`[RongCloudClient] 发送自定义消息异常: ${err.message}`);
312
+ return false;
313
+ }
314
+ }
315
+
260
316
  async sendReadReceipt(msg) {
261
317
  if (!this.isConnected) {
262
318
  this.log?.warn('[RongCloudClient] 未连接,无法发送已读回执');