mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
🏷️ fix: Title an Open Live Card Only by a Generated Label (#16412)
* 🏷️ fix: Title an Open Live Card Only by a Generated Label An open card still repeated its newest row: a running call's intent was counted as a label and put on the header above the very row that shows it, and with no label at all the header said "Thinking…", which the grouped thought row says too. Open, the header now takes only a generated label from the span, the newest batch label or a thought's label, and otherwise a generic running line that no row uses. A call's intent, a reasoning sentence, commentary and the generic thinking line are all row text and are walked past. * 🧪 test: Pin the Open Card's Title to the Running Line While a Thought Streams
This commit is contained in:
parent
129a1de52c
commit
da5e3931ca
3 changed files with 84 additions and 9 deletions
|
|
@ -595,7 +595,7 @@ describe('ActivityPhaseGroup open live header', () => {
|
|||
expect(within(header).queryByTitle('Next I check the ordering.')).toBeNull();
|
||||
});
|
||||
|
||||
test('falls back to the generic thinking line when no label has landed', () => {
|
||||
test('falls back to a running line no row uses when no label has landed', () => {
|
||||
render(
|
||||
<ActivityPhaseGroup labelPart={makeLabelPart('')} hasContent liveParts={[thought()]}>
|
||||
<div data-testid="phase-content" />
|
||||
|
|
@ -603,7 +603,62 @@ describe('ActivityPhaseGroup open live header', () => {
|
|||
);
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
settle();
|
||||
expect(within(screen.getByRole('button')).getByTitle('com_ui_thinking')).toBeInTheDocument();
|
||||
const header = screen.getByRole('button');
|
||||
expect(within(header).getByTitle('com_ui_running')).toBeInTheDocument();
|
||||
expect(within(header).queryByTitle('com_ui_thinking')).toBeNull();
|
||||
});
|
||||
|
||||
const runningCall = (intent: string): TMessageContentParts =>
|
||||
({
|
||||
type: ContentTypes.TOOL_CALL,
|
||||
[ContentTypes.TOOL_CALL]: {
|
||||
id: 'r1',
|
||||
name: 'list_documents',
|
||||
args: JSON.stringify({ intent }),
|
||||
type: 'tool_call',
|
||||
progress: 0.5,
|
||||
output: '',
|
||||
},
|
||||
}) as unknown as TMessageContentParts;
|
||||
const batchLabel = (text: string): TMessageContentParts =>
|
||||
({
|
||||
type: ContentTypes.ACTIVITY_LABEL,
|
||||
activity_label: text,
|
||||
activity_label_type: 'batch',
|
||||
pending: false,
|
||||
}) as unknown as TMessageContentParts;
|
||||
|
||||
test("does not repeat the newest call's intent, which is its own row", () => {
|
||||
const intent = 'Reading the roadmap card so edits preserve project choices';
|
||||
render(
|
||||
<ActivityPhaseGroup
|
||||
labelPart={makeLabelPart('')}
|
||||
hasContent
|
||||
liveParts={[runningCall(intent)]}
|
||||
>
|
||||
<div data-testid="phase-content" />
|
||||
</ActivityPhaseGroup>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
settle();
|
||||
const header = screen.getByRole('button');
|
||||
expect(within(header).queryByTitle(intent)).toBeNull();
|
||||
expect(within(header).getByTitle('com_ui_running')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('titles an open card by the newest batch label behind a running call', () => {
|
||||
render(
|
||||
<ActivityPhaseGroup
|
||||
labelPart={makeLabelPart('')}
|
||||
hasContent
|
||||
liveParts={[batchLabel('Found the recap'), runningCall('Reading the roadmap card')]}
|
||||
>
|
||||
<div data-testid="phase-content" />
|
||||
</ActivityPhaseGroup>,
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
settle();
|
||||
expect(within(screen.getByRole('button')).getByTitle('Found the recap')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -284,11 +284,19 @@ function newestLine(
|
|||
* repeating a line of it under the reader's eyes is noise, so the
|
||||
* header keeps to the thought's label. */
|
||||
const reasoning = typeof part.think === 'string' ? part.think : (part.think?.value ?? '');
|
||||
const sentence = preferLabels ? undefined : lastReasoningSentence(reasoning);
|
||||
const label = part.reasoning_label?.trim();
|
||||
if (preferLabels) {
|
||||
/** Only a generated label will do: the generic thinking line is what
|
||||
* the grouped thought row itself says. */
|
||||
if (label) {
|
||||
return { text: label, source: `think:${position}`, comboCount: 1 };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const sentence = lastReasoningSentence(reasoning);
|
||||
if (sentence != null) {
|
||||
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'),
|
||||
|
|
@ -315,6 +323,11 @@ function newestLine(
|
|||
return { text: labelText, source: `label:${position}`, comboCount: 1 };
|
||||
}
|
||||
const toolCall = getStandardToolCall(part);
|
||||
/** A call's line, intent or generic, is the text of its own row, so an
|
||||
* open card walks past it to the newest label instead. */
|
||||
if (toolCall != null && preferLabels) {
|
||||
continue;
|
||||
}
|
||||
if (toolCall != null) {
|
||||
const line = toolCallLine(part, toolCall, localize, serverNames, span);
|
||||
return {
|
||||
|
|
@ -331,6 +344,10 @@ function newestLine(
|
|||
};
|
||||
}
|
||||
}
|
||||
/** An open card with no label yet is titled by a line no row uses. */
|
||||
if (preferLabels && parts.some((part) => part != null)) {
|
||||
return { text: localize('com_ui_running'), source: 'running', comboCount: 1 };
|
||||
}
|
||||
return { text: '', source: '', comboCount: 1 };
|
||||
}
|
||||
|
||||
|
|
@ -350,10 +367,11 @@ export function getLiveActivity(
|
|||
localize: Localize,
|
||||
serverNames: readonly string[],
|
||||
attachmentsById?: Record<string, TAttachment[] | undefined>,
|
||||
/** Name the span by its newest LABEL: a thought's generated label or the
|
||||
* generic thinking line, a batch label, a call's line — never a line of
|
||||
* reasoning or commentary. For a header whose rows are on screen, where
|
||||
* quoting them back is repetition. */
|
||||
/** Name the span by its newest generated LABEL alone: a batch label or a
|
||||
* thought's label, else a generic running line. Never a call's intent, a
|
||||
* reasoning sentence, commentary or the generic thinking line, since each
|
||||
* of those is the text of a row. For a header whose rows are on screen,
|
||||
* where quoting any of them back is repetition. */
|
||||
preferLabels = false,
|
||||
): LiveActivity {
|
||||
const span = summarizeSpan(parts, attachmentsById);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,9 @@ test.describe('live reasoning', () => {
|
|||
if (process.env.E2E_FOLD_SHOTS) {
|
||||
await page.screenshot({ path: `${process.env.E2E_FOLD_SHOTS}/thought-open.png` });
|
||||
}
|
||||
expect(open, 'open card title').not.toMatch(/[a-z]\.$/);
|
||||
/** No label has landed on this span, so the open card takes the
|
||||
* generic running line, never a sentence of the thought below. */
|
||||
expect(open, 'open card title').toBe('Running...');
|
||||
expect(await messagesView(page).getByTestId('streaming-thought-peek').count()).toBe(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue