fix(cli): validate --model argument at startup (#21393)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Jaisal K Jain
2026-03-12 20:08:54 +05:30
committed by GitHub
parent 8432bcee75
commit 34709dc62d
4 changed files with 125 additions and 4 deletions
+43
View File
@@ -32,6 +32,15 @@ export const GEMINI_MODEL_ALIAS_PRO = 'pro';
export const GEMINI_MODEL_ALIAS_FLASH = 'flash';
export const GEMINI_MODEL_ALIAS_FLASH_LITE = 'flash-lite';
export const VALID_ALIASES = new Set([
GEMINI_MODEL_ALIAS_AUTO,
GEMINI_MODEL_ALIAS_PRO,
GEMINI_MODEL_ALIAS_FLASH,
GEMINI_MODEL_ALIAS_FLASH_LITE,
PREVIEW_GEMINI_MODEL_AUTO,
DEFAULT_GEMINI_MODEL_AUTO,
]);
export const DEFAULT_GEMINI_EMBEDDING_MODEL = 'gemini-embedding-001';
// Cap the thinking at 8192 to prevent run-away thinking loops.
@@ -283,3 +292,37 @@ export function isActiveModel(
);
}
}
/**
* Checks if the model name is valid (either a valid model or a valid alias).
*
* @param model The model name to check.
* @returns True if the model is valid.
*/
export function isValidModelOrAlias(model: string): boolean {
// Check if it's a valid alias
if (VALID_ALIASES.has(model)) {
return true;
}
// Check if it's a valid model name
if (VALID_GEMINI_MODELS.has(model)) {
return true;
}
// Allow custom models (non-gemini models)
if (!model.startsWith('gemini-')) {
return true;
}
return false;
}
/**
* Gets a list of all valid model names and aliases for error messages.
*
* @returns Array of valid model names and aliases.
*/
export function getValidModelsAndAliases(): string[] {
return [...new Set([...VALID_ALIASES, ...VALID_GEMINI_MODELS])].sort();
}