mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
* chore: typing * chore: typing * fix: enhance message scrolling logic to handle empty messages tree and ref checks * fix: optimize message selection logic with useCallback for better performance * chore: typing * refactor: optimize icon rendering * refactor: further optimize chat props * fix: remove unnecessary console log in useQueryParams cleanup * refactor: add queryClient to reset message data on new conversation initiation * refactor: update data-testid attributes for consistency and improve code readability * refactor: integrate queryClient to reset message data on new conversation initiation
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
import type * as t from 'librechat-data-provider';
|
|
import { getEndpointField, getIconKey, getEntity, getIconEndpoint } from '~/utils';
|
|
import { icons } from '~/components/Chat/Menus/Endpoints/Icons';
|
|
import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
|
|
|
|
export default function ConvoIcon({
|
|
conversation,
|
|
endpointsConfig,
|
|
assistantMap,
|
|
agentsMap,
|
|
className = '',
|
|
containerClassName = '',
|
|
context,
|
|
size,
|
|
}: {
|
|
conversation: t.TConversation | t.TPreset | null;
|
|
endpointsConfig: t.TEndpointsConfig;
|
|
assistantMap: t.TAssistantsMap | undefined;
|
|
agentsMap: t.TAgentsMap | undefined;
|
|
containerClassName?: string;
|
|
context?: 'message' | 'nav' | 'landing' | 'menu-item';
|
|
className?: string;
|
|
size?: number;
|
|
}) {
|
|
const iconURL = conversation?.iconURL ?? '';
|
|
let endpoint = conversation?.endpoint;
|
|
endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
|
|
|
|
const { entity, isAgent } = useMemo(
|
|
() =>
|
|
getEntity({
|
|
endpoint,
|
|
agentsMap,
|
|
assistantMap,
|
|
agent_id: conversation?.agent_id,
|
|
assistant_id: conversation?.assistant_id,
|
|
}),
|
|
[endpoint, conversation?.agent_id, conversation?.assistant_id, agentsMap, assistantMap],
|
|
);
|
|
|
|
const name = entity?.name ?? '';
|
|
const avatar = isAgent
|
|
? (entity as t.Agent | undefined)?.avatar?.filepath
|
|
: ((entity as t.Assistant | undefined)?.metadata?.avatar as string);
|
|
|
|
const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');
|
|
const iconKey = getIconKey({ endpoint, endpointsConfig, endpointIconURL });
|
|
const Icon = icons[iconKey] ?? null;
|
|
|
|
return (
|
|
<>
|
|
{iconURL && iconURL.includes('http') ? (
|
|
<ConvoIconURL
|
|
iconURL={iconURL}
|
|
modelLabel={conversation?.chatGptLabel ?? conversation?.modelLabel ?? ''}
|
|
endpointIconURL={endpointIconURL}
|
|
assistantAvatar={avatar}
|
|
assistantName={name}
|
|
agentAvatar={avatar}
|
|
agentName={name}
|
|
context={context}
|
|
/>
|
|
) : (
|
|
<div className={containerClassName}>
|
|
{endpoint && Icon != null && (
|
|
<Icon
|
|
size={size}
|
|
context={context}
|
|
endpoint={endpoint}
|
|
className={className}
|
|
iconURL={endpointIconURL}
|
|
assistantName={name}
|
|
agentName={name}
|
|
avatar={avatar}
|
|
/>
|
|
)}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|