From 2c522116c016c0798b64000e65e5eba27ce040b0 Mon Sep 17 00:00:00 2001 From: Amos Date: Sat, 22 Aug 2026 09:42:39 +0300 Subject: [PATCH] Gate 1 integration: shared streamdown config in reasoning, teaserText flattens \(...\) --- components/ai-elements/message.tsx | 4 ++-- components/ai-elements/reasoning.tsx | 21 ++++++++------------- components/question-dock.tsx | 4 +++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/components/ai-elements/message.tsx b/components/ai-elements/message.tsx index e37cab3..382ebfe 100644 --- a/components/ai-elements/message.tsx +++ b/components/ai-elements/message.tsx @@ -346,7 +346,7 @@ export type MessageResponseProps = ComponentProps; // // mermaid: the plugin supplies the renderer; the `mermaid` PROP (below) // carries the dark theme + the error fallback component. -const streamdownPlugins = { +export const streamdownPlugins = { cjk: { ...cjk, remarkPluginsAfter: [...cjk.remarkPluginsAfter, remarkBreaks], @@ -364,7 +364,7 @@ const mermaidTheme: MermaidConfig = { theme: "dark", }; -const mermaidOptions: MermaidOptions = { +export const mermaidOptions: MermaidOptions = { config: mermaidTheme, errorComponent: MermaidError, }; diff --git a/components/ai-elements/reasoning.tsx b/components/ai-elements/reasoning.tsx index b0ab48b..27d1900 100644 --- a/components/ai-elements/reasoning.tsx +++ b/components/ai-elements/reasoning.tsx @@ -7,10 +7,6 @@ import { CollapsibleTrigger, } from "@/components/ui/collapsible"; import { cn } from "@/lib/utils"; -import { cjk } from "@streamdown/cjk"; -import { code } from "@streamdown/code"; -import { createMathPlugin } from "@streamdown/math"; -import { mermaid } from "@streamdown/mermaid"; import { BrainIcon, ChevronDownIcon } from "lucide-react"; import type { ComponentProps, ReactNode } from "react"; import { @@ -23,8 +19,10 @@ import { useRef, useState, } from "react"; -import { Streamdown, type PluginConfig } from "streamdown"; +import { Streamdown } from "streamdown"; +import { transformMathDelimiters } from "@/src/core/math-delims"; +import { mermaidOptions, streamdownPlugins } from "./message"; import { Shimmer } from "./shimmer"; interface ReasoningContextValue { @@ -204,13 +202,8 @@ export type ReasoningContentProps = ComponentProps< children: string; }; -// See message.tsx — same streamdown plugin type skew + math config. -const streamdownPlugins = { - cjk, - code, - math: createMathPlugin({ singleDollarTextMath: true }), - mermaid, -} as unknown as PluginConfig; +// Shares message.tsx's Streamdown config (math delimiters, dark mermaid, +// remark-breaks) — reasoning renders the same contract as message text. export const ReasoningContent = memo( ({ className, children, ...props }: ReasoningContentProps) => ( @@ -222,7 +215,9 @@ export const ReasoningContent = memo( )} {...props} > - {children} + + {transformMathDelimiters(children)} + ) ); diff --git a/components/question-dock.tsx b/components/question-dock.tsx index a585a74..4c4c158 100644 --- a/components/question-dock.tsx +++ b/components/question-dock.tsx @@ -60,7 +60,9 @@ export function QuestionDock({ toolName, toolCallId, input, expanded, onExpand, /** A plain-text teaser of a question for the collapsed bar: unwrap math, flatten common LaTeX. */ function teaserText(q: string): string { return q - .replace(/\$\$?([^$]*)\$\$?/g, "$1") + .replace(/\\\(([\s\S]*?)\\\)/g, "$1") // \(...\) inline math + .replace(/\\\[([\s\S]*?)\\\]/g, "$1") // \[...\] display math + .replace(/\$\$?([^$]*)\$\$?/g, "$1") // legacy $...$ (pre-switch sessions) .replace(/\\frac\{([^{}]*)\}\{([^{}]*)\}/g, "$1/$2") .replace(/\\([a-zA-Z]+)/g, "$1") .replace(/[{}]/g, "")