Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(platforms): route non-primary attachment downloads

cyhhao375b5efb402f
diff --git a/core/handlers/message_handler.py b/core/handlers/message_handler.py
index 9b88249f8..1678f8c8f 100644
--- a/core/handlers/message_handler.py
+++ b/core/handlers/message_handler.py
@@ -673,6 +673,7 @@ class MessageHandler(BaseHandler):
"url_private_download": attachment.url, # Slack compat
"name": attachment.name,
"size": attachment.size,
+ "platform": context.platform,
}
attachment_data = getattr(attachment, "__dict__", {})
for key, value in attachment_data.items():
diff --git a/modules/agents/claude_agent.py b/modules/agents/claude_agent.py
index 682572fcd..19326526e 100644
--- a/modules/agents/claude_agent.py
+++ b/modules/agents/claude_agent.py
@@ -243,7 +243,7 @@ class ClaudeAgent(BaseAgent):
if text:
text_parts.append(text)
- assistant_text = self._extract_text_blocks(message)
+ assistant_text = self._extract_text_blocks(message, context)
if assistant_text:
self._last_assistant_text[composite_key] = assistant_text
@@ -513,7 +513,7 @@ class ClaudeAgent(BaseAgent):
return session_id
return None
- def _extract_text_blocks(self, message) -> str:
+ def _extract_text_blocks(self, message, context: MessageContext) -> str:
"""Extract text-only content blocks for result fallbacks."""
parts = []
for block in getattr(message, "content", []) or []:
diff --git a/modules/im/multi.py b/modules/im/multi.py
index d6ce32041..54faac0cc 100644
--- a/modules/im/multi.py
+++ b/modules/im/multi.py
@@ -46,6 +46,22 @@ class MultiIMClient(BaseIMClient):
except KeyError as exc:
raise ValueError(f"Platform '{platform}' is not enabled") from exc
+ def _resolve_platform_from_file_info(self, file_info: Dict[str, Any]) -> str:
+ platform = str(file_info.get("platform") or "").strip()
+ if platform in self.clients:
+ return platform
+
+ url = str(file_info.get("url") or file_info.get("url_private_download") or "")
+ if "wechat" in url:
+ return "wechat"
+ if "discordapp" in url or "discord.com" in url:
+ return "discord"
+ if "slack" in url:
+ return "slack"
+ if "feishu" in url or "lark" in url:
+ return "lark"
+ return self.primary_platform
+
def get_client_for_context(self, context: Optional[MessageContext] = None) -> BaseIMClient:
return self.get_client(self._resolve_platform(context))
@@ -190,9 +206,8 @@ class MultiIMClient(BaseIMClient):
async def download_file(
self, file_info: Dict[str, Any], max_bytes: Optional[int] = None, timeout_seconds: int = 30
):
- return await self.clients[self.primary_platform].download_file(
- file_info, max_bytes=max_bytes, timeout_seconds=timeout_seconds
- )
+ client = self.get_client(self._resolve_platform_from_file_info(file_info))
+ return await client.download_file(file_info, max_bytes=max_bytes, timeout_seconds=timeout_seconds)
async def download_file_to_path(
self,
@@ -201,7 +216,8 @@ class MultiIMClient(BaseIMClient):
max_bytes: Optional[int] = None,
timeout_seconds: int = 30,
):
- return await self.clients[self.primary_platform].download_file_to_path(
+ client = self.get_client(self._resolve_platform_from_file_info(file_info))
+ return await client.download_file_to_path(
file_info,
target_path,
max_bytes=max_bytes,
diff --git a/tests/test_multi_platform_runtime.py b/tests/test_multi_platform_runtime.py
index 0344d863c..9a86ff8b1 100644
--- a/tests/test_multi_platform_runtime.py
+++ b/tests/test_multi_platform_runtime.py
@@ -54,6 +54,16 @@ class _StubClient(BaseIMClient):
self.sent.append(("dm", user_id, text))
return self.name
+ async def download_file(self, file_info, max_bytes=None, timeout_seconds=30):
+ self.sent.append(("download", file_info.get("platform"), file_info.get("name")))
+ return b"data"
+
+ async def download_file_to_path(self, file_info, target_path, max_bytes=None, timeout_seconds=30):
+ self.sent.append(("download_to_path", file_info.get("platform"), target_path))
+ from modules.im.base import FileDownloadResult
+
+ return FileDownloadResult(True, target_path)
+
def format_markdown(self, text: str) -> str:
return text
@@ -130,3 +140,14 @@ def test_active_poll_info_round_trips_platform():
restored = ActivePollInfo.from_dict(poll.to_dict())
assert restored.platform == "discord"
+
+
+def test_multi_im_client_routes_download_by_file_info_platform():
+ slack = _StubClient("slack")
+ wechat = _StubClient("wechat")
+ client = MultiIMClient({"slack": slack, "wechat": wechat}, primary_platform="slack")
+
+ asyncio.run(client.download_file_to_path({"platform": "wechat", "name": "a.jpg"}, "/tmp/a.jpg"))
+
+ assert slack.sent == []
+ assert wechat.sent == [("download_to_path", "wechat", "/tmp/a.jpg")]