fix(agent): add OpenRouter provider support and guard against unknown models
Use generic OPENROUTER_* env vars (OPENROUTER_API_KEY, OPENROUTER_BASE_URL, OPENROUTER_MODEL) via the existing fallback mechanism instead of hardcoding mappings to OPENAI_* vars. Also add a guard when resolveModel returns undefined to throw a clear error instead of crashing on property access. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4f50b3b399
commit
b8201293b6
1 changed files with 8 additions and 0 deletions
|
|
@ -177,6 +177,14 @@ export class Agent {
|
|||
const effectiveModel = resolvedModel ?? options.model ?? storedMeta?.model;
|
||||
let model = resolveModel({ ...options, provider: effectiveProvider, model: effectiveModel });
|
||||
|
||||
if (!model) {
|
||||
throw new Error(
|
||||
`Unknown model: provider="${effectiveProvider}", model="${effectiveModel}". ` +
|
||||
`Check your LLM_PROVIDER and model env vars (e.g. OPENAI_MODEL). ` +
|
||||
`For OpenRouter, use LLM_PROVIDER=openrouter.`,
|
||||
);
|
||||
}
|
||||
|
||||
// Override base URL if provided via options or environment variable
|
||||
const baseUrl = resolveBaseUrl(model.provider, options.baseUrl);
|
||||
if (baseUrl) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue