From 1ee82b7268b4bc2989739182c1ac8f08af5759e2 Mon Sep 17 00:00:00 2001 From: kev1n77 Date: Thu, 29 Oct 2026 09:15:15 +0800 Subject: [PATCH 1/4] feat(flowchat): keep generated image cards open --- .../tool-cards/GenerateImageToolCard.test.tsx | 83 +++++++++++++++++++ .../tool-cards/GenerateImageToolCard.tsx | 68 +++++++++++++++ .../src/flow_chat/tool-cards/index.test.ts | 6 ++ src/web-ui/src/flow_chat/tool-cards/index.ts | 3 +- 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx create mode 100644 src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx new file mode 100644 index 0000000000..0093fe7f08 --- /dev/null +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx @@ -0,0 +1,83 @@ +// @vitest-environment jsdom + +import React, { act } from 'react'; +import { createRoot, type Root } from 'react-dom/client'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import type { FlowToolItem } from '../types/flow-chat'; +import { getToolItemCardConfig } from './toolCardMetadata'; +import { GenerateImageToolCard } from './GenerateImageToolCard'; + +vi.mock('@/infrastructure/i18n', () => ({ + useI18n: () => ({ t: (key: string) => key, formatNumber: String }), +})); + +const image = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB'; + +function item(overrides: Partial = {}): FlowToolItem { + return { + id: 'generate-image', + type: 'tool', + toolName: 'generate_image', + status: 'completed', + timestamp: 1, + toolCall: { id: 'generate-image', input: { prompt: 'A red kite over the sea' } }, + toolResult: { + success: true, + result: { path: '/workspace/generated.png', count: 1, model: 'gpt-image-1' }, + imageAttachments: [{ mime_type: 'image/png', data_base64: image }], + }, + ...overrides, + }; +} + +describe('GenerateImageToolCard', () => { + let host: HTMLDivElement; + let root: Root; + + beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true; + host = document.createElement('div'); + document.body.append(host); + root = createRoot(host); + }); + + afterEach(() => { + act(() => root.unmount()); + host.remove(); + }); + + function render(toolItem: FlowToolItem = item()) { + act(() => root.render( + , + )); + } + + it('shows generated image attachments in an always-open card', () => { + render(); + + const imageElement = host.querySelector('[data-openbitfun-part="media"] img'); + expect(imageElement?.src).toBe(`data:image/png;base64,${image}`); + expect(host.querySelector('[data-openbitfun-part="details"]')).not.toBeNull(); + expect(host.querySelector('[data-openbitfun-expandable="false"]')).not.toBeNull(); + expect(host.querySelector('[aria-expanded]')).toBeNull(); + }); + + it('does not hide the image when the card surface is clicked', () => { + render(); + + const surface = host.querySelector('[data-openbitfun-part="surface"]'); + expect(surface).not.toBeNull(); + act(() => surface?.click()); + expect(host.querySelector('[data-openbitfun-part="media"] img')).not.toBeNull(); + }); + + it('keeps failures visible while preserving the image card anatomy', () => { + render(item({ + status: 'error', + toolResult: { success: false, error: 'Image service unavailable', result: null }, + })); + + expect(host.querySelector('[data-openbitfun-part="error"]')?.textContent).toContain('Image service unavailable'); + expect(host.querySelector('[data-openbitfun-part="surface"]')).not.toBeNull(); + }); +}); diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx new file mode 100644 index 0000000000..7f60619244 --- /dev/null +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx @@ -0,0 +1,68 @@ +import React, { useMemo } from 'react'; +import { + ImageAnalysisToolCard, + type SemanticToolCardProps, +} from '@openbitfun/ui/flow-chat'; +import { useI18n } from '@/infrastructure/i18n'; +import type { ToolCardProps } from '../types/flow-chat'; +import { buildBuiltinToolCardModel } from './builtinToolCardModel'; +import { getToolCardStatusDescription } from './toolCardStatus'; +import { useToolCardHeightContract } from './useToolCardHeightContract'; + +/** + * Generated images are user-facing output, so keep their preview visible in + * the transcript instead of putting it behind the regular tool disclosure. + */ +export const GenerateImageToolCard: React.FC = ({ toolItem }) => { + const { t, formatNumber } = useI18n('flow-chat'); + const model = useMemo( + () => buildBuiltinToolCardModel(toolItem, 'generate_image', t, formatNumber), + [toolItem, t, formatNumber], + ); + const { cardRootRef, dispatchToolCardToggle } = useToolCardHeightContract({ + toolId: toolItem.id, + toolName: toolItem.toolName, + }); + + const media = model.imageSources.length > 0 + ? model.imageSources.map((source, index) => ( + {model.summary + )) + : undefined; + + const card: SemanticToolCardProps = { + status: model.status, + action: model.action, + attention: model.attention, + summary: model.summary, + resultSummary: model.resultSummary, + outcome: model.outcome, + fields: model.fields, + sections: model.sections, + emptyContent: model.emptyContent, + error: model.error, + media, + detailsAvailable: Boolean(media || model.rawResult !== undefined), + // A generated image is the result of this tool call, so it stays visible + // and this card deliberately has no disclosure callback. + isExpanded: true, + statusDescription: getToolCardStatusDescription(model.status, t, model.error), + }; + + return ( +
+ +
+ ); +}; diff --git a/src/web-ui/src/flow_chat/tool-cards/index.test.ts b/src/web-ui/src/flow_chat/tool-cards/index.test.ts index 1a8e43a04b..e6bc700c57 100644 --- a/src/web-ui/src/flow_chat/tool-cards/index.test.ts +++ b/src/web-ui/src/flow_chat/tool-cards/index.test.ts @@ -17,6 +17,7 @@ import { AgentInteractionToolCard } from './AgentInteractionToolCard'; import { OpenBitFunControlToolCard } from './OpenBitFunControlToolCard'; import { DefaultToolCard } from './DefaultToolCard'; import { compatibilityToolPresentationOwners, genericToolNames } from '@openbitfun/flow-chat-presentation/registry'; +import { GenerateImageToolCard } from './GenerateImageToolCard'; // These cards remain available for rendering historical or explicitly // configured tool calls, but are no longer part of the current presentation @@ -30,6 +31,11 @@ describe('tool card registry', () => { expect(usesDefaultToolCard('OpenBitFunControl')).toBe(false); expect(isCollapsibleTool('OpenBitFunControl')).toBe(false); }); + + it('uses the dedicated always-open image card for generated images', () => { + expect(getToolCardComponent('generate_image')).toBe(GenerateImageToolCard); + expect(isCollapsibleTool('generate_image')).toBe(false); + }); it('projects managed Review workers through the unified coverage card', () => { expect(getToolCardComponent('LaunchReviewAgent')).toBe(TaskToolDisplay); }); diff --git a/src/web-ui/src/flow_chat/tool-cards/index.ts b/src/web-ui/src/flow_chat/tool-cards/index.ts index 088a11b3a0..40a4e384ca 100644 --- a/src/web-ui/src/flow_chat/tool-cards/index.ts +++ b/src/web-ui/src/flow_chat/tool-cards/index.ts @@ -80,6 +80,7 @@ import { OpenBitFunControlToolCard } from './OpenBitFunControlToolCard'; import { ListModelsToolCard } from './ListModelsToolCard'; import { ControlHubToolCard } from './ControlHubToolCard'; import { BuiltinToolCard } from './BuiltinToolCard'; +import { GenerateImageToolCard } from './GenerateImageToolCard'; /** * Standard tool adapters backed by concrete `@openbitfun/ui/flow-chat` views. @@ -152,7 +153,7 @@ export const STANDARD_TOOL_CARD_ADAPTERS = { 'AgentDelete': AgentDeleteToolCard, 'SessionHistory': BuiltinToolCard, 'analyze_image': BuiltinToolCard, - 'generate_image': BuiltinToolCard, + 'generate_image': GenerateImageToolCard, 'GetTime': BuiltinToolCard, 'ListMCPResources': BuiltinToolCard, 'ReadMCPResource': BuiltinToolCard, From 39713d49be43381c916dfb2ba9285749e1352b41 Mon Sep 17 00:00:00 2001 From: kev1n77 Date: Thu, 29 Oct 2026 10:54:16 +0800 Subject: [PATCH 2/4] fix(flowchat): fold generated image metadata --- .../tool-cards/GenerateImageToolCard.test.tsx | 13 ++-- .../tool-cards/GenerateImageToolCard.tsx | 66 +++++++++++++------ 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx index 0093fe7f08..2a41ddc6c2 100644 --- a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx @@ -52,23 +52,26 @@ describe('GenerateImageToolCard', () => { )); } - it('shows generated image attachments in an always-open card', () => { + it('shows generated image attachments with metadata collapsed by default', () => { render(); const imageElement = host.querySelector('[data-openbitfun-part="media"] img'); expect(imageElement?.src).toBe(`data:image/png;base64,${image}`); expect(host.querySelector('[data-openbitfun-part="details"]')).not.toBeNull(); - expect(host.querySelector('[data-openbitfun-expandable="false"]')).not.toBeNull(); - expect(host.querySelector('[aria-expanded]')).toBeNull(); + expect(host.querySelector('[data-openbitfun-expandable="true"]')).not.toBeNull(); + expect(host.querySelector('[data-openbitfun-component="disclosure"]')?.getAttribute('data-open')).toBe('false'); }); - it('does not hide the image when the card surface is clicked', () => { + it('keeps metadata folded while allowing the image card to collapse', () => { render(); const surface = host.querySelector('[data-openbitfun-part="surface"]'); expect(surface).not.toBeNull(); + const details = host.querySelector('[data-openbitfun-component="disclosure"] button[aria-expanded]'); + expect(details?.getAttribute('aria-expanded')).toBe('false'); + act(() => surface?.click()); - expect(host.querySelector('[data-openbitfun-part="media"] img')).not.toBeNull(); + expect(host.querySelector('[data-openbitfun-part="expandedCollapse"]')?.getAttribute('data-open')).toBe('false'); }); it('keeps failures visible while preserving the image card anatomy', () => { diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx index 7f60619244..78ed3515e7 100644 --- a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx @@ -1,57 +1,81 @@ import React, { useMemo } from 'react'; import { ImageAnalysisToolCard, + ToolCardDisclosure, + ToolCardFields, + ToolCardSection, + ToolCardText, type SemanticToolCardProps, + type ToolCardField, } from '@openbitfun/ui/flow-chat'; import { useI18n } from '@/infrastructure/i18n'; +import { useToolCardDisclosure } from '../timeline/readerState'; import type { ToolCardProps } from '../types/flow-chat'; import { buildBuiltinToolCardModel } from './builtinToolCardModel'; import { getToolCardStatusDescription } from './toolCardStatus'; import { useToolCardHeightContract } from './useToolCardHeightContract'; /** - * Generated images are user-facing output, so keep their preview visible in - * the transcript instead of putting it behind the regular tool disclosure. + * Generated images stay visible in the expanded result while request metadata + * remains available from a separate, closed-by-default disclosure. */ -export const GenerateImageToolCard: React.FC = ({ toolItem }) => { +export const GenerateImageToolCard: React.FC = ({ toolItem, onExpand }) => { const { t, formatNumber } = useI18n('flow-chat'); + const [isExpanded, setExpanded] = useToolCardDisclosure('isExpanded', true); const model = useMemo( () => buildBuiltinToolCardModel(toolItem, 'generate_image', t, formatNumber), [toolItem, t, formatNumber], ); - const { cardRootRef, dispatchToolCardToggle } = useToolCardHeightContract({ + const { cardRootRef, applyExpandedState, dispatchToolCardToggle } = useToolCardHeightContract({ toolId: toolItem.id, toolName: toolItem.toolName, }); - const media = model.imageSources.length > 0 - ? model.imageSources.map((source, index) => ( - {model.summary - )) - : undefined; + const fields: ToolCardField[] = model.fields.map(({ label, value }) => ({ label, value })); + const metadata = fields.length > 0 || model.sections.length > 0 ? ( + + {fields.length > 0 && } + {model.sections.map(section => ( + + {section.content} + + ))} + + ) : undefined; + const media = model.imageSources.length > 0 || metadata ? ( +
+ {model.imageSources.map((source, index) => ( + {model.summary + ))} + {metadata} +
+ ) : undefined; const card: SemanticToolCardProps = { status: model.status, action: model.action, attention: model.attention, - summary: model.summary, + // Keep the full prompt in the closed metadata disclosure instead of the + // always-visible header summary. + summary: undefined, resultSummary: model.resultSummary, outcome: model.outcome, - fields: model.fields, - sections: model.sections, emptyContent: model.emptyContent, error: model.error, media, detailsAvailable: Boolean(media || model.rawResult !== undefined), - // A generated image is the result of this tool call, so it stays visible - // and this card deliberately has no disclosure callback. - isExpanded: true, + isExpanded, + onToggle: () => applyExpandedState(isExpanded, !isExpanded, setExpanded, { onExpand }), statusDescription: getToolCardStatusDescription(model.status, t, model.error), }; From da51e778c372f8cc3e49b7dddaae38598764301e Mon Sep 17 00:00:00 2001 From: kev1n77 Date: Thu, 29 Oct 2026 11:34:39 +0800 Subject: [PATCH 3/4] fix(flowchat): collapse generated image cards by default --- .../tool-cards/GenerateImageToolCard.test.tsx | 19 ++++++++++--------- .../tool-cards/GenerateImageToolCard.tsx | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx index 2a41ddc6c2..b138007c00 100644 --- a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.test.tsx @@ -52,26 +52,26 @@ describe('GenerateImageToolCard', () => { )); } - it('shows generated image attachments with metadata collapsed by default', () => { + it('keeps the image and metadata inside one collapsed card by default', () => { render(); - const imageElement = host.querySelector('[data-openbitfun-part="media"] img'); - expect(imageElement?.src).toBe(`data:image/png;base64,${image}`); - expect(host.querySelector('[data-openbitfun-part="details"]')).not.toBeNull(); expect(host.querySelector('[data-openbitfun-expandable="true"]')).not.toBeNull(); - expect(host.querySelector('[data-openbitfun-component="disclosure"]')?.getAttribute('data-open')).toBe('false'); + expect(host.querySelector('[data-openbitfun-expanded-shell="false"]')).not.toBeNull(); + expect(host.querySelector('[data-openbitfun-part="media"] img')).toBeNull(); }); - it('keeps metadata folded while allowing the image card to collapse', () => { + it('reveals the image while keeping metadata folded when expanded', () => { render(); const surface = host.querySelector('[data-openbitfun-part="surface"]'); expect(surface).not.toBeNull(); + act(() => surface?.click()); + + const imageElement = host.querySelector('[data-openbitfun-part="media"] img'); + expect(imageElement?.src).toBe(`data:image/png;base64,${image}`); + expect(host.querySelector('[data-openbitfun-expanded-shell="true"]')).not.toBeNull(); const details = host.querySelector('[data-openbitfun-component="disclosure"] button[aria-expanded]'); expect(details?.getAttribute('aria-expanded')).toBe('false'); - - act(() => surface?.click()); - expect(host.querySelector('[data-openbitfun-part="expandedCollapse"]')?.getAttribute('data-open')).toBe('false'); }); it('keeps failures visible while preserving the image card anatomy', () => { @@ -80,6 +80,7 @@ describe('GenerateImageToolCard', () => { toolResult: { success: false, error: 'Image service unavailable', result: null }, })); + act(() => host.querySelector('[data-openbitfun-part="surface"]')?.click()); expect(host.querySelector('[data-openbitfun-part="error"]')?.textContent).toContain('Image service unavailable'); expect(host.querySelector('[data-openbitfun-part="surface"]')).not.toBeNull(); }); diff --git a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx index 78ed3515e7..5d0b844652 100644 --- a/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx +++ b/src/web-ui/src/flow_chat/tool-cards/GenerateImageToolCard.tsx @@ -16,12 +16,12 @@ import { getToolCardStatusDescription } from './toolCardStatus'; import { useToolCardHeightContract } from './useToolCardHeightContract'; /** - * Generated images stay visible in the expanded result while request metadata - * remains available from a separate, closed-by-default disclosure. + * Generated images and request metadata stay inside one collapsible result + * card. The compact header is the default presentation in the transcript. */ export const GenerateImageToolCard: React.FC = ({ toolItem, onExpand }) => { const { t, formatNumber } = useI18n('flow-chat'); - const [isExpanded, setExpanded] = useToolCardDisclosure('isExpanded', true); + const [isExpanded, setExpanded] = useToolCardDisclosure('isExpanded', false); const model = useMemo( () => buildBuiltinToolCardModel(toolItem, 'generate_image', t, formatNumber), [toolItem, t, formatNumber], From 5d0f7cf8d721123919160a8a27c07ebcb89614ff Mon Sep 17 00:00:00 2001 From: kev1n77 Date: Thu, 29 Oct 2026 12:01:53 +0800 Subject: [PATCH 4/4] test(images): refresh image service prompt --- src/apps/desktop/src/api/commands.rs | 2 +- src/crates/adapters/ai-adapters/src/client/image_generation.rs | 2 +- .../components/image-generation/ImageGenerationEditor.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/desktop/src/api/commands.rs b/src/apps/desktop/src/api/commands.rs index 528dfdd638..046964b447 100644 --- a/src/apps/desktop/src/api/commands.rs +++ b/src/apps/desktop/src/api/commands.rs @@ -1260,7 +1260,7 @@ pub async fn test_image_generation_service( request: TestImageGenerationServiceRequest, ) -> Result { const DEFAULT_PROMPT: &str = - "A simple red circle centered on a plain white background, flat vector style"; + "A cute minimalist mascot icon with a rounded-rectangle body, two small friendly oval eyes, and a short top antenna ending in a round joystick knob. Use a playful, harmonious color palette selected randomly for each generation, with no fixed colors. Centered composition, clean uncluttered background, polished product illustration."; let prompt = request .prompt diff --git a/src/crates/adapters/ai-adapters/src/client/image_generation.rs b/src/crates/adapters/ai-adapters/src/client/image_generation.rs index 1ef9d9c4af..168397c07c 100644 --- a/src/crates/adapters/ai-adapters/src/client/image_generation.rs +++ b/src/crates/adapters/ai-adapters/src/client/image_generation.rs @@ -1352,7 +1352,7 @@ mod tests { let response = generate( &target, ImageGenerationRequest { - prompt: "A simple red circle on a white background".to_string(), + prompt: "A cute minimalist mascot icon with a rounded-rectangle body, two small friendly oval eyes, and a short top antenna ending in a round joystick knob. Use a playful, harmonious color palette selected randomly for each generation, with no fixed colors. Centered composition, clean uncluttered background, polished product illustration.".to_string(), size: Some("1024x1024".to_string()), n: Some(1), ..ImageGenerationRequest::default() diff --git a/src/web-ui/src/infrastructure/config/components/image-generation/ImageGenerationEditor.tsx b/src/web-ui/src/infrastructure/config/components/image-generation/ImageGenerationEditor.tsx index 327951b1ad..1f5c928304 100644 --- a/src/web-ui/src/infrastructure/config/components/image-generation/ImageGenerationEditor.tsx +++ b/src/web-ui/src/infrastructure/config/components/image-generation/ImageGenerationEditor.tsx @@ -39,7 +39,7 @@ export default function ImageGenerationEditor({ open, initial, credentials, serv const [outcome, setOutcome] = useState(); const version = useRef(0); const original = useRef(''); - const checkPrompt = 'A simple red circle centered on a plain white background'; + const checkPrompt = 'A cute minimalist mascot icon with a rounded-rectangle body, two small friendly oval eyes, and a short top antenna ending in a round joystick knob. Use a playful, harmonious color palette selected randomly for each generation, with no fixed colors. Centered composition, clean uncluttered background, polished product illustration.'; useEffect(() => { version.current += 1; setOutcome(undefined); setTesting(false); setSaving(false); setTestConfirmOpen(false);