Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions wework/src/components/chat/MessageList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('MessageList', () => {
expect(await screen.findByTestId('message-selection-actions')).toBeInTheDocument()
})

test('renders generated image artifacts from image generation blocks', () => {
test('renders generated image artifacts and opens an enlarged preview', async () => {
render(
<MessageList
messages={[
Expand All @@ -163,7 +163,8 @@ describe('MessageList', () => {
toolName: 'image_generation',
renderPayload: {
kind: 'image_generation',
imageBase64: 'aW1hZ2U=',
imageBase64:
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg==',
revisedPrompt: 'Minimal dashboard concept',
},
status: 'done',
Expand All @@ -175,9 +176,24 @@ describe('MessageList', () => {
/>
)

const image = screen.getByTestId('generated-image')
expect(image).toHaveAttribute('src', 'data:image/png;base64,aW1hZ2U=')
const image = await screen.findByTestId('generated-image')
expect(image).toHaveAttribute(
'src',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg=='
)
expect(image).toHaveAttribute('alt', 'Minimal dashboard concept')

await userEvent.click(screen.getByTestId('generated-image-preview-button'))

expect(await screen.findByTestId('attachment-image-lightbox')).toBeInTheDocument()
expect(await screen.findByTestId('attachment-image-lightbox-image')).toHaveAttribute(
'src',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg=='
)
expect(screen.getByTestId('attachment-image-lightbox-image')).toHaveAttribute(
'alt',
'Minimal dashboard concept'
)
})

test('marks message rows for offscreen rendering containment with intrinsic sizes', () => {
Expand Down
57 changes: 51 additions & 6 deletions wework/src/components/chat/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,19 @@ interface GeneratedImageArtifact {
alt: string
}

function generatedImageAttachment(image: GeneratedImageArtifact, index: number): Attachment {
return {
id: index + 1,
filename: image.alt,
file_size: 0,
mime_type: 'image/png',
status: 'ready',
file_extension: '.png',
created_at: '',
local_preview_url: image.src,
}
}

function getGeneratedImages(blocks: ProcessingBlock[]): GeneratedImageArtifact[] {
return blocks.flatMap(block => {
if (block.type !== 'tool' || block.toolName !== 'image_generation') return []
Expand All @@ -1845,24 +1858,56 @@ function getGeneratedImages(blocks: ProcessingBlock[]): GeneratedImageArtifact[]
}

function GeneratedImageGallery({ images }: { images: GeneratedImageArtifact[] }) {
const attachments = images.map(generatedImageAttachment)

return (
<div
className="mb-3 grid max-w-3xl grid-cols-1 gap-3 sm:grid-cols-2"
data-testid="generated-image-gallery"
>
{images.map(image => (
<img
{images.map((image, index) => (
<GeneratedImagePreview
key={image.id}
src={image.src}
alt={image.alt}
className="h-auto w-full rounded-lg border border-border bg-surface object-contain"
data-testid="generated-image"
image={image}
index={index}
galleryAttachments={attachments}
/>
))}
</div>
)
}

function GeneratedImagePreview({
image,
index,
galleryAttachments,
}: {
image: GeneratedImageArtifact
index: number
galleryAttachments: Attachment[]
}) {
const { id, src, alt } = image
const attachment = useMemo(
() => generatedImageAttachment({ id, src, alt }, index),
[alt, id, index, src]
)

return (
<AttachmentImagePreview
attachment={attachment}
galleryAttachments={galleryAttachments}
galleryIndex={index}
buttonTestId="generated-image-preview-button"
imageTestId="generated-image"
loadingTestId="generated-image-loading"
errorTestId="generated-image-error"
imageClassName="h-auto w-full rounded-lg border border-border bg-surface object-contain"
placeholderClassName="flex min-h-40 w-full items-center justify-center rounded-lg border border-border bg-surface text-text-muted"
buttonClassName="block w-full cursor-zoom-in p-0 text-left"
/>
)
}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
function ContentTruncatedNotice({
originalChars,
onLoadFullTranscript,
Expand Down
Loading