Compare commits

...

3 Commits

Author SHA1 Message Date
Kushagra Srivastava
b02f5aa37f Merge pull request #1015 from joaquinescalante23/fix/search-resilience-and-timeouts
feat: improve search resilience with timeouts and widget error handling
2026-03-10 19:05:09 +05:30
Joaquin
a2f2ac532e Improve resilience: catch widget execution failures 2026-03-04 10:02:51 -03:00
Joaquin
1763ee9d1f Add timeout and validation to SearXNG search 2026-03-04 10:02:51 -03:00
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 data = await res.json(); const timeoutId = setTimeout(() => controller.abort(), 10000);
const results: SearxngSearchResult[] = data.results; try {
const suggestions: string[] = data.suggestions; const res = await fetch(url, {
signal: controller.signal,
});
return { results, suggestions }; if (!res.ok) {
throw new Error(`SearXNG error: ${res.statusText}`);
}
const data = await res.json();
const results: SearxngSearchResult[] = data.results;
const suggestions: string[] = data.suggestions;
return { results, suggestions };
} catch (err: any) {
if (err.name === 'AbortError') {
throw new Error('SearXNG search timed out');
}
throw err;
} finally {
clearTimeout(timeoutId);
}
}; };