revert(tools): undo accidental merge of PR #18584

This commit is contained in:
Sebastian
2026-02-16 21:13:03 -05:00
parent 0158e41298
commit f924ab40d8
7 changed files with 8 additions and 107 deletions

View File

@@ -1,10 +1,9 @@
import { Type } from "@sinclair/typebox";
import { formatCliCommand } from "../../cli/command-format.js";
import type { OpenClawConfig } from "../../config/config.js";
import { matchesHostnameAllowlist, normalizeHostnameAllowlist } from "../../infra/net/ssrf.js";
import type { AnyAgentTool } from "./common.js";
import { formatCliCommand } from "../../cli/command-format.js";
import { wrapWebContent } from "../../security/external-content.js";
import { normalizeSecretInput } from "../../utils/normalize-secret-input.js";
import type { AnyAgentTool } from "./common.js";
import { jsonResult, readNumberParam, readStringParam } from "./common.js";
import {
CacheEntry,
@@ -13,7 +12,6 @@ import {
normalizeCacheKey,
readCache,
readResponseText,
resolveWebUrlAllowlist,
resolveCacheTtlMs,
resolveTimeoutSeconds,
withTimeout,
@@ -77,33 +75,6 @@ type WebSearchConfig = NonNullable<OpenClawConfig["tools"]>["web"] extends infer
: undefined
: undefined;
type WebConfig = NonNullable<OpenClawConfig["tools"]>["web"];
export function resolveUrlAllowlist(web?: WebConfig): string[] | undefined {
return resolveWebUrlAllowlist(web);
}
export function filterResultsByAllowlist(
results: Array<{ url?: string; siteName?: string }>,
allowlist: string[],
): Array<{ url?: string; siteName?: string }> {
if (allowlist.length === 0) {
return results;
}
const normalizedAllowlist = normalizeHostnameAllowlist(allowlist);
return results.filter((result) => {
if (!result.url) {
return true; // Keep entries without URL
}
try {
const hostname = new URL(result.url).hostname;
return matchesHostnameAllowlist(hostname, normalizedAllowlist);
} catch {
return true; // Keep entries with invalid URLs (let them pass through)
}
});
}
type BraveSearchResult = {
title?: string;
url?: string;
@@ -595,7 +566,6 @@ async function runWebSearch(params: {
perplexityModel?: string;
grokModel?: string;
grokInlineCitations?: boolean;
urlAllowlist?: string[];
}): Promise<Record<string, unknown>> {
const cacheKey = normalizeCacheKey(
params.provider === "brave"
@@ -718,15 +688,10 @@ async function runWebSearch(params: {
};
});
// Filter results by urlAllowlist if configured
const filteredResults = params.urlAllowlist
? filterResultsByAllowlist(mapped, params.urlAllowlist)
: mapped;
const payload = {
query: params.query,
provider: params.provider,
count: filteredResults.length,
count: mapped.length,
tookMs: Date.now() - start,
externalContent: {
untrusted: true,
@@ -734,7 +699,7 @@ async function runWebSearch(params: {
provider: params.provider,
wrapped: true,
},
results: filteredResults,
results: mapped,
};
writeCache(SEARCH_CACHE, cacheKey, payload, params.cacheTtlMs);
return payload;
@@ -752,7 +717,6 @@ export function createWebSearchTool(options?: {
const provider = resolveSearchProvider(search);
const perplexityConfig = resolvePerplexityConfig(search);
const grokConfig = resolveGrokConfig(search);
const urlAllowlist = resolveUrlAllowlist(options?.config?.tools?.web);
const description =
provider === "perplexity"
@@ -822,7 +786,6 @@ export function createWebSearchTool(options?: {
perplexityModel: resolvePerplexityModel(perplexityConfig),
grokModel: resolveGrokModel(grokConfig),
grokInlineCitations: resolveGrokInlineCitations(grokConfig),
urlAllowlist,
});
return jsonResult(result);
},
@@ -840,6 +803,4 @@ export const __testing = {
resolveGrokModel,
resolveGrokInlineCitations,
extractGrokContent,
resolveUrlAllowlist,
filterResultsByAllowlist,
} as const;