pi-better-web-search 0.1.9 → 0.1.11

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
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.11
4
+
5
+ - Increase the default timeout to 120 seconds per search and URL fetch attempt
6
+ for all providers. Provider errors still trigger fallback immediately, and
7
+ `PI_BETTER_WEB_SEARCH_TIMEOUT_MS` can override the default.
8
+
9
+ ## 0.1.10
10
+
11
+ - Verify against Pi 1.5.2 and document support for the OpenAI ChatGPT OAuth
12
+ login as well as OpenAI API keys and legacy Codex OAuth.
13
+ - Use the lowest model-supported reasoning effort for OpenAI Responses search,
14
+ independently of the conversation's thinking level, as in pi-web-search.
15
+ - Document that Pi virtual models are not directly supported.
16
+
3
17
  ## 0.1.9
4
18
 
5
19
  - Preserve provider diversity and apply cooldowns before limiting actual search
package/README.md CHANGED
@@ -10,7 +10,7 @@ and returns provider data as-is.
10
10
  [![CI](https://github.com/zhexusun10/pi-better-web-search/actions/workflows/ci.yml/badge.svg)](https://github.com/zhexusun10/pi-better-web-search/actions/workflows/ci.yml)
11
11
  [![npm](https://img.shields.io/npm/v/pi-better-web-search)](https://www.npmjs.com/package/pi-better-web-search)
12
12
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
13
- [![Pi 1.3](https://img.shields.io/badge/Pi-1.3-blue.svg)](https://pi.dev)
13
+ [![Pi 1.5.2](https://img.shields.io/badge/Pi-1.5.2-blue.svg)](https://pi.dev)
14
14
  [![Node](https://img.shields.io/badge/node-%3E%3D22.19-339933.svg)](https://nodejs.org)
15
15
 
16
16
  [简体中文](docs/README.zh-CN.md) · [Architecture](docs/architecture.md) · [Providers](docs/providers.md) · [Testing](docs/testing.md) · [Source](extensions/index.ts)
@@ -29,14 +29,14 @@ Then start a new pi process, or run `/reload` in an existing session.
29
29
  GitHub and local installations also work:
30
30
 
31
31
  ```bash
32
- pi install git:github.com/zhexusun10/pi-better-web-search@v0.1.9
32
+ pi install git:github.com/zhexusun10/pi-better-web-search@v0.1.11
33
33
  pi install ./path/to/pi-better-web-search
34
34
  ```
35
35
 
36
36
  > Do not load this package together with `pi-web-search`. Both register a tool
37
37
  > named `web_search`, and the second registration replaces the first.
38
38
 
39
- Requirements: **pi 1.3+** and **Node.js 22.19+**.
39
+ Requirements: **pi 1.3+** and **Node.js 22.19+**. Tested with **pi 1.5.2**.
40
40
 
41
41
  ## What it fixes
42
42
 
@@ -120,6 +120,12 @@ invalid URLs alongside valid work are reported in the `fetched` entries.
120
120
  | 10 | **xAI (Grok)** | Yes | No | Grok dialect Responses API (`web_search_call.action.sources`) |
121
121
  | * | **Anthropic Messages** | Yes | No | Messages API `web_search_20260209` tool & Claude Code OAuth |
122
122
 
123
+ OpenAI search supports both Pi's **OpenAI (ChatGPT subscription) / Sign in with
124
+ ChatGPT** OAuth login and an OpenAI API key, as well as the separate legacy
125
+ **OpenAI Codex** OAuth login. Model and web search availability still depend
126
+ on the account and service. Pi virtual models (`pi-virtual`) are not directly
127
+ supported; automatic fallback can still use an authenticated concrete model.
128
+
123
129
  URL analysis is only exposed when at least one usable interface supports it.
124
130
  For example, a current OpenAI model with only OpenAI credentials gets a
125
131
  query-only schema, while the same session with DeepSeek, Ollama Cloud, or Google
@@ -173,9 +179,12 @@ remembered compatible provider immediately on later calls.
173
179
 
174
180
  If a provider errors, the extension records the attempt and moves to the next
175
181
  interface. An overlong query rejected by DeepSeek instead returns immediately
176
- without trying another provider or updating its health state. Aborts stop immediately. Each attempt has a timeout (60 seconds by
177
- default, configurable with `PI_BETTER_WEB_SEARCH_TIMEOUT_MS`). If every attempt
178
- fails, the tool returns an error whose message contains the provider errors.
182
+ without trying another provider or updating its health state. Aborts stop
183
+ immediately. Each search or URL fetch attempt times out after 120 seconds by
184
+ default; explicit provider errors trigger fallback immediately without waiting
185
+ for the timeout. Set `PI_BETTER_WEB_SEARCH_TIMEOUT_MS` to override the per-attempt
186
+ timeout. If every attempt fails, the tool returns an error whose message contains
187
+ the provider errors.
179
188
  Provider/model routing remains in `details.attempts`. For a URL-only call, the
180
189
  error also reports the per-URL failures. Provider error bodies and model-facing
181
190
  error text are bounded to prevent an oversized error from filling the context.
@@ -22,14 +22,14 @@ pi install npm:pi-better-web-search
22
22
  也可以从 GitHub 或本地安装:
23
23
 
24
24
  ```bash
25
- pi install git:github.com/zhexusun10/pi-better-web-search@v0.1.9
25
+ pi install git:github.com/zhexusun10/pi-better-web-search@v0.1.11
26
26
  pi install ./path/to/pi-better-web-search
27
27
  ```
28
28
 
29
29
  > 不要和 `pi-web-search` 同时加载。两者都注册 `web_search`,后注册的会覆盖
30
30
  > 先注册的。
31
31
 
32
- 要求:**pi 1.3+**,**Node.js 22.19+**。
32
+ 要求:**pi 1.3+**,**Node.js 22.19+**。已通过 **pi 1.5.2** 依赖测试。
33
33
 
34
34
  ## 它解决什么问题
35
35
 
@@ -101,6 +101,11 @@ provider 都失败时,工具返回错误(`isError: true`),不会静默
101
101
  | 10 | **xAI (Grok)** | 是 | 否 | 原生 Grok 方言 Responses API(`web_search_call.action.sources`) |
102
102
  | * | **Anthropic Messages** | 是 | 否 | Messages API `web_search_20260209` 工具及 Claude Code OAuth 凭据 |
103
103
 
104
+ OpenAI 搜索支持 Pi 的 **OpenAI(ChatGPT 订阅)/ Sign in with ChatGPT**
105
+ OAuth 登录、OpenAI API Key,以及独立的旧版 **OpenAI Codex** OAuth 登录。
106
+ 模型和搜索工具能否使用仍取决于账号及服务。Pi 虚拟模型(`pi-virtual`)
107
+ 暂不直接支持,但可自动回退到其他已认证的具体模型。
108
+
104
109
  只有至少一个可用接口支持 URL 分析时,`urls` 才会暴露。例如:当前模型是
105
110
  OpenAI 且只有 OpenAI 凭据时,schema 只有 `query`;同一会话只要还有
106
111
  DeepSeek、Google Gemini、Antigravity 或 Ollama Cloud 凭据,就会出现 `urls`。
@@ -142,8 +147,9 @@ Provider 识别顺序:
142
147
  的兼容 provider。
143
148
 
144
149
  Provider 报错时记录 attempt 并继续下一个接口。DeepSeek 查询超长则直接返回错误,
145
- 不继续尝试其他 provider,也不记录为 provider 健康故障。取消会立即停止。每次尝试有
146
- 超时(默认 60 秒,`PI_BETTER_WEB_SEARCH_TIMEOUT_MS` 可调)。所有尝试都失败时,
150
+ 不继续尝试其他 provider,也不记录为 provider 健康故障。取消会立即停止。搜索和 URL
151
+ 抓取的每次尝试默认超时 120 秒;provider 直接报错时立即 fallback,不等待超时。
152
+ `PI_BETTER_WEB_SEARCH_TIMEOUT_MS` 可覆盖默认值。所有尝试都失败时,
147
153
  工具返回错误,消息中包含 provider 返回的错误;provider/model 路由信息保留在
148
154
  `details.attempts` 中。URL-only 调用还会报告每个 URL 的失败原因。provider 错误
149
155
  响应体与发给模型的错误文本都有大小限制,避免错误内容占满上下文。
package/docs/providers.md CHANGED
@@ -24,6 +24,9 @@ served by the native DeepSeek provider or Ollama Cloud. In particular, the
24
24
  built-in `opencode-go` DeepSeek models use `openai-completions`; brand ranking
25
25
  does not make them Responses-compatible or expose them as search candidates.
26
26
  A local Ollama daemon is not supported; Ollama Cloud uses the hosted REST API.
27
+ Pi virtual models (`pi-virtual`) are not directly supported: their routed
28
+ concrete model is not known to this extension. The normal fallback can still
29
+ select another authenticated concrete model.
27
30
 
28
31
  ## DeepSeek
29
32
 
@@ -150,9 +153,18 @@ Supported APIs:
150
153
  - `azure-openai-responses`
151
154
  - `openai-codex-responses`
152
155
 
156
+ The `openai` provider uses the Responses API with either pi's **Sign in with
157
+ ChatGPT** OAuth credentials or an OpenAI API key (`OPENAI_API_KEY` or pi's
158
+ registry). Pi resolves and refreshes OAuth credentials; the resulting access
159
+ token is sent as a Bearer token. `openai-codex` uses a separate legacy ChatGPT
160
+ OAuth flow and Codex endpoint. Search availability depends on the account,
161
+ subscription, model and OpenAI service.
162
+
153
163
  The request uses `tools: [{ "type": "web_search" }]`, `stream: true`, and
154
- `store: false`. Endpoint resolution appends `/responses`, or
155
- `/codex/responses` for Codex models. Codex requests add the account id header,
164
+ `store: false`. For reasoning models, the request uses the lowest effort
165
+ supported by the model metadata, independently of the conversation's thinking
166
+ level; native xAI does not send this setting. Endpoint resolution appends
167
+ `/responses`, or `/codex/responses` for Codex models. Codex requests add the account id header,
156
168
  `originator: codex_cli_rs`, instructions, low verbosity, required tool choice,
157
169
  and parallel tool calls.
158
170
 
@@ -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-0.1.9.tgz`. The tarball is not
33
+ This produces `dist/pi-better-web-search-0.1.11.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-0.1.9.tgz --access public
45
+ npm publish dist/pi-better-web-search-0.1.11.tgz --access public
46
46
  ```
47
47
 
48
48
  `prepublishOnly` reruns the checks, tests, and package verification. npm may
@@ -51,10 +51,10 @@ require browser or OTP authentication.
51
51
  ## Tag and release
52
52
 
53
53
  ```bash
54
- git tag -a v0.1.9 -m "v0.1.9"
55
- git push origin v0.1.9
56
- gh release create v0.1.9 dist/pi-better-web-search-0.1.9.tgz \
57
- --title "v0.1.9" \
54
+ git tag -a v0.1.11 -m "v0.1.11"
55
+ git push origin v0.1.11
56
+ gh release create v0.1.11 dist/pi-better-web-search-0.1.11.tgz \
57
+ --title "v0.1.11" \
58
58
  --notes-file /path/to/release-notes.md
59
59
  ```
60
60
 
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import { clampThinkingLevel, type Api, type Model } from "@earendil-works/pi-ai";
3
3
  import {
4
4
  buildRequestHeaders,
5
5
  getHeader,
@@ -152,6 +152,14 @@ async function searchResponses(
152
152
  stream: true,
153
153
  store: false,
154
154
  };
155
+ // Search is independent of the conversation's thinking setting. Use the
156
+ // lowest supported effort to avoid unnecessary latency and token usage.
157
+ // Native xAI does not accept the same reasoning controls.
158
+ if (family !== "xai" && model.reasoning) {
159
+ const level = clampThinkingLevel(model, "off");
160
+ const mapped = model.thinkingLevelMap?.[level];
161
+ if (mapped !== null) body.reasoning = { effort: mapped ?? (level === "off" ? "none" : level) };
162
+ }
155
163
  if (isCodex) {
156
164
  body.instructions = "Answer the user's request using web search when needed.";
157
165
  body.text = { verbosity: "low" };
package/lib/search.ts CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  import { QueryLengthError } from "./providers/types.ts";
32
32
  import { MAX_URLS } from "./schema.ts";
33
33
 
34
- export const DEFAULT_ATTEMPT_TIMEOUT_MS = 60_000;
34
+ export const DEFAULT_ATTEMPT_TIMEOUT_MS = 120_000;
35
35
 
36
36
  export interface UrlValidationError {
37
37
  url: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-web-search",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "A better provider-native web_search tool for pi: raw results, automatic provider fallback, URL analysis, and native DeepSeek Search/Fetch.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,8 +58,8 @@
58
58
  "typebox": "*"
59
59
  },
60
60
  "devDependencies": {
61
- "@earendil-works/pi-ai": "1.3.0",
62
- "@earendil-works/pi-coding-agent": "1.3.0",
61
+ "@earendil-works/pi-ai": "1.5.2",
62
+ "@earendil-works/pi-coding-agent": "1.5.2",
63
63
  "@types/node": "22.19.19",
64
64
  "typebox": "1.3.27",
65
65
  "typescript": "5.9.3"