Skip to content

Add image extraction and Images tab to DetailsView - #142

Open
Valyay wants to merge 1 commit into
mainfrom
images-tab
Open

Add image extraction and Images tab to DetailsView#142
Valyay wants to merge 1 commit into
mainfrom
images-tab

Conversation

@Valyay

@Valyay Valyay commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Adds end-to-end image support to the trace viewer: pure image-detection helpers in @evilmartians/agent-prism-data, an Images tab in DetailsView that surfaces images found in a span, plus the supporting ImageBadge and ImageViewer/ImageGallery components. The tab is shown only when the span actually exposes images, and stays hidden otherwise.

Ported from the internal agent-prism-saas repo (PR 3 of the open-source port backlog).

What's included

packages/data — pure, unit-tested helpers

New src/common/extract-image-paths.ts:

  • isImageSource — recognizes data URIs and image file extensions (case-insensitive)
  • extractImagePaths — pulls images out of fbase64 data URLs from Anthropic-style imagecontent blocks (defaults media type to image/png), file paths via regex, and inline data:image/...;base64,... URLs; deduplicates the result
  • extractAttributeImages — reads the JSON array carried on the claude_code.images span attribute; returns [] when absent or malformed
  • spanHasImages — predicate mirroring the tab's extraction, used to gate tab visibility

Covered by 11 vitest cases.

packages/ui — components

  • ImageBadge — badge shown on spans that carry images
  • ImageViewer / ImageGallery — image preview with expand-to-modal, loading and error states
  • DetailsView/DetailsViewImagesTab — renders input/output image galleries and the raw image-path list
  • DetailsView — adds the conditional Images tab, gated on spanHasImages(data)

All three components (and their ?raw source strings) are exported from the UI barrel.

packages/storybook

  • New DetailsViewImagesTab.stories.tsx — input/output paths, a real base64 image, and the empty state
  • DetailsView.stories.tsx — a WithImages story demonstrating the gated tab

Design notes

  • Image-detection logic lives in data (pure, DOM-free, fast to test) while rendering stays in ui. The spanHasImages predicate is the seam that lets tab-visibility be decided and tested without React.
  • Tab visibility is gated at the tab level in DetailsView (a pure function of the span), rather than only showing an empty state inside the tab.
  • ImageBadge uses the repo's Badge idiom (unstyled + cn(...)) so its color classes don't collide with Badge's default background.

Verification

  • eslint . — clean (0 errors)
  • prettier --check — clean
  • Full pnpm build green: types → data → ui → storybook → saas, including storybook build
  • vitest — 11/11 new tests pass (368 in packages/data)

Extract pure image-detection helpers (isImageSource, extractImagePaths,
extractAttributeImages, spanHasImages) into packages/data with vitest
coverage. Add ImageBadge, ImageViewer/ImageGallery, and a
DetailsViewImagesTab that surfaces images scraped from a span's
input/output and the claude_code.images attribute. The Images tab is
shown in DetailsView only when the span actually exposes images.
@Valyay
Valyay requested a review from Copilot July 8, 2026 15:53
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Valyay, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 11 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 477dc090-95fb-40bc-930f-1c1acb0b472e

📥 Commits

Reviewing files that changed from the base of the PR and between dd8b685 and f28ee87.

📒 Files selected for processing (10)
  • packages/data/src/common/extract-image-paths.test.ts
  • packages/data/src/common/extract-image-paths.ts
  • packages/data/src/index.ts
  • packages/storybook/src/stories/DetailsView.stories.tsx
  • packages/storybook/src/stories/DetailsViewImagesTab.stories.tsx
  • packages/ui/src/components/DetailsView/DetailsView.tsx
  • packages/ui/src/components/DetailsView/DetailsViewImagesTab.tsx
  • packages/ui/src/components/ImageBadge.tsx
  • packages/ui/src/components/ImageViewer.tsx
  • packages/ui/src/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch images-tab

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end image support to the trace viewer by introducing pure image-extraction helpers in packages/data and surfacing extracted images in the UI via a new conditional Images tab in DetailsView, plus supporting viewer/badge components and Storybook coverage.

Changes:

  • Added image-detection/extraction utilities (extractImagePaths, extractAttributeImages, spanHasImages) with new vitest coverage in packages/data.
  • Introduced UI components for displaying images (ImageViewer/ImageGallery) and an Images tab (DetailsViewImagesTab), then gated the tab in DetailsView.
  • Exported new UI components from the UI barrel and added Storybook stories demonstrating image and empty states.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/ui/src/index.ts Exports new image-related UI components and their ?raw sources.
packages/ui/src/components/ImageViewer.tsx Adds image preview/gallery UI with modal expansion and loading/error states.
packages/ui/src/components/ImageBadge.tsx Adds a badge component for spans that carry images.
packages/ui/src/components/DetailsView/DetailsViewImagesTab.tsx Adds the Images tab content rendering (input/output galleries + paths list).
packages/ui/src/components/DetailsView/DetailsView.tsx Adds conditional Images tab visibility via spanHasImages.
packages/storybook/src/stories/DetailsViewImagesTab.stories.tsx Adds Stories for the Images tab scenarios (input/output, attributes, empty).
packages/storybook/src/stories/DetailsView.stories.tsx Adds a WithImages story demonstrating the gated Images tab.
packages/data/src/index.ts Exports the new image-extraction helpers from the data package.
packages/data/src/common/extract-image-paths.ts Implements new pure image-detection/extraction logic and the spanHasImages predicate.
packages/data/src/common/extract-image-paths.test.ts Adds unit tests covering new image helper behaviors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 106 to +111
const [tab, setTab] = useState<DetailsViewTab>(defaultTab);

const tabItems = useMemo(
() => (spanHasImages(data) ? [...TAB_ITEMS, IMAGES_TAB_ITEM] : TAB_ITEMS),
[data],
);
Comment on lines +168 to +170
onKeyDown={
expandable ? (e) => e.key === "Enter" && handleClick() : undefined
}
Comment on lines +110 to +113
const [isExpanded, setIsExpanded] = useState(false);
const [hasError, setHasError] = useState(false);
const [isLoading, setIsLoading] = useState(true);

className,
...rest
}: ImageBadgeProps): ReactElement => {
const label = count && count > 1 ? `${count} Images` : "Image";
const buildEntries = (paths: string[], label: "Input" | "Output") =>
paths.map((src) => ({
src,
caption: `${label}: ${src.split("/").pop() || src}`,
Comment on lines +37 to +48
function isImageContentBlock(obj: unknown): obj is ImageContentBlock {
return (
typeof obj === "object" &&
obj !== null &&
"type" in obj &&
(obj as { type: unknown }).type === "image" &&
"source" in obj &&
typeof (obj as { source: unknown }).source === "object" &&
(obj as { source: { data: unknown } }).source !== null &&
"data" in (obj as { source: object }).source
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants