Fix: Add type safety to models status command

Add type checks before calling .trim() to prevent crashes when config
contains non-string values:
- Check entry.alias is string before trimming (line 110)
- Validate provider keys before trimming (lines 130, 179)

Prevents "Cannot read properties of undefined (reading 'trim')" errors.

Fixes #7062

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
BinHPdev
2026-02-15 02:28:52 +08:00
committed by Gustavo Madeira Santana
parent 01ec81dae4
commit b3e11605ca

View File

@@ -107,7 +107,7 @@ export async function modelsStatusCommand(
const imageFallbacks = typeof imageConfig === "object" ? (imageConfig?.fallbacks ?? []) : [];
const aliases = Object.entries(cfg.agents?.defaults?.models ?? {}).reduce<Record<string, string>>(
(acc, [key, entry]) => {
const alias = entry?.alias?.trim();
const alias = typeof entry?.alias === "string" ? entry.alias.trim() : undefined;
if (alias) {
acc[alias] = key;
}
@@ -127,7 +127,7 @@ export async function modelsStatusCommand(
);
const providersFromConfig = new Set(
Object.keys(cfg.models?.providers ?? {})
.map((p) => p.trim())
.map((p) => (typeof p === "string" ? p.trim() : ""))
.filter(Boolean),
);
const providersFromModels = new Set<string>();
@@ -176,7 +176,7 @@ export async function modelsStatusCommand(
...providersFromEnv,
]),
)
.map((p) => p.trim())
.map((p) => (typeof p === "string" ? p.trim() : ""))
.filter(Boolean)
.toSorted((a, b) => a.localeCompare(b));