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
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🧬 fix: Derive the Theme Cache Version and Align Color Tokens (#16819)
Marco Beretta41825b7bb9a0
diff --git a/client/index.html b/client/index.htmlindex 16be69fb9e..35f40da433 100644--- a/client/index.html+++ b/client/index.html@@ -105,7 +105,7 @@try {const cached = JSON.parse(localStorage.getItem('deployment-theme') || 'null');const boot =- cached && cached.v === 2 && cached.modes && cached.modes[dark ? 'dark' : 'light'];+ cached && cached.v === '__THEME_CACHE_VERSION__' && cached.modes && cached.modes[dark ? 'dark' : 'light'];if (boot && Array.isArray(boot.properties)) {let surface;let canvas;diff --git a/client/src/Providers/DeploymentTheme.tsx b/client/src/Providers/DeploymentTheme.tsxindex 7125d8dd34..f164038ddc 100644--- a/client/src/Providers/DeploymentTheme.tsx+++ b/client/src/Providers/DeploymentTheme.tsx@@ -243,6 +243,15 @@ export default function DeploymentTheme({ children }: { children: React.ReactNoduseRebindOnStartupConfigRebuild();const { data: startupConfig, isPreviousData } = useGetStartupConfig({ keepPreviousData: true });const owner = themeOwner(useRecoilValue(store.user));+ /**+ * The signed-out answer by identity, kept apart from the query cache: login removes the+ * queries, yet the observer keeps showing that answer as previous data until the signed-in+ * one arrives, and it must still read as the signed-out one.+ */+ const signedOutAnswer = useRef<typeof startupConfig>(undefined);+ if (startupConfig && !isPreviousData && !owner) {+ signedOutAnswer.current = startupConfig;+ }const [cached, setCached] = useThemeCache(owner);const [override, setOverride] = useState<ThemeOverride>(undefined);/** A route override is another tenant's theme: it neither reads nor writes the cache. */@@ -254,6 +263,7 @@ export default function DeploymentTheme({ children }: { children: React.ReactNodanswer: startupConfig && {theme: startupConfig.interface?.theme,current: !isPreviousData,+ signedOut: startupConfig === signedOutAnswer.current,},});const configTheme = decision.theme;diff --git a/client/src/Providers/__tests__/DeploymentTheme.spec.tsx b/client/src/Providers/__tests__/DeploymentTheme.spec.tsxindex ffb74ee833..24e699fe5b 100644--- a/client/src/Providers/__tests__/DeploymentTheme.spec.tsx+++ b/client/src/Providers/__tests__/DeploymentTheme.spec.tsx@@ -537,6 +537,57 @@ describe('DeploymentTheme cache', () => {await waitFor(() => expect(root().dataset.theme).toBe('acme'));});+ it('keeps painting the signed-out answer while the signed-in one loads', async () => {+ let signIn: () => void = () => undefined;+ function SignIn() {+ const setUser = useSetRecoilState(store.user);+ signIn = () => setUser(user as TUser);+ return null;+ }+ getStartupConfig.mockResolvedValueOnce(configWith('clickhouse'));+ render(+ <RecoilRoot>+ <QueryClientProvider client={queryClient}>+ <DeploymentTheme>+ <SignIn />+ </DeploymentTheme>+ </QueryClientProvider>+ </RecoilRoot>,+ );+ await waitFor(() => expect(root().dataset.theme).toBe('clickhouse'));++ getStartupConfig.mockReturnValue(new Promise(() => undefined));+ act(() => {+ queryClient.removeQueries();+ signIn();+ });+ expect(root().dataset.theme).toBe('clickhouse');+ });++ it('drops a signed-in answer when the identity ends before the signed-out one loads', async () => {+ let signOut: () => void = () => undefined;+ function SignOut() {+ const setUser = useSetRecoilState(store.user);+ signOut = () => setUser(undefined);+ return null;+ }+ getStartupConfig.mockResolvedValueOnce(configWith('clickhouse'));+ render(+ <RecoilRoot initializeState={({ set }) => set(store.user, user as TUser)}>+ <QueryClientProvider client={queryClient}>+ <DeploymentTheme>+ <SignOut />+ </DeploymentTheme>+ </QueryClientProvider>+ </RecoilRoot>,+ );+ await waitFor(() => expect(root().dataset.theme).toBe('clickhouse'));++ getStartupConfig.mockReturnValue(new Promise(() => undefined));+ act(() => signOut());+ await waitFor(() => expect(root().dataset.theme).toBeUndefined());+ });+it('does not write a signed-out answer over the cache', async () => {cacheTheme();getStartupConfig.mockResolvedValue(configWith());diff --git a/client/src/Providers/__tests__/bootScript.spec.tsx b/client/src/Providers/__tests__/bootScript.spec.tsxindex 168772862b..4eba68a637 100644--- a/client/src/Providers/__tests__/bootScript.spec.tsx+++ b/client/src/Providers/__tests__/bootScript.spec.tsx@@ -3,7 +3,14 @@ import { readFileSync } from 'fs';import { render } from '@testing-library/react';import { ThemeProvider, applyResolvedTheme, resolveTheme } from '@librechat/client';import type { ThemeDefinition } from '@librechat/client';-import { isPublicRoute, buildThemeCache, writeThemeCache } from '../themeCache';+import {+ isPublicRoute,+ buildThemeCache,+ writeThemeCache,+ THEME_CACHE_KEY,+ THEME_CACHE_VERSION,+} from '../themeCache';+import { THEME_CACHE_VERSION_PLACEHOLDER, injectThemeCacheVersion } from '../bootVersion';/** The inline shell script in `client/index.html`, run as the browser runs it. */const bootScript = (() => {@@ -13,7 +20,7 @@ const bootScript = (() => {if (!script) {throw new Error('client/index.html has no deployment theme boot script');}- return script;+ return injectThemeCacheVersion(script);})();const acme: ThemeDefinition = {@@ -96,6 +103,28 @@ describe('index.html deployment theme boot script', () => {},);+ it('leaves the placeholder out of the script the build serves', () => {+ expect(bootScript).not.toContain(THEME_CACHE_VERSION_PLACEHOLDER);+ expect(bootScript).toContain(`'${THEME_CACHE_VERSION}'`);+ });++ it('does not replay an entry stored against another role set', () => {+ const stored = JSON.parse(localStorage.getItem(THEME_CACHE_KEY) ?? 'null');+ localStorage.setItem(THEME_CACHE_KEY, JSON.stringify({ ...stored, v: 'before-a-new-role' }));+ boot();+ expect(root().getAttribute('style')).toBeNull();+ expect(root().hasAttribute('data-theme')).toBe(false);+ });++ it('paints nothing on a first-ever visit, leaving the operator theme to the config answer', () => {+ localStorage.clear();+ boot();+ expect(root().getAttribute('style')).toBeNull();+ expect(root().hasAttribute('data-theme')).toBe(false);+ expect(root().hasAttribute('data-theme-boot')).toBe(false);+ expect(root().classList.contains('light')).toBe(true);+ });+it('follows the OS scheme under `system`', () => {mockMedia(true);boot();diff --git a/client/src/Providers/__tests__/themeCache.spec.ts b/client/src/Providers/__tests__/themeCache.spec.tsindex e06258b002..e1e0bc951f 100644--- a/client/src/Providers/__tests__/themeCache.spec.ts+++ b/client/src/Providers/__tests__/themeCache.spec.ts@@ -1,4 +1,5 @@import { clickHouseTheme } from '@librechat/client';+import { themeRoleFingerprint } from 'librechat-data-provider';import type { ThemeCacheEntry } from '../themeCache';import {themeOwner,@@ -8,6 +9,7 @@ import {clearThemeCache,writeThemeCache,THEME_CACHE_KEY,+ THEME_CACHE_VERSION,reconcileThemeCache,} from '../themeCache';@@ -75,9 +77,26 @@ describe('reconcileThemeCache', () => {it('keeps the uncached behavior when nothing is cached', () => {expect(reconcileThemeCache({})).toEqual({ theme: undefined, cache: 'keep' });expect(- reconcileThemeCache({ owner: OWNER, answer: { theme: 'clickhouse', current: false } }),+ reconcileThemeCache({+ owner: OWNER,+ answer: { theme: 'clickhouse', current: false, signedOut: true },+ }),).toEqual({ theme: 'clickhouse', cache: 'keep' });});++ it('paints no previous answer that came from another signed-in key', () => {+ expect(+ reconcileThemeCache({ owner: OWNER, answer: { theme: 'clickhouse', current: false } }),+ ).toEqual({ theme: undefined, cache: 'keep' });+ expect(+ reconcileThemeCache({ answer: { theme: 'clickhouse', current: false, signedOut: false } }),+ ).toEqual({ theme: undefined, cache: 'keep' });+ });++ it('stamps entries with a version derived from the registry roles', () => {+ expect(cached.v).toBe(themeRoleFingerprint());+ expect(THEME_CACHE_VERSION).toBe(themeRoleFingerprint());+ });});describe('theme cache storage', () => {diff --git a/client/src/Providers/bootVersion.ts b/client/src/Providers/bootVersion.tsnew file mode 100644index 0000000000..cc093db1da--- /dev/null+++ b/client/src/Providers/bootVersion.ts@@ -0,0 +1,7 @@+import { themeRoleFingerprint } from 'librechat-data-provider';++export const THEME_CACHE_VERSION_PLACEHOLDER = '__THEME_CACHE_VERSION__';++/** Writes the cache version into the boot script's check, as the Vite build does for `index.html`. */+export const injectThemeCacheVersion = (html: string): string =>+ html.replace(THEME_CACHE_VERSION_PLACEHOLDER, themeRoleFingerprint());diff --git a/client/src/Providers/themeCache.ts b/client/src/Providers/themeCache.tsindex f4e43bfa02..e48b45ff77 100644--- a/client/src/Providers/themeCache.ts+++ b/client/src/Providers/themeCache.ts@@ -1,3 +1,4 @@+import { themeRoleFingerprint } from 'librechat-data-provider';import { resolveTheme, describeResolvedTheme } from '@librechat/client';import type { ResolvedThemeStyle, ThemeDefinition } from '@librechat/client';import type { TInterfaceConfig, TUser } from 'librechat-data-provider';@@ -10,10 +11,14 @@ type DeploymentThemeValue = TInterfaceConfig['theme'];* replays `modes` before the bundle runs, so its key and shape must stay in step.*/export const THEME_CACHE_KEY = 'deployment-theme';-export const THEME_CACHE_VERSION = 2;+/**+ * Derived from the registry's role set, so adding a role retires the entries stored before it.+ * `client/vite.config.ts` writes the same value into the boot script's version check.+ */+export const THEME_CACHE_VERSION = themeRoleFingerprint();export type ThemeCacheEntry = {- v: typeof THEME_CACHE_VERSION;+ v: string;/** `tenantId:userId` of the identity the theme was served to. */owner: string;/** The raw `interface.theme`, which the app resolves itself until the config answers. */@@ -30,8 +35,12 @@ export type ThemeCacheEntry = {*/export type ThemeCacheAction = 'keep' | 'clear' | 'disown' | 'write';-/** A config answer; `current` is false while `keepPreviousData` shows another identity's answer. */-export type ThemeAnswer = { theme: DeploymentThemeValue; current: boolean };+/**+ * A config answer; `current` is false while `keepPreviousData` shows the answer of another+ * query key. Only the signed-out answer of the same deployment is a safe stand-in, so+ * `signedOut` marks it.+ */+export type ThemeAnswer = { theme: DeploymentThemeValue; current: boolean; signedOut?: boolean };/*** Routes that render without the viewer's signed-in config: the auth pages, and shared@@ -133,7 +142,9 @@ export function writeThemeCache(entry: ThemeCacheEntry): void {* - with no current answer, the cache stands in, unless the signed-in identity is* known and is not the one it was served to: then nothing paints until that* identity's own answer arrives, since a previous answer may be the other one's;- * - otherwise the previous answer, if any, keeps painting as before.+ * - otherwise the previous answer keeps painting while it is the signed-out one, which is+ * the same deployment's; one from another signed-in key may be another identity's, so+ * nothing paints until the current answer arrives.* A theme that turns out invalid is cleared by the caller, which resolves it.*/export function reconcileThemeCache({@@ -160,5 +171,8 @@ export function reconcileThemeCache({if (cached) {return { theme: cached.source, cache: 'keep' };}+ if (answer && !answer.current && !answer.signedOut) {+ return { theme: undefined, cache: 'keep' };+ }return { theme: answer?.theme, cache: 'keep' };}diff --git a/client/vite.config.ts b/client/vite.config.tsindex 91d0cac2db..f187e47e89 100644--- a/client/vite.config.ts+++ b/client/vite.config.ts@@ -8,6 +8,7 @@ import { VitePWA } from 'vite-plugin-pwa';import { nodePolyfills } from 'vite-plugin-node-polyfills';import { compression, defineAlgorithm } from 'vite-plugin-compression2';import type { Plugin } from 'vite';+import { injectThemeCacheVersion } from './src/Providers/bootVersion.ts';const require = createRequire(import.meta.url);@@ -89,6 +90,7 @@ export default defineConfig(({ command }) => ({});},},+ themeCacheVersion(),copyPublicAssets(),VitePWA({injectRegister: 'auto', // 'auto' | 'manual' | 'disabled'@@ -455,6 +457,18 @@ export default defineConfig(({ command }) => ({},}));+/**+ * Writes the deployment-theme cache version into the boot script's check, the same value+ * `themeCache.ts` stamps on the entries it stores, so a role added to the registry retires+ * every entry stored before it without anyone remembering to bump a number.+ */+export function themeCacheVersion(): Plugin {+ return {+ name: 'theme-cache-version',+ transformIndexHtml: injectThemeCacheVersion,+ };+}+interface SourcemapExclude {excludeNodeModules?: boolean;}diff --git a/packages/client/src/components/Button.tsx b/packages/client/src/components/Button.tsxindex 51ab33fc10..99b764e491 100644--- a/packages/client/src/components/Button.tsx+++ b/packages/client/src/components/Button.tsx@@ -222,7 +222,7 @@ const buttonVariantRecipe = cva(card: 'justify-start whitespace-normal rounded-2xl text-left font-normal hover:bg-surface-hover focus-visible:ring-inset focus-visible:ring-offset-0',},size: {- default: 'h-theme-button px-4 py-2',+ default: 'h-theme-button px-theme-button-x py-2',/** Default-height actions with less horizontal padding, such as Copy link. */dense: 'h-theme-button px-3 py-2',/** Compact text controls that share a toolbar row with a compact dropdown. */diff --git a/packages/client/src/components/SelectDropDown.tsx b/packages/client/src/components/SelectDropDown.tsxindex 39ed02b82f..46a8a7d05d 100644--- a/packages/client/src/components/SelectDropDown.tsx+++ b/packages/client/src/components/SelectDropDown.tsx@@ -193,7 +193,7 @@ function SelectDropDown({><ListboxOptionsclassName={cn(- 'border-border-light bg-surface-secondary absolute z-10 mt-2 max-h-60 w-full overflow-auto rounded border text-xs md:w-[100%]',+ 'border-border-light bg-surface-secondary absolute z-10 mt-2 max-h-60 w-full overflow-auto rounded-sm border text-xs md:w-[100%]',optionsListClass ?? '',)}>diff --git a/packages/client/src/theme/README.md b/packages/client/src/theme/README.mdindex bfe9de15b4..1fd6ed299a 100644--- a/packages/client/src/theme/README.md+++ b/packages/client/src/theme/README.md@@ -426,7 +426,8 @@ Each status family has a foreground, a `-subtle` background, a `-border`, and a- `text-dialog-title` - An OGDialog title's ink. Follows `text-primary` when atheme names only that.- OGDialog chrome - `border-(length:--theme-dialog-stroke)` (`dialogStroke`, painted in- `border-light`, none by default), `px-theme-dialog-x` (`dialogPaddingX`),+ `border-light`, none by default), `px-theme-button-x` (`buttonPaddingX`, the Button's default+ size), `px-theme-dialog-x` (`dialogPaddingX`),`space-y-theme-dialog-header` (`dialogHeaderGap`), and for the title`text-(length:--theme-dialog-title-size)` and`leading-(--theme-dialog-title-leading)` (`dialogTitleSize`, `dialogTitleLeading`),diff --git a/packages/client/src/theme/defaults.css b/packages/client/src/theme/defaults.cssindex fb33f31fb9..1c968b8f7c 100644--- a/packages/client/src/theme/defaults.css+++ b/packages/client/src/theme/defaults.css@@ -275,6 +275,7 @@ html {--theme-icon-size-md: 1.25rem;--theme-icon-size-lg: 1.5rem;--theme-control-font-weight: 500;+ --theme-button-padding-x: 1rem;--theme-button-height: 2.5rem;--theme-button-height-sm: 2.25rem;--theme-button-height-xs: 1.75rem;diff --git a/packages/client/src/theme/registry.spec.ts b/packages/client/src/theme/registry.spec.tsindex 91a7d19a7e..125bda5e4f 100644--- a/packages/client/src/theme/registry.spec.ts+++ b/packages/client/src/theme/registry.spec.ts@@ -14,6 +14,7 @@ import {themeColorTokens,validateThemeDefinition,} from './registry';+import { describeResolvedTheme } from './utils/applyTheme';import { clickHouseTheme } from './themes/clickhouse';import { defaultTheme } from './themes/default';import { darkTheme } from './themes/dark';@@ -2147,3 +2148,41 @@ describe('theme registry', () => {expect(() => resolveTheme(definition as ThemeDefinition, 'light')).toThrow(TypeError);});});++describe('appearance families substitute through the emitted variables', () => {+ const reference: ThemeDefinition = {+ version: 1,+ name: 'family-reference',+ modes: {+ light: {+ appearance: {+ radiusLg: '0.125rem',+ fontFamily: 'Georgia, serif',+ shadowMd: '0 1px 2px 0 rgb(0 0 0 / 0.3)',+ controlHeight: '3rem',+ spaceNormal: '1rem',+ },+ },+ },+ };+ const emitted = (theme: ThemeDefinition) =>+ new Map(describeResolvedTheme(resolveTheme(theme, 'light')).properties);++ it.each([+ ['radius', '--theme-radius-lg', '0.125rem'],+ ['font', '--theme-font-family', 'Georgia, serif'],+ ['shadow', '--theme-shadow-md', '0 1px 2px 0 rgb(0 0 0 / 0.3)'],+ ['density (control height)', '--theme-control-height', '3rem'],+ ['density (spacing)', '--theme-space-normal', '1rem'],+ ])(+ 'changes the %s variable and only restates it for a reference theme',+ (_family, property, value) => {+ const base = emitted(libreChatTheme);+ const themed = emitted(reference);++ expect(base.get(property)).toBeDefined();+ expect(themed.get(property)).toBe(value);+ expect(themed.get(property)).not.toBe(base.get(property));+ },+ );+});diff --git a/packages/client/src/theme/registry.ts b/packages/client/src/theme/registry.tsindex 2d5f9c283c..783a0be366 100644--- a/packages/client/src/theme/registry.ts+++ b/packages/client/src/theme/registry.ts@@ -234,6 +234,7 @@ export const themeAppearanceProperties: Readonly<radius3xl: '--theme-radius-3xl',controlHeight: '--theme-control-height',controlPaddingX: '--theme-control-padding-x',+ buttonPaddingX: '--theme-button-padding-x',controlGap: '--theme-control-gap',iconSize: '--theme-icon-size',iconSizeMd: '--theme-icon-size-md',@@ -336,6 +337,7 @@ export const defaultAppearance: IThemeAppearance = Object.freeze({radius3xl: '1.5rem',controlHeight: '2.25rem',controlPaddingX: '0.75rem',+ buttonPaddingX: '1rem',controlGap: '0.375rem',iconSize: '1rem',iconSizeMd: '1.25rem',diff --git a/packages/client/src/theme/tailwind.spec.js b/packages/client/src/theme/tailwind.spec.jsindex 093b2d1c17..2df18a400e 100644--- a/packages/client/src/theme/tailwind.spec.js+++ b/packages/client/src/theme/tailwind.spec.js@@ -116,6 +116,7 @@ describe('LibreChat Tailwind preset', () => {['h-theme-field', '--theme-field-height', defaultAppearance.fieldHeight],['py-theme-field-y', '--theme-field-padding-y', defaultAppearance.fieldPaddingY],['font-theme-control', '--theme-control-font-weight', defaultAppearance.controlFontWeight],+ ['px-theme-button-x', '--theme-button-padding-x', defaultAppearance.buttonPaddingX],['px-theme-dialog-x', '--theme-dialog-padding-x', defaultAppearance.dialogPaddingX],['font-theme-dialog-title-weight',diff --git a/packages/client/src/theme/themes/clickhouse.spec.tsx b/packages/client/src/theme/themes/clickhouse.spec.tsxindex a38c28ab96..f6158caee5 100644--- a/packages/client/src/theme/themes/clickhouse.spec.tsx+++ b/packages/client/src/theme/themes/clickhouse.spec.tsx@@ -463,6 +463,7 @@ describe('clickhouse theme definition', () => {expect(appearance).toMatchObject({controlHeight: '2rem',controlPaddingX: '1rem',+ buttonPaddingX: '1rem',controlGap: '0.5rem',controlFontWeight: '400',buttonHeight: '2rem',diff --git a/packages/client/src/theme/themes/clickhouse.ts b/packages/client/src/theme/themes/clickhouse.tsindex bb56805fef..8debb349a1 100644--- a/packages/client/src/theme/themes/clickhouse.ts+++ b/packages/client/src/theme/themes/clickhouse.ts@@ -469,6 +469,7 @@ const clickHouseShape = {shadowSm: '0 2px 2px 0 rgb(0 0 0 / 0.03)', // shadow.5controlHeight: '2rem', // genericMenu.panel.size.heightcontrolPaddingX: '1rem', // button.basic.space.x+ buttonPaddingX: '1rem', // button.basic.space.xcontrolGap: '0.5rem', // button.basic.space.gapcontrolFontWeight: '400', // button.basic.typography.label.default/** Click UI's button is sized by its content: 0.2813rem of space.y on both sides of adiff --git a/packages/client/src/theme/themes/clickui.spec.ts b/packages/client/src/theme/themes/clickui.spec.tsindex 0a15612dcd..55e0a7234e 100644--- a/packages/client/src/theme/themes/clickui.spec.ts+++ b/packages/client/src/theme/themes/clickui.spec.ts@@ -759,6 +759,7 @@ const appearanceSources: Partial<Record<keyof IThemeAppearance, string>> = {elevationDrag: 'shadow.1',controlHeight: 'click.genericMenu.panel.size.height',controlPaddingX: 'click.button.basic.space.x',+ buttonPaddingX: 'click.button.basic.space.x',controlGap: 'click.button.basic.space.gap',controlFontWeight: 'click.button.basic.typography.label.default',dialogStroke: 'click.dialog.stroke.default',@@ -1592,7 +1593,11 @@ const sizeRoles: Record<SizeUtility, Record<string, keyof IThemeAppearance>> = {'theme-button-sm': 'buttonHeightSm',},py: { 'theme-table-cell': 'tableCellSpaceY', 'theme-field-y': 'fieldPaddingY' },- px: { 'theme-control-x': 'controlPaddingX', 'theme-dialog-x': 'dialogPaddingX' },+ px: {+ 'theme-button-x': 'buttonPaddingX',+ 'theme-control-x': 'controlPaddingX',+ 'theme-dialog-x': 'dialogPaddingX',+ },gap: { 'theme-control-gap': 'controlGap' },};diff --git a/packages/client/src/theme/tokens.css b/packages/client/src/theme/tokens.cssindex 7e41010148..d95db59fb4 100644--- a/packages/client/src/theme/tokens.css+++ b/packages/client/src/theme/tokens.css@@ -200,6 +200,18 @@--color-switch-thumb: rgb(var(--switch-thumb, var(--surface-primary)));--color-table-header-text: rgb(var(--table-header-text, var(--text-secondary)));--color-table-header-fill: rgb(var(--table-header-fill, var(--surface-dialog)));+ /* The code-syntax palette and the shimmer animation are painted from stylesheets, so these carry no+ * utility today; each is declared so the registry and this file name the same colors. */+ --color-syntax-text: rgb(var(--syntax-text));+ --color-syntax-comment: rgb(var(--syntax-comment));+ --color-syntax-meta: rgb(var(--syntax-meta));+ --color-syntax-builtin: rgb(var(--syntax-builtin));+ --color-syntax-keyword: rgb(var(--syntax-keyword));+ --color-syntax-string: rgb(var(--syntax-string));+ --color-syntax-attr: rgb(var(--syntax-attr));+ --color-syntax-title: rgb(var(--syntax-title));+ --color-shimmer-base: rgb(var(--shimmer-base) / var(--shimmer-base-alpha, 1));+ --color-shimmer-dip: rgb(var(--shimmer-dip) / var(--shimmer-dip-alpha, 1));}/* The plain radius, font, type scale and shadow utilities read theme-owned properties, so a themediff --git a/packages/client/src/theme/tokens.spec.ts b/packages/client/src/theme/tokens.spec.tsindex c0110e9e6e..a9977ac932 100644--- a/packages/client/src/theme/tokens.spec.ts+++ b/packages/client/src/theme/tokens.spec.ts@@ -3,6 +3,7 @@ import path from 'path';import fsp from 'fs/promises';import { compile } from 'tailwindcss';import { deserialize, serialize } from 'v8';+import { themeColorTokens, themeDerivedColorTokens } from 'librechat-data-provider';import { defaultTheme } from './themes/default';/** Tailwind's compiler clones its theme with `structuredClone`, which jsdom does not provide.@@ -21,13 +22,6 @@ const declarations = new Map();const declared = new Set(declarations.keys());-/**- * Theme properties consumed by stylesheets rather than by utilities: the shimmer animation and- * the code-syntax palette are set in CSS, so they carry no `bg-`/`text-` class and need no- * Tailwind color token.- */-const cssOnlyFamilies = /^(shimmer|syntax)-/;-async function generate(candidates: string[],entry = `@import 'tailwindcss';\n@import './tokens.css';\n@config '../../tailwind.preset.cjs';\n`,@@ -64,23 +58,37 @@ async function generate(}describe('theme color tokens', () => {- it('exposes every theme color the registry can set', () => {- const missing = Object.keys(defaultTheme)- .map((property) => property.replace(/^rgb-/, ''))- .filter((token) => !cssOnlyFamilies.test(token) && !declared.has(token));+ it('declares exactly the colors the registry names, in either direction', () => {+ const registry = new Set<string>([+ ...themeColorTokens.map((property) => property.replace(/^rgb-/, '')),+ ...themeDerivedColorTokens,+ ]);- expect(missing).toEqual([]);+ expect([...registry].filter((token) => !declared.has(token))).toEqual([]);+ expect([...declared].filter((token) => !registry.has(token))).toEqual([]);});it('lets a theme set every color token the stylesheet declares', () => {const registered = new Set(Object.keys(defaultTheme).map((key) => key.replace(/^rgb-/, '')));const unowned = [...declarations]+ .filter(([token]) => !(themeDerivedColorTokens as readonly string[]).includes(token)).filter(([, reads]) => !reads.some((property) => registered.has(property))).map(([token]) => token);expect(unowned).toEqual([]);});+ it('reads each derived color from roles a theme can set', () => {+ const registered = new Set<string>(+ Object.keys(defaultTheme).map((key) => key.replace(/^rgb-/, '')),+ );+ const orphaned = themeDerivedColorTokens.filter(+ (token) => !declarations.get(token)?.some((property) => registered.has(property)),+ );++ expect(orphaned).toEqual([]);+ });+it('resolves a token to the custom property the theme rewrites at runtime', async () => {const css = await generate(['bg-surface-primary',diff --git a/packages/client/src/theme/types/index.ts b/packages/client/src/theme/types/index.tsindex 86d23988f2..c7d8a75718 100644--- a/packages/client/src/theme/types/index.ts+++ b/packages/client/src/theme/types/index.ts@@ -616,6 +616,8 @@ export interface IThemeAppearance {/** A theme-sized control's inline padding and icon-to-label gap; they follow `spaceNormal` and* `spaceCompact` when a theme names those and not these. */controlPaddingX: string;+ /** The Button's default size inline padding. */+ buttonPaddingX: string;controlGap: string;/** An icon beside a label or in a menu row (0.75 to 1.25rem), and the larger one a dialog's* close button draws (1 to 2rem). */diff --git a/packages/client/src/utils/utils.spec.ts b/packages/client/src/utils/utils.spec.tsindex 9cac8b3bb8..31ee08c5b9 100644--- a/packages/client/src/utils/utils.spec.ts+++ b/packages/client/src/utils/utils.spec.ts@@ -24,4 +24,11 @@ describe('cn', () => {expect(cn('text-2xs', 'text-sm')).toBe('text-sm');expect(cn('text-sm', 'text-1xs')).toBe('text-1xs');});++ it.each(['px-0', 'px-3', 'px-theme-control-x'])(+ 'lets %s replace the Button padding role',+ (caller) => {+ expect(cn('px-theme-button-x', caller)).toBe(caller);+ },+ );});diff --git a/packages/client/src/utils/utils.ts b/packages/client/src/utils/utils.tsindex 4441c5398f..098973a853 100644--- a/packages/client/src/utils/utils.ts+++ b/packages/client/src/utils/utils.ts@@ -57,7 +57,7 @@ const twMerge = extendTailwindMerge({],},],- px: [{ px: ['theme-control-x', 'theme-dialog-x'] }],+ px: [{ px: ['theme-button-x', 'theme-control-x', 'theme-dialog-x'] }],gap: [{ gap: ['theme-control-gap'] }],'space-y': [{ 'space-y': ['theme-dialog-header'] }],'font-weight': [{ font: ['theme-control', 'theme-dialog-title-weight', 'theme-label'] }],diff --git a/packages/client/tailwind.preset.cjs b/packages/client/tailwind.preset.cjsindex 2a8bfa3164..e5a16d994c 100644--- a/packages/client/tailwind.preset.cjs+++ b/packages/client/tailwind.preset.cjs@@ -74,6 +74,7 @@ module.exports = {'theme-icon-lg': 'var(--theme-icon-size-lg, 1.5rem)',/** A theme-sized control's inline padding and gap, falling back to the shared spacing it* read before, for a stylesheet that predates the roles. */+ 'theme-button-x': 'var(--theme-button-padding-x, 1rem)','theme-control-x': 'var(--theme-control-padding-x, var(--theme-space-normal, 0.75rem))','theme-control-gap': 'var(--theme-control-gap, var(--theme-space-compact, 0.375rem))',/** A dialog's inline padding and the gap between its title and description. */diff --git a/packages/data-provider/src/theme.ts b/packages/data-provider/src/theme.tsindex 3c7c7b970f..642a60dba0 100644--- a/packages/data-provider/src/theme.ts+++ b/packages/data-provider/src/theme.ts@@ -181,6 +181,23 @@ export const themeBrandTokens = Object.freeze([export type ThemeBrandToken = (typeof themeBrandTokens)[number];+/**+ * Color utilities the stylesheet computes from other roles, so a theme sets the roles they read+ * (an overlay, a border, an appearance share) and never the name itself.+ */+export const themeDerivedColorTokens = Object.freeze([+ 'scrim',+ 'scrim-alert',+ 'scrim-modal',+ 'border-chrome',+ 'border-chrome-heavy',+ 'border-chrome-medium',+ 'border-inset',+ 'border-inset-medium',+] as const);++export type ThemeDerivedColorToken = (typeof themeDerivedColorTokens)[number];+/** One problem in a theme definition: where it is, relative to the definition, and what it is. */export interface ThemeIssue {path: string[];@@ -403,6 +420,8 @@ const appearanceValidators = {/** The inline padding and icon-to-label gap of a theme-sized control, apart from the shared* spacing that also pads message rows. */controlPaddingX: isLength,+ /** The Button's default size inline padding. */+ buttonPaddingX: isLength,controlGap: isLength,/** An icon's size (0.75 to 1.25rem), and the larger one a dialog's close button draws (1 to* 2rem). */@@ -506,6 +525,28 @@ export const themeAppearanceTokens = Object.freeze(Object.keys(appearanceValidators) as ThemeAppearanceToken[],);+/**+ * Bumped by hand when a release changes what resolving a theme emits without changing its roles+ * (a palette value, a fallback derivation, an emitted attribute), so cached entries are rebuilt.+ */+export const THEME_CACHE_EPOCH = 1 as const;++/**+ * Names the role set a stored resolved theme was built against: any color, brand or appearance+ * role added or removed changes it. A cache that replays resolved variables keys itself on this,+ * so an entry that predates a role is dropped instead of painting that role's stylesheet default.+ */+export function themeRoleFingerprint(): string {+ const roles = [...themeColorTokens, ...themeBrandTokens, ...themeAppearanceTokens]+ .sort()+ .join(',');+ let hash = 5381;+ for (let i = 0; i < roles.length; i++) {+ hash = ((hash * 33) ^ roles.charCodeAt(i)) >>> 0;+ }+ return `${THEME_VERSION}.${THEME_CACHE_EPOCH}.${hash.toString(36)}`;+}+export const isThemeAppearanceToken = (key: string): key is ThemeAppearanceToken =>Object.prototype.hasOwnProperty.call(appearanceValidators, key);