fix(tools): avoid web search provider loading at registration

This commit is contained in:
Ayaan Zaidi
2026-05-01 07:34:23 +05:30
parent 3144e7a729
commit 40b0b1bfe0
2 changed files with 25 additions and 15 deletions

View File

@@ -1,20 +1,36 @@
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { resolveManifestContractOwnerPluginId } from "../../plugins/plugin-registry.js";
import type { RuntimeWebSearchMetadata } from "../../secrets/runtime-web-tools.types.js";
import {
resolveWebSearchDefinition,
resolveWebSearchProviderId,
runWebSearch,
} from "../../web-search/runtime.js";
import { resolveWebSearchProviderId, runWebSearch } from "../../web-search/runtime.js";
import type { AnyAgentTool } from "./common.js";
import { asToolParamsRecord, jsonResult } from "./common.js";
import { SEARCH_CACHE } from "./web-search-provider-common.js";
const WebSearchSchema = {
type: "object",
properties: {
query: { type: "string", description: "Search query string." },
count: {
type: "number",
description: "Number of results to return.",
minimum: 1,
},
},
} satisfies Record<string, unknown>;
function isWebSearchDisabled(config?: OpenClawConfig): boolean {
const search = config?.tools?.web?.search;
return Boolean(search && typeof search === "object" && search.enabled === false);
}
export function createWebSearchTool(options?: {
config?: OpenClawConfig;
sandboxed?: boolean;
runtimeWebSearch?: RuntimeWebSearchMetadata;
}): AnyAgentTool | null {
if (isWebSearchDisabled(options?.config)) {
return null;
}
const runtimeProviderId =
options?.runtimeWebSearch?.selectedProvider ?? options?.runtimeWebSearch?.providerConfigured;
const preferRuntimeProviders =
@@ -25,19 +41,13 @@ export function createWebSearchTool(options?: {
origin: "bundled",
config: options?.config,
});
const resolved = resolveWebSearchDefinition({
...options,
preferRuntimeProviders,
});
if (!resolved) {
return null;
}
return {
label: "Web Search",
name: "web_search",
description: resolved.definition.description,
parameters: resolved.definition.parameters,
description:
"Search the web. Returns provider-normalized results for current information lookup.",
parameters: WebSearchSchema,
execute: async (_toolCallId, args) => {
const result = await runWebSearch({
config: options?.config,

View File

@@ -111,7 +111,7 @@ describe("web tools defaults", () => {
const result = await tool?.execute?.("call-runtime-provider", {});
expect(tool?.description).toBe("custom runtime tool");
expect(tool?.description).toContain("Search the web");
expect(result?.details).toMatchObject({ ok: true });
});
});