fix: include configured provider rows in all models list

This commit is contained in:
Shakker
2026-04-24 01:09:37 +01:00
committed by Shakker
parent d289e400d5
commit 19f9b69586
3 changed files with 22 additions and 8 deletions

View File

@@ -474,7 +474,9 @@ describe("models list/status", () => {
models: {
providers: {
"custom-proxy": {
api: "openai-responses",
baseUrl: "https://custom.example/v1",
apiKey: "$CUSTOM_PROXY_API_KEY",
models: [
{
id: "custom-model",
@@ -491,6 +493,7 @@ describe("models list/status", () => {
models: {
providers: {
"custom-proxy": {
api: "openai-responses",
baseUrl: "https://custom.example/v1",
apiKey: "sk-resolved-runtime-value", // pragma: allowlist secret
models: [
@@ -512,7 +515,7 @@ describe("models list/status", () => {
getRuntimeConfig.mockReturnValue(resolvedConfig);
const runtime = makeRuntime();
await modelsListCommand({ all: true, provider: "custom-proxy", json: true }, runtime);
await modelsListCommand({ all: true, json: true }, runtime);
expect(ensureOpenClawModelsJson).not.toHaveBeenCalled();
const payload = parseJsonLog(runtime);

View File

@@ -104,13 +104,11 @@ export async function modelsListCommand(
context: rowContext,
});
if (providerFilter) {
appendConfiguredProviderRows({
rows,
context: rowContext,
seenKeys,
});
}
appendConfiguredProviderRows({
rows,
context: rowContext,
seenKeys,
});
if (modelRegistry) {
await appendCatalogSupplementRows({

View File

@@ -104,6 +104,16 @@ function toConfiguredProviderListModel(params: {
};
}
function shouldListConfiguredProviderModel(params: {
providerConfig: Partial<ModelProviderConfig>;
model: Partial<ModelDefinitionConfig>;
}): boolean {
return (
params.providerConfig.apiKey !== undefined &&
(params.providerConfig.api !== undefined || params.model.api !== undefined)
);
}
export async function loadListModelRegistry(
cfg: OpenClawConfig,
opts?: { providerFilter?: string },
@@ -159,6 +169,9 @@ export function appendConfiguredProviderRows(params: {
params.context.cfg.models?.providers ?? {},
)) {
for (const configuredModel of providerConfig.models ?? []) {
if (!shouldListConfiguredProviderModel({ providerConfig, model: configuredModel })) {
continue;
}
const key = modelKey(provider, configuredModel.id);
if (params.seenKeys.has(key)) {
continue;