pi-web-providers 0.2.0 β†’ 1.0.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.
Files changed (3) hide show
  1. package/README.md +176 -193
  2. package/dist/index.js +5962 -1791
  3. package/package.json +6 -4
package/README.md CHANGED
@@ -1,42 +1,23 @@
1
1
  # 🌍 pi-web-providers
2
2
 
3
- A _meta_ web extension for [pi](https://pi.dev).
3
+ A _meta_ web extension for [pi](https://pi.dev) that routes search, content
4
+ extraction, answers, and research through configurable per-tool providers.
4
5
 
5
6
  ## Why?
6
7
 
7
- Most web extensions hard-wire a single search-and-fetch pipeline. That works
8
- until you want to swap providers, compare results, or use a capabilityβ€”like deep
9
- researchβ€”that only one backend offers.
10
-
11
- **pi-web-providers** takes a different approach: it doesn't do web work itself.
12
- Instead it dispatches every request to a **configurable set of providers**,
13
- giving you maximum flexibility and choice when it comes to consuming web results.
14
-
15
- The tool surface is **capability-based, not static**. At startup the extension
16
- inspects which providers are available and what each one supports, then registers
17
- only the tools that make sense. If your active provider offers search and
18
- content extraction but not deep research, the agent never sees a research tool.
19
- Switch to a provider that supports it and the tool appears automatically.
20
-
21
- The extension also separates **available tools** from the **active tool set**.
22
- When a session starts, it can add every available managed tool. Before each
23
- agent run, it removes tools that are no longer available but keeps any managed
24
- tools that you explicitly removed from the active set disabled. That keeps the
25
- tool prompt aligned with the tools that the agent can actually call.
8
+ Most web extensions hard-wire a single backend. **pi-web-providers** lets you
9
+ mix and match providers per tool instead, so `web_search`, `web_contents`,
10
+ `web_answer`, and `web_research` can each use a different backend or be turned
11
+ off entirely.
26
12
 
27
13
  ## ✨ Features
28
14
 
29
- - **Provider-driven tool surface** β€” tools are injected based on what the active
30
- provider actually supports, not a fixed list
31
- - **Six providers**: Claude, Codex, Exa, Gemini, Parallel, Valyu β€” each with
32
- its own SDK, strengths, and capability set
33
- - **One config command** (`/web-providers`) with a TUI that adapts to the
34
- selected provider
35
- - **Transparent fallback** β€” search falls back to Codex when no provider is
36
- explicitly enabled and the local CLI is installed and authenticated
37
- - **Per-provider tool toggles** β€” disable individual capabilities you don't need
38
- without switching providers
39
- - **Truncated output with temp-file spillover** for large results
15
+ - **Multiple providers** β€” Claude, Codex, Exa, Gemini, Perplexity, Parallel,
16
+ Valyu
17
+ - **Batched search and answers** β€” run several related queries in a single
18
+ `web_search` or `web_answer` call and get grouped results back in one response
19
+ - **Async contents prefetch** β€” optionally start background `web_contents`
20
+ extraction from `web_search` results and reuse the cached pages later
40
21
 
41
22
  ## πŸ“¦ Install
42
23
 
@@ -52,218 +33,220 @@ Run:
52
33
  /web-providers
53
34
  ```
54
35
 
55
- This command edits a single global config file:
56
- `~/.pi/agent/web-providers.json`.
36
+ This edits the global config file `~/.pi/agent/web-providers.json`. The
37
+ settings UI mirrors the three sections below: tools, providers, and generic
38
+ settings.
39
+
40
+ Each tool can be routed to any compatible provider:
57
41
 
58
- The flow is provider-first: pick the active provider, then configure only that
59
- provider's tool toggles and settings. Each provider view surfaces the knobs that
60
- actually applyβ€”Claude shows model/effort/turns settings; Codex shows
61
- reasoning-effort and web-search-mode toggles; Exa shows search type and
62
- text-content flags; and so on.
42
+ | Provider | search | contents | answer | research | Auth |
43
+ | -------------- | :----: | :------: | :----: | :------: | ---------------------- |
44
+ | **Claude** | βœ” | | βœ” | | Local Claude Code auth |
45
+ | **Codex** | βœ” | | | | Local Codex CLI auth |
46
+ | **Exa** | βœ” | βœ” | βœ” | βœ” | `EXA_API_KEY` |
47
+ | **Gemini** | βœ” | | βœ” | βœ” | `GOOGLE_API_KEY` |
48
+ | **Perplexity** | βœ” | | βœ” | βœ” | `PERPLEXITY_API_KEY` |
49
+ | **Parallel** | βœ” | βœ” | | | `PARALLEL_API_KEY` |
50
+ | **Valyu** | βœ” | βœ” | βœ” | βœ” | `VALYU_API_KEY` |
63
51
 
64
- ## πŸ”§ Tools
52
+ See [`example-config.json`](example-config.json) for a full default
53
+ configuration.
65
54
 
66
- Which of the tools below are registered depends on the capabilities of the
67
- available providers. If no provider supports a given capability, the
68
- corresponding tool is never exposed to the agent.
55
+ ### Tools
69
56
 
70
- ### `web_search`
57
+ Each managed tool maps to one provider id or `null` for off under the top-level
58
+ `tools` key. A tool is only exposed when it is mapped to a compatible provider
59
+ and that provider is currently available. Tool-specific settings live under
60
+ `toolSettings`; today this covers `toolSettings.search.prefetch`.
71
61
 
72
- Find likely sources on the public web and return titles, URLs, and snippets.
62
+ #### `web_search`
73
63
 
74
- | Parameter | Type | Default | Description |
75
- | ------------ | ------- | -------- | ----------------------------------------------------------------------------- |
76
- | `query` | string | required | What to search for |
77
- | `maxResults` | integer | `5` | Result count, clamped to `1–20` |
78
- | `provider` | string | auto | Optional override: `claude`, `codex`, `exa`, `gemini`, `parallel`, or `valyu` |
64
+ Find likely sources on the public web for up to 10 queries in a single call
65
+ and return titles, URLs, and snippets grouped by query.
79
66
 
80
- ### `web_contents`
67
+ | Parameter | Type | Default | Description |
68
+ | ------------ | -------- | -------- | -------------------------------------------------------------------- |
69
+ | `queries` | string[] | required | One or more search queries to run (max 10) |
70
+ | `maxResults` | integer | `5` | Result count per query, clamped to `1–20` |
71
+ | `options` | object | β€” | Provider-specific search options plus local `prefetch` orchestration |
72
+
73
+ `web_search.options.prefetch` is local-only and not forwarded into the provider
74
+ SDK. It accepts `provider`, `maxUrls`, `ttlMs`, and `contentsOptions`, and
75
+ starts a background page-extraction workflow only when `prefetch.provider` is
76
+ set. `/web-providers` can also persist default search prefetch settings under
77
+ `toolSettings.search.prefetch`.
78
+
79
+ #### `web_contents`
81
80
 
82
81
  Read and extract the main contents of one or more web pages.
83
82
 
84
- | Parameter | Type | Default | Description |
85
- | ---------- | -------- | -------- | ------------------------------------------------------- |
86
- | `urls` | string[] | required | One or more URLs to extract |
87
- | `options` | object | β€” | Provider-specific extraction options |
88
- | `provider` | string | auto | Optional override among providers that support contents |
83
+ | Parameter | Type | Default | Description |
84
+ | --------- | -------- | -------- | ------------------------------------ |
85
+ | `urls` | string[] | required | One or more URLs to extract |
86
+ | `options` | object | β€” | Provider-specific extraction options |
87
+
88
+ `web_contents` reuses any matching cached pages already present in the local
89
+ content storeβ€”whether they came from prefetch or an earlier readβ€”and only
90
+ fetches missing or stale URLs.
89
91
 
90
- ### `web_answer`
92
+ #### `web_answer`
91
93
 
92
- Answer a question using web-grounded evidence.
94
+ Answer one or more questions using web-grounded evidence.
93
95
 
94
- | Parameter | Type | Default | Description |
95
- | ---------- | ------ | -------- | ------------------------------------------------------ |
96
- | `query` | string | required | Question to answer |
97
- | `options` | object | β€” | Provider-specific answer options |
98
- | `provider` | string | auto | Optional override among providers that support answers |
96
+ | Parameter | Type | Default | Description |
97
+ | --------- | -------- | -------- | ---------------------------------------------------- |
98
+ | `queries` | string[] | required | One or more questions to answer in one call (max 10) |
99
+ | `options` | object | β€” | Provider-specific options |
99
100
 
100
- ### `web_research`
101
+ Responses are grouped into per-question sections when more than one question is provided.
102
+
103
+ #### `web_research`
101
104
 
102
105
  Investigate a topic across web sources and produce a longer report.
103
106
 
104
- | Parameter | Type | Default | Description |
105
- | ---------- | ------ | -------- | ------------------------------------------------------- |
106
- | `input` | string | required | Research brief or question |
107
- | `options` | object | β€” | Provider-specific research options |
108
- | `provider` | string | auto | Optional override among providers that support research |
107
+ | Parameter | Type | Default | Description |
108
+ | --------- | ------ | -------- | -------------------------- |
109
+ | `input` | string | required | Research brief or question |
110
+ | `options` | object | β€” | Provider-specific options |
111
+
112
+ `options` are provider-native and provider-specific. Equivalent concepts can use
113
+ different field names across SDKsβ€”for example Perplexity uses `country`, Exa
114
+ uses `userLocation`, and Valyu uses `countryCode`. Runtime `options` override
115
+ provider-native config, but managed tool inputs and tool wiring stay fixed.
116
+
117
+ <details>
118
+ <summary><strong>Timeout, retry, and delivery modes</strong></summary>
119
+
120
+ The extension accepts local control fields for robustness: `requestTimeoutMs`,
121
+ `retryCount`, and `retryDelayMs` on request/response tools, plus
122
+ `pollIntervalMs`, `timeoutMs`, `maxConsecutivePollErrors`, and `resumeId` on
123
+ `web_research` for lifecycle-based research providers. These fields are handled
124
+ by the extension and are not forwarded into the provider SDK call.
125
+
126
+ - Exa and Valyu research support polling, overall deadlines, and resume IDs
127
+ but reject `requestTimeoutMs` and do not retry non-idempotent job creation.
128
+ - Perplexity research runs in streaming foreground mode and only supports
129
+ `requestTimeoutMs`, `retryCount`, and `retryDelayMs`.
130
+
131
+ Providers deliver results in one of three modes:
109
132
 
110
- ## πŸ”Œ Providers
133
+ - **Silent foreground** β€” no intermediate output; result returned when done.
134
+ - **Streaming foreground** β€” progress updates while running, but the result is
135
+ still only usable after the tool finishes.
136
+ - **Background research** β€” the provider runs in the background; if
137
+ interrupted, the run can be resumed later via `resumeId`.
111
138
 
112
- Every provider is a thin adapter around an official SDK. The table below
113
- summarises which capabilities each provider exposes:
139
+ </details>
114
140
 
115
- | Provider | search | contents | answer | research | Auth |
116
- | ------------ | :----: | :------: | :----: | :------: | ---------------------- |
117
- | **Claude** | βœ“ | | βœ“ | | Local Claude Code auth |
118
- | **Codex** | βœ“ | | | | Local Codex CLI auth |
119
- | **Exa** | βœ“ | βœ“ | βœ“ | βœ“ | `EXA_API_KEY` |
120
- | **Gemini** | βœ“ | | βœ“ | βœ“ | `GOOGLE_API_KEY` |
121
- | **Parallel** | βœ“ | βœ“ | | | `PARALLEL_API_KEY` |
122
- | **Valyu** | βœ“ | βœ“ | βœ“ | βœ“ | `VALYU_API_KEY` |
141
+ ### Providers
123
142
 
124
- ### Claude
143
+ Every provider is a thin adapter around an official SDK. Each provider has an
144
+ `enabled` toggle that controls whether it is eligible for tool mappings.
145
+ Provider config is split into `native` settings (forwarded to the SDK) and
146
+ `policy` settings (local overrides that take precedence over generic settings);
147
+ legacy `defaults` blocks are still accepted when reading. Secret-like values
148
+ can be literal strings, environment variable names (e.g., `EXA_API_KEY`), or
149
+ shell commands prefixed with `!`.
150
+
151
+ <details>
152
+ <summary><strong>Claude</strong></summary>
125
153
 
126
154
  - SDK: `@anthropic-ai/claude-agent-sdk`
127
155
  - Uses Claude Code's built-in `WebSearch` and `WebFetch` tools behind a
128
156
  structured JSON adapter
157
+ - Runs in **silent foreground** mode
158
+ - Supports request-shaping `options` such as `model`, `thinking`, `effort`, and
159
+ `maxTurns`
129
160
  - Great for search plus grounded answers if you already use Claude Code locally
130
161
 
131
- ### Codex
162
+ </details>
163
+
164
+ <details>
165
+ <summary><strong>Codex</strong></summary>
132
166
 
133
167
  - SDK: `@openai/codex-sdk`
134
168
  - Runs in read-only mode with web search enabled
169
+ - Runs in **silent foreground** mode
170
+ - Supports request-shaping `web_search.options` such as `model`,
171
+ `modelReasoningEffort`, and `webSearchMode`
135
172
  - Best if you already use the local Codex CLI and auth flow
136
173
 
137
- ### Exa
174
+ </details>
175
+
176
+ <details>
177
+ <summary><strong>Exa</strong></summary>
138
178
 
139
179
  - SDK: `exa-js`
180
+ - Search, contents, and answer run in **silent foreground** mode
181
+ - Research runs in **background research** mode and supports `resumeId`
140
182
  - Neural, keyword, hybrid, and deep-research search modes
141
183
  - Inline text-content extraction on search results
142
184
 
143
- ### Gemini
185
+ </details>
186
+
187
+ <details>
188
+ <summary><strong>Gemini</strong></summary>
144
189
 
145
190
  - SDK: `@google/genai`
146
- - Grounded answers and deep-research agents via Google's Gemini API
191
+ - Search and answer run in **silent foreground** mode
192
+ - Research runs in **background research** mode and supports `resumeId`
193
+ - Google Search grounding for answers
194
+ - Deep-research agents via Google's Gemini API
195
+ - Supports provider-native request options such as `model`, `config`,
196
+ `generation_config`, and `agent_config` depending on the tool
197
+
198
+ </details>
199
+
200
+ <details>
201
+ <summary><strong>Perplexity</strong></summary>
202
+
203
+ - SDK: `@perplexity-ai/perplexity_ai`
204
+ - `web_search` and `web_answer` run in **silent foreground** mode
205
+ - `web_research` runs in **streaming foreground** mode (no `resumeId` support)
206
+ - Uses Perplexity Search for `web_search`
207
+ - Uses Sonar for `web_answer` and `sonar-deep-research` for `web_research`
208
+ - Supports provider-specific `web_search.options` such as `country`,
209
+ `search_mode`, `search_domain_filter`, and `search_recency_filter`
147
210
 
148
- ### Parallel
211
+ </details>
212
+
213
+ <details>
214
+ <summary><strong>Parallel</strong></summary>
149
215
 
150
216
  - SDK: `parallel-web`
217
+ - Runs in **silent foreground** mode
151
218
  - Agentic and one-shot search modes
152
219
  - Page content extraction with excerpt and full-content toggles
220
+ - Supports provider-native search and extraction options from the Parallel SDK
221
+
222
+ </details>
153
223
 
154
- ### Valyu
224
+ <details>
225
+ <summary><strong>Valyu</strong></summary>
155
226
 
156
227
  - SDK: `valyu-js`
228
+ - Search, contents, and answer run in **silent foreground** mode
229
+ - Research runs in **background research** mode and supports `resumeId`
157
230
  - Web, proprietary, and news search types
231
+ - Supports provider-native options such as `countryCode`, `responseLength`, and
232
+ search/source filters
158
233
  - Configurable response length for answers and research
159
234
 
160
- ## πŸ“ Config Notes
161
-
162
- - `/web-providers` keeps exactly one provider active by writing `enabled: true`
163
- for the selected provider and `enabled: false` for the others
164
- - Each provider can also enable or disable its individual tools through a `tools`
165
- block
166
- - Managed tools are registered from available provider capabilities, but the
167
- active tool set can still be narrower if you removed a tool from the session
168
- - If no provider is explicitly enabled for search, the extension falls back to
169
- Codex when the local CLI is installed and authenticated, unless Codex was
170
- explicitly configured as disabled
171
- - Tools stay inactive when no provider is available for their capability, so
172
- they are not injected into the LLM prompt
173
- - Before each agent run, the extension removes newly unavailable managed tools
174
- and keeps manually pruned managed tools inactive instead of re-adding them
175
- - Secret-like values can be:
176
- - literal strings
177
- - environment variable names such as `EXA_API_KEY`
178
- - shell commands prefixed with `!`
179
-
180
- Example:
181
-
182
- ```json
183
- {
184
- "version": 1,
185
- "providers": {
186
- "claude": {
187
- "enabled": false,
188
- "tools": {
189
- "search": true,
190
- "answer": true
191
- }
192
- },
193
- "codex": {
194
- "enabled": true,
195
- "tools": {
196
- "search": true
197
- },
198
- "defaults": {
199
- "webSearchMode": "live",
200
- "networkAccessEnabled": true
201
- }
202
- },
203
- "exa": {
204
- "enabled": false,
205
- "tools": {
206
- "search": true,
207
- "contents": true,
208
- "answer": true,
209
- "research": true
210
- },
211
- "apiKey": "EXA_API_KEY",
212
- "defaults": {
213
- "type": "auto",
214
- "contents": {
215
- "text": true
216
- }
217
- }
218
- },
219
- "gemini": {
220
- "enabled": false,
221
- "tools": {
222
- "search": true,
223
- "answer": true,
224
- "research": true
225
- },
226
- "apiKey": "GOOGLE_API_KEY",
227
- "defaults": {
228
- "searchModel": "gemini-2.5-flash",
229
- "answerModel": "gemini-2.5-flash",
230
- "researchAgent": "deep-research-pro-preview-12-2025"
231
- }
232
- },
233
- "parallel": {
234
- "enabled": false,
235
- "tools": {
236
- "search": true,
237
- "contents": true
238
- },
239
- "apiKey": "PARALLEL_API_KEY",
240
- "defaults": {
241
- "search": {
242
- "mode": "agentic"
243
- },
244
- "extract": {
245
- "excerpts": true,
246
- "full_content": false
247
- }
248
- }
249
- },
250
- "valyu": {
251
- "enabled": false,
252
- "tools": {
253
- "search": true,
254
- "contents": true,
255
- "answer": true,
256
- "research": true
257
- },
258
- "apiKey": "VALYU_API_KEY",
259
- "defaults": {
260
- "searchType": "all",
261
- "responseLength": "short"
262
- }
263
- }
264
- }
265
- }
266
- ```
235
+ </details>
236
+
237
+ ### Generic settings
238
+
239
+ The `genericSettings` block sets shared execution defaults that apply to all
240
+ providers unless overridden in a provider's `policy` block:
241
+
242
+ | Field | Default | Description |
243
+ | ---------------------------------- | ---------- | ---------------------------------------------- |
244
+ | `requestTimeoutMs` | `30000` | Maximum time for a single provider request |
245
+ | `retryCount` | `3` | Retries for transient failures |
246
+ | `retryDelayMs` | `2000` | Initial delay before retrying |
247
+ | `researchPollIntervalMs` | `3000` | How often to poll long-running research jobs |
248
+ | `researchTimeoutMs` | `21600000` | Overall deadline for research before returning |
249
+ | `researchMaxConsecutivePollErrors` | `3` | Consecutive poll failures before stopping |
267
250
 
268
251
  ## πŸ› οΈ Development
269
252