mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 06:51:59 +00:00
🕰️ fix: Send a Side Chat's Turns as Temporary Only When Its Own Conversation Is (#18455)
* 🕰️ fix: Send a Side Chat's Turns as Temporary Only When Its Own Conversation Is * 🧹 chore: Sort the Turn Services' Imports
This commit is contained in:
parent
56d8660ca0
commit
d7eea8086f
3 changed files with 86 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { renderHook } from '@testing-library/react';
|
||||
import { QueryKeys, EModelEndpoint } from 'librechat-data-provider';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { QueryKeys, RetentionMode, EModelEndpoint } from 'librechat-data-provider';
|
||||
import type { CodeApprovalModeInputs, CodeWorkspaceInputs } from '@librechat/chat';
|
||||
import type { TConversation } from 'librechat-data-provider';
|
||||
import type { ReactNode } from 'react';
|
||||
|
|
@ -118,6 +118,36 @@ describe('useTurnServices readCodeInputs', () => {
|
|||
expect(mockComparisons).toEqual({ workspace: null, approval: null });
|
||||
});
|
||||
|
||||
it("sends another pane's turns as temporary when its conversation is, not when main chat is", () => {
|
||||
/** The page's setting follows the conversation main chat shows: here, a temporary one. */
|
||||
settings = { ...settings, isTemporary: true };
|
||||
const saved = conversation({ conversationId: 'saved', isTemporary: false });
|
||||
const turns = (index: number, held: TConversation) =>
|
||||
renderHook(() => useTurnServices({ index, conversation: held }), { wrapper }).result.current;
|
||||
|
||||
expect(turns(0, saved).isTemporary).toBe(true);
|
||||
expect(turns(3, saved).isTemporary).toBe(false);
|
||||
|
||||
/** And the other way round: a temporary conversation beside a saved one stays temporary. */
|
||||
settings = { ...settings, isTemporary: false };
|
||||
const temporary = conversation({ conversationId: 'temporary', isTemporary: true });
|
||||
expect(turns(0, saved).isTemporary).toBe(false);
|
||||
expect(turns(3, temporary).isTemporary).toBe(true);
|
||||
/** A record from before the flag was stored carries only its deadline. */
|
||||
const legacy = conversation({
|
||||
conversationId: 'legacy',
|
||||
expiredAt: '2026-12-01T00:00:00.000Z',
|
||||
});
|
||||
expect(turns(3, legacy).isTemporary).toBe(true);
|
||||
|
||||
/** A deployment that keeps nothing makes every pane's turns temporary. */
|
||||
settings = {
|
||||
...settings,
|
||||
config: { ...settings.config, retentionMode: RetentionMode.EPHEMERAL },
|
||||
};
|
||||
expect(turns(3, saved).isTemporary).toBe(true);
|
||||
});
|
||||
|
||||
it('checks the submitted target against current query data, not the rendered conversation', () => {
|
||||
const rendered = conversation({ endpoint: EModelEndpoint.openAI, model: 'gpt-5' });
|
||||
const submitted = conversation({ endpoint: EModelEndpoint.agents, agent_id: 'agent_primary' });
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { useRef, useEffect } from 'react';
|
||||
import { useStore } from 'jotai';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { QueryKeys } from 'librechat-data-provider';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { launchedConversationFamily } from '@librechat/chat/react';
|
||||
import { QueryKeys, isForcedTemporaryRetention } from 'librechat-data-provider';
|
||||
import type { ChatTurnsParams, TurnServices } from '@librechat/chat/react';
|
||||
import type { TEndpointsConfig } from 'librechat-data-provider';
|
||||
import {
|
||||
|
|
@ -12,6 +12,7 @@ import {
|
|||
markPasteSubmitted,
|
||||
bindComposerLaunch,
|
||||
getRouteChatProjectId,
|
||||
isTemporaryConversation,
|
||||
} from '~/utils';
|
||||
import useGetConversation from '~/hooks/Conversations/useGetConversation';
|
||||
import useDiscardPastedFiles from '~/hooks/Files/useDiscardPastedFiles';
|
||||
|
|
@ -36,13 +37,22 @@ export default function useTurnServices({
|
|||
const setFilesToDelete = useSetFilesToDelete();
|
||||
const agentsMap = useAgentsMapContext();
|
||||
const settings = useChatSettings();
|
||||
const { isTemporary, config, auth, getEphemeralAgent } = settings;
|
||||
const { config, auth, getEphemeralAgent } = settings;
|
||||
/**
|
||||
* The conversation main chat is being compared with rides along with main chat's turns, from
|
||||
* either of its panes. A conversation in any other pane is on its own: that comparison's
|
||||
* readiness, workspace and approvals have no say in what it can send.
|
||||
*/
|
||||
const addedConversation = index === 0 || index === 1 ? settings.addedConversation : null;
|
||||
const ridesMainChat = index === 0 || index === 1;
|
||||
const addedConversation = ridesMainChat ? settings.addedConversation : null;
|
||||
/**
|
||||
* Whether main chat's turns are temporary is the page's setting, which the route keeps in step
|
||||
* with the conversation on screen. A conversation in any other pane is not that conversation,
|
||||
* so its turns are temporary when it is, or when the deployment makes every chat so.
|
||||
*/
|
||||
const isTemporary = ridesMainChat
|
||||
? settings.isTemporary
|
||||
: isTemporaryConversation(conversation) || isForcedTemporaryRetention(config.retentionMode);
|
||||
const { getExpiry } = useUserKey(conversation?.endpoint ?? '');
|
||||
const getConversation = useGetConversation(index);
|
||||
const codeWorkspaceState = useCodeWorkspace(conversation, addedConversation);
|
||||
|
|
|
|||
|
|
@ -269,3 +269,45 @@ test.describe('on a small screen', () => {
|
|||
await expect(composer).toHaveValue('Still reachable');
|
||||
});
|
||||
});
|
||||
|
||||
test('a saved conversation beside a temporary chat keeps its turns @scenario:side-chat-turn-is-not-temporary-beside-a-temporary-chat', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120_000);
|
||||
const saved = uniqueLabel('saved');
|
||||
const followUp = uniqueLabel('kept');
|
||||
const savedUrl = await startChat(page, saved);
|
||||
|
||||
/** The chat on screen is a new one the reader has made temporary. */
|
||||
await page.goto(NEW_CHAT_PATH, { timeout: 10_000 });
|
||||
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
|
||||
const temporary = page.getByRole('button', { name: 'Temporary Chat' });
|
||||
await temporary.click();
|
||||
await expect(temporary).toHaveAttribute('aria-pressed', 'true');
|
||||
|
||||
await openChatHistory(page);
|
||||
const row = conversationRow(page, savedUrl);
|
||||
await row.hover();
|
||||
await row.getByRole('button', { name: 'Conversation Menu Options' }).click();
|
||||
await page.getByRole('menuitem', { name: 'Open beside chat' }).click();
|
||||
const sideChat = page.getByRole('region', { name: 'Side chat' });
|
||||
await expect(sideChat).toContainText(replyText(saved), { timeout: 30_000 });
|
||||
|
||||
/** Temporary is what the chat on screen is, not the saved conversation beside it. */
|
||||
const composer = sideChat.getByRole('textbox', { name: 'Message input' });
|
||||
await composer.click();
|
||||
await page.keyboard.type(replyPrompt(followUp));
|
||||
const [start] = await Promise.all([
|
||||
page.waitForRequest(
|
||||
(request) =>
|
||||
request.method() === 'POST' &&
|
||||
/\/api\/agents\/chat\/[^/]+$/.test(new URL(request.url()).pathname) &&
|
||||
!request.url().endsWith('/abort'),
|
||||
),
|
||||
page.keyboard.press('Enter'),
|
||||
]);
|
||||
const posted = start.postDataJSON() as { conversationId?: string; isTemporary?: boolean };
|
||||
expect(savedUrl).toContain(posted.conversationId ?? 'none');
|
||||
expect(posted.isTemporary).toBe(false);
|
||||
await expect(sideChat).toContainText(replyText(followUp), { timeout: 30_000 });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue