claw-subagent-service 0.0.98 → 0.0.99
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
|
@@ -56,9 +56,9 @@ class MessageHandler {
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const allowedTypes = ['RC:TxtMsg'];
|
|
59
|
+
const allowedTypes = ['RC:TxtMsg', 'RC:ImgMsg', 'RC:SightMsg', 'RC:FileMsg', 'RC:HQVCMsg'];
|
|
60
60
|
if (!allowedTypes.includes(msg.messageType)) {
|
|
61
|
-
this.log?.info(`[MessageHandler]
|
|
61
|
+
this.log?.info(`[MessageHandler] 忽略不支持的消息类型: ${msg.messageType}`);
|
|
62
62
|
return false;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -253,6 +253,10 @@ class MessageHandler {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
getMessageType(msg) {
|
|
256
|
+
// 如果是媒体消息,直接返回 NORMAL 类型
|
|
257
|
+
if (['RC:ImgMsg', 'RC:SightMsg', 'RC:FileMsg', 'RC:HQVCMsg'].includes(msg.messageType)) {
|
|
258
|
+
return MessageType.NORMAL;
|
|
259
|
+
}
|
|
256
260
|
const text = typeof msg.content === 'string' ? msg.content : (msg.content?.content || '');
|
|
257
261
|
if (text.startsWith('/')) {
|
|
258
262
|
return MessageType.COMMAND;
|
|
@@ -324,7 +328,7 @@ class MessageHandler {
|
|
|
324
328
|
|
|
325
329
|
try {
|
|
326
330
|
// 确保传入的内容是字符串(claw 类型消息 content 可能是对象)
|
|
327
|
-
const chatContent =
|
|
331
|
+
const chatContent = this._extractMessageContent(msg);
|
|
328
332
|
this.log?.info(`[MessageHandler] 调用 chatStream, content_type=${typeof msg.content}, chatContent=${chatContent.substring(0, 50)}`);
|
|
329
333
|
await this.openclawClient.chatStream(
|
|
330
334
|
chatContent,
|
|
@@ -486,6 +490,51 @@ class MessageHandler {
|
|
|
486
490
|
await this._streamQueue;
|
|
487
491
|
}
|
|
488
492
|
|
|
493
|
+
/**
|
|
494
|
+
* 提取消息内容,支持文本、图片、视频、文件、语音
|
|
495
|
+
*/
|
|
496
|
+
_extractMessageContent(msg) {
|
|
497
|
+
const msgType = msg.messageType;
|
|
498
|
+
const content = msg.content;
|
|
499
|
+
|
|
500
|
+
// 文本消息
|
|
501
|
+
if (msgType === 'RC:TxtMsg') {
|
|
502
|
+
return typeof content === 'string' ? content : (content?.content || JSON.stringify(content));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// 图片消息
|
|
506
|
+
if (msgType === 'RC:ImgMsg') {
|
|
507
|
+
const imageUri = content?.imageUri || '';
|
|
508
|
+
return `[图片] ${imageUri}`;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// 视频消息
|
|
512
|
+
if (msgType === 'RC:SightMsg') {
|
|
513
|
+
const sightUrl = content?.sightUrl || '';
|
|
514
|
+
const name = content?.name || '未知视频';
|
|
515
|
+
const duration = content?.duration || 0;
|
|
516
|
+
return `[视频] ${sightUrl} ${name} ${duration}秒`;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// 文件消息
|
|
520
|
+
if (msgType === 'RC:FileMsg') {
|
|
521
|
+
const fileUrl = content?.fileUrl || '';
|
|
522
|
+
const name = content?.name || '未知文件';
|
|
523
|
+
const size = content?.size || 0;
|
|
524
|
+
return `[文件] ${fileUrl} ${name} ${size}`;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// 语音消息
|
|
528
|
+
if (msgType === 'RC:HQVCMsg') {
|
|
529
|
+
const remoteUrl = content?.remoteUrl || '';
|
|
530
|
+
const duration = content?.duration || 0;
|
|
531
|
+
return `[语音] ${remoteUrl} ${duration}秒`;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// 兜底
|
|
535
|
+
return typeof content === 'string' ? content : JSON.stringify(content);
|
|
536
|
+
}
|
|
537
|
+
|
|
489
538
|
parseCommand(raw, senderId) {
|
|
490
539
|
const trimmed = raw.slice(1).trim();
|
|
491
540
|
const parts = trimmed.split(/\s+/);
|