v1.11.8: address review — inject fetcher, byte-count limit, redirect TODO

This commit is contained in:
2026-05-20 21:40:11 +00:00
parent 2fdbb05477
commit 4e67a265ac
3 changed files with 58 additions and 3 deletions

View File

@@ -35,16 +35,19 @@ export interface WebSearchOutput {
// with a mocked fetch. Throws on network / non-200 — the executeToolCall
// wrapper in inference.ts turns the thrown message into the LLM-visible
// error string.
// v1.11.8 review: fetcher injection. Mirrors executeWebFetch's signature
// so tests can pass a vi.fn() stub without monkey-patching globalThis.
export async function executeWebSearch(
input: WebSearchInputT,
searxngUrl: string,
fetcher: typeof fetch = fetch,
): Promise<WebSearchOutput> {
const cap = Math.min(Math.max(1, input.max_results ?? DEFAULT_RESULTS), MAX_RESULTS_CAP);
const url = `${searxngUrl}/search?q=${encodeURIComponent(input.query)}&format=json`;
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
try {
const res = await fetch(url, {
const res = await fetcher(url, {
signal: controller.signal,
headers: { 'User-Agent': 'BooCode/1.11.8' },
});