mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 13:33:45 +00:00
🖼️ fix: Resolve Pinned Model Icons from Endpoint Config (#16089)
* 🖼️ fix: Resolve Pinned Model Icons from Endpoint Config - pass `endpointsConfig` and `model` to `MinimalIcon` from the pinned favorites row so a custom endpoint's `iconURL` is honored Fixes #16088 * test: Cover Pinned Model Endpoint Config Propagation --------- Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
0cc52cd8c7
commit
99707d64c6
4 changed files with 99 additions and 18 deletions
|
|
@ -279,6 +279,7 @@ const FavoriteRow = ({
|
|||
item={{ model: favorite.model, endpoint: favorite.endpoint }}
|
||||
type="model"
|
||||
onSelectEndpoint={onSelectEndpoint}
|
||||
endpointsConfig={endpointsConfig}
|
||||
onRemoveFocus={onRemoveFocus}
|
||||
keyShortcuts={keyShortcuts}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ import { render, screen, fireEvent, act } from '@testing-library/react';
|
|||
import '@testing-library/jest-dom';
|
||||
import { DndProvider } from 'react-dnd';
|
||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import type { TConversation, TEndpointsConfig } from 'librechat-data-provider';
|
||||
import FavoriteItem from '~/components/Nav/Favorites/FavoriteItem';
|
||||
import PinnedSection from '../PinnedSection';
|
||||
|
||||
const mockSetExpanded = jest.fn();
|
||||
|
|
@ -106,22 +107,24 @@ jest.mock('../Convo', () => {
|
|||
|
||||
jest.mock('~/components/Nav/Favorites/FavoriteItem', () => ({
|
||||
__esModule: true,
|
||||
default: ({
|
||||
item,
|
||||
type,
|
||||
keyShortcuts,
|
||||
}: {
|
||||
item: { model?: string; id?: string; label?: string };
|
||||
type: string;
|
||||
keyShortcuts?: string;
|
||||
}) => {
|
||||
const label = item.id ?? item.label ?? item.model ?? '';
|
||||
return (
|
||||
<div data-testid="favorite-item" data-type={type} aria-keyshortcuts={keyShortcuts}>
|
||||
{label}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
default: jest.fn(
|
||||
({
|
||||
item,
|
||||
type,
|
||||
keyShortcuts,
|
||||
}: {
|
||||
item: { model?: string; id?: string; label?: string };
|
||||
type: string;
|
||||
keyShortcuts?: string;
|
||||
}) => {
|
||||
const label = item.id ?? item.label ?? item.model ?? '';
|
||||
return (
|
||||
<div data-testid="favorite-item" data-type={type} aria-keyshortcuts={keyShortcuts}>
|
||||
{label}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
),
|
||||
}));
|
||||
|
||||
const pinnedConvo = (id: string, title: string) =>
|
||||
|
|
@ -159,6 +162,7 @@ describe('PinnedSection unified list', () => {
|
|||
mockFavoritesData.isAgentsLoading = false;
|
||||
mockFavoritesData.agentsMap = {};
|
||||
mockFavoritesData.specsMap = {};
|
||||
mockFavoritesData.endpointsConfig = {};
|
||||
});
|
||||
|
||||
it('renders nothing when there are no favorites or pinned conversations', () => {
|
||||
|
|
@ -172,6 +176,28 @@ describe('PinnedSection unified list', () => {
|
|||
expect(itemLabels()).toEqual(['gpt-4o', 'Pinned Chat', 'Another Pin']);
|
||||
});
|
||||
|
||||
it('forwards endpoint config to pinned models when the config loads', () => {
|
||||
const item = { model: 'claude-sonnet-4-5', endpoint: 'AnthropicClaude' };
|
||||
mockFavoritesData.favorites = [item];
|
||||
const { rerender } = renderSection([]);
|
||||
|
||||
expect(FavoriteItem).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ type: 'model', item, endpointsConfig: {} }),
|
||||
expect.anything(),
|
||||
);
|
||||
|
||||
const endpointsConfig: TEndpointsConfig = {
|
||||
AnthropicClaude: { iconURL: 'anthropic', order: 0 },
|
||||
};
|
||||
mockFavoritesData.endpointsConfig = endpointsConfig;
|
||||
rerender(renderTree([]));
|
||||
|
||||
expect(FavoriteItem).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ type: 'model', item, endpointsConfig }),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
/* Chats and favorites are two independently ordered groups: an order saved
|
||||
* before that rule, with the two interleaved, is read back grouped. */
|
||||
it('orders each kind by the stored order and keeps the kinds grouped', () => {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ type ModelFavoriteProps = FavoriteItemBaseProps & {
|
|||
type: 'model';
|
||||
item: FavoriteModel;
|
||||
onSelectEndpoint?: (endpoint?: EModelEndpoint | string | null, kwargs?: Kwargs) => void;
|
||||
endpointsConfig?: TEndpointsConfig;
|
||||
};
|
||||
|
||||
type SpecFavoriteProps = FavoriteItemBaseProps & {
|
||||
|
|
@ -105,7 +106,13 @@ export default function FavoriteItem(props: FavoriteItemProps) {
|
|||
}
|
||||
return (
|
||||
<div className="mr-2 h-5 w-5">
|
||||
<MinimalIcon endpoint={props.item.endpoint} size={20} isCreatedByUser={false} />
|
||||
<MinimalIcon
|
||||
endpoint={props.item.endpoint}
|
||||
endpointsConfig={props.endpointsConfig}
|
||||
model={props.item.model}
|
||||
size={20}
|
||||
isCreatedByUser={false}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import type { TEndpointsConfig } from 'librechat-data-provider';
|
||||
import type { FavoriteModel } from '~/store/favorites';
|
||||
import FavoriteItem from '../FavoriteItem';
|
||||
|
||||
/** Renders the real MinimalIcon so the provider resolution is exercised, unlike
|
||||
* FavoriteItem.spec.tsx which stubs it to assert layout. */
|
||||
jest.mock('~/hooks', () => ({
|
||||
useLocalize: () => (key: string) => key,
|
||||
useFavorites: () => ({
|
||||
removeFavoriteAgent: jest.fn(),
|
||||
removeFavoriteModel: jest.fn(),
|
||||
removeFavoriteSpec: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
const endpointsConfig: TEndpointsConfig = {
|
||||
AnthropicClaude: { iconURL: 'anthropic', order: 0 },
|
||||
MetaLlama: { iconURL: '/assets/meta-llama.png', order: 1 },
|
||||
};
|
||||
|
||||
const claudeModel: FavoriteModel = {
|
||||
model: 'claude-sonnet-4-5',
|
||||
endpoint: 'AnthropicClaude',
|
||||
};
|
||||
|
||||
const llamaModel: FavoriteModel = {
|
||||
model: 'llama3-3-70b-instruct',
|
||||
endpoint: 'MetaLlama',
|
||||
};
|
||||
|
||||
describe('FavoriteItem type="model" provider art', () => {
|
||||
it('renders the art named by the endpoint iconURL', () => {
|
||||
render(<FavoriteItem type="model" item={claudeModel} endpointsConfig={endpointsConfig} />);
|
||||
expect(screen.getByRole('img', { name: 'Anthropic', hidden: true })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders an image iconURL as the art', () => {
|
||||
render(<FavoriteItem type="model" item={llamaModel} endpointsConfig={endpointsConfig} />);
|
||||
expect(screen.getByAltText('MetaLlama Icon')).toHaveAttribute('src', '/assets/meta-llama.png');
|
||||
});
|
||||
|
||||
it('falls back to the custom art when the endpoint resolves to no provider', () => {
|
||||
render(<FavoriteItem type="model" item={claudeModel} />);
|
||||
expect(screen.getByRole('img', { name: 'Custom', hidden: true })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue