refactor: 内置搜索与 SearXNG 参数完全独立
内置模式: maxResults=30, fetchTop=5 固定默认值, 不读取 SearXNG 配置 SearXNG 模式: max_results/fetch_count 由配置面板控制 统一使用 useSearXNG 变量判断模式
This commit is contained in:
@@ -247,19 +247,25 @@ export class WebSearchTool implements IMetonaTool {
|
||||
async execute(args: Record<string, unknown>, _context: ToolExecutionContext): Promise<unknown> {
|
||||
const query = args.query as string;
|
||||
|
||||
// 读取 SearXNG 配置(提前读取,使工具参数默认值与配置一致)
|
||||
// 读取 SearXNG 配置
|
||||
const searxngConfig = this.readSearXNGConfig();
|
||||
const useSearXNG = searxngConfig.enabled && !!searxngConfig.url;
|
||||
|
||||
// max_results: 仅由配置面板控制,AI 不可覆盖
|
||||
const maxResults = Math.min(50, Math.max(1, searxngConfig.max_results > 0 ? searxngConfig.max_results : 30));
|
||||
// 两个模式参数完全独立:
|
||||
// - 内置模式:固定默认值 maxResults=30, fetchTop=5
|
||||
// - SearXNG 模式:由配置面板控制
|
||||
const maxResults = useSearXNG
|
||||
? Math.min(50, Math.max(1, searxngConfig.max_results > 0 ? searxngConfig.max_results : 30))
|
||||
: 30;
|
||||
|
||||
const timeRange = (args.time_range as string) ?? '';
|
||||
const enhanceSnippets = (args.enhance_snippets as boolean) ?? true;
|
||||
|
||||
// fetch_top: 仅由配置面板控制,AI 不可覆盖
|
||||
const fetchTop = Math.min(8, Math.max(3, searxngConfig.fetch_count > 0 ? searxngConfig.fetch_count : 5));
|
||||
const fetchTop = useSearXNG
|
||||
? Math.min(8, Math.max(3, searxngConfig.fetch_count > 0 ? searxngConfig.fetch_count : 5))
|
||||
: 5;
|
||||
|
||||
logTool('web_search', `Config: maxResults=${maxResults}, fetchTop=${fetchTop}, searxng=${searxngConfig.enabled}`);
|
||||
logTool('web_search', `Mode=${useSearXNG ? 'searxng' : 'builtin'}, maxResults=${maxResults}, fetchTop=${fetchTop}`);
|
||||
|
||||
// 缓存检查(key 含模式 + maxResults + fetchTop,避免配置变更后返回旧缓存)
|
||||
const cacheKey = `${searxngConfig.enabled ? 'searxng' : 'builtin'}:${maxResults}:${fetchTop}:${normalizeUrl(query).toLowerCase()}`;
|
||||
@@ -273,7 +279,7 @@ export class WebSearchTool implements IMetonaTool {
|
||||
let mode: string;
|
||||
let engineStats: Record<string, string>;
|
||||
|
||||
if (searxngConfig.enabled && searxngConfig.url) {
|
||||
if (useSearXNG) {
|
||||
const searxResult = await this.searchSearXNG(query, searxngConfig, maxResults, timeRange);
|
||||
results = searxResult.results;
|
||||
mode = 'searxng';
|
||||
|
||||
Reference in New Issue
Block a user