mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
* 🔧 chore: Add missing optional `scraperTimeout` to webSearchSchema
* chore: Add missing optional `scraperTimeout` to web search authentication result
* chore: linting
* feat: Integrate attachment handling and citation processing in message components
- Added `useAttachments` hook to manage message attachments and search results.
- Updated `MessageParts`, `ContentParts`, and `ContentRender` components to utilize the new hook for improved attachment handling.
- Enhanced `useCopyToClipboard` to format citations correctly, including support for composite citations and deduplication.
- Introduced utility functions for citation processing and cleanup.
- Added tests for the new `useCopyToClipboard` functionality to ensure proper citation formatting and handling.
* feat: Add configuration for LibreChat Code Interpreter API and Web Search variables
* fix: Update searchResults type to use SearchResultData for better type safety
* feat: Add web search configuration validation and logging
- Introduced `checkWebSearchConfig` function to validate web search configuration values, ensuring they are environment variable references.
- Added logging for proper configuration and warnings for incorrect values.
- Created unit tests for `checkWebSearchConfig` to cover various scenarios, including valid and invalid configurations.
* docs: Update README to include Web Search feature details
- Added a section for the Web Search feature, highlighting its capabilities to search the internet and enhance AI context.
- Included links for further information on the Web Search functionality.
* ci: Add mock for checkWebSearchConfig in AppService tests
* chore: linting
* feat: Enhance Shared Messages with Web Search UI by adding searchResults prop to SearchContent and MinimalHoverButtons components
* chore: linting
* refactor: remove Meilisearch index sync from importConversations function
* feat: update safeSearch implementation to use SafeSearchTypes enum
* refactor: remove commented-out code in loadTools function
* fix: ensure responseMessageId handles latestMessage ID correctly
* feat: enhance Vite configuration for improved chunking and caching
- Added additional globIgnores for map files in Workbox configuration.
- Implemented high-impact chunking for various large libraries to optimize performance.
- Increased chunkSizeWarningLimit from 1200 to 1500 for better handling of larger chunks.
* refactor: move health check hook to Root, fix bad setState for Temporary state
- Enhanced the `useHealthCheck` hook to initiate health checks only when the user is authenticated.
- Added logic for managing health check intervals and handling window focus events.
- Introduced a new test suite for `useHealthCheck` to cover various scenarios including authentication state changes and error handling.
- Removed the health check invocation from `ChatRoute` and added it to `Root` for global health monitoring.
* fix: update font alias in Vite configuration for correct path resolution
132 lines
3.9 KiB
TypeScript
132 lines
3.9 KiB
TypeScript
import { useRecoilValue } from 'recoil';
|
|
import { useCallback, useMemo } from 'react';
|
|
import { isAssistantsEndpoint, isAgentsEndpoint } from 'librechat-data-provider';
|
|
import type { SearchResultData } from 'librechat-data-provider';
|
|
import type { TMessageProps } from '~/common';
|
|
import {
|
|
useChatContext,
|
|
useAddedChatContext,
|
|
useAssistantsMapContext,
|
|
useAgentsMapContext,
|
|
} from '~/Providers';
|
|
import useCopyToClipboard from './useCopyToClipboard';
|
|
import { useAuthContext } from '~/hooks/AuthContext';
|
|
import useLocalize from '~/hooks/useLocalize';
|
|
import store from '~/store';
|
|
|
|
export type TMessageActions = Pick<
|
|
TMessageProps,
|
|
'message' | 'currentEditId' | 'setCurrentEditId'
|
|
> & {
|
|
isMultiMessage?: boolean;
|
|
searchResults?: { [key: string]: SearchResultData };
|
|
};
|
|
|
|
export default function useMessageActions(props: TMessageActions) {
|
|
const localize = useLocalize();
|
|
const { user } = useAuthContext();
|
|
const UsernameDisplay = useRecoilValue<boolean>(store.UsernameDisplay);
|
|
const { message, currentEditId, setCurrentEditId, isMultiMessage, searchResults } = props;
|
|
|
|
const {
|
|
ask,
|
|
index,
|
|
regenerate,
|
|
latestMessage,
|
|
handleContinue,
|
|
setLatestMessage,
|
|
conversation: rootConvo,
|
|
isSubmitting: isSubmittingRoot,
|
|
} = useChatContext();
|
|
const { conversation: addedConvo, isSubmitting: isSubmittingAdditional } = useAddedChatContext();
|
|
const conversation = useMemo(
|
|
() => (isMultiMessage === true ? addedConvo : rootConvo),
|
|
[isMultiMessage, addedConvo, rootConvo],
|
|
);
|
|
|
|
const agentsMap = useAgentsMapContext();
|
|
const assistantMap = useAssistantsMapContext();
|
|
|
|
const { text, content, messageId = null, isCreatedByUser } = message ?? {};
|
|
const edit = useMemo(() => messageId === currentEditId, [messageId, currentEditId]);
|
|
|
|
const enterEdit = useCallback(
|
|
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel === true ? -1 : messageId),
|
|
[messageId, setCurrentEditId],
|
|
);
|
|
|
|
const assistant = useMemo(() => {
|
|
if (!isAssistantsEndpoint(conversation?.endpoint)) {
|
|
return undefined;
|
|
}
|
|
|
|
const endpointKey = conversation?.endpoint ?? '';
|
|
const modelKey = message?.model ?? '';
|
|
|
|
return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined;
|
|
}, [conversation?.endpoint, message?.model, assistantMap]);
|
|
|
|
const agent = useMemo(() => {
|
|
if (!isAgentsEndpoint(conversation?.endpoint)) {
|
|
return undefined;
|
|
}
|
|
|
|
if (!agentsMap) {
|
|
return undefined;
|
|
}
|
|
|
|
const modelKey = message?.model ?? '';
|
|
if (modelKey) {
|
|
return agentsMap[modelKey];
|
|
}
|
|
|
|
const agentId = conversation?.agent_id ?? '';
|
|
if (agentId) {
|
|
return agentsMap[agentId];
|
|
}
|
|
}, [agentsMap, conversation?.agent_id, conversation?.endpoint, message?.model]);
|
|
|
|
const isSubmitting = useMemo(
|
|
() => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot),
|
|
[isMultiMessage, isSubmittingAdditional, isSubmittingRoot],
|
|
);
|
|
|
|
const regenerateMessage = useCallback(() => {
|
|
if ((isSubmitting && isCreatedByUser === true) || !message) {
|
|
return;
|
|
}
|
|
|
|
regenerate(message);
|
|
}, [isSubmitting, isCreatedByUser, message, regenerate]);
|
|
|
|
const copyToClipboard = useCopyToClipboard({ text, content, searchResults });
|
|
|
|
const messageLabel = useMemo(() => {
|
|
if (message?.isCreatedByUser === true) {
|
|
return UsernameDisplay ? (user?.name ?? '') || user?.username : localize('com_user_message');
|
|
} else if (agent) {
|
|
return agent.name ?? 'Assistant';
|
|
} else if (assistant) {
|
|
return assistant.name ?? 'Assistant';
|
|
} else {
|
|
return message?.sender;
|
|
}
|
|
}, [message, agent, assistant, UsernameDisplay, user, localize]);
|
|
|
|
return {
|
|
ask,
|
|
edit,
|
|
index,
|
|
agent,
|
|
assistant,
|
|
enterEdit,
|
|
conversation,
|
|
messageLabel,
|
|
isSubmitting,
|
|
latestMessage,
|
|
handleContinue,
|
|
copyToClipboard,
|
|
setLatestMessage,
|
|
regenerateMessage,
|
|
};
|
|
}
|