feat(matrix): support outbound attachments via message tool

- extend message tool with optional media paths for channel delivery

- switch Matrix uploads to stream providers and handle encrypted-room payloads

- add/expand tests for message tool media forwarding and Matrix upload edge cases
This commit is contained in:
Alexander Minges
2026-02-11 11:50:36 +01:00
parent d4d87bb4e5
commit 6a40665753
5 changed files with 195 additions and 52 deletions

View File

@@ -0,0 +1,37 @@
import pytest
from nanobot.agent.tools.message import MessageTool
from nanobot.bus.events import OutboundMessage
@pytest.mark.asyncio
async def test_message_tool_sends_media_paths_with_default_context() -> None:
sent: list[OutboundMessage] = []
async def _send(msg: OutboundMessage) -> None:
sent.append(msg)
tool = MessageTool(
send_callback=_send,
default_channel="test-channel",
default_chat_id="!room:example.org",
)
result = await tool.execute(
content="Here is the file.",
media=[" /tmp/test.txt ", "", " ", "/tmp/report.pdf"],
)
assert result == "Message sent to test-channel:!room:example.org"
assert len(sent) == 1
assert sent[0].channel == "test-channel"
assert sent[0].chat_id == "!room:example.org"
assert sent[0].content == "Here is the file."
assert sent[0].media == ["/tmp/test.txt", "/tmp/report.pdf"]
@pytest.mark.asyncio
async def test_message_tool_returns_error_when_no_target_context() -> None:
tool = MessageTool()
result = await tool.execute(content="test")
assert result == "Error: No target channel/chat specified"