Skip to content

Commit d264ef6

Browse files
committed
fix(gateway): honor profile auth for SecretRef model entries
1 parent 520992a commit d264ef6

2 files changed

Lines changed: 83 additions & 19 deletions

File tree

src/gateway/server-methods/models-list-result.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
type AuthProfileStore,
1515
} from "../../agents/auth-profiles.js";
1616
import { DEFAULT_PROVIDER } from "../../agents/defaults.js";
17-
import { NON_ENV_SECRETREF_MARKER } from "../../agents/model-auth-markers.js";
1817
import { hasRuntimeAvailableProviderAuth } from "../../agents/model-auth.js";
1918
import {
2019
loadModelCatalogForBrowse,
@@ -57,18 +56,6 @@ function omitRuntimeModelParams(entry: ModelCatalogEntry): ModelCatalogEntry {
5756
return rest;
5857
}
5958

60-
function modelCatalogEntryHasUnknownSecretRefAvailability(
61-
cfg: OpenClawConfig,
62-
entry: ModelCatalogEntry,
63-
): boolean {
64-
const providerId = normalizeProviderId(entry.provider);
65-
const provider = Object.entries(cfg.models?.providers ?? {}).find(
66-
([id]) => normalizeProviderId(id) === providerId,
67-
)?.[1];
68-
const apiKey = provider?.apiKey;
69-
return apiKey === NON_ENV_SECRETREF_MARKER || (isSecretRef(apiKey) && apiKey.source !== "env");
70-
}
71-
7259
function createInFlightProviderAuthChecker(
7360
providerAuthChecker: ModelsListProviderAuthChecker,
7461
): ModelsListProviderAuthChecker {
@@ -223,12 +210,6 @@ async function buildPublicModelsListEntry(params: {
223210
providerAuthChecker?: ModelsListProviderAuthChecker;
224211
}): Promise<ModelsListEntry> {
225212
const publicEntry = omitRuntimeModelParams(params.entry);
226-
if (modelCatalogEntryHasUnknownSecretRefAvailability(params.cfg, params.entry)) {
227-
return {
228-
...publicEntry,
229-
available: false,
230-
};
231-
}
232213
if (!params.providerAuthChecker) {
233214
return publicEntry;
234215
}

src/gateway/server-methods/models.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,89 @@ describe("models.list", () => {
549549
);
550550
});
551551

552+
it("marks auth profiles available even when provider config uses non-env SecretRef markers", async () => {
553+
for (const fixture of [
554+
{
555+
name: "file",
556+
apiKey: {
557+
source: "file",
558+
provider: "mounted-json",
559+
id: "/providers/vllm/apiKey",
560+
},
561+
},
562+
{ name: "managed-marker", apiKey: "secretref-managed" },
563+
] as const) {
564+
await withOpenClawTestState(
565+
{
566+
layout: "state-only",
567+
prefix: `openclaw-models-list-provider-${fixture.name}-profile-`,
568+
agentEnv: "main",
569+
env: {
570+
VLLM_API_KEY: "test-token",
571+
},
572+
},
573+
async (state) => {
574+
await state.writeAuthProfiles({
575+
version: 1,
576+
profiles: {
577+
"vllm:env": {
578+
type: "api_key",
579+
provider: "vllm",
580+
keyRef: {
581+
source: "env",
582+
provider: "default",
583+
id: "VLLM_API_KEY",
584+
},
585+
},
586+
},
587+
});
588+
589+
const cfg = {
590+
agents: {
591+
defaults: {
592+
models: {
593+
"vllm/*": {},
594+
},
595+
},
596+
},
597+
models: {
598+
providers: {
599+
vllm: {
600+
apiKey: fixture.apiKey,
601+
},
602+
},
603+
},
604+
} as unknown as OpenClawConfig;
605+
606+
const { request, respond } = requestModelsList({
607+
view: "all",
608+
runtimeConfig: cfg,
609+
loadGatewayModelCatalog: vi.fn(() =>
610+
Promise.resolve([{ id: "llama-secure", name: "Llama Secure", provider: "vllm" }]),
611+
),
612+
reqId: `req-models-list-provider-${fixture.name}-profile`,
613+
});
614+
await request;
615+
616+
expect(respond).toHaveBeenCalledWith(
617+
true,
618+
{
619+
models: [
620+
{
621+
id: "llama-secure",
622+
name: "Llama Secure",
623+
provider: "vllm",
624+
available: true,
625+
},
626+
],
627+
},
628+
undefined,
629+
);
630+
},
631+
);
632+
}
633+
});
634+
552635
it("preserves catalog load errors before the timeout fallback wins", async () => {
553636
const { request, respond } = requestModelsList({
554637
view: "configured",

0 commit comments

Comments
 (0)