pi-auto-web-search 0.1.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 +20 -0
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/README_EN.md +195 -0
- package/extensions/web-search.ts +18 -0
- package/package.json +56 -0
- package/src/adapters/anysearch.ts +107 -0
- package/src/adapters/cloudflare.ts +139 -0
- package/src/adapters/deepseek.ts +108 -0
- package/src/adapters/exa.ts +161 -0
- package/src/adapters/firecrawl.ts +202 -0
- package/src/adapters/index.ts +22 -0
- package/src/adapters/tavily.ts +148 -0
- package/src/adapters/tencent.ts +172 -0
- package/src/adapters/types.ts +122 -0
- package/src/adapters/util.ts +93 -0
- package/src/adapters/xai.ts +176 -0
- package/src/base-url.ts +40 -0
- package/src/cloudflare-oauth.ts +551 -0
- package/src/config.ts +547 -0
- package/src/http.ts +777 -0
- package/src/key-pool.ts +144 -0
- package/src/key-quota.ts +532 -0
- package/src/presets.ts +129 -0
- package/src/search-service.ts +411 -0
- package/src/secrets.ts +78 -0
- package/src/settings-ui.ts +1279 -0
- package/src/tools.ts +928 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- 版本号递增,包内容与 0.1.0 相同
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
- 首个版本:`web-search`、`web-fetch` 两个工具与 `/search` 命令
|
|
10
|
+
- 内置八家搜索与抓取供应商:tavily、exa、firecrawl、deepseek、xai、cloudflare、anysearch、tencent,支持直连(sdk)、上游密钥池网关(pool)和自定义代理(proxy)三种接入模式
|
|
11
|
+
- 配置层:JSONC 保留注释、`${VAR}` 插值、默认内置匿名 `anysearch` 兜底(移除后不再兜底)、默认链按优先级排序、显式链完全覆盖
|
|
12
|
+
- 传输层:凭证池与冷却、按密钥调用次数硬限额与周期轮转(持久化在 `search-usage.json`)、并发闸门、超时与取消、错误分类后换链上下一个实例
|
|
13
|
+
- 统一搜索参数与实时策略:`quality`、`sourceMode`、`topic`、`country` 跨供应商映射与降级说明,正文默认按实时抓取,xAI 支持模型配置、实例级 `xSearch` 开关与提示词软约束
|
|
14
|
+
- 结果来源与失败尝试链:成功响应、TUI 摘要与每条搜索结果带出 `providerUsed`,失败响应返回按顺序排列的尝试链与未尝试实例
|
|
15
|
+
- 腾讯云元宝搜索:采用服务 API KEY 兼容模式(`api.wsa.cloud.tencent.com/SearchPro`,`Authorization: Bearer` 鉴权),默认单密钥每自然月 2000 次硬限额保护后付费免费额度;SearchPro 只做搜索,按 10 条或 20 条档位返回
|
|
16
|
+
- Cloudflare OAuth:支持 `/search` TUI 授权登录页面与 `/search login|logout cloudflare` 命令,内置 PKCE、令牌自动刷新、Account ID 回填与撤销,令牌文件权限 `0600`
|
|
17
|
+
- 设置面板:实例列表与状态、新建(留空自动生成随机实例名)、编辑、删除、测试连接,支持 `sdk`/`proxy` 多密钥添加与逐条移除、按密钥调用限额配置与用量校准、xAI 模型配置、各供应商 `baseUrl` 路径层级与专属密钥提示,凭证全程打码
|
|
18
|
+
- web-fetch 支持 html / json / links,schema 由 Firecrawl 与 Cloudflare 兑现
|
|
19
|
+
- web-fetch `format=text` 由 Tavily 走官方 `/extract` 纯文本,其余实例抓 markdown 再本地转换
|
|
20
|
+
- 独立 `web-map` 工具,Tavily `/map` 与 Firecrawl `/v2/map`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 piexian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# pi-auto-web-search
|
|
2
|
+
|
|
3
|
+
[English](./README_EN.md) | 中文
|
|
4
|
+
|
|
5
|
+
面向 pi 编码代理的多供应商联网搜索、网页抓取与站点地图扩展,注册 `web-search`、`web-fetch`、`web-map` 工具与 `/search` 配置命令。
|
|
6
|
+
|
|
7
|
+
支持把多家搜索与抓取服务接成统一入口:请求失败时自动切换到下一个实例,单个实例支持多 Key 轮换与冷却,既可以直连官方 API,也可以接入自建中转或代理。
|
|
8
|
+
|
|
9
|
+
## 核心能力
|
|
10
|
+
|
|
11
|
+
| 能力 | 说明 |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| 统一搜索、抓取与站点地图 | 提供 `web-search`(联网搜索)、`web-fetch`(单页正文提取,支持 Markdown、纯文本、html、json 与 links)和 `web-map`(遍历站点发现 URL) |
|
|
14
|
+
| 多实例自动故障切换 | 按默认优先级或自定义顺序依次尝试,遇到限流、额度不足、超时或服务异常自动切到下一个实例 |
|
|
15
|
+
| 多 Key 轮换与冷却 | 单实例可配置多个 API Key,失败自动冷却并切换,支持按密钥调用次数硬限额与并发控制 |
|
|
16
|
+
| 多种接入方式 | 支持直连官方(`sdk`)、上游密钥池网关(`pool`)和自定义代理转发(`proxy`) |
|
|
17
|
+
| 实时正文策略 | 搜索和抓取正文默认优先获取最新页面内容,避免返回过时缓存 |
|
|
18
|
+
| JSONC 配置与面板 | 使用 `~/.pi/agent/search.json`(保留注释与 `${VAR}` 环境变量),并提供交互式 `/search` TUI 面板 |
|
|
19
|
+
| Cloudflare OAuth | 支持 Cloudflare 授权码 + PKCE 登录、自动刷新与登出撤销,令牌文件权限 `0600` |
|
|
20
|
+
|
|
21
|
+
## 支持的供应商
|
|
22
|
+
|
|
23
|
+
| 供应商 | `preset` 值 | `web-search` | `web-fetch` | `web-map` | 说明 |
|
|
24
|
+
| --- | --- | --- | --- | --- | --- |
|
|
25
|
+
| Exa | `exa` | 支持 | 支持 | 不支持 | 支持搜索质量档位、新闻分类、地区偏好与实时正文提取 |
|
|
26
|
+
| Firecrawl | `firecrawl` | 支持 | 支持 | 支持 | 支持网页与新闻搜索、地区偏好、实时单页抓取与站点地图 |
|
|
27
|
+
| AnySearch | `anysearch` | 支持 | 支持 | 不支持 | 可免 Key 匿名调用,适合快速上手或兜底 |
|
|
28
|
+
| 腾讯云元宝搜索 | `tencent` | 支持 | 不支持 | 不支持 | SearchPro 服务 API KEY(Bearer)模式,默认单密钥每自然月限额 2000 次,支持信源范围(`sourceMode`)与 10/20 条档位 |
|
|
29
|
+
| Tavily | `tavily` | 支持 | 支持 | 支持 | 支持搜索深度、新闻主题、实时正文提取与站点地图 |
|
|
30
|
+
| Cloudflare | `cloudflare` | 支持 | 支持 | 不支持 | Web Search 与 Browser Rendering,支持 API Token 或 OAuth 登录 |
|
|
31
|
+
| DeepSeek | `deepseek` | 支持 | 支持 | 不支持 | 支持官方 Search 与 Fetch 接口 |
|
|
32
|
+
| xAI | `xai` | 支持 | 不支持 | 不支持 | 基于 Responses API `web_search`,实例配置 `xSearch: true` 时固定附加 `x_search` |
|
|
33
|
+
|
|
34
|
+
`web-fetch` 支持输出 `markdown`(默认)、`text`、`html`、`json` 与 `links`;超过 12,000 字符的正文会自动截断并附带提示。
|
|
35
|
+
|
|
36
|
+
## 安装
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pi install npm:pi-auto-web-search
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
或从 GitHub 安装:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pi install git:github.com/piexian/pi-auto-web-search
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
本地开发或临时加载:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pi install ./pi-auto-web-search
|
|
52
|
+
pi -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
运行环境要求 Node.js `>=22.19.0` 和 pi coding agent。
|
|
56
|
+
|
|
57
|
+
## 配置
|
|
58
|
+
|
|
59
|
+
默认配置文件路径为 `~/.pi/agent/search.json`,可通过环境变量 `PI_SEARCH_CONFIG` 指定其他路径。文件按 JSONC 解析,保存时保留注释、BOM 和原有换行符。
|
|
60
|
+
|
|
61
|
+
首次使用且配置文件尚不存在时,插件会默认内置匿名 `anysearch` 实例(`priority: 999`)并直接显示在 `/search` 实例列表中,用于开箱体验和在自配供应商之后兜底;只要你从配置或面板中移除了 `anysearch`,插件就不会再隐式用它兜底。
|
|
62
|
+
|
|
63
|
+
### 最小配置(免 Key 体验)
|
|
64
|
+
|
|
65
|
+
```jsonc
|
|
66
|
+
{
|
|
67
|
+
"instances": [
|
|
68
|
+
{ "id": "anysearch", "preset": "anysearch", "mode": "sdk", "keys": [] }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 多供应商配置示例
|
|
74
|
+
|
|
75
|
+
```jsonc
|
|
76
|
+
{
|
|
77
|
+
"instances": [
|
|
78
|
+
{ "id": "tavily", "preset": "tavily", "mode": "sdk", "keys": ["${TAVILY_API_KEY}"] },
|
|
79
|
+
{ "id": "xai", "preset": "xai", "mode": "sdk", "keys": ["${XAI_API_KEY}"], "model": "grok-4.7" },
|
|
80
|
+
{ "id": "tencent", "preset": "tencent", "mode": "sdk", "keys": ["${TENCENTCLOUD_WSA_APIKEY}"] },
|
|
81
|
+
{
|
|
82
|
+
"id": "cloudflare",
|
|
83
|
+
"preset": "cloudflare",
|
|
84
|
+
"mode": "sdk",
|
|
85
|
+
"keys": ["${CF_API_TOKEN}"],
|
|
86
|
+
"accountId": "${CF_ACCOUNT_ID}"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- **接入模式(`mode`)**:
|
|
93
|
+
- `sdk`:直连供应商官方地址,插件本地负责多 Key 轮换与冷却(支持在 `/search` 面板新建与编辑时添加或逐条移除多个 Key)。
|
|
94
|
+
- `pool`:接入自带 Key 池的上游中转网关(需填写 `baseUrl`),插件侧只发一把网关 Key,轮换交给上游。
|
|
95
|
+
- `proxy`:通过自定义代理转发请求(需填写 `baseUrl`),仍由插件本地做多 Key 轮换与冷却(支持添加或逐条移除多个 Key)。
|
|
96
|
+
- **`baseUrl` 填写层级**:只需填到域名或反代前缀(例如 `https://proxy.example.com`),不要包含 `/search`、`/extract`、`/responses` 等具体接口路径;结尾的 `/v1`、`/v2`、`/v4` 版本段会自动归一化处理。Cloudflare 可填到 `/client` 或 `/client/v4`。
|
|
97
|
+
- **凭证与环境变量**:腾讯云元宝搜索采用服务 API KEY 兼容模式(`api.wsa.cloud.tencent.com/SearchPro`,在控制台「概览 > 服务 API KEY 方式」创建 `sk-...` 密钥,推荐使用 `${TENCENTCLOUD_WSA_APIKEY}`)。当环境变量缺失时,对应实例会被标记为“未配置”并自动跳过,不影响其他实例。
|
|
98
|
+
- **按密钥调用次数限额(`keyQuota`)**:支持为任意实例配置 `{ "limit": 2000, "period": "month" }`,周期支持自然周期(`day`、`week`、`month`、`year`)与固定时长(`24h`、`7d`、`30d`、`2w` 等),用量以密钥 SHA-256 指纹持久化在配置同目录的 `search-usage.json`(权限 `0600`)。由于腾讯云元宝搜索属于后付费服务且超出免费额度不会自动停服,`tencent` 实例默认启用单密钥每自然月 `2000` 次硬拦截(可设为 `keyQuota: false` 关闭或在 `/search` 面板修改/校准);单密钥达到上限后自动切换到池内下一把未满密钥,全部用满时直接停止发请求并触发故障切换。
|
|
99
|
+
- **高级选项**:可通过 `defaultChain` / `fetchChain` 指定搜索与抓取的回退顺序,也可配置 `limits`、`failover`、`priority`、`concurrency`、`cooldownSeconds` 与 `enabled`。xAI 实例支持配置 `model`(默认 `grok-4.7`)以及 `xSearch: true` 固定启用 `x_search`(默认关闭,不受 `quality` 影响)。
|
|
100
|
+
|
|
101
|
+
## 工具说明
|
|
102
|
+
|
|
103
|
+
### `web-search`
|
|
104
|
+
|
|
105
|
+
| 参数 | 说明 |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `query` | 必填,搜索关键词 |
|
|
108
|
+
| `instance` | 指定单个实例 ID,跳过默认回退顺序 |
|
|
109
|
+
| `chain` | 仅本次调用覆盖实例尝试顺序 |
|
|
110
|
+
| `limit` | 结果条数,范围 1–20,默认 10 |
|
|
111
|
+
| `domains` | 仅保留指定域名下的结果 |
|
|
112
|
+
| `excludeDomains` | 排除指定域名下的结果 |
|
|
113
|
+
| `freshness` | 时间范围:`day`、`week`、`month`、`year` |
|
|
114
|
+
| `contents` | 正文返回形式:`none`、`summary`、`markdown` |
|
|
115
|
+
| `answer` | 请求供应商附带整理后的答案(仅部分供应商支持) |
|
|
116
|
+
| `quality` | 搜索深度或推理档位:`basic`(默认)、`advanced`、`deep` |
|
|
117
|
+
| `sourceMode` | 信源范围:`public`、`authoritative`、`mixed`(默认不传) |
|
|
118
|
+
| `topic` | 搜索主题:`general`、`news`(默认不传) |
|
|
119
|
+
| `country` | 地区偏好,ISO 3166-1 alpha-2 两字母代码(如 `US`、`JP`),只影响排序偏置 |
|
|
120
|
+
|
|
121
|
+
#### 跨供应商参数映射
|
|
122
|
+
|
|
123
|
+
- **搜索质量(`quality`)**:
|
|
124
|
+
|
|
125
|
+
| `quality` | Exa `type` | Tavily `search_depth` | xAI `reasoning.effort` |
|
|
126
|
+
| --- | --- | --- | --- |
|
|
127
|
+
| `basic` | `lite` | `basic` | `low` |
|
|
128
|
+
| `advanced` | `auto` | `advanced` | `medium` |
|
|
129
|
+
| `deep` | `deep` | `advanced` | `high` |
|
|
130
|
+
|
|
131
|
+
Firecrawl、DeepSeek、Cloudflare、AnySearch 与腾讯云没有原生质量参数,请求时不发送该字段,在 `advanced` / `deep` 下会在 `notes` 中注明降级。Exa `lite` 不支持同时指定实时正文参数,请求正文时自动按 `auto` 发起并在 `notes` 说明。
|
|
132
|
+
|
|
133
|
+
- **信源范围(`sourceMode`)**:腾讯云映射官方 `Mode`(不传或 `public` → `0` 公开网页、`authoritative` → `1` 权威垂直信源、`mixed` → `2` 混合)。其余供应商无原生字段,照常执行并在 `notes` 说明降级;xAI 将其写入提示词作为软约束,不额外写 `notes`。
|
|
134
|
+
|
|
135
|
+
- **搜索主题(`topic`)**:`general` 与不传等价;`news` 分别映射到 Tavily `topic: "news"`、Exa `category: "news"`、Firecrawl `sources: ["news"]`(解析 `data.news`)以及腾讯云 `Industry: "news"`。DeepSeek、Cloudflare、AnySearch 在 `notes` 说明降级;xAI 走提示词软约束。
|
|
136
|
+
|
|
137
|
+
- **地区偏好(`country`)**:按 ISO 3166-1 alpha-2 校验并统一为大写,非法值直接拒绝且不发请求。原生映射到 Exa `userLocation.country` 与 Firecrawl `country`(两者均为排序偏置,非硬地域过滤);Tavily 仅接受国家全名枚举,不发该字段并在 `notes` 说明降级;DeepSeek、Cloudflare、AnySearch、腾讯云在 `notes` 说明降级;xAI 走提示词软约束。
|
|
138
|
+
|
|
139
|
+
- **实时正文**:正文默认按实时抓取,不对外暴露缓存时长参数。Tavily 固定传 `max_age_hours: 0`;Exa 在请求正文与 `/contents` 时固定传 `contents.maxAgeHours: 0`;Firecrawl 搜索与单页抓取固定传 `maxAge: 0`;xAI 通过提示词要求优先最新来源并传递 `freshness` 时间窗口。
|
|
140
|
+
|
|
141
|
+
### `web-fetch`
|
|
142
|
+
|
|
143
|
+
| 参数 | 说明 |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `url` | 必填,要抓取的 HTTP(S) 地址 |
|
|
146
|
+
| `format` | `markdown`(默认)、`text`、`html`、`json`、`links`。`text` 由 Tavily 原生 `format=text` 兑现,其余实例抓 markdown 再本地转换;`html` / `json` / `links` 仅 Firecrawl 与 Cloudflare 兑现,链上其余实例跳过 |
|
|
147
|
+
| `schema` | JSON 抓取结构;单独出现时当作 `json`。仅 Firecrawl、Cloudflare |
|
|
148
|
+
| `instance` | 指定单个实例 ID,跳过默认抓取顺序 |
|
|
149
|
+
|
|
150
|
+
### `web-map`
|
|
151
|
+
|
|
152
|
+
| 参数 | 说明 |
|
|
153
|
+
| --- | --- |
|
|
154
|
+
| `url` | 必填,要遍历的 HTTP(S) 地址 |
|
|
155
|
+
| `instructions` | 站点地图指引,仅 Tavily 兑现;Firecrawl 跳过并写 notes |
|
|
156
|
+
| `limit` | 返回条数,范围 1–100,默认 50 |
|
|
157
|
+
| `instance` | 指定单个实例 ID,跳过默认顺序 |
|
|
158
|
+
|
|
159
|
+
## 返回格式与失败排查
|
|
160
|
+
|
|
161
|
+
三个工具都返回 `content`(模型可读文本)、`details`(TUI 摘要)和 `structuredContent`(结构化数据):
|
|
162
|
+
|
|
163
|
+
- **成功时**:`structuredContent` 与 `details` 都包含实际响应的 `instance` 与 `providerUsed`,每条搜索结果同样带有这两个字段;`degraded` 标明是否发生过实例切换,`notes` 记录参数降级说明。
|
|
164
|
+
- **失败时**:返回 `isError: true`,文本以“尝试链”按顺序展示每次尝试的实例、供应商与错误分类,`structuredContent` 提供 `error`、`attempts`(`instance`、`provider`、`code`、`status`、`message`)与未尝试的 `unattempted`(`instance`、`provider`)。配置或参数错误不会发出请求,`attempts` 为空;取消请求仅返回“请求已取消”,不计入尝试链。
|
|
165
|
+
|
|
166
|
+
## 命令
|
|
167
|
+
|
|
168
|
+
```text
|
|
169
|
+
/search 打开交互式设置面板
|
|
170
|
+
/search status 查看实例状态以及搜索、抓取顺序
|
|
171
|
+
/search test [实例] 发起一次连通性测试请求
|
|
172
|
+
/search login cloudflare 打开 Cloudflare OAuth 授权登录页面
|
|
173
|
+
/search logout cloudflare 撤销并清除本地 Cloudflare OAuth 令牌
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 相关文件
|
|
177
|
+
|
|
178
|
+
| 路径 / 变量 | 用途 |
|
|
179
|
+
| --- | --- |
|
|
180
|
+
| `~/.pi/agent/search.json` | 默认配置文件 |
|
|
181
|
+
| `PI_SEARCH_CONFIG` | 覆盖配置文件路径的环境变量 |
|
|
182
|
+
| `~/.pi/agent/search-oauth.json` | Cloudflare OAuth 令牌存储文件(权限 `0600`) |
|
|
183
|
+
|
|
184
|
+
## 开发检查
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npm ci
|
|
188
|
+
npm run check
|
|
189
|
+
npm test
|
|
190
|
+
npm run pack:check
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 许可证
|
|
194
|
+
|
|
195
|
+
MIT
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# pi-auto-web-search
|
|
2
|
+
|
|
3
|
+
[中文](./README.md) | English
|
|
4
|
+
|
|
5
|
+
A multi-provider web search, page fetch, and site map extension for the pi coding agent. It registers `web-search`, `web-fetch`, `web-map`, and the `/search` configuration command.
|
|
6
|
+
|
|
7
|
+
Connect multiple search and scraping services behind one interface with automatic instance failover, per-instance API key rotation and cooldowns, and support for direct APIs, upstream key-pool gateways, or custom proxies.
|
|
8
|
+
|
|
9
|
+
## Highlights
|
|
10
|
+
|
|
11
|
+
| Capability | Description |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| Unified search, fetch & map | Provides `web-search` for web queries, `web-fetch` for single-page Markdown, plain text, html, json, or links extraction, and `web-map` to discover URLs on a site |
|
|
14
|
+
| Automatic failover | Tries configured instances in priority or custom order and switches on rate limits, quota errors, timeouts, or server failures |
|
|
15
|
+
| Key rotation & quotas | Supports multiple API keys per instance with failure cooldowns, per-key call quota hard limits, and concurrency limits |
|
|
16
|
+
| Flexible connection modes | Supports direct vendor APIs (`sdk`), upstream key-pool gateways (`pool`), and custom proxies (`proxy`) |
|
|
17
|
+
| Live content by default | Requests fresh page content instead of stale cached copies whenever providers expose freshness controls |
|
|
18
|
+
| JSONC config & TUI panel | Reads `~/.pi/agent/search.json` (preserving comments and `${VAR}` placeholders) with an interactive `/search` settings panel |
|
|
19
|
+
| Cloudflare OAuth | Built-in authorization code + PKCE login, token refresh, and revoke stored with `0600` permissions |
|
|
20
|
+
|
|
21
|
+
## Supported Providers
|
|
22
|
+
|
|
23
|
+
| Provider | `preset` | `web-search` | `web-fetch` | `web-map` | Notes |
|
|
24
|
+
| --- | --- | --- | --- | --- | --- |
|
|
25
|
+
| Exa | `exa` | Yes | Yes | No | Quality tiers, news category, regional bias, and live content extraction |
|
|
26
|
+
| Firecrawl | `firecrawl` | Yes | Yes | Yes | Web and news search, regional bias, live page scraping, and site mapping |
|
|
27
|
+
| AnySearch | `anysearch` | Yes | Yes | No | Works anonymously with no API key; easy zero-config start or fallback |
|
|
28
|
+
| Tencent Yuanbao | `tencent` | Yes | No | No | SearchPro Service API KEY (Bearer) mode, default 2,000 calls/month per-key hard quota, `sourceMode`, and 10/20 result tiers |
|
|
29
|
+
| Tavily | `tavily` | Yes | Yes | Yes | Search depth, news topic, live content extraction, and site mapping |
|
|
30
|
+
| Cloudflare | `cloudflare` | Yes | Yes | No | Web Search and Browser Rendering via API token or OAuth login |
|
|
31
|
+
| DeepSeek | `deepseek` | Yes | Yes | No | Official Search and Fetch endpoints |
|
|
32
|
+
| xAI | `xai` | Yes | No | No | Responses API `web_search`; set `xSearch: true` on an instance to also enable `x_search` |
|
|
33
|
+
|
|
34
|
+
`web-fetch` supports `markdown` (default), `text`, `html`, `json`, and `links`. Responses longer than 12,000 characters are truncated with a marker.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pi install npm:pi-auto-web-search
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or install from GitHub:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pi install git:github.com/piexian/pi-auto-web-search
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For local development or direct loading:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pi install ./pi-auto-web-search
|
|
52
|
+
pi -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Requires Node.js `>=22.19.0` and the pi coding agent.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
The default configuration file is `~/.pi/agent/search.json`. Set `PI_SEARCH_CONFIG` to override its path. It is parsed as JSONC, preserving comments, BOM, and line endings on save.
|
|
60
|
+
|
|
61
|
+
When no configuration file exists yet, the extension includes an anonymous `anysearch` instance (`priority: 999`) by default and shows it directly in `/search`, acting as a fallback after your configured providers. Once you remove `anysearch` from the configuration or settings panel, it is no longer used as a fallback.
|
|
62
|
+
|
|
63
|
+
### Minimal anonymous configuration
|
|
64
|
+
|
|
65
|
+
```jsonc
|
|
66
|
+
{
|
|
67
|
+
"instances": [
|
|
68
|
+
{ "id": "anysearch", "preset": "anysearch", "mode": "sdk", "keys": [] }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Multi-provider example
|
|
74
|
+
|
|
75
|
+
```jsonc
|
|
76
|
+
{
|
|
77
|
+
"instances": [
|
|
78
|
+
{ "id": "tavily", "preset": "tavily", "mode": "sdk", "keys": ["${TAVILY_API_KEY}"] },
|
|
79
|
+
{ "id": "xai", "preset": "xai", "mode": "sdk", "keys": ["${XAI_API_KEY}"], "model": "grok-4.7" },
|
|
80
|
+
{ "id": "tencent", "preset": "tencent", "mode": "sdk", "keys": ["${TENCENTCLOUD_WSA_APIKEY}"] },
|
|
81
|
+
{
|
|
82
|
+
"id": "cloudflare",
|
|
83
|
+
"preset": "cloudflare",
|
|
84
|
+
"mode": "sdk",
|
|
85
|
+
"keys": ["${CF_API_TOKEN}"],
|
|
86
|
+
"accountId": "${CF_ACCOUNT_ID}"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- **Connection modes (`mode`)**:
|
|
93
|
+
- `sdk`: Connects directly to the vendor's official endpoint with local multi-key rotation and cooldowns (supports adding and removing multiple keys in `/search`).
|
|
94
|
+
- `pool`: Connects to an upstream key-pool gateway (`baseUrl` required); the extension sends a single gateway key and delegates rotation upstream.
|
|
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
|
+
- **`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
|
+
- **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 with missing environment variables are marked as unconfigured and skipped automatically.
|
|
98
|
+
- **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.
|
|
99
|
+
- **Advanced options**: Set `defaultChain` and `fetchChain` to customize fallback order, or configure `limits`, `failover`, `priority`, `concurrency`, `cooldownSeconds`, and `enabled`. An xAI instance supports setting `model` (default `grok-4.7`) and `xSearch: true` to always include `x_search` (disabled by default, independent of `quality`).
|
|
100
|
+
|
|
101
|
+
## Tools
|
|
102
|
+
|
|
103
|
+
### `web-search`
|
|
104
|
+
|
|
105
|
+
| Parameter | Description |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| `query` | Required search query |
|
|
108
|
+
| `instance` | Target a single instance ID and bypass the default chain |
|
|
109
|
+
| `chain` | Override the fallback instance order for one call |
|
|
110
|
+
| `limit` | Number of results, 1–20, default `10` |
|
|
111
|
+
| `domains` | Restrict results to these domains |
|
|
112
|
+
| `excludeDomains` | Exclude results from these domains |
|
|
113
|
+
| `freshness` | Time window: `day`, `week`, `month`, `year` |
|
|
114
|
+
| `contents` | Page content mode: `none`, `summary`, `markdown` |
|
|
115
|
+
| `answer` | Ask the provider for a synthesized answer (supported by select providers) |
|
|
116
|
+
| `quality` | Search depth or reasoning tier: `basic` (default), `advanced`, `deep` |
|
|
117
|
+
| `sourceMode` | Source scope: `public`, `authoritative`, `mixed` (unset by default) |
|
|
118
|
+
| `topic` | Search topic: `general`, `news` (unset by default) |
|
|
119
|
+
| `country` | Regional preference as an ISO 3166-1 alpha-2 code (e.g. `US`, `JP`); biases ranking only |
|
|
120
|
+
|
|
121
|
+
#### Cross-provider parameter mapping
|
|
122
|
+
|
|
123
|
+
- **Quality (`quality`)**:
|
|
124
|
+
|
|
125
|
+
| `quality` | Exa `type` | Tavily `search_depth` | xAI `reasoning.effort` |
|
|
126
|
+
| --- | --- | --- | --- |
|
|
127
|
+
| `basic` | `lite` | `basic` | `low` |
|
|
128
|
+
| `advanced` | `auto` | `advanced` | `medium` |
|
|
129
|
+
| `deep` | `deep` | `advanced` | `high` |
|
|
130
|
+
|
|
131
|
+
Firecrawl, DeepSeek, Cloudflare, AnySearch, and Tencent do not expose a native quality parameter; the field is omitted and `advanced`/`deep` requests record a downgrade note in `notes`. Exa `lite` rejects live content parameters, so content requests automatically fall back to `auto` with a note.
|
|
132
|
+
|
|
133
|
+
- **Source scope (`sourceMode`)**: Tencent maps to its official `Mode` (`0` public web when unset or `public`, `1` authoritative vertical sources, `2` mixed). Other providers omit the field and add a downgrade note in `notes`; xAI injects it into the prompt as a soft constraint without adding `notes`.
|
|
134
|
+
|
|
135
|
+
- **Topic (`topic`)**: `general` behaves identically to unset; `news` maps to Tavily `topic: "news"`, Exa `category: "news"`, Firecrawl `sources: ["news"]` (reading `data.news`), and Tencent `Industry: "news"`. DeepSeek, Cloudflare, and AnySearch record a downgrade note; xAI applies a soft prompt constraint.
|
|
136
|
+
|
|
137
|
+
- **Regional preference (`country`)**: Validated as ISO 3166-1 alpha-2 and uppercased; invalid codes are rejected before sending any request. Maps natively to Exa `userLocation.country` and Firecrawl `country` (both bias ranking rather than hard-filtering). Tavily accepts only full country name enums, so the field is omitted with a downgrade note; DeepSeek, Cloudflare, AnySearch, and Tencent record a downgrade note; xAI applies a soft prompt constraint.
|
|
138
|
+
|
|
139
|
+
- **Live content**: Content is fetched live by default and cache age is not exposed as a tool argument. Tavily always sends `max_age_hours: 0`; Exa sends `contents.maxAgeHours: 0` for content and `/contents` calls; Firecrawl sends `maxAge: 0` for search scrapes and single-page scrapes; xAI steers toward current sources and applies `freshness` via prompt instructions.
|
|
140
|
+
|
|
141
|
+
### `web-fetch`
|
|
142
|
+
|
|
143
|
+
| Parameter | Description |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `url` | Required HTTP(S) URL to fetch |
|
|
146
|
+
| `format` | `markdown` (default), `text`, `html`, `json`, `links`. `text` is fulfilled by Tavily's native `format=text`; other instances fetch markdown and convert locally; `html` / `json` / `links` are fulfilled only by Firecrawl and Cloudflare, other instances on the chain are skipped |
|
|
147
|
+
| `schema` | JSON scrape schema; treated as `json` when given alone. Firecrawl and Cloudflare only |
|
|
148
|
+
| `instance` | Target a single instance ID and bypass the default fetch chain |
|
|
149
|
+
|
|
150
|
+
### `web-map`
|
|
151
|
+
|
|
152
|
+
| Parameter | Description |
|
|
153
|
+
| --- | --- |
|
|
154
|
+
| `url` | Required HTTP(S) URL to map |
|
|
155
|
+
| `instructions` | Mapping guidance; Tavily only. Firecrawl skips it and records a note |
|
|
156
|
+
| `limit` | Number of URLs, 1–100, default `50` |
|
|
157
|
+
| `instance` | Target a single instance ID and bypass the default chain |
|
|
158
|
+
|
|
159
|
+
## Output & Failure Diagnostics
|
|
160
|
+
|
|
161
|
+
All three tools return `content` (model-facing text), `details` (TUI summary), and `structuredContent` (typed payload):
|
|
162
|
+
|
|
163
|
+
- **On success**: `structuredContent` and `details` report the actual `instance` and `providerUsed`, and every search result carries both fields. `degraded` indicates that failover occurred; `notes` records parameter downgrades.
|
|
164
|
+
- **On failure**: Returns `isError: true`. The text includes an ordered attempt chain with instance, provider, and error class, while `structuredContent` returns `error`, ordered `attempts` (`instance`, `provider`, `code`, `status`, `message`), and `unattempted` (`instance`, `provider`). Config or parameter validation errors send no network request and keep `attempts` empty; cancelled requests report cancellation only and never appear in the attempt chain.
|
|
165
|
+
|
|
166
|
+
## Commands
|
|
167
|
+
|
|
168
|
+
```text
|
|
169
|
+
/search Open the interactive settings panel
|
|
170
|
+
/search status Show instance status and search/fetch chains
|
|
171
|
+
/search test [id] Run a live connectivity test request
|
|
172
|
+
/search login cloudflare Open the Cloudflare OAuth login dialog
|
|
173
|
+
/search logout cloudflare Revoke and remove the local Cloudflare OAuth token
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Files
|
|
177
|
+
|
|
178
|
+
| Path / Env Var | Purpose |
|
|
179
|
+
| --- | --- |
|
|
180
|
+
| `~/.pi/agent/search.json` | Default search configuration |
|
|
181
|
+
| `PI_SEARCH_CONFIG` | Overrides the configuration file path |
|
|
182
|
+
| `~/.pi/agent/search-oauth.json` | Cloudflare OAuth token store (`0600` permissions) |
|
|
183
|
+
|
|
184
|
+
## Development Checks
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npm ci
|
|
188
|
+
npm run check
|
|
189
|
+
npm test
|
|
190
|
+
npm run pack:check
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
createFetchTool,
|
|
4
|
+
createMapTool,
|
|
5
|
+
createSearchCommand,
|
|
6
|
+
createSearchTool,
|
|
7
|
+
resolveConfigPath,
|
|
8
|
+
SearchRuntime,
|
|
9
|
+
} from "../src/tools.ts";
|
|
10
|
+
|
|
11
|
+
/** 注册 web-search、web-fetch、web-map 与 /search 命令。 */
|
|
12
|
+
export default function (pi: ExtensionAPI) {
|
|
13
|
+
const runtime = new SearchRuntime({ configPath: resolveConfigPath() });
|
|
14
|
+
pi.registerTool(createSearchTool(runtime));
|
|
15
|
+
pi.registerTool(createFetchTool(runtime));
|
|
16
|
+
pi.registerTool(createMapTool(runtime));
|
|
17
|
+
pi.registerCommand("search", createSearchCommand(runtime));
|
|
18
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-auto-web-search",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Multi-provider web search and page fetch extension for pi coding agent — failover, key pools, proxy support, and TUI settings",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"web-search",
|
|
9
|
+
"search"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "piexian (https://github.com/piexian)",
|
|
14
|
+
"homepage": "https://github.com/piexian/pi-auto-web-search#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/piexian/pi-auto-web-search/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/piexian/pi-auto-web-search.git"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"extensions",
|
|
24
|
+
"src",
|
|
25
|
+
"README.md",
|
|
26
|
+
"README_EN.md",
|
|
27
|
+
"CHANGELOG.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.19.0"
|
|
32
|
+
},
|
|
33
|
+
"pi": {
|
|
34
|
+
"extensions": [
|
|
35
|
+
"./extensions"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"check": "tsc --noEmit",
|
|
40
|
+
"test": "node --test tests/*.test.ts",
|
|
41
|
+
"pack:check": "node scripts/pack-check.mjs"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"comment-json": "^4.2.5"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@earendil-works/pi-ai": "*",
|
|
48
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
49
|
+
"@earendil-works/pi-tui": "*",
|
|
50
|
+
"typebox": "*"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^24.0.0",
|
|
54
|
+
"typescript": "^5.6.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ResolvedInstance } from "../config.ts";
|
|
2
|
+
import type { ProviderResponse, RequestSpec } from "../http.ts";
|
|
3
|
+
import type { ExtractOutput, ExtractParams, SearchAdapter, SearchHit, SearchOutput, SearchParams } from "./types.ts";
|
|
4
|
+
import { asArray, asRecord, asString, businessFailure, countryGapNote, markdownOnlyExtract, qualityGapNote, rejectNoMap, rejectUnsupported, sourceModeGapNote, topicGapNote } from "./util.ts";
|
|
5
|
+
|
|
6
|
+
const MAX_RESULTS = 10;
|
|
7
|
+
|
|
8
|
+
function unsupportedParams(params: SearchParams): string[] {
|
|
9
|
+
const names: string[] = [];
|
|
10
|
+
if (params.domains?.length) names.push("domains");
|
|
11
|
+
if (params.excludeDomains?.length) names.push("excludeDomains");
|
|
12
|
+
if (params.freshness) names.push("freshness");
|
|
13
|
+
if (params.answer) names.push("answer");
|
|
14
|
+
return names;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function envelope(response: ProviderResponse): Record<string, unknown> {
|
|
18
|
+
const body = asRecord(response.data);
|
|
19
|
+
if (!body) throw businessFailure(response, "anysearch 响应不是 JSON 对象");
|
|
20
|
+
if (body.code !== 0) {
|
|
21
|
+
const message = asString(body.message) ?? "未知错误";
|
|
22
|
+
throw businessFailure(response, `anysearch 返回 code=${String(body.code)}:${message}`);
|
|
23
|
+
}
|
|
24
|
+
return asRecord(body.data) ?? {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function hitOf(value: unknown, params: SearchParams): SearchHit | undefined {
|
|
28
|
+
const item = asRecord(value);
|
|
29
|
+
if (!item) return undefined;
|
|
30
|
+
const url = asString(item.url);
|
|
31
|
+
if (!url) return undefined;
|
|
32
|
+
|
|
33
|
+
const hit: SearchHit = { title: asString(item.title) ?? url, url };
|
|
34
|
+
const snippet = asString(item.snippet);
|
|
35
|
+
if (snippet) hit.snippet = snippet;
|
|
36
|
+
const content = params.contents === "none" ? undefined : asString(item.content);
|
|
37
|
+
if (content) hit.content = content;
|
|
38
|
+
return hit;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** AnySearch:默认匿名,按信封里的 code 判成败,正文随搜索结果一起返回。 */
|
|
42
|
+
export const anysearchAdapter: SearchAdapter = {
|
|
43
|
+
preset: "anysearch",
|
|
44
|
+
capabilities: { search: true, fetch: true, map: false },
|
|
45
|
+
|
|
46
|
+
unsupported: unsupportedParams,
|
|
47
|
+
|
|
48
|
+
buildSearch(instance: ResolvedInstance, params: SearchParams): RequestSpec {
|
|
49
|
+
rejectUnsupported(instance, "anysearch", unsupportedParams(params));
|
|
50
|
+
const body: Record<string, unknown> = {
|
|
51
|
+
query: params.query,
|
|
52
|
+
max_results: Math.min(params.limit, MAX_RESULTS),
|
|
53
|
+
};
|
|
54
|
+
if (params.contents === "markdown") body.format = "markdown";
|
|
55
|
+
return { instance, path: "search", method: "POST", body };
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
checkSearch(response: ProviderResponse): void {
|
|
59
|
+
const data = envelope(response);
|
|
60
|
+
if (!Array.isArray(data.results)) {
|
|
61
|
+
throw businessFailure(response, "anysearch 响应缺少 results");
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
mapSearch(response: ProviderResponse, params: SearchParams): SearchOutput {
|
|
66
|
+
const data = envelope(response);
|
|
67
|
+
const hits = asArray(data.results)
|
|
68
|
+
.map((item) => hitOf(item, params))
|
|
69
|
+
.filter((hit): hit is SearchHit => hit !== undefined);
|
|
70
|
+
const notes: string[] = [];
|
|
71
|
+
if (params.limit > MAX_RESULTS) notes.push(`anysearch 每次最多 ${MAX_RESULTS} 条,已从 ${params.limit} 条裁剪`);
|
|
72
|
+
const gap = qualityGapNote("anysearch", params.quality);
|
|
73
|
+
if (gap) notes.push(gap);
|
|
74
|
+
if (params.sourceMode) notes.push(sourceModeGapNote("anysearch", params.sourceMode));
|
|
75
|
+
const topicGap = topicGapNote("anysearch", params.topic);
|
|
76
|
+
if (topicGap) notes.push(topicGap);
|
|
77
|
+
const countryGap = countryGapNote("anysearch", params.country);
|
|
78
|
+
if (countryGap) notes.push(countryGap);
|
|
79
|
+
return { hits, notes, rateLimit: response.rateLimit };
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
buildExtract(instance: ResolvedInstance, params: ExtractParams): RequestSpec {
|
|
83
|
+
return { instance, path: "extract", method: "POST", body: { url: params.url } };
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
checkExtract(response: ProviderResponse): void {
|
|
87
|
+
const data = envelope(response);
|
|
88
|
+
if (!asString(data.content)) {
|
|
89
|
+
throw businessFailure(response, "anysearch 提取未返回正文");
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
mapExtract(response: ProviderResponse): ExtractOutput {
|
|
94
|
+
const data = envelope(response);
|
|
95
|
+
return { title: asString(data.title), content: asString(data.content) ?? "" };
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
unsupportedExtract: markdownOnlyExtract,
|
|
99
|
+
|
|
100
|
+
buildMap(instance) {
|
|
101
|
+
rejectNoMap(instance.id, "anysearch");
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
mapSite() {
|
|
105
|
+
rejectNoMap("anysearch", "anysearch");
|
|
106
|
+
},
|
|
107
|
+
};
|