mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 08:40:21 +00:00
refactor web search config ownership into extensions
This commit is contained in:
@@ -61,22 +61,26 @@ function readProviderEnvValue(envVars: string[]): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function hasProviderCredential(providerId: string, search: WebSearchConfig | undefined): boolean {
|
||||
function hasProviderCredential(
|
||||
providerId: string,
|
||||
config: OpenClawConfig | undefined,
|
||||
search: WebSearchConfig | undefined,
|
||||
): boolean {
|
||||
const providers = resolvePluginWebSearchProviders({
|
||||
config,
|
||||
bundledAllowlistCompat: true,
|
||||
});
|
||||
const provider = providers.find((entry) => entry.id === providerId);
|
||||
if (!provider) {
|
||||
return false;
|
||||
}
|
||||
const rawValue = provider.getCredentialValue(search as Record<string, unknown> | undefined);
|
||||
const rawValue =
|
||||
provider.getConfiguredCredentialValue?.(config) ??
|
||||
provider.getCredentialValue(search as Record<string, unknown> | undefined);
|
||||
const fromConfig = normalizeSecretInput(
|
||||
normalizeResolvedSecretInputString({
|
||||
value: rawValue,
|
||||
path:
|
||||
providerId === "brave"
|
||||
? "tools.web.search.apiKey"
|
||||
: `tools.web.search.${providerId}.apiKey`,
|
||||
path: provider.credentialPath,
|
||||
}),
|
||||
);
|
||||
return Boolean(fromConfig || readProviderEnvValue(provider.envVars));
|
||||
@@ -93,11 +97,13 @@ export function listWebSearchProviders(params?: {
|
||||
|
||||
export function resolveWebSearchProviderId(params: {
|
||||
search?: WebSearchConfig;
|
||||
config?: OpenClawConfig;
|
||||
providers?: PluginWebSearchProviderEntry[];
|
||||
}): string {
|
||||
const providers =
|
||||
params.providers ??
|
||||
resolvePluginWebSearchProviders({
|
||||
config: params.config,
|
||||
bundledAllowlistCompat: true,
|
||||
});
|
||||
const raw =
|
||||
@@ -114,7 +120,7 @@ export function resolveWebSearchProviderId(params: {
|
||||
|
||||
if (!raw) {
|
||||
for (const provider of providers) {
|
||||
if (!hasProviderCredential(provider.id, params.search)) {
|
||||
if (!hasProviderCredential(provider.id, params.config, params.search)) {
|
||||
continue;
|
||||
}
|
||||
logVerbose(
|
||||
@@ -124,7 +130,7 @@ export function resolveWebSearchProviderId(params: {
|
||||
}
|
||||
}
|
||||
|
||||
return providers[0]?.id ?? "brave";
|
||||
return providers[0]?.id ?? "";
|
||||
}
|
||||
|
||||
export function resolveWebSearchDefinition(
|
||||
@@ -154,10 +160,13 @@ export function resolveWebSearchDefinition(
|
||||
options?.providerId ??
|
||||
options?.runtimeWebSearch?.selectedProvider ??
|
||||
options?.runtimeWebSearch?.providerConfigured ??
|
||||
resolveWebSearchProviderId({ search, providers });
|
||||
resolveWebSearchProviderId({ config: options?.config, search, providers });
|
||||
const provider =
|
||||
providers.find((entry) => entry.id === providerId) ??
|
||||
providers.find((entry) => entry.id === resolveWebSearchProviderId({ search, providers })) ??
|
||||
providers.find(
|
||||
(entry) =>
|
||||
entry.id === resolveWebSearchProviderId({ config: options?.config, search, providers }),
|
||||
) ??
|
||||
providers[0];
|
||||
if (!provider) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user