claw-subagent-service 0.0.110 → 0.0.111
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
|
@@ -363,10 +363,9 @@ class OpenClawClient {
|
|
|
363
363
|
const sessionId = `clawmessenger-${fromUser}`;
|
|
364
364
|
|
|
365
365
|
// 尝试多个可能的 SSE 端点,兼容不同版本 OpenClaw Gateway
|
|
366
|
-
// 注意:多模态图片必须使用 /v1/responses 端点
|
|
367
366
|
const endpoints = [
|
|
368
|
-
'http://127.0.0.1:18789/v1/
|
|
369
|
-
'http://127.0.0.1:18789/v1/
|
|
367
|
+
'http://127.0.0.1:18789/v1/chat/completions',
|
|
368
|
+
'http://127.0.0.1:18789/v1/responses'
|
|
370
369
|
];
|
|
371
370
|
|
|
372
371
|
for (let i = 0; i < endpoints.length; i++) {
|
|
@@ -394,13 +393,29 @@ class OpenClawClient {
|
|
|
394
393
|
if (err.response) {
|
|
395
394
|
this.log?.error(`[OpenClawClient] 错误状态码: ${err.response.status}`);
|
|
396
395
|
// 安全地提取错误信息
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
396
|
+
try {
|
|
397
|
+
const errorData = err.response.data;
|
|
398
|
+
if (typeof errorData === 'string') {
|
|
399
|
+
this.log?.error(`[OpenClawClient] 错误响应: ${errorData}`);
|
|
400
|
+
} else if (errorData && typeof errorData === 'object') {
|
|
401
|
+
// 检查是否是 IncomingMessage 对象(流)
|
|
402
|
+
if (errorData._readableState || errorData.socket) {
|
|
403
|
+
// 这是一个流对象,尝试读取其中的数据
|
|
404
|
+
const buffer = errorData._readableState?.buffer;
|
|
405
|
+
if (buffer && buffer.length > 0) {
|
|
406
|
+
const dataStr = buffer[0].toString('utf8');
|
|
407
|
+
this.log?.error(`[OpenClawClient] 错误响应(流): ${dataStr}`);
|
|
408
|
+
} else {
|
|
409
|
+
this.log?.error(`[OpenClawClient] 错误响应(流对象,无法读取)`);
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
// 提取常见错误字段
|
|
413
|
+
const errorMsg = errorData.error?.message || errorData.message || errorData.error || JSON.stringify(errorData);
|
|
414
|
+
this.log?.error(`[OpenClawClient] 错误响应: ${errorMsg}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} catch (e) {
|
|
418
|
+
this.log?.error(`[OpenClawClient] 无法解析错误响应: ${e.message}`);
|
|
404
419
|
}
|
|
405
420
|
}
|
|
406
421
|
}
|
|
@@ -462,61 +477,27 @@ class OpenClawClient {
|
|
|
462
477
|
// 下载图片并转换为 base64
|
|
463
478
|
const imageData = await this._downloadImageAsBase64(imageUrl);
|
|
464
479
|
|
|
465
|
-
|
|
466
|
-
// /v1/responses 端点格式(推荐,支持多模态)
|
|
467
|
-
payload = {
|
|
468
|
-
model: 'openclaw',
|
|
469
|
-
input: [
|
|
470
|
-
{ type: 'input_text', text: textContent || '描述这张图片' },
|
|
471
|
-
{
|
|
472
|
-
type: 'input_image',
|
|
473
|
-
source: {
|
|
474
|
-
type: 'base64',
|
|
475
|
-
media_type: imageData.mediaType,
|
|
476
|
-
data: imageData.base64 // 纯 base64,不带 data URI 前缀
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
],
|
|
480
|
-
stream: true,
|
|
481
|
-
max_tokens: 2048
|
|
482
|
-
};
|
|
483
|
-
} else {
|
|
484
|
-
// /v1/chat/completions 端点格式(兼容旧版)
|
|
485
|
-
payload = {
|
|
486
|
-
model: 'openclaw',
|
|
487
|
-
messages: [{
|
|
488
|
-
role: 'user',
|
|
489
|
-
content: [
|
|
490
|
-
{ type: 'text', text: textContent || '描述这张图片' },
|
|
491
|
-
{ type: 'image_url', image_url: { url: `data:${imageData.mediaType};base64,${imageData.base64}` } }
|
|
492
|
-
]
|
|
493
|
-
}],
|
|
494
|
-
stream: true,
|
|
495
|
-
max_tokens: 2048
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
} catch (err) {
|
|
499
|
-
this.log?.warn(`[OpenClawClient] 图片处理失败,回退到文本模式: ${err.message}`);
|
|
500
|
-
// 回退到纯文本模式
|
|
480
|
+
// 统一使用 messages 格式(OpenAI 兼容标准)
|
|
501
481
|
payload = {
|
|
502
482
|
model: 'openclaw',
|
|
503
|
-
messages: [{
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
],
|
|
483
|
+
messages: [{
|
|
484
|
+
role: 'user',
|
|
485
|
+
content: [
|
|
486
|
+
{ type: 'text', text: textContent || '描述这张图片' },
|
|
487
|
+
{
|
|
488
|
+
type: 'image_url',
|
|
489
|
+
image_url: {
|
|
490
|
+
url: `data:${imageData.mediaType};base64,${imageData.base64}`
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
}],
|
|
516
495
|
stream: true,
|
|
517
496
|
max_tokens: 2048
|
|
518
497
|
};
|
|
519
|
-
}
|
|
498
|
+
} catch (err) {
|
|
499
|
+
this.log?.warn(`[OpenClawClient] 图片处理失败,回退到文本模式: ${err.message}`);
|
|
500
|
+
// 回退到纯文本模式
|
|
520
501
|
payload = {
|
|
521
502
|
model: 'openclaw',
|
|
522
503
|
messages: [{ role: 'user', content: message }],
|
|
@@ -524,6 +505,14 @@ class OpenClawClient {
|
|
|
524
505
|
max_tokens: 2048
|
|
525
506
|
};
|
|
526
507
|
}
|
|
508
|
+
} else {
|
|
509
|
+
// 纯文本格式 - 统一使用 messages 格式
|
|
510
|
+
payload = {
|
|
511
|
+
model: 'openclaw',
|
|
512
|
+
messages: [{ role: 'user', content: message }],
|
|
513
|
+
stream: true,
|
|
514
|
+
max_tokens: 2048
|
|
515
|
+
};
|
|
527
516
|
}
|
|
528
517
|
|
|
529
518
|
this.log?.info(`[OpenClawClient] SSE 请求 payload: ${JSON.stringify(payload)}`);
|