Files
goodbuddy/src/main/capabilities/web-search-tester.ts
T
mesalogo 56ebd40bd8 feat: unify execution and add workspace file imports
Remove Ask/Execute modes and general product tool approvals so requests use the selected runtime, enabled capabilities, and execution account permissions. Migrate retired application metadata while preserving user content.

Retire the Results page while retaining conversation images and stored artifacts. Add local and remote workspace file imports, timestamps and sorting, improve image discovery and saving, and refine workspace navigation and supervision responsiveness. Include the accompanying web-search changes, tests, probes, and product documentation.

Remote imports require an updated Agent. Existing artifacts are not automatically copied into project directories. Validation evidence and outstanding failures remain documented in feature progress files; no full test suite or real-model calls were rerun for this commit.

Release note: Run requests without switching work modes, import files into a selected local or remote workspace folder, sort workspace files by date, and keep using conversation images after removal of the Results page.
2026-10-04 20:02:59 +08:00

81 lines
2.1 KiB
TypeScript

import type { WebSearchTestResult } from '../../shared/capability-contracts'
import {
ModelToolProvider,
type ModelToolResultPart
} from '../agent/model-tool-provider'
const TEST_QUERY = 'GoodBuddy desktop assistant'
export async function testWebSearch(
signal?: AbortSignal
): Promise<WebSearchTestResult> {
const controller = new AbortController()
const timeout = setTimeout(
() => controller.abort(new Error('联网搜索测试超时')),
20_000
)
const abortFromCaller = (): void => controller.abort(signal?.reason)
signal?.addEventListener('abort', abortFromCaller, { once: true })
if (signal?.aborted) {
abortFromCaller()
}
const provider = new ModelToolProvider(
process.cwd(),
[],
undefined,
undefined,
true
)
const startedAt = Date.now()
try {
const context = {
conversationId: 'web-search-diagnostic'
}
const tools = await provider.listTools(context, controller.signal)
if (
!tools.some((tool) => tool.name === 'web_search') ||
!tools.some((tool) => tool.name === 'web_fetch')
) {
throw new Error('Exa MCP 未提供所需的联网工具')
}
const result = await provider.callTool(
'web_search',
{ query: TEST_QUERY, numResults: 1 },
controller.signal,
context
)
const preview = result.parts
.filter(
(
part
): part is Extract<ModelToolResultPart, { type: 'text' }> =>
part.type === 'text'
)
.map((part) => part.text)
.join('\n')
.replace(/\s+/gu, ' ')
.trim()
.slice(0, 500)
if (!preview) {
throw new Error('联网搜索测试未返回文本结果')
}
return {
provider: 'exa',
query: TEST_QUERY,
durationMs: Date.now() - startedAt,
preview
}
} catch (error) {
if (signal?.aborted) {
throw new Error('联网搜索测试已取消', { cause: error })
}
throw new Error('联网搜索测试失败,请检查网络连接或稍后重试', {
cause: error
})
} finally {
clearTimeout(timeout)
signal?.removeEventListener('abort', abortFromCaller)
await provider.dispose()
}
}