Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

⚡ perf: Throttle Code Highlighting While a Message Streams (#16073)

Marco Beretta14d8bb8d3c69
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.startup.spec.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.startup.spec.tsx
new file mode 100644
index 0000000000..be3db35c35
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.startup.spec.tsx
@@ -0,0 +1,60 @@
+import { act, renderHook } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import useLazyHighlight, { CodeHighlightThrottleContext } from '../useLazyHighlight';
+
+const mockHighlight = jest.fn();
+jest.mock('lowlight', () => {
+ const actual = jest.requireActual('lowlight');
+ return {
+ ...actual,
+ lowlight: {
+ ...actual.lowlight,
+ highlight: (lang: string, code: string) => {
+ mockHighlight(lang, code);
+ return actual.lowlight.highlight(lang, code);
+ },
+ },
+ };
+});
+
+/** Separate module scope keeps the grammar cache cold independently of other suites. */
+it('finishes the initial lazy highlight when config resolves, without re-highlighting settled code', async () => {
+ jest.useFakeTimers();
+ try {
+ let throttleMs = 300;
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <CodeHighlightThrottleContext.Provider value={throttleMs}>
+ {children}
+ </CodeHighlightThrottleContext.Provider>
+ );
+ const { result, rerender } = renderHook(({ code }) => useLazyHighlight(code, 'javascript'), {
+ initialProps: { code: 'const first = 1;' },
+ wrapper,
+ });
+ expect(mockHighlight).not.toHaveBeenCalled();
+ throttleMs = 60000;
+ rerender({ code: 'const first = 1;' });
+ await act(async () => {
+ await Promise.resolve();
+ });
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+ expect(mockHighlight).toHaveBeenLastCalledWith('javascript', 'const first = 1;');
+ const initialTokens = result.current;
+ expect(initialTokens).not.toEqual(['const first = 1;']);
+ expect(jest.getTimerCount()).toBe(0);
+
+ // A cadence-only change must not tokenize an already completed value again.
+ throttleMs = 0;
+ rerender({ code: 'const first = 1;' });
+ expect(result.current).toBe(initialTokens);
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+ act(() => jest.advanceTimersByTime(60000));
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+
+ rerender({ code: 'const second = 2;' });
+ expect(mockHighlight).toHaveBeenCalledTimes(2);
+ expect(mockHighlight).toHaveBeenLastCalledWith('javascript', 'const second = 2;');
+ } finally {
+ jest.useRealTimers();
+ }
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.throttle.spec.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.throttle.spec.tsx
new file mode 100644
index 0000000000..eec9e65b2b
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/useLazyHighlight.throttle.spec.tsx
@@ -0,0 +1,210 @@
+import { act, renderHook } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import useLazyHighlight, {
+ CodeHighlightThrottleContext,
+ HIGHLIGHT_THROTTLE_MS,
+} from '../useLazyHighlight';
+
+const mockHighlight = jest.fn((_lang: string, code: string) => ({
+ type: 'root',
+ children: [{ type: 'text', value: code }],
+}));
+
+jest.mock('lowlight', () => ({
+ __esModule: true,
+ lowlight: {
+ registered: () => true,
+ highlight: (lang: string, code: string) => mockHighlight(lang, code),
+ highlightAuto: (code: string) => mockHighlight('auto', code),
+ },
+}));
+
+const flush = () => act(async () => Promise.resolve());
+
+describe('useLazyHighlight throttling', () => {
+ beforeEach(() => {
+ jest.useFakeTimers();
+ mockHighlight.mockClear();
+ });
+
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ it('ignores an in-flight highlight when the input changes', async () => {
+ const { result, rerender } = renderHook(
+ ({ code, lang }: { code: string; lang: string }) => useLazyHighlight(code, lang),
+ { initialProps: { code: 'a', lang: 'js' } },
+ );
+ rerender({ code: 'b', lang: 'js' });
+
+ await flush();
+ expect(result.current).toEqual(['b']);
+
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS));
+ await flush();
+ expect(result.current).toEqual(['b']);
+ });
+
+ it('highlights the first value immediately', async () => {
+ const { result } = renderHook(() => useLazyHighlight('a', 'js'));
+ expect([null, ['a']]).toContainEqual(result.current);
+ await flush();
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+ expect(mockHighlight).toHaveBeenCalledWith('js', 'a');
+ expect(result.current).toEqual(['a']);
+ });
+
+ it('throttles re-highlights while streaming and highlights the settled value once', async () => {
+ const { result, rerender } = renderHook(({ code }) => useLazyHighlight(code, 'js'), {
+ initialProps: { code: 'a' },
+ });
+ await flush();
+ mockHighlight.mockClear();
+
+ const chunks = ['ab', 'abc', 'abcd', 'abcde'];
+ for (const code of chunks) {
+ rerender({ code });
+ act(() => jest.advanceTimersByTime(20));
+ }
+ expect(mockHighlight).not.toHaveBeenCalled();
+ expect(result.current).toEqual(['abcde']);
+
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS));
+ await flush();
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+ expect(mockHighlight).toHaveBeenLastCalledWith('js', 'abcde');
+ expect(result.current).toEqual(['abcde']);
+ });
+
+ it('keeps completed highlights when the configured throttle changes', async () => {
+ let throttleMs = HIGHLIGHT_THROTTLE_MS;
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <CodeHighlightThrottleContext.Provider value={throttleMs}>
+ {children}
+ </CodeHighlightThrottleContext.Provider>
+ );
+ const { result, rerender } = renderHook(
+ ({ code }: { code: string }) => useLazyHighlight(code, 'js'),
+ {
+ initialProps: { code: 'a' },
+ wrapper,
+ },
+ );
+ await flush();
+ expect(result.current).toEqual(['a']);
+
+ throttleMs += 100;
+ rerender({ code: 'a' });
+
+ expect(result.current).toEqual(['a']);
+ });
+ it('reschedules pending highlights when the configured throttle changes', async () => {
+ let throttleMs = HIGHLIGHT_THROTTLE_MS;
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <CodeHighlightThrottleContext.Provider value={throttleMs}>
+ {children}
+ </CodeHighlightThrottleContext.Provider>
+ );
+ const { result, rerender } = renderHook(
+ ({ code }: { code: string }) => useLazyHighlight(code, 'js'),
+ {
+ initialProps: { code: 'a' },
+ wrapper,
+ },
+ );
+ await flush();
+ mockHighlight.mockClear();
+
+ rerender({ code: 'ab' });
+ act(() => jest.advanceTimersByTime(100));
+ throttleMs = HIGHLIGHT_THROTTLE_MS * 2;
+ rerender({ code: 'ab' });
+
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS * 2 - 101));
+ await flush();
+ expect(mockHighlight).not.toHaveBeenCalled();
+
+ act(() => jest.advanceTimersByTime(1));
+ await flush();
+ expect(mockHighlight).toHaveBeenCalledWith('js', 'ab');
+ expect(result.current).toEqual(['ab']);
+ });
+
+ it('uses the configured throttle interval', async () => {
+ const { result, rerender } = renderHook(({ code }) => useLazyHighlight(code, 'js'), {
+ initialProps: { code: 'a' },
+ wrapper: ({ children }) => (
+ <CodeHighlightThrottleContext.Provider value={300}>
+ {children}
+ </CodeHighlightThrottleContext.Provider>
+ ),
+ });
+ await flush();
+ mockHighlight.mockClear();
+
+ rerender({ code: 'ab' });
+ act(() => jest.advanceTimersByTime(299));
+ expect(result.current).toEqual(['ab']);
+ act(() => jest.advanceTimersByTime(1));
+ await flush();
+ expect(result.current).toEqual(['ab']);
+ });
+ it('keeps the throttle window stable when the wall clock moves backwards', async () => {
+ const { result, rerender } = renderHook(({ code }) => useLazyHighlight(code, 'js'), {
+ initialProps: { code: 'a' },
+ });
+ await flush();
+ mockHighlight.mockClear();
+
+ rerender({ code: 'ab' });
+ act(() => jest.setSystemTime(new Date(Date.now() - 60_000)));
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS - 1));
+ expect(result.current).toEqual(['ab']);
+ act(() => jest.advanceTimersByTime(1));
+ await flush();
+ expect(result.current).toEqual(['ab']);
+ });
+ it('does not parse an initialized value twice on mount', async () => {
+ const { result } = renderHook(() => useLazyHighlight('initialized', 'js'));
+ await flush();
+ expect(result.current).toEqual(['initialized']);
+ expect(mockHighlight).toHaveBeenCalledTimes(1);
+ });
+
+ it('shows current raw code while a replacement highlight is pending', async () => {
+ const { result, rerender } = renderHook(({ code }) => useLazyHighlight(code, 'js'), {
+ initialProps: { code: 'echo a' },
+ });
+ await flush();
+ rerender({ code: 'echo ab' });
+ expect(result.current).toEqual(['echo ab']);
+ });
+
+ it('clears immediately when code becomes empty', async () => {
+ const { result, rerender } = renderHook(
+ ({ code }: { code: string | undefined }) => useLazyHighlight(code, 'js'),
+ { initialProps: { code: 'a' as string | undefined } },
+ );
+ await flush();
+ rerender({ code: 'ab' });
+ rerender({ code: undefined });
+ expect(result.current).toBeNull();
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS * 2));
+ await flush();
+ expect(result.current).toBeNull();
+ });
+
+ it('does not schedule work after unmount', async () => {
+ const { rerender, unmount } = renderHook(({ code }) => useLazyHighlight(code, 'js'), {
+ initialProps: { code: 'a' },
+ });
+ await flush();
+ mockHighlight.mockClear();
+ rerender({ code: 'ab' });
+ unmount();
+ act(() => jest.advanceTimersByTime(HIGHLIGHT_THROTTLE_MS * 2));
+ await flush();
+ expect(mockHighlight).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/useLazyHighlight.ts b/client/src/components/Chat/Messages/Content/Parts/useLazyHighlight.ts
index 1a720e4512..b0fea391e8 100644
--- a/client/src/components/Chat/Messages/Content/Parts/useLazyHighlight.ts
+++ b/client/src/components/Chat/Messages/Content/Parts/useLazyHighlight.ts
@@ -1,4 +1,18 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useRef } from 'react';
+
+/** Minimum gap between highlights while the input keeps changing (streaming). */
+export const HIGHLIGHT_THROTTLE_MS = 300;
+export const CodeHighlightThrottleContext = React.createContext(HIGHLIGHT_THROTTLE_MS);
+
+export function normalizeCodeHighlightThrottleMs(value: unknown): number {
+ return typeof value === 'number' &&
+ Number.isFinite(value) &&
+ Number.isInteger(value) &&
+ value >= 0 &&
+ value <= 60000
+ ? value
+ : HIGHLIGHT_THROTTLE_MS;
+}
interface HastText {
type: 'text';
@@ -63,63 +77,122 @@ function highlightCode(mod: LowlightModule, code: string, lang: string): React.R
* so a hook mounted without code still recognizes the first code it receives as new. */
type HighlightState = { key: string; nodes: React.ReactNode[] | null };
-const NOTHING_HIGHLIGHTED: HighlightState = { key: '', nodes: null };
-
const highlightKey = (code: string | undefined, lang: string): string =>
code ? `${lang}\0${code}` : '';
+const now = (): number => (typeof performance === 'undefined' ? Date.now() : performance.now());
+
/**
* Tokens for a block of code, once the grammars have loaded.
*
- * Highlighting runs when the input changes, and once per input: the tokens carry the key they
- * were produced from, so a mount that could highlight immediately is not repeated by the effect
- * that follows it. Grammars load on first use, so a caller renders its own raw text until this
- * returns; passing `undefined` while a pane is closed keeps a collapsed card from tokenizing
- * output nobody is reading.
+ * Highlighting runs when the input changes, and once per input: the key the tokens were produced
+ * from is tracked, so a mount that could highlight immediately is not repeated by the effect that
+ * follows it. While the input keeps changing, as it does for a streaming tool call, highlights are
+ * throttled to one per `CodeHighlightThrottleContext` interval and the caller is handed its raw
+ * text in between, so a long code block stays readable without tokenizing every delta. Grammars
+ * load on first use, so a caller renders its own raw text until this returns; passing `undefined`
+ * while a pane is closed keeps a collapsed card from tokenizing output nobody is reading.
*/
export default function useLazyHighlight(
code: string | undefined,
lang: string,
): React.ReactNode[] | null {
- const [state, setState] = useState<HighlightState>(() =>
- code && lowlightModule
- ? { key: highlightKey(code, lang), nodes: highlightCode(lowlightModule, code, lang) }
- : NOTHING_HIGHLIGHTED,
+ const throttleMs = React.useContext(CodeHighlightThrottleContext);
+ const currentKey = highlightKey(code, lang);
+ const hasInitialHighlight = Boolean(code && lowlightModule);
+ const [highlighted, setHighlighted] = useState<HighlightState | null>(() =>
+ hasInitialHighlight
+ ? { key: currentKey, nodes: highlightCode(lowlightModule!, code!, lang) }
+ : null,
);
- const key = highlightKey(code, lang);
- const currentKey = state.key;
+ /** The input the tokens held were produced from, or that a pending run will produce. */
+ const scheduledKey = useRef(hasInitialHighlight ? currentKey : '');
+ const prevThrottleMs = useRef<number | null>(hasInitialHighlight ? throttleMs : null);
+ const lastRunAt = useRef<number | null>(hasInitialHighlight ? now() : null);
+ const generation = useRef(0);
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
useEffect(() => {
- if (key === currentKey) {
+ const key = highlightKey(code, lang);
+ const keyChanged = key !== scheduledKey.current;
+ const throttleChanged = throttleMs !== prevThrottleMs.current;
+ if (!keyChanged && !throttleChanged) {
return;
}
+ scheduledKey.current = key;
+ prevThrottleMs.current = throttleMs;
+ /** A new cadence only reschedules a waiting timer. Work already started
+ * for this same input may finish, and completed tokens need no new pass. */
+ if (!keyChanged && timer.current === null) {
+ return;
+ }
+ generation.current += 1;
+ if (keyChanged) {
+ setHighlighted(null);
+ }
+
+ if (timer.current) {
+ clearTimeout(timer.current);
+ timer.current = null;
+ }
if (!code) {
- setState(NOTHING_HIGHLIGHTED);
+ lastRunAt.current = null;
return;
}
- if (lowlightModule) {
- setState({ key, nodes: highlightCode(lowlightModule, code, lang) });
+ if (lang === 'plaintext') {
+ setHighlighted({ key, nodes: [code] });
return;
}
- let cancelled = false;
- loadLowlight()
- .then((mod) => {
- if (!cancelled) {
- setState({ key, nodes: highlightCode(mod, code, lang) });
- }
- })
- .catch(() => {
- if (!cancelled) {
- setState({ key, nodes: [code] });
- }
- });
- return () => {
- cancelled = true;
+ const run = () => {
+ timer.current = null;
+ lastRunAt.current = now();
+ const gen = ++generation.current;
+
+ if (lowlightModule) {
+ setHighlighted({ key, nodes: highlightCode(lowlightModule, code, lang) });
+ return;
+ }
+
+ loadLowlight()
+ .then((mod) => {
+ if (gen === generation.current) {
+ setHighlighted({ key, nodes: highlightCode(mod, code, lang) });
+ }
+ })
+ .catch(() => {
+ if (gen === generation.current) {
+ setHighlighted({ key, nodes: [code] });
+ }
+ });
};
- }, [key, currentKey, code, lang]);
- return state.nodes;
+ /** A clock that jumped backwards would otherwise hold the next highlight for a full window. */
+ const elapsed = lastRunAt.current === null ? throttleMs : now() - lastRunAt.current;
+ const wait = throttleMs - elapsed;
+ if (wait <= 0) {
+ run();
+ } else {
+ timer.current = setTimeout(run, wait);
+ }
+ }, [code, lang, throttleMs]);
+
+ useEffect(
+ () => () => {
+ if (timer.current) {
+ clearTimeout(timer.current);
+ }
+ scheduledKey.current = '';
+ prevThrottleMs.current = null;
+ generation.current += 1;
+ },
+ [],
+ );
+
+ if (highlighted && highlighted.key === currentKey) {
+ return highlighted.nodes;
+ }
+ return code ? [code] : null;
}
diff --git a/client/src/components/Share/ShareView.highlight.spec.tsx b/client/src/components/Share/ShareView.highlight.spec.tsx
new file mode 100644
index 0000000000..84912e7aa9
--- /dev/null
+++ b/client/src/components/Share/ShareView.highlight.spec.tsx
@@ -0,0 +1,104 @@
+import React, { useContext } from 'react';
+import { RecoilRoot } from 'recoil';
+import { MemoryRouter } from 'react-router-dom';
+import { act, render, screen } from '@testing-library/react';
+import type { TSharedLinkStartupConfig } from 'librechat-data-provider';
+import { CodeHighlightThrottleContext } from '~/components/Chat/Messages/Content/Parts/useLazyHighlight';
+import ShareView from './ShareView';
+
+let mockConfig: TSharedLinkStartupConfig | undefined;
+const mockStartupQuery = jest.fn();
+const mockConfigListeners = new Set<() => void>();
+jest.mock('~/data-provider', () => ({
+ useGetSharedStartupConfig: (...args: unknown[]) => {
+ mockStartupQuery(...args);
+ const { useSyncExternalStore } = jest.requireActual('react');
+ const data = useSyncExternalStore(
+ (listener: () => void) => {
+ mockConfigListeners.add(listener);
+ return () => mockConfigListeners.delete(listener);
+ },
+ () => mockConfig,
+ );
+ return { data };
+ },
+ useForkSharedConvoMutation: () => ({ mutate: jest.fn(), isLoading: false }),
+}));
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useAuthContext: () => ({ isAuthReady: true }),
+ useDocumentTitle: jest.fn(),
+}));
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useParams: () => ({ shareId: 'shared-link' }),
+}));
+jest.mock('librechat-data-provider/react-query', () => ({
+ ...jest.requireActual('librechat-data-provider/react-query'),
+ useGetSharedMessages: () => ({
+ data: {
+ messages: [{ messageId: 'shared-message', parentMessageId: null, text: 'hello' }],
+ title: 'Shared chat',
+ },
+ isLoading: false,
+ isFetching: false,
+ }),
+}));
+
+function MockCadence({ name }: { name: string }) {
+ return <output data-testid={name}>{useContext(CodeHighlightThrottleContext)}</output>;
+}
+jest.mock('./MessagesView', () => ({
+ __esModule: true,
+ default: () => <MockCadence name="message-cadence" />,
+}));
+jest.mock('~/components/Chat/Subagents/SharedSubagentActivityDialog', () => ({
+ __esModule: true,
+ default: () => <MockCadence name="subagent-cadence" />,
+}));
+jest.mock('./ShareArtifacts', () => ({
+ ShareArtifactsContainer: ({ mainContent }: { mainContent: React.ReactNode }) => mainContent,
+}));
+jest.mock('../Chat/Surface', () => ({
+ __esModule: true,
+ default: ({ children }: { children: React.ReactNode }) => children,
+}));
+jest.mock('../Chat/Footer', () => ({ __esModule: true, default: () => null }));
+
+const frame = () => (
+ <RecoilRoot>
+ <MemoryRouter>
+ <ShareView />
+ </MemoryRouter>
+ </RecoilRoot>
+);
+
+describe('shared code highlighting configuration', () => {
+ it.each([0, 100, 60000])(
+ 'passes the share payload cadence %i to both content surfaces',
+ (cadence) => {
+ mockConfig = { appTitle: 'Share', interface: { codeHighlightThrottleMs: cadence } };
+ render(frame());
+ expect(screen.getByTestId('message-cadence').textContent).toBe(String(cadence));
+ expect(screen.getByTestId('subagent-cadence').textContent).toBe(String(cadence));
+ expect(mockStartupQuery).toHaveBeenCalledWith('shared-link', { enabled: true });
+ },
+ );
+
+ it('uses the default while loading, then applies config without waiting on messages', () => {
+ mockConfig = undefined;
+ render(frame());
+ expect(screen.getByTestId('message-cadence').textContent).toBe('300');
+ act(() => {
+ mockConfig = { appTitle: 'Share', interface: { codeHighlightThrottleMs: 0 } };
+ mockConfigListeners.forEach((listener) => listener());
+ });
+ expect(screen.getByTestId('message-cadence').textContent).toBe('0');
+ });
+
+ it.each([undefined, -1, NaN, 60001])('normalizes absent or invalid cadence %s', (cadence) => {
+ mockConfig = { appTitle: 'Share', interface: { codeHighlightThrottleMs: cadence } };
+ render(frame());
+ expect(screen.getByTestId('message-cadence').textContent).toBe('300');
+ });
+});
diff --git a/client/src/components/Share/ShareView.tsx b/client/src/components/Share/ShareView.tsx
index 11ab9ae56c..1a316b9f35 100644
--- a/client/src/components/Share/ShareView.tsx
+++ b/client/src/components/Share/ShareView.tsx
@@ -20,6 +20,10 @@ import {
TooltipAnchor,
useToastContext,
} from '@librechat/client';
+import {
+ CodeHighlightThrottleContext,
+ normalizeCodeHighlightThrottleMs,
+} from '~/components/Chat/Messages/Content/Parts/useLazyHighlight';
import SharedSubagentActivityDialog from '~/components/Chat/Subagents/SharedSubagentActivityDialog';
import { cn, DEFAULT_APP_TITLE, getResponseStatus, selectActiveBranchTail } from '~/utils';
import { siblingIdxFamily, siblingKey } from '~/components/Chat/Messages/Thread/state';
@@ -240,18 +244,22 @@ function SharedView() {
);
return (
- <ShareContext.Provider
- value={{ isSharedConvo: true, shareId, hasConfiguredSender: data?.hasConfiguredSender }}
+ <CodeHighlightThrottleContext.Provider
+ value={normalizeCodeHighlightThrottleMs(config?.interface?.codeHighlightThrottleMs)}
>
- <AppChatSurface>
- <div className="relative flex h-screen w-full overflow-hidden dark:bg-surface-secondary">
- <main className="relative flex w-full grow overflow-hidden dark:bg-surface-secondary">
- {artifactsContainer}
- </main>
- </div>
- <SharedSubagentActivityDialog shareId={shareId} />
- </AppChatSurface>
- </ShareContext.Provider>
+ <ShareContext.Provider
+ value={{ isSharedConvo: true, shareId, hasConfiguredSender: data?.hasConfiguredSender }}
+ >
+ <AppChatSurface>
+ <div className="relative flex h-screen w-full overflow-hidden dark:bg-surface-secondary">
+ <main className="relative flex w-full grow overflow-hidden dark:bg-surface-secondary">
+ {artifactsContainer}
+ </main>
+ </div>
+ <SharedSubagentActivityDialog shareId={shareId} />
+ </AppChatSurface>
+ </ShareContext.Provider>
+ </CodeHighlightThrottleContext.Provider>
);
}
diff --git a/client/src/routes/Root.tsx b/client/src/routes/Root.tsx
index 11f5bba1c4..0051f7e57a 100644
--- a/client/src/routes/Root.tsx
+++ b/client/src/routes/Root.tsx
@@ -10,6 +10,10 @@ import {
MOBILE_DRAWER_FULL_WIDTH,
MOBILE_PANE_SHIFT,
} from '~/components/UnifiedSidebar';
+import {
+ CodeHighlightThrottleContext,
+ normalizeCodeHighlightThrottleMs,
+} from '~/components/Chat/Messages/Content/Parts/useLazyHighlight';
import {
PromptGroupsProvider,
AssistantsMapContext,
@@ -114,6 +118,9 @@ export default function Root() {
const { data: termsData } = useUserTermsQuery({
enabled: isAuthenticated && config?.interface?.termsOfService?.modalAcceptance === true,
});
+ const highlightThrottleMs = normalizeCodeHighlightThrottleMs(
+ config?.interface?.codeHighlightThrottleMs,
+ );
useSearchEnabled(isAuthenticated);
@@ -137,81 +144,83 @@ export default function Root() {
}
return (
- <SetConvoProvider>
- <FileMapContext.Provider value={fileMap}>
- <AssistantsMapContext.Provider value={assistantsMap}>
- <AgentsMapContext.Provider value={agentsMap}>
- <PromptGroupsProvider>
- <Banner onHeightChange={setBannerHeight} />
- <div className="flex" style={{ height: `calc(100dvh - ${bannerHeight}px)` }}>
- <div
- className="relative z-0 flex h-full w-full overflow-hidden"
- /** The drawer and the pane both read this, so their travel
- * cannot disagree about how far the drawer opens. */
- style={
- {
- [MOBILE_DRAWER_WIDTH_VAR]: drawerStrip
- ? MOBILE_DRAWER_STRIP_WIDTH
- : MOBILE_DRAWER_FULL_WIDTH,
- } as React.CSSProperties
- }
- >
- {/* The drawer stops being painted once it is closed and
- settled, so it needs the same travel window the scrim and
- the pane's `inert` read. */}
- <UnifiedSidebar isSliding={isSliding} />
+ <CodeHighlightThrottleContext.Provider value={highlightThrottleMs}>
+ <SetConvoProvider>
+ <FileMapContext.Provider value={fileMap}>
+ <AssistantsMapContext.Provider value={assistantsMap}>
+ <AgentsMapContext.Provider value={agentsMap}>
+ <PromptGroupsProvider>
+ <Banner onHeightChange={setBannerHeight} />
+ <div className="flex" style={{ height: `calc(100dvh - ${bannerHeight}px)` }}>
<div
- ref={paneRef}
- /** Focus target of last resort when the drawer closes on a
- * route that renders no opener. Not in the tab order. */
- tabIndex={-1}
- className="relative flex h-full max-w-full flex-1 flex-col overflow-hidden focus:outline-none"
- style={{
- /** A percentage of the pane's own width, so it tracks the
- * drawer without a literal and survives rotation. */
- transform: isSmallScreen && sidebarExpanded ? MOBILE_PANE_SHIFT : 'none',
- transition: prefersReducedMotion ? undefined : SIDEBAR_TRANSITION,
- }}
- /** Recoil's flip is deferred past the opening frames and
- * the closing transition outlives it at the other end, so
- * `isSliding` covers the travel `sidebarExpanded` brackets
- * too late and drops too early. */
- inert={isSmallScreen && (sidebarExpanded || isSliding) ? '' : undefined}
+ className="relative z-0 flex h-full w-full overflow-hidden"
+ /** The drawer and the pane both read this, so their travel
+ * cannot disagree about how far the drawer opens. */
+ style={
+ {
+ [MOBILE_DRAWER_WIDTH_VAR]: drawerStrip
+ ? MOBILE_DRAWER_STRIP_WIDTH
+ : MOBILE_DRAWER_FULL_WIDTH,
+ } as React.CSSProperties
+ }
>
- <Outlet />
- </div>
- {/* Without the strip the scrim exists only for the travel:
+ {/* The drawer stops being painted once it is closed and
+ settled, so it needs the same travel window the scrim and
+ the pane's `inert` read. */}
+ <UnifiedSidebar isSliding={isSliding} />
+ <div
+ ref={paneRef}
+ /** Focus target of last resort when the drawer closes on a
+ * route that renders no opener. Not in the tab order. */
+ tabIndex={-1}
+ className="relative flex h-full max-w-full flex-1 flex-col overflow-hidden focus:outline-none"
+ style={{
+ /** A percentage of the pane's own width, so it tracks the
+ * drawer without a literal and survives rotation. */
+ transform: isSmallScreen && sidebarExpanded ? MOBILE_PANE_SHIFT : 'none',
+ transition: prefersReducedMotion ? undefined : SIDEBAR_TRANSITION,
+ }}
+ /** Recoil's flip is deferred past the opening frames and
+ * the closing transition outlives it at the other end, so
+ * `isSliding` covers the travel `sidebarExpanded` brackets
+ * too late and drops too early. */
+ inert={isSmallScreen && (sidebarExpanded || isSliding) ? '' : undefined}
+ >
+ <Outlet />
+ </div>
+ {/* Without the strip the scrim exists only for the travel:
through a close that began while the strip was still on
(disabling it unmounts the scrim at once, but the drawer
needs the whole transition to widen), and through an open
the deferred flip has not committed yet. Once expanded
lands, a full-width drawer covers it, so keeping it
mounted would only expose a duplicate dismiss control. */}
- {isSmallScreen && (drawerStrip || (isSliding && !sidebarExpanded)) && (
- <MobileDrawerScrim
- expanded={sidebarExpanded}
- isSliding={isSliding}
- prefersReducedMotion={prefersReducedMotion}
- onClick={onScrimClick}
- />
- )}
+ {isSmallScreen && (drawerStrip || (isSliding && !sidebarExpanded)) && (
+ <MobileDrawerScrim
+ expanded={sidebarExpanded}
+ isSliding={isSliding}
+ prefersReducedMotion={prefersReducedMotion}
+ onClick={onScrimClick}
+ />
+ )}
+ </div>
</div>
- </div>
- </PromptGroupsProvider>
- <KeyboardShortcutsProvider />
- </AgentsMapContext.Provider>
- {config?.interface?.termsOfService?.modalAcceptance === true && (
- <TermsAndConditionsModal
- open={showTerms}
- onOpenChange={setShowTerms}
- onAccept={handleAcceptTerms}
- onDecline={handleDeclineTerms}
- title={config.interface.termsOfService.modalTitle}
- modalContent={config.interface.termsOfService.modalContent}
- />
- )}
- </AssistantsMapContext.Provider>
- </FileMapContext.Provider>
- </SetConvoProvider>
+ </PromptGroupsProvider>
+ <KeyboardShortcutsProvider />
+ </AgentsMapContext.Provider>
+ {config?.interface?.termsOfService?.modalAcceptance === true && (
+ <TermsAndConditionsModal
+ open={showTerms}
+ onOpenChange={setShowTerms}
+ onAccept={handleAcceptTerms}
+ onDecline={handleDeclineTerms}
+ title={config.interface.termsOfService.modalTitle}
+ modalContent={config.interface.termsOfService.modalContent}
+ />
+ )}
+ </AssistantsMapContext.Provider>
+ </FileMapContext.Provider>
+ </SetConvoProvider>
+ </CodeHighlightThrottleContext.Provider>
);
}
diff --git a/e2e/setup/fake-model.js b/e2e/setup/fake-model.js
index 7dd40b9577..fbd658c5fe 100644
--- a/e2e/setup/fake-model.js
+++ b/e2e/setup/fake-model.js
@@ -54,6 +54,7 @@ const RESUME_ICON_REPLY_MARKER = 'E2E_RESUME_ICON_REPLY:';
const FORCED_ERROR_MARKER = 'E2E_FORCED_ERROR:';
const MARKDOWN_REPLY_MARKER = 'E2E_MARKDOWN_REPLY';
const STREAMING_MARKDOWN_REPLY_MARKER = 'E2E_STREAMING_MARKDOWN_REPLY';
+const HIGHLIGHT_CODE_MARKER = 'E2E_HIGHLIGHT_CODE:';
const STATEFUL_CODE_MARKER = 'E2E_STATEFUL_CODE:';
/** Two prose paragraphs, so a spec can select the message's *closing* block. */
const PARAGRAPHS_REPLY_MARKER = 'E2E_PARAGRAPHS_REPLY';
@@ -102,6 +103,11 @@ const ACTIVITY_PHASE_FINAL_TEXT = 'E2E activity phase reply done';
const STEER_TOOL_NAME_PREFIX = 'remember_fact';
const ASK_USER_QUESTION_TOOL_NAME = 'ask_user_question';
const SLOW_CHUNK_DELAY_MS = Number(process.env.MOCK_LLM_SLOW_CHUNK_DELAY_MS) || 35;
+/** The highlight cancellation scenario has to open the code card and stop the
+ * run while its arguments are still arriving. At the ordinary slow cadence
+ * those ~40 chunks are gone in under two seconds, which is not a window a
+ * loaded runner can be relied on to hit, so that one variant streams wider. */
+const HIGHLIGHT_CANCEL_CHUNK_DELAY_MS = 200;
const ORDERED_CHUNK_DELAY_MS = 2;
const ORDERED_REPLY_PIECES = 64;
const SLOW_REPLY_CHUNKS = 160;
@@ -725,15 +731,40 @@ class UsageEmittingFakeChatModel extends FakeChatModel {
if (toolCalls?.length) {
await new Promise((resolve) => setTimeout(resolve, this.streamSleep));
- const toolCallChunks = toolCalls.map((toolCall, index) => ({
- name: toolCall.name,
- args: JSON.stringify(toolCall.args),
- id: toolCall.id,
- index,
- type: 'tool_call_chunk',
- }));
- yield this._createResponseChunk('', toolCallChunks);
- void runManager?.handleLLMNewToken('');
+ if (!toolCalls.some((toolCall) => toolCall.streamArgs)) {
+ const toolCallChunks = toolCalls.map((toolCall, index) => ({
+ name: toolCall.name,
+ args: JSON.stringify(toolCall.args),
+ id: toolCall.id,
+ index,
+ type: 'tool_call_chunk',
+ }));
+ yield this._createResponseChunk('', toolCallChunks);
+ void runManager?.handleLLMNewToken('');
+ return;
+ }
+
+ for (const [index, toolCall] of toolCalls.entries()) {
+ const serializedArgs = JSON.stringify(toolCall.args);
+ const chunks = toolCall.streamArgs
+ ? (serializedArgs.match(/.{1,64}/gs) ?? [''])
+ : [serializedArgs];
+ for (const [chunkIndex, args] of chunks.entries()) {
+ const toolCallChunk = {
+ name: chunkIndex === 0 ? toolCall.name : undefined,
+ args,
+ id: chunkIndex === 0 ? toolCall.id : undefined,
+ index,
+ type: 'tool_call_chunk',
+ };
+ yield this._createResponseChunk('', [toolCallChunk]);
+ void runManager?.handleLLMNewToken('');
+ if (chunkIndex < chunks.length - 1) {
+ await new Promise((resolve) => setTimeout(resolve, this.streamSleep));
+ }
+ }
+ }
+ return;
}
}
@@ -2750,6 +2781,37 @@ function provisioningToolResponses({ text, toolNames }) {
toolNames,
);
}
+ const highlightLabel = getMarkerValue(text, HIGHLIGHT_CODE_MARKER);
+ if (highlightLabel) {
+ const codeTool = CODE_EXEC_TOOLS.find((tool) => toolNames.has(tool.name));
+ if (!codeTool) {
+ return {
+ responses: [`E2E highlight code unavailable: ${JSON.stringify([...toolNames])}`],
+ };
+ }
+ const command = Array.from({ length: 120 }, (_, index) => `printf 'line-${index}-☃\\n'`).join(
+ '\n',
+ );
+ const args =
+ codeTool.name === 'bash_tool'
+ ? { command }
+ : codeTool.name === 'execute_code'
+ ? { lang: 'bash', code: command }
+ : codeTool.args;
+ return {
+ responses: ['', `E2E highlighted code complete: ${highlightLabel}`],
+ sleep: highlightLabel === 'cancel' ? HIGHLIGHT_CANCEL_CHUNK_DELAY_MS : SLOW_CHUNK_DELAY_MS,
+ toolCalls: [
+ {
+ id: EXECUTE_CODE_TOOL_CALL_ID,
+ name: codeTool.name,
+ args,
+ streamArgs: true,
+ type: 'tool_call',
+ },
+ ],
+ };
+ }
const codeLabel = getMarkerValue(text, EXECUTE_CODE_MARKER);
if (codeLabel) {
@@ -2775,7 +2837,6 @@ function provisioningToolResponses({ text, toolNames }) {
],
};
}
-
const searchLabel = getMarkerValue(text, FILE_SEARCH_MARKER);
if (searchLabel) {
if (!toolNames.has(FILE_SEARCH_TOOL_NAME)) {
diff --git a/e2e/specs/mock/scenarios/highlight-throttle.spec.ts b/e2e/specs/mock/scenarios/highlight-throttle.spec.ts
new file mode 100644
index 0000000000..f8e6219c34
--- /dev/null
+++ b/e2e/specs/mock/scenarios/highlight-throttle.spec.ts
@@ -0,0 +1,138 @@
+import { expect, test } from '@playwright/test';
+
+import {
+ enableCodeInterpreter,
+ isAgentsStream,
+ messagesView,
+ MOCK_ENDPOINTS,
+ NEW_CHAT_PATH,
+ selectMockEndpoint,
+ sendMessage,
+} from '../helpers';
+
+const stopButton = (page: Parameters<typeof sendMessage>[0]) =>
+ page.getByRole('button', { name: 'Stop generating' });
+
+const highlightedCode = (page: Parameters<typeof sendMessage>[0]) =>
+ messagesView(page).locator('code.hljs.language-bash').last();
+
+/** The card's disclosure, which `ProgressText` owns. It carries an
+ * `aria-expanded` state only once the card has input to show, so waiting on
+ * this locator also waits for the first streamed argument chunk. */
+const codeDisclosure = (page: Parameters<typeof sendMessage>[0]) =>
+ messagesView(page).locator('.progress-text-wrapper button[aria-expanded]').last();
+
+async function openHighlightChat(page: Parameters<typeof sendMessage>[0]) {
+ await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
+ await selectMockEndpoint(page, MOCK_ENDPOINTS[1]);
+ await enableCodeInterpreter(page);
+}
+
+/** Idempotent, because `autoExpandTools` opens the pane for an operator who
+ * turned it on; the default is off, so these runs do the opening themselves. */
+async function openCodePane(page: Parameters<typeof sendMessage>[0]) {
+ const disclosure = codeDisclosure(page);
+ await expect(disclosure).toBeVisible({ timeout: 30000 });
+ if ((await disclosure.getAttribute('aria-expanded')) === 'false') {
+ await disclosure.click();
+ }
+ await expect(disclosure).toHaveAttribute('aria-expanded', 'true');
+}
+
+/**
+ * Opens the card, then waits for tokens.
+ *
+ * A closed pane is passed no code at all, so it tokenizes nothing and renders
+ * its raw text: opening the card is part of asserting anything about
+ * highlighting, and a scenario that skipped it would wait out its timeout
+ * against unhighlighted output no matter how the throttle behaved. Opening it
+ * while arguments are still streaming is also what puts the throttle under
+ * test, because that is the only time the input keeps changing.
+ */
+async function expectHighlightedCode(page: Parameters<typeof sendMessage>[0]) {
+ await openCodePane(page);
+ const code = highlightedCode(page);
+ await expect(code).toBeVisible({ timeout: 30000 });
+ await expect.poll(() => code.locator('span').count(), { timeout: 30000 }).toBeGreaterThan(0);
+ return code;
+}
+
+test.describe('streamed code highlighting', () => {
+ test('streamed-code-highlights-after-settle @scenario:streamed-code-highlights-after-settle', async ({
+ page,
+ }) => {
+ test.setTimeout(120000);
+ await openHighlightChat(page);
+ await sendMessage(page, 'E2E_HIGHLIGHT_CODE:stream');
+
+ await expect(stopButton(page)).toBeVisible({ timeout: 30000 });
+ const streaming = await expectHighlightedCode(page);
+ await expect(streaming).toContainText('line-119-☃');
+
+ await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
+ /** Persisting the streamed message rebuilds the card, and a rebuilt card
+ * starts closed, so the settled value is asserted through the same
+ * open-then-wait path instead of against the streaming card's tokens. */
+ const settled = await expectHighlightedCode(page);
+ await expect(settled).toContainText('line-119-☃');
+ });
+
+ test('interrupted-code-highlights-after-cancel @scenario:interrupted-code-highlights-after-cancel', async ({
+ page,
+ }) => {
+ test.setTimeout(120000);
+ await openHighlightChat(page);
+ await sendMessage(page, 'E2E_HIGHLIGHT_CODE:cancel');
+
+ await expect(stopButton(page)).toBeVisible({ timeout: 30000 });
+ /** Open the card while the arguments are still arriving, but stop the run
+ * before waiting on any token: waiting for a highlight first can outlast
+ * the stream and leave nothing to cancel. */
+ await openCodePane(page);
+ await stopButton(page).click();
+ await expect(stopButton(page)).toBeHidden({ timeout: 30000 });
+ /** Cancellation persists the partial message, which rebuilds the card the
+ * same way a completed run does. */
+ const cancelled = await expectHighlightedCode(page);
+ await expect(cancelled).toContainText(/line-\d+-☃/);
+ });
+
+ test('regenerated-code-highlights-latest-branch @scenario:regenerated-code-highlights-latest-branch', async ({
+ page,
+ }) => {
+ test.setTimeout(180000);
+ await openHighlightChat(page);
+ await sendMessage(page, 'E2E_HIGHLIGHT_CODE:regenerate');
+ await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
+ await expectHighlightedCode(page);
+
+ const assistant = messagesView(page).locator('.message-render').last();
+ await assistant.hover();
+ const regenerate = assistant.getByRole('button', { name: 'Regenerate', exact: true }).last();
+ await expect(regenerate).toBeVisible({ timeout: 30000 });
+ await Promise.all([
+ page.waitForResponse(isAgentsStream, { timeout: 30000 }),
+ regenerate.click(),
+ ]);
+ await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
+ const latestCode = await expectHighlightedCode(page);
+ await expect(latestCode).toContainText('line-119-☃');
+ });
+
+ test('restored-history-code-remains-highlighted @scenario:restored-history-code-remains-highlighted', async ({
+ page,
+ }) => {
+ test.setTimeout(180000);
+ await openHighlightChat(page);
+ await sendMessage(page, 'E2E_HIGHLIGHT_CODE:history');
+ await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
+ await expectHighlightedCode(page);
+ const conversationUrl = page.url();
+
+ await page.reload({ timeout: 10000 });
+ await expect(page).toHaveURL(conversationUrl);
+ const restoredCode = await expectHighlightedCode(page);
+ await expect(restoredCode).toContainText('line-119-☃');
+ await expect.poll(() => restoredCode.locator('span').count()).toBeGreaterThan(0);
+ });
+});
diff --git a/librechat.example.yaml b/librechat.example.yaml
index de0793c8e7..3c02bc4486 100644
--- a/librechat.example.yaml
+++ b/librechat.example.yaml
@@ -143,6 +143,8 @@ cache: true
# Custom interface configuration
interface:
customWelcome: 'Welcome to LibreChat! Enjoy your experience.'
+ # Minimum interval between syntax-highlighting passes while streamed code changes (default: 300 ms)
+ # codeHighlightThrottleMs: 300
# Enable/disable file search as a chatarea selection (default: true)
# Note: This setting does not disable the Agents File Search Capability.
# To disable the Agents Capability, see the Agents Endpoint configuration instead.
diff --git a/packages/api/src/shared-links/config.test.ts b/packages/api/src/shared-links/config.test.ts
index 60d26ffd1b..b89b2bb344 100644
--- a/packages/api/src/shared-links/config.test.ts
+++ b/packages/api/src/shared-links/config.test.ts
@@ -102,6 +102,23 @@ describe('isFileSnapshotEnabled', () => {
});
describe('buildSharedLinkStartupPayload', () => {
+ it.each([0, 100, 60000])(
+ 'includes the configured highlight cadence %i without other settings',
+ (codeHighlightThrottleMs) => {
+ expect(
+ buildSharedLinkStartupPayload(
+ appConfig({
+ interfaceConfig: {
+ codeHighlightThrottleMs,
+ modelSelect: true,
+ },
+ }),
+ {},
+ ),
+ ).toEqual({ appTitle: 'LibreChat', interface: { codeHighlightThrottleMs } });
+ },
+ );
+
it('builds the share-view startup allowlist', () => {
const payload = buildSharedLinkStartupPayload(
appConfig({
diff --git a/packages/api/src/shared-links/config.ts b/packages/api/src/shared-links/config.ts
index 856e81c1e4..d6952683a1 100644
--- a/packages/api/src/shared-links/config.ts
+++ b/packages/api/src/shared-links/config.ts
@@ -94,9 +94,11 @@ export function buildSharedLinkStartupPayload(
payload.customFooter = env.CUSTOM_FOOTER;
}
- const { privacyPolicy, termsOfService } = appConfig?.interfaceConfig ?? {};
- if (privacyPolicy || termsOfService) {
+ const { privacyPolicy, termsOfService, codeHighlightThrottleMs } =
+ appConfig?.interfaceConfig ?? {};
+ if (privacyPolicy || termsOfService || codeHighlightThrottleMs != null) {
payload.interface = {
+ ...(codeHighlightThrottleMs != null ? { codeHighlightThrottleMs } : {}),
...(privacyPolicy ? { privacyPolicy } : {}),
...(termsOfService ? { termsOfService } : {}),
};
diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts
index 5e51ec86d6..c6ab14f786 100644
--- a/packages/data-provider/src/config.ts
+++ b/packages/data-provider/src/config.ts
@@ -2066,6 +2066,8 @@ export const interfaceSchema = z
customWelcome: z.string().optional(),
mcpServers: mcpServersSchema.optional(),
modelSelect: z.boolean().optional(),
+ /** Milliseconds between syntax highlights while a code block streams. */
+ codeHighlightThrottleMs: z.number().int().min(0).max(60_000).default(300),
parameters: z.boolean().optional(),
multiConvo: z.boolean().optional(),
bookmarks: z.boolean().optional(),
@@ -2187,6 +2189,7 @@ export const interfaceSchema = z
})
.default({
modelSelect: true,
+ codeHighlightThrottleMs: 300,
parameters: true,
presets: true,
multiConvo: true,
@@ -2410,7 +2413,7 @@ export type TStartupConfig = {
export type TSharedLinkStartupInterface = Pick<
Partial<TInterfaceConfig>,
- 'privacyPolicy' | 'termsOfService'
+ 'privacyPolicy' | 'termsOfService' | 'codeHighlightThrottleMs'
>;
export type TSharedLinkStartupConfig = Pick<TStartupConfig, 'appTitle'> &
diff --git a/packages/data-schemas/src/app/interface.spec.ts b/packages/data-schemas/src/app/interface.spec.ts
index 495760f6f8..9292db4f18 100644
--- a/packages/data-schemas/src/app/interface.spec.ts
+++ b/packages/data-schemas/src/app/interface.spec.ts
@@ -12,6 +12,30 @@ describe('loadDefaultInterface', () => {
expect(interfaceConfig?.autoSubmitFromUrl).toBe(true);
});
+ it('uses the schema default for code highlight throttling when not configured', async () => {
+ const interfaceConfig = await loadDefaultInterface({
+ config: {},
+ configDefaults: getConfigDefaults(),
+ });
+
+ expect(interfaceConfig?.codeHighlightThrottleMs).toBe(300);
+ });
+
+ it('preserves a configured code highlight throttle interval', async () => {
+ const config: Partial<TCustomConfig> = {
+ interface: {
+ codeHighlightThrottleMs: 100,
+ },
+ };
+
+ const interfaceConfig = await loadDefaultInterface({
+ config,
+ configDefaults: getConfigDefaults(),
+ });
+
+ expect(interfaceConfig?.codeHighlightThrottleMs).toBe(100);
+ });
+
it('preserves disabled URL auto-submit config', async () => {
const config: Partial<TCustomConfig> = {
interface: {
diff --git a/packages/data-schemas/src/app/interface.ts b/packages/data-schemas/src/app/interface.ts
index 5793763dd6..67a9303922 100644
--- a/packages/data-schemas/src/app/interface.ts
+++ b/packages/data-schemas/src/app/interface.ts
@@ -32,6 +32,8 @@ export async function loadDefaultInterface({
modelSelect:
interfaceConfig?.modelSelect ??
(hasModelSpecs ? includesAddedEndpoints : defaults.modelSelect),
+ codeHighlightThrottleMs:
+ interfaceConfig?.codeHighlightThrottleMs ?? defaults.codeHighlightThrottleMs,
parameters: interfaceConfig?.parameters ?? (hasModelSpecs ? false : defaults.parameters),
presets: interfaceConfig?.presets ?? (hasModelSpecs ? false : defaults.presets),
privacyPolicy: interfaceConfig?.privacyPolicy ?? defaults.privacyPolicy,