Skip to content
Open
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
15 changes: 12 additions & 3 deletions client/src/components/PromptsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ const PromptsTab = ({
clearCompletions();
}, [clearCompletions, selectedPrompt]);

const handleInputChange = async (argName: string, value: string) => {
setPromptArgs((prev) => ({ ...prev, [argName]: value }));

const triggerCompletions = (argName: string, value: string) => {
if (selectedPrompt) {
requestCompletions(
{
Expand All @@ -79,6 +77,16 @@ const PromptsTab = ({
}
};

const handleInputChange = async (argName: string, value: string) => {
setPromptArgs((prev) => ({ ...prev, [argName]: value }));
triggerCompletions(argName, value);
};

const handleFocus = async (argName: string) => {
const currentValue = promptArgs[argName] || "";
triggerCompletions(argName, currentValue);
};

const handleGetPrompt = () => {
if (selectedPrompt) {
getPrompt(selectedPrompt.name, promptArgs);
Expand Down Expand Up @@ -143,6 +151,7 @@ const PromptsTab = ({
onInputChange={(value) =>
handleInputChange(arg.name, value)
}
onFocus={() => handleFocus(arg.name)}
options={completions[arg.name] || []}
/>

Expand Down
14 changes: 13 additions & 1 deletion client/src/components/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface ComboboxProps {
value: string;
onChange: (value: string) => void;
onInputChange: (value: string) => void;
onFocus?: () => void;
options: string[];
placeholder?: string;
emptyMessage?: string;
Expand All @@ -29,13 +30,24 @@ export function Combobox({
value,
onChange,
onInputChange,
onFocus,
options = [],
placeholder = "Select...",
emptyMessage = "No results found.",
id,
}: ComboboxProps) {
const [open, setOpen] = React.useState(false);

const handleOpenChange = React.useCallback(
(newOpen: boolean) => {
setOpen(newOpen);
if (newOpen && onFocus) {
onFocus();
}
},
[onFocus],
);

const handleSelect = React.useCallback(
(option: string) => {
onChange(option);
Expand All @@ -52,7 +64,7 @@ export function Combobox({
);

return (
<Popover open={open} onOpenChange={setOpen}>
<Popover open={open} onOpenChange={handleOpenChange}>
<PopoverTrigger asChild>
<Button
variant="outline"
Expand Down