MCPcopy Index your code
hub / github.com/freecodexyz/free-code / parseUserSpecifiedModel

Function parseUserSpecifiedModel

src/utils/model/model.ts:484–545  ·  view source on GitHub ↗
(
  modelInput: ModelName | ModelAlias,
)

Source from the content-addressed store, hash-verified

482 * @param modelInput The model alias or name provided by the user.
483 */
484export function parseUserSpecifiedModel(
485 modelInput: ModelName | ModelAlias,
486): ModelName {
487 const modelInputTrimmed = modelInput.trim()
488 const normalizedModel = modelInputTrimmed.toLowerCase()
489
490 const has1mTag = has1mContext(normalizedModel)
491 const modelString = has1mTag
492 ? normalizedModel.replace(/\[1m]$/i, '').trim()
493 : normalizedModel
494
495 if (isModelAlias(modelString)) {
496 switch (modelString) {
497 case 'opusplan':
498 return getDefaultSonnetModel() + (has1mTag ? '[1m]' : '') // Sonnet is default, Opus in plan mode
499 case 'sonnet':
500 return getDefaultSonnetModel() + (has1mTag ? '[1m]' : '')
501 case 'haiku':
502 return getDefaultHaikuModel() + (has1mTag ? '[1m]' : '')
503 case 'opus':
504 return getDefaultOpusModel() + (has1mTag ? '[1m]' : '')
505 case 'best':
506 return getBestModel()
507 default:
508 }
509 }
510
511 // Opus 4/4.1 are no longer available on the first-party API (same as
512 // Claude.ai) — silently remap to the current Opus default. The 'opus'
513 // alias already resolves to 4.6, so the only users on these explicit
514 // strings pinned them in settings/env/--model/SDK before 4.5 launched.
515 // 3P providers may not yet have 4.6 capacity, so pass through unchanged.
516 if (
517 getAPIProvider() === 'firstParty' &&
518 isLegacyOpusFirstParty(modelString) &&
519 isLegacyModelRemapEnabled()
520 ) {
521 return getDefaultOpusModel() + (has1mTag ? '[1m]' : '')
522 }
523
524 if (process.env.USER_TYPE === 'ant') {
525 const has1mAntTag = has1mContext(normalizedModel)
526 const baseAntModel = normalizedModel.replace(/\[1m]$/i, '').trim()
527
528 const antModel = resolveAntModel(baseAntModel)
529 if (antModel) {
530 const suffix = has1mAntTag ? '[1m]' : ''
531 return antModel.model + suffix
532 }
533
534 // Fall through to the alias string if we cannot load the config. The API calls
535 // will fail with this string, but we should hear about it through feedback and
536 // can tell the user to restart/wait for flag cache refresh to get the latest values.
537 }
538
539 // Preserve original case for custom model names (e.g., Azure Foundry deployment IDs)
540 // Only strip [1m] suffix if present, maintaining case of the base model
541 if (has1mTag) {

Callers 15

submitMessageMethod · 0.85
logSessionTelemetryFunction · 0.85
runFunction · 0.85
getDefaultTeammateModelFunction · 0.85
renderToolUseTagFunction · 0.85
callFunction · 0.85
shouldShowEffortCalloutFunction · 0.85
resolveOptionModelFunction · 0.85
restoreAgentFromSessionFunction · 0.85
modelBelongsToFamilyFunction · 0.85

Calls 10

has1mContextFunction · 0.85
isModelAliasFunction · 0.85
getDefaultSonnetModelFunction · 0.85
getDefaultHaikuModelFunction · 0.85
getDefaultOpusModelFunction · 0.85
getBestModelFunction · 0.85
getAPIProviderFunction · 0.85
isLegacyOpusFirstPartyFunction · 0.85
resolveAntModelFunction · 0.85

Tested by

no test coverage detected