From 84a36630a0573248619ad70ddafa2e6e01ffecaa Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Thu, 5 Nov 2026 22:36:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8A=20refactor:=20Move=20the=20Context?= =?UTF-8?q?=20Usage=20Popover=20Into=20@librechat/chat=20(#17799)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Move the Context Usage Popover Pieces Into @librechat/chat * test: Cover the Context Usage Pieces in the Chat Package * fix: Ship the Collapsible Animations With the Shared Tailwind Preset * test: Keep the Expanded Breakdown Choice Across Remounts * test: Assert the Absent Compaction Hint by Its Fixed Copy * refactor: Give Collapsible and HoverCard the Breakdown Disclosure Styles * test: Cover the Breakdown Roll and Remembered Choice in the Browser * chore: Retest Against Current Dev --- .../Chat/Input/TokenUsage/index.spec.tsx | 42 +++- .../Chat/Input/TokenUsage/index.tsx | 15 +- .../Input/__tests__/appearanceTokens.spec.ts | 2 +- client/src/utils/tokens.spec.ts | 60 ----- client/src/utils/tokens.ts | 100 +------- client/tailwind.config.cjs | 14 -- .../scenarios/persisted-context-usage.spec.ts | 88 +++++++ eslint-suppressions.json | 5 - packages/chat/src/components.ts | 10 + .../components/composer/usage}/Breakdown.tsx | 43 ++-- .../composer/usage}/CompactAction.tsx | 16 +- .../src/components/composer/usage}/Gauge.tsx | 17 +- .../components/composer/usage}/Popover.tsx | 10 +- .../src/components/composer/usage}/Usage.tsx | 18 +- .../usage/__tests__}/Breakdown.spec.tsx | 214 +++++++++--------- .../composer/usage/__tests__}/Usage.spec.tsx | 41 ++-- .../src/core/usage/__tests__/format.spec.ts | 61 ++++- packages/chat/src/core/usage/format.ts | 106 +++++++++ .../src/components/Collapsible.spec.tsx | 47 ++++ .../client/src/components/Collapsible.tsx | 34 ++- .../client/src/components/HoverCard.spec.tsx | 16 ++ packages/client/src/components/HoverCard.tsx | 2 +- packages/client/tailwind.preset.cjs | 15 ++ 23 files changed, 609 insertions(+), 367 deletions(-) delete mode 100644 client/src/utils/tokens.spec.ts rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage}/Breakdown.tsx (94%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage}/CompactAction.tsx (80%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage}/Gauge.tsx (84%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage}/Popover.tsx (96%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage}/Usage.tsx (91%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage/__tests__}/Breakdown.spec.tsx (81%) rename {client/src/components/Chat/Input/TokenUsage => packages/chat/src/components/composer/usage/__tests__}/Usage.spec.tsx (76%) create mode 100644 packages/client/src/components/Collapsible.spec.tsx diff --git a/client/src/components/Chat/Input/TokenUsage/index.spec.tsx b/client/src/components/Chat/Input/TokenUsage/index.spec.tsx index a776599ad4..061a83a59a 100644 --- a/client/src/components/Chat/Input/TokenUsage/index.spec.tsx +++ b/client/src/components/Chat/Input/TokenUsage/index.spec.tsx @@ -36,9 +36,22 @@ jest.mock('~/hooks/Chat/useCompactConversation', () => ({ supportsCompaction: () => false, })); -jest.mock('./Breakdown', () => ({ - __esModule: true, - default: () =>
, +jest.mock('@librechat/chat/components', () => ({ + ...jest.requireActual('@librechat/chat/components'), + ContextBreakdown: ({ + expanded, + onExpandedChange, + }: { + expanded: boolean; + onExpandedChange: (expanded: boolean) => void; + }) => ( + + + Details + , + ); + + expect(screen.getByText('Details')).toHaveClass( + 'motion-reduce:data-[state=open]:animate-none', + 'motion-reduce:data-[state=closed]:animate-none', + ); + }); }); diff --git a/packages/client/src/components/HoverCard.tsx b/packages/client/src/components/HoverCard.tsx index 191c9e3ec7..d5796e89e6 100644 --- a/packages/client/src/components/HoverCard.tsx +++ b/packages/client/src/components/HoverCard.tsx @@ -36,7 +36,7 @@ const HoverCardContent: React.ForwardRefExoticComponent< sideOffset={sideOffset} style={{ ...nestedStyle, ...style }} className={cn( - 'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-theme-menu-panel z-50 w-64 max-w-[min(calc(100vw-1rem),var(--radix-hover-card-content-available-width))] origin-(--radix-hover-card-content-transform-origin) border p-4 shadow-md outline-hidden', + 'border-border-light bg-surface-secondary text-text-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 rounded-theme-menu-panel z-50 w-64 max-w-[min(calc(100vw-1rem),var(--radix-hover-card-content-available-width))] origin-(--radix-hover-card-content-transform-origin) border p-4 shadow-md outline-hidden motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=open]:animate-none', className, )} {...props} diff --git a/packages/client/tailwind.preset.cjs b/packages/client/tailwind.preset.cjs index 8ec492cf54..4c6e7b1e67 100644 --- a/packages/client/tailwind.preset.cjs +++ b/packages/client/tailwind.preset.cjs @@ -139,12 +139,27 @@ module.exports = { '0%,70%,100%': { opacity: '1' }, '20%,50%': { opacity: '0' }, }, + /** Radix Collapsible exposes its own height variable, not the accordion one. Lives in + * the preset because chat components that ship from @librechat/chat animate with it. + * The fade rides along so the rows dissolve instead of squashing. Opening + * decelerates into place; closing accelerates away, because a decelerating + * close stalls over its final pixels before the unmount. */ + 'collapsible-down': { + from: { height: 0, opacity: 0 }, + to: { height: 'var(--radix-collapsible-content-height)', opacity: 1 }, + }, + 'collapsible-up': { + from: { height: 'var(--radix-collapsible-content-height)', opacity: 1 }, + to: { height: 0, opacity: 0 }, + }, }, animation: { 'loading-dot': 'loading-dot 1.2s ease-in-out var(--loading-dot-delay, 0ms) infinite', 'accordion-down': 'accordion-down 0.2s ease-out', 'accordion-up': 'accordion-up 0.2s ease-out', 'caret-blink': 'caret-blink 1.25s ease-out infinite', + 'collapsible-down': 'collapsible-down 0.3s cubic-bezier(0, 0, 0.2, 1)', + 'collapsible-up': 'collapsible-up 0.2s cubic-bezier(0.4, 0, 1, 1)', }, /** * `rounded-sm` through `rounded-3xl` are not restated here: `@librechat/client/theme.css`