Merge pull request #1015 from joaquinescalante23/fix/search-resilience-and-timeouts

feat: improve search resilience with timeouts and widget error handling
This commit is contained in:
Kushagra Srivastava
2026-03-10 19:05:09 +05:30
committed by GitHub
2 changed files with 27 additions and 5 deletions

View File

@@ -19,6 +19,9 @@ class APISearchAgent {
chatHistory: input.chatHistory, chatHistory: input.chatHistory,
followUp: input.followUp, followUp: input.followUp,
llm: input.config.llm, llm: input.config.llm,
}).catch((err) => {
console.error(`Error executing widgets: ${err}`);
return [];
}); });
let searchPromise: Promise<ResearcherOutput> | null = null; let searchPromise: Promise<ResearcherOutput> | null = null;

View File

@@ -38,11 +38,30 @@ export const searchSearxng = async (
}); });
} }
const res = await fetch(url); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000);
try {
const res = await fetch(url, {
signal: controller.signal,
});
if (!res.ok) {
throw new Error(`SearXNG error: ${res.statusText}`);
}
const data = await res.json(); const data = await res.json();
const results: SearxngSearchResult[] = data.results; const results: SearxngSearchResult[] = data.results;
const suggestions: string[] = data.suggestions; const suggestions: string[] = data.suggestions;
return { results, suggestions }; return { results, suggestions };
} catch (err: any) {
if (err.name === 'AbortError') {
throw new Error('SearXNG search timed out');
}
throw err;
} finally {
clearTimeout(timeoutId);
}
}; };