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