mirror of https://github.com/openclaw/openclaw.git
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
|
|
|
export const DEFAULT_DDG_SAFE_SEARCH = "moderate";
|
|
|
|
export type DdgSafeSearch = "strict" | "moderate" | "off";
|
|
|
|
type DdgPluginConfig = {
|
|
webSearch?: {
|
|
region?: string;
|
|
safeSearch?: string;
|
|
};
|
|
};
|
|
|
|
export function resolveDdgWebSearchConfig(
|
|
config?: OpenClawConfig,
|
|
): DdgPluginConfig["webSearch"] | undefined {
|
|
const pluginConfig = config?.plugins?.entries?.duckduckgo?.config as DdgPluginConfig | undefined;
|
|
const webSearch = pluginConfig?.webSearch;
|
|
if (webSearch && typeof webSearch === "object" && !Array.isArray(webSearch)) {
|
|
return webSearch;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function resolveDdgRegion(config?: OpenClawConfig): string | undefined {
|
|
const region = resolveDdgWebSearchConfig(config)?.region;
|
|
if (typeof region !== "string") {
|
|
return undefined;
|
|
}
|
|
const trimmed = region.trim();
|
|
return trimmed || undefined;
|
|
}
|
|
|
|
export function resolveDdgSafeSearch(config?: OpenClawConfig): DdgSafeSearch {
|
|
const safeSearch = resolveDdgWebSearchConfig(config)?.safeSearch;
|
|
const normalized = typeof safeSearch === "string" ? safeSearch.trim().toLowerCase() : "";
|
|
if (normalized === "strict" || normalized === "off") {
|
|
return normalized;
|
|
}
|
|
return DEFAULT_DDG_SAFE_SEARCH;
|
|
}
|