pi-better-web-search 1.0.0 → 1.0.2
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 +58 -0
- package/README.md +36 -12
- package/assets/architecture.svg +4 -1
- package/docs/README.zh-CN.md +31 -9
- package/docs/architecture.md +9 -5
- package/docs/providers.md +15 -7
- package/docs/publishing.md +6 -6
- package/docs/search-apis.md +38 -10
- package/docs/testing.md +12 -5
- package/lib/candidates.ts +49 -4
- package/lib/login-command.ts +13 -2
- package/lib/providers/exa.ts +2 -1
- package/lib/providers/keenable.ts +3 -2
- package/lib/providers/perplexity.ts +2 -1
- package/lib/providers/response-metadata.ts +10 -0
- package/lib/providers/types.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.2 — Cleaner search results
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- Omit Keenable search/fetch billing `usage`, Perplexity request `id` and
|
|
8
|
+
`server_time`, and Exa search `requestId`, `costDollars`, `searchTime`,
|
|
9
|
+
`warnings` and deprecated `resolvedSearchType` from model-facing results.
|
|
10
|
+
Preserve source content, dates, scores, citations, truncation indicators,
|
|
11
|
+
Exa `notices`, unknown fields and nested fields with the same names.
|
|
12
|
+
|
|
13
|
+
## 1.0.1 — Your pi login, your search tools
|
|
14
|
+
|
|
15
|
+
### Fixes
|
|
16
|
+
|
|
17
|
+
- Discover official DeepSeek Search/Fetch through pi's provider-level `/login`
|
|
18
|
+
and `models.json` authentication even when the available chat catalog is
|
|
19
|
+
empty, filtered, stale, or has no flash model. Reuse request-time registry
|
|
20
|
+
credentials and configured native/proxy endpoints without copying keys or
|
|
21
|
+
invoking an inference model. Expose Search and Fetch in both provider pickers
|
|
22
|
+
and enable the URL-capable tool schema without a second extension login.
|
|
23
|
+
- Keep the pi-authenticated DeepSeek route separate from extension-saved and
|
|
24
|
+
environment standalone credentials. Preserve configured API priority, manual
|
|
25
|
+
preferences, fallback, and one menu entry per provider. Login/logout changes
|
|
26
|
+
invalidate discovery fingerprints; request-time auth and captured-header
|
|
27
|
+
redaction protect stale routes and in-flight credential rotation. Third-party
|
|
28
|
+
gateways merely hosting DeepSeek chat models are not treated as its native API.
|
|
29
|
+
- Show all terminal command entrypoints in `/pi-better-web-search` and
|
|
30
|
+
`/pi-better-web-search help`, including `/web-search-provider search`,
|
|
31
|
+
`/web-search-provider fetch`, and `/web-search-api`. Empty/help requests show
|
|
32
|
+
informational guidance instead of a warning; invalid arguments still warn
|
|
33
|
+
without echoing potentially sensitive values. Keep hidden-dialog-only key entry.
|
|
34
|
+
|
|
35
|
+
### Documentation and artwork
|
|
36
|
+
|
|
37
|
+
- Restore the original white-background, black/gray wireframe architecture style
|
|
38
|
+
and concise README introduction. Lead both English and Chinese READMEs with
|
|
39
|
+
what the plugin does; retain the updated standalone APIs and native fallback
|
|
40
|
+
diagram, and remove its duplicate from the later routing section.
|
|
41
|
+
- Use the maintainer's original Artificial Analysis screenshot unchanged as
|
|
42
|
+
`assets/search-index.png`, replacing the redrawn SVG chart. Update related
|
|
43
|
+
documentation links and package verification so the screenshot ships in npm.
|
|
44
|
+
- Prominently mark **Pi 1.5.2 verified** in both READMEs and the architecture
|
|
45
|
+
graphic. Define verification as type checking and automated tests against pi
|
|
46
|
+
1.5.2 host dependencies, with Node.js 22/24 CI, not live testing every provider.
|
|
47
|
+
- Document command discovery, independent search/fetch preferences, direct reuse
|
|
48
|
+
of pi's DeepSeek credentials, the API-only model-tier exception, and the latest
|
|
49
|
+
1.0.1 package and publishing commands in English and Chinese.
|
|
50
|
+
|
|
51
|
+
### Tests
|
|
52
|
+
|
|
53
|
+
- Add real pi 1.5.2 registry integration with isolated credential/model stores
|
|
54
|
+
for pi-login and `models.json` auth, plus regression tests for catalog gaps,
|
|
55
|
+
stale snapshots, legacy registries, tool exposure, provider selection,
|
|
56
|
+
proxy/auth overrides, logout, credential rotation, priority, and fallback.
|
|
57
|
+
- Add full-help discovery tests across TUI/RPC/print contexts and expand invalid
|
|
58
|
+
argument checks to ensure help opens no dialogs, changes no state, and never
|
|
59
|
+
echoes credentials.
|
|
60
|
+
|
|
3
61
|
## 1.0.0 — Search is an agent superpower
|
|
4
62
|
|
|
5
63
|
### The flagship search upgrade
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ providers. Keep your conversation model; get provider results as-is.
|
|
|
10
10
|
[](https://github.com/zhexusun10/pi-better-web-search/actions/workflows/ci.yml)
|
|
11
11
|
[](https://www.npmjs.com/package/pi-better-web-search)
|
|
12
12
|
[](LICENSE)
|
|
13
|
-
[](docs/testing.md)
|
|
14
14
|
[](https://nodejs.org)
|
|
15
15
|
|
|
16
16
|
[简体中文](docs/README.zh-CN.md) · [Search APIs](docs/search-apis.md) · [Architecture](docs/architecture.md) · [Providers](docs/providers.md) · [Testing](docs/testing.md)
|
|
@@ -46,7 +46,7 @@ tokens rediscovering a solution someone has already published.** One well-placed
|
|
|
46
46
|
`web_search` call can surface the right API, package, or fix—turning repeated
|
|
47
47
|
trial and error into a direct path to a successful task, with fewer wasted tokens.
|
|
48
48
|
|
|
49
|
-
### 1.0
|
|
49
|
+
### 1.0: An epic release for the pi open-source community
|
|
50
50
|
|
|
51
51
|
Built to be the web-search tool you reach for first:
|
|
52
52
|
|
|
@@ -63,7 +63,7 @@ Built to be the web-search tool you reach for first:
|
|
|
63
63
|
|
|
64
64
|
## Install and search
|
|
65
65
|
|
|
66
|
-
**Version 1.0.
|
|
66
|
+
**Version 1.0.2 is available.** [Release notes and package download](https://github.com/zhexusun10/pi-better-web-search/releases/tag/v1.0.2).
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
69
|
pi install npm:pi-better-web-search
|
|
@@ -93,7 +93,8 @@ pi install ./path/to/pi-better-web-search
|
|
|
93
93
|
> Do not load this package together with `pi-web-search`. Both register a tool
|
|
94
94
|
> named `web_search`, and the second registration replaces the first.
|
|
95
95
|
|
|
96
|
-
Requirements: **pi 1.3+** and **Node.js 22.19+**.
|
|
96
|
+
Requirements: **pi 1.3+** and **Node.js 22.19+**. **Pi 1.5.2 verified** with
|
|
97
|
+
type checking and automated tests against pi 1.5.2 host dependencies.
|
|
97
98
|
|
|
98
99
|
## What makes it better
|
|
99
100
|
|
|
@@ -105,7 +106,8 @@ A focused tool with the reliability features an agent actually needs:
|
|
|
105
106
|
and parameter schema.
|
|
106
107
|
- **Correct exposure.** The tool is hidden when the current model has no
|
|
107
108
|
compatible search interface and no compatible provider is authenticated. A
|
|
108
|
-
configured dedicated search API
|
|
109
|
+
configured dedicated search API, pi-authenticated DeepSeek tools, or an
|
|
110
|
+
authenticated lightweight model exposes it.
|
|
109
111
|
- **Automatic fallback.** If the current model cannot search, or a provider
|
|
110
112
|
call fails, the extension tries other authenticated provider interfaces until
|
|
111
113
|
one succeeds.
|
|
@@ -193,6 +195,13 @@ final return type.
|
|
|
193
195
|
|
|
194
196
|
## Dedicated search APIs
|
|
195
197
|
|
|
198
|
+
**Already logged into official DeepSeek with pi's `/login`, or configured its key
|
|
199
|
+
in pi's `models.json`? No second login is needed.** The extension reuses pi's
|
|
200
|
+
`deepseek` provider credentials for native Search/Fetch, even if the available chat
|
|
201
|
+
catalog is empty or has no `flash` model. Select it with `/web-search-provider fetch`
|
|
202
|
+
or `/web-search-provider search`. No inference model is invoked and no key is copied.
|
|
203
|
+
Third-party gateways merely hosting DeepSeek models are not treated as the official API.
|
|
204
|
+
|
|
196
205
|
Run **`/pi-better-web-search login`** in pi's terminal, choose **DeepSeek, Exa,
|
|
197
206
|
Keenable, or Perplexity**, then paste/type the API key into the **hidden input**
|
|
198
207
|
and press Enter. The key is saved separately from settings/cache, and the API
|
|
@@ -275,6 +284,9 @@ support per family.
|
|
|
275
284
|
|
|
276
285
|
## Choose providers in the terminal
|
|
277
286
|
|
|
287
|
+
Run `/pi-better-web-search` or `/pi-better-web-search help` to list all terminal
|
|
288
|
+
commands, including login, search/fetch preferences, and API enable/disable settings.
|
|
289
|
+
|
|
278
290
|
Run `/web-search-provider` to choose a preferred provider separately for
|
|
279
291
|
**Web Search** and **URL Fetch**. Or open either picker directly:
|
|
280
292
|
|
|
@@ -312,10 +324,11 @@ Dedicated retrieval APIs have no chat-model tier and can expose the tool on
|
|
|
312
324
|
their own. For model-backed interfaces, only lightweight models are eligible:
|
|
313
325
|
**OpenAI = `luna`, Claude = `haiku`,
|
|
314
326
|
all other brands (including DeepSeek) = `flash`**. This is a strict allowlist,
|
|
315
|
-
not live price detection. It applies to search, URL analysis,
|
|
316
|
-
cache hints, and
|
|
317
|
-
|
|
318
|
-
|
|
327
|
+
not live price detection. It applies to model-backed search, URL analysis,
|
|
328
|
+
current models, cache hints, and fallback. Pi-authenticated DeepSeek native tools
|
|
329
|
+
are an API-only exception: they use no inference model and need no `flash` id.
|
|
330
|
+
Without an eligible model, pi-authenticated DeepSeek tools, or a standalone API,
|
|
331
|
+
the tool stays hidden; it never silently upgrades to another inference-model tier.
|
|
319
332
|
|
|
320
333
|
After any explicit provider preference, configured **Keenable → Exa →
|
|
321
334
|
Perplexity → standalone DeepSeek** APIs are tried first (Fetch skips Perplexity),
|
|
@@ -451,7 +464,9 @@ tool call.
|
|
|
451
464
|
|
|
452
465
|
## Raw provider results
|
|
453
466
|
|
|
454
|
-
Provider
|
|
467
|
+
Provider content is returned in a JSON wrapper, with known billing, request
|
|
468
|
+
tracking and timing fields omitted from standalone API responses. Search results,
|
|
469
|
+
page text and source evidence retain their provider fields. A search looks like
|
|
455
470
|
this:
|
|
456
471
|
|
|
457
472
|
```json
|
|
@@ -479,6 +494,10 @@ this:
|
|
|
479
494
|
- Citation markers are not inserted, and no "Sources" or "Additional results"
|
|
480
495
|
sections are appended.
|
|
481
496
|
- Redirects are not resolved and sources are not derived.
|
|
497
|
+
- Known standalone API bookkeeping is omitted: Keenable `usage`, Perplexity
|
|
498
|
+
`id` / `server_time`, and Exa `requestId` / `costDollars` / `searchTime` /
|
|
499
|
+
`warnings` / `resolvedSearchType`. Exa `notices` remain available to the model.
|
|
500
|
+
See [response metadata handling](docs/search-apis.md#interfaces).
|
|
482
501
|
- Unknown provider fields are preserved when the result fits the size guard.
|
|
483
502
|
|
|
484
503
|
A final output-size guard limits model-facing results and errors to **96,000
|
|
@@ -524,10 +543,13 @@ needed.
|
|
|
524
543
|
search interface; or
|
|
525
544
|
- at least one authenticated available lightweight model maps to a supported
|
|
526
545
|
provider family; or
|
|
546
|
+
- pi has configured official `deepseek` provider credentials for native
|
|
547
|
+
Search/Fetch (no available chat model or `flash` id needed); or
|
|
527
548
|
- a dedicated search API is configured and usable (no chat model needed).
|
|
528
549
|
|
|
529
550
|
For model-backed interfaces the same lightweight restriction applies to `urls`;
|
|
530
|
-
standalone Keenable, Exa, and DeepSeek
|
|
551
|
+
standalone Keenable, Exa, and DeepSeek, plus pi-authenticated DeepSeek native
|
|
552
|
+
tools, expose it without a chat-model tier.
|
|
531
553
|
|
|
532
554
|
For an unsupported current model with no compatible login or API key, the tool
|
|
533
555
|
stays hidden (removed from the active tool set). The extension never calls an
|
|
@@ -588,6 +610,8 @@ See [SECURITY.md](SECURITY.md) for reporting vulnerabilities.
|
|
|
588
610
|
|
|
589
611
|
## Verified
|
|
590
612
|
|
|
613
|
+
- **Pi 1.5.2 verified**: type checking and automated tests against pi 1.5.2
|
|
614
|
+
host dependencies, with CI passing on Node.js 22 and 24.
|
|
591
615
|
- **Unit and integration tests** covering exposure, schema variants,
|
|
592
616
|
provider request shapes, SSE parsing, raw-result preservation, fallback,
|
|
593
617
|
cache invalidation, URL handling, truncation, and abort behavior.
|
|
@@ -630,7 +654,7 @@ npm run build
|
|
|
630
654
|
```
|
|
631
655
|
|
|
632
656
|
`npm run build` runs the checks and tests, verifies the npm file list, and packs
|
|
633
|
-
`dist/pi-better-web-search-1.0.
|
|
657
|
+
`dist/pi-better-web-search-1.0.2.tgz`. Nothing is published automatically.
|
|
634
658
|
|
|
635
659
|
The test suite uses plain `.mjs` files that import the `.ts` sources directly.
|
|
636
660
|
It mocks `globalThis.fetch`, uses a temporary cache file, and exercises
|
package/assets/architecture.svg
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="640" viewBox="0 0 1200 640" role="img" aria-labelledby="title desc">
|
|
2
2
|
<title id="title">pi-better-web-search architecture</title>
|
|
3
|
-
<desc id="desc">One web_search tool accepts a query, URLs, or both. The router honors separate search and fetch preferences, tries configured Keenable, Exa, Perplexity and DeepSeek APIs, then falls back across eligible authenticated native providers. Search and fetch preserve successful raw results independently, with a 96,000-character output guard.</desc>
|
|
3
|
+
<desc id="desc">One web_search tool accepts a query, URLs, or both. The router honors separate search and fetch preferences, tries configured Keenable, Exa, Perplexity and DeepSeek APIs, then falls back across eligible authenticated native providers. Search and fetch preserve successful raw results independently, with a 96,000-character output guard. Type checking and automated tests are verified against pi 1.5.2 host dependencies.</desc>
|
|
4
4
|
<defs>
|
|
5
5
|
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
6
6
|
<path d="M 0 0 L 10 5 L 0 10 z" fill="#52525b"/>
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
<text class="title" x="56" y="82">pi-better-web-search</text>
|
|
34
34
|
<text class="subtitle" x="56" y="116">one tool · search APIs · native fallback · raw results</text>
|
|
35
35
|
|
|
36
|
+
<rect class="box" x="980" y="54" width="160" height="30" rx="15"/>
|
|
37
|
+
<text class="p" x="1060" y="74" text-anchor="middle">Pi 1.5.2 verified</text>
|
|
38
|
+
|
|
36
39
|
<rect class="box" x="56" y="150" width="220" height="124" rx="16"/>
|
|
37
40
|
<text class="h" x="76" y="180">Your pi agent</text>
|
|
38
41
|
<text class="t" x="76" y="208">web_search</text>
|
package/docs/README.zh-CN.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
使用 **Keenable、Exa、Perplexity 或 DeepSeek** 搜索,在支持时抓取 URL,
|
|
7
7
|
并在已认证的原生 provider 之间自动回退。不换对话模型,provider 数据原样返回。
|
|
8
8
|
|
|
9
|
+
[](testing.md)
|
|
10
|
+
|
|
9
11
|
[English](../README.md) · [搜索 API](search-apis.md) · [架构说明](architecture.md) · [Provider 细节](providers.md) · [测试](testing.md)
|
|
10
12
|
|
|
11
13
|
## 插件具体在做什么
|
|
@@ -36,7 +38,7 @@ Artificial Analysis Search Index 把差距画得很直观:虚线是**无搜索
|
|
|
36
38
|
一次恰到好处的 `web_search`,就能找到正确的 API、可复用的包或有效修复,
|
|
37
39
|
用更少的无效 token,把任务做对。
|
|
38
40
|
|
|
39
|
-
### 1.0
|
|
41
|
+
### 1.0:献给 pi 开源社区的一次史诗级升级
|
|
40
42
|
|
|
41
43
|
冲着成为你首选的 Web Search 工具而来:
|
|
42
44
|
|
|
@@ -51,7 +53,7 @@ Artificial Analysis Search Index 把差距画得很直观:虚线是**无搜索
|
|
|
51
53
|
|
|
52
54
|
## 安装,登录,开搜
|
|
53
55
|
|
|
54
|
-
**1.0.
|
|
56
|
+
**1.0.2 已可用。** [查看更新说明与下载安装包](https://github.com/zhexusun10/pi-better-web-search/releases/tag/v1.0.2)。
|
|
55
57
|
|
|
56
58
|
```bash
|
|
57
59
|
pi install npm:pi-better-web-search
|
|
@@ -78,7 +80,8 @@ pi install ./path/to/pi-better-web-search
|
|
|
78
80
|
> 不要和 `pi-web-search` 同时加载。两者都注册 `web_search`,后注册的会覆盖
|
|
79
81
|
> 先注册的。
|
|
80
82
|
|
|
81
|
-
要求:**pi 1.3+**,**Node.js 22.19
|
|
83
|
+
要求:**pi 1.3+**,**Node.js 22.19+**。**Pi 1.5.2 verified**:已基于 pi 1.5.2
|
|
84
|
+
宿主依赖通过类型检查和自动化测试。
|
|
82
85
|
|
|
83
86
|
## 为什么更好用
|
|
84
87
|
|
|
@@ -159,6 +162,12 @@ URL 失败写入 `fetched[].error`。只有请求结构非法或没有任何成
|
|
|
159
162
|
|
|
160
163
|
## 第三方专用 Search API
|
|
161
164
|
|
|
165
|
+
**已通过 pi 自带 `/login` 登录官方 DeepSeek,或在 pi 的 `models.json` 配置其 key?
|
|
166
|
+
无需重复登录扩展。** 插件直接复用 `deepseek` provider 的凭据调用原生 Search/Fetch,
|
|
167
|
+
即使可用对话模型列表为空或没有 `flash` 模型,也会显示在搜索/抓取首选菜单中。
|
|
168
|
+
运行 `/web-search-provider fetch` 或 `/web-search-provider search` 即可选择。
|
|
169
|
+
不调用推理模型,也不复制 key;第三方网关仅提供 DeepSeek 模型不等于官方 API。
|
|
170
|
+
|
|
162
171
|
直接在 pi 终端运行:
|
|
163
172
|
|
|
164
173
|
```text
|
|
@@ -233,6 +242,9 @@ Provider 识别顺序:
|
|
|
233
242
|
|
|
234
243
|
## 在终端选择 provider
|
|
235
244
|
|
|
245
|
+
直接运行 `/pi-better-web-search` 或 `/pi-better-web-search help`,即可查看完整终端命令:
|
|
246
|
+
登录、搜索/抓取首选与 API 启用/禁用设置。
|
|
247
|
+
|
|
236
248
|
运行 `/web-search-provider`,分别设置 **Web Search** 和 **URL Fetch** 的首选
|
|
237
249
|
provider;也可以直接打开对应选择器:
|
|
238
250
|
|
|
@@ -263,8 +275,10 @@ URL 抓取只重试未成功的 URL;输入校验和取消行为保持不变。
|
|
|
263
275
|
## 自动选择与 fallback
|
|
264
276
|
|
|
265
277
|
模型接口严格限定轻量档位:**OpenAI 只用 `luna`,Claude 只用 `haiku`,DeepSeek 和其他
|
|
266
|
-
品牌只用 `flash
|
|
267
|
-
缓存和模型 fallback
|
|
278
|
+
品牌只用 `flash`**。这是名称白名单,不是实时价格判断。模型搜索、URL 分析、当前模型、
|
|
279
|
+
缓存和模型 fallback 都遵守此规则。通过 pi 认证的 DeepSeek 原生工具是纯 API 例外:
|
|
280
|
+
不调用推理模型,不要求 `flash` id。没有合格模型、pi 已认证的 DeepSeek 原生工具或
|
|
281
|
+
可用独立 API 时隐藏工具,不自动升级其他推理模型档位。
|
|
268
282
|
|
|
269
283
|
上述轻量档位限制只针对模型接口;专用 Search API 不调用推理模型。
|
|
270
284
|
在可用的手动首选之后,先尝试已配置的 **Keenable → Exa → Perplexity → 独立 DeepSeek**
|
|
@@ -381,7 +395,8 @@ rm ~/.pi/agent/better-web-search.json
|
|
|
381
395
|
|
|
382
396
|
## 原始结果
|
|
383
397
|
|
|
384
|
-
Provider
|
|
398
|
+
Provider 内容放在 JSON 外层中返回。独立 API 响应中已知的计费、请求追踪和
|
|
399
|
+
耗时字段会裁掉;搜索结果、网页正文和来源证据保留 provider 的原始字段。示例:
|
|
385
400
|
|
|
386
401
|
```json
|
|
387
402
|
{
|
|
@@ -407,6 +422,10 @@ Provider 数据放在 JSON 外层中返回,不做清理。示例:
|
|
|
407
422
|
- 结果不重排、不总结。
|
|
408
423
|
- 不插入 citation 标记,不追加 "Sources" 或 "Additional results"。
|
|
409
424
|
- 不解析 redirect,不派生 sources。
|
|
425
|
+
- 裁掉独立 API 的已知无关字段:Keenable 的 `usage`,Perplexity 的
|
|
426
|
+
`id` / `server_time`,以及 Exa 的 `requestId` / `costDollars` / `searchTime` /
|
|
427
|
+
`warnings` / `resolvedSearchType`。Exa 的 `notices` 解释结果生成方式,继续保留。
|
|
428
|
+
只处理响应外层,不递归删除结果或正文中的同名字段,详见[响应元数据处理](search-apis.md#interfaces)。
|
|
410
429
|
- 未超出大小限制时,provider 的未知字段也会保留。
|
|
411
430
|
|
|
412
431
|
最终大小保护默认限制结果及错误文本不超过 **96,000 个 Unicode code point**。
|
|
@@ -446,10 +465,11 @@ PowerShell 使用 `$env:PI_BETTER_WEB_SEARCH_MAX_CHARS = "100000"`。
|
|
|
446
465
|
|
|
447
466
|
- 当前对话模型属于上述轻量档位,且支持 provider 原生搜索接口;或
|
|
448
467
|
- 至少一个已认证的可用轻量模型映射到支持的 provider family;或
|
|
468
|
+
- pi 已配置官方 `deepseek` provider 凭据,可调用原生 Search/Fetch,无需可用对话模型或 `flash` id;或
|
|
449
469
|
- 已配置可用的专用 Search API,无需对话模型。
|
|
450
470
|
|
|
451
|
-
模型接口的 `urls` 暴露也遵守轻量档位限制;独立 Keenable、Exa
|
|
452
|
-
|
|
471
|
+
模型接口的 `urls` 暴露也遵守轻量档位限制;独立 Keenable、Exa、DeepSeek,
|
|
472
|
+
以及通过 pi 认证的 DeepSeek 原生工具,无需 chat 模型即可提供 URL 抓取。
|
|
453
473
|
|
|
454
474
|
当前模型不支持搜索,且没有兼容的登录/API key 时,工具保持隐藏(从 active
|
|
455
475
|
tool set 移除)。扩展不会调用未认证的 provider。可用 provider 或凭据集合变化
|
|
@@ -492,6 +512,8 @@ provider;`403`/`404` 作为单个 URL 的错误上报,orchestrator 只重试
|
|
|
492
512
|
|
|
493
513
|
## 已验证
|
|
494
514
|
|
|
515
|
+
- **Pi 1.5.2 verified**:基于 pi 1.5.2 宿主依赖通过类型检查和自动化测试,
|
|
516
|
+
Node.js 22 / 24 CI 均通过。
|
|
495
517
|
- **单元/集成测试**:暴露规则、schema 变体、provider 请求形状、SSE 解析、
|
|
496
518
|
原始结果保留、fallback、缓存失效、URL 处理、截断和取消。
|
|
497
519
|
- **真实 DeepSeek Search/Fetch**:使用真实 API key,返回 10 条原始搜索结果、
|
|
@@ -527,7 +549,7 @@ npm run build
|
|
|
527
549
|
```
|
|
528
550
|
|
|
529
551
|
`npm run build` 会运行检查、测试、包内容验证,并生成
|
|
530
|
-
`dist/pi-better-web-search-1.0.
|
|
552
|
+
`dist/pi-better-web-search-1.0.2.tgz`。不会自动发布。
|
|
531
553
|
|
|
532
554
|
测试是 `.mjs` 文件,直接导入 `.ts` 源码,mock `globalThis.fetch`,使用临时缓存
|
|
533
555
|
目录。详见 [测试](testing.md) 和 [发布](publishing.md)。
|
package/docs/architecture.md
CHANGED
|
@@ -20,7 +20,8 @@ output guard. It does not own provider result cleanup.
|
|
|
20
20
|
authentication quirks, and stream format.
|
|
21
21
|
5. **Strict lightweight routing.** Only OpenAI `luna`, Claude `haiku`, and
|
|
22
22
|
other brands' `flash` models are eligible for model-backed routes. Standalone
|
|
23
|
-
APIs are tier-independent. Prefer
|
|
23
|
+
APIs and pi-authenticated DeepSeek native tools are tier-independent. Prefer
|
|
24
|
+
an explicit user selection, then configured
|
|
24
25
|
APIs, then current-provider/cache/family routing. Model hints reselect eligible
|
|
25
26
|
models and cannot bypass tier rules.
|
|
26
27
|
6. **Do not touch pi's system prompt.** No prompt snippets, guidelines, loadout
|
|
@@ -71,14 +72,17 @@ as standalone interfaces merely because they share the `deepseek` provider id.
|
|
|
71
72
|
|
|
72
73
|
## Exposure
|
|
73
74
|
|
|
74
|
-
A candidate is
|
|
75
|
-
|
|
76
|
-
candidates have internal cache/health identities,
|
|
75
|
+
A candidate is a supported lightweight chat model, a configured standalone
|
|
76
|
+
retrieval API, or pi-authenticated DeepSeek native tools, all implementing
|
|
77
|
+
`ProviderAdapter`. API-only candidates have internal cache/health identities,
|
|
78
|
+
not actual inference models.
|
|
77
79
|
The tool is exposed when:
|
|
78
80
|
|
|
79
81
|
- the current conversation model has the required lightweight tier and maps to
|
|
80
82
|
a supported family; or
|
|
81
83
|
- `modelRegistry.getAvailable()` contains at least one supported lightweight model; or
|
|
84
|
+
- pi's registry reports configured `deepseek` auth and a native provider endpoint,
|
|
85
|
+
even when no eligible chat model is available; or
|
|
82
86
|
- a saved-key or environment-configured retrieval API (or explicitly enabled public
|
|
83
87
|
Keenable) is available, without requiring a model registry entry.
|
|
84
88
|
|
|
@@ -100,7 +104,7 @@ silently re-add it.
|
|
|
100
104
|
## Candidate ordering
|
|
101
105
|
|
|
102
106
|
An explicit per-phase provider preference is inserted first when authenticated,
|
|
103
|
-
|
|
107
|
+
supported, and lightweight for inference-backed routes. This is not a filter: all automatic fallback remains
|
|
104
108
|
available, and the explicit preference is tried first even after failures.
|
|
105
109
|
|
|
106
110
|
Configured Keenable, Exa, Perplexity, then standalone DeepSeek come next, ahead
|
package/docs/providers.md
CHANGED
|
@@ -49,8 +49,10 @@ failures; only unresolved URLs proceed to fallback.
|
|
|
49
49
|
Configured **Keenable → Exa → Perplexity → standalone DeepSeek** precede
|
|
50
50
|
automatic model routing (fetch skips Perplexity); explicit per-phase preferences
|
|
51
51
|
still win and fallback remains enabled. Health cooldowns reorder automatic
|
|
52
|
-
native routes only, not the explicit or standalone priorities. Search
|
|
53
|
-
and each fetched raw document are preserved
|
|
52
|
+
native routes only, not the explicit or standalone priorities. Search content
|
|
53
|
+
and each fetched raw document are preserved, with known API bookkeeping omitted
|
|
54
|
+
as described in [response metadata handling](search-apis.md#interfaces). These
|
|
55
|
+
services do not participate in model-tier ranking.
|
|
54
56
|
The [skill comparison](search-skills.md) explains the approved Exa options and
|
|
55
57
|
why no additional model-facing parameter or prompt injection was added.
|
|
56
58
|
|
|
@@ -60,16 +62,21 @@ For model-backed interfaces, routing strictly requires OpenAI-brand `luna`, Clau
|
|
|
60
62
|
brands' `flash` tier, including gateway models and DeepSeek/Ollama credential
|
|
61
63
|
candidates. Select the highest numeric version within the brand's eligible
|
|
62
64
|
tier. Current models, cache hints, and fallback cannot bypass this allowlist.
|
|
63
|
-
An authenticated
|
|
64
|
-
tool on its own; configured standalone APIs remain available.
|
|
65
|
+
An authenticated inference-model provider with no eligible model does not expose
|
|
66
|
+
the tool on its own; configured standalone APIs remain available. Pi-authenticated
|
|
67
|
+
DeepSeek Search/Fetch is a provider-level API exception: it needs no inference
|
|
68
|
+
model and does not depend on a `flash` id or a populated available chat catalog.
|
|
65
69
|
|
|
66
70
|
## DeepSeek
|
|
67
71
|
|
|
68
72
|
DeepSeek uses the documented native Search/Fetch API rather than the older
|
|
69
73
|
Anthropic-compatible chat route. Neither endpoint sends a `model` parameter:
|
|
70
74
|
choosing a flash candidate selects credentials/base URL, not an inference
|
|
71
|
-
model.
|
|
72
|
-
|
|
75
|
+
model. If no eligible chat route is available, provider-level discovery reuses
|
|
76
|
+
pi's official `deepseek` login or `models.json` credentials directly. No second
|
|
77
|
+
extension login is required; no key is copied into extension storage. The
|
|
78
|
+
terminal displays the actual Search or Fetch API endpoint rather than a
|
|
79
|
+
misleading pro/flash chat-model label.
|
|
73
80
|
|
|
74
81
|
### Authentication and base URL
|
|
75
82
|
|
|
@@ -281,6 +288,7 @@ a per-URL error.
|
|
|
281
288
|
preservation, search evidence, errors, aborts, and URL behavior.
|
|
282
289
|
6. Update this document, `README.md`, and `CHANGELOG.md`.
|
|
283
290
|
|
|
284
|
-
Keep provider
|
|
291
|
+
Keep provider content raw, apart from the documented response-level API
|
|
292
|
+
bookkeeping omissions. If the provider returns an answer, keep it as the
|
|
285
293
|
provider returned it. If it returns result objects, preserve their fields and
|
|
286
294
|
order. Do not add a normalization layer.
|
package/docs/publishing.md
CHANGED
|
@@ -30,7 +30,7 @@ local `pi-web-search` reference checkout, `.env` files, and `DESIGN.md`.
|
|
|
30
30
|
npm run build
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
This produces `dist/pi-better-web-search-1.0.
|
|
33
|
+
This produces `dist/pi-better-web-search-1.0.2.tgz`. The tarball is not
|
|
34
34
|
committed.
|
|
35
35
|
|
|
36
36
|
## Publish
|
|
@@ -42,7 +42,7 @@ npm publish --access public
|
|
|
42
42
|
Alternatively, publish the verified tarball directly:
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
npm publish dist/pi-better-web-search-1.0.
|
|
45
|
+
npm publish dist/pi-better-web-search-1.0.2.tgz --access public
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
When publishing from the checkout, `prepublishOnly` reruns the checks, tests,
|
|
@@ -52,10 +52,10 @@ build` first to verify it. npm may require browser or OTP authentication.
|
|
|
52
52
|
## Tag and release
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
git tag -a v1.0.
|
|
56
|
-
git push origin v1.0.
|
|
57
|
-
gh release create v1.0.
|
|
58
|
-
--title "v1.0.
|
|
55
|
+
git tag -a v1.0.2 -m "v1.0.2"
|
|
56
|
+
git push origin v1.0.2
|
|
57
|
+
gh release create v1.0.2 dist/pi-better-web-search-1.0.2.tgz \
|
|
58
|
+
--title "v1.0.2" \
|
|
59
59
|
--notes-file /path/to/release-notes.md
|
|
60
60
|
```
|
|
61
61
|
|
package/docs/search-apis.md
CHANGED
|
@@ -21,13 +21,39 @@ Web Search scores **74**. See the [original screenshot](../assets/search-index.p
|
|
|
21
21
|
| Keenable | `POST https://api.keenable.ai/v1/search` | `GET https://api.keenable.ai/v1/fetch` | `KEENABLE_API_KEY` or explicit public access |
|
|
22
22
|
| Exa | `POST https://api.exa.ai/search` | `POST https://api.exa.ai/contents` | `EXA_API_KEY` |
|
|
23
23
|
|
|
24
|
+
Successful responses omit known API bookkeeping before reaching the model:
|
|
25
|
+
|
|
26
|
+
| Provider | Omitted fields |
|
|
27
|
+
|---|---|
|
|
28
|
+
| Keenable search and fetch | `usage` (billing, credits and remaining balance) |
|
|
29
|
+
| Perplexity search | `id`, `server_time` (request tracking and server timing) |
|
|
30
|
+
| Exa search | `requestId`, `costDollars`, `searchTime`, `warnings`, `resolvedSearchType` |
|
|
31
|
+
|
|
32
|
+
This filtering is shallow and provider-specific. Result objects, page text,
|
|
33
|
+
source dates, scores, citations, truncation indicators and unknown fields remain
|
|
34
|
+
unchanged. Exa `notices` are retained because they explain how results were
|
|
35
|
+
produced; `warnings` are request diagnostics and `resolvedSearchType` is deprecated.
|
|
36
|
+
Exa fetch already returns individual documents rather than the response envelope.
|
|
37
|
+
Native model adapters select search results, answers and source evidence without
|
|
38
|
+
forwarding response-level token usage. HTTP errors retain their diagnostic details
|
|
39
|
+
for normal fallback and troubleshooting.
|
|
40
|
+
|
|
24
41
|
### DeepSeek: native Search/Fetch
|
|
25
42
|
|
|
26
43
|
Terminal login works without a pi chat model. Both native endpoints use the
|
|
27
44
|
resolved saved/environment key as a Bearer credential, and neither sends a
|
|
28
45
|
model name. Extension-saved keys are not silently forwarded to arbitrary
|
|
29
46
|
custom model gateways. It shares credential-specific `Retry-After` across search and fetch, and rejects
|
|
30
|
-
malformed header keys before HTTP.
|
|
47
|
+
malformed header keys before HTTP.
|
|
48
|
+
|
|
49
|
+
Pi's official `deepseek` provider is also supported independently: credentials
|
|
50
|
+
saved by pi's `/login` or configured through `models.json` are resolved through
|
|
51
|
+
pi's registry at request time, not copied into this extension. Provider-level
|
|
52
|
+
Search/Fetch discovery works without an available chat model or `flash` id.
|
|
53
|
+
These routes retain pi's configured native/proxy base URL and headers; extension
|
|
54
|
+
API toggles still apply only to the separate saved/environment standalone path.
|
|
55
|
+
Third-party gateways merely listing DeepSeek chat models are not promoted to
|
|
56
|
+
native DeepSeek Search/Fetch.
|
|
31
57
|
|
|
32
58
|
### Perplexity: standard Search API only
|
|
33
59
|
|
|
@@ -39,9 +65,9 @@ The request is exactly:
|
|
|
39
65
|
|
|
40
66
|
Authorization is `Bearer <PERPLEXITY_API_KEY>`. **Fast search is not used.**
|
|
41
67
|
There is no `effort`, `preset`, `model`, `tools`, conversation state or generated
|
|
42
|
-
answer. Neither Agent nor Orchestrator APIs are called.
|
|
43
|
-
|
|
44
|
-
`
|
|
68
|
+
answer. Neither Agent nor Orchestrator APIs are called. `results` and unknown
|
|
69
|
+
fields are returned inside `search` without rewriting the results; the outer
|
|
70
|
+
request `id` and `server_time` are omitted.
|
|
45
71
|
|
|
46
72
|
Perplexity alone exposes a query-only schema. Configure Keenable or an existing
|
|
47
73
|
URL-capable provider to add `urls`; a combined call can search with Perplexity
|
|
@@ -56,7 +82,8 @@ unauthenticated Perplexity request.
|
|
|
56
82
|
|
|
57
83
|
Search sends `{ "query": "...", "mode": "pro", "max_results": 10 }`, not the
|
|
58
84
|
fast `realtime` mode. Fetch uses GET with URL-encoded `url` and `live=true`,
|
|
59
|
-
without an LLM extraction `prompt`. Response
|
|
85
|
+
without an LLM extraction `prompt`. Response content and source metadata are
|
|
86
|
+
preserved; the outer billing `usage` object is omitted from both operations.
|
|
60
87
|
Keyed requests use `X-API-Key: <KEENABLE_API_KEY>`.
|
|
61
88
|
|
|
62
89
|
Without a key, explicit public access uses `/v1/search/public` and
|
|
@@ -86,11 +113,12 @@ With `X-API-Key: <EXA_API_KEY>`, search sends the user-approved request:
|
|
|
86
113
|
}
|
|
87
114
|
```
|
|
88
115
|
|
|
89
|
-
`type` is omitted (server default `auto`).
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
`type` is omitted (server default `auto`). Raw `results`/highlights, `notices`
|
|
117
|
+
and unknown fields are preserved. Request tracking, cost, timing, request
|
|
118
|
+
warnings and the deprecated resolved search type are omitted as listed above.
|
|
119
|
+
There is no chat model, SDK, Answer/Agent API or generated objective. The
|
|
120
|
+
model-facing contract stays `query` / `urls`; other advanced options remain
|
|
121
|
+
off. See the [skill comparison and decision table](search-skills.md).
|
|
94
122
|
|
|
95
123
|
URL-only calls use `POST /contents` without performing a search:
|
|
96
124
|
|
package/docs/testing.md
CHANGED
|
@@ -17,7 +17,7 @@ npm run verify:package
|
|
|
17
17
|
tarball contains runtime sources, docs, assets, and metadata, while excluding
|
|
18
18
|
tests, scripts, CI files, the local reference checkout, and `DESIGN.md`.
|
|
19
19
|
- `npm run build` runs the checks, tests, package verification, and packs
|
|
20
|
-
`dist/pi-better-web-search-1.0.
|
|
20
|
+
`dist/pi-better-web-search-1.0.2.tgz`.
|
|
21
21
|
|
|
22
22
|
Tests import the TypeScript sources directly. The suite mocks `globalThis.fetch`
|
|
23
23
|
and uses temporary cache directories. Coverage includes:
|
|
@@ -33,8 +33,9 @@ and uses temporary cache directories. Coverage includes:
|
|
|
33
33
|
- dedicated API protocols, standard Perplexity search (no fast/effort/Agent API),
|
|
34
34
|
Keenable keyed/public pro search and live GET fetch, Exa 10-result highlights
|
|
35
35
|
search and full-text `/contents` fetch, per-URL statuses, reordered/redirected
|
|
36
|
-
results, duplicate URLs,
|
|
37
|
-
|
|
36
|
+
results, duplicate URLs, source metadata, omission of response-level billing,
|
|
37
|
+
request tracking and timing fields, retained Exa notices and nested same-name
|
|
38
|
+
fields, standalone exposure, explicit/configured/native ordering and fallback;
|
|
38
39
|
- API configuration menus, public-access consent, secret-free persistence,
|
|
39
40
|
credential redaction and Retry-After seconds/HTTP-date behavior;
|
|
40
41
|
- atomic settings/cache replacement with injected partial-write and rename
|
|
@@ -51,7 +52,11 @@ and uses temporary cache directories. Coverage includes:
|
|
|
51
52
|
Exa in-flight key-rotation redaction and canonical-URL error statuses; bounded
|
|
52
53
|
HTTP error cleanup even when underlying stream cancellation never settles;
|
|
53
54
|
a subprocess-mocked DeepSeek smoke test that cannot call unrelated APIs;
|
|
54
|
-
-
|
|
55
|
+
- pi 1.5.2 registry integration using isolated credential/model stores: official
|
|
56
|
+
DeepSeek pi-login and `models.json` auth with an empty chat snapshot, native
|
|
57
|
+
Search/Fetch without a flash id, provider menus/tool exposure, proxy/header
|
|
58
|
+
preservation, login/logout fingerprints, rotation redaction and fallback;
|
|
59
|
+
- strict luna/haiku/flash eligibility for inference-backed routes and numeric newest-version ordering;
|
|
55
60
|
- explicit/current-provider/cache/family ordering without pinning an older model;
|
|
56
61
|
- terminal provider pickers, independent persistent search/fetch choices, Auto,
|
|
57
62
|
cancellation, unavailable choices, and save failures;
|
|
@@ -171,7 +176,9 @@ execution, provider switching, the real DeepSeek API, and cache persistence.
|
|
|
171
176
|
|
|
172
177
|
## CI
|
|
173
178
|
|
|
174
|
-
|
|
179
|
+
**Pi 1.5.2 verified** means type checking and automated tests pass against the
|
|
180
|
+
pinned pi 1.5.2 host dependencies. It does not imply live verification of every
|
|
181
|
+
provider. The GitHub Actions workflow runs on Node 22 and 24:
|
|
175
182
|
|
|
176
183
|
```bash
|
|
177
184
|
npm ci --ignore-scripts
|
package/lib/candidates.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface Candidate {
|
|
|
22
22
|
model: Model<Api>;
|
|
23
23
|
family: ProviderFamily;
|
|
24
24
|
adapter: ProviderAdapter;
|
|
25
|
+
/** Provider-level tools use no inference model and have no model-tier limit. */
|
|
26
|
+
nativeTools?: true;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface ResolutionContext {
|
|
@@ -71,11 +73,12 @@ function modelBrandRank(id: string): number {
|
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
/**
|
|
74
|
-
* A strict allowlist, not a price estimate:
|
|
76
|
+
* A strict allowlist for inference-backed routes, not a price estimate:
|
|
77
|
+
* never fall back to a larger tier. API-only tools invoke no inference model.
|
|
75
78
|
* Classify by model brand, not API family, so gateways follow the same rule.
|
|
76
79
|
*/
|
|
77
80
|
function isLightweightCandidate(candidate: Candidate): boolean {
|
|
78
|
-
if (candidate.adapter.standalone) return true;
|
|
81
|
+
if (candidate.adapter.standalone || candidate.nativeTools) return true;
|
|
79
82
|
const id = normalizedModelId(candidate.model.id);
|
|
80
83
|
const brand = modelBrandRank(id);
|
|
81
84
|
const tier = brand === 1 ? "luna" : brand === 2 ? "haiku" : "flash";
|
|
@@ -160,6 +163,42 @@ function dedicatedCandidate(provider: DedicatedProvider): Candidate {
|
|
|
160
163
|
return { model, family: provider, adapter: provider === "deepseek" ? { ...adapter, standalone: true } : adapter };
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
/** Reuse pi's DeepSeek login even while its chat catalog is empty, filtered,
|
|
167
|
+
* stale, or contains only non-flash ids. Never read/copy pi's credential file. */
|
|
168
|
+
function piDeepSeekToolsCandidate(
|
|
169
|
+
ctx: ExtensionContext,
|
|
170
|
+
nativeCandidates: Candidate[],
|
|
171
|
+
current: Candidate | undefined,
|
|
172
|
+
): Candidate | undefined {
|
|
173
|
+
if (nativeCandidates.some(candidate => candidate.family === "deepseek" && supportsUrls(candidate))) {
|
|
174
|
+
return undefined; // The existing authenticated model route already works.
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const registry = ctx.modelRegistry;
|
|
178
|
+
const provider = registry.getProvider?.("deepseek");
|
|
179
|
+
// Preserve configured native/proxy origins; never borrow another provider's key.
|
|
180
|
+
const baseUrl = provider?.baseUrl
|
|
181
|
+
|| registry.getAll?.().find(model => model.provider === "deepseek" && isChatModel(model))?.baseUrl;
|
|
182
|
+
if (!baseUrl) return undefined;
|
|
183
|
+
const model: Model<Api> = {
|
|
184
|
+
...dedicatedCandidate("deepseek").model,
|
|
185
|
+
id: "pi-search-fetch",
|
|
186
|
+
api: "pi-native-web-search",
|
|
187
|
+
baseUrl,
|
|
188
|
+
};
|
|
189
|
+
const configured = registry.getProviderAuthStatus?.("deepseek").configured
|
|
190
|
+
|| registry.hasConfiguredAuth(model);
|
|
191
|
+
if (!configured) return undefined;
|
|
192
|
+
if (current?.family === "deepseek" && supportsUrls(current) && registry.hasConfiguredAuth(current.model)) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
return { model, family: "deepseek", adapter: getAdapterForFamily("deepseek")!, nativeTools: true };
|
|
196
|
+
} catch {
|
|
197
|
+
// Older registries or failed provider discovery must not break other routes.
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
163
202
|
function availableModels(ctx: ExtensionContext): Model<Api>[] {
|
|
164
203
|
try {
|
|
165
204
|
const models = ctx.modelRegistry.getAvailable();
|
|
@@ -193,12 +232,18 @@ export function resolveResolutionContext(
|
|
|
193
232
|
available.push(candidate);
|
|
194
233
|
}
|
|
195
234
|
|
|
235
|
+
const piDeepSeek = piDeepSeekToolsCandidate(ctx, available, current);
|
|
236
|
+
if (piDeepSeek) available.push(piDeepSeek);
|
|
237
|
+
|
|
196
238
|
const preferences = readProviderPreferences();
|
|
197
239
|
for (const provider of configuredDedicatedProviders(preferences.apis)) {
|
|
198
240
|
available.push(dedicatedCandidate(provider));
|
|
199
241
|
}
|
|
200
242
|
const cache = readCache();
|
|
201
|
-
const fingerprint = fingerprintAvailableModels(ctx, models,
|
|
243
|
+
const fingerprint = fingerprintAvailableModels(ctx, models, [
|
|
244
|
+
...dedicatedFingerprintEntries(preferences.apis),
|
|
245
|
+
...(piDeepSeek ? [`pi-tools:deepseek@${piDeepSeek.model.baseUrl}`] : []),
|
|
246
|
+
]);
|
|
202
247
|
return {
|
|
203
248
|
ctx,
|
|
204
249
|
...(conversationModel ? { currentProvider: conversationModel.provider } : {}),
|
|
@@ -215,7 +260,7 @@ function compareText(left: string, right: string): number {
|
|
|
215
260
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
216
261
|
}
|
|
217
262
|
|
|
218
|
-
/**
|
|
263
|
+
/** Inference-backed routes require lightweight models; newest version wins. */
|
|
219
264
|
export function rankFamilyCandidates(candidates: Candidate[]): Candidate[] {
|
|
220
265
|
return candidates.filter(isLightweightCandidate).sort((left, right) => {
|
|
221
266
|
const standaloneOrder = Number(!!right.adapter.standalone) - Number(!!left.adapter.standalone);
|
package/lib/login-command.ts
CHANGED
|
@@ -6,17 +6,28 @@ import { promptApiKey } from "./secret-input.ts";
|
|
|
6
6
|
|
|
7
7
|
export const LOGIN_COMMAND_NAME = "pi-better-web-search";
|
|
8
8
|
|
|
9
|
+
const COMMAND_HELP = [
|
|
10
|
+
"Usage:",
|
|
11
|
+
`/${LOGIN_COMMAND_NAME} [help] — show all web search commands`,
|
|
12
|
+
`/${LOGIN_COMMAND_NAME} login|logout|status — manage saved API keys`,
|
|
13
|
+
"/web-search-provider search — choose the preferred search provider",
|
|
14
|
+
"/web-search-provider fetch — choose the preferred URL fetch provider",
|
|
15
|
+
"/web-search-api [deepseek|exa|keenable|perplexity] — enable/disable standalone APIs",
|
|
16
|
+
"Search and fetch preferences are independent. Manual preferences are tried first; automatic fallback remains enabled.",
|
|
17
|
+
"Enter keys only in the hidden terminal dialog, never in a command argument.",
|
|
18
|
+
].join("\n");
|
|
19
|
+
|
|
9
20
|
export function registerLoginCommand(
|
|
10
21
|
pi: Pick<ExtensionAPI, "registerCommand">,
|
|
11
22
|
onChanged?: (ctx: ExtensionContext) => void,
|
|
12
23
|
): void {
|
|
13
24
|
pi.registerCommand(LOGIN_COMMAND_NAME, {
|
|
14
|
-
description: "
|
|
25
|
+
description: "Web search help and API login/logout/status; discover provider preferences and API settings",
|
|
15
26
|
handler: async (args, ctx) => {
|
|
16
27
|
const action = args.trim();
|
|
17
28
|
// Never accept an API key as an argument: arguments can enter history.
|
|
18
29
|
if (!["login", "logout", "status"].includes(action)) {
|
|
19
|
-
ctx.ui.notify(
|
|
30
|
+
ctx.ui.notify(COMMAND_HELP, !action || action === "help" ? "info" : "warning");
|
|
20
31
|
return;
|
|
21
32
|
}
|
|
22
33
|
if (!ctx.hasUI || ctx.mode !== "tui" || typeof ctx.ui.custom !== "function") {
|
package/lib/providers/exa.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { dedicatedKey } from "../dedicated-config.ts";
|
|
2
2
|
import { redactSecrets } from "../redact.ts";
|
|
3
3
|
import { dedicatedRequest } from "./dedicated-http.ts";
|
|
4
|
+
import { omitResponseMetadata } from "./response-metadata.ts";
|
|
4
5
|
import type { ProviderAdapter } from "./types.ts";
|
|
5
6
|
|
|
6
7
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -31,7 +32,7 @@ export const exaAdapter: ProviderAdapter = {
|
|
|
31
32
|
body: JSON.stringify({ query, numResults: 10, contents: { highlights: true } }),
|
|
32
33
|
}, signal);
|
|
33
34
|
if (!Array.isArray(data.results)) throw new Error("Exa Search returned no results array");
|
|
34
|
-
return data;
|
|
35
|
+
return omitResponseMetadata(data, ["requestId", "costDollars", "searchTime", "warnings", "resolvedSearchType"]);
|
|
35
36
|
},
|
|
36
37
|
async fetch(_ctx, _model, urls, _query, signal) {
|
|
37
38
|
// Capture the credential before awaiting HTTP; login may rotate it while
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readProviderPreferences } from "../preferences.ts";
|
|
2
2
|
import { dedicatedRequest } from "./dedicated-http.ts";
|
|
3
3
|
import { errorMessage, HttpError, isAbortError } from "./http.ts";
|
|
4
|
+
import { omitResponseMetadata } from "./response-metadata.ts";
|
|
4
5
|
import type { ProviderAdapter, ProviderFetchEntry } from "./types.ts";
|
|
5
6
|
|
|
6
7
|
function endpoint(operation: "search" | "fetch", hasKey: boolean): string {
|
|
@@ -27,7 +28,7 @@ export const keenableAdapter: ProviderAdapter = {
|
|
|
27
28
|
body: JSON.stringify({ query, mode: "pro", max_results: 10 }),
|
|
28
29
|
}, signal);
|
|
29
30
|
if (!Array.isArray(data.results)) throw new Error("Keenable returned no results array");
|
|
30
|
-
return data;
|
|
31
|
+
return omitResponseMetadata(data, ["usage"]);
|
|
31
32
|
},
|
|
32
33
|
async fetch(_ctx, _model, urls, _query, signal) {
|
|
33
34
|
const entries: ProviderFetchEntry[] = [];
|
|
@@ -42,7 +43,7 @@ export const keenableAdapter: ProviderAdapter = {
|
|
|
42
43
|
if (typeof data.content !== "string" || typeof data.url !== "string") {
|
|
43
44
|
entries.push({ url, error: "Keenable returned no URL or page content" });
|
|
44
45
|
} else {
|
|
45
|
-
entries.push({ url, data });
|
|
46
|
+
entries.push({ url, data: omitResponseMetadata(data, ["usage"]) });
|
|
46
47
|
}
|
|
47
48
|
} catch (error) {
|
|
48
49
|
if (isAbortError(error, signal)) throw error;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dedicatedRequest } from "./dedicated-http.ts";
|
|
2
|
+
import { omitResponseMetadata } from "./response-metadata.ts";
|
|
2
3
|
import type { ProviderAdapter } from "./types.ts";
|
|
3
4
|
|
|
4
5
|
/** Raw Search API only. No Agent API, inference model, fetch, or effort setting. */
|
|
@@ -15,6 +16,6 @@ export const perplexityAdapter: ProviderAdapter = {
|
|
|
15
16
|
body: JSON.stringify({ query, search_type: "web", max_results: 10 }),
|
|
16
17
|
}, signal);
|
|
17
18
|
if (!Array.isArray(data.results)) throw new Error("Perplexity Search returned no results array");
|
|
18
|
-
return data;
|
|
19
|
+
return omitResponseMetadata(data, ["id", "server_time"]);
|
|
19
20
|
},
|
|
20
21
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Remove known API bookkeeping only at the response root. Result objects and
|
|
2
|
+
* page content may use the same field names and must remain untouched. */
|
|
3
|
+
export function omitResponseMetadata(
|
|
4
|
+
data: Record<string, unknown>,
|
|
5
|
+
fields: readonly string[],
|
|
6
|
+
): Record<string, unknown> {
|
|
7
|
+
const result = { ...data };
|
|
8
|
+
for (const field of fields) delete result[field];
|
|
9
|
+
return result;
|
|
10
|
+
}
|
package/lib/providers/types.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class QueryLengthError extends Error {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface ProviderSearchResult {
|
|
26
|
-
/** Preserve
|
|
26
|
+
/** Preserve result content and unknown fields, omitting known API bookkeeping. */
|
|
27
27
|
[key: string]: unknown;
|
|
28
28
|
answer?: string;
|
|
29
29
|
results?: unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-better-web-search",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Give pi agents the web: native Keenable, Exa, Perplexity and DeepSeek search APIs, URL fetch, raw results, and automatic provider fallback.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|