fix(agent): resolve relative media paths in MessageTool
When deployed with Docker and workspace mounted as a volume, sending media files failed because relative paths (e.g. output/image.png) were not resolved against the workspace directory. The process CWD differs from the workspace in containerized environments, causing os.path.isfile checks to fail in channel handlers. Normalize relative media paths at the MessageTool entry point using get_workspace_path().
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
"""Message tool for sending messages to users."""
|
||||
|
||||
import os
|
||||
from contextvars import ContextVar
|
||||
from typing import Any, Awaitable, Callable
|
||||
|
||||
from nanobot.agent.tools.base import Tool, tool_parameters
|
||||
from nanobot.agent.tools.schema import ArraySchema, StringSchema, tool_parameters_schema
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
from nanobot.config.paths import get_workspace_path
|
||||
|
||||
|
||||
@tool_parameters(
|
||||
@@ -141,6 +143,15 @@ class MessageTool(Tool):
|
||||
if not self._send_callback:
|
||||
return "Error: Message sending not configured"
|
||||
|
||||
if media:
|
||||
resolved = []
|
||||
for p in media:
|
||||
if p.startswith(("http://", "https://")) or os.path.isabs(p):
|
||||
resolved.append(p)
|
||||
else:
|
||||
resolved.append(str(get_workspace_path() / p))
|
||||
media = resolved
|
||||
|
||||
metadata = dict(self._default_metadata.get()) if same_target else {}
|
||||
if message_id:
|
||||
metadata["message_id"] = message_id
|
||||
|
||||
Reference in New Issue
Block a user