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: Read Theme Roles for the Last Artifact and Agent Chip Colours (#16705)
Marco Berettaa2b184b23107
diff --git a/client/src/components/Artifacts/Artifacts.tsx b/client/src/components/Artifacts/Artifacts.tsxindex 2f93beb32c..c8a10c66b3 100644--- a/client/src/components/Artifacts/Artifacts.tsx+++ b/client/src/components/Artifacts/Artifacts.tsx@@ -448,7 +448,7 @@ export default function Artifacts() {{isMobile && (<divclassName={cn(- 'fixed inset-0 z-[99] bg-black will-change-[opacity,backdrop-filter] motion-reduce:transition-none',+ 'bg-surface-overlay fixed inset-0 z-[99] will-change-[opacity,backdrop-filter] motion-reduce:transition-none',isVisible && !isClosing? 'transition-all duration-300': 'pointer-events-none opacity-0 backdrop-blur-none transition-opacity duration-150',@@ -663,7 +663,7 @@ export default function Artifacts() {<divclassName={cn(- 'absolute inset-0 z-[60] flex items-center justify-center bg-black/70 backdrop-blur-xs transition-opacity duration-300 ease-in-out',+ 'bg-surface-media-overlay/70 absolute inset-0 z-[60] flex items-center justify-center backdrop-blur-xs transition-opacity duration-300 ease-in-out',isRefreshing ? 'pointer-events-auto opacity-100' : 'pointer-events-none opacity-0',)}aria-hidden={!isRefreshing}diff --git a/client/src/components/SidePanel/Agents/AgentConfig.tsx b/client/src/components/SidePanel/Agents/AgentConfig.tsxindex 6e4de70689..4e091d513d 100644--- a/client/src/components/SidePanel/Agents/AgentConfig.tsx+++ b/client/src/components/SidePanel/Agents/AgentConfig.tsx@@ -117,7 +117,7 @@ export default function AgentConfig() {><div className="flex w-full min-w-0 items-center gap-2">{providerValue !== undefined && (- <div className="shadow-stroke relative flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-white text-black dark:bg-white">+ <div className="shadow-stroke bg-surface-primary text-text-primary relative flex h-6 w-6 shrink-0 items-center justify-center rounded-full"><ResolvedProviderIconprovider={providerId}imageURL={imageURL}diff --git a/e2e/specs/mock/scenarios/theme-sweep-roles.spec.ts b/e2e/specs/mock/scenarios/theme-sweep-roles.spec.tsnew file mode 100644index 0000000000..5be56e7f5c--- /dev/null+++ b/e2e/specs/mock/scenarios/theme-sweep-roles.spec.ts@@ -0,0 +1,204 @@+import { randomUUID } from 'crypto';+import { expect, test } from '@playwright/test';+import type { Locator, Page } from '@playwright/test';+import {+ deleteConversations,+ deleteMessagesByConversation,+ seedConversations,+ seedMessages,+} from '../db';+import { openAgentBuilder, selectMockModel } from '../agents.helpers';+import { NEW_CHAT_PATH, messagesView } from '../helpers';+import { getE2EUser } from '../../../setup/user';++/**+ * Three literals outlived the theme sweep: the Agent Builder's provider chip+ * was always white on black, the artifact sheet's phone backdrop was always+ * black, and the artifact refresh veil was always black at 70%. Each now paints+ * a role, so a theme decides them. These scenarios read the computed paint of+ * each element, first against the role as the bundled palette resolves it and+ * then under a definition whose triples no bundled palette holds, which only+ * the role can deliver.+ */++const THEME_PARAM = 'e2eThemeMode';+const ROOT_PARENT = '00000000-0000-0000-0000-000000000000';+const ARTIFACT_TITLE = 'Overlay roles';+const ARTIFACT_TEXT = [+ `:::artifact{identifier="e2e-overlay-roles" type="text/html" title="${ARTIFACT_TITLE}"}`,+ '<main><h1>Overlay roles</h1></main>',+ ':::',+].join('\n');++/** No bundled palette holds these triples, so only the definition can produce them. */+const REFERENCE_COLORS = {+ 'rgb-surface-primary': '12 34 56',+ 'rgb-text-primary': '201 202 203',+ 'rgb-surface-overlay': '40 50 60',+ 'rgb-surface-media-overlay': '10 20 30',+};+const REFERENCE_THEME = {+ version: 1,+ name: 'e2e-theme-sweep-roles',+ modes: { light: { colors: REFERENCE_COLORS }, dark: { colors: REFERENCE_COLORS } },+} as const;++type Paint = { background: string; color: string; roles: Record<string, string> };++/** Same bridge as `dialog-scrim-role`: the mode rides in the URL, the definition in storage. */+async function installThemeBridge(page: Page, definition?: unknown) {+ await page.addInitScript((stored) => {+ const mode = new URL(location.href).searchParams.get('e2eThemeMode');+ if (mode) {+ localStorage.setItem('color-theme', mode);+ }+ localStorage.removeItem('theme-colors');+ localStorage.removeItem('theme-name');+ if (stored) {+ localStorage.setItem('theme-definition', JSON.stringify(stored));+ localStorage.setItem('theme-source', 'definition');+ } else {+ localStorage.removeItem('theme-definition');+ localStorage.removeItem('theme-source');+ }+ }, definition ?? null);+}++/** The project's own scheme, so each project checks the palette it renders. */+const projectMode = (): 'light' | 'dark' =>+ test.info().project.use.colorScheme === 'dark' ? 'dark' : 'light';++/**+ * The element's paint and each role triple as the element sees it, all rounded+ * through a canvas: Tailwind 4 serializes alpha utilities as `oklab()`, and the+ * canvas gives back the sRGB channels either spelling describes.+ */+async function readPaint(target: Locator, roles: string[]): Promise<Paint> {+ return target.evaluate((element, names) => {+ const brush = document.createElement('canvas').getContext('2d', { willReadFrequently: true });+ if (!brush) {+ throw new Error('the color-normalizing canvas has no 2d context');+ }+ const normalize = (css: string) => {+ brush.clearRect(0, 0, 1, 1);+ brush.fillStyle = css;+ brush.fillRect(0, 0, 1, 1);+ const [r, g, b, a] = brush.getImageData(0, 0, 1, 1).data;+ const alpha = Math.round((a / 255) * 100) / 100;+ return alpha === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${alpha})`;+ };+ const style = getComputedStyle(element);+ const resolved: Record<string, string> = {};+ for (const name of names) {+ resolved[name] = normalize(`rgb(${style.getPropertyValue(`--${name}`).trim()})`);+ }+ return {+ background: normalize(style.backgroundColor),+ color: normalize(style.color),+ roles: resolved,+ };+ }, roles);+}++const withAlpha = (rgb: string, alpha: number) =>+ rgb.replace('rgb(', 'rgba(').replace(')', `, ${alpha})`);++async function showProviderChip(page: Page, mode: string): Promise<Locator> {+ await page.goto(`${NEW_CHAT_PATH}?${THEME_PARAM}=${mode}`, { timeout: 15000 });+ await openAgentBuilder(page, { navigate: false });+ await selectMockModel(page, true);+ const chip = page.locator('#provider').locator('div.rounded-full').first();+ await expect(chip).toBeVisible();+ return chip;+}++async function openArtifact(page: Page, conversationId: string, mode: string) {+ await page.goto(`/c/${conversationId}?${THEME_PARAM}=${mode}`, { timeout: 15000 });+ await messagesView(page).locator('[data-artifact-trigger]').first().click();+ const panel = page.locator('#artifact-viewer');+ await expect(panel).toBeVisible({ timeout: 15000 });+ /** Always mounted, transparent and `aria-hidden` until a refresh runs. */+ const veil = panel.locator('div.absolute.inset-0[role="status"]');+ await expect(veil).toHaveCount(1);+ /** Phone only: the backdrop is the panel's preceding sibling. */+ const backdrop = page.locator('#artifact-viewer').locator('xpath=preceding-sibling::div[1]');+ return { veil, backdrop };+}++test.describe('theme sweep roles', () => {+ test('the agent provider chip paints surface and text primary @scenario:agent-provider-chip-role', async ({+ page,+ }) => {+ test.setTimeout(120000);+ const mode = projectMode();+ await installThemeBridge(page);++ const bundled = await readPaint(await showProviderChip(page, mode), [+ 'surface-primary',+ 'text-primary',+ ]);+ expect(bundled.background).toBe(bundled.roles['surface-primary']);+ expect(bundled.color).toBe(bundled.roles['text-primary']);++ /** Registered later, so it runs after the first bridge and wins. */+ await installThemeBridge(page, REFERENCE_THEME);+ const chip = await showProviderChip(page, mode);+ await expect(page.locator('html')).toHaveAttribute('data-theme', REFERENCE_THEME.name);+ const themed = await readPaint(chip, []);+ expect(themed.background).toBe('rgb(12, 34, 56)');+ expect(themed.color).toBe('rgb(201, 202, 203)');+ });++ test('the artifact refresh veil and phone backdrop paint overlay roles @scenario:artifact-overlay-roles', async ({+ page,+ }, testInfo) => {+ test.setTimeout(120000);+ const mode = projectMode();+ const isMobile = testInfo.project.use.isMobile === true;+ const conversationId = randomUUID();+ const email = getE2EUser().email;+ await seedConversations(email, [+ { conversationId, title: ARTIFACT_TITLE, updatedAt: new Date() },+ ]);+ await seedMessages(email, conversationId, [+ {+ messageId: randomUUID(),+ parentMessageId: ROOT_PARENT,+ text: ARTIFACT_TEXT,+ isCreatedByUser: false,+ sender: 'Assistant',+ model: 'mock-model-a',+ },+ ]);++ try {+ await installThemeBridge(page);+ let { veil, backdrop } = await openArtifact(page, conversationId, mode);+ const roles = ['surface-media-overlay', 'surface-overlay'];+ const bundledVeil = await readPaint(veil, roles);+ expect(bundledVeil.background).toBe(+ withAlpha(bundledVeil.roles['surface-media-overlay'], 0.7),+ );+ expect(bundledVeil.background).toBe('rgba(0, 0, 0, 0.7)');+ if (isMobile) {+ const bundledBackdrop = await readPaint(backdrop, roles);+ expect(bundledBackdrop.background).toBe(bundledBackdrop.roles['surface-overlay']);+ }++ await installThemeBridge(page, REFERENCE_THEME);+ ({ veil, backdrop } = await openArtifact(page, conversationId, mode));+ await expect(page.locator('html')).toHaveAttribute('data-theme', REFERENCE_THEME.name);+ expect((await readPaint(veil, [])).background).toBe('rgba(10, 20, 30, 0.7)');+ if (isMobile) {+ /** Its class carries no alpha; the fade is the inline `opacity`. */+ expect((await readPaint(backdrop, [])).background).toBe('rgb(40, 50, 60)');+ } else {+ /** The desktop rail mounts no backdrop at all. */+ await expect(page.locator('* + #artifact-viewer')).toHaveCount(0);+ }+ } finally {+ await deleteMessagesByConversation([conversationId]);+ await deleteConversations([conversationId]);+ }+ });+});diff --git a/packages/client/src/theme/allowlist.md b/packages/client/src/theme/allowlist.mdindex 28b253e016..1405b0267b 100644--- a/packages/client/src/theme/allowlist.md+++ b/packages/client/src/theme/allowlist.md@@ -2,8 +2,6 @@Every colour in `client/src` and `packages/client/src` comes from a semantic theme role, except the entries below. Each entry is one kind of colour that must not follow the theme, with the files that hold it and why the theme does not own it. Scrims, chips and progress drawn over the user's own media are not exceptions: they read `surface-media-overlay` and `text-on-media`, which every bundled theme keeps black and white. The drop zone's artwork reads the `illustration` roles, file-type tiles the `file-*` roles, the default avatar's hairline `avatar-edge`, and a dragged badge's lift `elevationDrag`.-Files an open pull request was editing when this list was last swept, with their counts, are listed in berry-13/LibreChat#195. Until those land, a file absent from this list is not evidence that it holds no literal colour.-A literal the design lint can see stays recorded in `eslint-suppressions.json` (inline disablesof the design rules are rejected by the static checks), so its count there is the exception, notdebt; the file-scoped allow entry for these paths belongs in `eslint.config.mjs`. Everything else@@ -13,14 +11,14 @@ Adding an entry needs the same bar: if a theme author would reasonably want to ris a role, not an exception. Keep the list to ten entries or fewer; a new kind of exception thatdoes not fit an entry below is a sign it should be a role.-| # | Entry | Files | Why |-| --- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| 1 | Theme definitions | `packages/client/src/theme/themes/*.ts`, `themes/clickui.json`, `packages/client/src/theme/registry.ts`, `packages/client/src/theme/defaults.css`, `packages/client/src/theme/tokens.css` | The palettes and appearance values themselves: these are the values roles resolve to. |-| 2 | Third-party brand marks | `packages/client/src/svgs/GoogleIcon.tsx`, `FacebookIcon.tsx`, `DiscordIcon.tsx`, `GeminiIcon.tsx`, `PaLMIcon.tsx`; `client/src/mobile.css` (`.azure-bg-color`); `client/src/components/Chat/Input/Files/SourceIcon.tsx` (the OpenAI chip) | Fixed by each company's brand guidelines: the Google, Facebook, Discord, Gemini and PaLM marks, the Azure file-source chip's blue gradient, and the OpenAI file-source chip (white/75, black/65 in dark) behind OpenAI's mark. |-| 3 | Provider brand colours | `packages/client/src/icons/provider/registry.ts`, `icons/provider/Avatar.tsx` | Each provider colour is already behind a `--provider-*` variable a deployment can override; the literal is only its fallback. |-| 4 | Opt-in decorative palettes | `packages/client/src/svgs/BirthdayIcon.tsx`, `packages/client/src/components/PixelCard.tsx` | A multicolour illustration, and the `blue`, `yellow` and `pink` PixelCard presets a caller opts into like its `colors` prop. The app renders only PixelCard's default, which reads theme roles. |-| 5 | Documents that leave the app | `client/src/utils/markdown.ts`, `client/src/utils/richtext.ts` | The downloaded HTML document's GitHub Primer stylesheet, and inline styles on HTML copied to the clipboard; both are read outside the app, where no theme variables exist and the sender's theme must not travel. The markdown high-contrast branch reads the roles. |-| 6 | Sandboxed iframe documents | `client/src/utils/mermaid.ts`, `client/src/utils/artifacts.ts` | The mermaid document and its zoom controls, and the artifact document's scrollbar thumb, render in their own iframe without theme variables; the token reads' fallbacks and the luminance repair ink are literals by necessity. |-| 7 | Third-party surface | `client/src/hooks/Files/useSharePointPicker.ts` | Background of Microsoft's SharePoint file picker iframe, matched to that third party's own surface. |-| 8 | Library stylesheet elevation | `packages/client/src/components/Dropdown.css`, `packages/client/src/components/Tooltip.css` | Popover and tooltip shadows in black alpha. The app paints `.popover-ui` from its own copy of the Dropdown rules in `client/src/style.css`, so both copies move to `--theme-shadow-lg` together; the tooltip shadow is smaller than any shadow step. |-| 9 | Fallbacks for a role read at runtime | `client/src/utils/officePreview.ts`, `client/src/hooks/ScreenshotContext.tsx` | Used only when the role's variable is unset; the value painted otherwise is the role, read with `readThemeColor` or from the bundled palette. |+| # | Entry | Files | Why |+| --- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| 1 | Theme definitions | `packages/client/src/theme/themes/*.ts`, `themes/clickui.json`, `packages/client/src/theme/registry.ts`, `packages/client/src/theme/defaults.css`, `packages/client/src/theme/tokens.css` | The palettes and appearance values themselves: these are the values roles resolve to. |+| 2 | Third-party brand marks | `packages/client/src/svgs/GoogleIcon.tsx`, `FacebookIcon.tsx`, `DiscordIcon.tsx`, `GeminiIcon.tsx`, `PaLMIcon.tsx`; `client/src/mobile.css` (`.azure-bg-color`); `client/src/components/Chat/Input/Files/SourceIcon.tsx` (the OpenAI chip) | Fixed by each company's brand guidelines: the Google, Facebook, Discord, Gemini and PaLM marks, the Azure file-source chip's blue gradient, and the OpenAI file-source chip (white/75, black/65 in dark) behind OpenAI's mark. |+| 3 | Provider brand colours | `packages/client/src/icons/provider/registry.ts`, `icons/provider/Avatar.tsx` | Each provider colour is already behind a `--provider-*` variable a deployment can override; the literal is only its fallback. |+| 4 | Opt-in decorative palettes | `packages/client/src/svgs/BirthdayIcon.tsx`, `packages/client/src/components/PixelCard.tsx` | A multicolour illustration, and the `blue`, `yellow` and `pink` PixelCard presets a caller opts into like its `colors` prop. The app renders only PixelCard's default, which reads theme roles. |+| 5 | Documents that leave the app | `client/src/utils/markdown.ts`, `client/src/utils/richtext.ts` | The downloaded HTML document's GitHub Primer stylesheet, and inline styles on HTML copied to the clipboard; both are read outside the app, where no theme variables exist and the sender's theme must not travel. The markdown high-contrast branch reads the roles. |+| 6 | Sandboxed iframe documents | `client/src/utils/mermaid.ts`, `client/src/utils/artifacts.ts` | The mermaid document and its zoom controls, and the artifact document's scrollbar thumb, render in their own iframe without theme variables; the token reads' fallbacks and the luminance repair ink are literals by necessity. |+| 7 | Third-party surfaces | `client/src/hooks/Files/useSharePointPicker.ts`, `client/src/components/Artifacts/ArtifactCodeEditor.tsx` | Background of Microsoft's SharePoint file picker iframe, matched to that third party's own surface, and the canvas of Monaco's built-in `vs-dark` editor theme, painted behind the editor while it loads so the Code tab does not flash; Monaco owns that colour, and the high-contrast editor themes already read the roles. |+| 8 | Library stylesheet elevation | `packages/client/src/components/Dropdown.css`, `packages/client/src/components/Tooltip.css` | Popover and tooltip shadows in black alpha. The app paints `.popover-ui` from its own copy of the Dropdown rules in `client/src/style.css`, so both copies move to `--theme-shadow-lg` together; the tooltip shadow is smaller than any shadow step. |+| 9 | Fallbacks for a role read at runtime | `client/src/utils/officePreview.ts`, `client/src/hooks/ScreenshotContext.tsx` | Used only when the role's variable is unset; the value painted otherwise is the role, read with `readThemeColor` or from the bundled palette. |