diff --git a/client/src/components/Chat/Input/Composer/Queue.tsx b/client/src/components/Chat/Input/Composer/Queue.tsx index c8903d4dbe..36eb7b71d4 100644 --- a/client/src/components/Chat/Input/Composer/Queue.tsx +++ b/client/src/components/Chat/Input/Composer/Queue.tsx @@ -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( + + {serverActionable && ( + + + )} + + + , + portalElement, + message.id, + ); + } + return (
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) => ( + + ); - The rows are the list; the hint and the live region are not items, and a - list that owns them reports the wrong count. */ -
-
- {queued.map((message: QueuedMessage, index: number) => ( - - ))} -
- {queued.length > 1 && ( - - {localize('com_ui_queue_reorder_hint')} - + return ( + <> + {queued.length > (portaledIndex >= 0 ? 1 : 0) && ( +
+
+ {queued.map((message, index) => + index === portaledIndex ? null : renderRow(message, index), + )} +
+ {queued.length > 1 && ( + + {localize('com_ui_queue_reorder_hint')} + + )} + + {announcement} + +
)} - - {announcement} - -
+ {portaledIndex >= 0 && + target != null && + renderRow(queued[portaledIndex], portaledIndex, target.element)} + ); } diff --git a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx index e0c778b294..0b528e87d1 100644 --- a/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx +++ b/client/src/components/Chat/Input/Composer/__tests__/Queue.spec.tsx @@ -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 ( +
+ +
+ ); +} + const queued = (over: Partial = {}): QueuedMessage => ({ id: 'q1', @@ -116,20 +136,26 @@ function renderQueue( onEditToComposer?: jest.Mock; onRestoreToComposer?: jest.Mock; canRestoreToComposer?: jest.Mock; + portalRequestId?: string; } = {}, ) { return render( set(store.queuedMessagesByConvoId(CONVO_ID), items)}> {/* Mirrors `App`, which mounts the provider around the whole tree. */} - + + + {handlers.portalRequestId != null && ( + + )} + , ); @@ -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', diff --git a/e2e/specs/mock/activity-fold.spec.ts b/e2e/specs/mock/activity-fold.spec.ts index 7a588ce22f..233f1bd009 100644 --- a/e2e/specs/mock/activity-fold.spec.ts +++ b/e2e/specs/mock/activity-fold.spec.ts @@ -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[] { diff --git a/e2e/specs/mock/user-image-alignment.spec.ts b/e2e/specs/mock/user-image-alignment.spec.ts index 6fa0160de7..28e1d55ec1 100644 --- a/e2e/specs/mock/user-image-alignment.spec.ts +++ b/e2e/specs/mock/user-image-alignment.spec.ts @@ -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' &&