revert: restore message.py to tanishra baseline (out of scope)

This commit is contained in:
Alexander Minges
2026-02-20 18:05:00 +01:00
parent 334078e242
commit 36d650e475

View File

@@ -1,6 +1,6 @@
"""Message tool for sending messages to users.""" """Message tool for sending messages to users."""
from typing import Any, Awaitable, Callable from typing import Any, Callable, Awaitable
from nanobot.agent.tools.base import Tool from nanobot.agent.tools.base import Tool
from nanobot.bus.events import OutboundMessage from nanobot.bus.events import OutboundMessage
@@ -13,7 +13,7 @@ class MessageTool(Tool):
self, self,
send_callback: Callable[[OutboundMessage], Awaitable[None]] | None = None, send_callback: Callable[[OutboundMessage], Awaitable[None]] | None = None,
default_channel: str = "", default_channel: str = "",
default_chat_id: str = "", default_chat_id: str = ""
): ):
self._send_callback = send_callback self._send_callback = send_callback
self._default_channel = default_channel self._default_channel = default_channel
@@ -34,35 +34,32 @@ class MessageTool(Tool):
@property @property
def description(self) -> str: def description(self) -> str:
return ( return "Send a message to the user. Use this when you want to communicate something."
"Send a message to the user. Supports optional media/attachment "
"paths for channels that can send files."
)
@property @property
def parameters(self) -> dict[str, Any]: def parameters(self) -> dict[str, Any]:
return { return {
"type": "object", "type": "object",
"properties": { "properties": {
"content": {"type": "string", "description": "The message content to send"}, "content": {
"type": "string",
"description": "The message content to send"
},
"channel": { "channel": {
"type": "string", "type": "string",
"description": "Optional: target channel (telegram, discord, etc.)", "description": "Optional: target channel (telegram, discord, etc.)"
}, },
"chat_id": {"type": "string", "description": "Optional: target chat/user ID"}, "chat_id": {
"media": { "type": "string",
"type": "array", "description": "Optional: target chat/user ID"
"description": "Optional: local file paths to send as attachments",
"items": {"type": "string"},
}, },
"chat_id": {"type": "string", "description": "Optional: target chat/user ID"},
"media": { "media": {
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"type": "string"},
"description": "Optional: list of file paths to attach (images, audio, documents)", "description": "Optional: list of file paths to attach (images, audio, documents)"
}
}, },
}, "required": ["content"]
"required": ["content"],
} }
async def execute( async def execute(
@@ -71,7 +68,7 @@ class MessageTool(Tool):
channel: str | None = None, channel: str | None = None,
chat_id: str | None = None, chat_id: str | None = None,
media: list[str] | None = None, media: list[str] | None = None,
**kwargs: Any, **kwargs: Any
) -> str: ) -> str:
channel = channel or self._default_channel channel = channel or self._default_channel
chat_id = chat_id or self._default_chat_id chat_id = chat_id or self._default_chat_id
@@ -82,17 +79,16 @@ class MessageTool(Tool):
if not self._send_callback: if not self._send_callback:
return "Error: Message sending not configured" return "Error: Message sending not configured"
media_paths: list[str] = [] msg = OutboundMessage(
for item in media or []: channel=channel,
if isinstance(item, str): chat_id=chat_id,
candidate = item.strip() content=content,
if candidate: media=media or []
media_paths.append(candidate) )
msg = OutboundMessage(channel=channel, chat_id=chat_id, content=content, media=media_paths)
try: try:
await self._send_callback(msg) await self._send_callback(msg)
return f"Message sent to {channel}:{chat_id}" media_info = f" with {len(media)} attachments" if media else ""
return f"Message sent to {channel}:{chat_id}{media_info}"
except Exception as e: except Exception as e:
return f"Error sending message: {str(e)}" return f"Error sending message: {str(e)}"