claw-subagent-service 0.0.106 → 0.0.108
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
|
@@ -392,10 +392,14 @@ class OpenClawClient {
|
|
|
392
392
|
// 打印详细错误响应
|
|
393
393
|
if (err.response) {
|
|
394
394
|
this.log?.error(`[OpenClawClient] 错误状态码: ${err.response.status}`);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
this.log?.error(`[OpenClawClient]
|
|
395
|
+
// 安全地提取错误信息
|
|
396
|
+
const errorData = err.response.data;
|
|
397
|
+
if (typeof errorData === 'string') {
|
|
398
|
+
this.log?.error(`[OpenClawClient] 错误响应: ${errorData}`);
|
|
399
|
+
} else if (errorData && typeof errorData === 'object') {
|
|
400
|
+
// 提取常见错误字段
|
|
401
|
+
const errorMsg = errorData.error?.message || errorData.message || errorData.error || JSON.stringify(errorData);
|
|
402
|
+
this.log?.error(`[OpenClawClient] 错误响应: ${errorMsg}`);
|
|
399
403
|
}
|
|
400
404
|
}
|
|
401
405
|
}
|
|
@@ -405,6 +409,29 @@ class OpenClawClient {
|
|
|
405
409
|
}
|
|
406
410
|
}
|
|
407
411
|
|
|
412
|
+
async _downloadImageAsBase64(imageUrl) {
|
|
413
|
+
try {
|
|
414
|
+
this.log?.info(`[OpenClawClient] 下载图片: ${imageUrl}`);
|
|
415
|
+
const response = await axios.get(imageUrl, {
|
|
416
|
+
responseType: 'arraybuffer',
|
|
417
|
+
timeout: 30000,
|
|
418
|
+
maxContentLength: 10 * 1024 * 1024 // 10MB
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const buffer = Buffer.from(response.data);
|
|
422
|
+
const base64 = buffer.toString('base64');
|
|
423
|
+
|
|
424
|
+
// 检测 MIME 类型
|
|
425
|
+
const contentType = response.headers['content-type'] || 'image/jpeg';
|
|
426
|
+
this.log?.info(`[OpenClawClient] 图片下载完成: ${imageUrl}, size=${buffer.length}, type=${contentType}`);
|
|
427
|
+
|
|
428
|
+
return `data:${contentType};base64,${base64}`;
|
|
429
|
+
} catch (err) {
|
|
430
|
+
this.log?.error(`[OpenClawClient] 图片下载失败: ${imageUrl}, ${err.message}`);
|
|
431
|
+
throw err;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
408
435
|
async _doChatStream(apiUrl, gatewayToken, sessionId, message, onDelta, onDone) {
|
|
409
436
|
const headers = {
|
|
410
437
|
'Content-Type': 'application/json',
|
|
@@ -423,13 +450,22 @@ class OpenClawClient {
|
|
|
423
450
|
const imageUrl = imageUrlMatch[1];
|
|
424
451
|
const textContent = message.replace(/\[图片\]\s*https?:\/\/[^\s]+/, '').trim();
|
|
425
452
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
453
|
+
try {
|
|
454
|
+
// 下载图片并转换为 base64
|
|
455
|
+
const base64Image = await this._downloadImageAsBase64(imageUrl);
|
|
456
|
+
|
|
457
|
+
messages = [{
|
|
458
|
+
role: 'user',
|
|
459
|
+
content: [
|
|
460
|
+
{ type: 'text', text: textContent || '描述这张图片' },
|
|
461
|
+
{ type: 'image_url', image_url: { url: base64Image } }
|
|
462
|
+
]
|
|
463
|
+
}];
|
|
464
|
+
} catch (err) {
|
|
465
|
+
this.log?.warn(`[OpenClawClient] 图片处理失败,回退到文本模式: ${err.message}`);
|
|
466
|
+
// 回退到纯文本模式
|
|
467
|
+
messages = [{ role: 'user', content: message }];
|
|
468
|
+
}
|
|
433
469
|
} else {
|
|
434
470
|
// 纯文本格式
|
|
435
471
|
messages = [{ role: 'user', content: message }];
|