mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:50:43 +00:00
fix(tools): avoid web search provider loading at registration
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user