fix(engine): fall back to provider template for unrecognized model IDs

When a configured primary/fallback model isn't found in the registry,
check if the provider has any known models and construct a model
on-the-fly using that provider as a template (mirroring the pi CLI's
buildFallbackModel logic). This lets any valid provider model ID work
(e.g. any OpenRouter model string) without requiring it to be in the
built-in or custom model list. Only throw if the provider itself is
completely unknown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-05 22:17:30 -07:00
parent e3ad694d7a
commit ef3136d601
2 changed files with 15 additions and 0 deletions

View File

@@ -154,6 +154,17 @@ function resolveConfiguredModel(
return model;
}
// Fall back to constructing a model on-the-fly if the provider is known.
// This mirrors the pi CLI's buildFallbackModel behaviour, which accepts any
// model ID for a configured provider (e.g. any OpenRouter model string) even
// when it isn't in the built-in or custom model list.
const providerModels = modelRegistry.getAll().filter((m) => m.provider === provider);
if (providerModels.length > 0) {
const baseModel = providerModels[0]!;
console.log(`[pi] ${kind} model ${provider}/${modelId} not in registry; using provider base model as template`);
return { ...baseModel, id: modelId, name: modelId };
}
throw new Error(
`Configured ${kind} model ${provider}/${modelId} was not found in the pi model registry. ` +
"Open Settings and choose a model from /api/models, or update your pi model configuration.",