Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion client/src/hooks/Chat/__tests__/services.readCodeInputs.spec.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' });
Expand Down
16 changes: 13 additions & 3 deletions client/src/hooks/Chat/services.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,6 +12,7 @@ import {
markPasteSubmitted,
bindComposerLaunch,
getRouteChatProjectId,
isTemporaryConversation,
} from '~/utils';
import useGetConversation from '~/hooks/Conversations/useGetConversation';
import useDiscardPastedFiles from '~/hooks/Files/useDiscardPastedFiles';
Expand All @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions e2e/specs/mock/scenarios/side-chat-open-beside.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,48 @@ test('an earlier conversation opens beside the one on screen and takes a turn th
await expect(page.getByRole('menuitem', { name: 'Open beside chat' })).toHaveCount(0);
});

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 });
});

test.describe('on a small screen', () => {
test.use({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });

Expand Down
Loading