diff --git a/browser_tests/fixtures/agentPromptHistoryFixture.ts b/browser_tests/fixtures/agentPromptHistoryFixture.ts index 5d13129caeb..abef30d8364 100644 --- a/browser_tests/fixtures/agentPromptHistoryFixture.ts +++ b/browser_tests/fixtures/agentPromptHistoryFixture.ts @@ -10,6 +10,7 @@ import { zAgentPostMessageRequest } from '@comfyorg/ingest-types/zod' import type { AgentWsEvent, + PersistedThinkingEntry, PersistedToolCallSummary } from '@/workbench/extensions/agent/schemas/agentApiSchema' @@ -26,8 +27,9 @@ const base = mergeTests(agentTest, workflowSelectionTest, webSocketFixture) // the stricter wire `ToolCallSummary` generated type. type MockAgentMessageContent = Omit< NonNullable, - 'tool_calls' + 'thinking' | 'tool_calls' > & { + thinking?: PersistedThinkingEntry[] tool_calls?: PersistedToolCallSummary[] } type MockAgentMessage = Omit & { diff --git a/browser_tests/fixtures/components/AgentPanel.ts b/browser_tests/fixtures/components/AgentPanel.ts index 39a00351392..083a20b25f1 100644 --- a/browser_tests/fixtures/components/AgentPanel.ts +++ b/browser_tests/fixtures/components/AgentPanel.ts @@ -62,6 +62,7 @@ export class AgentPanel { public readonly settingsSwitch: Locator public readonly stopButton: Locator public readonly suggestedPrompts: Locator + public readonly thinkingShortenedNotices: Locator public readonly userMessageBubbles: Locator private readonly toasts: ToastHelper public readonly workflowPicker: Locator @@ -160,6 +161,9 @@ export class AgentPanel { this.suggestedPrompts = this.root .getByTestId('suggested-prompts') .getByRole('button', { includeHidden: true }) + this.thinkingShortenedNotices = this.root.getByTestId( + TestIds.agent.thinkingShortened + ) this.userMessageBubbles = this.root.getByTestId('user-message-bubble') this.workflowPicker = this.root.getByRole('button', { name: enMessages.agent.switchWorkflow diff --git a/browser_tests/fixtures/selectors.ts b/browser_tests/fixtures/selectors.ts index b3fcc8df1b0..71ec6e05015 100644 --- a/browser_tests/fixtures/selectors.ts +++ b/browser_tests/fixtures/selectors.ts @@ -9,7 +9,8 @@ export const TestIds = { }, agent: { conversationScroll: 'agent-conversation-scroll', - activityTrace: 'agent-activity-trace' + activityTrace: 'agent-activity-trace', + thinkingShortened: 'agent-thinking-shortened' }, sidebar: { toolbar: 'side-toolbar', diff --git a/browser_tests/tests/agent/agentThinkingShortenedNotice.spec.ts b/browser_tests/tests/agent/agentThinkingShortenedNotice.spec.ts new file mode 100644 index 00000000000..255f9e34814 --- /dev/null +++ b/browser_tests/tests/agent/agentThinkingShortenedNotice.spec.ts @@ -0,0 +1,80 @@ +import { expect } from '@playwright/test' + +import { promptHistoryTest as test } from '@e2e/fixtures/agentPromptHistoryFixture' +import enMessages from '@/locales/en/main.json' with { type: 'json' } +import type { PersistedThinkingEntry } from '@/workbench/extensions/agent/schemas/agentApiSchema' + +test.describe.configure({ timeout: 120_000 }) +test.use({ connectWebSocketToServer: false }) + +const cutRound: PersistedThinkingEntry = { + text: 'Picking an upscaler, then', + truncated: true +} +const wholeRound: PersistedThinkingEntry = { text: 'Reading the workflow.' } + +test( + 'BE-24672: tells the reader a reloaded reasoning trace was shortened', + { tag: ['@cloud', '@ui'] }, + async ({ agentPanel, promptHistory, workflowSelection }) => { + await test.step('completes a turn the server stored with a cut round', async () => { + await agentPanel.open() + await agentPanel.chooseWorkflow() + await expect.poll(() => workflowSelection.savedPaths.length).toBe(1) + workflowSelection.finishSave(true) + await agentPanel.sendMessage('Upscale it') + await expect.poll(() => promptHistory.requests.length).toBe(1) + + promptHistory.completeLatestTurn({ + text: 'Done.', + thinking: [wholeRound, cutRound] + }) + await agentPanel.stopButton.click() + }) + + await test.step('reloads the persisted transcript', async () => { + await agentPanel.reload() + }) + + await test.step('names the shortening once, on the round that was cut', async () => { + await agentPanel.openWorkSummary() + await expect(agentPanel.thinkingShortenedNotices).toHaveText([ + enMessages.agent.thinkingShortened + ]) + await expect(agentPanel.activityRows.last()).toContainText(cutRound.text) + }) + } +) + +test( + 'BE-24672: stays silent when the reloaded reasoning trace is whole', + { tag: ['@cloud', '@ui'] }, + async ({ agentPanel, promptHistory, workflowSelection }) => { + await test.step('completes a turn the server stored whole', async () => { + await agentPanel.open() + await agentPanel.chooseWorkflow() + await expect.poll(() => workflowSelection.savedPaths.length).toBe(1) + workflowSelection.finishSave(true) + await agentPanel.sendMessage('Upscale it') + await expect.poll(() => promptHistory.requests.length).toBe(1) + + promptHistory.completeLatestTurn({ + text: 'Done.', + thinking: [wholeRound] + }) + await agentPanel.stopButton.click() + }) + + await test.step('reloads the persisted transcript', async () => { + await agentPanel.reload() + }) + + await test.step('shows the round with no shortening notice', async () => { + await agentPanel.openWorkSummary() + await expect(agentPanel.activityRows.last()).toContainText( + wholeRound.text + ) + await expect(agentPanel.thinkingShortenedNotices).toHaveCount(0) + }) + } +) diff --git a/src/locales/en/main.json b/src/locales/en/main.json index e52aac4dfab..3a984cb66b9 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -6250,6 +6250,7 @@ "viewAddedNodes": "View node | View nodes", "stopShortcut": "Esc", "thinking": "Thinking...", + "thinkingShortened": "Reasoning shortened: the rest was too long to save.", "working": "Working...", "helpful": "Helpful", "notHelpful": "Not helpful", diff --git a/src/workbench/extensions/agent/components/agent/message/ActivityTrace.test.ts b/src/workbench/extensions/agent/components/agent/message/ActivityTrace.test.ts new file mode 100644 index 00000000000..02be5d9427b --- /dev/null +++ b/src/workbench/extensions/agent/components/agent/message/ActivityTrace.test.ts @@ -0,0 +1,35 @@ +import { render, screen } from '@testing-library/vue' +import { describe, expect, it } from 'vitest' + +import { i18n } from '@/i18n' +import type { ActivityPart } from '@/workbench/extensions/agent/services/agent/agentMessageParts' + +import ActivityTrace from './ActivityTrace.vue' + +function renderTrace(parts: ActivityPart[]) { + return render(ActivityTrace, { + props: { parts }, + global: { plugins: [i18n] } + }) +} + +describe('ActivityTrace', () => { + it('BE-24672: says the reasoning was shortened where the stored thinking stops being whole', () => { + renderTrace([ + { type: 'thinking', text: 'Round one.', state: 'done' }, + { type: 'thinking', text: 'Round two…', state: 'done', truncated: true } + ]) + + const notices = screen.getAllByTestId('agent-thinking-shortened') + expect(notices).toHaveLength(1) + expect(notices[0].textContent).toBe( + 'Reasoning shortened: the rest was too long to save.' + ) + }) + + it('shows no notice for a whole trace', () => { + renderTrace([{ type: 'thinking', text: 'Round one.', state: 'done' }]) + + expect(screen.queryByTestId('agent-thinking-shortened')).toBeNull() + }) +}) diff --git a/src/workbench/extensions/agent/components/agent/message/ActivityTrace.vue b/src/workbench/extensions/agent/components/agent/message/ActivityTrace.vue index 71b8dec01eb..db12f2d6763 100644 --- a/src/workbench/extensions/agent/components/agent/message/ActivityTrace.vue +++ b/src/workbench/extensions/agent/components/agent/message/ActivityTrace.vue @@ -81,7 +81,7 @@ function rowSignature(row: ActivityRow): string { row.canvasConfirmed, row.count ]) - : `think:${row.state}:${row.text}` + : `think:${row.state}:${row.truncated === true}:${row.text}` } @@ -105,13 +105,20 @@ function rowSignature(row: ActivityRow): string { />
- {{ row.text || t('agent.thinking') }} +
+ {{ row.text || t('agent.thinking') }} + {{ t('agent.thinkingShortened') }} +