chenbhao commited on
Commit
78e2eb9
·
1 Parent(s): 6cc93c0

fix: rm default choice

Browse files
src/utils/model/modelOptions.ts CHANGED
@@ -474,23 +474,34 @@ function getModelOptionsBase(fastMode = false): ModelOption[] {
474
  // eslint-disable-next-line @typescript-eslint/no-require-imports
475
  const openRouterModelsModule = require('./openRouterModels.js') as {
476
  getCachedOpenRouterModels: () => ModelOption[]
 
477
  }
478
  cachedModels = openRouterModelsModule.getCachedOpenRouterModels()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  } catch {
480
  // Module not yet loaded - will be populated by background fetch
481
  }
482
 
483
- // If we have cached models, use them
484
- if (cachedModels.length > 0) {
485
- return [
486
- getDefaultOptionForUser(fastMode),
487
- ...cachedModels.slice(0, 100), // Show top 100 models
488
- ]
489
- }
490
-
491
- // No cached models yet, just show Default option
492
  // The background fetch will populate the cache for next time
493
- return [getDefaultOptionForUser(fastMode)]
494
  }
495
 
496
  // PAYG 3P: Default (Sonnet 4.5) + Sonnet (3P custom) or Sonnet 4.6/1M + Opus (3P custom) or Opus 4.1/Opus 4.6/Opus1M + Haiku + Opus 4.1
 
474
  // eslint-disable-next-line @typescript-eslint/no-require-imports
475
  const openRouterModelsModule = require('./openRouterModels.js') as {
476
  getCachedOpenRouterModels: () => ModelOption[]
477
+ getFirstFreeModel: () => ModelOption | null
478
  }
479
  cachedModels = openRouterModelsModule.getCachedOpenRouterModels()
480
+
481
+ // Find the first free model
482
+ const firstFreeModel = openRouterModelsModule.getFirstFreeModel()
483
+
484
+ // If we have cached models, show them
485
+ if (cachedModels.length > 0) {
486
+ let modelsToShow = cachedModels.slice(0, 100) // Show top 100 models
487
+
488
+ // If there's a free model, put it at the front
489
+ if (firstFreeModel) {
490
+ // Remove the free model from its current position
491
+ modelsToShow = modelsToShow.filter(m => m.value !== firstFreeModel.value)
492
+ // Add it to the front
493
+ modelsToShow = [firstFreeModel, ...modelsToShow]
494
+ }
495
+
496
+ return modelsToShow
497
+ }
498
  } catch {
499
  // Module not yet loaded - will be populated by background fetch
500
  }
501
 
502
+ // No cached models yet, return empty array
 
 
 
 
 
 
 
 
503
  // The background fetch will populate the cache for next time
504
+ return []
505
  }
506
 
507
  // PAYG 3P: Default (Sonnet 4.5) + Sonnet (3P custom) or Sonnet 4.6/1M + Opus (3P custom) or Opus 4.1/Opus 4.6/Opus1M + Haiku + Opus 4.1
src/utils/model/openRouterModels.ts CHANGED
@@ -138,6 +138,19 @@ export function hasOpenRouterModelsCache(): boolean {
138
  return openRouterModelsCache !== null
139
  }
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  export function clearOpenRouterModelsCache(): void {
142
  openRouterModelsCache = null
143
  cacheTimestamp = 0
 
138
  return openRouterModelsCache !== null
139
  }
140
 
141
+ export function getFirstFreeModel(): ModelOption | null {
142
+ if (!openRouterModelsCache || openRouterModelsCache.length === 0) {
143
+ return null
144
+ }
145
+
146
+ return openRouterModelsCache.find(model => {
147
+ // Check if this model is free by looking at the model name
148
+ // Models with "(free)" in the name are free
149
+ const label = model.label || ''
150
+ return label.toLowerCase().includes('(free)')
151
+ }) || null
152
+ }
153
+
154
  export function clearOpenRouterModelsCache(): void {
155
  openRouterModelsCache = null
156
  cacheTimestamp = 0