openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
96 lines (95 loc) • 3.62 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as createLazyRuntimeModule } from "./lazy-runtime-zGjszCtt.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { n as WEB_SEARCH_QUERY_COUNT_PROPERTIES, t as createBaseWebSearchProviderContractFields } from "./provider-web-search-contract-fields-2WwRfXtg.mjs";
import { r as mergeScopedSearchConfig, s as resolvePluginWebSearchConfig } from "./web-search-provider-config-CYzD1DF7.mjs";
//#region extensions/google/src/gemini-web-search-provider.ts
const GEMINI_CREDENTIAL_PATH = "plugins.entries.google.config.webSearch.apiKey";
const GOOGLE_PROVIDER_CREDENTIAL_PATH = "models.providers.google.apiKey";
const loadGeminiWebSearchRuntime = createLazyRuntimeModule(() => import("./gemini-web-search-provider.runtime.js"));
const GEMINI_TOOL_PARAMETERS = {
type: "object",
properties: {
...WEB_SEARCH_QUERY_COUNT_PROPERTIES,
country: {
type: "string",
description: "Not supported by Gemini."
},
language: {
type: "string",
description: "Not supported by Gemini."
},
freshness: {
type: "string",
description: "Filter Gemini search freshness: week, month, and year use hard Google Search time ranges; day prioritizes the last 24 hours as a recency hint."
},
date_after: {
type: "string",
description: "Only ground with results published after this date (YYYY-MM-DD)."
},
date_before: {
type: "string",
description: "Only ground with results published before this date (YYYY-MM-DD)."
}
},
required: ["query"]
};
function createGeminiWebSearchProvider() {
const e = createBaseWebSearchProviderContractFields({
credentialPath: GEMINI_CREDENTIAL_PATH,
searchCredential: {
type: "scoped",
scopeId: "gemini"
},
configuredCredential: { pluginId: "google" }
});
return {
id: "gemini",
label: "Gemini (Google Search)",
hint: "Requires Google Gemini API key · Google Search grounding",
onboardingScopes: ["text-inference"],
credentialLabel: "Google Gemini API key",
envVars: ["GEMINI_API_KEY"],
placeholder: "AIza...",
signupUrl: "https://aistudio.google.com/apikey",
docsUrl: "https://docs.openclaw.ai/tools/web",
autoDetectOrder: 20,
credentialPath: GEMINI_CREDENTIAL_PATH,
...e,
getConfiguredCredentialFallback: (e) => {
const t = e?.models?.providers?.google;
return t && t.apiKey !== void 0 ? {
path: GOOGLE_PROVIDER_CREDENTIAL_PATH,
value: t.apiKey
} : void 0;
},
createTool: (e) => {
let t = mergeScopedSearchConfig(e.searchConfig, "gemini", resolvePluginWebSearchConfig(e.config, "google"));
const n = e.config?.models?.providers?.google;
if (n && (n.apiKey !== void 0 || n.baseUrl !== void 0)) {
const e = isRecord(t?.gemini) ? { ...t.gemini } : {};
const r = t ? Object.defineProperties({}, Object.getOwnPropertyDescriptors(t)) : {};
const i = t ? Object.getOwnPropertyDescriptor(t, "gemini") : void 0;
if (n.apiKey !== void 0) e.providerApiKey = n.apiKey;
if (n.baseUrl !== void 0) e.providerBaseUrl = n.baseUrl;
Object.defineProperty(r, "gemini", {
value: e,
enumerable: i?.enumerable ?? false,
configurable: true,
writable: true
});
t = r;
}
return {
description: "Search the web using Gemini with Google Search grounding. Returns AI-synthesized answers with citations from Google Search.",
parameters: GEMINI_TOOL_PARAMETERS,
execute: async (e, n) => {
const { executeGeminiSearch: r } = await loadGeminiWebSearchRuntime();
return await r(e, t, n);
}
};
}
};
}
//#endregion
export { createGeminiWebSearchProvider as t };