Phase 1: Refactor all 16 element component interfaces to use MCP SDK types

Replace ad-hoc local type definitions in element components with real
MCP SDK types and Inspector wrapper types from core/mcp/types.ts:

Schema-typed primitives:
- LogLevelBadge: LogLevel → LoggingLevel (SDK)
- TransportBadge: "stdio"|"http" → ServerType (core), add sse/streamable-http
- TaskStatusBadge: local TaskStatus → SDK TaskStatus (working/input_required/...)
- ServerStatusIndicator: inline union → ConnectionStatus (core), "failed"→"error"

MCP wrapper consumers:
- AnnotationBadge: label+variant → facet+value with SDK Role type
- CapabilityItem: name:string → capability:keyof ServerCapabilities|ClientCapabilities
- LogEntry: flat props → entry:{receivedAt:Date, params:LoggingMessageNotification["params"]}
- MessageBubble: flat props → message:SamplingMessage|PromptMessage
- ProgressDisplay: flat props → params:ProgressNotification["params"]

Composite-input elements:
- ContentViewer: type+content+mimeType → block:ContentBlock (SDK discriminated union)
- InlineError: message+details → error:{message,data?}
- ConnectionToggle: checked+loading+onChange → status:ConnectionStatus+onConnect/onDisconnect

Also updates all group/screen/view consumers to keep the build green,
and renames CSS variable --inspector-status-failed → --inspector-status-error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-04-16 22:25:23 -04:00
commit 2d4fca4fa6
2 changed files with 905 additions and 648 deletions

View file

@ -12,28 +12,39 @@ type Story = StoryObj<typeof MessageBubble>;
export const UserText: Story = {
args: {
index: 0,
role: "user",
content: "Hello, my name is John and I like cats",
message: {
role: "user",
content: { type: "text", text: "Hello, my name is John and I like cats" },
},
},
};
export const AssistantText: Story = {
args: {
index: 1,
role: "assistant",
content:
"Nice to meet you, John! It's wonderful that you enjoy cats. They're such fascinating and independent creatures. Do you have any cats of your own?",
message: {
role: "assistant",
content: {
type: "text",
text: "Nice to meet you, John! It's wonderful that you enjoy cats. They're such fascinating and independent creatures. Do you have any cats of your own?",
},
},
},
};
export const UserWithImage: Story = {
args: {
index: 0,
role: "user",
content: "Check this out",
imageContent: {
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
mimeType: "image/png",
message: {
role: "user",
content: [
{ type: "text", text: "Check this out" },
{
type: "image",
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
mimeType: "image/png",
},
],
},
},
};
@ -41,8 +52,12 @@ export const UserWithImage: Story = {
export const LongMessage: Story = {
args: {
index: 0,
role: "user",
content:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.",
message: {
role: "user",
content: {
type: "text",
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
},
},
},
};

View file

@ -1,12 +1,13 @@
import { Group, Image, Paper, Stack, Text } from "@mantine/core";
import type {
PromptMessage,
SamplingMessage,
} from "@modelcontextprotocol/sdk/types.js";
import { CopyButton } from "../CopyButton/CopyButton";
export interface MessageBubbleProps {
index: number;
role: "user" | "assistant";
content: string;
imageContent?: { data: string; mimeType: string };
audioContent?: { data: string; mimeType: string };
message: SamplingMessage | PromptMessage;
}
function buildDataUri(mimeType: string, data: string): string {
@ -21,6 +22,41 @@ function formatQuotedContent(content: string): string {
return `"${content}"`;
}
interface ContentBlockRendered {
text: string;
imageUri?: string;
audioUri?: string;
audioMime?: string;
}
function extractContent(
message: SamplingMessage | PromptMessage,
): ContentBlockRendered {
const content = message.content;
const blocks = Array.isArray(content) ? content : [content];
let text = "";
let imageUri: string | undefined;
let audioUri: string | undefined;
let audioMime: string | undefined;
for (const block of blocks) {
switch (block.type) {
case "text":
text += block.text;
break;
case "image":
imageUri = buildDataUri(block.mimeType, block.data);
break;
case "audio":
audioUri = buildDataUri(block.mimeType, block.data);
audioMime = block.mimeType;
break;
}
}
return { text, imageUri, audioUri, audioMime };
}
const BubbleContainer = Paper.withProps({
p: "md",
radius: "md",
@ -38,32 +74,21 @@ const PreviewImage = Image.withProps({
mt: "xs",
});
export function MessageBubble({
index,
role,
content,
imageContent,
audioContent,
}: MessageBubbleProps) {
export function MessageBubble({ index, message }: MessageBubbleProps) {
const { text, imageUri, audioUri, audioMime } = extractContent(message);
return (
<BubbleContainer>
<Stack gap="xs">
<Group justify="space-between">
<RoleLabel>{formatRoleLabel(index, role)}</RoleLabel>
<CopyButton value={content} />
<RoleLabel>{formatRoleLabel(index, message.role)}</RoleLabel>
{text && <CopyButton value={text} />}
</Group>
<Text size="sm">{formatQuotedContent(content)}</Text>
{imageContent && (
<PreviewImage
src={buildDataUri(imageContent.mimeType, imageContent.data)}
/>
)}
{audioContent && (
{text && <Text size="sm">{formatQuotedContent(text)}</Text>}
{imageUri && <PreviewImage src={imageUri} />}
{audioUri && (
<audio controls>
<source
src={buildDataUri(audioContent.mimeType, audioContent.data)}
type={audioContent.mimeType}
/>
<source src={audioUri} type={audioMime} />
</audio>
)}
</Stack>