diff --git a/.qwen/e2e-tests/2026-07-31-export-collapsible-tool-output.md b/.qwen/e2e-tests/2026-07-31-export-collapsible-tool-output.md
new file mode 100644
index 00000000000..fc3c7b688dc
--- /dev/null
+++ b/.qwen/e2e-tests/2026-07-31-export-collapsible-tool-output.md
@@ -0,0 +1,83 @@
+# Export Collapsible Tool Output
+
+## Scope
+
+Verify that long shell output and long `think` tool content keep their full
+text in the shared WebUI while remaining collapsed by default. This covers the
+HTML export viewer and the other consumers of `@qwen-code/webui`.
+
+## Baseline
+
+A released global `qwen` executable was not available in this environment, so
+the before-change `/export` dry-run could not be performed. Source inspection
+on `upstream/main` reproduces the loss: `ShellToolCall` and `ThinkToolCall`
+replace content after 500 characters with an ellipsis.
+
+## Manual Scenario
+
+1. Export a session containing a successful Bash or Execute tool call whose
+ output is longer than 500 characters and ends with a unique marker.
+2. Open the exported HTML and find the tool call.
+3. Confirm the output is collapsed and has a `Show more` control.
+4. Expand it and confirm the unique tail marker is visible, then collapse it
+ again.
+5. Repeat with a `think` tool call longer than 500 characters.
+
+## Regression Checks
+
+- Content of exactly 500 characters has no new toggle.
+- Both Bash and Execute variants preserve the full output.
+- A long single-line Shell result remains horizontally scrollable after it is
+ expanded.
+- A collapsible Shell result does not widen the enclosing message container,
+ and its toggle remains inside the visible message bounds.
+- Clicking a shell toggle does not invoke the surrounding OUT-row action.
+- Clicking the shell OUT row still opens the complete output.
+- Error, empty-output, and short-thinking paths remain unchanged.
+- Toggle buttons expose their expanded state to assistive technology.
+
+## Automated Verification
+
+```bash
+cd packages/webui
+npx vitest run \
+ src/components/toolcalls/shared/CollapsibleOutput.test.tsx \
+ src/components/toolcalls/GenericToolCall.test.tsx \
+ src/components/toolcalls/ShellToolCall.test.tsx \
+ src/components/toolcalls/ThinkToolCall.test.tsx
+npm test
+npm run typecheck
+npm run lint
+npm run build
+
+cd ../sdk-typescript
+npm run build
+
+cd ../web-shell
+npm run lint
+npm run typecheck
+npm run test:e2e:smoke
+```
+
+## Results
+
+- Failure-first run: 3 long-output cases failed because their tail markers
+ were absent; the 500-character boundary and short-thinking cases passed.
+- Focused component regression run: 4 files and 9 tests passed.
+- Failure-first Playwright run: both Bash and Execute failed because their
+ output boxes expanded to roughly 5.7k pixels, leaving no internal horizontal
+ overflow to scroll.
+- Post-fix Playwright run: both Bash and Execute passed in real Chromium. The
+ output scroll width exceeds its client width in collapsed and expanded
+ states, the enclosing message has no horizontal overflow, the toggle remains
+ visible, and the output accepts a non-zero horizontal scroll position.
+- Full web-shell Playwright smoke run: 26 tests passed, including both new
+ WebUI layout cases.
+- Full WebUI run: 31 files and 400 tests passed with Node.js 24.
+- WebUI lint, typecheck, and production build passed.
+- Web-shell lint and typecheck passed; the latter was run after generating the
+ SDK declarations required by that package. All changed files pass Prettier.
+- A normal local `/export` smoke test was not used as proof because the
+ generated page loads the published WebUI package from unpkg rather than the
+ worktree bundle. Component tests and the local WebUI build cover this change
+ until a release build is available for the manual scenario.
diff --git a/packages/web-shell/client/e2e/webui-tool-output-layout-harness.html b/packages/web-shell/client/e2e/webui-tool-output-layout-harness.html
new file mode 100644
index 00000000000..d617f4ab955
--- /dev/null
+++ b/packages/web-shell/client/e2e/webui-tool-output-layout-harness.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+ WebUI tool output layout harness
+
+
+
+
+
+
+
diff --git a/packages/web-shell/client/e2e/webui-tool-output-layout-harness.tsx b/packages/web-shell/client/e2e/webui-tool-output-layout-harness.tsx
new file mode 100644
index 00000000000..e080a0ac181
--- /dev/null
+++ b/packages/web-shell/client/e2e/webui-tool-output-layout-harness.tsx
@@ -0,0 +1,38 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import React from 'react';
+import ReactDOM from 'react-dom/client';
+import { ChatViewer, type ChatMessageData } from '@qwen-code/webui';
+
+const params = new URLSearchParams(window.location.search);
+const kind = params.get('kind') === 'execute' ? 'execute' : 'bash';
+const output = `${'0123456789'.repeat(82)}__${kind.toUpperCase()}_TAIL__`;
+
+const message: ChatMessageData = {
+ uuid: `${kind}-layout-message`,
+ timestamp: '2026-07-31T00:00:00.000Z',
+ type: 'tool_call',
+ toolCall: {
+ toolCallId: `${kind}-layout-tool-call`,
+ kind,
+ title: 'Run layout regression fixture',
+ status: 'completed',
+ rawInput: { command: 'printf long-output' },
+ content: [
+ {
+ type: 'content',
+ content: { type: 'text', text: output },
+ },
+ ],
+ },
+};
+
+ReactDOM.createRoot(document.getElementById('root')!).render(
+
+
+ ,
+);
diff --git a/packages/web-shell/client/e2e/webui-tool-output-layout.spec.ts b/packages/web-shell/client/e2e/webui-tool-output-layout.spec.ts
new file mode 100644
index 00000000000..22e7367342c
--- /dev/null
+++ b/packages/web-shell/client/e2e/webui-tool-output-layout.spec.ts
@@ -0,0 +1,74 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { expect, test, type Locator } from '@playwright/test';
+
+for (const kind of ['bash', 'execute'] as const) {
+ test(`keeps collapsible ${kind} output inside the message layout @smoke`, async ({
+ page,
+ }) => {
+ await page.setViewportSize({ width: 800, height: 900 });
+ await page.goto(`/e2e/webui-tool-output-layout-harness.html?kind=${kind}`);
+
+ const messages = page.locator('.chat-viewer-messages');
+ const output = page.locator(`.${kind}-toolcall-output-subtle`);
+ const toggle = page.locator('button[aria-expanded]');
+
+ await expect(messages).toBeVisible();
+ await expect(output).toBeVisible();
+ await expect(toggle).toBeVisible();
+ await expect(toggle).toHaveAttribute('aria-label', 'Expand output');
+
+ const collapsed = await readOverflowMetrics(messages, output);
+ expect(collapsed.outputScrollWidth).toBeGreaterThan(
+ collapsed.outputClientWidth,
+ );
+ expect(collapsed.messagesScrollWidth).toBe(collapsed.messagesClientWidth);
+
+ const messagesBox = await messages.boundingBox();
+ const toggleBox = await toggle.boundingBox();
+ if (!messagesBox || !toggleBox) {
+ throw new Error('Expected visible message and toggle bounding boxes.');
+ }
+ expect(toggleBox.x).toBeGreaterThanOrEqual(messagesBox.x);
+ expect(toggleBox.x + toggleBox.width).toBeLessThanOrEqual(
+ messagesBox.x + messagesBox.width,
+ );
+
+ await toggle.click();
+ await expect(toggle).toHaveAttribute('aria-expanded', 'true');
+
+ const expanded = await readOverflowMetrics(messages, output);
+ expect(expanded.outputScrollWidth).toBeGreaterThan(
+ expanded.outputClientWidth,
+ );
+ expect(expanded.messagesScrollWidth).toBe(expanded.messagesClientWidth);
+
+ const reachableScrollLeft = await output.evaluate((element) => {
+ element.scrollLeft = element.scrollWidth;
+ return element.scrollLeft;
+ });
+ expect(reachableScrollLeft).toBeGreaterThan(0);
+ });
+}
+
+async function readOverflowMetrics(messages: Locator, output: Locator) {
+ const messagesMetrics = await messages.evaluate((element) => ({
+ clientWidth: element.clientWidth,
+ scrollWidth: element.scrollWidth,
+ }));
+ const outputMetrics = await output.evaluate((element) => ({
+ clientWidth: element.clientWidth,
+ scrollWidth: element.scrollWidth,
+ }));
+
+ return {
+ messagesClientWidth: messagesMetrics.clientWidth,
+ messagesScrollWidth: messagesMetrics.scrollWidth,
+ outputClientWidth: outputMetrics.clientWidth,
+ outputScrollWidth: outputMetrics.scrollWidth,
+ };
+}
diff --git a/packages/webui/src/components/toolcalls/GenericToolCall.test.tsx b/packages/webui/src/components/toolcalls/GenericToolCall.test.tsx
new file mode 100644
index 00000000000..e4bbc64e752
--- /dev/null
+++ b/packages/webui/src/components/toolcalls/GenericToolCall.test.tsx
@@ -0,0 +1,90 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+// @vitest-environment jsdom
+
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { GenericToolCall } from './GenericToolCall.js';
+
+describe('GenericToolCall collapsible output', () => {
+ let container: HTMLDivElement | null = null;
+ let root: Root | null = null;
+
+ beforeEach(() => {
+ (
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true;
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ });
+
+ afterEach(() => {
+ if (root) {
+ act(() => root?.unmount());
+ root = null;
+ }
+ if (container) {
+ container.remove();
+ container = null;
+ }
+ });
+
+ const renderOutput = (output: string) => {
+ act(() => {
+ root?.render(
+ ,
+ );
+ });
+ };
+
+ it('preserves and collapses output longer than 400 characters', () => {
+ const tailMarker = '__GENERIC_TAIL__';
+ renderOutput(`${'x'.repeat(401)}${tailMarker}`);
+
+ expect(container?.textContent).toContain(tailMarker);
+ const content = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ expect(content.classList.contains('text-[13px]')).toBe(true);
+ expect(content.classList.contains('opacity-90')).toBe(true);
+ expect(content.style.maxHeight).toBe('200px');
+ expect(
+ container?.querySelector('button[aria-label="Expand output"]'),
+ ).not.toBeNull();
+ });
+
+ it('does not add a toggle at the 400-character boundary', () => {
+ const output = 'x'.repeat(400);
+ renderOutput(output);
+
+ expect(container?.textContent).toContain(output);
+ const content = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ expect(content.classList.contains('text-[13px]')).toBe(true);
+ expect(content.classList.contains('opacity-90')).toBe(true);
+ expect(content.style.maxHeight).toBe('');
+ expect(
+ container?.querySelector('button[aria-label="Expand output"]'),
+ ).toBeNull();
+ });
+});
diff --git a/packages/webui/src/components/toolcalls/GenericToolCall.tsx b/packages/webui/src/components/toolcalls/GenericToolCall.tsx
index b73820c754b..d20f7561022 100644
--- a/packages/webui/src/components/toolcalls/GenericToolCall.tsx
+++ b/packages/webui/src/components/toolcalls/GenericToolCall.tsx
@@ -6,8 +6,9 @@
* Generic tool call component - handles all tool call types as fallback
*/
-import { useState, type FC } from 'react';
+import type { FC } from 'react';
import {
+ CollapsibleOutput,
ToolCallContainer,
ToolCallCard,
ToolCallRow,
@@ -20,44 +21,8 @@ import type { BaseToolCallProps } from './shared/index.js';
import { getToolDisplayLabel } from './labelUtils.js';
import { MarkdownRenderer } from '../messages/MarkdownRenderer/MarkdownRenderer.js';
-const COLLAPSED_HEIGHT = 200;
const EXPAND_THRESHOLD = 400;
-const CollapsibleOutput: FC<{ content: string }> = ({ content }) => {
- const [isExpanded, setIsExpanded] = useState(false);
- const isLongContent = content.length > EXPAND_THRESHOLD;
-
- return (
-
-
-
-
- {isLongContent && (
-
- setIsExpanded(!isExpanded)}
- className="text-[var(--app-secondary-foreground)] text-[0.8em] hover:text-[var(--app-primary-foreground)] cursor-pointer bg-transparent border-none px-2 py-1 rounded hover:bg-[var(--app-input-background)] transition-colors"
- >
- {isExpanded ? '▲ Collapse' : '▼ Show more'}
-
-
- )}
-
- );
-};
-
/**
* Generic tool call component that can display any tool call type
* Used as fallback for unknown tool call kinds
@@ -101,7 +66,12 @@ export const GenericToolCall: FC = ({
{operationText}
-
+ EXPAND_THRESHOLD}
+ className="text-[13px] opacity-90"
+ >
+
+
);
diff --git a/packages/webui/src/components/toolcalls/ShellToolCall.css b/packages/webui/src/components/toolcalls/ShellToolCall.css
index bf4ec3c56f6..cc5b6c84123 100644
--- a/packages/webui/src/components/toolcalls/ShellToolCall.css
+++ b/packages/webui/src/components/toolcalls/ShellToolCall.css
@@ -65,6 +65,10 @@
overflow: hidden;
}
+.bash-toolcall-row-content.bash-toolcall-full {
+ min-width: 0;
+}
+
.bash-toolcall-pre {
margin-block: 0;
overflow: hidden;
@@ -89,6 +93,10 @@
box-sizing: border-box;
}
+.bash-toolcall-output-subtle .bash-toolcall-pre {
+ overflow: visible;
+}
+
.bash-toolcall-error-content {
color: #c74e39;
}
@@ -157,6 +165,10 @@
overflow: hidden;
}
+.execute-toolcall-row-content.execute-toolcall-full {
+ min-width: 0;
+}
+
.execute-toolcall-pre {
margin-block: 0;
overflow: hidden;
@@ -180,6 +192,10 @@
box-sizing: border-box;
}
+.execute-toolcall-output-subtle .execute-toolcall-pre {
+ overflow: visible;
+}
+
.execute-toolcall-error-content {
color: #c74e39;
}
diff --git a/packages/webui/src/components/toolcalls/ShellToolCall.stories.tsx b/packages/webui/src/components/toolcalls/ShellToolCall.stories.tsx
index 1ff26c4e330..2f005528698 100644
--- a/packages/webui/src/components/toolcalls/ShellToolCall.stories.tsx
+++ b/packages/webui/src/components/toolcalls/ShellToolCall.stories.tsx
@@ -129,7 +129,7 @@ export const ExecuteWithDescription: Story = {
};
/**
- * Execute variant with long output (truncated)
+ * Execute variant with long, collapsible output
*/
export const ExecuteLongOutput: Story = {
args: {
diff --git a/packages/webui/src/components/toolcalls/ShellToolCall.test.tsx b/packages/webui/src/components/toolcalls/ShellToolCall.test.tsx
new file mode 100644
index 00000000000..f62823a3577
--- /dev/null
+++ b/packages/webui/src/components/toolcalls/ShellToolCall.test.tsx
@@ -0,0 +1,137 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+// @vitest-environment jsdom
+
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { PlatformProvider } from '../../context/PlatformContext.js';
+import { ShellToolCall } from './ShellToolCall.js';
+
+describe('ShellToolCall collapsible output', () => {
+ let container: HTMLDivElement | null = null;
+ let root: Root | null = null;
+
+ beforeEach(() => {
+ (
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true;
+ });
+
+ afterEach(() => {
+ if (root) {
+ act(() => root?.unmount());
+ root = null;
+ }
+ if (container) {
+ container.remove();
+ container = null;
+ }
+ });
+
+ const renderToolCall = (
+ kind: 'bash' | 'execute',
+ output: string,
+ openTempFile = vi.fn(),
+ ) => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+
+ act(() => {
+ root?.render(
+ () => {},
+ openTempFile,
+ }}
+ >
+
+ ,
+ );
+ });
+
+ return openTempFile;
+ };
+
+ it.each(['bash', 'execute'] as const)(
+ 'preserves and expands the full %s output without opening a temp file',
+ (kind) => {
+ const tailMarker = '__OUTPUT_TAIL__';
+ const output = `${'x'.repeat(501)}${tailMarker}`;
+ const openTempFile = renderToolCall(kind, output);
+
+ expect(container?.textContent).toContain(tailMarker);
+
+ const toggle = container?.querySelector(
+ 'button[aria-label="Expand output"]',
+ ) as HTMLButtonElement;
+ expect(toggle).not.toBeNull();
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
+ const collapsibleContent = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ expect(collapsibleContent.style.maxHeight).toBe('60px');
+ expect(collapsibleContent.style.maskImage).toContain('40px');
+ expect(collapsibleContent.style.maskImage).toContain('60px');
+ act(() => {
+ toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(toggle.getAttribute('aria-expanded')).toBe('true');
+ expect(toggle.textContent).toContain('Collapse');
+ expect(collapsibleContent.style.maxHeight).toBe('');
+ expect(openTempFile).not.toHaveBeenCalled();
+
+ act(() => {
+ toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
+ expect(collapsibleContent.style.maxHeight).toBe('60px');
+ expect(openTempFile).not.toHaveBeenCalled();
+
+ const outRow = Array.from(
+ container?.querySelectorAll(`.${kind}-toolcall-row`) ?? [],
+ ).find((row) => row.textContent?.includes('OUT'));
+ expect(outRow).toBeDefined();
+
+ act(() => {
+ outRow?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(openTempFile).toHaveBeenCalledWith(
+ output,
+ `${kind}-output-${kind}-1`,
+ );
+ },
+ );
+
+ it('does not add a toggle at the 500-character boundary', () => {
+ renderToolCall('bash', 'x'.repeat(500));
+
+ expect(
+ container?.querySelector('button[aria-label="Expand output"]'),
+ ).toBeNull();
+ });
+});
diff --git a/packages/webui/src/components/toolcalls/ShellToolCall.tsx b/packages/webui/src/components/toolcalls/ShellToolCall.tsx
index 37a5fbe7316..7dc3aa510a4 100644
--- a/packages/webui/src/components/toolcalls/ShellToolCall.tsx
+++ b/packages/webui/src/components/toolcalls/ShellToolCall.tsx
@@ -9,6 +9,7 @@
import type { FC } from 'react';
import {
+ CollapsibleOutput,
ToolCallContainer,
CopyButton,
safeTitle,
@@ -211,8 +212,12 @@ const ShellToolCallImpl: FC = ({
// Success with output
if (textOutputs.length > 0) {
const output = textOutputs.join('\n');
- const truncatedOutput =
- output.length > 500 ? output.substring(0, 500) + '...' : output;
+ const isCollapsible = output.length > 500;
+ const outputContent = (
+
+ );
return (
= ({
style={{ cursor: 'pointer' }}
>
OUT
-
-
-
- {truncatedOutput}
-
-
+
+ {isCollapsible ? (
+
+ {outputContent}
+
+ ) : (
+ outputContent
+ )}
diff --git a/packages/webui/src/components/toolcalls/ThinkToolCall.test.tsx b/packages/webui/src/components/toolcalls/ThinkToolCall.test.tsx
new file mode 100644
index 00000000000..ea2ecce312b
--- /dev/null
+++ b/packages/webui/src/components/toolcalls/ThinkToolCall.test.tsx
@@ -0,0 +1,102 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+// @vitest-environment jsdom
+
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { ThinkToolCall } from './ThinkToolCall.js';
+
+describe('ThinkToolCall collapsible output', () => {
+ let container: HTMLDivElement | null = null;
+ let root: Root | null = null;
+
+ beforeEach(() => {
+ (
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true;
+ });
+
+ afterEach(() => {
+ if (root) {
+ act(() => root?.unmount());
+ root = null;
+ }
+ if (container) {
+ container.remove();
+ container = null;
+ }
+ });
+
+ const renderThoughts = (thoughts: string) => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+
+ act(() => {
+ root?.render(
+ ,
+ );
+ });
+ };
+
+ it('preserves long thoughts and exposes expand and collapse controls', () => {
+ const tailMarker = '__THOUGHT_TAIL__';
+ renderThoughts(`${'x'.repeat(501)}${tailMarker}`);
+
+ expect(container?.textContent).toContain(tailMarker);
+
+ const toggle = container?.querySelector(
+ 'button[aria-label="Expand output"]',
+ ) as HTMLButtonElement;
+ expect(toggle).not.toBeNull();
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
+ const collapsibleContent = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ expect(collapsibleContent.style.maxHeight).toBe('200px');
+
+ act(() => {
+ toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(toggle.getAttribute('aria-expanded')).toBe('true');
+ expect(toggle.textContent).toContain('Collapse');
+ expect(collapsibleContent.style.maxHeight).toBe('');
+
+ act(() => {
+ toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
+ expect(toggle.textContent).toContain('Show more');
+ expect(collapsibleContent.style.maxHeight).toBe('200px');
+ });
+
+ it('keeps short thoughts in the compact layout without a toggle', () => {
+ renderThoughts('short thought');
+
+ expect(container?.textContent).toContain('short thought');
+ expect(container?.querySelector('.toolcall-card')).toBeNull();
+ expect(
+ container?.querySelector('button[aria-label="Expand output"]'),
+ ).toBeNull();
+ });
+});
diff --git a/packages/webui/src/components/toolcalls/ThinkToolCall.tsx b/packages/webui/src/components/toolcalls/ThinkToolCall.tsx
index 7d041d80c34..aecb203b428 100644
--- a/packages/webui/src/components/toolcalls/ThinkToolCall.tsx
+++ b/packages/webui/src/components/toolcalls/ThinkToolCall.tsx
@@ -8,6 +8,7 @@
import type { FC } from 'react';
import {
+ CollapsibleOutput,
ToolCallContainer,
ToolCallCard,
ToolCallRow,
@@ -50,15 +51,23 @@ export const ThinkToolCall: FC = ({
const isLong = thoughts.length > 200;
if (isLong) {
- const truncatedThoughts =
- thoughts.length > 500 ? thoughts.substring(0, 500) + '...' : thoughts;
+ const isCollapsible = thoughts.length > 500;
return (
-
- {truncatedThoughts}
-
+ {isCollapsible ? (
+
+ {thoughts}
+
+ ) : (
+
+ {thoughts}
+
+ )}
);
diff --git a/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.test.tsx b/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.test.tsx
new file mode 100644
index 00000000000..11569a427a2
--- /dev/null
+++ b/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.test.tsx
@@ -0,0 +1,82 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+// @vitest-environment jsdom
+
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { CollapsibleOutput } from './CollapsibleOutput.js';
+
+describe('CollapsibleOutput', () => {
+ let container: HTMLDivElement | null = null;
+ let root: Root | null = null;
+
+ beforeEach(() => {
+ (
+ globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
+ ).IS_REACT_ACT_ENVIRONMENT = true;
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ });
+
+ afterEach(() => {
+ if (root) {
+ act(() => root?.unmount());
+ root = null;
+ }
+ if (container) {
+ container.remove();
+ container = null;
+ }
+ });
+
+ it('toggles the collapsed height while preserving all children', () => {
+ act(() => {
+ root?.render(
+
+ full content with __TAIL__
+ ,
+ );
+ });
+
+ expect(container?.textContent).toContain('__TAIL__');
+ const content = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ const toggle = container?.querySelector(
+ 'button[aria-label="Expand output"]',
+ ) as HTMLButtonElement;
+ expect(content.style.maxHeight).toBe('200px');
+ expect(content.style.maskImage).toContain('140px');
+ expect(content.style.maskImage).toContain('200px');
+ expect(toggle.getAttribute('aria-expanded')).toBe('false');
+
+ act(() => {
+ toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ });
+
+ expect(content.style.maxHeight).toBe('');
+ expect(toggle.getAttribute('aria-expanded')).toBe('true');
+ });
+
+ it('does not clip or show a toggle when content is not collapsible', () => {
+ act(() => {
+ root?.render(
+
+ short content
+ ,
+ );
+ });
+
+ const content = container?.querySelector(
+ '.toolcall-collapsible-output-content',
+ ) as HTMLDivElement;
+ expect(content.style.maxHeight).toBe('');
+ expect(container?.querySelector('button')).toBeNull();
+ });
+});
diff --git a/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.tsx b/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.tsx
new file mode 100644
index 00000000000..4e73f141e01
--- /dev/null
+++ b/packages/webui/src/components/toolcalls/shared/CollapsibleOutput.tsx
@@ -0,0 +1,63 @@
+/**
+ * @license
+ * Copyright 2025 Qwen Team
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { useState, type FC, type ReactNode } from 'react';
+
+interface CollapsibleOutputProps {
+ children: ReactNode;
+ isCollapsible: boolean;
+ collapsedHeight?: number;
+ fadeStart?: number;
+ className?: string;
+}
+
+/**
+ * Renderer-agnostic wrapper for long tool output.
+ */
+export const CollapsibleOutput: FC = ({
+ children,
+ isCollapsible,
+ collapsedHeight = 200,
+ fadeStart = 140,
+ className = '',
+}) => {
+ const [isExpanded, setIsExpanded] = useState(false);
+
+ return (
+
+
+ {children}
+
+ {isCollapsible && (
+
+ {
+ event.stopPropagation();
+ setIsExpanded((expanded) => !expanded);
+ }}
+ aria-expanded={isExpanded}
+ aria-label={isExpanded ? 'Collapse output' : 'Expand output'}
+ className="text-[var(--app-secondary-foreground)] text-[0.8em] hover:text-[var(--app-primary-foreground)] cursor-pointer bg-transparent border-none px-2 py-1 rounded hover:bg-[var(--app-input-background)] transition-colors"
+ >
+ {isExpanded ? '▲ Collapse' : '▼ Show more'}
+
+
+ )}
+
+ );
+};
diff --git a/packages/webui/src/components/toolcalls/shared/index.ts b/packages/webui/src/components/toolcalls/shared/index.ts
index aa1e696e969..8030ec4bfb3 100644
--- a/packages/webui/src/components/toolcalls/shared/index.ts
+++ b/packages/webui/src/components/toolcalls/shared/index.ts
@@ -14,6 +14,7 @@ export {
LocationsList,
} from './LayoutComponents.js';
export type { ToolCallContainerProps } from './LayoutComponents.js';
+export { CollapsibleOutput } from './CollapsibleOutput.js';
// Copy utilities
export { handleCopyToClipboard, CopyButton } from './copyUtils.js';