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_leb8d2a3401297
diff --git a/jiuwenclaw/agentserver/interface.py b/jiuwenclaw/agentserver/interface.py
index 02adde22af..f8264942ca 100644
--- a/jiuwenclaw/agentserver/interface.py
+++ b/jiuwenclaw/agentserver/interface.py
@@ -423,6 +423,8 @@ class JiuWenClaw:
cron_controller.set_target_channel(CronTargetChannel.FEISHU)
elif channel == "wecom":
cron_controller.set_target_channel(CronTargetChannel.WECOM)
+ elif channel == "xiaoyi":
+ cron_controller.set_target_channel(CronTargetChannel.XIAOYI)
elif channel in ("web", "sess"):
cron_controller.set_target_channel(CronTargetChannel.WEB)
diff --git a/jiuwenclaw/app.py b/jiuwenclaw/app.py
index 8626a405cd..7b1f7082b8 100644
--- a/jiuwenclaw/app.py
+++ b/jiuwenclaw/app.py
@@ -1454,15 +1454,35 @@ async def _run() -> None:
if not enabled:
logger.info("[App] channels.xiaoyi.%s,XiaoyiChannel 未启用", reason)
else:
- xiaoyi_config = XiaoyiChannelConfig(
- enabled=True,
- ak=str(xiaoyi_conf.get("ak") or "").strip(),
- sk=str(xiaoyi_conf.get("sk") or "").strip(),
- agent_id=str(xiaoyi_conf.get("agent_id") or "").strip(),
- ws_url1=str(xiaoyi_conf.get("ws_url1") or "wss://116.63.174.231/openclaw/v1/ws/link").strip(),
- ws_url2=str(xiaoyi_conf.get("ws_url2") or "wss://hag.cloud.huawei.com/openclaw/v1/ws/link").strip(),
- enable_streaming=bool(xiaoyi_conf.get("enable_streaming", True)),
- )
+ if xiaoyi_conf.get("mode") == "xiaoyi_channel":
+ xiaoyi_config = XiaoyiChannelConfig(
+ enabled=True,
+ mode=str(xiaoyi_conf.get("mode") or "xiaoyi_channel").strip(),
+ ak=str(xiaoyi_conf.get("ak") or "").strip(),
+ sk=str(xiaoyi_conf.get("sk") or "").strip(),
+ api_id=str(xiaoyi_conf.get("api_id") or "").strip(),
+ push_id=str(xiaoyi_conf.get("push_id") or "").strip(),
+ push_url=str(xiaoyi_conf.get("push_url") or "").strip(),
+ agent_id=str(xiaoyi_conf.get("agent_id") or "").strip(),
+ ws_url1=str(xiaoyi_conf.get("ws_url1")).strip(),
+ ws_url2=str(xiaoyi_conf.get("ws_url2")).strip(),
+ enable_streaming=bool(xiaoyi_conf.get("enable_streaming", True)),
+ )
+ else:
+ xiaoyi_config = XiaoyiChannelConfig(
+ enabled=True,
+ mode=str(xiaoyi_conf.get("mode") or "xiaoyi_claw").strip(),
+ api_id=str(xiaoyi_conf.get("api_id") or "").strip(),
+ push_id=str(xiaoyi_conf.get("push_id") or "").strip(),
+ push_url=str(xiaoyi_conf.get("push_url") or "").strip(),
+ agent_id=str(xiaoyi_conf.get("agent_id") or "").strip(),
+ uid=str(xiaoyi_conf.get("uid") or "").strip(),
+ api_key=str(xiaoyi_conf.get("api_key") or "").strip(),
+ file_upload_url=str(xiaoyi_conf.get("file_upload_url") or "").strip(),
+ ws_url1=str(xiaoyi_conf.get("ws_url1")).strip(),
+ ws_url2=str(xiaoyi_conf.get("ws_url2")).strip(),
+ enable_streaming=bool(xiaoyi_conf.get("enable_streaming", True)),
+ )
xiaoyi_channel = XiaoyiChannel(xiaoyi_config, _DummyBus())
channel_manager.register_channel(xiaoyi_channel)
xiaoyi_task = asyncio.create_task(xiaoyi_channel.start(), name="xiaoyi")
diff --git a/jiuwenclaw/channel/xiaoyi_channel.py b/jiuwenclaw/channel/xiaoyi_channel.py
index 83f5de402e..07ae8bb3c1 100644
--- a/jiuwenclaw/channel/xiaoyi_channel.py
+++ b/jiuwenclaw/channel/xiaoyi_channel.py
@@ -19,6 +19,7 @@ from urllib.parse import urlparse
from jiuwenclaw.utils import logger
from jiuwenclaw.channel.base import BaseChannel, ChannelMetadata, RobotMessageRouter
from jiuwenclaw.schema.message import EventType, Message, ReqMethod
+from jiuwenclaw.channel.xiaoyi_utils.push import XiaoYiPushService, PushConfig
@dataclass
@@ -26,6 +27,7 @@ class XiaoyiChannelConfig:
"""小艺通道配置(客户端模式)."""
enabled: bool = False
+ mode: str = "xiaoyi_channel" # xiaoyi_channel or xiaoyi_claw
ak: str = ""
sk: str = ""
agent_id: str = ""
@@ -33,8 +35,12 @@ class XiaoyiChannelConfig:
ws_url2: str = ""
enable_streaming: bool = True
# Push notification configuration
+ uid: str = ""
+ api_key = ""
api_id: str = ""
push_id: str = ""
+ push_url: str = ""
+ file_upload_url: str = ""
# Task timeout in milliseconds (default: 1 hour)
task_timeout_ms: int = 3600000
# Session cleanup timeout in milliseconds (default: 1 hour)
@@ -51,15 +57,22 @@ def _generate_signature(sk: str, timestamp: str) -> str:
return base64.b64encode(h.digest()).decode("utf-8")
-def _generate_auth_headers(ak: str, sk: str, agent_id: str) -> dict[str, str]:
+def _generate_auth_headers(config: XiaoyiChannelConfig) -> dict[str, str]:
"""生成鉴权 Header."""
+ if config.mode == "xiaoyi_claw":
+ return {
+ "x-uid": config.uid,
+ "x-api-key": config.api_key,
+ "x-agent-id": config.agent_id,
+ "x-request-from": "openclaw"
+ }
timestamp = str(int(time.time() * 1000))
- signature = _generate_signature(sk, timestamp)
+ signature = _generate_signature(config.sk, timestamp)
return {
- "x-access-key": ak,
+ "x-access-key": config.ak,
"x-sign": signature,
"x-ts": timestamp,
- "x-agent-id": agent_id,
+ "x-agent-id": config.agent_id
}
@@ -193,13 +206,20 @@ class XiaoyiChannel(BaseChannel):
logger.info(f"XiaoyiChannel 发送消息: {msg}")
content = ""
+ cron_job_name = ""
if isinstance(msg.payload, dict):
content = msg.payload.get("content", "\n")
if isinstance(content, dict):
content = content.get("output", str(content))
content = str(content)
+ cron_job_name = msg.payload.get("cron", {}).get("job_name", "")
elif msg.payload:
content = str(msg.payload)
+
+ # 推送消息发送
+ if msg.id.startswith("cron-push"):
+ await self._send_push_notification(cron_job_name, content)
+ return
# 如果禁用流式,总是作为完整消息发送
if not self.config.enable_streaming:
@@ -297,7 +317,7 @@ class XiaoyiChannel(BaseChannel):
"""连接到小艺服务器(双通道)."""
import websockets
- headers = _generate_auth_headers(self.config.ak, self.config.sk, self.config.agent_id)
+ headers = _generate_auth_headers(self.config)
parsed = urlparse(url)
is_ip = bool(parsed.hostname and parsed.hostname.replace(".", "").isdigit())
@@ -404,16 +424,6 @@ class XiaoyiChannel(BaseChannel):
user_message = message.get("params", {}).get("message", {})
parts = user_message.get("parts", [])
- # ==================== CONCURRENT REQUEST DETECTION ====================
- # Check if this session already has an active task
- if self._is_session_active(session_id):
- logger.info(f"[CONCURRENT] Session {session_id} has an active task, sending busy response")
- # Send busy response and skip processing
- for url_key in list(self._ws_connections.keys()):
- await self._send_text_response(session_id, task_id, "上一个任务仍在处理中,请稍后再试", url_key, is_final=True)
- return
- # =================================================================
-
# Mark session as active
self._mark_session_active(session_id)
self._session_task_map[session_id] = task_id
@@ -456,6 +466,11 @@ class XiaoyiChannel(BaseChannel):
except Exception as e:
logger.error(f"XiaoYi: Failed to process file {name}: {e}")
file_attachments.append(f"[文件处理失败: {name}]")
+ elif kind == "data":
+ data = part.get("data", {})
+ if isinstance(data, dict):
+ push_id = data.get("variables", {}).get("systemVariables", {}).get("push_id", "")
+ self.config.push_id = push_id if push_id else self.config.push_id
# =================================================================
# Log summary of processed attachments
@@ -506,7 +521,7 @@ class XiaoyiChannel(BaseChannel):
# Add media payload to metadata
params = {"query": text, "task_id": task_id}
if media_payload:
- params.update(media_payload)
+ params["files"] = media_payload
user_message = Message(
id=message.get("id", ""),
@@ -807,11 +822,10 @@ class XiaoyiChannel(BaseChannel):
return False
try:
- from jiuwenclaw.channel.xiaoyi_utils.push import XiaoYiPushService, PushConfig
-
push_config = PushConfig(
api_id=self.config.api_id,
push_id=self.config.push_id,
+ push_url=self.config.push_url,
ak=self.config.ak,
sk=self.config.sk,
)
diff --git a/jiuwenclaw/channel/xiaoyi_utils/push.py b/jiuwenclaw/channel/xiaoyi_utils/push.py
index ebf5602d58..258c632dec 100644
--- a/jiuwenclaw/channel/xiaoyi_utils/push.py
+++ b/jiuwenclaw/channel/xiaoyi_utils/push.py
@@ -14,6 +14,8 @@ import aiohttp
from jiuwenclaw.utils import logger
+PUSH_URL = "https://hag.cloud.huawei.com/open-ability-agent/v1/agent-webhook"
+
@dataclass
class PushConfig:
@@ -22,7 +24,7 @@ class PushConfig:
push_id: str = ""
ak: str = ""
sk: str = ""
- push_url: str = "https://hag.cloud.huawei.com/open-ability-agent/v1/agent-webhook"
+ push_url: str = ""
@property
def is_configured(self) -> bool:
@@ -111,7 +113,7 @@ class XiaoYiPushService:
timeout = aiohttp.ClientTimeout(total=30)
async with aiohttp.ClientSession() as session:
async with session.post(
- self.config.push_url,
+ self.config.push_url or PUSH_URL,
headers=headers,
json=payload,
timeout=timeout,
diff --git a/jiuwenclaw/gateway/cron/models.py b/jiuwenclaw/gateway/cron/models.py
index 0998533b3f..12caf6fa26 100644
--- a/jiuwenclaw/gateway/cron/models.py
+++ b/jiuwenclaw/gateway/cron/models.py
@@ -12,7 +12,7 @@ class CronTargetChannel(str, Enum):
FEISHU = "feishu"
WHATSAPP = "whatsapp"
WECOM = "wecom"
- # XIAOYI = "xiaoyi"
+ XIAOYI = "xiaoyi"
# DINGTALK = "dingtalk"
diff --git a/jiuwenclaw/resources/config.yaml b/jiuwenclaw/resources/config.yaml
index 6fcf40d24a..4dfd685e2f 100644
--- a/jiuwenclaw/resources/config.yaml
+++ b/jiuwenclaw/resources/config.yaml
@@ -59,11 +59,18 @@ channels:
enabled: false
xiaoyi:
# 华为小艺 A2A 配置
+ mode: xiaoyi_channel
ak:
sk:
+ api_id:
+ push_id:
agent_id:
ws_url1: wss://hag.cloud.huawei.com/openclaw/v1/ws/link
ws_url2: wss://116.63.174.231/openclaw/v1/ws/link
+ uid:
+ api_key:
+ push_url:
+ file_upload_url:
enable_streaming: true
enabled: false
dingtalk: