pi-web-lite 0.1.3 → 0.1.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-lite",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Lightweight web_search and fetch tools for Pi with Exa, Tavily, Brave, Doubao, auto priority, and balanced provider-key pools.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/config.ts CHANGED
@@ -133,7 +133,8 @@ export function parseConfig(raw: unknown, sourcePath = CONFIG_PATH): WebLiteConf
133
133
  doubao: normalizeKeys(apiKeysRaw.doubao, "doubao"),
134
134
  },
135
135
  search: {
136
- numResults: Math.min(normalizeNumber(searchRaw.numResults, DEFAULT_SEARCH.numResults, "search.numResults"), 20),
136
+ // Respect user-configured value; provider APIs enforce their own caps.
137
+ numResults: normalizeNumber(searchRaw.numResults, DEFAULT_SEARCH.numResults, "search.numResults"),
137
138
  timeoutMs: normalizeNumber(searchRaw.timeoutMs, DEFAULT_SEARCH.timeoutMs, "search.timeoutMs"),
138
139
  },
139
140
  fetch: {
@@ -25,9 +25,11 @@ function normalizeSnippet(value: unknown): string | null {
25
25
  }
26
26
 
27
27
  export async function searchBrave(query: string, apiKey: string, options: SearchOptions): Promise<SearchResponse> {
28
+ const numResults = Math.min(options.numResults, 50);
28
29
  const url = new URL(BRAVE_LLM_CONTEXT_URL);
29
30
  url.searchParams.set("q", query);
30
- url.searchParams.set("count", String(options.numResults));
31
+ url.searchParams.set("count", String(numResults));
32
+ url.searchParams.set("maximum_number_of_urls", String(numResults));
31
33
 
32
34
  const response = await fetch(url, {
33
35
  headers: {
@@ -61,7 +63,7 @@ export async function searchBrave(query: string, apiKey: string, options: Search
61
63
  snippet: snippets.join("\n\n"),
62
64
  });
63
65
  seen.add(item.url);
64
- if (results.length >= options.numResults) break;
66
+ if (results.length >= numResults) break;
65
67
  }
66
68
 
67
69
  return { answer: "", results };
@@ -42,6 +42,7 @@ function responseError(data: DoubaoResponse): string | null {
42
42
  }
43
43
 
44
44
  export async function searchDoubao(query: string, apiKey: string, options: SearchOptions): Promise<SearchResponse> {
45
+ const numResults = Math.min(options.numResults, 50);
45
46
  const response = await fetch(DOUBAO_SEARCH_URL, {
46
47
  method: "POST",
47
48
  headers: {
@@ -52,7 +53,7 @@ export async function searchDoubao(query: string, apiKey: string, options: Searc
52
53
  body: JSON.stringify({
53
54
  Query: query,
54
55
  SearchType: "web",
55
- Count: options.numResults,
56
+ Count: numResults,
56
57
  Filter: {
57
58
  NeedContent: false,
58
59
  NeedUrl: true,
@@ -88,7 +89,7 @@ export async function searchDoubao(query: string, apiKey: string, options: Searc
88
89
  snippet: cleanText(item.Summary || item.Snippet || item.Content, 1200),
89
90
  });
90
91
  seen.add(item.Url);
91
- if (results.length >= options.numResults) break;
92
+ if (results.length >= numResults) break;
92
93
  }
93
94
 
94
95
  return { answer: "", results };
@@ -50,6 +50,7 @@ function mapResults(results: ExaSearchResponse["results"], numResults: number):
50
50
  }
51
51
 
52
52
  export async function searchExa(query: string, apiKey: string, options: SearchOptions): Promise<SearchResponse> {
53
+ const numResults = Math.min(options.numResults, 100);
53
54
  const response = await fetch(EXA_SEARCH_URL, {
54
55
  method: "POST",
55
56
  headers: {
@@ -59,7 +60,7 @@ export async function searchExa(query: string, apiKey: string, options: SearchOp
59
60
  body: JSON.stringify({
60
61
  query,
61
62
  type: "auto",
62
- numResults: options.numResults,
63
+ numResults,
63
64
  contents: {
64
65
  text: { maxCharacters: 1000 },
65
66
  highlights: true,
@@ -76,6 +77,6 @@ export async function searchExa(query: string, apiKey: string, options: SearchOp
76
77
  const data = await response.json() as ExaSearchResponse;
77
78
  return {
78
79
  answer: buildAnswer(data.results),
79
- results: mapResults(data.results, options.numResults),
80
+ results: mapResults(data.results, numResults),
80
81
  };
81
82
  }
@@ -13,13 +13,14 @@ interface TavilyResponse {
13
13
  }
14
14
 
15
15
  export async function searchTavily(query: string, apiKey: string, options: SearchOptions): Promise<SearchResponse> {
16
+ const numResults = Math.min(options.numResults, 20);
16
17
  const response = await fetch(TAVILY_API_URL, {
17
18
  method: "POST",
18
19
  headers: { "Content-Type": "application/json" },
19
20
  body: JSON.stringify({
20
21
  api_key: apiKey,
21
22
  query,
22
- max_results: options.numResults,
23
+ max_results: numResults,
23
24
  search_depth: "basic",
24
25
  include_answer: true,
25
26
  }),
@@ -40,7 +41,7 @@ export async function searchTavily(query: string, apiKey: string, options: Searc
40
41
  url: item.url,
41
42
  snippet: cleanText(item.content),
42
43
  });
43
- if (results.length >= options.numResults) break;
44
+ if (results.length >= numResults) break;
44
45
  }
45
46
 
46
47
  return {