Closes the Phase 5 audit partial: the inline card's prop interface now matches SamplingRequestPanel's, accepting an optional CreateMessageResult draft instead of a flat scalar. Lets future hook-layer wiring share a single draft store between the inline card and the full panel. Rendering: - No draft → existing layout (request preview, model hints, action buttons), with the readonly placeholder textarea removed. - Text draft → 2-line preview of draftResult.content.text (lineClamp 2). - Image / audio draft → "[Image content]" / "[Audio content]" label, matching the ContentViewer fallback convention. Updates the three consumer stories that threaded responseText="" through (PendingClientRequests, ToolsScreen) — no callback signatures changed. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
130 lines
3.3 KiB
TypeScript
130 lines
3.3 KiB
TypeScript
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;
|
|
draftResult?: CreateMessageResult;
|
|
onAutoRespond: () => void;
|
|
onEditAndSend: () => void;
|
|
onReject: () => void;
|
|
onViewDetails: () => void;
|
|
}
|
|
|
|
const RequestContainer = Paper.withProps({
|
|
p: "md",
|
|
withBorder: true,
|
|
});
|
|
|
|
const QueueLabel = Text.withProps({
|
|
size: "xs",
|
|
c: "dimmed",
|
|
});
|
|
|
|
const PreviewText = Text.withProps({
|
|
size: "sm",
|
|
c: "dimmed",
|
|
lineClamp: 2,
|
|
});
|
|
|
|
const DraftPreview = Text.withProps({
|
|
size: "sm",
|
|
lineClamp: 2,
|
|
});
|
|
|
|
const DetailButton = Button.withProps({
|
|
variant: "subtle",
|
|
size: "xs",
|
|
});
|
|
|
|
const ActionsRow = Group.withProps({
|
|
justify: "flex-end",
|
|
gap: "xs",
|
|
});
|
|
|
|
const CompactButton = Button.withProps({
|
|
size: "xs",
|
|
variant: "light",
|
|
});
|
|
|
|
const RejectButton = Button.withProps({
|
|
size: "xs",
|
|
variant: "light",
|
|
color: "red",
|
|
});
|
|
|
|
function extractPreview(request: CreateMessageRequestParams): string {
|
|
const lastMessage = request.messages[request.messages.length - 1];
|
|
if (!lastMessage) return "";
|
|
const content = lastMessage.content;
|
|
if (Array.isArray(content)) {
|
|
const textBlock = content.find((b) => b.type === "text");
|
|
return textBlock && "text" in textBlock ? textBlock.text : "";
|
|
}
|
|
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 {
|
|
const hints = request.modelPreferences?.hints;
|
|
if (!hints || hints.length === 0) return undefined;
|
|
return hints.map((h) => h.name).filter(Boolean) as string[];
|
|
}
|
|
|
|
function formatModelHints(hints: string[]): string {
|
|
return `Model hints: ${hints.join(", ")}`;
|
|
}
|
|
|
|
export function InlineSamplingRequest({
|
|
request,
|
|
queuePosition,
|
|
draftResult,
|
|
onAutoRespond,
|
|
onEditAndSend,
|
|
onReject,
|
|
onViewDetails,
|
|
}: InlineSamplingRequestProps) {
|
|
const modelHints = extractModelHints(request);
|
|
const messagePreview = extractPreview(request);
|
|
const draftPreview = draftResult ? extractDraftPreview(draftResult) : null;
|
|
|
|
return (
|
|
<RequestContainer>
|
|
<Stack gap="sm">
|
|
<Group justify="space-between">
|
|
<Badge color="blue">sampling/createMessage</Badge>
|
|
<QueueLabel>{queuePosition}</QueueLabel>
|
|
</Group>
|
|
|
|
{modelHints && <Text size="sm">{formatModelHints(modelHints)}</Text>}
|
|
|
|
<PreviewText>{messagePreview}</PreviewText>
|
|
|
|
<DetailButton onClick={onViewDetails}>View Details</DetailButton>
|
|
|
|
{draftPreview !== null && <DraftPreview>{draftPreview}</DraftPreview>}
|
|
|
|
<ActionsRow>
|
|
<CompactButton onClick={onAutoRespond}>Auto-respond</CompactButton>
|
|
<CompactButton onClick={onEditAndSend}>Edit & Send</CompactButton>
|
|
<RejectButton onClick={onReject}>Reject</RejectButton>
|
|
</ActionsRow>
|
|
</Stack>
|
|
</RequestContainer>
|
|
);
|
|
}
|