mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00

* refactor: Ensure Axios Errors are less Verbose if No Response * refactor: Improve error handling in logAxiosError function * fix: Prevent ModelSelect from rendering for Agent Endpoints * refactor: Enhance logging functions with type parameter for better clarity * refactor: Update buildDefaultConvo function to use optional endpoint parameter since we pass a default value for undefined * refactor: Replace console logs with logger warnings and errors in useNavigateToConvo hook, and handle removed endpoint edge case * chore: import order
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import {
|
|
parseConvo,
|
|
EModelEndpoint,
|
|
isAssistantsEndpoint,
|
|
isAgentsEndpoint,
|
|
} from 'librechat-data-provider';
|
|
import type { TConversation } from 'librechat-data-provider';
|
|
import { getLocalStorageItems } from './localStorage';
|
|
|
|
const buildDefaultConvo = ({
|
|
models,
|
|
conversation,
|
|
endpoint = null,
|
|
lastConversationSetup,
|
|
}: {
|
|
models: string[];
|
|
conversation: TConversation;
|
|
endpoint?: EModelEndpoint | null;
|
|
lastConversationSetup: TConversation | null;
|
|
}): TConversation => {
|
|
const { lastSelectedModel, lastSelectedTools } = getLocalStorageItems();
|
|
const endpointType = lastConversationSetup?.endpointType ?? conversation.endpointType;
|
|
|
|
if (!endpoint) {
|
|
return {
|
|
...conversation,
|
|
endpointType,
|
|
endpoint,
|
|
};
|
|
}
|
|
|
|
const availableModels = models;
|
|
const model = lastConversationSetup?.model ?? lastSelectedModel?.[endpoint] ?? '';
|
|
const secondaryModel: string | null =
|
|
endpoint === EModelEndpoint.gptPlugins
|
|
? (lastConversationSetup?.agentOptions?.model ?? lastSelectedModel?.secondaryModel ?? null)
|
|
: null;
|
|
|
|
let possibleModels: string[], secondaryModels: string[];
|
|
|
|
if (availableModels.includes(model)) {
|
|
possibleModels = [model, ...availableModels];
|
|
} else {
|
|
possibleModels = [...availableModels];
|
|
}
|
|
|
|
if (secondaryModel != null && secondaryModel !== '' && availableModels.includes(secondaryModel)) {
|
|
secondaryModels = [secondaryModel, ...availableModels];
|
|
} else {
|
|
secondaryModels = [...availableModels];
|
|
}
|
|
|
|
const convo = parseConvo({
|
|
endpoint,
|
|
endpointType,
|
|
conversation: lastConversationSetup,
|
|
possibleValues: {
|
|
models: possibleModels,
|
|
secondaryModels,
|
|
},
|
|
});
|
|
|
|
const defaultConvo = {
|
|
...conversation,
|
|
...convo,
|
|
endpointType,
|
|
endpoint,
|
|
};
|
|
|
|
// Ensures assistant_id is always defined
|
|
const assistantId = convo?.assistant_id ?? '';
|
|
const defaultAssistantId = lastConversationSetup?.assistant_id ?? '';
|
|
if (isAssistantsEndpoint(endpoint) && !defaultAssistantId && assistantId) {
|
|
defaultConvo.assistant_id = assistantId;
|
|
}
|
|
|
|
// Ensures agent_id is always defined
|
|
const agentId = convo?.agent_id ?? '';
|
|
const defaultAgentId = lastConversationSetup?.agent_id ?? '';
|
|
if (isAgentsEndpoint(endpoint) && !defaultAgentId && agentId) {
|
|
defaultConvo.agent_id = agentId;
|
|
}
|
|
|
|
defaultConvo.tools = lastConversationSetup?.tools ?? lastSelectedTools ?? defaultConvo.tools;
|
|
|
|
return defaultConvo;
|
|
};
|
|
|
|
export default buildDefaultConvo;
|