Phase 2: Refactor Sampling/Elicitation cluster to MCP SDK types
Replace ad hoc local types with SDK schema types across the Sampling and Elicitation group components. - SamplingRequestPanel: accept `request: CreateMessageRequestParams` + `draftResult: CreateMessageResult` instead of 16 flat props; derive messages, model preferences, and parameters from the request object; drop `tools`/`toolChoice` (not in MCP 2025-11-25 CreateMessageRequest) - InlineSamplingRequest: accept `request: CreateMessageRequestParams`; derive messagePreview and modelHints from the request - ElicitationFormPanel: accept `request: ElicitRequest['params']` + `serverName`; pass requestedSchema directly to SchemaForm - ElicitationUrlPanel: rename `elicitationId` to `requestId` - InlineElicitationRequest: accept `request: ElicitRequest['params']`; discriminate form vs URL mode on request shape instead of `mode` prop - PendingClientRequests: unchanged (children-based wrapper) - Delete local `SamplingTool` type - Update all stories with real SDK type fixtures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7b74598f83
commit
c1a63cb37d
1 changed files with 326 additions and 299 deletions
|
|
@ -7,11 +7,11 @@ import {
|
|||
Text,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import type { CreateMessageRequestParams } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
export interface InlineSamplingRequestProps {
|
||||
request: CreateMessageRequestParams;
|
||||
queuePosition: string;
|
||||
modelHints?: string[];
|
||||
messagePreview: string;
|
||||
responseText: string;
|
||||
onAutoRespond: () => void;
|
||||
onEditAndSend: () => void;
|
||||
|
|
@ -56,20 +56,41 @@ const RejectButton = Button.withProps({
|
|||
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 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,
|
||||
modelHints,
|
||||
messagePreview,
|
||||
responseText,
|
||||
onAutoRespond,
|
||||
onEditAndSend,
|
||||
onReject,
|
||||
onViewDetails,
|
||||
}: InlineSamplingRequestProps) {
|
||||
const modelHints = extractModelHints(request);
|
||||
const messagePreview = extractPreview(request);
|
||||
|
||||
return (
|
||||
<RequestContainer>
|
||||
<Stack gap="sm">
|
||||
|
|
|
|||
Loading…
Reference in a new issue