AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Handle workspace:// URLs in regular markdown links (#12166)
Nicholas Tindle77fb4419d0dc
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsxindex 9bcec6deae..c0a9e5da10 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx@@ -32,13 +32,16 @@ import { ViewAgentOutputTool } from "../../tools/ViewAgentOutput/ViewAgentOutput/*** Resolve workspace:// URLs in markdown text to proxy download URLs.- * Detects MIME type from the hash fragment (e.g. workspace://id#video/mp4)- * and prefixes the alt text with "video:" so the custom img component can- * render a <video> element instead.+ *+ * Handles both image syntax `` and regular link+ * syntax `[text](workspace://id)`. For images the MIME type hash fragment is+ * inspected so that videos can be rendered with a `<video>` element via the+ * custom img component.*/function resolveWorkspaceUrls(text: string): string {- return text.replace(- /!\[([^\]]*)\]\(workspace:\/\/([^)#\s]+)(?:#([^)\s]*))?\)/g,+ // Handle image links: + let resolved = text.replace(+ /!\[([^\]]*)\]\(workspace:\/\/([^)#\s]+)(?:#([^)#\s]*))?\)/g,(_match, alt: string, fileId: string, mimeHint?: string) => {const apiPath = getGetWorkspaceDownloadFileByIdUrl(fileId);const url = `/api/proxy${apiPath}`;@@ -48,6 +51,21 @@ function resolveWorkspaceUrls(text: string): string {return ``;},);++ // Handle regular links: [text](workspace://id) — without the leading "!"+ // These are blocked by Streamdown's rehype-harden sanitizer because+ // "workspace://" is not in the allowed URL-scheme whitelist, which causes+ // "[blocked]" to appear next to the link text.+ resolved = resolved.replace(+ /(?<!!)\[([^\]]*)\]\(workspace:\/\/([^)#\s]+)(?:#[^)#\s]*)?\)/g,+ (_match, linkText: string, fileId: string) => {+ const apiPath = getGetWorkspaceDownloadFileByIdUrl(fileId);+ const url = `/api/proxy${apiPath}`;+ return `[${linkText || "Download file"}](${url})`;+ },+ );++ return resolved;}/**