mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-10 01:44:44 +00:00
📌 fix: Preserve Ephemeral Agent Selections on Optimistic Hydration (#13433)
This commit is contained in:
parent
e3cc2a9c62
commit
fd5d44162a
2 changed files with 49 additions and 1 deletions
48
client/src/store/__tests__/agents.spec.tsx
Normal file
48
client/src/store/__tests__/agents.spec.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import React from 'react';
|
||||
import { RecoilRoot, useRecoilValue } from 'recoil';
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
|
||||
import { ephemeralAgentByConvoId, useApplyNewAgentTemplate } from '../agents';
|
||||
|
||||
jest.mock('~/utils', () => ({
|
||||
logger: {
|
||||
log: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<RecoilRoot>{children}</RecoilRoot>
|
||||
);
|
||||
|
||||
const useAgentTemplateHarness = (conversationId: string) => {
|
||||
const applyTemplate = useApplyNewAgentTemplate();
|
||||
const ephemeralAgent = useRecoilValue(ephemeralAgentByConvoId(conversationId));
|
||||
return { applyTemplate, ephemeralAgent };
|
||||
};
|
||||
|
||||
describe('useApplyNewAgentTemplate', () => {
|
||||
it('applies an explicit ephemeral agent when optimistic hydration makes source and target match', async () => {
|
||||
const conversationId = 'convo-123';
|
||||
const agent = {
|
||||
mcp: ['chrome-devtools'],
|
||||
skills: true,
|
||||
artifacts: 'default',
|
||||
web_search: true,
|
||||
file_search: true,
|
||||
execute_code: true,
|
||||
};
|
||||
const { result } = renderHook(() => useAgentTemplateHarness(conversationId), {
|
||||
wrapper: Wrapper,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.applyTemplate(conversationId, conversationId, agent);
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.ephemeralAgent).toEqual(agent);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -43,7 +43,7 @@ export function useApplyNewAgentTemplate() {
|
|||
const sourceId = _sourceId || Constants.NEW_CONVO;
|
||||
logger.log('agents', `Attempting to apply template from "${sourceId}" to "${targetId}"`);
|
||||
|
||||
if (targetId === sourceId) {
|
||||
if (targetId === sourceId && ephemeralAgentState == null) {
|
||||
logger.warn('agents', `Attempted to apply template to itself ("${sourceId}"). Skipping.`);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue