fix: use static provider catalogs for model listing

This commit is contained in:
Shakker
2026-04-22 02:36:18 +01:00
committed by Shakker
parent 651d5e0022
commit 04ecf284fc
16 changed files with 219 additions and 25 deletions

View File

@@ -15,6 +15,10 @@ function resolveProviderCatalogHook(provider: ProviderPlugin) {
return provider.catalog ?? provider.discovery;
}
function resolveProviderCatalogOrderHook(provider: ProviderPlugin) {
return resolveProviderCatalogHook(provider) ?? provider.staticCatalog;
}
export async function resolvePluginDiscoveryProviders(params: {
config?: OpenClawConfig;
workspaceDir?: string;
@@ -23,7 +27,7 @@ export async function resolvePluginDiscoveryProviders(params: {
}): Promise<ProviderPlugin[]> {
return (await loadProviderRuntime())
.resolvePluginDiscoveryProvidersRuntime(params)
.filter((provider) => resolveProviderCatalogHook(provider));
.filter((provider) => resolveProviderCatalogOrderHook(provider));
}
export function groupPluginDiscoveryProvidersByOrder(
@@ -37,7 +41,7 @@ export function groupPluginDiscoveryProvidersByOrder(
} as Record<ProviderDiscoveryOrder, ProviderPlugin[]>;
for (const provider of providers) {
const order = resolveProviderCatalogHook(provider)?.order ?? "late";
const order = resolveProviderCatalogOrderHook(provider)?.order ?? "late";
grouped[order].push(provider);
}
@@ -118,3 +122,26 @@ export function runProviderCatalog(params: {
resolveProviderAuth: params.resolveProviderAuth,
});
}
export function runProviderStaticCatalog(params: {
provider: ProviderPlugin;
config: OpenClawConfig;
agentDir?: string;
workspaceDir?: string;
env: NodeJS.ProcessEnv;
}) {
return params.provider.staticCatalog?.run({
config: params.config,
agentDir: params.agentDir,
workspaceDir: params.workspaceDir,
env: params.env,
resolveProviderApiKey: () => ({
apiKey: undefined,
}),
resolveProviderAuth: () => ({
apiKey: undefined,
mode: "none",
source: "none",
}),
});
}

View File

@@ -1083,6 +1083,14 @@ export type ProviderPlugin = {
* Returns provider config/model definitions that merge into models.providers.
*/
catalog?: ProviderPluginCatalog;
/**
* Offline provider catalog for display-only surfaces.
*
* Unlike `catalog`, this hook must not perform network I/O or require real
* credentials. Use it for bundled/static rows that can be shown before auth is
* configured.
*/
staticCatalog?: ProviderPluginCatalog;
/**
* Legacy alias for catalog.
* Kept for compatibility with existing provider plugins.