@yexuan910812/finch-brave-search 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 henryye
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,42 @@
1
+ # Brave Search for Finch
2
+
3
+ 通过 Brave Search API 为 Finch 提供实时网页搜索能力,返回网页标题、摘要与链接。
4
+
5
+ ## 功能
6
+
7
+ - 支持中文与英文搜索
8
+ - 每次返回 1–20 条结果
9
+ - 适用于最新信息检索、资料查找与事实核验
10
+ - API Key 仅通过 Finch 的安全密钥机制读取
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ npx @finchtoys/minitools add @yexuan910812/finch-brave-search
16
+ ```
17
+
18
+ ## 配置
19
+
20
+ 1. 前往 [Brave Search API](https://brave.com/search/api/) 获取 API Key。
21
+ 2. 在 Finch 为此 mini tool 配置 `BRAVE_API_KEY`。
22
+ 3. 如果尚未配置,首次搜索时会出现安全输入表单;输入值仅用于当前调用,不会返回给模型。
23
+
24
+ ## 工具
25
+
26
+ ### `brave_search_web_search`
27
+
28
+ 参数:
29
+
30
+ - `query`:搜索关键词,必填
31
+ - `count`:结果数量,1–20,默认 10
32
+
33
+ ## 权限
34
+
35
+ - `network`:访问 Brave Search API
36
+ - `secrets.BRAVE_API_KEY`:读取用户在 Finch 中安全配置的 API Key
37
+
38
+ 本项目不会把 API Key 写入日志、搜索结果或 npm 发布包。
39
+
40
+ ## License
41
+
42
+ MIT
@@ -0,0 +1,2 @@
1
+ import type * as finch from 'finch';
2
+ export declare function activate(ctx: finch.MiniToolContext): void;
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.activate = activate;
4
+ const BRAVE_SEARCH_API = 'https://api.search.brave.com/res/v1/web/search';
5
+ function activate(ctx) {
6
+ ctx.subscriptions.push(ctx.tools.register({
7
+ name: 'brave_search_web_search',
8
+ title: '网页搜索 (Brave)',
9
+ description: '使用 Brave Search API 搜索互联网。当用户需要最新信息、查找特定资料、验证事实、搜索中文或国际内容时调用。返回标题、摘要和链接。',
10
+ inputSchema: {
11
+ type: 'object',
12
+ properties: {
13
+ query: {
14
+ type: 'string',
15
+ description: '搜索关键词,支持中文和英文。尽量精确以获得更好的结果。',
16
+ },
17
+ count: {
18
+ type: 'number',
19
+ description: '返回结果数量(1-20,默认 10)',
20
+ default: 10,
21
+ },
22
+ },
23
+ required: ['query'],
24
+ },
25
+ risk: 'low',
26
+ defaultEnabled: true,
27
+ async execute(input, exec) {
28
+ const query = String(input.query);
29
+ const count = Math.min(Math.max(Number(input.count) || 10, 1), 20);
30
+ // 获取 API Key
31
+ let apiKey = await exec.secrets.get('BRAVE_API_KEY');
32
+ // 如果没有 Key,弹表单让用户输入
33
+ if (!apiKey) {
34
+ const form = await exec.ui.requestForm({
35
+ title: '配置 Brave Search API',
36
+ description: '首次使用需要设置 Brave Search API Key。前往 https://brave.com/search/api/ 免费获取。',
37
+ fields: [
38
+ {
39
+ key: 'apiKey',
40
+ label: 'API Key',
41
+ type: 'password',
42
+ secret: true,
43
+ placeholder: '输入你的 Brave Search API Key',
44
+ required: true,
45
+ width: '2/3',
46
+ },
47
+ {
48
+ key: 'signup',
49
+ label: '免费获取 API Key',
50
+ type: 'link',
51
+ href: 'https://brave.com/search/api/',
52
+ width: '1/3',
53
+ },
54
+ ],
55
+ submitLabel: '使用并搜索',
56
+ cancelLabel: '取消',
57
+ });
58
+ if (!form.submitted) {
59
+ return {
60
+ content: [{ type: 'text', text: '用户取消了 Brave Search API Key 设置,无法完成搜索。' }],
61
+ isError: true,
62
+ };
63
+ }
64
+ apiKey = String(form.values.apiKey);
65
+ }
66
+ // 发起 Brave Search 请求
67
+ try {
68
+ const url = new URL(BRAVE_SEARCH_API);
69
+ url.searchParams.set('q', query);
70
+ url.searchParams.set('count', String(count));
71
+ const response = await fetch(url.toString(), {
72
+ headers: {
73
+ 'X-Subscription-Token': apiKey,
74
+ 'Accept': 'application/json',
75
+ },
76
+ });
77
+ if (!response.ok) {
78
+ if (response.status === 401 || response.status === 403) {
79
+ return {
80
+ content: [{ type: 'text', text: `Brave Search API 认证失败(${response.status})。请检查 API Key 是否正确,或前往 https://brave.com/search/api/ 重新获取。` }],
81
+ isError: true,
82
+ };
83
+ }
84
+ return {
85
+ content: [{ type: 'text', text: `Brave Search API 请求失败:HTTP ${response.status} ${response.statusText}` }],
86
+ isError: true,
87
+ };
88
+ }
89
+ const data = (await response.json());
90
+ if (!data.web?.results || data.web.results.length === 0) {
91
+ return {
92
+ content: [{ type: 'text', text: `关于"${query}"未找到相关结果。` }],
93
+ };
94
+ }
95
+ // 格式化结果
96
+ const lines = [
97
+ `## 搜索结果 — "${data.query?.original || query}"`,
98
+ '',
99
+ ];
100
+ for (const r of data.web.results) {
101
+ lines.push(`### [${r.title}](${r.url})`);
102
+ lines.push(`${r.description || '(无摘要)'}`);
103
+ lines.push('');
104
+ }
105
+ lines.push(`---\n共 ${data.web.results.length} 条结果`);
106
+ return {
107
+ content: [{ type: 'text', text: lines.join('\n') }],
108
+ };
109
+ }
110
+ catch (err) {
111
+ return {
112
+ content: [{ type: 'text', text: `搜索请求出错:${err instanceof Error ? err.message : String(err)}` }],
113
+ isError: true,
114
+ };
115
+ }
116
+ },
117
+ }));
118
+ ctx.logger.info('Brave Search mini tool activated');
119
+ }
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG,gDAAgD,CAAC;AAiB1E,kBAAyB,GAA0B;IACjD,GAAG,CAAC,aAAa,CAAC,IAAI,CACpB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QACjB,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,0EAA0E;QACvF,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;iBAC3C;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,oBAAoB;oBACjC,OAAO,EAAE,EAAE;iBACZ;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,CAAC;SACpB;QACD,IAAI,EAAE,KAAK;QACX,cAAc,EAAE,IAAI;QACpB,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI;YACvB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAClC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC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KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;oBACjC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;oBACzC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,IAAI,OAAO,EAAE,CAAC,CAAC;oBAC1C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACjB,CAAC;gBAED,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,MAAM,CAAC,CAAC;gBAEpD,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;iBACpD,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;oBAC/F,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CACH,CAAC;IAEF,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;AACtD,CAAC"}
package/icon.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@yexuan910812/finch-brave-search",
3
+ "version": "1.0.0",
4
+ "description": "Brave Search API 网页搜索 mini tool for Finch",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist/",
8
+ "icon.png",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "typecheck": "tsc --noEmit",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "finch",
19
+ "finch-mini-tool",
20
+ "brave-search",
21
+ "web-search",
22
+ "ai-agent"
23
+ ],
24
+ "author": "henryye",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org"
29
+ },
30
+ "finch": {
31
+ "manifestVersion": 1,
32
+ "id": "brave-search",
33
+ "name": "Brave Search",
34
+ "description": "通过 Brave Search API 搜索互联网,获取最新网页结果。",
35
+ "miniToolType": "community",
36
+ "main": "dist/index.js",
37
+ "activationEvents": [
38
+ "onStartup"
39
+ ],
40
+ "contributes": {
41
+ "tools": true
42
+ },
43
+ "permissions": {
44
+ "network": true,
45
+ "secrets": [
46
+ "BRAVE_API_KEY"
47
+ ]
48
+ }
49
+ },
50
+ "devDependencies": {
51
+ "@finchtoys/minitool-api": "^0.1.17",
52
+ "@types/node": "^26.1.1",
53
+ "typescript": "^7.0.2"
54
+ }
55
+ }