Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): add streamdown mermaid + cjk plugins to chat rendering (#275)

Generf74c6c82e9ba
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8f86a4310..31d9ed065 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -213,6 +213,12 @@ importers:
'@opennextjs/cloudflare':
specifier: ^1.19.11
+ '@streamdown/cjk':
+ specifier: ^1.0.3
+ '@streamdown/mermaid':
+ specifier: ^1.0.2
+ version: 1.0.2([email protected])
'@tiptap/extension-image':
specifier: ^3.23.6
version: 3.23.6(@tiptap/[email protected](@tiptap/[email protected]))
@@ -354,7 +360,7 @@ importers:
version: 9.39.4([email protected])
eslint-config-next:
specifier: 16.2.6
eslint-plugin-tailwind-canonical-classes:
specifier: ^1.3.3
@@ -2653,6 +2659,16 @@ packages:
'@standard-schema/[email protected]':
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
+ '@streamdown/[email protected]':
+ resolution: {integrity: sha512-WRg8HR/gHbBoTgsMd91OKFUClIoDcEFVofJvluvEAyjx3KpU0aGgD9tGDqHkHj14ShoMSkX0IYetWGegTcwIJw==}
+ peerDependencies:
+ react: ^18.0.0 || ^19.0.0
+
+ '@streamdown/[email protected]':
+ resolution: {integrity: sha512-Fr/4sBWnAeSnxM3PcrV/+DiZe5oPMq9gOkUIAH7ZauJeuwrZ/DVzD4g0zlav6AH0axh2m/sOfrfLtY5aLT7niw==}
+ peerDependencies:
+ react: ^18.0.0 || ^19.0.0
+
resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==}
@@ -5941,6 +5957,35 @@ packages:
resolution: {integrity: sha512-RDBrHEMSxVFLg6xvnXmb1Ayr2WzLAWjeSATAoxwKYJV94TeNavgoIdA0a9ytzDSVzBy2YKFK+emCPOEibLeCrg==}
+ resolution: {integrity: sha512-wVC0zwjJNqQeX+bb07YTPu/CvSAyCTafyYb7sMhX1r62/Lw5M/df3JyYaANyp8g15c1ypJRFSsookTqA1IDsUg==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ micromark: ^4.0.0
+ micromark-util-types: ^2.0.0
+ peerDependenciesMeta:
+ micromark-util-types:
+ optional: true
+
+ resolution: {integrity: sha512-GcbXqTTHOsiZHyF753oIddP/J2eH8j9zpyQPhkof6B2JNxfEJabnQqxbCgzJNuNes0Y2jTNJ3LiYPSXr6eJA8w==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ micromark-util-types: '*'
+ peerDependenciesMeta:
+ micromark-util-types:
+ optional: true
+
+ resolution: {integrity: sha512-OkzoYVTL1ChbvQ8Cc1ayTIz7paFQz8iS9oIYmewncweUSwmWR+hkJF9spJ1lxB90XldJl26A1F4IkPOKS3bDXw==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ micromark: ^4.0.0
+ micromark-util-types: ^2.0.0
+ peerDependenciesMeta:
+ micromark-util-types:
+ optional: true
+
resolution: {integrity: sha512-oOg7knzhicgQ3t4QCjCWgTmfNhvQbDDnJeVu9v81r7NltNCVmhPy1fJRX27pISafdjL+SVc4d3l48Gb6pbRypw==}
@@ -6747,6 +6792,26 @@ packages:
resolution: {integrity: sha512-lWyvf/jwu+oS5+hL5eClVd3hNdmwM1kAC0BUvEGD19pajQMIzcNUd/k9GsfQ+FfECvX+JE+e9/btsKH0EjJT6A==}
+ resolution: {integrity: sha512-pWKj25O2eLXIL1aBupayl1fKhco+Brw8qWUWJPVB9EBzbQNd7nGLj0nLmJpggWsGLR5j5y40PIdjxby9IEYTuA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ '@types/mdast': ^4.0.0
+ unified: ^11.0.0
+ peerDependenciesMeta:
+ '@types/mdast':
+ optional: true
+
+ resolution: {integrity: sha512-6WwkoQyZf/4j5k53zdFYrR8Ca+UVn992jXdLUSBDZR4eBpFhKyVxmA4gUHra/5fesjGIxrDhHesNr/sVoiiysA==}
+ engines: {node: '>=18'}
+ peerDependencies:
+ '@types/mdast': ^4.0.0
+ unified: ^11.0.0
+ peerDependenciesMeta:
+ '@types/mdast':
+ optional: true
+
resolution: {integrity: sha512-1quofZ2RQ9EWdeN34S79+KExV1764+wCUGop5CPL1WGdD0ocPpu91lzPGbwWMECpEpd42kJGQwzRfyov9j4yNg==}
@@ -10241,6 +10306,23 @@ snapshots:
'@standard-schema/[email protected]': {}
+ dependencies:
+ react: 19.2.6
+ remark-cjk-friendly-gfm-strikethrough: 2.0.1(@types/[email protected])([email protected])([email protected])([email protected])
+ unist-util-visit: 5.1.0
+ transitivePeerDependencies:
+ - '@types/mdast'
+ - micromark
+ - micromark-util-types
+ - unified
+
+ dependencies:
+ mermaid: 11.14.0
+ react: 19.2.6
+
dependencies:
tslib: 2.8.1
@@ -12273,13 +12355,13 @@ snapshots:
optionalDependencies:
source-map: 0.6.1
dependencies:
'@next/eslint-plugin-next': 16.2.6
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
+ eslint-plugin-import: 2.32.0([email protected])([email protected]([email protected]))
eslint-plugin-jsx-a11y: 6.10.2([email protected]([email protected]))
eslint-plugin-react: 7.37.5([email protected]([email protected]))
eslint-plugin-react-hooks: 7.1.1([email protected]([email protected]))
@@ -12312,22 +12394,21 @@ snapshots:
tinyglobby: 0.2.16
unrs-resolver: 1.11.1
optionalDependencies:
+ eslint-plugin-import: 2.32.0([email protected])([email protected]([email protected]))
transitivePeerDependencies:
- supports-color
dependencies:
debug: 3.2.7
optionalDependencies:
- '@typescript-eslint/parser': 8.59.4([email protected]([email protected]))([email protected])
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
eslint-import-resolver-typescript: 3.10.1([email protected])([email protected]([email protected]))
transitivePeerDependencies:
- supports-color
dependencies:
'@rtsao/scc': 1.1.0
array-includes: 3.1.9
@@ -12338,7 +12419,7 @@ snapshots:
doctrine: 2.1.0
eslint: 9.39.4([email protected])
eslint-import-resolver-node: 0.3.10
hasown: 2.0.3
is-core-module: 2.16.2
is-glob: 4.0.3
@@ -12349,8 +12430,6 @@ snapshots:
semver: 6.3.1
string.prototype.trimend: 1.0.9
tsconfig-paths: 3.15.0
- optionalDependencies:
- '@typescript-eslint/parser': 8.59.4([email protected]([email protected]))([email protected])
transitivePeerDependencies:
- eslint-import-resolver-typescript
- eslint-import-resolver-webpack
@@ -14049,6 +14128,38 @@ snapshots:
micromark-util-symbol: 2.0.1
micromark-util-types: 2.0.2
+ dependencies:
+ devlop: 1.1.0
+ get-east-asian-width: 1.6.0
+ micromark: 4.0.2
+ micromark-extension-cjk-friendly-util: 3.0.1([email protected])
+ micromark-util-character: 2.1.1
+ micromark-util-chunked: 2.0.1
+ micromark-util-resolve-all: 2.0.1
+ micromark-util-symbol: 2.0.1
+ optionalDependencies:
+ micromark-util-types: 2.0.2
+
+ dependencies:
+ get-east-asian-width: 1.6.0
+ micromark-util-character: 2.1.1
+ micromark-util-symbol: 2.0.1
+ optionalDependencies:
+ micromark-util-types: 2.0.2
+
+ dependencies:
+ devlop: 1.1.0
+ micromark: 4.0.2
+ micromark-extension-cjk-friendly-util: 3.0.1([email protected])
+ micromark-util-chunked: 2.0.1
+ micromark-util-resolve-all: 2.0.1
+ micromark-util-symbol: 2.0.1
+ optionalDependencies:
+ micromark-util-types: 2.0.2
+
dependencies:
micromark-util-character: 2.1.1
@@ -15166,6 +15277,26 @@ snapshots:
hast-util-to-string: 3.0.1
unist-util-visit: 5.1.0
+ dependencies:
+ micromark-extension-cjk-friendly-gfm-strikethrough: 2.0.1([email protected])([email protected])
+ unified: 11.0.5
+ optionalDependencies:
+ '@types/mdast': 4.0.4
+ transitivePeerDependencies:
+ - micromark
+ - micromark-util-types
+
+ dependencies:
+ micromark-extension-cjk-friendly: 2.0.1([email protected])([email protected])
+ unified: 11.0.5
+ optionalDependencies:
+ '@types/mdast': 4.0.4
+ transitivePeerDependencies:
+ - micromark
+ - micromark-util-types
+
dependencies:
'@types/mdast': 4.0.4
diff --git a/src/web/package.json b/src/web/package.json
index 1a9decb36..7cf6bf1cd 100644
--- a/src/web/package.json
+++ b/src/web/package.json
@@ -34,6 +34,8 @@
"@next/mdx": "^16.2.6",
"@next/third-parties": "^16.2.6",
"@opennextjs/cloudflare": "^1.19.11",
+ "@streamdown/cjk": "^1.0.3",
+ "@streamdown/mermaid": "^1.0.2",
"@tiptap/extension-image": "^3.23.6",
"@tiptap/extension-link": "^3.23.6",
"@tiptap/extension-mention": "^3.23.6",
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index 1bab45168..45245288f 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -2,6 +2,8 @@
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@source "../node_modules/streamdown/dist/*.js";
+@source "../node_modules/@streamdown/mermaid/dist/*.js";
+@source "../node_modules/@streamdown/cjk/dist/*.js";
@custom-variant dark (&:is(.dark *));
@@ -1389,6 +1391,90 @@ html.dark .blog-content [data-rehype-pretty-code-figure] span {
pointer-events: auto;
}
+/* ── Streamdown mermaid block: match code-block visual style ── */
+
+/* Outer container: clean border + radius (overflow visible for dropdown menus) */
+[data-streamdown="mermaid-block"] {
+ position: relative !important;
+ padding: 0 !important;
+ margin-top: 0.5em !important;
+ margin-bottom: 0.5em !important;
+ gap: 0 !important;
+ border: 1px solid oklch(1 0 0 / 8%) !important;
+ border-radius: var(--radius-md) !important;
+ overflow: visible !important;
+ background: var(--background) !important;
+}
+
+/* Header ("mermaid" label): absolute top-left, show on hover */
+[data-streamdown="mermaid-block"] > div:first-child {
+ position: absolute !important;
+ top: 0.375rem;
+ left: 0.625rem;
+ z-index: 5;
+ height: auto !important;
+ padding: 0 !important;
+ background: transparent !important;
+ font-size: 0.7rem;
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 150ms ease;
+}
+[data-streamdown="mermaid-block"]:hover > div:first-child {
+ opacity: 0.5;
+}
+
+/* Actions wrapper: absolute top-right, invisible and non-interactive by default */
+[data-streamdown="mermaid-block"] > div:has([data-streamdown="mermaid-block-actions"]) {
+ position: absolute !important;
+ top: 0.375rem;
+ right: 0.375rem;
+ z-index: 10;
+ margin-top: 0 !important;
+ height: auto !important;
+ pointer-events: none;
+}
+
+/* On hover of the ENTIRE mermaid block: make actions interactive */
+[data-streamdown="mermaid-block"]:hover > div:has([data-streamdown="mermaid-block-actions"]) {
+ pointer-events: auto;
+}
+
+/* Actions buttons: fade in on hover */
+[data-streamdown="mermaid-block-actions"] {
+ opacity: 0;
+ transition: opacity 150ms ease;
+}
+[data-streamdown="mermaid-block"]:hover [data-streamdown="mermaid-block-actions"] {
+ opacity: 1;
+}
+
+/* Mermaid download dropdown menu */
+[data-streamdown="mermaid-block-actions"] .absolute {
+ z-index: 50 !important;
+ min-width: 10rem;
+ color: var(--foreground) !important;
+ background: var(--background) !important;
+ border-color: var(--border) !important;
+}
+
+/* Diagram content area */
+[data-streamdown="mermaid-block"] > div:last-child {
+ margin: 0 !important;
+ border: none !important;
+ border-radius: var(--radius-md) !important;
+ padding: 1rem !important;
+ overflow: hidden;
+}
+
+/* Mermaid node shapes: add rounded corners to rectangles */
+[data-streamdown="mermaid-block"] .node rect,
+[data-streamdown="mermaid-block"] .node .basic {
+ rx: 8 !important;
+ ry: 8 !important;
+}
+
+
/* ── Streamdown table: strip wrapper chrome, clean rows ── */
/* Outer wrapper: strip bg-sidebar, border, padding, gap, rounded */
diff --git a/src/web/src/components/agent-chat/message-list.tsx b/src/web/src/components/agent-chat/message-list.tsx
index 6827f5383..355195d1f 100644
--- a/src/web/src/components/agent-chat/message-list.tsx
+++ b/src/web/src/components/agent-chat/message-list.tsx
@@ -5,6 +5,7 @@ import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
import { Streamdown } from "streamdown";
+import { mermaid, cjk } from "@/lib/streamdown-plugins";
import { highlightMentions } from "@/lib/highlight-mentions";
import { TaskStream } from "@/components/task-stream";
import { HistoricalTaskThinking } from "@/components/agent-chat/historical-task-thinking";
@@ -243,7 +244,7 @@ export const MessageItem = memo(function MessageItem({
)}
{messageBody && (
<div className="markdown markdown-user">
- <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: false, download: false, fullscreen: false } }} linkSafety={{ enabled: false }} allowedTags={MENTION_ALLOWED_TAGS} literalTagContent={MENTION_LITERAL_TAGS} components={mentionComponents}>{highlightMentions(messageBody, agents)}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }} controls={{ code: { copy: true, download: false }, table: { copy: false, download: false, fullscreen: false } }} linkSafety={{ enabled: false }} allowedTags={MENTION_ALLOWED_TAGS} literalTagContent={MENTION_LITERAL_TAGS} components={mentionComponents}>{highlightMentions(messageBody, agents)}</Streamdown>
</div>
)}
{msg.attachment_ids && msg.attachment_ids.length > 0 && (
@@ -291,7 +292,7 @@ export const MessageItem = memo(function MessageItem({
</div>
) : (
<div className="markdown max-w-full min-w-0 px-1 py-1 text-base text-foreground">
- <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }} allowedTags={MENTION_ALLOWED_TAGS} literalTagContent={MENTION_LITERAL_TAGS} components={mentionComponents}>{highlightMentions(msg.content, agents)}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }} controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }} allowedTags={MENTION_ALLOWED_TAGS} literalTagContent={MENTION_LITERAL_TAGS} components={mentionComponents}>{highlightMentions(msg.content, agents)}</Streamdown>
</div>
)}
{actionButtons}
diff --git a/src/web/src/components/artifact-content-renderer.tsx b/src/web/src/components/artifact-content-renderer.tsx
index 06e54ddec..88dfa8674 100644
--- a/src/web/src/components/artifact-content-renderer.tsx
+++ b/src/web/src/components/artifact-content-renderer.tsx
@@ -5,6 +5,7 @@ import { getArtifactContent } from "@/lib/api";
import type { Artifact } from "@alook/shared";
import { Loader2, Download } from "lucide-react";
import { Streamdown } from "streamdown";
+import { mermaid, cjk } from "@/lib/streamdown-plugins";
const TEXT_TYPES = new Set([
"application/json",
@@ -111,7 +112,7 @@ export function ArtifactContentRenderer({ artifact, workspaceId }: ArtifactConte
if (isMarkdown(artifact.filename)) {
return (
<div className="markdown text-sm">
- <Streamdown>{content ?? ""}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }}>{content ?? ""}</Streamdown>
</div>
);
}
diff --git a/src/web/src/components/issues/issue-sheet.tsx b/src/web/src/components/issues/issue-sheet.tsx
index 4080f563d..84841bcd2 100644
--- a/src/web/src/components/issues/issue-sheet.tsx
+++ b/src/web/src/components/issues/issue-sheet.tsx
@@ -36,6 +36,7 @@ import Link from "next/link";
import { cn } from "@/lib/utils";
import { toast } from "sonner";
import { Streamdown } from "streamdown";
+import { mermaid, cjk } from "@/lib/streamdown-plugins";
import type { Agent, Artifact, Issue, IssueComment, Message, TaskApi } from "@alook/shared";
import { isPreviewable, getArtifactUrl } from "@/components/artifact-content-renderer";
import { formatSize } from "@/components/agent-chat/artifact-sheet";
@@ -124,7 +125,7 @@ function MessageRow({ message }: { message: Message }) {
<span>{new Date(message.created_at).toLocaleString()}</span>
</div>
<div className="prose prose-sm dark:prose-invert max-w-none text-sm wrap-break-word">
- <Streamdown>{message.content}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }}>{message.content}</Streamdown>
</div>
</div>
);
@@ -141,7 +142,7 @@ function CommentRow({ comment, agents }: { comment: IssueComment; agents: Agent[
<span>{new Date(comment.created_at).toLocaleString()}</span>
</div>
<div className="prose prose-sm dark:prose-invert max-w-none text-sm wrap-break-word">
- <Streamdown>{comment.content}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }}>{comment.content}</Streamdown>
</div>
</div>
);
diff --git a/src/web/src/components/task-stream.tsx b/src/web/src/components/task-stream.tsx
index 8ff8e7be6..d2c35d435 100644
--- a/src/web/src/components/task-stream.tsx
+++ b/src/web/src/components/task-stream.tsx
@@ -10,6 +10,7 @@ import {
Loader2,
} from "lucide-react";
import { Streamdown } from "streamdown";
+import { mermaid, cjk } from "@/lib/streamdown-plugins";
import { RuntimeErrorBlock } from "@/components/agent-chat/runtime-error-block";
/* ── Grouped stream items ── */
@@ -221,7 +222,7 @@ export function TaskStream({
)}
{intermediateTextItems.map((item) => (
<div key={item.id} className="markdown max-w-full min-w-0 px-1 text-sm text-muted-foreground">
- <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{item.content}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }} controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{item.content}</Streamdown>
</div>
))}
</div>
@@ -230,7 +231,7 @@ export function TaskStream({
{/* Final text — shown after completion (not for historical tasks which render it as a message) */}
{hasFinalText && !onExpandThinking && (
<div className="markdown max-w-full min-w-0 px-1 py-1 text-base text-foreground">
- <Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{finalTextItem.content}</Streamdown>
+ <Streamdown plugins={{ mermaid, cjk }} controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }}>{finalTextItem.content}</Streamdown>
</div>
)}
diff --git a/src/web/src/lib/streamdown-plugins.ts b/src/web/src/lib/streamdown-plugins.ts
new file mode 100644
index 000000000..e6c8d58eb
--- /dev/null
+++ b/src/web/src/lib/streamdown-plugins.ts
@@ -0,0 +1,27 @@
+import { createMermaidPlugin } from "@streamdown/mermaid";
+export { cjk } from "@streamdown/cjk";
+
+export const mermaid = createMermaidPlugin({
+ config: {
+ theme: "base",
+ themeVariables: {
+ primaryColor: "#eceae6",
+ primaryTextColor: "#2d2a26",
+ primaryBorderColor: "#e0ddd9",
+ lineColor: "#7d7972",
+ secondaryColor: "#f5f4f2",
+ tertiaryColor: "#faf9f8",
+ noteBkgColor: "#f5f4f2",
+ noteTextColor: "#2d2a26",
+ noteBorderColor: "#e0ddd9",
+ textColor: "#2d2a26",
+ mainBkg: "#eceae6",
+ nodeBorder: "#e0ddd9",
+ clusterBkg: "#f5f4f2",
+ clusterBorder: "#e0ddd9",
+ edgeLabelBackground: "#fdfcfb",
+ fontSize: "14px",
+ },
+ fontFamily: "ui-sans-serif, system-ui, sans-serif",
+ },
+});