Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
feat(open-knowledge): render standalone .mmd / .mermaid files as diagrams (#2485)
Abraham9668fb109f62
diff --git a/packages/app/src/components/AssetPreview.tsx b/packages/app/src/components/AssetPreview.tsxindex 6dc66afc4..fe4c97f54 100644--- a/packages/app/src/components/AssetPreview.tsx+++ b/packages/app/src/components/AssetPreview.tsx@@ -1,6 +1,7 @@import { type InlineAssetMediaKind, toDesktopAssetHref } from '@inkeep/open-knowledge-core';import { Trans } from '@lingui/react/macro';import { useState } from 'react';+import { MermaidFileViewer } from '@/components/MermaidFileViewer';import { TextViewer } from '@/components/TextViewer';import { Button } from '@/components/ui/button';import { LoadingImage } from '@/components/ui/loading-image';@@ -87,6 +88,24 @@ export function AssetPreview({ assetPath, mediaKind }: AssetPreviewProps) {);}+ // Standalone Mermaid diagram files (`.mmd` / `.mermaid`). Fetched via+ // the same ungated `/api/asset-text` byte path as `TextViewer`, then+ // rendered through the editor's `<Mermaid>` component so theming and+ // parse-error advisories match ` ```mermaid ` fences in docs. The+ // viewer exposes a Source toggle so non-Mermaid content that shares+ // the extension (MultiMarkdown, hand-authored fragments) is still+ // readable.+ if (effectiveMediaKind === 'mermaid') {+ return (+ <MermaidFileViewer+ key={assetPath}+ src={assetTextUrl(assetPath)}+ fileName={fileName}+ extension={rawExtension.toLowerCase()}+ />+ );+ }+return (<main className="flex h-full min-h-0 flex-col bg-background" aria-label={fileName}><div className="flex min-h-0 flex-1 items-center justify-center overflow-auto p-4">diff --git a/packages/app/src/components/MermaidFileViewer.tsx b/packages/app/src/components/MermaidFileViewer.tsxnew file mode 100644index 000000000..586919f80--- /dev/null+++ b/packages/app/src/components/MermaidFileViewer.tsx@@ -0,0 +1,149 @@+/**+ * Read-only viewer for a standalone Mermaid diagram file+ * (`.mmd` / `.mermaid`). Fetches the raw text via the ungated+ * `/api/asset-text` endpoint — same fetch path as `TextViewer` — and hands+ * the source to the editor's `<Mermaid>` component. Because Mermaid is+ * the single-source-of-truth renderer here (identical theming + parse-+ * error advisory as ` ```mermaid ` fences inside docs), keeping the file+ * viewer as a thin wrapper avoids a parallel diagram-render surface.+ *+ * The segmented Diagram ⇄ Source toggle mirrors `EditorModeToggle` (same+ * `ToggleGroup` primitives, sizing, and top-of-pane placement) so the+ * file viewer reads as "the same control we use for md docs" rather+ * than a bespoke pane. MermaidView's own error state renders the+ * offending source below its advisory; we hide that copy inside this+ * wrapper so parse failures show exactly one path to the raw bytes —+ * the Source toggle.+ *+ * STOP: do not bind this viewer to a Y.Doc. `.mmd`/`.mermaid` are NOT in+ * `SUPPORTED_DOC_EXTENSIONS` — the file is read-only by contract. Editing+ * .mmd in place is a separate slice.+ */++import { Trans, useLingui } from '@lingui/react/macro';+import { Code, Workflow } from 'lucide-react';+import { useState } from 'react';+import { TextViewer } from '@/components/TextViewer';+import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';+import { MermaidView } from '@/editor/components/Mermaid';+import { useViewerText, type ViewerTextSource } from './use-viewer-text';+import { ViewerErrorPane, ViewerLoadingPane } from './ViewerStatusPane';++type MermaidFileViewerProps = ViewerTextSource & {+ fileName: string;+ /** Lowercased, dot-stripped (e.g. `mmd`, not `.MMD`). */+ extension: string;+};++type Mode = 'diagram' | 'source';++export function MermaidFileViewer({ fileName, extension, ...source }: MermaidFileViewerProps) {+ const { t } = useLingui();+ const [mode, setMode] = useState<Mode>('diagram');+ const fetchState = useViewerText(source);++ const extraAttrs = { 'data-mermaid-file-viewer-extension': extension };++ if (fetchState.status === 'loading') {+ return (+ <ViewerLoadingPane+ fileName={fileName}+ dataAttr="data-mermaid-file-viewer"+ extraAttrs={extraAttrs}+ />+ );+ }++ if (fetchState.status === 'error') {+ return (+ <ViewerErrorPane+ fileName={fileName}+ dataAttr="data-mermaid-file-viewer"+ extraAttrs={extraAttrs}+ message={fetchState.message}+ openHref={source.src}+ />+ );+ }++ const text = fetchState.content;++ return (+ <main+ className="flex h-full min-h-0 flex-col bg-background"+ aria-label={fileName}+ data-mermaid-file-viewer=""+ data-mermaid-file-viewer-state="loaded"+ data-mermaid-file-viewer-mode={mode}+ {...extraAttrs}+ >+ <div className="flex shrink-0 items-center justify-center border-b bg-background py-2">+ <ToggleGroup+ type="single"+ value={mode}+ onValueChange={(v: Mode | '') => {+ if (v) setMode(v);+ }}+ aria-label={t`Diagram view mode`}+ variant="segmented"+ size="sm"+ spacing={1}+ className="shrink-0 bg-muted p-0.5 data-[size=sm]:rounded-[10px]"+ >+ <Tooltip>+ <ToggleGroupItem+ value="diagram"+ aria-label={t`Show diagram`}+ className="size-7 px-0 dark:data-[state=on]:bg-foreground/15"+ asChild+ >+ <TooltipTrigger>+ <Workflow className="size-4" />+ </TooltipTrigger>+ </ToggleGroupItem>+ <TooltipContent side="bottom">+ <Trans>Diagram</Trans>+ </TooltipContent>+ </Tooltip>+ <Tooltip>+ <ToggleGroupItem+ value="source"+ aria-label={t`Show source`}+ className="size-7 px-0 dark:data-[state=on]:bg-foreground/15"+ asChild+ >+ <TooltipTrigger>+ <Code className="size-4" />+ </TooltipTrigger>+ </ToggleGroupItem>+ <TooltipContent side="bottom">+ <Trans>Source</Trans>+ </TooltipContent>+ </Tooltip>+ </ToggleGroup>+ </div>+ <div className="min-h-0 flex-1 overflow-hidden">+ {mode === 'diagram' ? (+ // `[&_.mermaid-error-source]:hidden` suppresses MermaidView's+ // in-error raw-source `<pre>` — the Source toggle already carries+ // that responsibility, and rendering the file twice on parse+ // failure (advisory + inline source pane below) reads as+ // duplication rather than diagnosis.+ <div className="flex h-full min-h-0 flex-col p-3 [&_.mermaid-error-source]:hidden">+ <MermaidView chart={text} className="min-h-0 flex-1" />+ </div>+ ) : (+ // Source-mode fallback and copy-the-raw-bytes affordance. Reusing+ // `TextViewer` (rather than a bare `<pre>`) so theme, line+ // numbering, Cmd-A, and read-only semantics match every other+ // source view in the app. The extension stays `mmd` even for+ // `.mermaid` files — CodeMirror has no Mermaid grammar so it+ // falls through to plain-text anyway; the label just needs to+ // read consistently.+ <TextViewer {...source} fileName={fileName} extension={extension} />+ )}+ </div>+ </main>+ );+}diff --git a/packages/app/src/lib/sidebar-drag.ts b/packages/app/src/lib/sidebar-drag.tsindex 707b921dc..dbb37d4d6 100644--- a/packages/app/src/lib/sidebar-drag.ts+++ b/packages/app/src/lib/sidebar-drag.ts@@ -19,6 +19,7 @@ const INLINE_ASSET_MEDIA_KIND_VALUES = {audio: true,pdf: true,text: true,+ mermaid: true,} satisfies Record<InlineAssetMediaKind, true>;export function serializeSidebarDragPayload(payload: SidebarDragPayload): string {diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.jsonindex d168127cf..f3d9480ba 100644--- a/packages/app/src/locales/en/messages.json+++ b/packages/app/src/locales/en/messages.json@@ -320,6 +320,7 @@"6s7LXO": ["Heads up"],"6u9LvN": [["days", "plural", { "one": ["#", " day ago"], "other": ["#", " days ago"] }]],"6vEr3W": ["Link target"],+ "72xhRD": ["Diagram view mode"],"74-bX-": ["A pull quote stands out from the surrounding text."],"74eHt-": ["No file or folder selected"],"75Y1dk": ["Horizontal pill strip + active panel below; click a pill to switch panels."],@@ -543,6 +544,7 @@"D8OV7J": ["Only collaborators"],"DDTdLl": ["Code block settings"],"DELNQk": ["Collaborators see your in-progress edits as soon as they sync."],+ "DEWDbv": ["Show diagram"],"DF1MtZ": ["Loading conflict for ", ["filePath"]],"DFfRbX": ["Sync status: ", ["syncStateLabel"], " — git identity unset"],"DId6MT": ["Project-level pages with no outgoing graph edges."],@@ -1346,6 +1348,7 @@["pickedRelative"],"</1> because it contains a <2>.git</2> folder (one .ok/ per git repo). <3>Content directory</3> defaults to <4>.</4> (the whole repo); type a sub-folder to narrow it."],+ "Y6SK9K": ["Show source"],"Y8ViJx": ["A newer version may have been deployed since this tab opened."],"YC6_wP": ["Edit ", ["keyName"]],"YEP3X2": ["Delete a table when the active table cell selection covers the full table."],@@ -1733,6 +1736,7 @@"hxEUVJ": ["Initialize ", ["selectedPackName"]],"hyCxJY": ["Open that worktree instead"],"hynz2K": ["Download started"],+ "i-ShMB": ["Diagram"],"i1flq_": ["Wiki link suggestions"],"i3f2kh": ["No matching commands."],"i92eAT": ["We'll create a repository and start syncing — no terminal needed."],@@ -2288,6 +2292,7 @@"w_Sphq": ["Attachments"],"wbv9xO": ["Create new project"],"wbwHYD": ["Enable sync"],+ "wdxz7K": ["Source"],"weP6me": ["Couldn't load docs — type @ again to retry"],"wlwXUk": ["You picked ~/Downloads. Files there are usually transient — consider a stable folder instead."diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.poindex d6983267c..733339588 100644--- a/packages/app/src/locales/en/messages.po+++ b/packages/app/src/locales/en/messages.po@@ -2291,10 +2291,18 @@ msgstr "Detected from the editors this project is set up for. Adjust to controlmsgid "Detecting"msgstr "Detecting"+#: src/components/MermaidFileViewer.tsx+msgid "Diagram"+msgstr "Diagram"+#: src/editor/slash-command/component-items.tsxmsgid "Diagram from Mermaid source — flowchart, sequence, class, state, ER, gantt, pie."msgstr "Diagram from Mermaid source — flowchart, sequence, class, state, ER, gantt, pie."+#: src/components/MermaidFileViewer.tsx+msgid "Diagram view mode"+msgstr "Diagram view mode"+#: src/components/TimelinePanel.tsxmsgid "Diff layout"msgstr "Diff layout"@@ -6141,6 +6149,10 @@ msgstr "Show {hidden} more"msgid "Show advanced"msgstr "Show advanced"+#: src/components/MermaidFileViewer.tsx+msgid "Show diagram"+msgstr "Show diagram"+#: src/components/GraphPanel.tsxmsgid "Show external URL nodes"msgstr "Show external URL nodes"@@ -6202,6 +6214,10 @@ msgstr "Show replace"msgid "Show selection preview"msgstr "Show selection preview"+#: src/components/MermaidFileViewer.tsx+msgid "Show source"+msgstr "Show source"+#: src/components/TerminalRevealTab.tsxmsgid "Show terminal"msgstr "Show terminal"@@ -6323,6 +6339,10 @@ msgstr "Something went wrong starting the terminal."msgid "Something went wrong. Please try again."msgstr "Something went wrong. Please try again."+#: src/components/MermaidFileViewer.tsx+msgid "Source"+msgstr "Source"+#: src/lib/keyboard-shortcuts.tsmsgid "Source editing"msgstr "Source editing"diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.jsonindex 61022f93e..2002d79ae 100644--- a/packages/app/src/locales/pseudo/messages.json+++ b/packages/app/src/locales/pseudo/messages.json@@ -320,6 +320,7 @@"6s7LXO": ["Ĥēàďś ũƥ"],"6u9LvN": [["days", "plural", { "one": ["#", " ďàŷ àĝō"], "other": ["#", " ďàŷś àĝō"] }]],"6vEr3W": ["Ĺĩńķ ţàŕĝēţ"],+ "72xhRD": ["Ďĩàĝŕàḿ vĩēŵ ḿōďē"],"74-bX-": ["À ƥũĺĺ ǫũōţē śţàńďś ōũţ ƒŕōḿ ţĥē śũŕŕōũńďĩńĝ ţēxţ."],"74eHt-": ["Ńō ƒĩĺē ōŕ ƒōĺďēŕ śēĺēćţēď"],"75Y1dk": ["Ĥōŕĩźōńţàĺ ƥĩĺĺ śţŕĩƥ + àćţĩvē ƥàńēĺ ƀēĺōŵ; ćĺĩćķ à ƥĩĺĺ ţō śŵĩţćĥ ƥàńēĺś."],@@ -543,6 +544,7 @@"D8OV7J": ["Ōńĺŷ ćōĺĺàƀōŕàţōŕś"],"DDTdLl": ["Ćōďē ƀĺōćķ śēţţĩńĝś"],"DELNQk": ["Ćōĺĺàƀōŕàţōŕś śēē ŷōũŕ ĩń-ƥŕōĝŕēśś ēďĩţś àś śōōń àś ţĥēŷ śŷńć."],+ "DEWDbv": ["Śĥōŵ ďĩàĝŕàḿ"],"DF1MtZ": ["Ĺōàďĩńĝ ćōńƒĺĩćţ ƒōŕ ", ["filePath"]],"DFfRbX": ["Śŷńć śţàţũś: ", ["syncStateLabel"], " — ĝĩţ ĩďēńţĩţŷ ũńśēţ"],"DId6MT": ["ƤŕōĴēćţ-ĺēvēĺ ƥàĝēś ŵĩţĥ ńō ōũţĝōĩńĝ ĝŕàƥĥ ēďĝēś."],@@ -1346,6 +1348,7 @@["pickedRelative"],"</1> ƀēćàũśē ĩţ ćōńţàĩńś à <2>.ĝĩţ</2> ƒōĺďēŕ (ōńē .ōķ/ ƥēŕ ĝĩţ ŕēƥō). <3>Ćōńţēńţ ďĩŕēćţōŕŷ</3> ďēƒàũĺţś ţō <4>.</4> (ţĥē ŵĥōĺē ŕēƥō); ţŷƥē à śũƀ-ƒōĺďēŕ ţō ńàŕŕōŵ ĩţ."],+ "Y6SK9K": ["Śĥōŵ śōũŕćē"],"Y8ViJx": ["À ńēŵēŕ vēŕśĩōń ḿàŷ ĥàvē ƀēēń ďēƥĺōŷēď śĩńćē ţĥĩś ţàƀ ōƥēńēď."],"YC6_wP": ["Ēďĩţ ", ["keyName"]],"YEP3X2": ["Ďēĺēţē à ţàƀĺē ŵĥēń ţĥē àćţĩvē ţàƀĺē ćēĺĺ śēĺēćţĩōń ćōvēŕś ţĥē ƒũĺĺ ţàƀĺē."],@@ -1733,6 +1736,7 @@"hxEUVJ": ["Ĩńĩţĩàĺĩźē ", ["selectedPackName"]],"hyCxJY": ["Ōƥēń ţĥàţ ŵōŕķţŕēē ĩńśţēàď"],"hynz2K": ["Ďōŵńĺōàď śţàŕţēď"],+ "i-ShMB": ["Ďĩàĝŕàḿ"],"i1flq_": ["Ŵĩķĩ ĺĩńķ śũĝĝēśţĩōńś"],"i3f2kh": ["Ńō ḿàţćĥĩńĝ ćōḿḿàńďś."],"i92eAT": ["Ŵē'ĺĺ ćŕēàţē à ŕēƥōśĩţōŕŷ àńď śţàŕţ śŷńćĩńĝ — ńō ţēŕḿĩńàĺ ńēēďēď."],@@ -2288,6 +2292,7 @@"w_Sphq": ["Àţţàćĥḿēńţś"],"wbv9xO": ["Ćŕēàţē ńēŵ ƥŕōĴēćţ"],"wbwHYD": ["Ēńàƀĺē śŷńć"],+ "wdxz7K": ["Śōũŕćē"],"weP6me": ["Ćōũĺďń'ţ ĺōàď ďōćś — ţŷƥē @ àĝàĩń ţō ŕēţŕŷ"],"wlwXUk": ["Ŷōũ ƥĩćķēď ~/Ďōŵńĺōàďś. Ƒĩĺēś ţĥēŕē àŕē ũśũàĺĺŷ ţŕàńśĩēńţ — ćōńśĩďēŕ à śţàƀĺē ƒōĺďēŕ ĩńśţēàď."diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.poindex a035282ae..de3880145 100644--- a/packages/app/src/locales/pseudo/messages.po+++ b/packages/app/src/locales/pseudo/messages.po@@ -2286,10 +2286,18 @@ msgstr ""msgid "Detecting"msgstr ""+#: src/components/MermaidFileViewer.tsx+msgid "Diagram"+msgstr ""+#: src/editor/slash-command/component-items.tsxmsgid "Diagram from Mermaid source — flowchart, sequence, class, state, ER, gantt, pie."msgstr ""+#: src/components/MermaidFileViewer.tsx+msgid "Diagram view mode"+msgstr ""+#: src/components/TimelinePanel.tsxmsgid "Diff layout"msgstr ""@@ -6136,6 +6144,10 @@ msgstr ""msgid "Show advanced"msgstr ""+#: src/components/MermaidFileViewer.tsx+msgid "Show diagram"+msgstr ""+#: src/components/GraphPanel.tsxmsgid "Show external URL nodes"msgstr ""@@ -6197,6 +6209,10 @@ msgstr ""msgid "Show selection preview"msgstr ""+#: src/components/MermaidFileViewer.tsx+msgid "Show source"+msgstr ""+#: src/components/TerminalRevealTab.tsxmsgid "Show terminal"msgstr ""@@ -6318,6 +6334,10 @@ msgstr ""msgid "Something went wrong. Please try again."msgstr ""+#: src/components/MermaidFileViewer.tsx+msgid "Source"+msgstr ""+#: src/lib/keyboard-shortcuts.tsmsgid "Source editing"msgstr ""diff --git a/packages/core/src/constants/upload.test.ts b/packages/core/src/constants/upload.test.tsindex 17f9079fe..1fc0e1523 100644--- a/packages/core/src/constants/upload.test.ts+++ b/packages/core/src/constants/upload.test.ts@@ -6,6 +6,7 @@ import {IMAGE_EXTENSIONS,INLINE_RENDERABLE_EXTENSIONS,LINKABLE_ASSET_EXTENSIONS,+ MERMAID_FILE_EXTENSIONS,mediaKindForSidebarAssetExtension,TEXT_VIEWER_FALLBACK_EXTENSIONS,VIDEO_EXTENSIONS,@@ -163,6 +164,30 @@ describe('mediaKindForSidebarAssetExtension', () => {expect(mediaKindForSidebarAssetExtension(ext)).toBe(expected);});+ test.each([+ ['mmd', 'mermaid'],+ ['mermaid', 'mermaid'],+ ] as const)('classifies %s → %s (mermaid diagram files)', (ext, expected) => {+ expect(mediaKindForSidebarAssetExtension(ext)).toBe(expected);+ });++ test('normalizes mermaid extension casing and leading dot', () => {+ expect(mediaKindForSidebarAssetExtension('.MMD')).toBe('mermaid');+ expect(mediaKindForSidebarAssetExtension('.MERMAID')).toBe('mermaid');+ });++ test('mmd and mermaid are absent from ASSET_EXTENSIONS and INLINE_RENDERABLE_EXTENSIONS', () => {+ // Mirrors the text-viewer-fallback guard: MERMAID_FILE_EXTENSIONS are+ // LINKABLE (indexable + wiki-linkable, /api/asset-text-served) but must+ // NOT enter the XSS/serve allowlist. Diagram render is client-side —+ // the raw bytes never need to go through the inline-renderable path.+ for (const ext of MERMAID_FILE_EXTENSIONS) {+ expect(ASSET_EXTENSIONS.has(ext)).toBe(false);+ expect(INLINE_RENDERABLE_EXTENSIONS.has(ext)).toBe(false);+ expect(LINKABLE_ASSET_EXTENSIONS.has(ext)).toBe(true);+ }+ });+test('base and canvas are absent from ASSET_EXTENSIONS and INLINE_RENDERABLE_EXTENSIONS', () => {// These extensions resolve to mediaKind:'text' via TEXT_VIEWER_FALLBACK_EXTENSIONS// rather than the inline-text set, so the serve/XSS boundary (ASSET_EXTENSIONS +@@ -194,11 +219,16 @@ describe('mediaKindForSidebarAssetExtension', () => {expect(LINKABLE_ASSET_EXTENSIONS.has('canvas')).toBe(true);});- test('size equals ASSET_EXTENSIONS + TEXT_VIEWER_FALLBACK_EXTENSIONS', () => {+ test('size equals ASSET_EXTENSIONS + TEXT_VIEWER_FALLBACK_EXTENSIONS + MERMAID_FILE_EXTENSIONS', () => {expect(LINKABLE_ASSET_EXTENSIONS.size).toBe(- ASSET_EXTENSIONS.size + TEXT_VIEWER_FALLBACK_EXTENSIONS.size,+ ASSET_EXTENSIONS.size + TEXT_VIEWER_FALLBACK_EXTENSIONS.size + MERMAID_FILE_EXTENSIONS.size,);});++ test('contains mmd and mermaid (mermaid-file members)', () => {+ expect(LINKABLE_ASSET_EXTENSIONS.has('mmd')).toBe(true);+ expect(LINKABLE_ASSET_EXTENSIONS.has('mermaid')).toBe(true);+ });});test('lock files dispatch to TextViewer regardless of stem prefix', () => {diff --git a/packages/core/src/constants/upload.ts b/packages/core/src/constants/upload.tsindex b5b0a487b..7f603687c 100644--- a/packages/core/src/constants/upload.ts+++ b/packages/core/src/constants/upload.ts@@ -575,7 +575,7 @@ export const WIKI_EMBED_EXTENSIONS: ReadonlySet<string> = new Set(['mobi',]);-export type InlineAssetMediaKind = 'image' | 'video' | 'audio' | 'pdf' | 'text';+export type InlineAssetMediaKind = 'image' | 'video' | 'audio' | 'pdf' | 'text' | 'mermaid';// Sidebar-clickable asset extensions, grouped by inline-render path.// Each set is a STRICT subset of its canonical-class set (asserted below),@@ -671,6 +671,16 @@ assertSubset(// /api/asset keeps returning 415 for them (serve allowlist is unchanged).export const TEXT_VIEWER_FALLBACK_EXTENSIONS: ReadonlySet<string> = new Set(['base', 'canvas']);+// Standalone Mermaid diagram source files (mermaid-cli's input format;+// GitHub linguist registers `.mmd`/`.mermaid` as the Mermaid language).+// Rendered via the editor's `<Mermaid>` component through the ungated+// `/api/asset-text` byte path — same allowlist stance as the text-viewer+// fallback set (indexable + linkable but not admitted to the XSS-gated+// `/api/asset` serve path). Parse-failing content (including MultiMarkdown+// `.mmd`, which shares the extension) falls back to the read-only source+// view in the app-side viewer, so the file always reads.+export const MERMAID_FILE_EXTENSIONS: ReadonlySet<string> = new Set(['mmd', 'mermaid']);+// Code-file extensions live in a sibling module so the// language→extension table can be shared with the app-side TextViewer// (which maps the same canonical IDs to CodeMirror language packs).@@ -690,6 +700,7 @@ export { CODE_FILE_EXTENSIONS };export const LINKABLE_ASSET_EXTENSIONS: ReadonlySet<string> = new Set([...ASSET_EXTENSIONS,...TEXT_VIEWER_FALLBACK_EXTENSIONS,+ ...MERMAID_FILE_EXTENSIONS,]);/**@@ -710,6 +721,7 @@ export function mediaKindForSidebarAssetExtension(ext: string): InlineAssetMediaif (SIDEBAR_PDF_ASSET_EXTENSIONS.has(normalized)) return 'pdf';if (SIDEBAR_TEXT_ASSET_EXTENSIONS.has(normalized)) return 'text';if (TEXT_VIEWER_FALLBACK_EXTENSIONS.has(normalized)) return 'text';+ if (MERMAID_FILE_EXTENSIONS.has(normalized)) return 'mermaid';// Files whose extension matches a codeblock-supported language// (`ts` / `py` / `go` / ...) open by default in the read-only// text viewer with syntax highlighting — same kind dispatch asdiff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 7b4b57baf..affc3828d 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -243,6 +243,7 @@ export {INLINE_RENDERABLE_EXTENSIONS,type InlineAssetMediaKind,LINKABLE_ASSET_EXTENSIONS,+ MERMAID_FILE_EXTENSIONS,mediaKindForSidebarAssetExtension,PDF_EXTENSIONS,SANDBOXED_HTML_CSP,diff --git a/packages/core/src/schemas/api/document-read.ts b/packages/core/src/schemas/api/document-read.tsindex 67cd72c75..9cba124be 100644--- a/packages/core/src/schemas/api/document-read.ts+++ b/packages/core/src/schemas/api/document-read.ts@@ -52,9 +52,10 @@ export type DocumentReadSuccess = z.infer<typeof DocumentReadSuccessSchema>;* when `isSymlink: true`).* - `kind: 'asset'` — referenced asset discovered through wiki-link or markdown* image syntax. Carries `path` (contentDir-relative), `assetExt`,- * `mediaKind` (`'image' | 'video' | 'audio' | 'pdf' | 'text' | null` —+ * `mediaKind` (`'image' | 'video' | 'audio' | 'pdf' | 'text' | 'mermaid' | null` —* `'text'` is set for data formats the sidebar previews via CodeMirror- * (json / toml / lock); `null` for non-renderable extensions that surface only+ * (json / toml / lock); `'mermaid'` for standalone `.mmd` / `.mermaid`+ * diagram files; `null` for non-renderable extensions that surface only* via `[[wiki-link]]` references), and `referencedBy` (the docNames* that point at it).* - `kind: 'file'` — any ContentFilter-passing non-markdown@@ -87,7 +88,7 @@ export const DocumentListEntrySchema = z// path within the content directory.path: z.string().min(1).optional(),assetExt: z.string().min(1).optional(),- mediaKind: z.enum(['image', 'video', 'audio', 'pdf', 'text']).nullable().optional(),+ mediaKind: z.enum(['image', 'video', 'audio', 'pdf', 'text', 'mermaid']).nullable().optional(),referencedBy: z.array(z.string().min(1)).optional(),// Folder-only. True when the folder contains at least one non-skipped child// entry. The depth-1 children variant of GET /api/documents