* fix: WebSearch providers + MCPTool bugs WebSearchTool: - custom.ts: fix buildAuthHeadersForPreset WEB_AUTH_HEADER opt-out - custom.ts: fix WEB_AUTH_SCHEME empty string handling - custom.ts: fix walkJsonPath null safety for jsonPath parsing - duckduckgo.ts: use SafeSearchType enum instead of raw 0 - mojeek.ts: always send Accept: application/json header - README: fix timeout documentation (15s -> 120s to match code) - custom.test.ts: add tests for auth header behavior MCPTool: - MCPTool.ts: fix outputSchema to accept ContentBlockParam[] (not just string) - MCPTool.ts: fix isResultTruncated for array output (iterates text blocks) * fix: address PR #593 review feedback 1. Export buildAuthHeadersForPreset and add direct tests for: - WEB_AUTH_HEADER="" explicit opt-out behavior - WEB_AUTH_SCHEME="" stripping scheme prefix - Preset defaults (authHeader + authScheme) - No WEB_KEY returns empty headers 2. Add duckduckgo.test.ts verifying SafeSearchType.STRICT === 0, confirming the enum change is semantically identical to the previous raw value. Addresses review by @Vasanthdev2004 at pullrequestreview-4093533095 --------- Co-authored-by: FluxLuFFy <flux@openclaude.dev> Co-authored-by: Fix Bot <fix@openclaude.local>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import type { SearchInput, SearchProvider } from './types.js'
|
|
import { applyDomainFilters, type ProviderOutput } from './types.js'
|
|
|
|
export const duckduckgoProvider: SearchProvider = {
|
|
name: 'duckduckgo',
|
|
|
|
isConfigured() {
|
|
// DDG is the default fallback — always available (duck-duck-scrape is a runtime dep)
|
|
return true
|
|
},
|
|
|
|
async search(input: SearchInput, signal?: AbortSignal): Promise<ProviderOutput> {
|
|
const start = performance.now()
|
|
let search: typeof import('duck-duck-scrape').search
|
|
let SafeSearchType: typeof import('duck-duck-scrape').SafeSearchType
|
|
try {
|
|
;({ search, SafeSearchType } = await import('duck-duck-scrape'))
|
|
} catch {
|
|
throw new Error('duck-duck-scrape package not installed. Run: npm install duck-duck-scrape')
|
|
}
|
|
if (signal?.aborted) throw new DOMException('Aborted', 'AbortError')
|
|
// TODO: duck-duck-scrape doesn't accept AbortSignal — can't cancel in-flight searches
|
|
const response = await search(input.query, { safeSearch: SafeSearchType.STRICT })
|
|
|
|
const hits = applyDomainFilters(
|
|
response.results.map(r => ({
|
|
title: r.title || r.url,
|
|
url: r.url,
|
|
description: r.description ?? undefined,
|
|
})),
|
|
input,
|
|
)
|
|
|
|
return {
|
|
hits,
|
|
providerName: 'duckduckgo',
|
|
durationSeconds: (performance.now() - start) / 1000,
|
|
}
|
|
},
|
|
}
|