fix(agent): validate assistant model requests
This commit is contained in:
@@ -41,9 +41,8 @@ export function normalizeLlmModelsPayload(payload: unknown): LlmModelOption[] {
|
||||
if (typeof row !== "object" || row === null || !("id" in row)) continue;
|
||||
const id = (row as { id?: unknown }).id;
|
||||
if (typeof id !== "string") continue;
|
||||
const trimmed = id.trim();
|
||||
if (!isValidLlmModelId(trimmed)) continue;
|
||||
ids.add(trimmed);
|
||||
if (!isValidLlmModelId(id)) continue;
|
||||
ids.add(id);
|
||||
}
|
||||
|
||||
return [...ids].sort((a, b) => a.localeCompare(b)).map((id) => ({ id, label: id }));
|
||||
@@ -101,8 +100,8 @@ export function resolveAssistantModel(options: {
|
||||
? options.fallbackModel
|
||||
: (options.models[0]?.id ?? options.fallbackModel);
|
||||
|
||||
if (options.requestedModel) {
|
||||
if (!available.has(options.requestedModel)) {
|
||||
if (options.requestedModel !== null && options.requestedModel !== undefined) {
|
||||
if (!isValidLlmModelId(options.requestedModel) || !available.has(options.requestedModel)) {
|
||||
return { ok: false, model: fallback, error: "Invalid assistant model" };
|
||||
}
|
||||
return { ok: true, model: options.requestedModel };
|
||||
|
||||
Reference in New Issue
Block a user