Skip to content

feat(web): expandable resource_link with read-on-demand (#1449)#1456

Open
cliffhall wants to merge 2 commits into
v2/mainfrom
v2/resource-link-expandable-1449
Open

feat(web): expandable resource_link with read-on-demand (#1449)#1456
cliffhall wants to merge 2 commits into
v2/mainfrom
v2/resource-link-expandable-1449

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #1449

Summary

Replaces V2's placeholder resource_link rendering with a dedicated, Mantine-native ResourceLink element that brings V1's interactive, expandable, click-to-read experience to V2.

Behavior

  • Shows the URI (monospace, link-styled), optional name and description, and a mimeType badge.
  • Expand/collapse affordance (chevron + loading spinner) that is keyboard accessible — a native button gives role, aria-expanded, aria-label, and Enter/Space handling.
  • On first expand, reads the linked resource on demand and renders the full read result inline as formatted JSON under a green "Resource:" label, capped to a max height (400px) with scroll for large results. The fetched result is cached across collapse/expand.

The matching V1 layout (uri / name / description / mime badge / green "Resource:" label / scrollable JSON):

Collapsed cards + one expanded showing the read result ✅ ported

Wiring

Follows the V2 "dumb component + callbacks as props" pattern. The read handler is threaded App → InspectorView → ToolsScreen → ToolResultPanel → ContentViewer → ResourceLink. App supplies a handler returning the ReadResourceResult from inspectorClient.readResource(uri).

Refactor

Extracts the shared resourceContentsToBlock helper into utils/resourceContents.ts (previously private to ResourcePreviewPanel).

Testing

  • New unit tests: ResourceLink (collapsed/expanded/error/cache/non-interactive), resourceContents, and the ContentViewer resource_link wiring.
  • New Storybook stories with play functions for ResourceLink and ContentViewer.
  • Verified the expanded layout visually in Storybook against the target design.
  • npm run validate, npm run test:integration (522), and npm run test:storybook (345) all pass.

🤖 Generated with Claude Code

Replace the placeholder `resource_link` rendering in ContentViewer with a
dedicated, Mantine-native `ResourceLink` element that mirrors V1's behavior:

- Shows uri (monospace, link-styled), optional name/description, and a
  mimeType badge.
- Expand/collapse affordance (chevron + loading spinner) that is keyboard
  accessible (native button: role, aria-expanded, aria-label, Enter/Space).
- On first expand, reads the linked resource on demand via an injected
  callback and renders the full read result inline as formatted JSON under a
  green "Resource:" label, capped to a max height with scroll for large
  results. The fetched result is cached across collapse/expand.

The read handler is threaded as a "dumb component + callback as prop" through
ToolResultPanel → ToolsScreen → InspectorView, with App supplying a handler
that returns the `ReadResourceResult` from `inspectorClient.readResource`.

Also extract the shared `resourceContentsToBlock` helper into
`utils/resourceContents.ts` (previously private to ResourcePreviewPanel).

Tests: unit coverage for ResourceLink (collapsed/expanded/error/cache) and
the ContentViewer wiring, plus Storybook stories with play functions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Jun 12, 2026
A plain ScrollArea with only `mah` does not scroll when its parent (the
content-sized card) has no definite height, so a large read result overflowed
the card instead of scrolling. Switch to ScrollArea.Autosize, which grows with
content up to the max height and then scrolls. Adds a LargeResult story
covering the bounded-scroll behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant