Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Meta, StoryObj } from "@storybook/react-vite";
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
import type {
CreateMessageRequestParams,
CreateMessageResult,
} from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test";
import { InlineSamplingRequest } from "./InlineSamplingRequest";

Expand All @@ -16,13 +19,31 @@ const defaultRequest: CreateMessageRequestParams = {
maxTokens: 1024,
};

const textDraft: CreateMessageResult = {
role: "assistant",
model: "claude-sonnet-4-20250514",
content: {
type: "text",
text: "The code looks good overall. Consider extracting the repeated logic into a helper function and adding type annotations to the public API.",
},
};

const imageDraft: CreateMessageResult = {
role: "assistant",
model: "claude-sonnet-4-20250514",
content: {
type: "image",
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
mimeType: "image/png",
},
};

const meta: Meta<typeof InlineSamplingRequest> = {
title: "Groups/InlineSamplingRequest",
component: InlineSamplingRequest,
args: {
request: defaultRequest,
queuePosition: "1 of 1",
responseText: "",
onAutoRespond: fn(),
onEditAndSend: fn(),
onReject: fn(),
Expand All @@ -49,10 +70,15 @@ export const WithModelHints: Story = {
},
};

export const PrefilledResponse: Story = {
export const WithTextDraft: Story = {
args: {
draftResult: textDraft,
},
};

export const WithNonTextDraft: Story = {
args: {
responseText:
"The code looks good overall. Consider extracting the repeated logic into a helper function.",
draftResult: imageDraft,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
Badge,
Button,
Group,
Paper,
Stack,
Text,
Textarea,
} from "@mantine/core";
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
import { Badge, Button, Group, Paper, Stack, Text } from "@mantine/core";
import type {
CreateMessageRequestParams,
CreateMessageResult,
} from "@modelcontextprotocol/sdk/types.js";

export interface InlineSamplingRequestProps {
request: CreateMessageRequestParams;
queuePosition: string;
responseText: string;
draftResult?: CreateMessageResult;
onAutoRespond: () => void;
onEditAndSend: () => void;
onReject: () => void;
Expand All @@ -35,6 +30,11 @@ const PreviewText = Text.withProps({
lineClamp: 2,
});

const DraftPreview = Text.withProps({
size: "sm",
lineClamp: 2,
});

const DetailButton = Button.withProps({
variant: "subtle",
size: "xs",
Expand Down Expand Up @@ -67,6 +67,17 @@ function extractPreview(request: CreateMessageRequestParams): string {
return content.type === "text" ? content.text : `[${content.type}]`;
}

function extractDraftPreview(draft: CreateMessageResult): string {
switch (draft.content.type) {
case "text":
return draft.content.text;
case "image":
return "[Image content]";
case "audio":
return "[Audio content]";
}
}

function extractModelHints(
request: CreateMessageRequestParams,
): string[] | undefined {
Expand All @@ -82,14 +93,15 @@ function formatModelHints(hints: string[]): string {
export function InlineSamplingRequest({
request,
queuePosition,
responseText,
draftResult,
onAutoRespond,
onEditAndSend,
onReject,
onViewDetails,
}: InlineSamplingRequestProps) {
const modelHints = extractModelHints(request);
const messagePreview = extractPreview(request);
const draftPreview = draftResult ? extractDraftPreview(draftResult) : null;

return (
<RequestContainer>
Expand All @@ -105,14 +117,7 @@ export function InlineSamplingRequest({

<DetailButton onClick={onViewDetails}>View Details</DetailButton>

<Textarea
size="sm"
value={responseText}
placeholder="Response..."
autosize
minRows={2}
readOnly
/>
{draftPreview !== null && <DraftPreview>{draftPreview}</DraftPreview>}

<ActionsRow>
<CompactButton onClick={onAutoRespond}>Auto-respond</CompactButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const SingleSampling: Story = {
maxTokens: 1024,
}}
queuePosition="1 of 1"
responseText=""
onAutoRespond={fn()}
onEditAndSend={fn()}
onReject={fn()}
Expand Down Expand Up @@ -102,7 +101,6 @@ export const MultipleMixed: Story = {
maxTokens: 1024,
}}
queuePosition="1 of 2"
responseText=""
onAutoRespond={fn()}
onEditAndSend={fn()}
onReject={fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ export const WithPendingRequests: Story = {
maxTokens: 1024,
}}
queuePosition="1 of 2"
responseText=""
onAutoRespond={fn()}
onEditAndSend={fn()}
onReject={fn()}
Expand Down