From 100b127111731e8cb874adc3e33853e70517e376 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sun, 11 Oct 2026 14:36:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=AC=20feat:=20Animate=20Background=20T?= =?UTF-8?q?asks=20and=20Add=20Tool=20Navigation=20(#16959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Animate background tasks and add tool navigation * fix: Focus background task navigation destinations directly * style: Refine background task controls and navigation icons * style: Place task stop controls after navigation * fix: Address background task navigation and rendering findings * fix: Fence task navigation and animate first detail reveal * fix: Prefer exact subagent thread navigation targets * fix: Preserve tool card hydration without navigation wrappers * fix: Scope task destinations and reveal event subagents * fix: Protect navigation focus and use theme focus roles --- .../Chat/BackgroundTasks/Button.tsx | 117 ++++++- .../components/Chat/BackgroundTasks/Card.tsx | 74 +++- .../Chat/BackgroundTasks/Section.tsx | 11 +- .../BackgroundTasks/__tests__/Button.test.tsx | 319 +++++++++++++++++- .../components/Chat/BackgroundTasks/rows.ts | 12 + .../components/Chat/Messages/Content/Part.tsx | 7 + .../Chat/Messages/Content/Parts/BashCall.tsx | 9 +- .../Messages/Content/Parts/ExecuteCode.tsx | 9 +- .../Messages/Content/Parts/ReadFileCall.tsx | 11 +- .../Chat/Messages/Content/ToolCall.tsx | 4 + .../Subagents/EventSubagentActivityGroup.tsx | 4 +- client/src/locales/en/translation.json | 2 + client/src/style.css | 4 + eslint-suppressions.json | 5 - packages/client/src/components/IconButton.tsx | 4 +- 15 files changed, 545 insertions(+), 47 deletions(-) diff --git a/client/src/components/Chat/BackgroundTasks/Button.tsx b/client/src/components/Chat/BackgroundTasks/Button.tsx index 472f9433ac..ace336d4ee 100644 --- a/client/src/components/Chat/BackgroundTasks/Button.tsx +++ b/client/src/components/Chat/BackgroundTasks/Button.tsx @@ -1,7 +1,8 @@ import { memo, useEffect, useRef, useState } from 'react'; import * as Ariakit from '@ariakit/react'; -import { TooltipAnchor } from '@librechat/client'; +import { Button, IconButton, TooltipAnchor } from '@librechat/client'; import { ListTodo, Maximize2, Minimize2, Square, X } from 'lucide-react'; +import type { TaskRow } from './rows'; import { RECENT_SUBAGENT_WINDOW_MS } from './rows'; import useBackgroundTasks from './useTasks'; import { useLocalize } from '~/hooks'; @@ -12,7 +13,7 @@ import { cn } from '~/utils'; const TICK_MS = 1_000; const iconButtonClass = - 'flex size-7 shrink-0 items-center justify-center rounded-md text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring-primary disabled:pointer-events-none disabled:opacity-50'; + 'flex size-7 shrink-0 items-center justify-center rounded-md text-text-secondary hover:bg-surface-hover hover:text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-control disabled:pointer-events-none disabled:opacity-50'; /** Header control listing the conversation's background tools and subagents. */ function BackgroundTasksButton({ @@ -26,6 +27,7 @@ function BackgroundTasksButton({ const popover = Ariakit.usePopoverStore({ placement: 'bottom-end' }); const open = Ariakit.useStoreState(popover, 'open'); const disclosureRef = useRef(null); + const finalFocusRef = useRef(null); const [now, setNow] = useState(() => Date.now()); const [wide, setWide] = useState(false); const [popoverElement, setPopoverElement] = useState(null); @@ -34,6 +36,7 @@ function BackgroundTasksButton({ useEffect(() => { setNow(Date.now()); + if (open) finalFocusRef.current = disclosureRef.current; if (!open || activeCount === 0) return; const timer = setInterval(() => setNow(Date.now()), TICK_MS); return () => clearInterval(timer); @@ -81,6 +84,86 @@ function BackgroundTasksButton({ } else if (partiallyStoppable) { stopAllLabel = localize('com_ui_background_tasks_stop_available'); } + const jumpToTool = (row: TaskRow): boolean => { + if (row.eventOrigin && row.threadId != null) { + const events = Array.from( + document.querySelectorAll( + '[data-event-subagent-conversation] [data-subagent-thread]', + ), + ).filter( + (element) => + element.dataset.subagentThread === row.threadId && + element.dataset.subagentParentMessage === row.messageId && + element.closest('[data-event-subagent-conversation]')?.dataset + .eventSubagentConversation === conversationId, + ); + if (events.length !== 1) return false; + const target = events[0]; + if (target.matches(':disabled')) return false; + const group = target.closest('[data-event-subagent-conversation]'); + group?.querySelector('button[aria-expanded="false"]')?.click(); + finalFocusRef.current = null; + popover.hide(); + window.requestAnimationFrame(() => { + if (!target.isConnected || popover.getState().open) return; + target.focus({ preventScroll: true }); + target.scrollIntoView?.({ + block: 'center', + behavior: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches + ? 'instant' + : 'smooth', + }); + }); + return true; + } + if (row.messageId == null) return false; + const message = document.getElementById(row.messageId); + if (message == null) return false; + const scope = message; + const destinations = Array.from( + scope.querySelectorAll('[data-task-tool-call]'), + ).filter( + (element) => + element.dataset.taskToolCall === row.toolCallId && + (row.stepId == null || element.dataset.taskStep === row.stepId), + ); + const targets = Array.from( + scope.querySelectorAll( + '[data-tool-call-id], [data-subagent-tool-call], [data-subagent-thread]', + ), + ).filter( + (element) => + (row.threadId != null && element.dataset.subagentThread === row.threadId) || + (row.toolCallId != null && + (element.dataset.toolCallId === row.toolCallId || + element.dataset.subagentToolCall === row.toolCallId)), + ); + // Legacy call ids are only usable when they identify one rendered call. + const threads = + row.threadId == null + ? [] + : targets.filter((element) => element.dataset.subagentThread === row.threadId); + let target = message; + if (threads.length === 1) target = threads[0]; + else if (destinations.length === 1) target = destinations[0]; + else if (destinations.length === 0 && targets.length === 1) target = targets[0]; + if (target == null || target.closest('[inert], [hidden], [aria-hidden="true"]') != null) + return false; + if (!target.hasAttribute('tabindex') && !target.matches('button')) { + target.tabIndex = -1; + target.addEventListener('blur', () => target.removeAttribute('tabindex'), { once: true }); + } + finalFocusRef.current = null; + target.focus({ preventScroll: true }); + popover.hide(); + target.scrollIntoView?.({ + block: 'center', + behavior: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches + ? 'instant' + : 'smooth', + }); + return true; + }; const card = (row: (typeof rows)[number]) => ( ); @@ -126,30 +210,35 @@ function BackgroundTasksButton({ gutter={8} portal unmountOnHide - finalFocus={disclosureRef} + finalFocus={finalFocusRef} + autoFocusOnHide={() => finalFocusRef.current != null} aria-label={title} className={cn( - 'border-border-medium bg-surface-secondary text-text-primary rounded-theme-menu-panel z-[200] flex max-h-[min(36rem,calc(100vh-5rem))] max-w-[calc(100vw-2rem)] flex-col border shadow-lg focus:outline-none', - wide ? 'w-[36rem]' : 'w-80', + 'animate-composer-popover border-border-medium bg-surface-secondary text-text-primary rounded-theme-menu-panel animate-composer-popover-resize z-[200] flex max-w-[calc(100vw-2rem)] flex-col border shadow-lg focus:outline-none motion-reduce:transition-none', + wide + ? 'max-h-[calc(100dvh-5rem)] w-[min(56rem,calc(100vw-2rem))]' + : 'max-h-[min(36rem,calc(100dvh-5rem))] w-80', )} >
{title} - + @@ -165,7 +254,7 @@ function BackgroundTasksButton({

{localize('com_ui_background_tasks_load_failed')}

+ } /> diff --git a/client/src/components/Chat/BackgroundTasks/Card.tsx b/client/src/components/Chat/BackgroundTasks/Card.tsx index 65ed9fadd0..4987da9641 100644 --- a/client/src/components/Chat/BackgroundTasks/Card.tsx +++ b/client/src/components/Chat/BackgroundTasks/Card.tsx @@ -1,10 +1,11 @@ import { memo, useId, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { ChevronDown, Square } from 'lucide-react'; -import { Spinner, TooltipAnchor } from '@librechat/client'; +import { ArrowUpRight, ChevronDown, Square } from 'lucide-react'; +import { IconButton, Spinner, TooltipAnchor } from '@librechat/client'; import type { TaskRow, TaskRowDelivery, TaskRowStatus } from './rows'; import type { TranslationKeys } from '~/hooks/useLocalize'; import { getRunStepDurationLabels, getToolDisplayLabel, cn } from '~/utils'; +import { Collapse } from '~/components/ui'; import { useLocalize } from '~/hooks'; const STATUS_KEYS: Record = { @@ -36,6 +37,7 @@ function TaskCard({ isStopping, onStop, portalElement, + onJump, }: { row: TaskRow; now: number; @@ -43,11 +45,14 @@ function TaskCard({ isStopping: boolean; onStop: (row: TaskRow) => void; portalElement: HTMLElement | null; + onJump: (row: TaskRow) => boolean; }) { const localize = useLocalize(); const { i18n } = useTranslation(); const detailId = useId(); const [open, setOpen] = useState(false); + const [visited, setVisited] = useState(false); + const [jumpUnavailable, setJumpUnavailable] = useState(false); const active = row.status === 'running' || row.status === 'stopping'; const kindLabel = row.kind === 'subagent' @@ -71,10 +76,15 @@ function TaskCard({ type="button" aria-expanded={open} aria-controls={detailId} - onClick={() => setOpen((value) => !value)} - className="text-text-primary focus-visible:ring-ring-primary flex max-w-full items-start gap-1 rounded text-left text-sm focus-visible:ring-2 focus-visible:outline-none" + onClick={() => { + setVisited(true); + setOpen((value) => !value); + }} + className="text-text-primary focus-visible:ring-focus-control flex max-w-full items-start gap-1 rounded text-left text-sm focus-visible:ring-2 focus-visible:outline-none" > - {title} + + {title} +
+ setJumpUnavailable(!onJump(row))} + > +