void
+}) {
+ const known = useMemo(() => new Set(models.map((m) => m.model)), [models])
+ const isCustom = value !== "" && !known.has(value)
+ const [customMode, setCustomMode] = useState(isCustom)
+
+ // Reset to dropdown if the available models change (e.g. provider switched)
+ // and we're not actively in custom mode.
+ useEffect(() => {
+ if (!isCustom) setCustomMode(false)
+ }, [models, isCustom])
+
+ if (customMode) {
+ return (
+
+ onChange(e.target.value)}
+ placeholder="custom-model-id"
+ autoFocus
+ />
+
+
+ )
+ }
+
+ return (
+
+ )
+}
+
function Field({ label, children }: { label: string; children: React.ReactNode }) {
return (