Elffuss BraidHub

kikocis/continue public

6e4b7e9fc0a8 · 1.3 KiBRawPermalink
1import { ToolImpl } from ".";
2import { fetchSearchResults } from "../../context/providers/WebContextProvider";
3
4const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
5
6export const searchWebImpl: ToolImpl = async (args, extras) => {
7 const webResults = await fetchSearchResults(args.query, 5, extras.fetch);
8
9 // Track truncated results
10 const truncatedResults: string[] = [];
11
12 // Check and truncate each result
13 const processedResults = webResults.map((result, index) => {
14 if (result.content.length > DEFAULT_WEB_SEARCH_CHAR_LIMIT) {
15 truncatedResults.push(
16 result.name || result.description || `Result #${index + 1}`,
17 );
18 return {
19 ...result,
20 content: result.content.substring(0, DEFAULT_WEB_SEARCH_CHAR_LIMIT),
21 };
22 }
23 return result;
24 });
25
26 // Add truncation warning if needed
27 if (truncatedResults.length > 0) {
28 processedResults.push({
29 name: "Web search truncation warning",
30 description: "Informs that search results were truncated",
31 content: `The content from the following search results was truncated because it exceeded the ${DEFAULT_WEB_SEARCH_CHAR_LIMIT} character limit: ${truncatedResults.join(", ")}. For more detailed information, consider refining your search query.`,
32 });
33 }
34
35 return processedResults;
36};