pi-auto-web-search 0.1.2 → 1.2.1

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ - Cloudflare OAuth 按实例管理凭据和账号绑定;旧授权只迁移到一个实例,存储故障不再阻断其他供应商。
6
+
3
7
  ## 0.1.2
4
8
 
5
9
  - `web-search`、`web-fetch`、`web-map` 不再接受 `instance` 或 `chain`。默认沿用配置顺序;点名供应商时传 `provider`,只在当前链上同供应商的实例间切换。`/search test <实例ID>` 保留。
package/README.md CHANGED
@@ -95,8 +95,9 @@ pi -e .
95
95
  - `proxy`:通过自定义代理转发请求(需填写 `baseUrl`),仍由插件本地做多 Key 轮换与冷却(支持添加或逐条移除多个 Key)。
96
96
  - **`baseUrl` 填写层级**:只需填到域名或反代前缀(例如 `https://proxy.example.com`),不要包含 `/search`、`/extract`、`/responses` 等具体接口路径;结尾的 `/v1`、`/v2`、`/v4` 版本段会自动归一化处理。Cloudflare 可填到 `/client` 或 `/client/v4`。
97
97
  - **凭证与环境变量**:腾讯云元宝搜索采用服务 API KEY 兼容模式(`api.wsa.cloud.tencent.com/SearchPro`,在控制台「概览 > 服务 API KEY 方式」创建 `sk-...` 密钥,推荐使用 `${TENCENTCLOUD_WSA_APIKEY}`)。没有可用凭据的实例会标为“未配置”并跳过。
98
- - **Cloudflare OAuth**:只有启用的 Cloudflare `sdk` 实例在使用 `bearer` 且没有配置静态 `keys` 时才使用 OAuth。静态 key 变量失效不会改用 OAuth。登录只回填这些实例中缺省或留空的 `accountId`;读取配置和测试连接都不回填。
99
- - **Cloudflare 账号**:未绑定账号的 OAuth 实例可使用令牌中的账号。显式账号或变量引用优先;如果账号变量未设置,就只能使用不含 `{accountId}` 的自定义端点。面板会区分“未配置”和“部分可用”,连通性测试使用 Markdown 抓取端点。
98
+ - **Cloudflare OAuth**:只有启用、使用 `bearer` 且没有配置静态 `keys` 的 Cloudflare `sdk` 实例才使用 OAuth;静态凭据失效时不会改用 OAuth。每个实例独立登录、刷新和退出,实例名不能与已有 OAuth 凭据仅大小写不同。读取配置和测试连接不回填账号。
99
+ - **旧版授权**:`search-oauth.json` 只自动迁移给唯一且账号无冲突的合格实例。多个候选时,用 `/search migrate cloudflare <实例>` 指定一个;其他实例需独立登录。已有不同或损坏的目标凭据不会被覆盖。未迁移的授权可用 `/search logout cloudflare @legacy` 撤销。
100
+ - **Cloudflare 账号**:登录只回填当前实例。自动回填的 `accountId` 会随重新登录切号更新;旧配置里没有 `oauthBackfilledAccountId` 标记的字面值和 `${VAR}` 始终按手工绑定处理。在面板手工设置账号会清除标记。未绑定时使用令牌账号;显式账号变量未设置时,只能使用不含 `{accountId}` 的自定义端点。
100
101
  - **按密钥调用次数限额(`keyQuota`)**:支持为任意实例配置 `{ "limit": 2000, "period": "month" }`,周期支持自然周期(`day`、`week`、`month`、`year`)与固定时长(`24h`、`7d`、`30d`、`2w` 等),用量以密钥 SHA-256 指纹持久化在配置同目录的 `search-usage.json`(权限 `0600`)。由于腾讯云元宝搜索属于后付费服务且超出免费额度不会自动停服,`tencent` 实例默认启用单密钥每自然月 `2000` 次硬拦截(可设为 `keyQuota: false` 关闭或在 `/search` 面板修改/校准);单密钥达到上限后自动切换到池内下一把未满密钥,全部用满时直接停止发请求并触发故障切换。
101
102
  - **多进程共用配额**:所有客户端都应升级,共用同一个本地 `search-usage.json`,并为同一密钥设置一致的周期。已有 v1 计数继续有效;同目录的 `search-usage.json.lock.sqlite` 只用于互斥,不保存用量,不要删除。锁竞争最多等待 1 秒,网络请求期间不持锁。请求发送前先持久预占;成功或超时保留计数,明确失败或取消退回。锁或台账不可用时停止请求;本地结算失败不会触发重发。
102
103
  - **核对与校准**:本地台账不是供应商账单。`/search` 的校准和清零只调整当前周期已确认的次数,不释放未结算预占。在途请求按实际结果结算;如果进程在结算前退出,遗留的预占会一直占用名额,直到周期结束。
@@ -181,8 +182,9 @@ pi -e .
181
182
  /search 打开交互式设置面板
182
183
  /search status 查看实例状态以及搜索、抓取顺序
183
184
  /search test [实例] 发起一次连通性测试请求
184
- /search login cloudflare 打开 Cloudflare OAuth 授权登录页面
185
- /search logout cloudflare 撤销并清除本地 Cloudflare OAuth 令牌
185
+ /search login cloudflare [实例] 打开 Cloudflare OAuth 授权登录页面
186
+ /search logout cloudflare [实例] 撤销并清除对应实例的 Cloudflare OAuth 令牌
187
+ /search migrate cloudflare <实例> 将旧版授权迁移到指定实例
186
188
  ```
187
189
 
188
190
  ## 相关文件
@@ -191,7 +193,8 @@ pi -e .
191
193
  | --- | --- |
192
194
  | `~/.pi/agent/search.json` | 默认配置文件 |
193
195
  | `PI_SEARCH_CONFIG` | 覆盖配置文件路径的环境变量 |
194
- | `~/.pi/agent/search-oauth.json` | Cloudflare OAuth 令牌存储文件(权限 `0600`) |
196
+ | `~/.pi/agent/search-oauth/<实例名>+<accountId>.json` | 实例 OAuth 令牌(目录 `0700`、文件 `0600`) |
197
+ | `~/.pi/agent/search-oauth.lock.sqlite` | 多个 pi 进程写入或迁移 OAuth 凭据时使用的锁,不保存令牌 |
195
198
 
196
199
  ## 开发检查
197
200
 
package/README_EN.md CHANGED
@@ -95,8 +95,9 @@ When no configuration file exists yet, the extension includes an anonymous `anys
95
95
  - `proxy`: Routes requests through a custom proxy (`baseUrl` required) while keeping local multi-key rotation and cooldowns (supports adding and removing multiple keys in `/search`).
96
96
  - **`baseUrl` path level**: Provide only the origin or proxy prefix (for example `https://proxy.example.com`) without endpoint paths such as `/search`, `/extract`, or `/responses`; trailing version segments (`/v1`, `/v2`, `/v4`) are normalized automatically. For Cloudflare, point to the origin or `/client` (or `/client/v4`).
97
97
  - **Credentials & environment variables**: Tencent Yuanbao uses the Service API KEY compatibility mode (`api.wsa.cloud.tencent.com/SearchPro`, Bearer `sk-...` key created under Console → Overview → Service API KEY, e.g. `${TENCENTCLOUD_WSA_APIKEY}`). Instances without usable credentials are marked as unconfigured and skipped automatically.
98
- - **Cloudflare OAuth:** Only enabled Cloudflare `sdk` instances with `bearer` auth and no configured static `keys` use OAuth. An unresolved static key never falls back to OAuth. Login fills `accountId` only when omitted or blank on those instances. Reading the configuration and testing connectivity do not fill it.
99
- - **Cloudflare account:** An OAuth instance with no account binding can use the account from its token. An explicit account or variable reference takes precedence. If the variable is unset, only custom endpoints without `{accountId}` are usable. The panel distinguishes unconfigured from partially available instances; connectivity tests use Markdown fetch.
98
+ - **Cloudflare OAuth:** Only enabled Cloudflare `sdk` instances using `bearer` without static `keys` use OAuth. An unresolved static key never falls back to OAuth. Each instance logs in, refreshes, and logs out independently. Instance IDs must not differ from a stored OAuth ID only by case. Reading configuration or testing a connection does not backfill an account.
99
+ - **Legacy authorization:** `search-oauth.json` migrates automatically only to a single eligible instance with no conflicting account. For multiple candidates, choose one with `/search migrate cloudflare <id>`; other instances require separate logins. Existing different or damaged credentials are never overwritten. Use `/search logout cloudflare @legacy` to revoke an unmigrated grant.
100
+ - **Cloudflare account:** Login backfills only the selected instance. An automatically filled `accountId` follows account changes on re-login. Unmarked literals in older configurations and `${VAR}` references remain manual bindings. Setting the account in the panel clears the `oauthBackfilledAccountId` marker. An unbound instance uses the token account; an unset explicit variable permits only custom endpoints without `{accountId}`.
100
101
  - **Per-key call quota (`keyQuota`)**: Any instance can enforce a client-side per-key hard limit via `{ "limit": 2000, "period": "month" }`. Supported periods are calendar cycles (`day`, `week`, `month`, `year`) and fixed durations (`24h`, `7d`, `30d`, `2w`, etc.). Counters are persisted by SHA-256 key fingerprint in `search-usage.json` (mode `0600`) next to `search.json`. Because Tencent Yuanbao Search is postpaid and keeps billing past its free tier, `tencent` enables a default limit of `2000` calls per key per calendar month (set `keyQuota: false` to disable, or adjust/calibrate in `/search`). Exhausted keys are skipped for other keys in the pool; once all keys reach their limit, no upstream request is sent and failover advances to the next provider.
101
102
  - **Shared quotas:** Upgrade every client, use the same local `search-usage.json`, and configure the same period for each shared key. Existing v1 counters remain valid. The private sibling `search-usage.json.lock.sqlite` is a lock file, not a usage database; leave it in place. Lock contention waits at most one second, and no lock is held across a network request. Each request reserves capacity on disk before dispatch. Success and timeout consume it; explicit failure and cancellation refund it. Storage or lock failures stop dispatch, and a local settlement failure never triggers a resend.
102
103
  - **Reconciliation:** The local ledger is not a provider bill. Calibration and reset in `/search` change only the confirmed usage for the current window; they do not release pending reservations. In-flight requests settle normally. If a client exits before settlement, its reservation occupies capacity until the window ends.
@@ -181,8 +182,9 @@ All three tools return `content` (model-facing text), `details` (TUI summary), a
181
182
  /search Open the interactive settings panel
182
183
  /search status Show instance status and search/fetch chains
183
184
  /search test [id] Run a live connectivity test request
184
- /search login cloudflare Open the Cloudflare OAuth login dialog
185
- /search logout cloudflare Revoke and remove the local Cloudflare OAuth token
185
+ /search login cloudflare [id] Open the Cloudflare OAuth login dialog
186
+ /search logout cloudflare [id] Revoke and remove the Cloudflare OAuth token for an instance
187
+ /search migrate cloudflare <id> Move the legacy grant to the specified instance
186
188
  ```
187
189
 
188
190
  ## Files
@@ -191,7 +193,8 @@ All three tools return `content` (model-facing text), `details` (TUI summary), a
191
193
  | --- | --- |
192
194
  | `~/.pi/agent/search.json` | Default search configuration |
193
195
  | `PI_SEARCH_CONFIG` | Overrides the configuration file path |
194
- | `~/.pi/agent/search-oauth.json` | Cloudflare OAuth token store (`0600` permissions) |
196
+ | `~/.pi/agent/search-oauth/<id>+<accountId>.json` | Per-instance OAuth token (`0700` directory, `0600` file) |
197
+ | `~/.pi/agent/search-oauth.lock.sqlite` | Cross-process lock for OAuth writes and migration; contains no tokens |
195
198
 
196
199
  ## Development Checks
197
200
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-auto-web-search",
3
- "version": "0.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "Multi-provider web search and page fetch extension for pi coding agent — failover, key pools, proxy support, and TUI settings",
5
5
  "keywords": [
6
6
  "pi-package",