2 import type { MCPPromptInfo } from '$lib/types';
3 import { fly } from 'svelte/transition';
4 import { Input } from '$lib/components/ui/input';
5 import { Label } from '$lib/components/ui/label';
7 type PromptArgument = NonNullable<MCPPromptInfo['arguments']>[number];
10 argument: PromptArgument;
12 suggestions?: string[];
13 isLoadingSuggestions?: boolean;
14 isAutocompleteActive?: boolean;
15 autocompleteIndex?: number;
16 onInput: (value: string) => void;
17 onKeydown: (event: KeyboardEvent) => void;
20 onSelectSuggestion: (value: string) => void;
27 isLoadingSuggestions = false,
28 isAutocompleteActive = false,
29 autocompleteIndex = 0,
38 <div class="relative grid gap-1">
39 <Label for="arg-{argument.name}" class="mb-1 text-muted-foreground">
43 {#if argument.required}
44 <span class="text-destructive">*</span>
48 {#if isLoadingSuggestions}
49 <span class="text-xs text-muted-foreground/50">...</span>
54 id="arg-{argument.name}"
57 oninput={(e) => onInput(e.currentTarget.value)}
61 placeholder={argument.description || argument.name}
62 required={argument.required}
66 {#if isAutocompleteActive && suggestions.length > 0}
68 class="absolute top-full right-0 left-0 z-10 mt-1 max-h-32 overflow-y-auto rounded-lg border border-border/50 bg-background shadow-lg"
69 transition:fly={{ y: -5, duration: 100 }}
71 {#each suggestions as suggestion, i (suggestion)}
74 onmousedown={() => onSelectSuggestion(suggestion)}
75 class="w-full px-3 py-1.5 text-left text-sm hover:bg-accent {i === autocompleteIndex