From 6d9b7baeb4ead98a257258951477de417329dff4 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Tue, 31 Mar 2026 18:14:49 +0800 Subject: [PATCH] fix(weixin): file send failed --- agent/chat/service.py | 20 -------------------- channel/weixin/weixin_api.py | 17 +++++++++++------ plugins/cow_cli/cow_cli.py | 4 +--- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/agent/chat/service.py b/agent/chat/service.py index 58931b00..1afe1691 100644 --- a/agent/chat/service.py +++ b/agent/chat/service.py @@ -75,26 +75,6 @@ class ChatService: # a new segment; collect tool results until turn_end. state.pending_tool_results = [] - elif event_type == "file_to_send": - # Cloud CHAT stream: local paths are useless to the web UI; push a markdown link when we have a public URL. - url = data.get("url") or "" - if url: - msg = (data.get("message") or "").strip() - fname = data.get("file_name") or "file" - ft = data.get("file_type") or "file" - parts = [] - if msg: - parts.append(f"{msg}\n\n") - if ft == "image": - parts.append(f"![{fname}]({url})") - else: - parts.append(f"[{fname}]({url})") - send_chunk_fn({ - "chunk_type": "content", - "delta": "\n\n" + "".join(parts) + "\n\n", - "segment_id": state.segment_id, - }) - elif event_type == "tool_execution_start": # Notify the client that a tool is about to run (with its input args) tool_name = data.get("tool_name", "") diff --git a/channel/weixin/weixin_api.py b/channel/weixin/weixin_api.py index b98fe5df..58ef70ef 100644 --- a/channel/weixin/weixin_api.py +++ b/channel/weixin/weixin_api.py @@ -303,13 +303,18 @@ def upload_media_to_cdn(api: WeixinApi, file_path: str, to_user_id: str, filesize=cipher_size, aeskey=aes_key_hex, ) - upload_param = resp.get("upload_param", "") - if not upload_param: - raise RuntimeError(f"[Weixin] getUploadUrl returned no upload_param: {resp}") - cdn_url = (f"{api.cdn_base_url}/upload" - f"?encrypted_query_param={quote(upload_param)}" - f"&filekey={quote(filekey)}") + # API may return either upload_full_url (new) or upload_param (legacy) + upload_full_url = resp.get("upload_full_url", "") + upload_param = resp.get("upload_param", "") + if upload_full_url: + cdn_url = upload_full_url + elif upload_param: + cdn_url = (f"{api.cdn_base_url}/upload" + f"?encrypted_query_param={quote(upload_param)}" + f"&filekey={quote(filekey)}") + else: + raise RuntimeError(f"[Weixin] getUploadUrl returned neither upload_full_url nor upload_param: {resp}") cdn_resp = requests.post(cdn_url, data=encrypted, headers={ "Content-Type": "application/octet-stream", diff --git a/plugins/cow_cli/cow_cli.py b/plugins/cow_cli/cow_cli.py index 39b578d9..a2caf0fc 100644 --- a/plugins/cow_cli/cow_cli.py +++ b/plugins/cow_cli/cow_cli.py @@ -683,10 +683,8 @@ class CowCliPlugin(Plugin): lines = [] for skill_name in result.installed: desc = _read_skill_description(os.path.join(skills_dir, skill_name)) - lines.append(f"✅ {skill_name}") + lines.append(f"✅ 技能安装成功:{skill_name}") if desc: - if len(desc) > 60: - desc = desc[:57] + "…" lines.append(f" {desc}") if len(result.installed) > 1: