mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
🃏 refactor: Agent Avatar Conversation Icons and Streaming Indicators (#13563)
This commit is contained in:
parent
98822341ed
commit
727dd3bea4
10 changed files with 472 additions and 249 deletions
|
|
@ -1,66 +1,82 @@
|
|||
import { getEndpointField, isAssistantsEndpoint } from 'librechat-data-provider';
|
||||
import { getEndpointField, isAssistantsEndpoint, isAgentsEndpoint } from 'librechat-data-provider';
|
||||
import type {
|
||||
TPreset,
|
||||
TConversation,
|
||||
TAgentsMap,
|
||||
TAssistantsMap,
|
||||
TEndpointsConfig,
|
||||
} from 'librechat-data-provider';
|
||||
import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
|
||||
import MinimalIcon from '~/components/Endpoints/MinimalIcon';
|
||||
import { getIconEndpoint } from '~/utils';
|
||||
import { getAgentAvatarUrl, getIconEndpoint } from '~/utils';
|
||||
import { isImageURL } from '~/utils/icons';
|
||||
|
||||
const emptyEndpointsConfig = {} as TEndpointsConfig;
|
||||
|
||||
export default function EndpointIcon({
|
||||
conversation,
|
||||
endpointsConfig,
|
||||
endpointsConfig = emptyEndpointsConfig,
|
||||
className = 'mr-0',
|
||||
assistantMap,
|
||||
agentsMap,
|
||||
context,
|
||||
size = 20,
|
||||
}: {
|
||||
conversation: TConversation | TPreset | null;
|
||||
endpointsConfig: TEndpointsConfig;
|
||||
containerClassName?: string;
|
||||
context?: 'message' | 'nav' | 'landing' | 'menu-item';
|
||||
assistantMap?: TAssistantsMap;
|
||||
agentsMap?: TAgentsMap;
|
||||
className?: string;
|
||||
size?: number;
|
||||
}) {
|
||||
const convoIconURL = conversation?.iconURL ?? '';
|
||||
let endpoint = conversation?.endpoint;
|
||||
const originalEndpoint = conversation?.endpoint;
|
||||
let endpoint = originalEndpoint;
|
||||
endpoint = getIconEndpoint({ endpointsConfig, iconURL: convoIconURL, endpoint });
|
||||
|
||||
const endpointType = getEndpointField(endpointsConfig, endpoint, 'type');
|
||||
const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
|
||||
|
||||
const agent = isAgentsEndpoint(endpoint) ? agentsMap?.[conversation?.agent_id ?? ''] : null;
|
||||
const assistant = isAssistantsEndpoint(endpoint)
|
||||
? assistantMap?.[endpoint]?.[conversation?.assistant_id ?? '']
|
||||
: null;
|
||||
const agentAvatar = getAgentAvatarUrl(agent) ?? '';
|
||||
const agentName = agent?.name ?? '';
|
||||
const assistantAvatar = (assistant && (assistant.metadata?.avatar as string)) || '';
|
||||
const assistantName = assistant && (assistant.name ?? '');
|
||||
const entityAvatar = agentAvatar || assistantAvatar;
|
||||
const entityName = agentName || assistantName || '';
|
||||
const hasCustomIcon =
|
||||
isImageURL(convoIconURL) || (convoIconURL !== '' && convoIconURL !== originalEndpoint);
|
||||
|
||||
const iconURL = assistantAvatar || convoIconURL;
|
||||
const iconURL = hasCustomIcon ? convoIconURL : entityAvatar || convoIconURL;
|
||||
|
||||
if (isImageURL(iconURL)) {
|
||||
return (
|
||||
<ConvoIconURL
|
||||
iconURL={iconURL}
|
||||
modelLabel={conversation?.chatGptLabel ?? conversation?.modelLabel ?? ''}
|
||||
modelLabel={entityName || conversation?.chatGptLabel || conversation?.modelLabel || ''}
|
||||
context={context}
|
||||
endpointIconURL={endpointIconURL}
|
||||
assistantAvatar={assistantAvatar}
|
||||
assistantName={assistantName ?? ''}
|
||||
agentAvatar={agentAvatar}
|
||||
agentName={agentName}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<MinimalIcon
|
||||
size={20}
|
||||
iconURL={endpointIconURL}
|
||||
endpoint={endpoint}
|
||||
endpointType={endpointType}
|
||||
model={conversation?.model}
|
||||
error={false}
|
||||
className={className}
|
||||
size={size}
|
||||
isCreatedByUser={false}
|
||||
chatGptLabel={undefined}
|
||||
modelLabel={undefined}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
import React from 'react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { EModelEndpoint } from 'librechat-data-provider';
|
||||
import type { Agent, TConversation, TEndpointsConfig } from 'librechat-data-provider';
|
||||
import EndpointIcon from '../EndpointIcon';
|
||||
|
||||
jest.mock('~/components/Endpoints/ConvoIconURL', () => ({
|
||||
__esModule: true,
|
||||
default: ({
|
||||
iconURL,
|
||||
modelLabel,
|
||||
agentAvatar,
|
||||
agentName,
|
||||
}: {
|
||||
iconURL: string;
|
||||
modelLabel?: string;
|
||||
agentAvatar?: string;
|
||||
agentName?: string;
|
||||
}) => (
|
||||
<img
|
||||
src={iconURL}
|
||||
alt={modelLabel || 'Icon'}
|
||||
data-testid="convo-url-icon"
|
||||
data-agent-avatar={agentAvatar}
|
||||
data-agent-name={agentName}
|
||||
/>
|
||||
),
|
||||
}));
|
||||
|
||||
jest.mock('~/components/Endpoints/MinimalIcon', () => ({
|
||||
__esModule: true,
|
||||
default: ({ endpoint, iconURL }: { endpoint?: string | null; iconURL?: string }) => (
|
||||
<div data-testid="minimal-icon" data-endpoint={endpoint ?? ''} data-icon-url={iconURL ?? ''} />
|
||||
),
|
||||
}));
|
||||
|
||||
const endpointsConfig = {
|
||||
[EModelEndpoint.agents]: {},
|
||||
[EModelEndpoint.google]: {},
|
||||
} as TEndpointsConfig;
|
||||
|
||||
const agent = {
|
||||
id: 'agent_123',
|
||||
name: 'Research Agent',
|
||||
avatar: {
|
||||
filepath: '/images/agents/agent_123/avatar.png',
|
||||
source: 'local',
|
||||
},
|
||||
} as Agent;
|
||||
|
||||
describe('EndpointIcon', () => {
|
||||
it('uses the agent avatar when the agents endpoint would otherwise render its default icon', () => {
|
||||
const conversation = {
|
||||
endpoint: EModelEndpoint.agents,
|
||||
agent_id: agent.id,
|
||||
iconURL: EModelEndpoint.agents,
|
||||
} as TConversation;
|
||||
|
||||
render(
|
||||
<EndpointIcon
|
||||
conversation={conversation}
|
||||
endpointsConfig={endpointsConfig}
|
||||
agentsMap={{ [agent.id]: agent }}
|
||||
/>,
|
||||
);
|
||||
|
||||
const icon = screen.getByTestId('convo-url-icon');
|
||||
expect(icon).toHaveAttribute('src', '/images/agents/agent_123/avatar.png');
|
||||
expect(icon).toHaveAttribute('alt', 'Research Agent');
|
||||
});
|
||||
|
||||
it('keeps an explicit model spec icon ahead of the agent avatar', () => {
|
||||
const conversation = {
|
||||
endpoint: EModelEndpoint.agents,
|
||||
agent_id: agent.id,
|
||||
spec: 'research-spec',
|
||||
iconURL: EModelEndpoint.google,
|
||||
} as TConversation;
|
||||
|
||||
render(
|
||||
<EndpointIcon
|
||||
conversation={conversation}
|
||||
endpointsConfig={endpointsConfig}
|
||||
agentsMap={{ [agent.id]: agent }}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('convo-url-icon')).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('minimal-icon')).toHaveAttribute(
|
||||
'data-endpoint',
|
||||
EModelEndpoint.google,
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue