Gate 1 integration: shared streamdown config in reasoning, teaserText flattens \(...\)
This commit is contained in:
@@ -346,7 +346,7 @@ export type MessageResponseProps = ComponentProps<typeof Streamdown>;
|
|||||||
//
|
//
|
||||||
// mermaid: the plugin supplies the renderer; the `mermaid` PROP (below)
|
// mermaid: the plugin supplies the renderer; the `mermaid` PROP (below)
|
||||||
// carries the dark theme + the error fallback component.
|
// carries the dark theme + the error fallback component.
|
||||||
const streamdownPlugins = {
|
export const streamdownPlugins = {
|
||||||
cjk: {
|
cjk: {
|
||||||
...cjk,
|
...cjk,
|
||||||
remarkPluginsAfter: [...cjk.remarkPluginsAfter, remarkBreaks],
|
remarkPluginsAfter: [...cjk.remarkPluginsAfter, remarkBreaks],
|
||||||
@@ -364,7 +364,7 @@ const mermaidTheme: MermaidConfig = {
|
|||||||
theme: "dark",
|
theme: "dark",
|
||||||
};
|
};
|
||||||
|
|
||||||
const mermaidOptions: MermaidOptions = {
|
export const mermaidOptions: MermaidOptions = {
|
||||||
config: mermaidTheme,
|
config: mermaidTheme,
|
||||||
errorComponent: MermaidError,
|
errorComponent: MermaidError,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ import {
|
|||||||
CollapsibleTrigger,
|
CollapsibleTrigger,
|
||||||
} from "@/components/ui/collapsible";
|
} from "@/components/ui/collapsible";
|
||||||
import { cn } from "@/lib/utils";
|
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 { BrainIcon, ChevronDownIcon } from "lucide-react";
|
||||||
import type { ComponentProps, ReactNode } from "react";
|
import type { ComponentProps, ReactNode } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -23,8 +19,10 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} 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";
|
import { Shimmer } from "./shimmer";
|
||||||
|
|
||||||
interface ReasoningContextValue {
|
interface ReasoningContextValue {
|
||||||
@@ -204,13 +202,8 @@ export type ReasoningContentProps = ComponentProps<
|
|||||||
children: string;
|
children: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// See message.tsx — same streamdown plugin type skew + math config.
|
// Shares message.tsx's Streamdown config (math delimiters, dark mermaid,
|
||||||
const streamdownPlugins = {
|
// remark-breaks) — reasoning renders the same contract as message text.
|
||||||
cjk,
|
|
||||||
code,
|
|
||||||
math: createMathPlugin({ singleDollarTextMath: true }),
|
|
||||||
mermaid,
|
|
||||||
} as unknown as PluginConfig;
|
|
||||||
|
|
||||||
export const ReasoningContent = memo(
|
export const ReasoningContent = memo(
|
||||||
({ className, children, ...props }: ReasoningContentProps) => (
|
({ className, children, ...props }: ReasoningContentProps) => (
|
||||||
@@ -222,7 +215,9 @@ export const ReasoningContent = memo(
|
|||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Streamdown plugins={streamdownPlugins}>{children}</Streamdown>
|
<Streamdown mermaid={mermaidOptions} plugins={streamdownPlugins}>
|
||||||
|
{transformMathDelimiters(children)}
|
||||||
|
</Streamdown>
|
||||||
</CollapsibleContent>
|
</CollapsibleContent>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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. */
|
/** A plain-text teaser of a question for the collapsed bar: unwrap math, flatten common LaTeX. */
|
||||||
function teaserText(q: string): string {
|
function teaserText(q: string): string {
|
||||||
return q
|
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(/\\frac\{([^{}]*)\}\{([^{}]*)\}/g, "$1/$2")
|
||||||
.replace(/\\([a-zA-Z]+)/g, "$1")
|
.replace(/\\([a-zA-Z]+)/g, "$1")
|
||||||
.replace(/[{}]/g, "")
|
.replace(/[{}]/g, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user