Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: xiaoyi channel 调整用户上传文件字段

ray_le9833b918e3ee
diff --git a/jiuwenclaw/channel/xiaoyi_channel.py b/jiuwenclaw/channel/xiaoyi_channel.py
index 53745818cd..83f5de402e 100644
--- a/jiuwenclaw/channel/xiaoyi_channel.py
+++ b/jiuwenclaw/channel/xiaoyi_channel.py
@@ -10,16 +10,12 @@ import hmac
import hashlib
import inspect
import json
-import os
-import re
import time
import ssl
from dataclasses import dataclass
from typing import Any, Callable
from urllib.parse import urlparse
-import aiohttp
-
from jiuwenclaw.utils import logger
from jiuwenclaw.channel.base import BaseChannel, ChannelMetadata, RobotMessageRouter
from jiuwenclaw.schema.message import EventType, Message, ReqMethod
@@ -83,7 +79,6 @@ class XiaoyiChannel(BaseChannel):
self._connect_tasks: dict[str, asyncio.Task] = {} # Connection tasks for each channel
self._session_task_map: dict[str, str] = {}
self._session_heartbeat_tasks: dict[str, asyncio.Task] = {} # Response heartbeat tasks for each session
- self._artifact_map: dict[str, str] = {}
self._stream_text_buffers: dict[str, str] = {}
self._task_keepalive_tasks: dict[str, asyncio.Task] = {}
self._task_last_activity: dict[str, float] = {}
@@ -425,7 +420,6 @@ class XiaoyiChannel(BaseChannel):
# ==================== PROCESS PARTS (TEXT & FILES) ====================
text = ""
- files = []
file_attachments: list[str] = []
media_files: list[dict[str, Any]] = []
@@ -513,7 +507,6 @@ class XiaoyiChannel(BaseChannel):
params = {"query": text, "task_id": task_id}
if media_payload:
params.update(media_payload)
- params["query"] += f"\n用户上传的文件路径为:{','.join(media_payload.get('MediaPaths', []))}"
user_message = Message(
id=message.get("id", ""),
@@ -597,11 +590,10 @@ class XiaoyiChannel(BaseChannel):
"",
url_key,
append=True,
- final=False,
+ is_final=False,
)
except Exception as e:
logger.warning(f"XiaoyiChannel 发送心跳消息失败 ({url_key}): {e}")
- logger.warning(f"XiaoyiChannel 发送心跳消息失败 ({url_key}): {e}")
except asyncio.CancelledError:
logger.info(f"XiaoyiChannel 会话心跳已停止: {session_id}")
except Exception as e:
@@ -765,8 +757,6 @@ class XiaoyiChannel(BaseChannel):
},
}
await self._send_agent_response(session_id, task_id, response, url_key)
- if final:
- self._artifact_map.pop(artifact_key, None)
async def _send_agent_response(self, session_id: str, task_id: str, response: dict[str, Any], url_key: str) -> None:
"""发送 agent_response 包装的消息(A2A 格式)到指定通道."""
@@ -782,6 +772,18 @@ class XiaoyiChannel(BaseChannel):
except Exception as e:
logger.warning(f"XiaoyiChannel 发送响应失败 ({url_key}): {e}")
+ async def _safe_ws_send(self, url_key: str, payload: dict[str, Any]) -> None:
+ ws = self._ws_connections.get(url_key)
+ if not ws:
+ raise RuntimeError(f"ws connection not available: {url_key}")
+ lock = self._send_locks.get(url_key)
+ if lock is None:
+ lock = asyncio.Lock()
+ self._send_locks[url_key] = lock
+ data = json.dumps(payload, ensure_ascii=False)
+ async with lock:
+ await ws.send(data)
+
def _clear_task_timeout(self, session_id: str) -> None:
"""清除任务超时任务."""
if session_id in self._task_timeout_tasks:
diff --git a/jiuwenclaw/channel/xiaoyi_utils/media.py b/jiuwenclaw/channel/xiaoyi_utils/media.py
index 269443eb96..4aeddf6110 100644
--- a/jiuwenclaw/channel/xiaoyi_utils/media.py
+++ b/jiuwenclaw/channel/xiaoyi_utils/media.py
@@ -12,10 +12,9 @@ from typing import Any
import aiohttp
-from jiuwenclaw.utils import logger, get_workspace_dir
+from jiuwenclaw.utils import logger, get_xy_tmp_dir
-_WORKSPACE = get_workspace_dir()
-_TMP_MEDIA_PATH = _WORKSPACE / "xiaoyi_channel"
+_TMP_MEDIA_PATH = get_xy_tmp_dir()
# ==================== Configuration ====================
@@ -264,19 +263,8 @@ def build_xiaoyi_media_payload(media_list: list[DownloadedMedia]) -> dict[str, A
if not media_list:
return {}
- first = media_list[0]
- media_paths = [str(media.path) for media in media_list]
- media_types = [media.content_type for media in media_list if media.content_type]
-
- result: dict[str, Any] = {}
-
- if len(media_paths) > 0:
- result["MediaPaths"] = media_paths
-
- if len(media_types) > 0:
- result["MediaTypes"] = media_types
-
- return result
+ files = [dict(path=str(media.path), type=media.content_type or "") for media in media_list]
+ return files
# ==================== Image Extraction ====================
diff --git a/jiuwenclaw/utils.py b/jiuwenclaw/utils.py
index 6c1e6f682d..fbc78c1766 100644
--- a/jiuwenclaw/utils.py
+++ b/jiuwenclaw/utils.py
@@ -322,6 +322,12 @@ def get_logs_dir() -> Path:
return USER_WORKSPACE_DIR / ".logs"
+def get_xy_tmp_dir() -> Path:
+ xy_tmp_dir = USER_WORKSPACE_DIR / "tmp" / "xiaoyi"
+ xy_tmp_dir.mkdir(parents=True, exist_ok=True)
+ return xy_tmp_dir
+
+
def get_env_file() -> Path:
return get_config_dir() / ".env"