Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🪄 fix: Hide Sole Tool Row Under Its Group Header (#16750)

Marco Beretta34279ca3330b
diff --git a/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx b/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx
index b1b5c042ea..405bfffacd 100644
--- a/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/BackgroundTaskCall.tsx
@@ -68,11 +68,13 @@ export default function BackgroundTaskCall({
() => (display?.kind === 'list' ? backgroundListGuidanceKeys(display) : []),
[display],
);
- const { showCode, toggleCode, expandRef, phase, hasContent } = useToolCallState({
+ const { showCode, toggleCode, expandRef, phase, hasContent, bare, rowRef } = useToolCallState({
initialProgress,
isSubmitting,
output,
hasInput: hasParams || (attachments?.length ?? 0) > 0,
+ panelReady: display != null,
+ keepRow: intent != null,
onExpand,
runStepStatus,
extraError: outcome === 'failed',
@@ -111,22 +113,25 @@ export default function BackgroundTaskCall({
<span className="sr-only" aria-live="polite" aria-atomic="true">
{announcedText}
</span>
- <div
- className={TOOL_ROW_CLASSES}
- data-testid="background-task-call"
- data-tool-call-id={toolCallId}
- >
- <ProgressText
- phase={phase}
- onClick={handleToggle}
- inProgressText={intent ?? localize('com_ui_background_tasks_checking')}
- finishedText={finishedText}
- durationMs={runStepDurationMs}
- icon={<ToolIcon type="background_tasks" isAnimating={phase === 'running'} />}
- hasInput={hasContent}
- isExpanded={showCode}
- />
- </div>
+ {!bare && (
+ <div
+ className={TOOL_ROW_CLASSES}
+ ref={rowRef}
+ data-testid="background-task-call"
+ data-tool-call-id={toolCallId}
+ >
+ <ProgressText
+ phase={phase}
+ onClick={handleToggle}
+ inProgressText={intent ?? localize('com_ui_background_tasks_checking')}
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ icon={<ToolIcon type="background_tasks" isAnimating={phase === 'running'} />}
+ hasInput={hasContent}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div
data-background-task-fold
data-expanded={showCode}
diff --git a/client/src/components/Chat/Messages/Content/Parts/BareStatus.tsx b/client/src/components/Chat/Messages/Content/Parts/BareStatus.tsx
new file mode 100644
index 0000000000..7745227bcd
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/BareStatus.tsx
@@ -0,0 +1,26 @@
+import { useContext } from 'react';
+import { LoneGroupContext, SoleToolContext } from '../disclosure';
+
+/**
+ * The settled outcome of a sole call, spoken after its row is gone. The row's
+ * text changes from the running label to the finished one, but a row that
+ * unmounts in the same render cannot announce that, and the group header keeps
+ * the tool's name. This region mounts with the card and stays, so the text it
+ * gains when the row leaves is announced; a card that mounts already settled
+ * (a restored message) starts with the text in place and says nothing.
+ *
+ * Only a call that can drop its row renders it, so a card with a row of its
+ * own never carries a second, empty live region.
+ */
+export default function BareStatus({ active, text }: { active: boolean; text: string }) {
+ const sole = useContext(SoleToolContext) === true;
+ const lone = useContext(LoneGroupContext);
+ if (!sole && !lone) {
+ return null;
+ }
+ return (
+ <span className="sr-only" role="status" aria-live="polite" aria-atomic="true">
+ {active ? text : ''}
+ </span>
+ );
+}
diff --git a/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx b/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx
index 06b30cf924..f953ecd617 100644
--- a/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx
@@ -18,6 +18,7 @@ import { AttachmentGroup } from './Attachment';
import { parseCommandOutput } from './command';
import { useToolCallIntent } from './intent';
import PtcToolTrace from './PtcToolTrace';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
@@ -120,16 +121,21 @@ export default function BashCall({
)
: null;
- const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput } = useToolCallState({
- initialProgress,
- isSubmitting,
- output,
- hasInput: !!command,
- onExpand,
- runStepStatus,
- extraError: backgroundFailed || result?.failed === true,
- extraCancelled: cancelledInBackground,
- });
+ /** The model-authored `intent` is the settled label too, and only the row
+ * renders it, so a call that carries one keeps its row. */
+ const intent = useToolCallIntent(args);
+ const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput, bare, rowRef } =
+ useToolCallState({
+ initialProgress,
+ isSubmitting,
+ output,
+ hasInput: !!command,
+ onExpand,
+ runStepStatus,
+ extraError: backgroundFailed || result?.failed === true,
+ extraCancelled: cancelledInBackground,
+ keepRow: backgroundHandle != null || intent != null,
+ });
const highlighted = useLazyHighlight(showCode ? command || undefined : undefined, 'bash');
const { ref: commandPaneRef, onScroll: onCommandPaneScroll } = useFollowScroll<HTMLDivElement>(
@@ -157,7 +163,6 @@ export default function BashCall({
* live label from the earliest delta — before the command exists and while
* it runs. It persists as the settled label too (completion is a UI state,
* not a tense change); the generic texts are the no-intent fallback. */
- const intent = useToolCallIntent(args);
const inProgressText = (() => {
if (intent != null) {
return intent;
@@ -171,41 +176,45 @@ export default function BashCall({
return localize('com_ui_running_command');
})();
+ const finishedText =
+ phase === 'cancelled'
+ ? localize('com_ui_cancelled')
+ : (backgroundFinishedText ?? intent ?? localize('com_ui_command_finished'));
+
return (
<>
- <div className={TOOL_ROW_CLASSES}>
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={inProgressText}
- finishedText={
- phase === 'cancelled'
- ? localize('com_ui_cancelled')
- : (backgroundFinishedText ?? intent ?? localize('com_ui_command_finished'))
- }
- /** A backgrounded call's run step closes when dispatch returns the
- * handle, so its duration is the dispatch time — showing it would
- * misstate a detached task's runtime as seconds. The handle check
- * covers the live card; the persisted `backgrounded` marker covers
- * the card after harvest replaces the handle with real stdout
- * (and after any reload), when no transient signal survives. */
- durationMs={
- backgroundHandle == null && backgrounded !== true ? runStepDurationMs : undefined
- }
- icon={
- <LangIcon
- lang="bash"
- className={cn(
- 'text-text-secondary size-4 shrink-0',
- phase === 'running' && 'animate-pulse',
- )}
- />
- }
- hasInput={!!command || hasOutput}
- isExpanded={showCode}
- verdict={verdict}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className={TOOL_ROW_CLASSES} ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={inProgressText}
+ finishedText={finishedText}
+ /** A backgrounded call's run step closes when dispatch returns the
+ * handle, so its duration is the dispatch time, and showing it would
+ * misstate a detached task's runtime as seconds. The handle check
+ * covers the live card; the persisted `backgrounded` marker covers
+ * the card after harvest replaces the handle with real stdout
+ * (and after any reload), when no transient signal survives. */
+ durationMs={
+ backgroundHandle == null && backgrounded !== true ? runStepDurationMs : undefined
+ }
+ icon={
+ <LangIcon
+ lang="bash"
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ />
+ }
+ hasInput={!!command || hasOutput}
+ isExpanded={showCode}
+ verdict={verdict}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
<div
diff --git a/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx b/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
index 693660f148..874744b6c8 100644
--- a/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/ExecuteCode.tsx
@@ -13,6 +13,7 @@ import { AttachmentGroup } from './Attachment';
import { useToolCallIntent } from './intent';
import { TOOL_ROW_CLASSES } from '../rows';
import PtcToolTrace from './PtcToolTrace';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import Stdout from './Stdout';
import { cn } from '~/utils';
@@ -117,16 +118,18 @@ export default function ExecuteCode({
)
: null;
- const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput } = useToolCallState({
- initialProgress,
- isSubmitting,
- output,
- hasInput: !!code,
- onExpand,
- runStepStatus,
- extraError: backgroundFailed,
- extraCancelled: cancelledInBackground,
- });
+ const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput, bare, rowRef } =
+ useToolCallState({
+ initialProgress,
+ isSubmitting,
+ output,
+ hasInput: !!code,
+ onExpand,
+ runStepStatus,
+ extraError: backgroundFailed,
+ extraCancelled: cancelledInBackground,
+ keepRow: backgroundHandle != null || intent != null,
+ });
const highlighted = useLazyHighlight(showCode ? code : undefined, lang);
const { ref: codePaneRef, onScroll: onCodePaneScroll } = useFollowScroll<HTMLPreElement>(
@@ -135,43 +138,47 @@ export default function ExecuteCode({
showCode,
);
+ const finishedText =
+ phase === 'cancelled'
+ ? localize('com_ui_cancelled')
+ : (backgroundFinishedText ?? intent ?? localize('com_ui_analyzing_finished'));
+
return (
<>
- <div className={TOOL_ROW_CLASSES}>
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={
- intent ??
- (sandboxStarting ? localize('com_ui_sandbox_starting') : localize('com_ui_analyzing'))
- }
- finishedText={
- phase === 'cancelled'
- ? localize('com_ui_cancelled')
- : (backgroundFinishedText ?? intent ?? localize('com_ui_analyzing_finished'))
- }
- /** A backgrounded call's run step closes when dispatch returns the
- * handle, so its duration is the dispatch time — showing it would
- * misstate a detached task's runtime as seconds. The handle check
- * covers the live card; the persisted `backgrounded` marker covers
- * the card after harvest replaces the handle with real stdout
- * (and after any reload), when no transient signal survives. */
- durationMs={
- backgroundHandle == null && backgrounded !== true ? runStepDurationMs : undefined
- }
- icon={
- <SquareTerminal
- className={cn(
- 'text-text-secondary size-4 shrink-0',
- phase === 'running' && 'animate-pulse',
- )}
- aria-hidden="true"
- />
- }
- hasInput={!!code?.length}
- isExpanded={showCode}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className={TOOL_ROW_CLASSES} ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={
+ intent ??
+ (sandboxStarting ? localize('com_ui_sandbox_starting') : localize('com_ui_analyzing'))
+ }
+ finishedText={finishedText}
+ /** A backgrounded call's run step closes when dispatch returns the
+ * handle, so its duration is the dispatch time, and showing it would
+ * misstate a detached task's runtime as seconds. The handle check
+ * covers the live card; the persisted `backgrounded` marker covers
+ * the card after harvest replaces the handle with real stdout
+ * (and after any reload), when no transient signal survives. */
+ durationMs={
+ backgroundHandle == null && backgrounded !== true ? runStepDurationMs : undefined
+ }
+ icon={
+ <SquareTerminal
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ aria-hidden="true"
+ />
+ }
+ hasInput={!!code?.length}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
<div
diff --git a/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx b/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
index c488018b77..47d8c5a5e6 100644
--- a/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/FileAuthoringCall.tsx
@@ -18,6 +18,7 @@ import { AttachmentGroup } from './Attachment';
import { langFromPath } from './ReadFileCall';
import { useToolCallIntent } from './intent';
import { TOOL_ROW_CLASSES } from '../rows';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
@@ -169,11 +170,15 @@ export default function FileAuthoringCall({
previewLang = fileLang;
}
- const { showCode, toggleCode, expandStyle, expandRef, phase } = useToolCallState({
+ const { showCode, toggleCode, expandStyle, expandRef, phase, bare, rowRef } = useToolCallState({
initialProgress,
isSubmitting,
output,
hasInput: !!filePath || !!preview,
+ /** An overwrite reads "Updated" on the row while the group header keeps the
+ * `create_file` name, so the row stays the only place that says it. */
+ panelReady: !!preview && !overwrote,
+ keepRow: intent != null,
onExpand,
runStepStatus,
});
@@ -194,37 +199,41 @@ export default function FileAuthoringCall({
finishedKey = overwrote ? 'com_ui_updated_file' : 'com_ui_created_file';
}
+ const finishedText =
+ phase === 'cancelled'
+ ? localize('com_ui_cancelled')
+ : (intent ?? localize(finishedKey, { 0: fileName }));
+
return (
<>
- <div className={TOOL_ROW_CLASSES}>
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={
- intent ??
- localize(isCreate ? 'com_ui_creating_file' : 'com_ui_editing_file', {
- 0: fileName,
- })
- }
- finishedText={
- phase === 'cancelled'
- ? localize('com_ui_cancelled')
- : (intent ?? localize(finishedKey, { 0: fileName }))
- }
- durationMs={runStepDurationMs}
- icon={
- <Icon
- className={cn(
- 'text-text-secondary size-4 shrink-0',
- phase === 'running' && 'animate-pulse',
- )}
- aria-hidden="true"
- />
- }
- hasInput={!!filePath || !!preview}
- isExpanded={showCode}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className={TOOL_ROW_CLASSES} ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={
+ intent ??
+ localize(isCreate ? 'com_ui_creating_file' : 'com_ui_editing_file', {
+ 0: fileName,
+ })
+ }
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ icon={
+ <Icon
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ aria-hidden="true"
+ />
+ }
+ hasInput={!!filePath || !!preview}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
{!!preview && (
diff --git a/client/src/components/Chat/Messages/Content/Parts/MemoryCall.tsx b/client/src/components/Chat/Messages/Content/Parts/MemoryCall.tsx
index 9b67b57e81..f9ddd21d8b 100644
--- a/client/src/components/Chat/Messages/Content/Parts/MemoryCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/MemoryCall.tsx
@@ -8,6 +8,7 @@ import useToolCallState from './useToolCallState';
import { AttachmentGroup } from './Attachment';
import parseJsonField from './parseJsonField';
import MemoryInfo from '../MemoryInfo';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
@@ -63,11 +64,12 @@ export default function MemoryCall({
}, [attachments]);
const memoryFailed = isMemoryFailureOutput(toolName, output) || memoryErrors.length > 0;
- const { showCode, toggleCode, expandStyle, expandRef, phase } = useToolCallState({
+ const { showCode, toggleCode, expandStyle, expandRef, phase, bare, rowRef } = useToolCallState({
initialProgress,
isSubmitting,
output,
hasInput: hasPanel || memoryFailed || runStepStatus === 'failed',
+ panelReady: hasPanel,
onExpand,
runStepStatus,
extraError: memoryFailed,
@@ -81,39 +83,42 @@ export default function MemoryCall({
return (
<>
- <div className="relative my-1 flex h-5 shrink-0 items-center gap-2.5">
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={localize(isSave ? 'com_ui_memory_saving' : 'com_ui_memory_deleting')}
- finishedText={finishedText}
- durationMs={runStepDurationMs}
- subtitle={memoryKey || undefined}
- icon={
- <Brain
- className={cn(
- 'size-4 shrink-0 text-text-secondary',
- phase === 'running' && 'animate-pulse',
- )}
- aria-hidden="true"
- />
- }
- hasInput={hasPanel || phase === 'failed'}
- isExpanded={showCode}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className="relative my-1 flex h-5 shrink-0 items-center gap-2.5" ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={localize(isSave ? 'com_ui_memory_saving' : 'com_ui_memory_deleting')}
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ subtitle={memoryKey || undefined}
+ icon={
+ <Brain
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ aria-hidden="true"
+ />
+ }
+ hasInput={hasPanel || phase === 'failed'}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
{(hasPanel || phase === 'failed') && (
<div
className={cn(
toolPanelSpacingClassName,
- 'overflow-hidden rounded-lg border border-border-light bg-surface-secondary p-3',
+ 'border-border-light bg-surface-secondary overflow-hidden rounded-lg border p-3',
)}
>
{phase === 'failed' ? (
<>
- <pre className="whitespace-pre-wrap break-words font-mono text-xs text-status-error">
+ <pre className="text-status-error font-mono text-xs break-words whitespace-pre-wrap">
{output}
</pre>
<MemoryInfo memoryArtifacts={memoryErrors} />
@@ -121,12 +126,12 @@ export default function MemoryCall({
) : (
<>
{memoryKey && (
- <div className="mb-1 text-xs font-bold uppercase tracking-wide text-text-secondary">
+ <div className="text-text-secondary mb-1 text-xs font-bold tracking-wide uppercase">
{memoryKey}
</div>
)}
{isSave && memoryValue && (
- <div className="whitespace-pre-wrap text-sm text-text-primary">
+ <div className="text-text-primary text-sm whitespace-pre-wrap">
{memoryValue}
</div>
)}
@@ -136,7 +141,7 @@ export default function MemoryCall({
claimed the memory was gone while the header said
Cancelled. The key above already shows what was tried. */}
{!isSave && phase === 'completed' && (
- <div className="text-sm italic text-text-secondary">
+ <div className="text-text-secondary text-sm italic">
{localize('com_ui_memory_deleted')}
</div>
)}
diff --git a/client/src/components/Chat/Messages/Content/Parts/ReadFileCall.tsx b/client/src/components/Chat/Messages/Content/Parts/ReadFileCall.tsx
index 1955d445d7..7246391179 100644
--- a/client/src/components/Chat/Messages/Content/Parts/ReadFileCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/ReadFileCall.tsx
@@ -10,6 +10,7 @@ import { AttachmentGroup } from './Attachment';
import parseJsonField from './parseJsonField';
import { useToolCallIntent } from './intent';
import { TOOL_ROW_CLASSES } from '../rows';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
@@ -94,43 +95,50 @@ export default function ReadFileCall({
const fileName = filePath.split('/').pop() || filePath;
const lang = useMemo(() => langFromPath(filePath), [filePath]);
- const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput } = useToolCallState({
- initialProgress,
- isSubmitting,
- output,
- hasInput: !!filePath,
- onExpand,
- runStepStatus,
- });
+ const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput, bare, rowRef } =
+ useToolCallState({
+ initialProgress,
+ isSubmitting,
+ output,
+ hasInput: !!filePath,
+ panelReady: output.length > 0,
+ keepRow: intent != null,
+ onExpand,
+ runStepStatus,
+ });
const highlighted = useLazyHighlight(showCode && hasOutput ? output : undefined, lang);
+ const finishedText =
+ phase === 'cancelled'
+ ? localize('com_ui_cancelled')
+ : (intent ?? localize('com_ui_read_file', { 0: fileName }));
+
return (
<>
- <div className={TOOL_ROW_CLASSES}>
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={intent ?? localize('com_ui_reading_file', { 0: fileName })}
- finishedText={
- phase === 'cancelled'
- ? localize('com_ui_cancelled')
- : (intent ?? localize('com_ui_read_file', { 0: fileName }))
- }
- durationMs={runStepDurationMs}
- icon={
- <FileText
- className={cn(
- 'text-text-secondary size-4 shrink-0',
- phase === 'running' && 'animate-pulse',
- )}
- aria-hidden="true"
- />
- }
- hasInput={!!filePath || hasOutput}
- isExpanded={showCode}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className={TOOL_ROW_CLASSES} ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={intent ?? localize('com_ui_reading_file', { 0: fileName })}
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ icon={
+ <FileText
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ aria-hidden="true"
+ />
+ }
+ hasInput={!!filePath || hasOutput}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
{hasOutput && (
diff --git a/client/src/components/Chat/Messages/Content/Parts/SkillCall.tsx b/client/src/components/Chat/Messages/Content/Parts/SkillCall.tsx
index 635c2050b1..1bd4965e22 100644
--- a/client/src/components/Chat/Messages/Content/Parts/SkillCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/SkillCall.tsx
@@ -8,6 +8,7 @@ import { AttachmentGroup } from './Attachment';
import parseJsonField from './parseJsonField';
import { useToolCallIntent } from './intent';
import { TOOL_ROW_CLASSES } from '../rows';
+import BareStatus from './BareStatus';
import { useLocalize } from '~/hooks';
import Stdout from './Stdout';
import { cn } from '~/utils';
@@ -38,41 +39,48 @@ export default function SkillCall({
const skillName = parsedSkillName || localize('com_ui_skill').toLowerCase();
const intent = useToolCallIntent(args);
- const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput } = useToolCallState({
- initialProgress,
- isSubmitting,
- output,
- hasInput: !!parsedSkillName,
- onExpand,
- runStepStatus,
- });
+ const { showCode, toggleCode, expandStyle, expandRef, phase, hasOutput, bare, rowRef } =
+ useToolCallState({
+ initialProgress,
+ isSubmitting,
+ output,
+ hasInput: !!parsedSkillName,
+ /** The row is the only place that names the skill that ran. */
+ keepRow: true,
+ onExpand,
+ runStepStatus,
+ });
+
+ const finishedText =
+ phase === 'cancelled'
+ ? localize('com_ui_cancelled')
+ : (intent ?? localize('com_ui_skill_finished', { 0: skillName }));
return (
<>
- <div className={TOOL_ROW_CLASSES}>
- <ProgressText
- phase={phase}
- onClick={toggleCode}
- inProgressText={intent ?? localize('com_ui_skill_running', { 0: skillName })}
- finishedText={
- phase === 'cancelled'
- ? localize('com_ui_cancelled')
- : (intent ?? localize('com_ui_skill_finished', { 0: skillName }))
- }
- durationMs={runStepDurationMs}
- icon={
- <ScrollText
- className={cn(
- 'text-text-secondary size-4 shrink-0',
- phase === 'running' && 'animate-pulse',
- )}
- aria-hidden="true"
- />
- }
- hasInput={!!parsedSkillName || hasOutput}
- isExpanded={showCode}
- />
- </div>
+ <BareStatus active={bare} text={finishedText} />
+ {!bare && (
+ <div className={TOOL_ROW_CLASSES} ref={rowRef}>
+ <ProgressText
+ phase={phase}
+ onClick={toggleCode}
+ inProgressText={intent ?? localize('com_ui_skill_running', { 0: skillName })}
+ finishedText={finishedText}
+ durationMs={runStepDurationMs}
+ icon={
+ <ScrollText
+ className={cn(
+ 'text-text-secondary size-4 shrink-0',
+ phase === 'running' && 'animate-pulse',
+ )}
+ aria-hidden="true"
+ />
+ }
+ hasInput={!!parsedSkillName || hasOutput}
+ isExpanded={showCode}
+ />
+ </div>
+ )}
<div style={expandStyle}>
<div className="overflow-hidden" ref={expandRef}>
{hasOutput && (
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx
index f8f6635d04..0960cd1a8f 100644
--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx
@@ -2,8 +2,7 @@ import React from 'react';
import { RecoilRoot } from 'recoil';
import copy from 'copy-to-clipboard';
import { render, screen, fireEvent } from '@testing-library/react';
-import type { ToolDisclosures } from '../../disclosure';
-import { SoleToolContext, ToolDisclosureContext, ToolDisclosureKeyContext } from '../../disclosure';
+import { LoneGroupContext, SoleToolContext } from '../../disclosure';
import BashCall from '../BashCall';
import store from '~/store';
@@ -353,6 +352,104 @@ describe('BashCall sole tool disclosure', () => {
expect(panel(container).style.gridTemplateRows).toBe('0fr');
});
+ it('drops its own row when it is the only call, so the output follows the group header', () => {
+ renderCall(true);
+ expect(screen.queryByTestId('progress-text')).not.toBeInTheDocument();
+ expect(screen.getByText('hi')).toBeInTheDocument();
+ });
+
+ it('keeps its row when it is one of several calls', () => {
+ renderCall(false);
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+
+ it('keeps its row when the call carries a model-authored intent', () => {
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value>
+ <BashCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ intent: 'Check the build', command: 'echo hi' }}
+ output="hi"
+ runStepStatus="completed"
+ />
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Check the build');
+ });
+
+ it('drops its row when its group holds one call inside a phase of several', () => {
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value={false}>
+ <LoneGroupContext.Provider value>
+ <BashCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ command: 'echo hi' }}
+ output="hi"
+ runStepStatus="completed"
+ />
+ </LoneGroupContext.Provider>
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ expect(screen.queryByTestId('progress-text')).not.toBeInTheDocument();
+ expect(screen.getByText('hi')).toBeInTheDocument();
+ });
+
+ it('keeps its row while the only call is still running', () => {
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value>
+ <BashCall initialProgress={0.5} isSubmitting args={{ command: 'sleep 5' }} output="" />
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Running command');
+ });
+
+ it('keeps its row when the only call failed, so the failure stays reachable', () => {
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value>
+ <BashCall
+ initialProgress={1}
+ isSubmitting={false}
+ executor="attached_workspace"
+ args={{ command: 'false' }}
+ output={'stderr:\nboom\n\n[exit code: 1]'}
+ />
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('progress-text')).toHaveTextContent('tool failed');
+ });
+
+ it('keeps its row for a detached task whose dispatch step has closed', () => {
+ const handle = JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ });
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value>
+ <BashCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ command: 'sleep 600' }}
+ output={handle}
+ />
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Running in background');
+ });
+
it('closes the card again when its group gains a second call', () => {
const { container, rerender } = renderCall(true);
expect(panel(container).style.gridTemplateRows).toBe('1fr');
@@ -370,32 +467,6 @@ describe('BashCall sole tool disclosure', () => {
);
expect(panel(container).style.gridTemplateRows).toBe('0fr');
});
-
- it('keeps a closed sole card closed when it remounts under a new group', () => {
- const disclosures: ToolDisclosures = new Map();
- const tree = () => (
- <RecoilRoot>
- <ToolDisclosureContext.Provider value={disclosures}>
- <ToolDisclosureKeyContext.Provider value="call-1">
- <SoleToolContext.Provider value>
- <BashCall
- initialProgress={1}
- isSubmitting={false}
- args={{ command: 'echo hi' }}
- output="hi"
- />
- </SoleToolContext.Provider>
- </ToolDisclosureKeyContext.Provider>
- </ToolDisclosureContext.Provider>
- </RecoilRoot>
- );
- const first = render(tree());
- fireEvent.click(first.getByTestId('progress-text'));
- expect(panel(first.container).style.gridTemplateRows).toBe('0fr');
- first.unmount();
- const second = render(tree());
- expect(panel(second.container).style.gridTemplateRows).toBe('0fr');
- });
});
/**
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleFocus.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleFocus.test.tsx
new file mode 100644
index 0000000000..aebb455c1a
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleFocus.test.tsx
@@ -0,0 +1,96 @@
+import React from 'react';
+import { RecoilRoot } from 'recoil';
+import { act, render, screen } from '@testing-library/react';
+import { SoleToolContext } from '../../disclosure';
+import BashCall from '../BashCall';
+
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useProgress: (initialProgress: number) => initialProgress,
+ useExpandCollapse: (isExpanded: boolean) => ({
+ style: { display: 'grid', gridTemplateRows: isExpanded ? '1fr' : '0fr' },
+ ref: { current: null },
+ }),
+}));
+
+jest.mock('~/components/Chat/Messages/Content/ProgressText', () => ({
+ __esModule: true,
+ default: ({ onClick, finishedText }: { onClick?: () => void; finishedText: string }) => (
+ <button type="button" data-testid="progress-text" onClick={onClick}>
+ {finishedText}
+ </button>
+ ),
+}));
+
+const tree = (settled: boolean, announcer = false) => (
+ <RecoilRoot>
+ <input data-testid="outside" />
+ <div data-fold-root="">
+ {announcer && <span role="status" data-testid="announcer" />}
+ <div className="flex">
+ <button type="button" data-testid="group-header">
+ {'Group'}
+ </button>
+ </div>
+ <SoleToolContext.Provider value>
+ <BashCall
+ initialProgress={settled ? 1 : 0.5}
+ isSubmitting={!settled}
+ args={{ command: 'echo hi' }}
+ output={settled ? 'hi' : ''}
+ runStepStatus={settled ? 'completed' : undefined}
+ />
+ </SoleToolContext.Provider>
+ </div>
+ </RecoilRoot>
+);
+
+describe('a sole call that drops its row on completion', () => {
+ it('hands keyboard focus to the group header when the focused row goes away', () => {
+ const { rerender } = render(tree(false));
+ act(() => screen.getByTestId('progress-text').focus());
+ expect(screen.getByTestId('progress-text')).toHaveFocus();
+
+ rerender(tree(true));
+
+ expect(screen.queryByTestId('progress-text')).not.toBeInTheDocument();
+ expect(screen.getByTestId('group-header')).toHaveFocus();
+ });
+
+ it('finds the header when the fold root leads with a screen-reader announcer', () => {
+ const { rerender } = render(tree(false, true));
+ act(() => screen.getByTestId('progress-text').focus());
+
+ rerender(tree(true, true));
+
+ expect(screen.getByTestId('group-header')).toHaveFocus();
+ });
+
+ it('leaves focus alone when it was somewhere else', () => {
+ const { rerender } = render(tree(false));
+ act(() => screen.getByTestId('outside').focus());
+
+ rerender(tree(true));
+
+ expect(screen.getByTestId('outside')).toHaveFocus();
+ });
+
+ it('leaves focus alone when the row was never focused', () => {
+ const { rerender } = render(tree(false));
+
+ rerender(tree(true));
+
+ expect(screen.getByTestId('group-header')).not.toHaveFocus();
+ });
+
+ it('announces the settled outcome through a live region that outlives the row', () => {
+ const { container, rerender } = render(tree(false));
+ const region = () => container.querySelector('[aria-live="polite"]');
+ expect(region()).toBeInTheDocument();
+ expect(region()).toHaveTextContent('');
+
+ rerender(tree(true));
+
+ expect(region()).toHaveTextContent('com_ui_command_finished');
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleRow.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleRow.test.tsx
new file mode 100644
index 0000000000..78c3b99501
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/SoleRow.test.tsx
@@ -0,0 +1,140 @@
+import React from 'react';
+import { RecoilRoot } from 'recoil';
+import { render, screen } from '@testing-library/react';
+import FileAuthoringCall from '../FileAuthoringCall';
+import { SoleToolContext } from '../../disclosure';
+import ReadFileCall from '../ReadFileCall';
+import MemoryCall from '../MemoryCall';
+import SkillCall from '../SkillCall';
+
+jest.mock('~/hooks', () => ({
+ useLocalize: () => (key: string) => key,
+ useProgress: (initialProgress: number) => initialProgress,
+ useExpandCollapse: (isExpanded: boolean) => ({
+ style: { display: 'grid', gridTemplateRows: isExpanded ? '1fr' : '0fr' },
+ ref: { current: null },
+ }),
+}));
+
+jest.mock('~/components/Chat/Messages/Content/ProgressText', () => ({
+ __esModule: true,
+ default: ({ finishedText }: { finishedText: string }) => (
+ <div data-testid="progress-text">{finishedText}</div>
+ ),
+}));
+
+const renderSole = (ui: React.ReactElement, sole = true) =>
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value={sole}>{ui}</SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+
+describe('a sole call keeps its row when its panel would be empty', () => {
+ it('ReadFileCall: an empty file still shows the file name row', () => {
+ renderSole(
+ <ReadFileCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ path: 'src/empty.ts' }}
+ output=""
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+
+ it('ReadFileCall: drops the row once there is output to show', () => {
+ renderSole(
+ <ReadFileCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ path: 'src/a.ts' }}
+ output="const a = 1;"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.queryByTestId('progress-text')).not.toBeInTheDocument();
+ });
+
+ it('ReadFileCall: keeps the row that carries the model-authored intent', () => {
+ renderSole(
+ <ReadFileCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ intent: 'Check the config', path: 'src/a.ts' }}
+ output="const a = 1;"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Check the config');
+ });
+
+ it('FileAuthoringCall: a create that overwrote a file keeps the row naming the update', () => {
+ renderSole(
+ <FileAuthoringCall
+ toolName="create_file"
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ path: 'src/a.ts', content: 'x' }}
+ output="Updated src/a.ts"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+
+ it('FileAuthoringCall: a fresh create drops the row once there is a preview', () => {
+ renderSole(
+ <FileAuthoringCall
+ toolName="create_file"
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ path: 'src/a.ts', content: 'x' }}
+ output="Created src/a.ts"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.queryByTestId('progress-text')).not.toBeInTheDocument();
+ });
+
+ it('MemoryCall: output with no parseable key or value keeps its row', () => {
+ renderSole(
+ <MemoryCall
+ toolName="set_memory"
+ initialProgress={1}
+ isSubmitting={false}
+ args="{}"
+ output="Memory saved"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+
+ it('SkillCall: a named skill keeps its row so the skill name stays visible', () => {
+ renderSole(
+ <SkillCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ skillName: 'pdf' }}
+ output="loaded"
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+
+ it('SkillCall: a named skill with empty output keeps its row', () => {
+ renderSole(
+ <SkillCall
+ initialProgress={1}
+ isSubmitting={false}
+ args={{ skillName: 'pdf' }}
+ output=""
+ runStepStatus="completed"
+ />,
+ );
+ expect(screen.getByTestId('progress-text')).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/Chat/Messages/Content/Parts/useToolCallState.ts b/client/src/components/Chat/Messages/Content/Parts/useToolCallState.ts
index 98ef27288f..aeb4a695cc 100644
--- a/client/src/components/Chat/Messages/Content/Parts/useToolCallState.ts
+++ b/client/src/components/Chat/Messages/Content/Parts/useToolCallState.ts
@@ -1,10 +1,11 @@
-import { useCallback } from 'react';
+import { useCallback, useContext } from 'react';
import type { PartMetadata } from 'librechat-data-provider';
import type { ToolCallPhase } from '~/utils/toolCallPhase';
+import { LoneGroupContext, SoleToolContext, useToolExpansion } from '../disclosure';
import { isError } from '~/components/Chat/Messages/Content/ToolOutput';
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
import { useProgress, useExpandCollapse } from '~/hooks';
-import { useToolExpansion } from '../disclosure';
+import useRowHandoff from '../handoff';
interface ToolCallState {
showCode: boolean;
@@ -19,6 +20,11 @@ interface ToolCallState {
phase: ToolCallPhase;
hasOutput: boolean;
hasContent: boolean;
+ /** Goes on the card's row so focus can follow it out. */
+ rowRef: (node: HTMLElement | null) => void;
+ /** The only call of its group, with a panel to show: the group header is
+ * already the row, so the card renders its panel alone, held open. */
+ bare: boolean;
}
export interface UseToolCallStateInput {
@@ -40,6 +46,13 @@ export interface UseToolCallStateInput {
* cancelled ordinary background tool. Cancellation outranks error-shaped
* output so the card never relabels an intentional stop as failure. */
extraCancelled?: boolean;
+ /** Keep the card's own row even as the only call, for a state its phase does
+ * not carry (a detached task still running after its dispatch step closed). */
+ keepRow?: boolean;
+ /** Whether the panel has a body to show. Defaults to `hasContent`; a card
+ * whose panel needs more than its input (a read file's output) passes its
+ * own, so a sole call never loses its row to an empty panel. */
+ panelReady?: boolean;
}
export default function useToolCallState({
@@ -51,13 +64,12 @@ export default function useToolCallState({
runStepStatus,
extraError = false,
extraCancelled = false,
+ keepRow = false,
+ panelReady,
}: UseToolCallStateInput): ToolCallState {
const hasOutput = output.length > 0;
const hasContent = hasInput || hasOutput;
- const [showCode, setExpansionOverride] = useToolExpansion(hasContent);
- const { style: expandStyle, ref: expandRef } = useExpandCollapse(showCode);
-
const isClosed = runStepStatus != null;
/**
* Passing 1 in for a closed step stops `useProgress` scheduling its 200ms
@@ -67,13 +79,6 @@ export default function useToolCallState({
* 0.99 can no longer read as in-flight.
*/
const rawProgress = useProgress(isClosed ? 1 : initialProgress);
- const toggleCode = useCallback(() => {
- const next = !showCode;
- setExpansionOverride(next);
- if (next) {
- onExpand?.();
- }
- }, [onExpand, setExpansionOverride, showCode]);
/**
* One resolution; everything the card shows is a read of this value. The
@@ -88,6 +93,25 @@ export default function useToolCallState({
hasError: (hasOutput && isError(output)) || extraError,
});
+ /** The only call of its group, settled successfully: the group header is
+ * already the row, so the card renders its panel alone, held open. While it
+ * runs, or once it failed or was stopped, the row is the only place that
+ * says so, and `keepRow` covers a state the phase cannot express. */
+ const lone = useContext(LoneGroupContext);
+ const solo = useContext(SoleToolContext) === true || lone;
+ const bare = solo && (panelReady ?? hasContent) && phase === 'completed' && !keepRow;
+ const [expanded, setExpansionOverride] = useToolExpansion(hasContent);
+ const showCode = bare || expanded;
+ const { style: expandStyle, ref: expandRef } = useExpandCollapse(showCode);
+ const rowRef = useRowHandoff(bare);
+ const toggleCode = useCallback(() => {
+ const next = !showCode;
+ setExpansionOverride(next);
+ if (next) {
+ onExpand?.();
+ }
+ }, [onExpand, setExpansionOverride, showCode]);
+
return {
showCode,
toggleCode,
@@ -96,5 +120,7 @@ export default function useToolCallState({
phase,
hasOutput,
hasContent,
+ rowRef,
+ bare,
};
}
diff --git a/client/src/components/Chat/Messages/Content/ToolCall.tsx b/client/src/components/Chat/Messages/Content/ToolCall.tsx
index 23fbbe9af9..e02114abb0 100644
--- a/client/src/components/Chat/Messages/Content/ToolCall.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolCall.tsx
@@ -8,11 +8,16 @@ import {
splitToolCallName,
} from 'librechat-data-provider';
import type { TAttachment, PartMetadata } from 'librechat-data-provider';
-import { toolPanelSpacingClassName, useToolExpansion, SoleToolContext } from './disclosure';
+import {
+ toolPanelSpacingClassName,
+ useToolExpansion,
+ LoneGroupContext,
+ SoleToolContext,
+} from './disclosure';
import { useLocalize, useProgress, useExpandCollapse, useLazyCollapseBody } from '~/hooks';
+import { ToolIcon, getToolIconType, isError, hasRenderableOutput } from './ToolOutput';
import { cn, getToolDisplayLabel, logger, openInNewTab } from '~/utils';
import { isToolCallPreparing, useToolPreparation } from './preparation';
-import { ToolIcon, getToolIconType, isError } from './ToolOutput';
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
import { resolveToolCallPhase } from '~/utils/toolCallPhase';
import { MCPAppViews } from '~/components/MCPUIResource';
@@ -21,8 +26,10 @@ import { AttachmentGroup } from './Parts';
import ToolCallInfo from './ToolCallInfo';
import ProgressText from './ProgressText';
import { TOOL_ROW_CLASSES } from './rows';
+import { hasToolParams } from './params';
import { ToolAuthWarning } from './auth';
import { firstErrorLine } from './live';
+import useRowHandoff from './handoff';
export default function ToolCall({
initialProgress = 0.1,
@@ -193,10 +200,6 @@ export default function ToolCall({
/** The preference opens a card once it has output; a sole call opens on
* its arguments too, so a call that returned nothing still shows them. */
const soleTool = useContext(SoleToolContext) === true;
- const [showInfo, setShowInfo] = useToolExpansion(soleTool ? hasInfo : (output?.length ?? 0) > 0);
- const { style: expandStyle, ref: expandRef } = useExpandCollapse(showInfo);
- const { shouldRenderBody, mountBody, handleTransitionEnd } = useLazyCollapseBody(showInfo);
-
const authDomain = useMemo(() => {
return parsedAuthUrl?.hostname ?? '';
}, [parsedAuthUrl]);
@@ -222,6 +225,31 @@ export default function ToolCall({
});
const showOAuth = Boolean(auth) && phase === 'running';
+ const [expandedInfo, setShowInfo] = useToolExpansion(
+ soleTool ? hasInfo : (output?.length ?? 0) > 0,
+ );
+ /** The only call of its group, settled successfully: the group header is the
+ * row, so the panel stands alone and stays open. An MCP or action call keeps
+ * its row, the only place its function name and domain appear, as does a call
+ * with a model-authored intent. */
+ const intent = useToolCallIntent(_args);
+ const isActionCall = domain != null && domain !== '';
+ const loneGroup = useContext(LoneGroupContext);
+ /** The cheap, identity and phase checks run first: a streaming call re-renders
+ * on every argument delta, and the panel check parses its payload. */
+ const bare =
+ phase === 'completed' &&
+ (soleTool || loneGroup) &&
+ !isMCPToolCall &&
+ !isActionCall &&
+ intent == null &&
+ hasInfo &&
+ (hasToolParams(args) || hasRenderableOutput(output));
+ const showInfo = bare || expandedInfo;
+ const { style: expandStyle, ref: expandRef } = useExpandCollapse(showInfo);
+ const rowRef = useRowHandoff(bare);
+ const { shouldRenderBody, mountBody, handleTransitionEnd } = useLazyCollapseBody(showInfo);
+
/**
* Binds when the sign-in prompt appears instead of on tap, so the tap opens the provider
* synchronously: an iOS home-screen app drops a tab opened after an awaited request. The button
@@ -315,7 +343,6 @@ export default function ToolCall({
/** Model-authored live label, streamed as the first args key (injected by
* the `tool_intents` capability); persists as the settled label —
* completion is a UI state, not a tense change. */
- const intent = useToolCallIntent(_args);
const preparationText = useToolPreparation();
const preparing = useMemo(
() =>
@@ -401,29 +428,40 @@ export default function ToolCall({
return getFinishedText();
})()}
</span>
- <div className={TOOL_ROW_CLASSES} data-testid="tool-call" data-tool-call-id={toolCallId}>
- <ProgressText
- phase={phase}
- onClick={handleToggleInfo}
- inProgressText={inProgressText}
- authText={
- phase === 'running' && authDomain.length > 0
- ? localize('com_ui_requires_auth')
- : undefined
- }
- finishedText={getFinishedText()}
- subtitle={subtitle}
- durationMs={runStepDurationMs}
- toolPreparationDurationMs={toolPreparationDurationMs}
- toolExecutionDurationMs={toolExecutionDurationMs}
- phaseStartAt={toolDispatchedAt ?? toolPreparationStartedAt}
- icon={
- <ToolIcon type={toolIconType} iconUrl={mcpIconUrl} isAnimating={phase === 'running'} />
- }
- hasInput={hasInfo}
- isExpanded={showInfo}
- />
- </div>
+ {!bare && (
+ <div
+ className={TOOL_ROW_CLASSES}
+ ref={rowRef}
+ data-testid="tool-call"
+ data-tool-call-id={toolCallId}
+ >
+ <ProgressText
+ phase={phase}
+ onClick={handleToggleInfo}
+ inProgressText={inProgressText}
+ authText={
+ phase === 'running' && authDomain.length > 0
+ ? localize('com_ui_requires_auth')
+ : undefined
+ }
+ finishedText={getFinishedText()}
+ subtitle={subtitle}
+ durationMs={runStepDurationMs}
+ toolPreparationDurationMs={toolPreparationDurationMs}
+ toolExecutionDurationMs={toolExecutionDurationMs}
+ phaseStartAt={toolDispatchedAt ?? toolPreparationStartedAt}
+ icon={
+ <ToolIcon
+ type={toolIconType}
+ iconUrl={mcpIconUrl}
+ isAnimating={phase === 'running'}
+ />
+ }
+ hasInput={hasInfo}
+ isExpanded={showInfo}
+ />
+ </div>
+ )}
<div
style={expandStyle}
onTransitionEnd={handleTransitionEnd}
diff --git a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
index b28f2800e2..3af780ebf5 100644
--- a/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolCallGroup.tsx
@@ -31,13 +31,14 @@ import {
import { useLocalize, useExpandCollapse, scheduleMessageContentLayoutReconcile } from '~/hooks';
import { ASK_USER_QUESTION, getSubmittedAskAnswer } from '~/utils/approval';
import { ToolAuthWarning, ToolAuthWarningContext } from './auth';
+import { LoneGroupContext, SoleToolContext } from './disclosure';
import { useMCPIconMap, useMCPServerNames } from '~/hooks/MCP';
import { AttachmentGroup, ReasoningCompact } from './Parts';
import { getOutcomeStatus, summarizeSpan } from './outcome';
import { FOLD_RAIL_CLASSES, ROW_GLYPH_SLOT } from './rows';
import { MCPAppViews } from '~/components/MCPUIResource';
+import { parseToolName } from '~/utils/toolLabels';
import { StackedToolIcons } from './ToolOutput';
-import { SoleToolContext } from './disclosure';
import { mapAttachments } from '~/utils/map';
import { getSourceDomains } from './sources';
import SearchVerticals from './verticals';
@@ -141,9 +142,25 @@ export default function ToolCallGroup({
const labelSettled =
activityLabelText.length > 0 &&
(labelPart?.part as { pending?: boolean } | undefined)?.pending !== true;
+ /** A detached task's dispatch step closes with a handle as its output, so
+ * the call reads as done while the work is still going. Only the code
+ * cards interpret that handle and say "Running in background"; a generic
+ * MCP or action row reports the closed step as ran, and the header must
+ * not contradict the row it sits above. */
+ const detachedRunning = useMemo(
+ () =>
+ toolMetadata.some(
+ (m) =>
+ m.background === 'running' &&
+ !m.cancelled &&
+ !m.failed &&
+ parseToolName(m.name, mcpServerNames).friendlyKey === 'com_ui_tool_name_code',
+ ),
+ [toolMetadata, mcpServerNames],
+ );
const allCompleted = useMemo(
- () => labelSettled || toolMetadata.every((m) => m.hasOutput === true),
- [toolMetadata, labelSettled],
+ () => !detachedRunning && (labelSettled || toolMetadata.every((m) => m.hasOutput === true)),
+ [toolMetadata, labelSettled, detachedRunning],
);
const sourceDomains = useMemo(
() => getSourceDomains(sourceAttachments ?? groupAttachments, 3),
@@ -281,7 +298,9 @@ export default function ToolCallGroup({
/** Past tense once the turn is settled — matches the Asking/Asked record
* card. While a multi-question turn streams, the still-open question's
* tool_call part has no output yet, so keep the present tense. */
- const groupDone = allCompleted || !isSubmitting;
+ /** A detached task keeps the group in the running tense after the response
+ * ends: its handle is the call's output, but the work is still going. */
+ const groupDone = (allCompleted || !isSubmitting) && !detachedRunning;
const askQuestionsDone = allAskQuestions && (groupDone || askQuestionsAnswered);
/** One verdict for the header's tense, its glyph and its icon animation —
@@ -291,6 +310,9 @@ export default function ToolCallGroup({
/** For a single-tool group, lead with the tool's own (capitalized) label
* instead of the generic "Used 1 tool: name", which reads awkwardly. */
+ const singleToolIsCode =
+ toolMetadata[0]?.name != null &&
+ parseToolName(toolMetadata[0].name, mcpServerNames).friendlyKey === 'com_ui_tool_name_code';
const singleToolLabel = useMemo(() => {
const raw = getToolDisplayLabel(toolMetadata[0]?.name ?? '', localize, mcpServerNames);
return raw ? raw.charAt(0).toUpperCase() + raw.slice(1) : '';
@@ -344,6 +366,19 @@ export default function ToolCallGroup({
useEffect(() => {
if (autoCollapse && !userOverride) {
+ /** A row that held focus goes inert with the collapse, so focus moves to
+ * the header first rather than falling to the document. */
+ const header = headerRef.current?.querySelector<HTMLElement>('button');
+ const active = document.activeElement;
+ if (
+ header != null &&
+ active != null &&
+ active !== header &&
+ rootRef.current?.contains(active) === true &&
+ !headerRef.current?.contains(active)
+ ) {
+ header.focus();
+ }
setIsExpanded(false);
}
}, [autoCollapse, userOverride]);
@@ -479,6 +514,37 @@ export default function ToolCallGroup({
);
}
if (count === 1) {
+ /** A bare "Code" reads as a category, not as what the call is doing, so
+ * the code tool says the verb its live row says. Other tools already
+ * name an action ("Create File"). */
+ if (singleToolLabel && singleToolIsCode) {
+ /** Only a success signal earns "Ran": a detached task's output is its
+ * handle, a stopped or failed call did not run to the end, and a
+ * legacy record that was cut off has no output to show for it. */
+ const only = toolMetadata[0];
+ const rawCall = parts.find(({ part }) => part.type === ContentTypes.TOOL_CALL)?.part;
+ const legacyCall =
+ rawCall?.type === ContentTypes.TOOL_CALL
+ ? (rawCall[ContentTypes.TOOL_CALL] as { runStepStatus?: unknown; progress?: number })
+ : undefined;
+ /** The card infers a stop from a legacy record with no step status whose
+ * progress never reached 1 once the stream is over, and `Part` supplies
+ * 0.1 when the field is absent; the metadata does not. */
+ const interrupted =
+ !isSubmitting && legacyCall?.runStepStatus == null && (legacyCall?.progress ?? 0.1) < 1;
+ if (only?.failed) {
+ return localize('com_ui_failed_subject', { 0: singleToolLabel });
+ }
+ if (only?.cancelled || interrupted) {
+ return localize('com_ui_cancelled');
+ }
+ if (!groupDone) {
+ return localize('com_assistants_running_var', { 0: singleToolLabel });
+ }
+ return only?.hasOutput
+ ? localize('com_assistants_completed_function', { 0: singleToolLabel })
+ : singleToolLabel;
+ }
return singleToolLabel || localize('com_ui_used_one_tool');
}
return localize(groupDone ? 'com_ui_ran_n_actions' : 'com_ui_running_n_actions', {
@@ -656,57 +722,60 @@ export default function ToolCallGroup({
/>
<ToolAuthWarningContext.Provider value>
<FailedRevealContext.Provider value={revealValue}>
- <SoleToolContext.Provider value={phaseSole ?? count === 1}>
- <div className="flex flex-col py-0.5">
- {parts.map(({ part, idx }, partIndex) => {
- if (part.type === ContentTypes.THINK) {
- const think = part.think;
- const reasoning = typeof think === 'string' ? think : (think?.value ?? '');
- /** A detached-subagent projection carries an empty THINK
- * part flagged `reasoning_unavailable`, which `Part`
- * renders as a `ReasoningMarker`. `ReasoningCompact` has
- * no text to show and returns null, so the marker has to
- * keep going through the standalone path or it vanishes
- * the moment its call joins a group. */
- if (reasoning.trim() === '' && part.reasoning_unavailable === true) {
- return renderPart(
- part,
- idx,
- isLast && idx === lastContentIdx,
- handleToolExpand,
+ <LoneGroupContext.Provider value={count === 1}>
+ <SoleToolContext.Provider value={phaseSole ?? count === 1}>
+ <div className="flex flex-col py-0.5">
+ {parts.map(({ part, idx }, partIndex) => {
+ if (part.type === ContentTypes.THINK) {
+ const think = part.think;
+ const reasoning =
+ typeof think === 'string' ? think : (think?.value ?? '');
+ /** A detached-subagent projection carries an empty THINK
+ * part flagged `reasoning_unavailable`, which `Part`
+ * renders as a `ReasoningMarker`. `ReasoningCompact` has
+ * no text to show and returns null, so the marker has to
+ * keep going through the standalone path or it vanishes
+ * the moment its call joins a group. */
+ if (reasoning.trim() === '' && part.reasoning_unavailable === true) {
+ return renderPart(
+ part,
+ idx,
+ isLast && idx === lastContentIdx,
+ handleToolExpand,
+ );
+ }
+ const streaming = isSubmitting && idx === lastContentIdx;
+ const isAfterTool =
+ partIndex > 0 &&
+ parts[partIndex - 1]?.part.type === ContentTypes.TOOL_CALL;
+ /** Mirrors the standalone `Reasoning` path: the authored
+ * label wins, generic text is only a fallback. */
+ const generatedLabel = part.reasoning_label?.trim();
+ const label =
+ generatedLabel ||
+ (streaming ? localize('com_ui_thinking') : localize('com_ui_thoughts'));
+ return (
+ <ReasoningCompact
+ key={`reasoning-${idx}`}
+ partKeyIndex={getPartKeyIndex(part, idx)}
+ reasoning={reasoning}
+ label={label}
+ showThinking={showThinking}
+ isAfterTool={isAfterTool}
+ isStreaming={streaming}
+ />
);
}
- const streaming = isSubmitting && idx === lastContentIdx;
- const isAfterTool =
- partIndex > 0 &&
- parts[partIndex - 1]?.part.type === ContentTypes.TOOL_CALL;
- /** Mirrors the standalone `Reasoning` path: the authored
- * label wins, generic text is only a fallback. */
- const generatedLabel = part.reasoning_label?.trim();
- const label =
- generatedLabel ||
- (streaming ? localize('com_ui_thinking') : localize('com_ui_thoughts'));
- return (
- <ReasoningCompact
- key={`reasoning-${idx}`}
- partKeyIndex={getPartKeyIndex(part, idx)}
- reasoning={reasoning}
- label={label}
- showThinking={showThinking}
- isAfterTool={isAfterTool}
- isStreaming={streaming}
- />
+ return renderPart(
+ part,
+ idx,
+ isLast && idx === lastContentIdx,
+ handleToolExpand,
);
- }
- return renderPart(
- part,
- idx,
- isLast && idx === lastContentIdx,
- handleToolExpand,
- );
- })}
- </div>
- </SoleToolContext.Provider>
+ })}
+ </div>
+ </SoleToolContext.Provider>
+ </LoneGroupContext.Provider>
</FailedRevealContext.Provider>
</ToolAuthWarningContext.Provider>
{hasPendingAuthRequest && <ToolAuthWarning className="mt-2.5 mb-1" />}
diff --git a/client/src/components/Chat/Messages/Content/ToolCallInfo.tsx b/client/src/components/Chat/Messages/Content/ToolCallInfo.tsx
index abb1636218..25f44df226 100644
--- a/client/src/components/Chat/Messages/Content/ToolCallInfo.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolCallInfo.tsx
@@ -2,6 +2,7 @@ import { useState, useMemo } from 'react';
import { ChevronDown } from 'lucide-react';
import { useLocalize, useExpandCollapse } from '~/hooks';
import { OutputRenderer } from './ToolOutput';
+import { hasToolParams } from './params';
import { cn } from '~/utils';
function isSimpleObject(obj: unknown): obj is Record<string, string | number | boolean | null> {
@@ -92,20 +93,7 @@ export default function ToolCallInfo({ input, output }: { input: string; output?
const [showParams, setShowParams] = useState(false);
const { style: paramsExpandStyle, ref: paramsExpandRef } = useExpandCollapse(showParams);
- const hasParams = useMemo(() => {
- if (!input || input.trim().length === 0) {
- return false;
- }
- try {
- const parsed = JSON.parse(input);
- if (typeof parsed === 'object' && parsed !== null) {
- return Object.keys(parsed).length > 0;
- }
- } catch {
- // Not JSON
- }
- return input.trim().length > 0;
- }, [input]);
+ const hasParams = useMemo(() => hasToolParams(input), [input]);
return (
<div className="w-full px-3 py-3.5">
diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
index dabc548799..40bd2bf725 100644
--- a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
+++ b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx
@@ -103,6 +103,12 @@ function extractText(raw: string, verbatim = false): ExtractedText {
return { text: trimmed, rawError: '', error: false, isJson: false };
}
+/** Whether the default renderer would draw anything for this output. Callers
+ * that decide a panel is worth showing use it, so the two cannot disagree. */
+export function hasRenderableOutput(raw?: string | null): boolean {
+ return extractText(raw ?? '').text.length > 0;
+}
+
export interface OutputSegment {
text: string;
className?: string;
diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/index.ts b/client/src/components/Chat/Messages/Content/ToolOutput/index.ts
index fbac042099..ee29df34f5 100644
--- a/client/src/components/Chat/Messages/Content/ToolOutput/index.ts
+++ b/client/src/components/Chat/Messages/Content/ToolOutput/index.ts
@@ -1,4 +1,4 @@
export type { ToolIconType } from './ToolIcon';
export { default as StackedToolIcons } from './StackedToolIcons';
-export { default as OutputRenderer, isError } from './OutputRenderer';
+export { default as OutputRenderer, isError, hasRenderableOutput } from './OutputRenderer';
export { default as ToolIcon, getToolIconType, getMCPServerName } from './ToolIcon';
diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolCall.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolCall.test.tsx
index ef960ec963..83a68a028a 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/ToolCall.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolCall.test.tsx
@@ -4,8 +4,8 @@ import { Tools, Constants, dataService } from 'librechat-data-provider';
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import type { TStartupConfig } from 'librechat-data-provider';
import { MCPAppsPolicyProvider } from '~/Providers/MCPAppsPolicyContext';
+import { LoneGroupContext, SoleToolContext } from '../disclosure';
import { ToolAuthWarningContext } from '../auth';
-import { SoleToolContext } from '../disclosure';
import ToolCall from '../ToolCall';
import { logger } from '~/utils';
import store from '~/store';
@@ -987,6 +987,223 @@ describe('ToolCall failure fast path', () => {
});
describe('ToolCall sole tool disclosure', () => {
+ it('keeps the row of an only MCP call, the one place its function name shows', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args='{"query":"weather"}'
+ name="search_documents_mcp_Workspace"
+ output="sunny"
+ initialProgress={1}
+ isSubmitting={false}
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('drops its row when its group holds one call inside a phase of several', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value={false}>
+ <LoneGroupContext.Provider value>
+ <ToolCall
+ args='{"query":"weather"}'
+ name="lookup"
+ output="sunny"
+ initialProgress={1}
+ isSubmitting={false}
+ />
+ </LoneGroupContext.Provider>
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.queryByTestId('tool-call')).not.toBeInTheDocument();
+ expect(screen.getByTestId('tool-call-info')).toBeInTheDocument();
+ });
+
+ it.each([['{}'], ['[]']])(
+ 'keeps the row of an only call whose arguments are %s and output is empty',
+ (args) => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args={args}
+ name="lookup"
+ output=""
+ initialProgress={1}
+ isSubmitting={false}
+ runStepStatus="completed"
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ },
+ );
+
+ it('keeps the row of an only call whose output is only whitespace', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args="{}"
+ name="lookup"
+ output={' \n '}
+ initialProgress={1}
+ isSubmitting={false}
+ runStepStatus="completed"
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('keeps the row of an only call whose output blocks render as empty text', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args="{}"
+ name="lookup"
+ output={JSON.stringify([{ type: 'text', text: ' ' }])}
+ initialProgress={1}
+ isSubmitting={false}
+ runStepStatus="completed"
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('keeps the row of an only call that is still running', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args='{"query":"weather"}'
+ name="lookup"
+ output=""
+ initialProgress={0.5}
+ isSubmitting
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('keeps the row of an only call that carries a model-authored intent', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args='{"intent":"Look up the weather","query":"weather"}'
+ name="lookup"
+ output="sunny"
+ initialProgress={1}
+ isSubmitting={false}
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('keeps the row of an only action call, which names the operation and domain', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args='{"query":"weather"}'
+ name="get_weather_action_api---example---com"
+ output="sunny"
+ initialProgress={1}
+ isSubmitting={false}
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.getByTestId('tool-call')).toBeInTheDocument();
+ });
+
+ it('drops its own row once the only call has settled, leaving the info panel', () => {
+ render(
+ <RecoilRoot>
+ <MCPAppsPolicyProvider
+ startupConfig={{ mcpApps: { enabled: true } } as TStartupConfig}
+ ready
+ userId="user-1"
+ >
+ <SoleToolContext.Provider value>
+ <ToolCall
+ args='{"query":"weather"}'
+ name="lookup"
+ output="sunny"
+ initialProgress={1}
+ isSubmitting={false}
+ />
+ </SoleToolContext.Provider>
+ </MCPAppsPolicyProvider>
+ </RecoilRoot>,
+ );
+ expect(screen.queryByTestId('tool-call')).not.toBeInTheDocument();
+ expect(screen.getByTestId('tool-call-info')).toBeInTheDocument();
+ });
+
it('opens the only call of a group when it returned no output but has arguments', () => {
const { container } = render(
<RecoilRoot>
diff --git a/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
index a44b2cd91b..bd92c1c724 100644
--- a/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
+++ b/client/src/components/Chat/Messages/Content/__tests__/ToolCallGroup.test.tsx
@@ -1,9 +1,9 @@
-import React from 'react';
+import React, { useContext } from 'react';
import { RecoilRoot } from 'recoil';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { Tools, Constants, ContentTypes, ToolCallTypes } from 'librechat-data-provider';
import type { TAttachment, TMessageContentParts } from 'librechat-data-provider';
-import { SoleToolContext, useToolAutoExpand } from '../disclosure';
+import { LoneGroupContext, SoleToolContext, useToolAutoExpand } from '../disclosure';
import { FailedRevealContext, useFailedReveal } from '../reveal';
import { scheduleMessageContentLayoutReconcile } from '~/hooks';
import ToolCallGroup from '../ToolCallGroup';
@@ -207,6 +207,15 @@ const makePart = (
},
}) as unknown as TMessageContentParts;
+const completed = (part: TMessageContentParts): TMessageContentParts =>
+ ({
+ ...part,
+ [ContentTypes.TOOL_CALL]: {
+ ...(part as unknown as Record<string, object>)[ContentTypes.TOOL_CALL],
+ runStepStatus: 'completed',
+ },
+ }) as unknown as TMessageContentParts;
+
const makeApprovalPart = (id: string, output = ''): TMessageContentParts =>
({
type: ContentTypes.TOOL_CALL,
@@ -941,6 +950,359 @@ describe('ToolCallGroup image hoisting', () => {
expect(screen.getByRole('button', { name: 'Create File' })).toBeInTheDocument();
});
+ it('names a lone code call by what it did, not by the bare tool name', () => {
+ renderGroup({
+ ...baseProps,
+ parts: [{ part: completed(makePart('code-1', 'done', 'execute_code')), idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.getByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).toBeInTheDocument();
+ });
+
+ it('names a lone running code call by what it is doing', () => {
+ renderGroup({
+ ...baseProps,
+ isSubmitting: true,
+ parts: [{ part: makePart('code-1', '', 'execute_code'), idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(screen.getByRole('button', { name: /^com_assistants_running_var/ })).toBeInTheDocument();
+ });
+
+ it('keeps a multi-call group in the running tense while one detached task runs', () => {
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [
+ { part: completed(makePart('plain-1', 'ok', 'fetch_image')), idx: 0 },
+ {
+ part: completed(
+ makePart(
+ 'code-bg-2',
+ JSON.stringify({
+ background_task_id: 'task-2',
+ tool: 'bash_tool',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ }),
+ 'bash_tool',
+ ),
+ ),
+ idx: 1,
+ },
+ ],
+ lastContentIdx: 1,
+ });
+
+ expect(screen.getByRole('button', { name: /^Running 2 actions/ })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: /^Ran 2 actions/ })).not.toBeInTheDocument();
+ });
+
+ it('does not hold a group in the running tense for a detached MCP call its row reports as ran', () => {
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [
+ { part: completed(makePart('plain-1', 'ok', 'fetch_image')), idx: 0 },
+ {
+ part: completed(
+ makePart(
+ 'mcp-bg',
+ JSON.stringify({
+ background_task_id: 'task-3',
+ tool: 'search',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ }),
+ 'search_mcp_github',
+ ),
+ ),
+ idx: 1,
+ },
+ ],
+ lastContentIdx: 1,
+ });
+
+ expect(screen.getByRole('button', { name: /^Ran 2 actions/ })).toBeInTheDocument();
+ });
+
+ it('keeps the group open while a lone detached task is still running', () => {
+ renderGroup({
+ ...baseProps,
+ parts: [
+ {
+ part: completed(
+ makePart(
+ 'code-bg',
+ JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ }),
+ 'bash_tool',
+ ),
+ ),
+ idx: 0,
+ },
+ ],
+ lastContentIdx: 0,
+ });
+
+ expect(screen.getByRole('button', { name: /^com_assistants_running_var/ })).toHaveAttribute(
+ 'aria-expanded',
+ 'true',
+ );
+ });
+
+ it('keeps a lone code call in the running tense while its detached task runs', () => {
+ renderGroup({
+ ...baseProps,
+ parts: [
+ {
+ part: completed(
+ makePart(
+ 'code-1',
+ JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ }),
+ 'bash_tool',
+ ),
+ ),
+ idx: 0,
+ },
+ ],
+ lastContentIdx: 0,
+ });
+
+ expect(screen.getByRole('button', { name: /^com_assistants_running_var/ })).toBeInTheDocument();
+ });
+
+ const handleOutput = JSON.stringify({
+ background_task_id: 'task-1',
+ tool: 'bash_tool',
+ status: 'running',
+ message: 'Use check_background_task to follow it',
+ });
+ const detachedProps = (attachments: TAttachment[] = []) => ({
+ ...baseProps,
+ parts: [{ part: completed(makePart('code-1', handleOutput, 'bash_tool')), idx: 0 }],
+ lastContentIdx: 0,
+ groupAttachments: attachments,
+ });
+
+ it('does not keep a cancelled detached task open or live', () => {
+ const cancelled = completed(makePart('code-1', handleOutput, 'bash_tool'));
+ (cancelled as unknown as Record<string, Record<string, unknown>>)[
+ ContentTypes.TOOL_CALL
+ ].backgroundTask = { cancelled: true };
+ renderGroup({ ...baseProps, parts: [{ part: cancelled, idx: 0 }], lastContentIdx: 0 });
+
+ expect(screen.getByRole('button', { name: /^com_ui_cancelled/ })).toHaveAttribute(
+ 'aria-expanded',
+ 'false',
+ );
+ });
+
+ it('moves focus to the header when a focused detached task settles and the group collapses', () => {
+ const renderPart = (_p: TMessageContentParts, idx: number) => (
+ <button type="button" data-testid="row" key={idx}>
+ {'row'}
+ </button>
+ );
+ const settled = {
+ type: 'background_task_status',
+ status: 'finished',
+ toolCallId: 'code-1',
+ messageId: 'm1',
+ } as unknown as TAttachment;
+ const tree = (attachments: TAttachment[]) => (
+ <RecoilRoot>
+ <ToolCallGroup {...detachedProps(attachments)} renderPart={renderPart} />
+ </RecoilRoot>
+ );
+ const { rerender } = render(tree([]));
+ screen.getByTestId('row').focus();
+ expect(screen.getByTestId('row')).toHaveFocus();
+
+ rerender(tree([settled]));
+
+ expect(
+ screen.getByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).toHaveFocus();
+ });
+
+ it('does not call a failed lone code call "ran"', () => {
+ const failed = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-f',
+ name: 'execute_code',
+ args: '{}',
+ output: 'boom',
+ runStepStatus: 'failed',
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ parts: [{ part: failed, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('does not call a failed lone code call "running"', () => {
+ const failed = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-f2',
+ name: 'execute_code',
+ args: '{}',
+ output: 'boom',
+ runStepStatus: 'failed',
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ parts: [{ part: failed, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_running_var/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('does not claim a lone code call ran when an interrupted legacy record has no success signal', () => {
+ const interrupted = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-legacy',
+ name: 'execute_code',
+ args: '{}',
+ output: '',
+ progress: 0.5,
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [{ part: interrupted, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('does not claim a lone code call ran when an interrupted legacy record kept partial output', () => {
+ const interrupted = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-partial',
+ name: 'execute_code',
+ args: '{}',
+ output: 'partial',
+ progress: 0.5,
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [{ part: interrupted, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('does not claim a lone code call ran when a legacy record has output but no progress field', () => {
+ const noProgress = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-no-progress',
+ name: 'execute_code',
+ args: '{}',
+ output: 'done',
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [{ part: noProgress, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).not.toBeInTheDocument();
+ });
+
+ it('calls a lone legacy code call ran once its progress reaches 1', () => {
+ const finished = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-legacy-ok',
+ name: 'execute_code',
+ args: '{}',
+ output: 'done',
+ progress: 1,
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ isSubmitting: false,
+ parts: [{ part: finished, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.getByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).toBeInTheDocument();
+ });
+
+ it('does not call a stopped lone code call "ran"', () => {
+ const cancelled = {
+ type: ContentTypes.TOOL_CALL,
+ [ContentTypes.TOOL_CALL]: {
+ id: 'code-c',
+ name: 'execute_code',
+ args: '{}',
+ output: '',
+ runStepStatus: 'cancelled',
+ },
+ } as unknown as TMessageContentParts;
+
+ renderGroup({
+ ...baseProps,
+ parts: [{ part: cancelled, idx: 0 }],
+ lastContentIdx: 0,
+ });
+
+ expect(
+ screen.queryByRole('button', { name: /^com_assistants_completed_function/ }),
+ ).not.toBeInTheDocument();
+ });
+
it('keeps repeated action counts and failed-call status in the compact summary', () => {
renderGroup({
...baseProps,
@@ -1591,6 +1953,36 @@ describe('ToolCallGroup sole tool', () => {
expect(screen.getByTestId('probe-0')).toHaveTextContent('true');
});
+ it('marks a one-call group as lone even when its phase holds several calls', () => {
+ function LoneProbe() {
+ return <div data-testid="lone">{String(useContext(LoneGroupContext))}</div>;
+ }
+ render(
+ <RecoilRoot>
+ <SoleToolContext.Provider value={false}>
+ <ToolCallGroup
+ {...props(['only'])}
+ renderPart={(_p: TMessageContentParts, idx: number) => <LoneProbe key={idx} />}
+ />
+ </SoleToolContext.Provider>
+ </RecoilRoot>,
+ );
+ fireEvent.click(screen.getByRole('button', { expanded: false }));
+ expect(screen.getByTestId('lone')).toHaveTextContent('true');
+ });
+
+ it('does not mark a two-call group as lone', () => {
+ function LoneProbe({ idx }: { idx: number }) {
+ return <div data-testid={`lone-${idx}`}>{String(useContext(LoneGroupContext))}</div>;
+ }
+ renderGroup({
+ ...props(['a', 'b']),
+ renderPart: (_p: TMessageContentParts, idx: number) => <LoneProbe key={idx} idx={idx} />,
+ });
+ fireEvent.click(screen.getByRole('button', { expanded: false }));
+ expect(screen.getByTestId('lone-0')).toHaveTextContent('false');
+ });
+
it('keeps a one-call group collapsed when its phase holds several calls', () => {
render(
<RecoilRoot>
diff --git a/client/src/components/Chat/Messages/Content/disclosure.ts b/client/src/components/Chat/Messages/Content/disclosure.ts
index ec08a1b99c..d6cc0737e1 100644
--- a/client/src/components/Chat/Messages/Content/disclosure.ts
+++ b/client/src/components/Chat/Messages/Content/disclosure.ts
@@ -62,6 +62,12 @@ export function useToolDisclosure() {
* wins over the groups inside it. */
export const SoleToolContext = createContext<boolean | undefined>(undefined);
+/** Set by a tool group for its own rows: true when the group holds exactly one
+ * tool call, whatever the phase around it holds. `SoleToolContext` lets the
+ * phase decide whether a card opens by default; this one decides whether the
+ * card's own row is redundant under the group header it sits beneath. */
+export const LoneGroupContext = createContext<boolean>(false);
+
/** Whether a tool card opens by default: the user's "auto-expand tools"
* preference, or being the only call inside its group. */
export function useToolAutoExpand() {
diff --git a/client/src/components/Chat/Messages/Content/handoff.ts b/client/src/components/Chat/Messages/Content/handoff.ts
new file mode 100644
index 0000000000..4db6adafb0
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/handoff.ts
@@ -0,0 +1,40 @@
+import { useCallback, useLayoutEffect, useRef } from 'react';
+
+/**
+ * A sole call drops its own row once it settles, because the group header is
+ * the row. If that row held keyboard focus, the browser would drop focus to the
+ * document, so focus moves to the header the row is replaced by.
+ *
+ * The row is watched through its ref callback: React detaches it before the
+ * node leaves the DOM, which is the last moment `document.activeElement` still
+ * says whether the row had focus, and the node can still name its group.
+ */
+export default function useRowHandoff(bare: boolean) {
+ const rowNode = useRef<HTMLElement | null>(null);
+ const handoff = useRef<HTMLElement | null>(null);
+
+ const rowRef = useCallback((node: HTMLElement | null) => {
+ if (node == null) {
+ const held = rowNode.current?.contains(document.activeElement) === true;
+ const root = rowNode.current?.closest('[data-fold-root]');
+ /** The header precedes every row in document order, whatever else the
+ * root leads with (a phase puts its announcer first). */
+ const header = held ? (root?.querySelector<HTMLElement>('button') ?? null) : null;
+ handoff.current = header != null && !rowNode.current?.contains(header) ? header : null;
+ } else {
+ handoff.current = null;
+ }
+ rowNode.current = node;
+ }, []);
+
+ useLayoutEffect(() => {
+ if (!bare || handoff.current == null) {
+ return;
+ }
+ const target = handoff.current;
+ handoff.current = null;
+ target.focus();
+ }, [bare]);
+
+ return rowRef;
+}
diff --git a/client/src/components/Chat/Messages/Content/params.ts b/client/src/components/Chat/Messages/Content/params.ts
new file mode 100644
index 0000000000..64f4e420b6
--- /dev/null
+++ b/client/src/components/Chat/Messages/Content/params.ts
@@ -0,0 +1,17 @@
+/** Whether serialized tool arguments hold anything the info panel can show.
+ * An empty object or array renders nothing, so a card must not count it as
+ * content. Shared by the panel and by the card deciding to drop its row. */
+export function hasToolParams(input?: string | null): boolean {
+ if (!input || input.trim().length === 0) {
+ return false;
+ }
+ try {
+ const parsed = JSON.parse(input);
+ if (typeof parsed === 'object' && parsed !== null) {
+ return Object.keys(parsed).length > 0;
+ }
+ } catch {
+ // Not JSON
+ }
+ return input.trim().length > 0;
+}