diff --git a/sdk/real.py b/sdk/real.py index 792c6c1..bf432d9 100644 --- a/sdk/real.py +++ b/sdk/real.py @@ -191,6 +191,27 @@ class RealPlatformClient(PlatformClient): code = getattr(exc, "code", None) or "PLATFORM_CONNECTION_ERROR" return PlatformError(str(exc), code=code) + @staticmethod + def _normalize_workspace_path(location: str) -> str | None: + if not location: + return None + + path = Path(location) + if not path.is_absolute(): + normalized = path.as_posix() + return normalized or None + + parts = path.parts + if len(parts) >= 2 and parts[1] == "workspace": + relative = Path(*parts[2:]).as_posix() + return relative or None + if len(parts) >= 3 and parts[1] == "agents": + relative = Path(*parts[3:]).as_posix() + return relative or None + + relative = path.as_posix().lstrip("/") + return relative or None + @staticmethod def _attachment_paths(attachments: list[Attachment] | None) -> list[str]: if not attachments: @@ -198,18 +219,18 @@ class RealPlatformClient(PlatformClient): paths = [] for attachment in attachments: if attachment.workspace_path: - paths.append(attachment.workspace_path) + normalized = RealPlatformClient._normalize_workspace_path( + attachment.workspace_path + ) + if normalized: + paths.append(normalized) return paths @staticmethod def _attachment_from_send_file_event(event: MsgEventSendFile) -> Attachment: location = str(event.path) filename = Path(location).name or None - workspace_path = location - if workspace_path.startswith("/workspace/"): - workspace_path = workspace_path[len("/workspace/") :] - elif workspace_path == "/workspace": - workspace_path = "" + workspace_path = RealPlatformClient._normalize_workspace_path(location) return Attachment( url=location, mime_type="application/octet-stream",