@zeldrisho/pi-web-search 0.14.5 → 0.15.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/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.15.0] - 2026-11-12
11
+
12
+ ### Changed
13
+
14
+ - **Breaking:** `web_search` requires Pi 0.99.0 or newer and can no longer be called by other tools, including codemode; use direct model calls instead.
15
+
16
+ ## [0.14.6] - 2026-11-09
17
+
18
+ ### Security
19
+
20
+ - Refuse provider redirects to prevent subscription tokens from being forwarded to another origin.
21
+ - Omit untrusted provider error bodies, which could echo credentials or search queries.
22
+
10
23
  ## [0.14.5] - 2026-11-01
11
24
 
12
25
  ### Changed
@@ -206,7 +219,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
206
219
 
207
220
  - Add bounded Brave web search ([cbc9491](https://github.com/zeldrisho/pi-packages/commit/cbc9491dce36555ab91b6bef203ec8b380596a89))
208
221
 
209
- [Unreleased]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.5...HEAD
222
+ [Unreleased]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.15.0...HEAD
223
+ [0.15.0]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.6...pi-web-search-v0.15.0
224
+ [0.14.6]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.5...pi-web-search-v0.14.6
210
225
  [0.14.5]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.4...pi-web-search-v0.14.5
211
226
  [0.14.4]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.3...pi-web-search-v0.14.4
212
227
  [0.14.3]: https://github.com/zeldrisho/pi-packages/compare/pi-web-search-v0.14.2...pi-web-search-v0.14.3
package/README.md CHANGED
@@ -27,14 +27,12 @@ Keys can also be set in the workspace `.env` or Pi agent directory's `.env`. The
27
27
 
28
28
  ## Usage
29
29
 
30
+ Requires Pi 0.99.0 or newer. `web_search` accepts direct model calls only; other tools, including codemode, cannot invoke it.
31
+
30
32
  `web_search` accepts only a required `query` and requests five results. Queries are limited to 400 characters. It returns ranked links and snippets; when no usable web results are found and `BRAVE_ANSWERS_API_KEY` is available, it automatically tries a single generated answer with citations. Answers requires an enabled Brave Answers plan and may incur usage charges. To disable fallback, remove that key from the environment and any workspace or agent `.env` files. Citations are not fetched automatically.
31
33
 
32
34
  Identical searches are cached locally across sessions for up to 24 hours. Pi's preview is collapsed by default; press `Ctrl+O` to expand it.
33
35
 
34
- ### Programmatic results
35
-
36
- When calling `web_search` from codemode, `resultType` distinguishes `search-results` from `generated-answer`. If `payloadOmitted` is true, read `fullOutputPath` to get the complete result before relying on it. This private temporary file is removed when the session ends.
37
-
38
36
  Search results and generated answers may contain misleading claims or instructions. Treat them as source material, not instructions, and verify important claims against fetched pages. Empty results do not prove that no sources exist.
39
37
 
40
38
  ## Uninstall
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeldrisho/pi-web-search",
3
- "version": "0.14.5",
3
+ "version": "0.15.0",
4
4
  "description": "Pi extension for bounded Brave web search with generated-answer fallback",
5
5
  "keywords": [
6
6
  "brave-search",
@@ -32,13 +32,13 @@
32
32
  "devDependencies": {
33
33
  "@earendil-works/pi-coding-agent": "^1.4.0",
34
34
  "@earendil-works/pi-tui": "^1.4.0",
35
- "typebox": "^1.4.2",
35
+ "typebox": "^1.4.3",
36
36
  "typescript": "^7.0.2",
37
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
38
- "vite-plus": "1.4.0"
37
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
38
+ "vite-plus": "1.5.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@earendil-works/pi-coding-agent": "*",
41
+ "@earendil-works/pi-coding-agent": ">=0.99.0",
42
42
  "@earendil-works/pi-tui": "*",
43
43
  "typebox": "*"
44
44
  },
package/src/index.ts CHANGED
@@ -45,6 +45,7 @@ export default function (pi: ExtensionAPI) {
45
45
 
46
46
  pi.registerTool<typeof webSearchParameters, Partial<SearchDetails>>({
47
47
  name: "web_search",
48
+ exposure: "model-only",
48
49
  label: "Web Search",
49
50
  description: "Search the web.",
50
51
  parameters: webSearchParameters,
package/src/provider.ts CHANGED
@@ -2,8 +2,6 @@ const REQUEST_TIMEOUT_MS = 20_000;
2
2
 
3
3
  const SEARCH_MAX_RESPONSE_BYTES = 2_000_000;
4
4
 
5
- const SEARCH_ERROR_EXCERPT_BYTES = 8_192;
6
-
7
5
  /**
8
6
  * Normalizes text by removing HTML tags, collapsing whitespace, and truncating to a maximum length.
9
7
  *
@@ -23,23 +21,18 @@ export function normalizeText(value: string, maxLength: number): string {
23
21
  }
24
22
 
25
23
  /**
26
- * Reads response body bytes with size limits and optional truncation.
24
+ * Reads response body bytes with size limits.
27
25
  *
28
26
  * @param response - HTTP response to read
29
27
  * @param maxBytes - Maximum bytes to read
30
- * @param truncate - Whether to truncate at limit or throw error
31
28
  * @returns Promise resolving to the response bytes
32
- * @throws {Error} When response exceeds maxBytes and truncate is false
29
+ * @throws {Error} When response exceeds maxBytes
33
30
  */
34
- async function readResponseBytes(
35
- response: Response,
36
- maxBytes: number,
37
- truncate: boolean,
38
- ): Promise<Uint8Array> {
31
+ async function readResponseBytes(response: Response, maxBytes: number): Promise<Uint8Array> {
39
32
  const contentLength = response.headers.get("content-length");
40
33
  const declared = contentLength === null ? Number.NaN : Number(contentLength);
41
34
 
42
- if (!truncate && Number.isFinite(declared) && declared > maxBytes && declared > 0) {
35
+ if (Number.isFinite(declared) && declared > maxBytes && declared > 0) {
43
36
  await response.body?.cancel().catch(() => undefined);
44
37
  throw new Error("Search provider response is too large.");
45
38
  }
@@ -58,14 +51,7 @@ async function readResponseBytes(
58
51
  const remaining = maxBytes - total;
59
52
 
60
53
  if (value.byteLength > remaining) {
61
- if (truncate && remaining > 0) chunks.push(value.subarray(0, remaining));
62
54
  await reader.cancel().catch(() => undefined);
63
-
64
- if (truncate) {
65
- total = maxBytes;
66
- break;
67
- }
68
-
69
55
  throw new Error("Search provider response is too large.");
70
56
  }
71
57
 
@@ -92,16 +78,11 @@ async function readResponseBytes(
92
78
  *
93
79
  * @param response - HTTP response to read
94
80
  * @param maxBytes - Maximum bytes to read
95
- * @param truncate - Whether to truncate at limit or throw error
96
81
  * @returns Promise resolving to the decoded text
97
82
  * @throws {Error} When response exceeds maxBytes and truncate is false
98
83
  */
99
- async function readResponseText(
100
- response: Response,
101
- maxBytes: number,
102
- truncate = false,
103
- ): Promise<string> {
104
- return new TextDecoder().decode(await readResponseBytes(response, maxBytes, truncate));
84
+ async function readResponseText(response: Response, maxBytes: number): Promise<string> {
85
+ return new TextDecoder().decode(await readResponseBytes(response, maxBytes));
105
86
  }
106
87
 
107
88
  /**
@@ -132,21 +113,14 @@ export async function requestText(
132
113
  if (signal?.aborted) controller.abort();
133
114
 
134
115
  try {
135
- const response = await fetch(url, { ...init, signal: controller.signal });
116
+ // Custom subscription-token headers are not stripped by fetch on cross-origin
117
+ // redirects. Never follow a provider-controlled redirect with credentials.
118
+ const response = await fetch(url, { ...init, redirect: "error", signal: controller.signal });
136
119
 
137
120
  if (!response.ok) {
138
- let body = "";
139
-
140
- try {
141
- body = normalizeText(
142
- await readResponseText(response, SEARCH_ERROR_EXCERPT_BYTES, true),
143
- 500,
144
- );
145
- } catch {
146
- // Preserve the useful HTTP status when an untrusted error body cannot be read.
147
- }
148
-
149
- throw new Error(`Provider returned HTTP ${response.status}${body ? `: ${body}` : ""}`);
121
+ // Error bodies are untrusted and can echo credentials or private queries.
122
+ void response.body?.cancel().catch(() => undefined);
123
+ throw new Error(`Provider returned HTTP ${response.status}`);
150
124
  }
151
125
 
152
126
  return await readResponseText(response, SEARCH_MAX_RESPONSE_BYTES);