@@ -129,13 +129,14 @@ export class LoadBalancer {
129129 * Check if provider supports model
130130 */
131131 private providerSupportsModel ( provider : Provider , model : string ) : boolean {
132- if ( ! provider . supportedModels || provider . supportedModels . length === 0 ) {
132+ const effectiveModels = storeManager . getEffectiveModels ( provider . id )
133+ if ( effectiveModels . length === 0 ) {
133134 return true
134135 }
135136
136137 const normalizedModel = model . toLowerCase ( )
137- const supported = provider . supportedModels . some ( m => {
138- const normalizedSupported = m . toLowerCase ( )
138+ const supported = effectiveModels . some ( m => {
139+ const normalizedSupported = m . displayName . toLowerCase ( )
139140 if ( normalizedSupported . endsWith ( '*' ) ) {
140141 return normalizedModel . startsWith ( normalizedSupported . slice ( 0 , - 1 ) )
141142 }
@@ -146,17 +147,9 @@ export class LoadBalancer {
146147 return true
147148 }
148149
149- // Check if model is in provider's model mappings
150- if ( provider . modelMappings && provider . modelMappings [ model ] ) {
151- console . log ( `[LoadBalancer] Model "${ model } " found in provider model mappings` )
152- return true
153- }
154-
155- // Check global model mappings
156150 const config = storeManager . getConfig ( )
157151 const globalMapping = config . modelMappings [ model ]
158152 if ( globalMapping ) {
159- // If preferredProviderId is set, only match that provider
160153 if ( globalMapping . preferredProviderId ) {
161154 if ( globalMapping . preferredProviderId === provider . id ) {
162155 console . log ( `[LoadBalancer] Model "${ model } " matched preferred provider ${ provider . name } ` )
@@ -165,11 +158,10 @@ export class LoadBalancer {
165158 return false
166159 }
167160
168- // If no preferredProviderId, check if provider supports the actualModel
169161 const actualModel = globalMapping . actualModel
170162 const normalizedActualModel = actualModel . toLowerCase ( )
171- const actualSupported = provider . supportedModels . some ( m => {
172- const normalizedSupported = m . toLowerCase ( )
163+ const actualSupported = effectiveModels . some ( m => {
164+ const normalizedSupported = m . displayName . toLowerCase ( )
173165 if ( normalizedSupported . endsWith ( '*' ) ) {
174166 return normalizedActualModel . startsWith ( normalizedSupported . slice ( 0 , - 1 ) )
175167 }
@@ -180,15 +172,9 @@ export class LoadBalancer {
180172 console . log ( `[LoadBalancer] Model "${ model } " (actualModel: "${ actualModel } ") supported by ${ provider . name } ` )
181173 return true
182174 }
183-
184- // Also check provider's model mappings for actualModel
185- if ( provider . modelMappings && provider . modelMappings [ actualModel ] ) {
186- console . log ( `[LoadBalancer] Model "${ model } " (actualModel: "${ actualModel } ") found in provider model mappings` )
187- return true
188- }
189175 }
190176
191- console . log ( `[LoadBalancer] Provider ${ provider . name } does not support model ${ model } , supported models:` , provider . supportedModels )
177+ console . log ( `[LoadBalancer] Provider ${ provider . name } does not support model ${ model } ` )
192178 return false
193179 }
194180
@@ -212,28 +198,30 @@ export class LoadBalancer {
212198 */
213199 private mapModel ( model : string , provider : Provider ) : string {
214200 console . log ( `[LoadBalancer] mapModel called with model="${ model } ", provider="${ provider . name } "` )
215- console . log ( `[LoadBalancer] provider.modelMappings:` , provider . modelMappings )
216201
217- // First check provider-level model mapping
218- if ( provider . modelMappings && provider . modelMappings [ model ] ) {
219- const mapped = provider . modelMappings [ model ]
220- console . log ( `[LoadBalancer] Model mapped from "${ model } " to "${ mapped } " via provider mapping` )
221- return mapped
202+ const effectiveModels = storeManager . getEffectiveModels ( provider . id )
203+ const effectiveModel = effectiveModels . find ( m =>
204+ m . displayName . toLowerCase ( ) === model . toLowerCase ( )
205+ )
206+
207+ if ( effectiveModel ) {
208+ console . log ( `[LoadBalancer] Model mapped from "${ model } " to "${ effectiveModel . actualModelId } " via effective models` )
209+ return effectiveModel . actualModelId
222210 }
223211
224- // Then check global config model mapping
225212 const config = storeManager . getConfig ( )
226213 const mapping = config . modelMappings [ model ]
227214
228215 if ( mapping && ( ! mapping . preferredProviderId || mapping . preferredProviderId === provider . id ) ) {
229216 const actualModel = mapping . actualModel
230217 console . log ( `[LoadBalancer] Model mapped from "${ model } " to "${ actualModel } " via global mapping` )
231218
232- // After global mapping, check if provider has a mapping for the actual model
233- if ( provider . modelMappings && provider . modelMappings [ actualModel ] ) {
234- const finalModel = provider . modelMappings [ actualModel ]
235- console . log ( `[LoadBalancer] Model further mapped from "${ actualModel } " to "${ finalModel } " via provider mapping` )
236- return finalModel
219+ const actualEffectiveModel = effectiveModels . find ( m =>
220+ m . displayName . toLowerCase ( ) === actualModel . toLowerCase ( )
221+ )
222+ if ( actualEffectiveModel ) {
223+ console . log ( `[LoadBalancer] Model further mapped from "${ actualModel } " to "${ actualEffectiveModel . actualModelId } " via effective models` )
224+ return actualEffectiveModel . actualModelId
237225 }
238226
239227 return actualModel
@@ -340,8 +328,9 @@ export class LoadBalancer {
340328 const accounts = storeManager . getAccountsByProviderId ( provider . id )
341329 . filter ( account => this . isAccountAvailable ( account ) )
342330
343- if ( accounts . length > 0 && provider . supportedModels ) {
344- provider . supportedModels . forEach ( m => models . add ( m ) )
331+ if ( accounts . length > 0 ) {
332+ const effectiveModels = storeManager . getEffectiveModels ( provider . id )
333+ effectiveModels . forEach ( m => models . add ( m . displayName ) )
345334 }
346335 }
347336
0 commit comments