Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): open native message links externally (#677)

Gener5d46c5a36870
diff --git a/scripts/ci/workflow-contract.test.ts b/scripts/ci/workflow-contract.test.ts
index 4282d230a..64377baf5 100644
--- a/scripts/ci/workflow-contract.test.ts
+++ b/scripts/ci/workflow-contract.test.ts
@@ -59,10 +59,30 @@ const desktopConfig = JSON.parse(
readFileSync(resolve(import.meta.dirname, "../../src/desktop/src-tauri/tauri.conf.json"), "utf8"),
) as {
build?: { devUrl?: string; frontendDist?: string }
- app?: { windows?: Array<{ label?: string; dragDropEnabled?: boolean }> }
+ app?: {
+ windows?: Array<{ label?: string; dragDropEnabled?: boolean }>
+ security?: { capabilities?: Array<string | Record<string, unknown>> }
+ }
bundle?: { createUpdaterArtifacts?: boolean | string }
plugins?: { updater?: { endpoints?: string[] } }
}
+type ExternalLinksCapability = {
+ identifier: string
+ windows: string[]
+ platforms: string[]
+ local: boolean
+ remote: { urls: string[] }
+ permissions: Array<{
+ identifier: string
+ allow?: Array<{ url: string }>
+ }>
+}
+const externalLinksCapability = JSON.parse(
+ readFileSync(
+ resolve(import.meta.dirname, "../../src/desktop/src-tauri/capabilities/external-links.json"),
+ "utf8",
+ ),
+) as ExternalLinksCapability
const desktopMacConfig = JSON.parse(
readFileSync(resolve(import.meta.dirname, "../../src/desktop/src-tauri/tauri.macos.conf.json"), "utf8"),
) as { bundle?: { macOS?: { entitlements?: string; signingIdentity?: string } } }
@@ -98,7 +118,7 @@ const desktopDevConfig = JSON.parse(readFileSync(
resolve(import.meta.dirname, "../../src/desktop/src-tauri/tauri.dev.conf.json"),
"utf8",
)) as {
- app: { security: { capabilities: Array<string | DesktopCapability> } }
+ app: { security: { capabilities: Array<string | DesktopCapability | ExternalLinksCapability> } }
}
const bumpScript = readFileSync(resolve(import.meta.dirname, "../bump-version.mjs"), "utf8")
const mobileReleaseWorkflow = resolve(workflowRoot, "mobile-release.yml")
@@ -437,6 +457,89 @@ describe("CI dependency setup", () => {
})
})
+describe("Native message external-link opener", () => {
+ const expectedPlatforms = ["linux", "macOS", "windows", "android", "iOS"]
+ const expectedPermission = [{
+ identifier: "opener:allow-open-url",
+ allow: [{ url: "http://*" }, { url: "https://*" }],
+ }]
+ const scopedUrlAllowed = (href: string, capability: ExternalLinksCapability) => {
+ const patterns = capability.permissions.flatMap((permission) => (
+ permission.allow?.map((entry) => entry.url) ?? []
+ ))
+ return patterns.includes(`${new URL(href).protocol}//*`)
+ }
+
+ it("registers the official opener plugin in the common desktop/mobile builder", () => {
+ const desktopOnlyDependencies = desktopCargoManifest.indexOf(
+ "[target.\"cfg(not(any(target_os = \\\"android\\\", target_os = \\\"ios\\\")))\".dependencies]",
+ )
+ const dependency = desktopCargoManifest.indexOf('tauri-plugin-opener = "2"')
+ const registration = desktopRustEntry.indexOf("plugin(tauri_plugin_opener::init())")
+ const desktopOnlyPlugins = desktopRustEntry.indexOf("// Desktop-only plugins")
+
+ expect(dependency).toBeGreaterThan(-1)
+ expect(dependency).toBeLessThan(desktopOnlyDependencies)
+ expect(registration).toBeGreaterThan(-1)
+ expect(registration).toBeLessThan(desktopOnlyPlugins)
+ })
+
+ it("grants only scoped HTTP(S) URL opening to the production five-platform app webview", () => {
+ expect(externalLinksCapability).toMatchObject({
+ identifier: "external-links",
+ windows: ["main"],
+ platforms: expectedPlatforms,
+ local: true,
+ remote: { urls: ["https://alook.ai"] },
+ permissions: expectedPermission,
+ })
+ expect(desktopConfig.app?.security?.capabilities).toContain("external-links")
+ expect([
+ "http://example.com:8080/path/to/story?source=chat#section",
+ "https://example.com:9443/a/b?query=yes#fragment",
+ "https://alook.ai/c/invite/abcdef?from=dm",
+ ].every((href) => scopedUrlAllowed(href, externalLinksCapability))).toBe(true)
+ expect([
+ "mailto:[email protected]",
+ "tel:+15551234567",
+ "file:///tmp/private",
+ ].some((href) => scopedUrlAllowed(href, externalLinksCapability))).toBe(false)
+ })
+
+ it("reuses the same minimal HTTP(S) scope for the local development app webview", () => {
+ const capabilities = desktopDevConfig.app?.security?.capabilities ?? []
+ const inlineOpener = capabilities.find((capability): capability is ExternalLinksCapability => (
+ typeof capability !== "string"
+ && capability.permissions.some((permission) => (
+ typeof permission !== "string" && permission.identifier.startsWith("opener:")
+ ))
+ ))
+
+ expect(capabilities).toContain("external-links")
+ expect(capabilities.filter((capability) => capability === "external-links")).toHaveLength(1)
+ expect(inlineOpener).toBeUndefined()
+ })
+
+ it("does not grant default schemes, paths, reveal, shell, or CSP expansion", () => {
+ const capabilityText = JSON.stringify({
+ production: externalLinksCapability,
+ development: desktopDevConfig.app?.security?.capabilities,
+ })
+ for (const rejected of [
+ "opener:default",
+ "opener:allow-default-urls",
+ "opener:allow-open-path",
+ "opener:allow-reveal-item-in-dir",
+ "shell:",
+ "mailto:",
+ "tel:",
+ ]) {
+ expect(capabilityText).not.toContain(rejected)
+ }
+ expect(desktopConfig.app).not.toHaveProperty("security.csp")
+ })
+})
+
describe("Turbo CI execution", () => {
const cachedJobs = ["blog-build", "static-checks", "test-linux", "test-windows"]
const affectedJobs = ["static-checks", "test-windows"]
@@ -738,7 +841,10 @@ describe("Desktop image clipboard", () => {
remote: { urls: ["https://alook.ai"] },
permissions: [writeImagePermission],
})
- expect(desktopDevConfig.app.security.capabilities).toEqual(["desktop-capability"])
+ expect(desktopDevConfig.app.security.capabilities).toEqual([
+ "desktop-capability",
+ "external-links",
+ ])
})
})
diff --git a/src/desktop/src-tauri/Cargo.lock b/src/desktop/src-tauri/Cargo.lock
index fc5ba18df..d5204b6bd 100644
--- a/src/desktop/src-tauri/Cargo.lock
+++ b/src/desktop/src-tauri/Cargo.lock
@@ -48,6 +48,7 @@ dependencies = [
"tauri-plugin-clipboard-manager",
"tauri-plugin-dialog",
"tauri-plugin-notification",
+ "tauri-plugin-opener",
"tauri-plugin-single-instance",
"tauri-plugin-updater",
"tokio",
@@ -1903,6 +1904,25 @@ version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
+[[package]]
+name = "is-docker"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "is-wsl"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
+dependencies = [
+ "is-docker",
+ "once_cell",
+]
+
[[package]]
name = "itoa"
version = "1.0.18"
@@ -2581,6 +2601,17 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+[[package]]
+name = "open"
+version = "5.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ade3be4664bc1ef537ce133015f04c176b737815c2ba9fd60edf212d6e90dd55"
+dependencies = [
+ "dunce",
+ "is-wsl",
+ "libc",
+]
+
[[package]]
name = "openssl-probe"
version = "0.2.1"
@@ -4068,6 +4099,28 @@ dependencies = [
"url",
]
+[[package]]
+name = "tauri-plugin-opener"
+version = "2.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60d60366174b745b4ef5824b8bbc1c457fd08f0ce101ff643c0a49181a9f4e91"
+dependencies = [
+ "dunce",
+ "glob",
+ "objc2-app-kit",
+ "objc2-foundation",
+ "open",
+ "schemars 0.8.22",
+ "serde",
+ "serde_json",
+ "tauri",
+ "tauri-plugin",
+ "thiserror 2.0.18",
+ "url",
+ "windows",
+ "zbus",
+]
+
[[package]]
name = "tauri-plugin-single-instance"
version = "2.4.3"
diff --git a/src/desktop/src-tauri/Cargo.toml b/src/desktop/src-tauri/Cargo.toml
index f9ff02fb8..1eb576ae9 100644
--- a/src/desktop/src-tauri/Cargo.toml
+++ b/src/desktop/src-tauri/Cargo.toml
@@ -15,6 +15,7 @@ tauri-build = { version = "2", features = [] }
tauri = { version = "2", features = ["tray-icon", "image-png", "macos-private-api"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+tauri-plugin-opener = "2"
[package.metadata.cargo-machete]
ignored = ["serde_json"]
diff --git a/src/desktop/src-tauri/capabilities/external-links.json b/src/desktop/src-tauri/capabilities/external-links.json
new file mode 100644
index 000000000..221be7474
--- /dev/null
+++ b/src/desktop/src-tauri/capabilities/external-links.json
@@ -0,0 +1,20 @@
+{
+ "$schema": "../gen/schemas/desktop-schema.json",
+ "identifier": "external-links",
+ "description": "System-browser access for HTTP(S) links in the main webview",
+ "windows": ["main"],
+ "platforms": ["linux", "macOS", "windows", "android", "iOS"],
+ "local": true,
+ "remote": {
+ "urls": ["https://alook.ai"]
+ },
+ "permissions": [
+ {
+ "identifier": "opener:allow-open-url",
+ "allow": [
+ { "url": "http://*" },
+ { "url": "https://*" }
+ ]
+ }
+ ]
+}
diff --git a/src/desktop/src-tauri/src/lib.rs b/src/desktop/src-tauri/src/lib.rs
index a719586d5..dcf7f22c5 100644
--- a/src/desktop/src-tauri/src/lib.rs
+++ b/src/desktop/src-tauri/src/lib.rs
@@ -8,7 +8,7 @@ mod macos_window;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
- let builder = tauri::Builder::default();
+ let builder = tauri::Builder::default().plugin(tauri_plugin_opener::init());
// Desktop-only plugins
#[cfg(desktop)]
diff --git a/src/desktop/src-tauri/tauri.conf.json b/src/desktop/src-tauri/tauri.conf.json
index 3dd581718..71b84e910 100644
--- a/src/desktop/src-tauri/tauri.conf.json
+++ b/src/desktop/src-tauri/tauri.conf.json
@@ -45,7 +45,8 @@
],
"security": {
"capabilities": [
- "desktop-capability"
+ "desktop-capability",
+ "external-links"
]
}
},
diff --git a/src/desktop/src-tauri/tauri.dev.conf.json b/src/desktop/src-tauri/tauri.dev.conf.json
index 97a4e2f1a..7d09a1df0 100644
--- a/src/desktop/src-tauri/tauri.dev.conf.json
+++ b/src/desktop/src-tauri/tauri.dev.conf.json
@@ -2,7 +2,7 @@
"$schema": "./gen/schemas/desktop-schema.json",
"app": {
"security": {
- "capabilities": ["desktop-capability"]
+ "capabilities": ["desktop-capability", "external-links"]
}
}
}
diff --git a/src/web/src/components/community/messages/message-body.test.ts b/src/web/src/components/community/messages/message-body.test.ts
index 73fcfdce0..6596e84db 100644
--- a/src/web/src/components/community/messages/message-body.test.ts
+++ b/src/web/src/components/community/messages/message-body.test.ts
@@ -15,6 +15,7 @@ describe("MessageBody — plain URL rendering", () => {
const link = renderer!.root.findByType("a")
expect(link.props.href).toBe("https://example.com/story")
expect(link.props["data-platform-link"]).toBe("generic")
+ expect(link.props["data-message-external-link"]).toBe(true)
expect(renderer!.root.findAllByType("svg")).toHaveLength(1)
})
@@ -32,8 +33,10 @@ describe("MessageBody — plain URL rendering", () => {
expect(links).toHaveLength(2)
expect(links[0].props.href).toBe("https://github.com/alookai/alook/pull/598")
expect(links[0].props["data-platform-link"]).toBe("github")
+ expect(links[0].props["data-message-external-link"]).toBe(true)
expect(links[1].props.href).toBe("https://example.com/story")
expect(links[1].props["data-platform-link"]).toBe("generic")
+ expect(links[1].props["data-message-external-link"]).toBe(true)
})
})
diff --git a/src/web/src/components/community/messages/message-external-link.test.ts b/src/web/src/components/community/messages/message-external-link.test.ts
new file mode 100644
index 000000000..ea598cff8
--- /dev/null
+++ b/src/web/src/components/community/messages/message-external-link.test.ts
@@ -0,0 +1,158 @@
+import React from "react"
+import TestRenderer, { act } from "react-test-renderer"
+import { afterEach, describe, expect, it, vi } from "vitest"
+import { toast } from "sonner"
+import {
+ MESSAGE_EXTERNAL_LINK_ERROR,
+ MessageExternalLink,
+ handleMessageExternalLinkClick,
+} from "./message-external-link"
+
+vi.mock("sonner", () => ({ toast: { error: vi.fn() } }))
+
+afterEach(() => {
+ vi.unstubAllGlobals()
+})
+
+function clickEvent(defaultPrevented = false) {
+ return {
+ defaultPrevented,
+ preventDefault: vi.fn(),
+ stopPropagation: vi.fn(),
+ }
+}
+
+describe("handleMessageExternalLinkClick", () => {
+ it.each([
+ "http://example.com:8080/path/to/story?source=chat#section",
+ "https://github.com/alookai/alook/pull/598?view=files#diff",
+ "https://alook.ai/blog/native-links?from=message#intro",
+ "https://alook.ai/c/invite/abcdef?from=dm",
+ ])("opens an absolute Tauri HTTP(S) URL exactly once without WebView navigation: %s", async (href) => {
+ const event = clickEvent()
+ const order: string[] = []
+ event.preventDefault.mockImplementation(() => { order.push("prevent") })
+ const openUrl = vi.fn(async () => { order.push("open") })
+ const onError = vi.fn()
+
+ const opening = handleMessageExternalLinkClick(event, href, {
+ tauri: true,
+ openUrl,
+ onError,
+ })
+
+ expect(event.preventDefault).toHaveBeenCalledOnce()
+ expect(event.stopPropagation).toHaveBeenCalledOnce()
+ expect(openUrl).toHaveBeenCalledOnce()
+ expect(openUrl).toHaveBeenCalledWith(href)
+ expect(order).toEqual(["prevent", "open"])
+ await opening
+ expect(onError).not.toHaveBeenCalled()
+ })
+
+ it.each([
+ ["ordinary Web", false, "https://example.com"],
+ ["relative App route", true, "/c/channels/server/channel"],
+ ["mailto", true, "mailto:[email protected]"],
+ ["tel", true, "tel:+15551234567"],
+ ["invalid URL", true, "not a URL"],
+ ])("leaves %s to its existing browser or App behavior", (_case, tauri, href) => {
+ const event = clickEvent()
+ const openUrl = vi.fn()
+
+ expect(handleMessageExternalLinkClick(event, href, { tauri, openUrl })).toBeNull()
+
+ expect(event.preventDefault).not.toHaveBeenCalled()
+ expect(event.stopPropagation).not.toHaveBeenCalled()
+ expect(openUrl).not.toHaveBeenCalled()
+ })
+
+ it("respects a caller that already prevented the click", () => {
+ const event = clickEvent(true)
+ const openUrl = vi.fn()
+
+ expect(handleMessageExternalLinkClick(event, "https://example.com", {
+ tauri: true,
+ openUrl,
+ })).toBeNull()
+
+ expect(openUrl).not.toHaveBeenCalled()
+ })
+
+ it("fails closed with one visible error when an old bundle has no opener API", async () => {
+ vi.mocked(toast.error).mockReset()
+ const event = clickEvent()
+
+ await handleMessageExternalLinkClick(event, "https://example.com", {
+ tauri: true,
+ openUrl: null,
+ })
+
+ expect(event.preventDefault).toHaveBeenCalledOnce()
+ expect(toast.error).toHaveBeenCalledOnce()
+ expect(toast.error).toHaveBeenCalledWith(MESSAGE_EXTERNAL_LINK_ERROR)
+ })
+
+ it.each([
+ ["asynchronously", () => Promise.reject(new Error("denied"))],
+ ["synchronously", () => { throw new Error("missing command") }],
+ ])("fails closed with one visible error when opener rejects %s", async (_case, implementation) => {
+ const event = clickEvent()
+ const openUrl = vi.fn(implementation)
+ const onError = vi.fn()
+
+ await handleMessageExternalLinkClick(event, "https://example.com", {
+ tauri: true,
+ openUrl,
+ onError,
+ })
+
+ expect(openUrl).toHaveBeenCalledOnce()
+ expect(onError).toHaveBeenCalledOnce()
+ })
+})
+
+describe("MessageExternalLink", () => {
+ it("preserves anchor attributes and marks the shared external-link surface", () => {
+ let renderer: TestRenderer.ReactTestRenderer
+ act(() => {
+ renderer = TestRenderer.create(
+ React.createElement(MessageExternalLink, {
+ href: "https://example.com/story",
+ target: "_blank",
+ rel: "noopener noreferrer",
+ }, "Example"),
+ )
+ })
+
+ expect(renderer!.root.findByType("a").props).toMatchObject({
+ href: "https://example.com/story",
+ target: "_blank",
+ rel: "noopener noreferrer",
+ "data-message-external-link": true,
+ })
+ })
+
+ it("uses the registered global Tauri opener from the rendered anchor", async () => {
+ const openUrl = vi.fn().mockResolvedValue(undefined)
+ vi.stubGlobal("window", { __TAURI__: { opener: { openUrl } } })
+ const event = clickEvent()
+ let renderer: TestRenderer.ReactTestRenderer
+ act(() => {
+ renderer = TestRenderer.create(
+ React.createElement(MessageExternalLink, {
+ href: "https://example.com/native",
+ }, "Example"),
+ )
+ })
+
+ await act(async () => {
+ renderer!.root.findByType("a").props.onClick(event)
+ await Promise.resolve()
+ })
+
+ expect(event.preventDefault).toHaveBeenCalledOnce()
+ expect(openUrl).toHaveBeenCalledOnce()
+ expect(openUrl).toHaveBeenCalledWith("https://example.com/native")
+ })
+})
diff --git a/src/web/src/components/community/messages/message-external-link.tsx b/src/web/src/components/community/messages/message-external-link.tsx
new file mode 100644
index 000000000..b4bd6f073
--- /dev/null
+++ b/src/web/src/components/community/messages/message-external-link.tsx
@@ -0,0 +1,89 @@
+"use client"
+
+import type { ComponentPropsWithoutRef, MouseEvent } from "react"
+import { isTauri } from "@alook/shared"
+import { toast } from "sonner"
+
+export const MESSAGE_EXTERNAL_LINK_ERROR = "Couldn't open link in your browser"
+
+type OpenUrl = (url: string) => Promise<void>
+type MessageLinkClickEvent = Pick<
+ MouseEvent<HTMLAnchorElement>,
+ "defaultPrevented" | "preventDefault" | "stopPropagation"
+>
+
+type TauriOpenerWindow = Window & {
+ __TAURI__?: {
+ opener?: {
+ openUrl?: OpenUrl
+ }
+ }
+}
+
+function isAbsoluteHttpUrl(href: string | undefined): href is string {
+ if (!href) return false
+ try {
+ const protocol = new URL(href).protocol
+ return protocol === "http:" || protocol === "https:"
+ } catch {
+ return false
+ }
+}
+
+function readTauriOpenUrl(): OpenUrl | null {
+ if (typeof window === "undefined") return null
+ const openUrl = (window as TauriOpenerWindow).__TAURI__?.opener?.openUrl
+ return openUrl ? (url) => openUrl(url) : null
+}
+
+export function handleMessageExternalLinkClick(
+ event: MessageLinkClickEvent,
+ href: string | undefined,
+ options: {
+ tauri?: boolean
+ openUrl?: OpenUrl | null
+ onError?: () => void
+ } = {},
+): Promise<void> | null {
+ const tauri = options.tauri ?? isTauri()
+ if (!tauri || event.defaultPrevented || !isAbsoluteHttpUrl(href)) return null
+
+ event.preventDefault()
+ event.stopPropagation()
+ const onError = options.onError ?? (() => toast.error(MESSAGE_EXTERNAL_LINK_ERROR))
+ const openUrl = options.openUrl === undefined ? readTauriOpenUrl() : options.openUrl
+ if (!openUrl) {
+ onError()
+ return Promise.resolve()
+ }
+
+ try {
+ return Promise.resolve(openUrl(href)).catch(() => {
+ onError()
+ })
+ } catch {
+ onError()
+ return Promise.resolve()
+ }
+}
+
+export function MessageExternalLink({
+ href,
+ onClick,
+ children,
+ ...props
+}: ComponentPropsWithoutRef<"a">) {
+ return (
+ <a
+ {...props}
+ href={href}
+ data-message-external-link
+ onClick={(event) => {
+ onClick?.(event)
+ void handleMessageExternalLinkClick(event, href)
+ }}
+ >
+ {children}
+ </a>
+ )
+}
diff --git a/src/web/src/components/community/messages/message.render.test.ts b/src/web/src/components/community/messages/message.render.test.ts
index ec07502cc..d404ac5f2 100644
--- a/src/web/src/components/community/messages/message.render.test.ts
+++ b/src/web/src/components/community/messages/message.render.test.ts
@@ -290,6 +290,37 @@ describe("Message reply content projection", () => {
})
})
+describe("Message embed links", () => {
+ it("routes author and title URLs through the shared external-link anchor", () => {
+ let renderer: TestRenderer.ReactTestRenderer
+ act(() => {
+ renderer = TestRenderer.create(makeTree({
+ m: baseMsg({
+ embeds: [{
+ title: "Example story",
+ url: "https://example.com/story?from=embed",
+ author: {
+ name: "Example author",
+ url: "https://example.com/author",
+ },
+ }],
+ }),
+ onOpenThread: vi.fn(),
+ }), { createNodeMock: () => genericMock })
+ })
+
+ const links = renderer!.root.findAllByProps({ "data-message-external-link": true })
+ expect(links).toHaveLength(2)
+ expect(links.map((link) => link.props.href)).toEqual([
+ "https://example.com/author",
+ "https://example.com/story?from=embed",
+ ])
+ expect(links.every((link) => (
+ link.props.target === "_blank" && link.props.rel === "noopener noreferrer"
+ ))).toBe(true)
+ })
+})
+
describe("Message reaction picker", () => {
it("opens the non-hover picker and suppresses its Shadow DOM selection click at the row", async () => {
vi.stubGlobal("window", { getSelection: () => null })
diff --git a/src/web/src/components/community/messages/message.tsx b/src/web/src/components/community/messages/message.tsx
index 8ff3bd775..a26e9f0f0 100644
--- a/src/web/src/components/community/messages/message.tsx
+++ b/src/web/src/components/community/messages/message.tsx
@@ -11,6 +11,7 @@ import { ContextMenu, ContextMenuTrigger, ContextMenuContent } from "@/component
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from "@/components/ui/dropdown-menu"
import { Avatar } from "../avatar"
import { MessageBody } from "./message-body"
+import { MessageExternalLink } from "./message-external-link"
import { BotApprovalCard } from "../social/bot-approval-card"
import { EmojiPickerPopover } from "./emoji-picker"
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"
@@ -556,7 +557,7 @@ function MessageImpl({
<span className="grid size-5 place-items-center rounded-full bg-muted text-[9px] font-semibold text-muted-foreground">{avatarInitial(embed.author.name)}</span>
)}
{embed.author.url ? (
- <a href={embed.author.url} target="_blank" rel="noopener noreferrer" className="text-xs font-medium hover:underline">{embed.author.name}</a>
+ <MessageExternalLink href={embed.author.url} target="_blank" rel="noopener noreferrer" className="text-xs font-medium hover:underline">{embed.author.name}</MessageExternalLink>
) : (
<span className="text-xs font-medium">{embed.author.name}</span>
)}
@@ -564,7 +565,7 @@ function MessageImpl({
)}
{embed.provider && <div className="text-xs text-muted-foreground">{embed.provider}</div>}
{embed.url ? (
- <a href={embed.url} target="_blank" rel="noopener noreferrer" className="mt-1 block font-medium text-primary hover:underline">{embed.title}</a>
+ <MessageExternalLink href={embed.url} target="_blank" rel="noopener noreferrer" className="mt-1 block font-medium text-primary hover:underline">{embed.title}</MessageExternalLink>
) : (
<div className="mt-1 font-medium">{embed.title}</div>
)}
diff --git a/src/web/src/components/community/messages/platform-link-badge.test.ts b/src/web/src/components/community/messages/platform-link-badge.test.ts
index a2fa4b318..5453b290a 100644
--- a/src/web/src/components/community/messages/platform-link-badge.test.ts
+++ b/src/web/src/components/community/messages/platform-link-badge.test.ts
@@ -18,6 +18,7 @@ describe("PlatformLinkBadge", () => {
const link = renderer!.root.findByType("a")
expect(link.props["data-platform-link"]).toBe("alook")
+ expect(link.props["data-message-external-link"]).toBe(true)
expect(link.props["aria-label"]).toBe(
"Alook: https://alook.ai/c/invite/abcdef",
)
@@ -40,6 +41,7 @@ describe("PlatformLinkBadge", () => {
const link = renderer!.root.findByType("a")
expect(link.props["data-platform-link"]).toBe("github")
+ expect(link.props["data-message-external-link"]).toBe(true)
expect(link.props["aria-label"]).toBe("GitHub: https://github.com/alookai/alook/pull/598")
expect(link.props.target).toBe("_blank")
expect(renderer!.root.findAllByType("svg")).toHaveLength(1)
@@ -64,6 +66,7 @@ describe("PlatformLinkBadge", () => {
expect(link.props.className).toContain("platform-link-badge")
expect(link.props.className).toContain("existing-link")
expect(link.props["data-platform-link"]).toBe("generic")
+ expect(link.props["data-message-external-link"]).toBe(true)
expect(link.props["aria-label"]).toBe("Link: https://example.com/story")
expect(renderer!.root.findAllByType("svg")).toHaveLength(1)
expect(renderer!.root.findByType("span").children.join("")).toBe("Example story")
diff --git a/src/web/src/components/community/messages/platform-link-badge.tsx b/src/web/src/components/community/messages/platform-link-badge.tsx
index eea8a832f..3f2810ab6 100644
--- a/src/web/src/components/community/messages/platform-link-badge.tsx
+++ b/src/web/src/components/community/messages/platform-link-badge.tsx
@@ -13,6 +13,7 @@ import {
import type { PlatformLinkKind } from "@/lib/community/platform-link"
import { matchPlatformLink } from "@/lib/community/platform-link"
import { cn } from "@/lib/utils"
+import { MessageExternalLink } from "./message-external-link"
const ICONS = {
github: SiGithub,
@@ -39,7 +40,7 @@ export function PlatformLinkBadge({
const platform = matchPlatformLink(href)
if (!platform) {
return (
- <a
+ <MessageExternalLink
{...props}
href={href}
className={cn("platform-link-badge", className)}
@@ -48,7 +49,7 @@ export function PlatformLinkBadge({
>
<Link2 className="platform-link-badge-icon" aria-hidden="true" />
<span className="platform-link-badge-label">{children}</span>
- </a>
+ </MessageExternalLink>
)
}
@@ -69,7 +70,7 @@ export function PlatformLinkBadge({
return <Icon className="platform-link-badge-icon" aria-hidden="true" />
})()
return (
- <a
+ <MessageExternalLink
{...props}
href={href}
className={cn("platform-link-badge", className)}
@@ -78,6 +79,6 @@ export function PlatformLinkBadge({
>
{icon}
<span className="platform-link-badge-label">{children}</span>
- </a>
+ </MessageExternalLink>
)
}