mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-15 15:08:52 +01:00
🎯 refactor: Centralize Agent Model Handling Across Conversation Lifecycle (#10956)
* refactor: Implement clearModelForNonEphemeralAgent utility for improved agent handling - Introduced clearModelForNonEphemeralAgent function to manage model state for non-ephemeral agents across various components. - Updated ModelSelectorContext to initialize model based on agent type. - Enhanced useNavigateToConvo, useQueryParams, and useSelectMention hooks to clear model for non-ephemeral agents. - Refactored buildDefaultConvo and endpoints utility to ensure proper handling of agent_id and model state. - Improved overall conversation logic and state management for better performance and reliability. * refactor: Enhance useNewConvo hook to improve agent conversation handling - Added logic to skip access checks for existing agent conversations, utilizing localStorage to restore conversations after refresh. - Improved handling of default endpoints for agents based on user access and existing conversation state, ensuring more reliable conversation initialization. * refactor: Update ChatRoute and useAuthRedirect to include user roles - Enhanced ChatRoute to utilize user roles for improved conversation state management. - Modified useAuthRedirect to return user roles alongside authentication status, ensuring roles are available for conditional logic in ChatRoute. - Adjusted conversation initialization logic to depend on the loaded roles, enhancing the reliability of the conversation setup. * refactor: Update BaseClient to handle non-ephemeral agents in conversation logic - Added a check for non-ephemeral agents in BaseClient, modifying the exceptions set to include 'model' when applicable. - Enhanced conversation handling to improve flexibility based on agent type. * test: Add mock for clearModelForNonEphemeralAgent in useQueryParams tests - Introduced a mock for clearModelForNonEphemeralAgent to enhance testing of query parameters related to non-ephemeral agents. - This addition supports improved test coverage and ensures proper handling of model state in relevant scenarios. * refactor: Simplify mocks in useQueryParams tests for improved clarity - Updated the mocking strategy for utilities in useQueryParams tests to use actual implementations where possible, while still suppressing test output for the logger. - Enhanced the mock for tQueryParamsSchema to minimize complexity and avoid unnecessary validation during tests, improving test reliability and maintainability. * refactor: Enhance agent identification logic in BaseClient for improved clarity * chore: Import Constants in families.ts for enhanced functionality
This commit is contained in:
parent
06719794f6
commit
b5ab32c5ae
12 changed files with 161 additions and 49 deletions
|
|
@ -16,7 +16,7 @@ import store from '~/store';
|
|||
|
||||
export default function ChatRoute() {
|
||||
const { data: startupConfig } = useGetStartupConfig();
|
||||
const { isAuthenticated, user } = useAuthRedirect();
|
||||
const { isAuthenticated, user, roles } = useAuthRedirect();
|
||||
|
||||
const defaultTemporaryChat = useRecoilValue(temporaryStore.defaultTemporaryChat);
|
||||
const setIsTemporary = useRecoilCallback(
|
||||
|
|
@ -61,8 +61,11 @@ export default function ChatRoute() {
|
|||
* Adjusting this may have unintended consequences on the conversation state.
|
||||
*/
|
||||
useEffect(() => {
|
||||
// Wait for roles to load so hasAgentAccess has a definitive value in useNewConvo
|
||||
const rolesLoaded = roles?.USER != null;
|
||||
const shouldSetConvo =
|
||||
(startupConfig && !hasSetConversation.current && !modelsQuery.data?.initial) ?? false;
|
||||
(startupConfig && rolesLoaded && !hasSetConversation.current && !modelsQuery.data?.initial) ??
|
||||
false;
|
||||
/* Early exit if startupConfig is not loaded and conversation is already set and only initial models have loaded */
|
||||
if (!shouldSetConvo) {
|
||||
return;
|
||||
|
|
@ -119,6 +122,7 @@ export default function ChatRoute() {
|
|||
/* Creates infinite render if all dependencies included due to newConversation invocations exceeding call stack before hasSetConversation.current becomes truthy */
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
roles,
|
||||
startupConfig,
|
||||
initialConvoQuery.data,
|
||||
endpointsQuery.data,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|||
import { useAuthContext } from '~/hooks';
|
||||
|
||||
export default function useAuthRedirect() {
|
||||
const { user, isAuthenticated } = useAuthContext();
|
||||
const { user, roles, isAuthenticated } = useAuthContext();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -20,6 +20,7 @@ export default function useAuthRedirect() {
|
|||
|
||||
return {
|
||||
user,
|
||||
roles,
|
||||
isAuthenticated,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue