mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 04:20:21 +00:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { OpenClawConfig } from "../config/config.js";
|
|
import type { PluginManifestRecord } from "./manifest-registry.js";
|
|
import { resolvePluginWebSearchProviders } from "./web-search-providers.runtime.js";
|
|
|
|
function hasConfiguredCredentialValue(value: unknown): boolean {
|
|
if (typeof value === "string") {
|
|
return value.trim().length > 0;
|
|
}
|
|
return value !== undefined && value !== null;
|
|
}
|
|
|
|
export function hasConfiguredWebSearchCredential(params: {
|
|
config: OpenClawConfig;
|
|
env?: NodeJS.ProcessEnv;
|
|
searchConfig?: Record<string, unknown>;
|
|
origin?: PluginManifestRecord["origin"];
|
|
bundledAllowlistCompat?: boolean;
|
|
}): boolean {
|
|
const searchConfig =
|
|
params.searchConfig ??
|
|
(params.config.tools?.web?.search as Record<string, unknown> | undefined);
|
|
return resolvePluginWebSearchProviders({
|
|
config: params.config,
|
|
env: params.env,
|
|
bundledAllowlistCompat: params.bundledAllowlistCompat ?? false,
|
|
origin: params.origin,
|
|
}).some((provider) => {
|
|
const configuredCredential =
|
|
provider.getConfiguredCredentialValue?.(params.config) ??
|
|
provider.getCredentialValue(searchConfig);
|
|
if (hasConfiguredCredentialValue(configuredCredential)) {
|
|
return true;
|
|
}
|
|
return provider.envVars.some((envVar) => hasConfiguredCredentialValue(params.env?.[envVar]));
|
|
});
|
|
}
|