Skip to content

Commit 35bc23c

Browse files
committed
fix(agents): count env/config credentials in plugin tool provider-auth gating (#103828)
The plugin-tool availability gate (hasAuthForProvider) consulted only the auth profile store, so tools like image analysis rejected providers whose API key arrives via the process environment (including keys injected through OPENCLAW_SERVICE_MANAGED_ENV_KEYS) or config apiKey SecretRefs - paths chat routing resolves fine via resolveApiKeyForProvider. Route the gate through the shared hasProviderAuthForTool helper the media model selection already uses, which layers runtime env, custom-provider SecretRefs, managed secrets, and the profile store.
1 parent 7647d5c commit 35bc23c

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎src/agents/openclaw-plugin-tools.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "./openclaw-tools.plugin-context.js";
2121
import { applyPluginToolDeliveryDefaults } from "./plugin-tool-delivery-defaults.js";
2222
import type { AnyAgentTool } from "./tools/common.js";
23+
import { hasProviderAuthForTool } from "./tools/model-config.helpers.js";
2324

2425
type ResolveOpenClawPluginToolsOptions = OpenClawPluginToolOptions & {
2526
pluginToolAllowlist?: string[];
@@ -92,9 +93,18 @@ export function resolveOpenClawPluginToolsForOptions(params: {
9293
provider: providerId,
9394
})
9495
: undefined;
95-
const hasAuthForProvider = authProfileStore
96-
? (providerId: string) => (resolveAuthProfileIdsForProvider?.(providerId) ?? []).length > 0
97-
: undefined;
96+
// Availability must match what chat routing can actually resolve: env keys
97+
// (incl. OPENCLAW_SERVICE_MANAGED_ENV_KEYS-injected ones), config apiKey
98+
// SecretRefs, and managed secrets count too, not only auth-profile entries.
99+
// A store-only check rejected providers whose key lives solely in the
100+
// service-managed environment (#103828).
101+
const hasAuthForProvider = (providerId: string) =>
102+
hasProviderAuthForTool({
103+
provider: providerId,
104+
cfg: resolveCurrentRuntimeConfig(),
105+
agentDir: params.options?.agentDir,
106+
...(authProfileStore ? { authStore: authProfileStore } : {}),
107+
});
98108
const resolveApiKeyForProvider = authProfileStore
99109
? async (providerId: string): Promise<string | undefined> => {
100110
for (const profileId of resolveAuthProfileIdsForProvider?.(providerId) ?? []) {
@@ -121,14 +131,14 @@ export function resolveOpenClawPluginToolsForOptions(params: {
121131
...pluginToolInputs,
122132
context: {
123133
...pluginToolInputs.context,
124-
...(hasAuthForProvider ? { hasAuthForProvider } : {}),
134+
hasAuthForProvider,
125135
...(resolveApiKeyForProvider ? { resolveApiKeyForProvider } : {}),
126136
},
127137
existingToolNames: params.existingToolNames ?? new Set<string>(),
128138
toolAllowlist: params.options?.pluginToolAllowlist,
129139
toolDenylist: params.options?.pluginToolDenylist,
130140
allowGatewaySubagentBinding: params.options?.allowGatewaySubagentBinding,
131-
...(hasAuthForProvider ? { hasAuthForProvider } : {}),
141+
hasAuthForProvider,
132142
});
133143

134144
return applyPluginToolDeliveryDefaults({

‎src/agents/tools/image-tool.custom-provider-auth.regression.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ describe("image custom provider auth regression", () => {
234234
});
235235
});
236236

237+
it("accepts a custom provider whose key arrives only via the process environment", async () => {
238+
// Service-managed env keys (OPENCLAW_SERVICE_MANAGED_ENV_KEYS) land in
239+
// process.env, not in the auth profile store; availability gating must
240+
// count them like chat routing does (#103828).
241+
const cfg = createUserReportedConfig({ includeApiKey: false });
242+
const providers = (cfg.models?.providers ?? {}) as Record<string, { apiKey?: unknown }>;
243+
const providerEntry = providers[USER_PROVIDER];
244+
if (providerEntry) {
245+
providerEntry.apiKey = "${NVIDIA_TEST_API_KEY}";
246+
}
247+
const previous = process.env.NVIDIA_TEST_API_KEY;
248+
process.env.NVIDIA_TEST_API_KEY = "test-env-only-key";
249+
try {
250+
expect(hasProviderAuthForTool({ provider: USER_PROVIDER, cfg })).toBe(true);
251+
} finally {
252+
if (previous === undefined) {
253+
delete process.env.NVIDIA_TEST_API_KEY;
254+
} else {
255+
process.env.NVIDIA_TEST_API_KEY = previous;
256+
}
257+
}
258+
});
259+
237260
it("still rejects the same config when apiKey is missing", async () => {
238261
await withEmptyAgentDir(async (agentDir) => {
239262
const cfg = createUserReportedConfig({ includeApiKey: false });

0 commit comments

Comments
 (0)