feat: 日志面板显示搜索模式(SearXNG/内置),结果带_mode标记
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ function summarizeResult(toolName: string, result: Record<string, unknown>): str
|
|||||||
case 'move_file': return `${result.source} → ${result.destination}`;
|
case 'move_file': return `${result.source} → ${result.destination}`;
|
||||||
case 'copy_file': return `${result.source} → ${result.destination}`;
|
case 'copy_file': return `${result.source} → ${result.destination}`;
|
||||||
case 'web_fetch': return `${result.status} | ${result.length} chars`;
|
case 'web_fetch': return `${result.status} | ${result.length} chars`;
|
||||||
case 'web_search': return `"${result.query}" → ${result.total} 条结果`;
|
case 'web_search': return `[${(result as any)._mode === 'searxng' ? 'SearXNG' : '内置'}] "${result.query}" → ${result.total} 条结果`;
|
||||||
case 'edit_file': return `${result.path} (${result.replaceCount} 处替换)`;
|
case 'edit_file': return `${result.path} (${result.replaceCount} 处替换)`;
|
||||||
case 'get_file_info': return `${result.name} (${result.type}, ${result.size}B)`;
|
case 'get_file_info': return `${result.name} (${result.type}, ${result.size}B)`;
|
||||||
case 'tree': return `${result.path} (${result.fileCount} 文件 / ${result.dirCount} 目录)`;
|
case 'tree': return `${result.path} (${result.fileCount} 文件 / ${result.dirCount} 目录)`;
|
||||||
|
|||||||
@@ -494,6 +494,7 @@ async function handleWebSearchSearxng(
|
|||||||
sendLog('success', `🔍 SearXNG HTML 完成`, `${text.length} 字符`);
|
sendLog('success', `🔍 SearXNG HTML 完成`, `${text.length} 字符`);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
_mode: 'searxng',
|
||||||
url: apiUrl,
|
url: apiUrl,
|
||||||
content,
|
content,
|
||||||
content_type: 'text/html',
|
content_type: 'text/html',
|
||||||
@@ -545,7 +546,7 @@ async function handleWebSearchSearxng(
|
|||||||
|
|
||||||
sendLog('success', `🔍 SearXNG 完成`, `${results.length} 条结果, 引擎: ${engineNames.join(', ')}`);
|
sendLog('success', `🔍 SearXNG 完成`, `${results.length} 条结果, 引擎: ${engineNames.join(', ')}`);
|
||||||
|
|
||||||
return buildSearchResponse(
|
const result = buildSearchResponse(
|
||||||
results.map(r => ({
|
results.map(r => ({
|
||||||
title: r.title,
|
title: r.title,
|
||||||
url: r.url,
|
url: r.url,
|
||||||
@@ -558,6 +559,8 @@ async function handleWebSearchSearxng(
|
|||||||
false,
|
false,
|
||||||
engineStats
|
engineStats
|
||||||
);
|
);
|
||||||
|
result._mode = 'searxng';
|
||||||
|
return result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
sendLog('error', `🔍 SearXNG 异常`, (err as Error).message);
|
sendLog('error', `🔍 SearXNG 异常`, (err as Error).message);
|
||||||
return { success: false, error: `SearXNG 搜索异常: ${(err as Error).message}` };
|
return { success: false, error: `SearXNG 搜索异常: ${(err as Error).message}` };
|
||||||
@@ -583,9 +586,11 @@ export async function handleWebSearch(params: { query: string; max_results?: num
|
|||||||
// ── SearXNG 模式:如果启用了 SearXNG,走 JSON API ──
|
// ── SearXNG 模式:如果启用了 SearXNG,走 JSON API ──
|
||||||
const searxngEnabled = getSetting<boolean>('searxng_enabled', false);
|
const searxngEnabled = getSetting<boolean>('searxng_enabled', false);
|
||||||
if (searxngEnabled) {
|
if (searxngEnabled) {
|
||||||
|
sendLog('info', `🔍 web_search → SearXNG 模式`, `\"${query}\"`);
|
||||||
return handleWebSearchSearxng(query, maxResults, timeRange, enhanceSnippets);
|
return handleWebSearchSearxng(query, maxResults, timeRange, enhanceSnippets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendLog('info', `🔍 web_search → 内置引擎`, `\"${query}\"`);
|
||||||
const cacheKey = `${query}|${maxResults}|${timeRange}`;
|
const cacheKey = `${query}|${maxResults}|${timeRange}`;
|
||||||
|
|
||||||
// ── 时间范围 → URL 参数映射 ──
|
// ── 时间范围 → URL 参数映射 ──
|
||||||
@@ -601,7 +606,9 @@ export async function handleWebSearch(params: { query: string; max_results?: num
|
|||||||
const cached = cacheGet(cacheKey);
|
const cached = cacheGet(cacheKey);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
sendLog('success', `🔍 web_search 缓存命中`, `"${query}" → ${cached.results.length} 条`);
|
sendLog('success', `🔍 web_search 缓存命中`, `"${query}" → ${cached.results.length} 条`);
|
||||||
return buildSearchResponse(cached.results, maxResults, true);
|
const cachedResult = buildSearchResponse(cached.results, maxResults, true);
|
||||||
|
cachedResult._mode = 'builtin';
|
||||||
|
return cachedResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendLog('info', `🔍 web_search`, `"${query}" (${maxResults} 条) [并行]`);
|
sendLog('info', `🔍 web_search`, `"${query}" (${maxResults} 条) [并行]`);
|
||||||
@@ -747,7 +754,9 @@ export async function handleWebSearch(params: { query: string; max_results?: num
|
|||||||
// ── 6. 缓存结果 ──
|
// ── 6. 缓存结果 ──
|
||||||
cacheSet(cacheKey, { results: finalResults, time: Date.now() });
|
cacheSet(cacheKey, { results: finalResults, time: Date.now() });
|
||||||
|
|
||||||
return buildSearchResponse(finalResults, maxResults, false, engineStats);
|
const finalResult = buildSearchResponse(finalResults, maxResults, false, engineStats);
|
||||||
|
finalResult._mode = 'builtin';
|
||||||
|
return finalResult;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { success: false, error: (err as Error).message };
|
return { success: false, error: (err as Error).message };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user