fix(tools): fix OpenClaw connection test and multimodal format compatibility

- Use safe .get() for server URL to avoid KeyError
- Support both api_key and token in connection test auth
- Add OpenAI/Volcano image format (image_url) support
- Add aiohttp import in _test_openclaw_connection
This commit is contained in:
miao
2026-04-07 13:58:38 +08:00
parent e298b38de9
commit 562ca6c1f1
3 changed files with 14 additions and 5 deletions

View File

@@ -220,7 +220,9 @@ class CustomTool(BaseTool):
image_url = None
if self._uploaded_files:
for f in self._uploaded_files:
if f.get("type") == "image":
f_type = f.get("type", "")
if f_type == "image":
# Bedrock/Anthropic 格式:{"type": "image", "source": {"type": "base64", ...}}
source = f.get("source", {})
if source.get("type") == "base64":
media_type = source.get("media_type", "image/jpeg")
@@ -232,7 +234,11 @@ class CustomTool(BaseTool):
elif f.get("url"):
# 其他格式:{"type": "image", "url": "https://..."}
image_url = f.get("url")
break # 只取第一张图片
break
elif f_type == "image_url":
# OpenAI/Volcano 格式:{"type": "image_url", "image_url": {"url": "..."}}
image_url = f.get("image_url", {}).get("url", "")
break
# 如果 image_url 是服务器中转 URL直接下载图片转 base64
# 避免 OSS 签名 URL 在重定向解析过程中被破坏