From 8718f5ac6f07a3e47366a16d5865ccd8308a1849 Mon Sep 17 00:00:00 2001 From: thzxx Date: Tue, 7 Jul 2026 21:45:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20SearXNG=20max=5Fresults=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=A2=AB=20AI=20=E5=8F=82=E6=95=B0=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: ?? 空值回退链让 AI 传入的 max_results:10 直接生效, 配置面板的 30 被跳过 修复: 改用 Math.max() 让配置面板作为下限, AI 参数不得低于配置值 同时修复 fetch_top 的相同问题 --- electron/harness/tools/built-in/web-search.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/electron/harness/tools/built-in/web-search.ts b/electron/harness/tools/built-in/web-search.ts index 6c17ed7..14f40b3 100644 --- a/electron/harness/tools/built-in/web-search.ts +++ b/electron/harness/tools/built-in/web-search.ts @@ -252,18 +252,18 @@ export class WebSearchTool implements IMetonaTool { // 读取 SearXNG 配置(提前读取,使工具参数默认值与配置一致) const searxngConfig = this.readSearXNGConfig(); - // max_results: 工具参数 > 配置面板 > 默认 30。取较大值保证配置面板的下限约束 + // max_results: 配置面板为下限,AI 参数不得低于配置值,上限 30 const argMaxResults = (args.max_results as number) ?? undefined; const cfgMaxResults = searxngConfig.max_results > 0 ? searxngConfig.max_results : undefined; - const maxResults = Math.min(30, Math.max(1, argMaxResults ?? cfgMaxResults ?? 30)); + const maxResults = Math.min(30, Math.max(1, argMaxResults ?? 30, cfgMaxResults ?? 0)); const timeRange = (args.time_range as string) ?? ''; const enhanceSnippets = (args.enhance_snippets as boolean) ?? true; - // fetch_top: 工具参数 > 配置面板 > 默认 5。取较大值保证配置面板的下限约束 + // fetch_top: 配置面板为下限,AI 参数不得低于配置值,上限 8 const argFetchTop = (args.fetch_top as number) ?? undefined; const cfgFetchCount = searxngConfig.fetch_count > 0 ? searxngConfig.fetch_count : undefined; - const fetchTop = Math.min(8, Math.max(3, argFetchTop ?? cfgFetchCount ?? 5)); + const fetchTop = Math.min(8, Math.max(3, argFetchTop ?? 5, cfgFetchCount ?? 0)); // 缓存检查(缓存 key 含 SearXNG 模式,避免切换后返回旧缓存) const cacheKey = `${searxngConfig.enabled ? 'searxng' : 'builtin'}:${normalizeUrl(query).toLowerCase()}`;