mirror of https://github.com/openclaw/openclaw.git
perf: trim provider policy runtime lookups
This commit is contained in:
parent
d28b02a7b1
commit
1d2d70a8fd
|
|
@ -299,6 +299,12 @@ async function inferImplicitProviderTestPluginIds(params: {
|
|||
providerIds.add(pluginId);
|
||||
}
|
||||
}
|
||||
const legacyGrokApiKey = (
|
||||
params.config?.tools?.web?.search as { grok?: { apiKey?: unknown } } | undefined
|
||||
)?.grok?.apiKey;
|
||||
if (legacyGrokApiKey !== undefined) {
|
||||
providerIds.add("xai");
|
||||
}
|
||||
if (providerIds.size === 0) {
|
||||
// No config/env/auth hints: keep ambient local auto-discovery focused on the
|
||||
// one provider that is expected to probe localhost in tests.
|
||||
|
|
|
|||
|
|
@ -38,4 +38,16 @@ describe("models-config.providers.policy", () => {
|
|||
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not treat generic transport APIs as provider plugin ids", () => {
|
||||
const provider = {
|
||||
api: "openai-completions" as const,
|
||||
baseUrl: "https://example.invalid/v1",
|
||||
apiKey: "EXAMPLE_KEY",
|
||||
models: [],
|
||||
};
|
||||
|
||||
expect(resolveProviderConfigApiKeyResolver("dashscope-vision", provider)).toBeUndefined();
|
||||
expect(normalizeProviderSpecificConfig("dashscope-vision", provider)).toBe(provider);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,19 +1,35 @@
|
|||
import { resolveMantleBearerToken } from "../../extensions/amazon-bedrock-mantle/discovery.js";
|
||||
import { resolveBedrockConfigApiKey } from "../../extensions/amazon-bedrock/api.js";
|
||||
import { resolveAnthropicVertexConfigApiKey } from "../../extensions/anthropic-vertex/region.js";
|
||||
import {
|
||||
normalizeGoogleProviderConfig,
|
||||
shouldNormalizeGoogleProviderConfig,
|
||||
} from "../../extensions/google/api.js";
|
||||
import { MODEL_APIS } from "../config/types.models.js";
|
||||
import {
|
||||
applyProviderNativeStreamingUsageCompatWithPlugin,
|
||||
normalizeProviderConfigWithPlugin,
|
||||
resolveProviderConfigApiKeyWithPlugin,
|
||||
resolveProviderRuntimePlugin,
|
||||
} from "../plugins/provider-runtime.js";
|
||||
import type { ProviderConfig } from "./models-config.providers.secrets.js";
|
||||
|
||||
const GENERIC_PROVIDER_APIS = new Set<string>([
|
||||
"openai-completions",
|
||||
"openai-responses",
|
||||
"anthropic-messages",
|
||||
"google-generative-ai",
|
||||
]);
|
||||
const PROVIDERS_WITH_RUNTIME_NORMALIZE_CONFIG = new Set<string>(["anthropic"]);
|
||||
|
||||
function resolveProviderPluginLookupKey(providerKey: string, provider?: ProviderConfig): string {
|
||||
const api = typeof provider?.api === "string" ? provider.api.trim() : "";
|
||||
return api || providerKey;
|
||||
if (
|
||||
api &&
|
||||
MODEL_APIS.includes(api as (typeof MODEL_APIS)[number]) &&
|
||||
!GENERIC_PROVIDER_APIS.has(api)
|
||||
) {
|
||||
return api;
|
||||
}
|
||||
return providerKey;
|
||||
}
|
||||
|
||||
export function applyNativeStreamingUsageCompat(
|
||||
|
|
@ -47,6 +63,9 @@ export function normalizeProviderSpecificConfig(
|
|||
return normalizeGoogleProviderConfig(providerKey, provider);
|
||||
}
|
||||
const runtimeProviderKey = resolveProviderPluginLookupKey(providerKey, provider);
|
||||
if (!PROVIDERS_WITH_RUNTIME_NORMALIZE_CONFIG.has(runtimeProviderKey)) {
|
||||
return provider;
|
||||
}
|
||||
const normalized =
|
||||
normalizeProviderConfigWithPlugin({
|
||||
provider: runtimeProviderKey,
|
||||
|
|
@ -71,19 +90,16 @@ export function resolveProviderConfigApiKeyResolver(
|
|||
return resolved?.trim() || undefined;
|
||||
};
|
||||
}
|
||||
const runtimeProviderKey = resolveProviderPluginLookupKey(providerKey, provider);
|
||||
if (!resolveProviderRuntimePlugin({ provider: runtimeProviderKey })?.resolveConfigApiKey) {
|
||||
return undefined;
|
||||
const runtimeProviderKey = resolveProviderPluginLookupKey(providerKey, provider).trim();
|
||||
if (runtimeProviderKey === "anthropic-vertex") {
|
||||
return (env) => {
|
||||
const resolved = resolveAnthropicVertexConfigApiKey(env);
|
||||
return resolved?.trim() || undefined;
|
||||
};
|
||||
}
|
||||
return (env) => {
|
||||
const resolved = resolveProviderConfigApiKeyWithPlugin({
|
||||
provider: runtimeProviderKey,
|
||||
env,
|
||||
context: {
|
||||
provider: providerKey,
|
||||
env,
|
||||
},
|
||||
});
|
||||
return resolved?.trim() || undefined;
|
||||
};
|
||||
if (runtimeProviderKey === "amazon-bedrock-mantle") {
|
||||
return (env) =>
|
||||
resolveMantleBearerToken(env)?.trim() ? "AWS_BEARER_TOKEN_BEDROCK" : undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue