pi-unsloth-webtools 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web-search.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { checkUrlAccess, scopeSearchQuery, type WebsitePolicy } from "./web-access.ts";
2
+ import { loadDefaultMaxResults } from "./settings.ts";
2
3
  import { collapseWhitespace } from "./html-to-md.ts";
3
4
  import {
4
5
  autoTextSearch,
@@ -41,13 +42,16 @@ export interface WebSearchOptions {
41
42
  signal?: AbortSignal;
42
43
  websitePolicy?: WebsitePolicy | null;
43
44
  client?: SearchClient;
45
+ cwd?: string;
44
46
  }
45
47
 
48
+ export { loadDefaultMaxResults };
49
+
46
50
  export async function webSearch(
47
51
  query: string | undefined,
48
52
  options: WebSearchOptions = {},
49
53
  ): Promise<string> {
50
- const maxResults = options.maxResults ?? MAX_RESULTS;
54
+ const maxResults = options.maxResults ?? (await loadDefaultMaxResults(options.cwd));
51
55
  const timeoutMs = options.timeoutMs ?? SEARCH_TIMEOUT_MS;
52
56
  const signal = options.signal;
53
57
  const policy = options.websitePolicy ?? null;
@@ -83,6 +87,8 @@ export async function webSearch(
83
87
  export function searchFailureMessage(exc: unknown, timeoutMs = SEARCH_TIMEOUT_MS): string {
84
88
  if (exc instanceof SearchCancelled) return "Search cancelled.";
85
89
  if (exc instanceof SearchTimeoutError) {
90
+ const providers = [...((exc as SearchTimeoutError).providers ?? [])].sort();
91
+ if (providers.length) return `Search failed: the search engines (${providers.join(", ")}) did not respond within ${Math.round(timeoutMs / 1000)} seconds.`;
86
92
  return `Search failed: the search engines did not respond within ${Math.round(timeoutMs / 1000)} seconds.`;
87
93
  }
88
94
  if (exc instanceof EmptySweepError || (exc instanceof Error && exc.message.includes("No results found"))) {