Open History to see the last commit
1import {
2 type ProviderInstanceId,
3 type ProviderDriverKind,
4 type ResolvedKeybindingsConfig,
5} from "@t3tools/contracts";
6import { resolveSelectableModel } from "@t3tools/shared/model";
7import { LegendList, type LegendListRef } from "@legendapp/list/react";
8import { memo, useMemo, useState, useCallback, useEffect, useLayoutEffect, useRef } from "react";
9import { SearchIcon } from "lucide-react";
10import { ModelListRow } from "./ModelListRow";
11import { ModelPickerSidebar } from "./ModelPickerSidebar";
12import { isModelPickerNewModel } from "./modelPickerModelHighlights";
13import { buildModelPickerSearchText, scoreModelPickerSearch } from "./modelPickerSearch";
14import { Combobox, ComboboxEmpty, ComboboxInput, ComboboxListVirtualized } from "../ui/combobox";
15import { ModelEsque } from "./providerIconUtils";
16import {
17 modelPickerJumpCommandForIndex,
18 modelPickerJumpIndexFromCommand,
19 resolveShortcutCommand,
20 shortcutLabelForCommand,
21} from "../../keybindings";
22import { useClientSettings, useUpdateClientSettings } from "~/hooks/useSettings";
23import { cn } from "~/lib/utils";
24import { TooltipProvider } from "../ui/tooltip";
25import {
26 isProviderInstancePickerReady,
27 isProviderInstancePickerVisible,
28 type ProviderInstanceEntry,
29} from "../../providerInstances";
30import { providerModelKey, sortProviderModelItems } from "../../modelOrdering";
31
32type ModelPickerItem = {
33 slug: string;
34 name: string;
35 shortName?: string;
36 subProvider?: string;
37 instanceId: ProviderInstanceId;
38 driverKind: ProviderDriverKind;
39 instanceDisplayName: string;
40 instanceAccentColor?: string | undefined;
41 continuationGroupKey?: string | undefined;
42};
43
44const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
45
46// Split a `${instanceId}:${slug}` combobox key back into its pieces. Slugs
47// can contain colons (e.g. some vendor model ids), so we only split on the
48// first colon — anything after that is the slug.
49function splitInstanceModelKey(key: string): { instanceId: ProviderInstanceId; slug: string } {
50 const colonIndex = key.indexOf(":");
51 if (colonIndex === -1) {
52 return { instanceId: key as ProviderInstanceId, slug: "" };
53 }
54 return {
55 instanceId: key.slice(0, colonIndex) as ProviderInstanceId,
56 slug: key.slice(colonIndex + 1),
57 };
58}
59
60export const ModelPickerContent = memo(function ModelPickerContent(props: {
61 /** The instance currently selected in the composer (combobox "value"). */
62 activeInstanceId: ProviderInstanceId;
63 model: string;
64 /**
65 * When set, the picker is locked to the given driver kind — typically
66 * because the user is editing a previously-sent message and can't change
67 * which driver served the turn. Multiple instances of the same kind
68 * remain selectable (e.g. locked to `codex` still lets the user switch
69 * between the default Codex and a custom Codex Personal).
70 */
71 lockedProvider: ProviderDriverKind | null;
72 lockedContinuationGroupKey?: string | null;
73 /**
74 * All configured provider instances in display order. Used to render
75 * the sidebar (one button per instance) and to resolve display names
76 * for the locked-mode header.
77 */
78 instanceEntries: ReadonlyArray<ProviderInstanceEntry>;
79 keybindings?: ResolvedKeybindingsConfig;
80 /**
81 * Model options per instance. Keyed by `ProviderInstanceId` so the
82 * default Codex instance and any custom Codex instances each have their
83 * own list (custom instances typically start with the same built-in
84 * model set but are free to diverge via customModels).
85 */
86 modelOptionsByInstance: ReadonlyMap<ProviderInstanceId, ReadonlyArray<ModelEsque>>;
87 terminalOpen: boolean;
88 onRequestClose?: () => void;
89 getModelDisabledReason?: (instanceId: ProviderInstanceId, model: string) => string | null;
90 onInstanceModelChange: (instanceId: ProviderInstanceId, model: string) => void;
91}) {
92 const {
93 keybindings: providedKeybindings,
94 modelOptionsByInstance,
95 instanceEntries,
96 getModelDisabledReason,
97 onInstanceModelChange,
98 } = props;
99 const [searchQuery, setSearchQuery] = useState("");
100 const [showTopScrollFade, setShowTopScrollFade] = useState(false);
101 const [showBottomScrollFade, setShowBottomScrollFade] = useState(false);
102 const searchInputRef = useRef<HTMLInputElement>(null);
103 const modelListRef = useRef<LegendListRef | null>(null);
104 const highlightedModelKeyRef = useRef<string | null>(null);
105 const favorites = useClientSettings((s) => s.favorites ?? []);
106 const [selectedInstanceId, setSelectedInstanceId] = useState<ProviderInstanceId | "favorites">(
107 () => {
108 if (props.lockedProvider !== null) {
109 // When locked, prime the sidebar to the currently-active instance
110 // so jumping into the picker keeps the focused instance visible.
111 return props.activeInstanceId;
112 }
113 return favorites.length > 0 ? "favorites" : props.activeInstanceId;
114 },
115 );
116 const keybindings = useMemo<ResolvedKeybindingsConfig>(
117 () => providedKeybindings ?? [],
118 [providedKeybindings],
119 );
120 const updateSettings = useUpdateClientSettings();
121
122 const focusSearchInput = useCallback(() => {
123 searchInputRef.current?.focus({ preventScroll: true });
124 }, []);
125
126 const handleSelectInstance = useCallback(
127 (instanceId: ProviderInstanceId | "favorites") => {
128 setSelectedInstanceId(instanceId);
129 window.requestAnimationFrame(() => {
130 focusSearchInput();
131 });
132 },
133 [focusSearchInput],
134 );
135
136 useLayoutEffect(() => {
137 focusSearchInput();
138 const frame = window.requestAnimationFrame(() => {
139 focusSearchInput();
140 });
141 const timeout = window.setTimeout(() => {
142 focusSearchInput();
143 }, 0);
144 return () => {
145 window.cancelAnimationFrame(frame);
146 window.clearTimeout(timeout);
147 };
148 }, [focusSearchInput]);
149
150 // Create a Set for efficient lookup. Favorites are keyed by
151 // `${instanceId}:${slug}`; the storage schema widened from ProviderDriverKind
152 // to ProviderInstanceId so pre-migration favorites keyed by driver slugs
153 // (e.g. `"codex:gpt-5"`) still resolve — the default instance id equals
154 // the driver slug.
155 const favoritesSet = useMemo(() => {
156 return new Set(favorites.map((fav) => providerModelKey(fav.provider, fav.model)));
157 }, [favorites]);
158
159 /**
160 * Lookup table keyed by `instanceId`. Used for display name + driver
161 * kind enrichment and for `ready`/enabled filtering before flattening
162 * models into the search list.
163 */
164 const entryByInstanceId = useMemo(
165 () => new Map(instanceEntries.map((entry) => [entry.instanceId, entry])),
166 [instanceEntries],
167 );
168 const matchesLockedProvider = useCallback(
169 (entry: Pick<ProviderInstanceEntry, "driverKind" | "continuationGroupKey">): boolean => {
170 if (props.lockedProvider === null) return true;
171 if (entry.driverKind !== props.lockedProvider) return false;
172 if (!props.lockedContinuationGroupKey) return true;
173 return entry.continuationGroupKey === props.lockedContinuationGroupKey;
174 },
175 [props.lockedContinuationGroupKey, props.lockedProvider],
176 );
177
178 const readyInstanceSet = useMemo(() => {
179 const ready = new Set<ProviderInstanceId>();
180 for (const entry of instanceEntries) {
181 if (isProviderInstancePickerReady(entry)) {
182 ready.add(entry.instanceId);
183 }
184 }
185 return ready;
186 }, [instanceEntries]);
187
188 // Flatten models into a searchable array. One pass over the
189 // instance-keyed map; each model carries its instance id + driver kind
190 // so the list row can render the right icon and display name without
191 // another lookup.
192 const flatModels = useMemo(() => {
193 const out: ModelPickerItem[] = [];
194 for (const [instanceId, models] of modelOptionsByInstance) {
195 const entry = entryByInstanceId.get(instanceId);
196 if (!entry) {
197 // Instance disappeared between renders (configuration change). Skip
198 // its models — stale options shouldn't appear in the picker.
199 continue;
200 }
201 if (!readyInstanceSet.has(instanceId)) {
202 continue;
203 }
204 for (const model of models) {
205 out.push({
206 slug: model.slug,
207 name: model.name,
208 ...(model.shortName ? { shortName: model.shortName } : {}),
209 ...(model.subProvider ? { subProvider: model.subProvider } : {}),
210 instanceId,
211 driverKind: entry.driverKind,
212 instanceDisplayName: entry.displayName,
213 ...(entry.accentColor ? { instanceAccentColor: entry.accentColor } : {}),
214 ...(entry.continuationGroupKey
215 ? { continuationGroupKey: entry.continuationGroupKey }
216 : {}),
217 });
218 }
219 }
220 return out;
221 }, [modelOptionsByInstance, entryByInstanceId, readyInstanceSet]);
222
223 const isLocked = props.lockedProvider !== null;
224 const isSearching = searchQuery.trim().length > 0;
225 const lockedDisabledInstanceIds = useMemo(() => {
226 if (!isLocked) {
227 return undefined;
228 }
229 const disabled = new Set<ProviderInstanceId>();
230 for (const entry of instanceEntries) {
231 if (!matchesLockedProvider(entry)) {
232 disabled.add(entry.instanceId);
233 }
234 }
235 return disabled;
236 }, [instanceEntries, isLocked, matchesLockedProvider]);
237 const sidebarInstanceEntries = useMemo(() => {
238 const enabledEntries = instanceEntries.filter(isProviderInstancePickerVisible);
239 if (!isLocked) {
240 return enabledEntries;
241 }
242 const available: ProviderInstanceEntry[] = [];
243 const disabled: ProviderInstanceEntry[] = [];
244 for (const entry of enabledEntries) {
245 if (matchesLockedProvider(entry)) {
246 available.push(entry);
247 } else {
248 disabled.push(entry);
249 }
250 }
251 return [...available, ...disabled];
252 }, [instanceEntries, isLocked, matchesLockedProvider]);
253 const showSidebar = !isSearching && sidebarInstanceEntries.length > 0;
254 const instanceOrder = useMemo(
255 () => instanceEntries.map((entry) => entry.instanceId),
256 [instanceEntries],
257 );
258
259 // Filter models based on search query and selected instance
260 const filteredModels = useMemo(() => {
261 let result = flatModels;
262
263 // Apply tokenized fuzzy search across the combined provider/model search fields.
264 if (searchQuery.trim()) {
265 const rankedMatches = result
266 .map((model) => ({
267 model,
268 score: scoreModelPickerSearch(
269 {
270 name: model.name,
271 ...(model.shortName ? { shortName: model.shortName } : {}),
272 ...(model.subProvider ? { subProvider: model.subProvider } : {}),
273 driverKind: model.driverKind,
274 providerDisplayName: model.instanceDisplayName,
275 isFavorite: favoritesSet.has(providerModelKey(model.instanceId, model.slug)),
276 },
277 searchQuery,
278 ),
279 isFavorite: favoritesSet.has(providerModelKey(model.instanceId, model.slug)),
280 tieBreaker: buildModelPickerSearchText({
281 name: model.name,
282 ...(model.shortName ? { shortName: model.shortName } : {}),
283 ...(model.subProvider ? { subProvider: model.subProvider } : {}),
284 driverKind: model.driverKind,
285 providerDisplayName: model.instanceDisplayName,
286 }),
287 }))
288 .filter(
289 (
290 rankedModel,
291 ): rankedModel is {
292 model: ModelPickerItem;
293 score: number;
294 isFavorite: boolean;
295 tieBreaker: string;
296 } => rankedModel.score !== null,
297 );
298
299 // When searching, we only respect locked provider (by driver kind),
300 // ignoring sidebar selection so account-scoped searches can find a
301 // model before the user chooses a specific instance rail item.
302 if (props.lockedProvider !== null) {
303 const lockedProviderMatches: Array<(typeof rankedMatches)[number]> = [];
304 for (const rankedModel of rankedMatches) {
305 if (matchesLockedProvider(rankedModel.model)) {
306 lockedProviderMatches.push(rankedModel);
307 }
308 }
309 return lockedProviderMatches
310 .toSorted((a, b) => {
311 const scoreDelta = a.score - b.score;
312 if (scoreDelta !== 0) {
313 return scoreDelta;
314 }
315 if (a.isFavorite !== b.isFavorite) {
316 return a.isFavorite ? -1 : 1;
317 }
318 return a.tieBreaker.localeCompare(b.tieBreaker);
319 })
320 .map((rankedModel) => rankedModel.model);
321 }
322
323 return rankedMatches
324 .toSorted((a, b) => {
325 const scoreDelta = a.score - b.score;
326 if (scoreDelta !== 0) {
327 return scoreDelta;
328 }
329 if (a.isFavorite !== b.isFavorite) {
330 return a.isFavorite ? -1 : 1;
331 }
332 return a.tieBreaker.localeCompare(b.tieBreaker);
333 })
334 .map((rankedModel) => rankedModel.model);
335 }
336
337 if (props.lockedProvider !== null) {
338 result = result.filter((m) => matchesLockedProvider(m));
339 if (selectedInstanceId === "favorites") {
340 result = result.filter((m) => favoritesSet.has(providerModelKey(m.instanceId, m.slug)));
341 } else {
342 result = result.filter((m) => m.instanceId === selectedInstanceId);
343 }
344 } else if (selectedInstanceId === "favorites") {
345 result = result.filter((m) => favoritesSet.has(providerModelKey(m.instanceId, m.slug)));
346 } else {
347 result = result.filter((m) => m.instanceId === selectedInstanceId);
348 }
349
350 return sortProviderModelItems(result, {
351 favoriteModelKeys: favoritesSet,
352 groupFavorites: selectedInstanceId !== "favorites",
353 instanceOrder: selectedInstanceId === "favorites" ? instanceOrder : [],
354 });
355 }, [
356 favoritesSet,
357 flatModels,
358 instanceOrder,
359 matchesLockedProvider,
360 props.lockedProvider,
361 searchQuery,
362 selectedInstanceId,
363 ]);
364
365 const handleModelSelect = useCallback(
366 (modelSlug: string, instanceId: ProviderInstanceId) => {
367 if (getModelDisabledReason?.(instanceId, modelSlug)) {
368 return;
369 }
370 const options = modelOptionsByInstance.get(instanceId);
371 if (!options) {
372 return;
373 }
374 const entry = entryByInstanceId.get(instanceId);
375 if (!entry) {
376 return;
377 }
378 // `resolveSelectableModel` uses the driver kind for normalization
379 // (slug casing etc.). Custom instances share their driver's
380 // normalization rules, so pass the driver kind here.
381 const resolvedModel = resolveSelectableModel(entry.driverKind, modelSlug, options);
382 if (resolvedModel) {
383 onInstanceModelChange(instanceId, resolvedModel);
384 }
385 },
386 [entryByInstanceId, getModelDisabledReason, modelOptionsByInstance, onInstanceModelChange],
387 );
388
389 const toggleFavorite = useCallback(
390 (instanceId: ProviderInstanceId, model: string) => {
391 const newFavorites = [...favorites];
392 const index = newFavorites.findIndex((f) => f.provider === instanceId && f.model === model);
393 if (index >= 0) {
394 newFavorites.splice(index, 1);
395 } else {
396 newFavorites.push({ provider: instanceId, model });
397 }
398 updateSettings({ favorites: newFavorites });
399 },
400 [favorites, updateSettings],
401 );
402
403 const modelJumpCommandByKey = useMemo(() => {
404 const mapping = new Map<
405 string,
406 NonNullable<ReturnType<typeof modelPickerJumpCommandForIndex>>
407 >();
408 let selectableModelIndex = 0;
409 for (const model of filteredModels) {
410 if (getModelDisabledReason?.(model.instanceId, model.slug)) {
411 continue;
412 }
413 const jumpCommand = modelPickerJumpCommandForIndex(selectableModelIndex);
414 if (!jumpCommand) {
415 return mapping;
416 }
417 mapping.set(`${model.instanceId}:${model.slug}`, jumpCommand);
418 selectableModelIndex += 1;
419 }
420 return mapping;
421 }, [filteredModels, getModelDisabledReason]);
422 const modelJumpModelKeys = useMemo(
423 () => [...modelJumpCommandByKey.keys()],
424 [modelJumpCommandByKey],
425 );
426 const allModelKeys = useMemo(
427 (): string[] => flatModels.map((model) => `${model.instanceId}:${model.slug}`),
428 [flatModels],
429 );
430 const filteredModelKeys = useMemo(
431 (): string[] => filteredModels.map((model) => `${model.instanceId}:${model.slug}`),
432 [filteredModels],
433 );
434 const filteredModelByKey = useMemo(
435 (): ReadonlyMap<string, ModelPickerItem> =>
436 new Map(filteredModels.map((model) => [`${model.instanceId}:${model.slug}`, model] as const)),
437 [filteredModels],
438 );
439 const updateModelListScrollFades = useCallback(() => {
440 const scrollElement = modelListRef.current?.getScrollableNode();
441 if (!(scrollElement instanceof HTMLElement)) {
442 return;
443 }
444 const maxScrollOffset = Math.max(0, scrollElement.scrollHeight - scrollElement.clientHeight);
445 setShowTopScrollFade(scrollElement.scrollTop > 1);
446 setShowBottomScrollFade(maxScrollOffset - scrollElement.scrollTop > 1);
447 }, []);
448 const modelJumpShortcutContext = useMemo(
449 () =>
450 ({
451 terminalFocus: false,
452 terminalOpen: props.terminalOpen,
453 modelPickerOpen: true,
454 }) as const,
455 [props.terminalOpen],
456 );
457 const modelJumpLabelByKey = useMemo((): ReadonlyMap<string, string> => {
458 if (modelJumpCommandByKey.size === 0) {
459 return EMPTY_MODEL_JUMP_LABELS;
460 }
461 const shortcutLabelOptions = {
462 platform: navigator.platform,
463 context: modelJumpShortcutContext,
464 };
465 const mapping = new Map<string, string>();
466 for (const [modelKey, command] of modelJumpCommandByKey) {
467 const label = shortcutLabelForCommand(keybindings, command, shortcutLabelOptions);
468 if (label) {
469 mapping.set(modelKey, label);
470 }
471 }
472 return mapping.size > 0 ? mapping : EMPTY_MODEL_JUMP_LABELS;
473 }, [keybindings, modelJumpCommandByKey, modelJumpShortcutContext]);
474
475 useEffect(() => {
476 const onWindowKeyDown = (event: globalThis.KeyboardEvent) => {
477 if (event.defaultPrevented || event.repeat) {
478 return;
479 }
480
481 const command = resolveShortcutCommand(event, keybindings, {
482 platform: navigator.platform,
483 context: modelJumpShortcutContext,
484 });
485 const jumpIndex = modelPickerJumpIndexFromCommand(command ?? "");
486 if (jumpIndex === null) {
487 return;
488 }
489
490 const targetModelKey = modelJumpModelKeys[jumpIndex];
491 if (!targetModelKey) {
492 return;
493 }
494 const { instanceId, slug } = splitInstanceModelKey(targetModelKey);
495 event.preventDefault();
496 event.stopPropagation();
497 handleModelSelect(slug, instanceId);
498 };
499
500 window.addEventListener("keydown", onWindowKeyDown, true);
501
502 return () => {
503 window.removeEventListener("keydown", onWindowKeyDown, true);
504 };
505 }, [handleModelSelect, keybindings, modelJumpModelKeys, modelJumpShortcutContext]);
506
507 useLayoutEffect(() => {
508 setShowTopScrollFade(false);
509 setShowBottomScrollFade(filteredModelKeys.length > 5);
510 let nestedFrame = 0;
511 const frame = window.requestAnimationFrame(() => {
512 updateModelListScrollFades();
513 nestedFrame = window.requestAnimationFrame(updateModelListScrollFades);
514 });
515 return () => {
516 window.cancelAnimationFrame(frame);
517 window.cancelAnimationFrame(nestedFrame);
518 };
519 }, [filteredModelKeys, updateModelListScrollFades]);
520
521 return (
522 <TooltipProvider delay={0}>
523 <div
524 className="relative flex h-screen max-h-96 w-screen max-w-100 flex-row overflow-hidden rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]"
525 data-model-picker-content="true"
526 >
527 {/* Sidebar */}
528 {showSidebar && (
529 <ModelPickerSidebar
530 selectedInstanceId={selectedInstanceId}
531 onSelectInstance={handleSelectInstance}
532 instanceEntries={sidebarInstanceEntries}
533 showFavorites
534 {...(lockedDisabledInstanceIds
535 ? {
536 disabledInstanceIds: lockedDisabledInstanceIds,
537 getDisabledInstanceTooltip: (entry: ProviderInstanceEntry) =>
538 `${entry.displayName} is unavailable in this thread. Start a new thread to switch providers.`,
539 }
540 : {})}
541 />
542 )}
543
544 {/* Main content area */}
545 <Combobox
546 inline
547 items={allModelKeys}
548 filteredItems={filteredModelKeys}
549 filter={null}
550 autoHighlight
551 open
552 virtualized
553 value={`${props.activeInstanceId}:${props.model}`}
554 onItemHighlighted={(modelKey, eventDetails) => {
555 highlightedModelKeyRef.current = typeof modelKey === "string" ? modelKey : null;
556 if (eventDetails.reason === "keyboard" && eventDetails.index >= 0) {
557 void modelListRef.current?.scrollIndexIntoView?.({
558 index: eventDetails.index,
559 animated: false,
560 });
561 }
562 }}
563 onValueChange={(modelKey) => {
564 if (typeof modelKey !== "string") {
565 return;
566 }
567 const { instanceId, slug } = splitInstanceModelKey(modelKey);
568 handleModelSelect(slug, instanceId);
569 }}
570 >
571 <div
572 className={cn(
573 "flex min-h-0 flex-1 flex-col overflow-hidden bg-muted/40",
574 showSidebar && "border-l",
575 )}
576 >
577 {/* Search bar */}
578 <div className="px-4 pt-2.5">
579 <div className="-translate-y-px border-b border-border/70 pb-2.5 transition-colors focus-within:border-ring">
580 <ComboboxInput
581 ref={searchInputRef}
582 className="[&_input]:h-6.5 [&_input]:font-sans [&_input]:leading-6.5"
583 inputClassName="rounded-none bg-transparent text-sm"
584 placeholder="Search models..."
585 showTrigger={false}
586 startAddon={
587 <SearchIcon className="-translate-x-0.5 size-4 shrink-0 text-muted-foreground/55" />
588 }
589 value={searchQuery}
590 onChange={(e) => setSearchQuery(e.target.value)}
591 onKeyDown={(e) => {
592 if (e.key === "Escape") {
593 e.preventDefault();
594 e.stopPropagation();
595 props.onRequestClose?.();
596 return;
597 }
598 if (e.key === "Enter" && highlightedModelKeyRef.current) {
599 (
600 e as typeof e & { preventBaseUIHandler?: () => void }
601 ).preventBaseUIHandler?.();
602 e.preventDefault();
603 e.stopPropagation();
604 const { instanceId, slug } = splitInstanceModelKey(
605 highlightedModelKeyRef.current,
606 );
607 handleModelSelect(slug, instanceId);
608 return;
609 }
610 e.stopPropagation();
611 }}
612 onMouseDown={(e) => e.stopPropagation()}
613 onTouchStart={(e) => e.stopPropagation()}
614 size="sm"
615 unstyled
616 />
617 </div>
618 </div>
619
620 {/* Model list */}
621 <div className="relative min-h-0 flex-1 overflow-hidden">
622 <ComboboxListVirtualized className="model-picker-list size-full min-w-0 p-0">
623 <LegendList<string>
624 ref={modelListRef}
625 data={filteredModelKeys}
626 extraData={favoritesSet}
627 keyExtractor={(modelKey) => modelKey}
628 renderItem={({ item: modelKey, index }) => {
629 const model = filteredModelByKey.get(modelKey);
630 if (!model) {
631 return null;
632 }
633 const disabledReason =
634 getModelDisabledReason?.(model.instanceId, model.slug) ?? null;
635 return (
636 <ModelListRow
637 key={modelKey}
638 index={index}
639 model={model}
640 instanceId={model.instanceId}
641 driverKind={model.driverKind}
642 providerDisplayName={model.instanceDisplayName}
643 providerAccentColor={model.instanceAccentColor}
644 isFavorite={favoritesSet.has(modelKey)}
645 isSelected={modelKey === `${props.activeInstanceId}:${props.model}`}
646 showProvider
647 preferShortName={!isLocked}
648 useTriggerLabel={false}
649 showNewBadge={isModelPickerNewModel(model.driverKind, model.slug)}
650 jumpLabel={modelJumpLabelByKey.get(modelKey) ?? null}
651 disabledReason={disabledReason}
652 onToggleFavorite={() => toggleFavorite(model.instanceId, model.slug)}
653 />
654 );
655 }}
656 estimatedItemSize={60}
657 drawDistance={480}
658 recycleItems
659 onLayout={updateModelListScrollFades}
660 onScroll={updateModelListScrollFades}
661 className={cn(
662 "scrollbar-gutter-both h-full overflow-x-hidden overscroll-y-contain py-1.5 [--fade-size:1.5rem]",
663 showTopScrollFade && "mask-t-from-[calc(100%-var(--fade-size))]",
664 showBottomScrollFade && "mask-b-from-[calc(100%-var(--fade-size))]",
665 )}
666 />
667 </ComboboxListVirtualized>
668 </div>
669 <ComboboxEmpty className="not-empty:py-6 empty:h-0 text-xs font-normal leading-snug">
670 No models found
671 </ComboboxEmpty>
672 </div>
673 </Combobox>
674 </div>
675 </TooltipProvider>
676 );
677});