☑️ refactor: Allow Mid-convo Agent Selection from Agent Panel (#8510)

This commit is contained in:
Danny Avila 2025-07-17 11:30:50 -04:00 committed by GitHub
parent 0a169a1ff6
commit 0b1b0af741
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,11 @@
import { useCallback, useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { EModelEndpoint, isAgentsEndpoint, Constants, QueryKeys } from 'librechat-data-provider';
import {
Constants,
QueryKeys,
EModelEndpoint,
isAssistantsEndpoint,
} from 'librechat-data-provider';
import type { TConversation, TPreset, Agent } from 'librechat-data-provider';
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
@ -24,22 +29,22 @@ export default function useSelectAgent() {
const updateConversation = useCallback(
(agent: Partial<Agent>, template: Partial<TPreset | TConversation>) => {
logger.log('conversation', 'Updating conversation with agent', agent);
if (isAgentsEndpoint(conversation?.endpoint)) {
const currentConvo = getDefaultConversation({
conversation: { ...(conversation ?? {}), agent_id: agent.id },
preset: template,
});
newConversation({
template: currentConvo,
preset: template as Partial<TPreset>,
keepLatestMessage: true,
});
} else {
if (isAssistantsEndpoint(conversation?.endpoint)) {
newConversation({
template: { ...(template as Partial<TConversation>) },
preset: template as Partial<TPreset>,
});
return;
}
const currentConvo = getDefaultConversation({
conversation: { ...(conversation ?? {}), agent_id: agent.id },
preset: template,
});
newConversation({
template: currentConvo,
preset: template as Partial<TPreset>,
keepLatestMessage: true,
});
},
[conversation, getDefaultConversation, newConversation],
);