mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 23:43:35 +00:00
🛶 fix: Keep Revealed Queue Actions and E2E Flows After Composer Redesign
(cherry picked from commit 25d74a636d)
Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/16361
This commit is contained in:
parent
bb82aee8c3
commit
596c4dd592
4 changed files with 174 additions and 61 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { memo, useId, useRef, useMemo, useState, useCallback } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useDrag, useDrop } from 'react-dnd';
|
||||
import { X, Pencil, TextQuote, TriangleAlert, GripVertical, Clock } from 'lucide-react';
|
||||
import {
|
||||
|
|
@ -13,8 +14,9 @@ import {
|
|||
import type { RestoreToComposer } from '~/Providers/ComposerRestoreContext';
|
||||
import type { SteeringControls } from '~/hooks/Chat/useSteering';
|
||||
import type { QueuedMessage } from '~/store/families';
|
||||
import { claimQueuedIntent, releaseQueuedIntent, hasQueuedIntent } from '~/utils/queueIntent';
|
||||
import { useQueuedTurnPortal } from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import { escalatingSteerFamily, revealedQueuedTurnFamily } from '~/store/steer';
|
||||
import { claimQueuedIntent, releaseQueuedIntent } from '~/utils/queueIntent';
|
||||
import EscalateNowButton from '~/components/Chat/Input/EscalateNowButton';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
|
@ -59,6 +61,8 @@ interface QueueRowProps {
|
|||
canRestoreToComposer: (conversationId: string) => boolean;
|
||||
/** The server has revealed this row as the next user turn; only removal remains meaningful. */
|
||||
revealed?: boolean;
|
||||
/** The matching user turn owns this row's actions when its bubble is visible. */
|
||||
portalElement?: HTMLSpanElement;
|
||||
onAnnounce: (message: string) => void;
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +104,7 @@ function QueueRow({
|
|||
canRestoreToComposer,
|
||||
onAnnounce,
|
||||
revealed = false,
|
||||
portalElement,
|
||||
}: QueueRowProps) {
|
||||
const localize = useLocalize();
|
||||
const { showToast } = useToastContext();
|
||||
|
|
@ -388,6 +393,38 @@ function QueueRow({
|
|||
* short enough that appearing and vanishing again just reads as a flicker. */
|
||||
const showEscalate = !isRecovered && (steering.pausedOnApproval || steering.duringRunActive);
|
||||
|
||||
if (portalElement != null) {
|
||||
return createPortal(
|
||||
<span className="flex items-center gap-1">
|
||||
{serverActionable && (
|
||||
<IconButton
|
||||
label={localize('com_ui_edit_message')}
|
||||
size="xs"
|
||||
disabled={actionPending || hasQueuedIntent(message.id)}
|
||||
onClick={editToComposer}
|
||||
>
|
||||
<Pencil className="h-4 w-4" aria-hidden="true" />
|
||||
</IconButton>
|
||||
)}
|
||||
<IconButton
|
||||
label={localize('com_ui_remove_queued')}
|
||||
size="xs"
|
||||
disabled={
|
||||
actionPending ||
|
||||
hasQueuedIntent(message.id) ||
|
||||
(!serverActionable &&
|
||||
!(message.server?.id != null && message.server.status === 'claimed'))
|
||||
}
|
||||
onClick={removeToComposer}
|
||||
>
|
||||
<X className="h-4 w-4" aria-hidden="true" />
|
||||
</IconButton>
|
||||
</span>,
|
||||
portalElement,
|
||||
message.id,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={rowRef}
|
||||
|
|
@ -609,55 +646,69 @@ function Queue({
|
|||
setAnnouncement('');
|
||||
}
|
||||
|
||||
const target = useQueuedTurnPortal()?.target;
|
||||
const portaledIndex =
|
||||
target?.conversationId === conversationId &&
|
||||
revealed?.clientRequestId === target.clientRequestId
|
||||
? queued.findIndex((message) => message.clientRequestId === target.clientRequestId)
|
||||
: -1;
|
||||
|
||||
if (queued.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
/* Inset and only rounded on top: the rail reads as paper tucked behind
|
||||
the composer rather than a second composer stacked on it.
|
||||
const renderRow = (message: QueuedMessage, index: number, portalElement?: HTMLSpanElement) => (
|
||||
<QueueRow
|
||||
key={message.id}
|
||||
message={message}
|
||||
index={index}
|
||||
total={queued.length}
|
||||
order={order}
|
||||
serverOwnedIds={serverOwnedIds}
|
||||
steering={steering}
|
||||
conversationId={conversationId}
|
||||
interruptPending={interruptPending}
|
||||
reorderHintId={reorderHintId}
|
||||
onRestoreToComposer={onRestoreToComposer}
|
||||
canRestoreToComposer={canRestoreToComposer}
|
||||
revealed={
|
||||
revealed != null &&
|
||||
message.clientRequestId != null &&
|
||||
revealed.clientRequestId === message.clientRequestId
|
||||
}
|
||||
portalElement={portalElement}
|
||||
onAnnounce={setAnnouncement}
|
||||
/>
|
||||
);
|
||||
|
||||
The rows are the list; the hint and the live region are not items, and a
|
||||
list that owns them reports the wrong count. */
|
||||
<div className="border-border-light bg-surface-secondary mx-3 overflow-hidden rounded-t-2xl border border-b-0">
|
||||
<div
|
||||
role="list"
|
||||
aria-label={localize('com_ui_queued_messages')}
|
||||
data-testid="composer-queue"
|
||||
className="flex flex-col"
|
||||
>
|
||||
{queued.map((message: QueuedMessage, index: number) => (
|
||||
<QueueRow
|
||||
key={message.id}
|
||||
message={message}
|
||||
index={index}
|
||||
total={queued.length}
|
||||
order={order}
|
||||
serverOwnedIds={serverOwnedIds}
|
||||
steering={steering}
|
||||
conversationId={conversationId}
|
||||
interruptPending={interruptPending}
|
||||
reorderHintId={reorderHintId}
|
||||
onRestoreToComposer={onRestoreToComposer}
|
||||
canRestoreToComposer={canRestoreToComposer}
|
||||
revealed={
|
||||
revealed != null &&
|
||||
message.clientRequestId != null &&
|
||||
revealed.clientRequestId === message.clientRequestId
|
||||
}
|
||||
onAnnounce={setAnnouncement}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{queued.length > 1 && (
|
||||
<span id={reorderHintId} className="sr-only">
|
||||
{localize('com_ui_queue_reorder_hint')}
|
||||
</span>
|
||||
return (
|
||||
<>
|
||||
{queued.length > (portaledIndex >= 0 ? 1 : 0) && (
|
||||
<div className="border-border-light bg-surface-secondary mx-3 overflow-hidden rounded-t-2xl border border-b-0">
|
||||
<div
|
||||
role="list"
|
||||
aria-label={localize('com_ui_queued_messages')}
|
||||
data-testid="composer-queue"
|
||||
className="flex flex-col"
|
||||
>
|
||||
{queued.map((message, index) =>
|
||||
index === portaledIndex ? null : renderRow(message, index),
|
||||
)}
|
||||
</div>
|
||||
{queued.length > 1 && (
|
||||
<span id={reorderHintId} className="sr-only">
|
||||
{localize('com_ui_queue_reorder_hint')}
|
||||
</span>
|
||||
)}
|
||||
<span role="status" aria-live="polite" className="sr-only">
|
||||
{announcement}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<span role="status" aria-live="polite" className="sr-only">
|
||||
{announcement}
|
||||
</span>
|
||||
</div>
|
||||
{portaledIndex >= 0 &&
|
||||
target != null &&
|
||||
renderRow(queued[portaledIndex], portaledIndex, target.element)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ import { ReasoningEffort } from 'librechat-data-provider';
|
|||
import { act, render, screen, within, fireEvent } from '@testing-library/react';
|
||||
import type { SteeringControls } from '~/hooks/Chat/useSteering';
|
||||
import type { QueuedMessage } from '~/store/families';
|
||||
import {
|
||||
QueuedTurnPortalProvider,
|
||||
useQueuedTurnPortal,
|
||||
} from '~/components/Chat/Steering/QueuedTurnPortal';
|
||||
import { hasQueuedIntent, releaseQueuedIntent } from '~/utils/queueIntent';
|
||||
import { revealedQueuedTurnFamily } from '~/store/steer';
|
||||
import Queue from '../Queue';
|
||||
|
|
@ -99,6 +103,22 @@ const approvalPausedSteering = steeringWith({
|
|||
pausedOnApproval: true,
|
||||
});
|
||||
|
||||
function PendingTurnTarget({ requestId }: { requestId: string }) {
|
||||
const setTarget = useQueuedTurnPortal()?.setTarget;
|
||||
const register = React.useCallback(
|
||||
(element: HTMLSpanElement | null) =>
|
||||
setTarget?.(
|
||||
element == null ? null : { element, conversationId: CONVO_ID, clientRequestId: requestId },
|
||||
),
|
||||
[setTarget, requestId],
|
||||
);
|
||||
return (
|
||||
<div data-testid="pending-turn">
|
||||
<span ref={register} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const queued = (over: Partial<QueuedMessage> = {}): QueuedMessage =>
|
||||
({
|
||||
id: 'q1',
|
||||
|
|
@ -116,20 +136,26 @@ function renderQueue(
|
|||
onEditToComposer?: jest.Mock;
|
||||
onRestoreToComposer?: jest.Mock;
|
||||
canRestoreToComposer?: jest.Mock;
|
||||
portalRequestId?: string;
|
||||
} = {},
|
||||
) {
|
||||
return render(
|
||||
<RecoilRoot initializeState={({ set }) => set(store.queuedMessagesByConvoId(CONVO_ID), items)}>
|
||||
{/* Mirrors `App`, which mounts the provider around the whole tree. */}
|
||||
<DndProvider backend={HTML5Backend}>
|
||||
<Queue
|
||||
steering={steeringOverride}
|
||||
conversationId={CONVO_ID}
|
||||
onRestoreToComposer={
|
||||
handlers.onRestoreToComposer ?? handlers.onEditToComposer ?? jest.fn()
|
||||
}
|
||||
canRestoreToComposer={handlers.canRestoreToComposer ?? jest.fn().mockReturnValue(true)}
|
||||
/>
|
||||
<QueuedTurnPortalProvider>
|
||||
<Queue
|
||||
steering={steeringOverride}
|
||||
conversationId={CONVO_ID}
|
||||
onRestoreToComposer={
|
||||
handlers.onRestoreToComposer ?? handlers.onEditToComposer ?? jest.fn()
|
||||
}
|
||||
canRestoreToComposer={handlers.canRestoreToComposer ?? jest.fn().mockReturnValue(true)}
|
||||
/>
|
||||
{handlers.portalRequestId != null && (
|
||||
<PendingTurnTarget requestId={handlers.portalRequestId} />
|
||||
)}
|
||||
</QueuedTurnPortalProvider>
|
||||
</DndProvider>
|
||||
</RecoilRoot>,
|
||||
);
|
||||
|
|
@ -828,6 +854,39 @@ describe('Queue', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('moves a claimed turn’s sole remove action into the pending user turn', () => {
|
||||
const jotaiStore = getDefaultStore();
|
||||
jotaiStore.set(revealedQueuedTurnFamily(CONVO_ID), {
|
||||
clientRequestId: 'req-1',
|
||||
parentMessageId: 'response-1',
|
||||
text: 'follow up on this',
|
||||
revealedAt: '2026-09-14T00:00:00.000Z',
|
||||
});
|
||||
try {
|
||||
renderQueue(
|
||||
[
|
||||
queued({
|
||||
id: 'q1',
|
||||
clientRequestId: 'req-1',
|
||||
server: { id: 'server-q1', status: 'claimed' },
|
||||
}),
|
||||
queued({ id: 'q2', text: 'another queued message' }),
|
||||
],
|
||||
steeringWith({ canSendQueuedNow: false, canSteer: false }),
|
||||
{ portalRequestId: 'req-1' },
|
||||
);
|
||||
const turn = within(screen.getByTestId('pending-turn'));
|
||||
expect(turn.getByLabelText('com_ui_remove_queued')).toBeEnabled();
|
||||
expect(turn.queryByRole('button', { name: 'com_ui_send_now' })).not.toBeInTheDocument();
|
||||
expect(turn.queryByLabelText('com_ui_edit_message')).not.toBeInTheDocument();
|
||||
const row = screen.getByTestId('queued-message-row');
|
||||
expect(row).toHaveTextContent('another queued message');
|
||||
expect(row).not.toHaveTextContent('follow up on this');
|
||||
} finally {
|
||||
jotaiStore.set(revealedQueuedTurnFamily(CONVO_ID), null);
|
||||
}
|
||||
});
|
||||
|
||||
describe('server-owned queue states', () => {
|
||||
it.each(['sending', 'claimed', 'uncertain'] as const)(
|
||||
'disables local actions while a %s row remains server-owned',
|
||||
|
|
|
|||
|
|
@ -29,13 +29,14 @@ async function setPhaseLabel(request: APIRequestContext) {
|
|||
}
|
||||
|
||||
async function selectEphemeralMCP(page: Page) {
|
||||
await page.getByRole('button', { name: 'MCP Servers', exact: true }).click();
|
||||
const serverItem = page.getByRole('menuitemcheckbox', { name: new RegExp(MCP_SERVER_TITLE) });
|
||||
await expect(serverItem).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Attach and tools' }).click();
|
||||
const palette = page.getByRole('dialog', { name: 'Attach and tools' });
|
||||
const serverItem = palette.getByRole('button', { name: new RegExp(`^${MCP_SERVER_TITLE}\\b`) });
|
||||
await expect(serverItem).toBeVisible({ timeout: 20_000 });
|
||||
await serverItem.click();
|
||||
await expect(serverItem).toHaveAttribute('aria-checked', 'true');
|
||||
await expect(serverItem).toHaveAttribute('aria-pressed', 'true');
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.getByRole('button', { name: new RegExp(MCP_SERVER_TITLE) })).toBeVisible();
|
||||
await expect(page.getByRole('listitem', { name: MCP_SERVER_TITLE, exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
function collectPageProblems(page: Page): string[] {
|
||||
|
|
|
|||
|
|
@ -29,10 +29,12 @@ test('keeps uploaded user images on the right side of a wider message bubble', a
|
|||
await page.goto(NEW_CHAT_PATH);
|
||||
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
|
||||
|
||||
await page.getByRole('button', { name: 'Attach File Options' }).click();
|
||||
const chooser = page.waitForEvent('filechooser');
|
||||
await page.getByText('Upload to Provider').click();
|
||||
const fileChooser = await chooser;
|
||||
await page.getByRole('button', { name: 'Attach and tools' }).click();
|
||||
const palette = page.getByRole('dialog', { name: 'Attach and tools' });
|
||||
const [fileChooser] = await Promise.all([
|
||||
page.waitForEvent('filechooser'),
|
||||
palette.getByRole('button', { name: 'Upload to Provider', exact: true }).click(),
|
||||
]);
|
||||
const upload = page.waitForResponse(
|
||||
(response) =>
|
||||
new URL(response.url()).pathname === '/api/files/images' &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue