Skip to content

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.

fix(frontend): fix Streamdown link safety modal and add origin check (#12209)

Otto195b14286a14
diff --git a/autogpt_platform/frontend/.storybook/main.ts b/autogpt_platform/frontend/.storybook/main.ts
index eb153ac920..e2f7b5678a 100644
--- a/autogpt_platform/frontend/.storybook/main.ts
+++ b/autogpt_platform/frontend/.storybook/main.ts
@@ -6,6 +6,7 @@ const config: StorybookConfig = {
"../src/components/tokens/**/*.stories.@(js|jsx|mjs|ts|tsx)",
"../src/components/atoms/**/*.stories.@(js|jsx|mjs|ts|tsx)",
"../src/components/molecules/**/*.stories.@(js|jsx|mjs|ts|tsx)",
+ "../src/components/ai-elements/**/*.stories.@(js|jsx|mjs|ts|tsx)",
],
addons: [
"@storybook/addon-a11y",
diff --git a/autogpt_platform/frontend/src/components/ai-elements/message.stories.tsx b/autogpt_platform/frontend/src/components/ai-elements/message.stories.tsx
new file mode 100644
index 0000000000..4fbe629623
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/ai-elements/message.stories.tsx
@@ -0,0 +1,110 @@
+import type { Meta, StoryObj } from "@storybook/nextjs";
+
+import { Message, MessageContent, MessageResponse } from "./message";
+
+const meta: Meta<typeof Message> = {
+ title: "AI Elements/Message",
+ component: Message,
+ parameters: {
+ layout: "padded",
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof Message>;
+
+type MessageStoryProps = { children: string };
+
+function AssistantMessage({ children }: MessageStoryProps) {
+ return (
+ <Message from="assistant">
+ <MessageContent>
+ <MessageResponse>{children}</MessageResponse>
+ </MessageContent>
+ </Message>
+ );
+}
+
+function UserMessage({ children }: MessageStoryProps) {
+ return (
+ <Message from="user">
+ <MessageContent>
+ <MessageResponse>{children}</MessageResponse>
+ </MessageContent>
+ </Message>
+ );
+}
+
+export const Default: Story = {
+ render: () => (
+ <div className="flex flex-col gap-4">
+ <AssistantMessage>
+ {
+ "Here is a response with **bold text**, *italic text*, and `inline code`."
+ }
+ </AssistantMessage>
+ </div>
+ ),
+};
+
+export const UserMessageStory: Story = {
+ name: "User Message",
+ render: () => (
+ <div className="flex flex-col gap-4">
+ <UserMessage>{"How do I download my workspace files?"}</UserMessage>
+ </div>
+ ),
+};
+
+export const WithLinks: Story = {
+ name: "With Links (Internal & External)",
+ render: () => (
+ <div className="flex flex-col gap-4">
+ <AssistantMessage>
+ {[
+ "Here are some links:\n\n",
+ "- Internal link: [Download file](/api/proxy/api/v1/workspace/files/download/abc123)\n",
+ "- External link: [GitHub](https://github.com/Significant-Gravitas/AutoGPT)\n",
+ "- Another external: [Documentation](https://docs.agpt.co)\n\n",
+ "Internal links should open directly. External links should show a safety modal.\n\n",
+ "**Try clicking each link to verify behavior.**",
+ ].join("")}
+ </AssistantMessage>
+ </div>
+ ),
+};
+
+export const LinkSafetyModal: Story = {
+ name: "LinkSafetyModal",
+ render: () => (
+ <div className="flex flex-col gap-4">
+ <p className="text-sm text-muted-foreground">
+ Click the external link below to trigger the link safety modal. Verify
+ that both &quot;Copy link&quot; and &quot;Open link&quot; buttons are
+ visible.
+ </p>
+ <AssistantMessage>
+ {
+ "Click this external link to see the safety modal: [Example Site](https://example.com)"
+ }
+ </AssistantMessage>
+ </div>
+ ),
+};
+
+export const Conversation: Story = {
+ render: () => (
+ <div className="flex flex-col gap-4">
+ <UserMessage>{"Can you help me with my workspace files?"}</UserMessage>
+ <AssistantMessage>
+ {[
+ "Sure! Here's how to manage your workspace files:\n\n",
+ "1. Upload files using the attachment button\n",
+ "2. Download files by clicking the link in chat\n",
+ "3. View all files in the [workspace panel](/workspace)\n\n",
+ "For more details, check the [documentation](https://docs.agpt.co/workspace).",
+ ].join("")}
+ </AssistantMessage>
+ </div>
+ ),
+};
diff --git a/autogpt_platform/frontend/src/components/ai-elements/message.tsx b/autogpt_platform/frontend/src/components/ai-elements/message.tsx
index cc11c2f01b..035b110784 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/message.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/message.tsx
@@ -303,6 +303,15 @@ export const MessageBranchPage = ({
export type MessageResponseProps = ComponentProps<typeof Streamdown>;
+function isSameOriginLink(url: string): boolean {
+ try {
+ const parsed = new URL(url, window.location.origin);
+ return parsed.origin === window.location.origin;
+ } catch {
+ return false;
+ }
+}
+
export const MessageResponse = memo(
({ className, ...props }: MessageResponseProps) => (
<Streamdown
@@ -311,6 +320,10 @@ export const MessageResponse = memo(
className,
)}
plugins={{ code, mermaid, math, cjk }}
+ linkSafety={{
+ enabled: true,
+ onLinkCheck: isSameOriginLink,
+ }}
{...props}
/>
),
diff --git a/autogpt_platform/frontend/tailwind.config.ts b/autogpt_platform/frontend/tailwind.config.ts
index 85b31c72f8..753755cef2 100644
--- a/autogpt_platform/frontend/tailwind.config.ts
+++ b/autogpt_platform/frontend/tailwind.config.ts
@@ -5,7 +5,7 @@ import { colors } from "./src/components/styles/colors";
const config = {
darkMode: ["class", ".dark-mode"], // ignore dark: prefix classes for now until we fully support dark mode
- content: ["./src/**/*.{ts,tsx}"],
+ content: ["./src/**/*.{ts,tsx}", "./node_modules/streamdown/dist/**/*.js"],
prefix: "",
theme: {
container: {