11"use client" ;
22
33import { ArrowDownIcon , ArrowUpIcon , PencilIcon , PlusIcon , StarIcon , XIcon } from "lucide-react" ;
4- import { useEffect , useMemo , useRef , useState } from "react" ;
4+ import { useEffect , useRef , useState } from "react" ;
55import {
66 ProviderDriverKind ,
77 type ProviderInstanceId ,
@@ -113,6 +113,12 @@ interface ProviderModelsSectionProps {
113113 readonly onModelOrderChange : ( next : ReadonlyArray < string > ) => void ;
114114}
115115
116+ /** CustomModelEditor keys its option list on this array. */
117+ function useBuiltInModels ( models : ReadonlyArray < ServerProviderModel > ) {
118+ "use memo" ;
119+ return models . filter ( ( model ) => ! model . isCustom ) ;
120+ }
121+
116122export function ProviderModelsSection ( {
117123 instanceId,
118124 driverKind,
@@ -136,22 +142,18 @@ export function ProviderModelsSection({
136142 const [ editingSlug , setEditingSlug ] = useState < string | null > ( null ) ;
137143 const listRef = useRef < HTMLDivElement > ( null ) ;
138144 const scrollToSlugRef = useRef < string | null > ( null ) ;
139- const hiddenModelSet = useMemo ( ( ) => new Set ( hiddenModels ) , [ hiddenModels ] ) ;
140- const favoriteModelSet = useMemo ( ( ) => new Set ( favoriteModels ) , [ favoriteModels ] ) ;
141- const displayModels = useMemo (
142- ( ) =>
143- groupModelsForDisplay ( models , {
144- favoriteModels : favoriteModelSet ,
145- hiddenModels : hiddenModelSet ,
146- modelOrder,
147- } ) ,
148- [ favoriteModelSet , hiddenModelSet , modelOrder , models ] ,
149- ) ;
145+ const hiddenModelSet = new Set ( hiddenModels ) ;
146+ const favoriteModelSet = new Set ( favoriteModels ) ;
147+ const displayModels = groupModelsForDisplay ( models , {
148+ favoriteModels : favoriteModelSet ,
149+ hiddenModels : hiddenModelSet ,
150+ modelOrder,
151+ } ) ;
150152 const favoriteCount = displayModels . filter ( ( model ) => favoriteModelSet . has ( model . slug ) ) . length ;
151153 const hiddenCount = displayModels . filter (
152154 ( model ) => ! model . isCustom && hiddenModelSet . has ( model . slug ) ,
153155 ) . length ;
154- const builtInModels = useMemo ( ( ) => models . filter ( ( model ) => ! model . isCustom ) , [ models ] ) ;
156+ const builtInModels = useBuiltInModels ( models ) ;
155157 const allBuiltInModelsHidden =
156158 builtInModels . length > 0 && builtInModels . every ( ( model ) => hiddenModelSet . has ( model . slug ) ) ;
157159 const showFilter = models . length > FILTER_THRESHOLD ;
@@ -165,6 +167,7 @@ export function ProviderModelsSection({
165167 )
166168 : displayModels ;
167169
170+ // A model added or moved lands in a later commit, so each commit looks for the pending row.
168171 useEffect ( ( ) => {
169172 const slug = scrollToSlugRef . current ;
170173 if ( slug === null ) return ;
@@ -174,7 +177,7 @@ export function ProviderModelsSection({
174177 if ( ! row ) return ;
175178 scrollToSlugRef . current = null ;
176179 row . scrollIntoView ( { block : "nearest" } ) ;
177- } , [ displayModels ] ) ;
180+ } ) ;
178181
179182 const handleAdd = ( ) => {
180183 if ( ! canManageCustomModels || driverKind === "antigravity" ) return ;
0 commit comments