{t("This test runs from the DeepTutor backend. In Docker, localhost points to the DeepTutor container. Use a shared-network service name and container port, or host.docker.internal and the published host port.")}
{t(
"Detected describes model modalities, not API compatibility. Provider support indicates an available integration; test a specific model to verify your account access.",
)}
);
}
/**
* The model ID, with the provider's listed models offered as suggestions.
*
* This was a native input with a datalist, which hands the popup to the
* browser — and the browser draws every option at once. A provider that lists
* thirty models covered the page from above its header to below its footer, in
* the browser's styling rather than ours. A datalist popup takes no CSS at all,
* so capping that height means owning the list.
*
* The field stays free text: a model the provider does not list is still a
* model the user may have to type, so the suggestions narrow as they type and
* simply stay shut when nothing matches — an unlisted ID is this field working,
* not an error to report.
*/
export function RegistryModelIdField({
label,
value,
options,
onChange,
placeholder,
disabled = false,
required = false,
invalid = false,
}: {
label: string;
value: string;
options: string[];
onChange: (value: string) => void;
placeholder?: string;
disabled?: boolean;
required?: boolean;
invalid?: boolean;
}) {
const { t } = useTranslation();
const id = useId();
const box = useRef(null);
const listRef = useRef(null);
const [open, setOpen] = useState(false);
const [active, setActive] = useState(-1);
useOutsideClick(box, open, () => setOpen(false));
// A value that *is* one of the options keeps the list whole: narrowing it to
// the single option the field already holds would turn "show me the models"
// into "show me the one I picked".
const query = value.trim().toLowerCase();
const matches =
!query || options.some((option) => option.toLowerCase() === query)
? options
: options.filter((option) => option.toLowerCase().includes(query));
const visible = open && matches.length > 0;
useEffect(() => {
if (!visible) return;
listRef.current
?.querySelector('[data-active="true"]')
// Optional call, as elsewhere: a host without the method (jsdom) has
// nothing to scroll, and keyboard navigation must not depend on it.
?.scrollIntoView?.({ block: "nearest" });
}, [visible, active]);
const pick = (option: string) => {
onChange(option);
setActive(-1);
setOpen(false);
};
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
if (!open) return;
// Contained on purpose: Escape in an open list means "close the list",
// not "leave the editor" to whatever is listening further up.
event.stopPropagation();
setOpen(false);
return;
}
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
if (!matches.length) return;
// Otherwise the caret jumps to either end of the ID being typed.
event.preventDefault();
if (!visible) {
setActive(event.key === "ArrowDown" ? 0 : matches.length - 1);
setOpen(true);
return;
}
const step = event.key === "ArrowDown" ? 1 : -1;
setActive((current) => {
const next = current + step;
if (next < 0) return matches.length - 1;
return next >= matches.length ? 0 : next;
});
return;
}
if (event.key === "Enter" && visible && active >= 0) {
event.preventDefault();
pick(matches[active]);
}
};
return (