Elffuss BraidHub

kikocis/continue public

main · 1.3 KiBRawPermalink
1import { ToolImpl } from ".";
2import { fetchSearchResults } from "../../context/providers/WebContextProvider";
3import { getStringArg } from "../parseArgs";
4
5const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
6
7export const searchWebImpl: ToolImpl = async (args, extras) => {
8 const query = getStringArg(args, "query");
9
10 const webResults = await fetchSearchResults(query, 5, extras.fetch);
11
12 // Track truncated results
13 const truncatedResults: string[] = [];
14
15 // Check and truncate each result
16 const processedResults = webResults.map((result, index) => {
17 if (result.content.length > DEFAULT_WEB_SEARCH_CHAR_LIMIT) {
18 truncatedResults.push(
19 result.name || result.description || `Result #${index + 1}`,
20 );
21 return {
22 ...result,
23 content: result.content.substring(0, DEFAULT_WEB_SEARCH_CHAR_LIMIT),
24 };
25 }
26 return result;
27 });
28
29 // Add truncation warning if needed
30 if (truncatedResults.length > 0) {
31 processedResults.push({
32 name: "Truncation warning",
33 description: "",
34 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.`,
35 });
36 }
37
38 return processedResults;
39};