import { Badge, Button, Divider, Group, Paper, Select, Stack, Text, TextInput, Textarea, Title, } from "@mantine/core"; import { ClearButton } from "../../elements/ClearButton/ClearButton"; import type { CreateMessageRequestParams, CreateMessageResult, } from "@modelcontextprotocol/sdk/types.js"; import { MessageBubble } from "../../elements/MessageBubble/MessageBubble"; export interface SamplingRequestPanelProps { request: CreateMessageRequestParams; draftResult: CreateMessageResult; onResultChange: (result: CreateMessageResult) => void; onSend: () => void; onReject: () => void; /** * A response has been dispatched; lock the actions so a second click can't * resolve the request twice (the underlying handler throws if called again). */ busy?: boolean; } function formatPriority(value: number): string { if (value < 0.4) return `low (${value})`; if (value <= 0.7) return `medium (${value})`; return `high (${value})`; } function formatOptional(value: unknown, fallback: string): string { return value !== undefined ? String(value) : fallback; } function serializeJson(value: unknown): string { return JSON.stringify(value); } const HintText = Text.withProps({ size: "sm", c: "dimmed", }); const PreferencesContainer = Paper.withProps({ p: "sm", withBorder: true, }); const RejectButton = Button.withProps({ variant: "light", color: "red", }); export function SamplingRequestPanel({ request, draftResult, onResultChange, onSend, onReject, busy = false, }: SamplingRequestPanelProps) { const { messages, modelPreferences, maxTokens, stopSequences, temperature, includeContext, } = request; const hints = (modelPreferences?.hints?.map((h) => h.name).filter(Boolean) as string[]) ?? []; return ( The server is requesting an LLM completion. Messages: {messages.map((message, index) => ( ))} {modelPreferences && ( Model Preferences: {hints.length > 0 && ( Hints: {hints.map((hint) => ( {hint} ))} )} {modelPreferences?.costPriority !== undefined && ( Cost Priority: {formatPriority(modelPreferences.costPriority)} )} {modelPreferences?.speedPriority !== undefined && ( Speed Priority: {formatPriority(modelPreferences.speedPriority)} )} {modelPreferences?.intelligencePriority !== undefined && ( Intelligence Priority:{" "} {formatPriority(modelPreferences.intelligencePriority)} )} )} Parameters: Max Tokens: {formatOptional(maxTokens, "not specified")} Stop Sequences:{" "} {stopSequences ? serializeJson(stopSequences) : "not specified"} Temperature: {formatOptional(temperature, "not specified")} {includeContext && ( Include Context: {includeContext} )} Response: