@vipinsights/gemini-web-search-grounding 1.0.0 → 1.1.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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Minimal `web_search` tool for [pi](https://pi.dev) using Gemini's Grounding with Google Search. Derived from [ttttmr/pi-web-search](https://github.com/ttttmr/pi-web-search) (MIT).
4
4
 
5
+ https://www.npmjs.com/package/@vipinsights/gemini-web-search-grounding
6
+
5
7
  ## Scope
6
8
 
7
9
  - One tool: `web_search(query)`. Returns a grounded answer plus source links.
@@ -14,7 +16,7 @@ Minimal `web_search` tool for [pi](https://pi.dev) using Gemini's Grounding with
14
16
  Requires Pi 1.5.0 or newer. Do not load it alongside `pi-web-search`; both register `web_search`.
15
17
 
16
18
  ```bash
17
- pi install npm:gemini-web-search-grounding
19
+ pi install npm:@vipinsights/gemini-web-search-grounding
18
20
  ```
19
21
 
20
22
  ## Replace the previous web search tool
@@ -34,7 +36,7 @@ pi install npm:gemini-web-search-grounding
34
36
  3. Install this one:
35
37
 
36
38
  ```bash
37
- pi install npm:gemini-web-search-grounding
39
+ pi install npm:@vipinsights/gemini-web-search-grounding
38
40
  ```
39
41
 
40
42
  4. Set `GEMINI_API_KEY`, restart Pi, and select a Gemini model.
@@ -46,9 +48,9 @@ pi install npm:gemini-web-search-grounding
46
48
  2. Confirm `name` and `version` in `package.json`; the name must be unused on npm.
47
49
  3. Run checks: `npm test && npm run typecheck`
48
50
  4. Preview the tarball: `npm pack --dry-run` (only `src` and `README.md` should ship)
49
- 5. Publish: `npm publish` (add `--access public` for a scoped name like `@vtinfo/...`)
50
- 6. Verify: `pi install npm:gemini-web-search-grounding`
51
- 7. For later releases: `npm version patch|minor|major`, then `npm publish`
51
+ 5. Publish: `npm publish --access public`
52
+ 6. Verify: `pi install npm:@vipinsights/gemini-web-search-grounding`
53
+ 7. For later releases: `npm version patch|minor|major`, then `npm publish --access public`
52
54
 
53
55
  The `pi-package` keyword in `package.json` makes it discoverable as a Pi package.
54
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vipinsights/gemini-web-search-grounding",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Minimal web_search for pi using Gemini's Grounding with Google Search. Gemini models only; no URL fetching.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -23,6 +23,9 @@
23
23
  "test": "node --test tests/*.test.mjs",
24
24
  "typecheck": "tsc --noEmit"
25
25
  },
26
+ "engines": {
27
+ "node": ">=24.0.0"
28
+ },
26
29
  "devDependencies": {
27
30
  "@earendil-works/pi-ai": "^1.5.0",
28
31
  "@earendil-works/pi-coding-agent": "^1.5.0",
package/src/web_search.ts CHANGED
@@ -38,8 +38,10 @@ export async function webSearch(
38
38
  const apiKey = getEnvApiKey(model.provider);
39
39
  if (!apiKey) throw new Error(`web_search: set the environment variable pi uses for provider "${model.provider}" (GEMINI_API_KEY).`);
40
40
 
41
+ const baseUrl = (model.baseUrl ?? "").replace(/\/+$/, "");
42
+ const modelId = encodeURIComponent(model.id.replace(/^models\//, ""));
41
43
  const timeout = AbortSignal.timeout(TIMEOUT_MS);
42
- const res = await fetch(`${model.baseUrl}/models/${encodeURIComponent(model.id)}:generateContent`, {
44
+ const res = await fetch(`${baseUrl}/models/${modelId}:generateContent`, {
43
45
  method: "POST",
44
46
  headers: { "Content-Type": "application/json", "x-goog-api-key": apiKey },
45
47
  body: JSON.stringify({
@@ -59,6 +61,10 @@ export async function webSearch(
59
61
  }
60
62
 
61
63
  const candidate = data.candidates?.[0];
64
+ if (candidate?.finishReason && !["STOP", "MAX_TOKENS"].includes(candidate.finishReason)) {
65
+ throw new Error(`web_search: generation stopped by Gemini (${candidate.finishReason})`);
66
+ }
67
+
62
68
  const answer = (candidate?.content?.parts ?? [])
63
69
  .filter((part) => !part.thought)
64
70
  .map((part) => part.text ?? "")