mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
☑️ refactor: Allow Mid-convo Agent Selection from Agent Panel (#8510)
This commit is contained in:
parent
0a169a1ff6
commit
0b1b0af741
1 changed files with 17 additions and 12 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
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 type { TConversation, TPreset, Agent } from 'librechat-data-provider';
|
||||||
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
|
import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo';
|
||||||
import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
|
import { useAgentsMapContext } from '~/Providers/AgentsMapContext';
|
||||||
|
|
@ -24,22 +29,22 @@ export default function useSelectAgent() {
|
||||||
const updateConversation = useCallback(
|
const updateConversation = useCallback(
|
||||||
(agent: Partial<Agent>, template: Partial<TPreset | TConversation>) => {
|
(agent: Partial<Agent>, template: Partial<TPreset | TConversation>) => {
|
||||||
logger.log('conversation', 'Updating conversation with agent', agent);
|
logger.log('conversation', 'Updating conversation with agent', agent);
|
||||||
if (isAgentsEndpoint(conversation?.endpoint)) {
|
if (isAssistantsEndpoint(conversation?.endpoint)) {
|
||||||
const currentConvo = getDefaultConversation({
|
|
||||||
conversation: { ...(conversation ?? {}), agent_id: agent.id },
|
|
||||||
preset: template,
|
|
||||||
});
|
|
||||||
newConversation({
|
|
||||||
template: currentConvo,
|
|
||||||
preset: template as Partial<TPreset>,
|
|
||||||
keepLatestMessage: true,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
newConversation({
|
newConversation({
|
||||||
template: { ...(template as Partial<TConversation>) },
|
template: { ...(template as Partial<TConversation>) },
|
||||||
preset: template as Partial<TPreset>,
|
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],
|
[conversation, getDefaultConversation, newConversation],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue