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:
@@ -10,6 +10,7 @@ const discoverAndLoadExtensionsMock = vi.fn().mockResolvedValue({
|
||||
});
|
||||
const packageManagerResolveMock = vi.fn().mockResolvedValue({ extensions: [] });
|
||||
const findMock = vi.fn();
|
||||
const getAllMock = vi.fn(() => [] as any[]);
|
||||
const registerProviderMock = vi.fn();
|
||||
const refreshMock = vi.fn();
|
||||
const settingsManagerCreateMock = vi.fn(() => ({ kind: "settings-manager-create" }));
|
||||
@@ -43,6 +44,9 @@ vi.mock("@mariozechner/pi-coding-agent", () => ({
|
||||
find(provider: string, modelId: string) {
|
||||
return findMock(provider, modelId);
|
||||
}
|
||||
getAll() {
|
||||
return getAllMock();
|
||||
}
|
||||
registerProvider(name: string, config: unknown) {
|
||||
return registerProviderMock(name, config);
|
||||
}
|
||||
|
||||
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user