mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🎰 fix: Show Live Tool Combo Multipliers (#16202)
* 🧮 fix: Show Live Tool Combo Multipliers * 🧮 fix: Preserve Live Outcome Separator * 🧮 fix: Narrow Combo Scan Parts * 🧮 test: Expect Live Combo Labels * 🎰 fix: Synchronize Live Combo Transitions * 🎰 test: Await Live Combo Reset * 🎰 perf: Accumulate Tool Combos During Span Summaries --------- Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
a9c87939af
commit
e7a451cbf8
5 changed files with 209 additions and 17 deletions
|
|
@ -294,7 +294,10 @@ function LivePhaseHeader({
|
|||
? localize('com_ui_sandbox_starting')
|
||||
: activity.text;
|
||||
const { source } = activity;
|
||||
const line = useMemo(() => ({ text, source }), [text, source]);
|
||||
const line = useMemo(
|
||||
() => ({ text, source, comboCount: activity.comboCount }),
|
||||
[text, source, activity.comboCount],
|
||||
);
|
||||
const previewRef = useRef<HTMLSpanElement>(null);
|
||||
const [isPreviewFull, setIsPreviewFull] = useState(false);
|
||||
const painted = useThrottledValue(
|
||||
|
|
@ -329,6 +332,7 @@ function LivePhaseHeader({
|
|||
* fail while a later one runs, and the line alone would never say so. The
|
||||
* hidden group header carries the same counts in the same words. */
|
||||
const { failed, cancelled } = activity.outcome;
|
||||
const combo = painted.comboCount > 1 ? `×${painted.comboCount}` : '';
|
||||
const detail = useMemo(() => {
|
||||
const notes: string[] = [];
|
||||
if (failed > 0) {
|
||||
|
|
@ -396,13 +400,22 @@ function LivePhaseHeader({
|
|||
lineId={lineId}
|
||||
previewRef={previewRef}
|
||||
/>
|
||||
{detail && (
|
||||
{(combo || detail) && (
|
||||
<span
|
||||
id={detailId}
|
||||
className="shrink-0 text-xs font-normal text-text-warning"
|
||||
data-testid="live-phase-outcome"
|
||||
className={cn(
|
||||
'shrink-0 text-xs font-normal',
|
||||
detail ? 'text-text-warning' : 'text-text-secondary',
|
||||
)}
|
||||
data-testid={detail ? 'live-phase-outcome' : 'live-phase-combo'}
|
||||
>
|
||||
· {detail}
|
||||
{combo && <span>{combo}</span>}
|
||||
{detail && (
|
||||
<>
|
||||
<span className={cn(combo ? 'mx-1' : 'mr-1', 'text-text-secondary')}>·</span>
|
||||
<span>{detail}</span>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -1621,7 +1621,7 @@ describe('ContentParts — live activity fold', () => {
|
|||
expect(screen.getByTestId('activity-phase-announcer')).toHaveTextContent(
|
||||
'Reading the lens file',
|
||||
);
|
||||
expect(liveHeader()).toHaveAccessibleName('Querying');
|
||||
expect(liveHeader()).toHaveAccessibleName('Querying ×2');
|
||||
});
|
||||
|
||||
it('leaves a span of legacy Assistants calls, which the header cannot name, unfolded', () => {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import type {
|
|||
import { resolveAskUserQuestionPart } from '~/utils/approval';
|
||||
import { sandboxStartingByToolCallId } from '~/store';
|
||||
import ContentParts from '../ContentParts';
|
||||
import { getLiveActivity } from '../live';
|
||||
import store from '~/store';
|
||||
|
||||
/**
|
||||
|
|
@ -185,6 +186,73 @@ const foldVerdict = (): Verdict => {
|
|||
: 'completed';
|
||||
};
|
||||
|
||||
describe('live combo aggregation', () => {
|
||||
const activity = (parts: Array<TMessageContentParts | undefined>) =>
|
||||
getLiveActivity(parts, (key) => key, []);
|
||||
|
||||
it('counts a long repeated suffix without reading the historical prefix twice per delta', () => {
|
||||
const parts = Array.from({ length: 1024 }, (_, index) =>
|
||||
toPart({ name: 'lookup', output: 'ok' }, `call-${index}`),
|
||||
);
|
||||
const first = parts[0];
|
||||
const readFirst = jest.fn(() => first);
|
||||
Object.defineProperty(parts, 0, { get: readFirst });
|
||||
|
||||
for (const intent of ['Checking', 'Checking the', 'Checking the last file']) {
|
||||
parts[parts.length - 1] = toPart({ name: 'lookup', args: { intent } }, 'tail');
|
||||
readFirst.mockClear();
|
||||
expect(activity(parts).comboCount).toBe(1024);
|
||||
expect(readFirst).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
});
|
||||
|
||||
it('counts only the suffix, ignoring descriptive metadata and sparse slots', () => {
|
||||
const call = (name: string) => toPart({ name, output: 'ok' });
|
||||
expect(
|
||||
activity([
|
||||
call('read_file'),
|
||||
call('edit_file'),
|
||||
call('read_file'),
|
||||
undefined,
|
||||
{ type: ContentTypes.THINK, think: 'Checking another file' },
|
||||
{ type: ContentTypes.ACTIVITY_LABEL, activity_label: 'Read a file' },
|
||||
call('read_file'),
|
||||
]).comboCount,
|
||||
).toBe(2);
|
||||
});
|
||||
|
||||
it('uses full tool identity, not the shared MCP server or icon', () => {
|
||||
expect(
|
||||
activity([
|
||||
toPart({ name: 'read_mcp_workspace', output: 'ok' }),
|
||||
toPart({ name: 'edit_mcp_workspace', output: 'ok' }),
|
||||
]).comboCount,
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('reuses normalized Bash identity and recomputes it when streamed arguments change', () => {
|
||||
const first = toPart({ name: Tools.bash_tool, output: 'ok' });
|
||||
const programmatic = (lang: string) =>
|
||||
toPart({ name: Constants.PROGRAMMATIC_TOOL_CALLING, args: { lang } });
|
||||
expect(activity([first, programmatic('bash')]).comboCount).toBe(2);
|
||||
expect(activity([first, programmatic('python')]).comboCount).toBe(1);
|
||||
});
|
||||
|
||||
it.each<TMessageContentParts>([
|
||||
{ type: ContentTypes.THINK, think: 'Considering the results' },
|
||||
{ type: ContentTypes.TEXT, text: 'Checking the results', phase: 'commentary' },
|
||||
{ type: ContentTypes.ACTIVITY_LABEL, activity_label: 'Checked the results' },
|
||||
])('does not attach a tool multiplier to a trailing $type line', (tail) => {
|
||||
expect(
|
||||
activity([
|
||||
toPart({ name: 'lookup', output: 'ok' }, 'first'),
|
||||
toPart({ name: 'lookup', output: 'ok' }, 'second'),
|
||||
tail,
|
||||
]).comboCount,
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('live fold parity with the cards it hides', () => {
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
|
|
@ -232,6 +300,95 @@ describe('live fold parity with the cards it hides', () => {
|
|||
expect(screen.queryByTestId('activity-phase-card')).toBeNull();
|
||||
});
|
||||
|
||||
it('shows a multiplier for consecutive uses of the same tool and resets on a different tool', () => {
|
||||
jest.useFakeTimers();
|
||||
const first = toPart({ name: 'create_file', output: 'created' }, 'first');
|
||||
const second = toPart({ name: 'create_file', output: '' }, 'second');
|
||||
const view = mount([first, second], undefined, true);
|
||||
|
||||
expect(screen.getByTestId('live-phase-combo')).toHaveTextContent('×2');
|
||||
expect(
|
||||
within(screen.getByTestId('activity-phase-card')).getAllByRole('button')[0],
|
||||
).toHaveAccessibleName(/×2/);
|
||||
|
||||
view.rerender(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<RecoilRoot>
|
||||
<ContentParts
|
||||
content={[first, second, toPart({ name: 'edit_file', output: '' }, 'third')]}
|
||||
messageId="m1"
|
||||
conversationId="c1"
|
||||
isCreatedByUser={false}
|
||||
isLast
|
||||
isLatestMessage
|
||||
isSubmitting
|
||||
showThinking={false}
|
||||
/>
|
||||
</RecoilRoot>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('live-phase-combo')).toHaveTextContent('×2');
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
expect(screen.queryByTestId('live-phase-combo')).toBeNull();
|
||||
});
|
||||
|
||||
it('changes the multiplier with the throttled status line', () => {
|
||||
jest.useFakeTimers();
|
||||
const first = toPart(
|
||||
{ name: 'create_file', args: '{"intent":"Creating the first file"}', output: '' },
|
||||
'first',
|
||||
);
|
||||
const second = toPart(
|
||||
{ name: 'create_file', args: '{"intent":"Creating the second file"}', output: '' },
|
||||
'second',
|
||||
);
|
||||
const view = mount([first], undefined, true);
|
||||
view.rerender(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<RecoilRoot>
|
||||
<ContentParts
|
||||
content={[first, second]}
|
||||
messageId="m1"
|
||||
conversationId="c1"
|
||||
isCreatedByUser={false}
|
||||
isLast
|
||||
isLatestMessage
|
||||
isSubmitting
|
||||
showThinking={false}
|
||||
/>
|
||||
</RecoilRoot>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
const header = within(screen.getByTestId('activity-phase-card')).getAllByRole('button')[0];
|
||||
expect(header).toHaveAccessibleName('Creating the first file');
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
expect(header).toHaveAccessibleName('Creating the second file ×2');
|
||||
});
|
||||
|
||||
it('resets the multiplier across an agent handoff', () => {
|
||||
const handoff = {
|
||||
type: ContentTypes.AGENT_UPDATE,
|
||||
[ContentTypes.AGENT_UPDATE]: { agentId: 'agent-b', index: 1 },
|
||||
} as TMessageContentParts;
|
||||
mount(
|
||||
[
|
||||
toPart({ name: 'create_file', output: 'created' }, 'first'),
|
||||
handoff,
|
||||
toPart({ name: 'create_file', output: '' }, 'second'),
|
||||
],
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('live-phase-combo')).toBeNull();
|
||||
});
|
||||
|
||||
it('treats a second call that reuses a provider id as a new line', () => {
|
||||
jest.useFakeTimers();
|
||||
const first = toPart({ name: 'lookup', args: '{"intent":"First pass"}', output: 'ok' }, 'dup');
|
||||
|
|
@ -870,7 +1027,7 @@ describe('live activity hardening transitions', () => {
|
|||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
const header = screen.getByRole('button');
|
||||
expect(header).toHaveAccessibleName('Checking the next file');
|
||||
expect(header).toHaveAccessibleName('Checking the next file ×2');
|
||||
expect(header.querySelector('.absolute[aria-hidden="true"]')).toBeNull();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ export type LiveActivity = {
|
|||
* the content array; the header reads the same signal for this call rather
|
||||
* than unfolding the span to let the card say it. */
|
||||
pendingToolCallId?: string;
|
||||
/** Consecutive uses of the newest tool, including the current call. */
|
||||
comboCount: number;
|
||||
/** Failed and stopped calls anywhere in the span, not just the newest line. */
|
||||
outcome: SpanOutcome;
|
||||
};
|
||||
|
|
@ -235,7 +237,7 @@ function newestLine(
|
|||
localize: Localize,
|
||||
serverNames: readonly string[],
|
||||
span: SpanSummary,
|
||||
): Pick<LiveActivity, 'text' | 'source' | 'pendingToolCallId'> {
|
||||
): Pick<LiveActivity, 'text' | 'source' | 'pendingToolCallId' | 'comboCount'> {
|
||||
for (let position = parts.length - 1; position >= 0; position -= 1) {
|
||||
const part = parts[position];
|
||||
if (part == null) {
|
||||
|
|
@ -248,11 +250,15 @@ function newestLine(
|
|||
const reasoning = typeof part.think === 'string' ? part.think : (part.think?.value ?? '');
|
||||
const sentence = lastReasoningSentence(reasoning);
|
||||
if (sentence != null) {
|
||||
return { text: sentence, source: `think:${position}` };
|
||||
return { text: sentence, source: `think:${position}`, comboCount: 1 };
|
||||
}
|
||||
const label = part.reasoning_label?.trim();
|
||||
if (label || reasoning.trim()) {
|
||||
return { text: label || localize('com_ui_thinking'), source: `think:${position}` };
|
||||
return {
|
||||
text: label || localize('com_ui_thinking'),
|
||||
source: `think:${position}`,
|
||||
comboCount: 1,
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -264,13 +270,13 @@ function newestLine(
|
|||
const value = typeof part.text === 'string' ? part.text : (part.text?.value ?? '');
|
||||
const commentary = boundIntentLabel(value);
|
||||
if (commentary != null) {
|
||||
return { text: commentary, source: `text:${position}` };
|
||||
return { text: commentary, source: `text:${position}`, comboCount: 1 };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const labelText = getActivityLabelText(getBatchActivityLabelPart(part));
|
||||
if (labelText) {
|
||||
return { text: labelText, source: `label:${position}` };
|
||||
return { text: labelText, source: `label:${position}`, comboCount: 1 };
|
||||
}
|
||||
const toolCall = getStandardToolCall(part);
|
||||
if (toolCall != null) {
|
||||
|
|
@ -280,11 +286,12 @@ function newestLine(
|
|||
* identity: a second call reusing an id is a new line, not the first
|
||||
* one still growing. */
|
||||
source: `tool:${toolCall.id ?? ''}:${position}`,
|
||||
comboCount: Math.max(1, span.trailingToolCount),
|
||||
...(isAwaitingStartup(part, toolCall, span) && { pendingToolCallId: toolCall.id }),
|
||||
};
|
||||
}
|
||||
}
|
||||
return { text: '', source: '' };
|
||||
return { text: '', source: '', comboCount: 1 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -293,9 +300,9 @@ function newestLine(
|
|||
* label once one lands after it, or the thought streaming after both. Later parts win, so the
|
||||
* header always reads as the bottom line of the list it stands for.
|
||||
*
|
||||
* Runs on every streamed delta. Outcome aggregation visits the full span so
|
||||
* late failures cannot disappear; the line stops at the newest nameable part
|
||||
* and icons only inspect a fixed tail window.
|
||||
* Runs on every streamed delta. Outcomes and the tool combo share one full-span
|
||||
* pass so late failures cannot disappear; the line stops at the newest nameable
|
||||
* part and icons only inspect a fixed tail window.
|
||||
*/
|
||||
export function getLiveActivity(
|
||||
parts: ReadonlyArray<TMessageContentParts | undefined>,
|
||||
|
|
|
|||
|
|
@ -197,6 +197,9 @@ export function getOutcomeStatus({
|
|||
}
|
||||
|
||||
export type SpanSummary = SpanOutcome & {
|
||||
/** Consecutive uses of the last tool, reset by another tool or an agent handoff.
|
||||
* Reasoning and labels describe the work without breaking its sequence. */
|
||||
trailingToolCount: number;
|
||||
/** The verdict for one part of the span, scoped the way the count was. */
|
||||
metaOf: (part: TMessageContentParts) => ToolMeta | null;
|
||||
};
|
||||
|
|
@ -274,8 +277,20 @@ export function summarizeSpan(
|
|||
};
|
||||
let failed = 0;
|
||||
let cancelled = 0;
|
||||
let trailingToolCount = 0;
|
||||
let trailingTool: string | undefined;
|
||||
for (const part of parts) {
|
||||
if (part?.type === ContentTypes.AGENT_UPDATE) {
|
||||
trailingTool = undefined;
|
||||
trailingToolCount = 0;
|
||||
}
|
||||
const meta = part == null ? null : metaOf(part);
|
||||
if (meta != null) {
|
||||
/** iconName retains full tool identity (including MCP names), with Bash
|
||||
* wrappers already normalized by the cached metadata resolver. */
|
||||
trailingToolCount = meta.iconName === trailingTool ? trailingToolCount + 1 : 1;
|
||||
trailingTool = meta.iconName;
|
||||
}
|
||||
if (meta?.failed === true) {
|
||||
failed += 1;
|
||||
}
|
||||
|
|
@ -283,5 +298,5 @@ export function summarizeSpan(
|
|||
cancelled += 1;
|
||||
}
|
||||
}
|
||||
return { failed, cancelled, metaOf };
|
||||
return { failed, cancelled, trailingToolCount, metaOf };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue