@jiangyuan1209/yuan-claw 0.1.3 → 0.1.10

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,194 @@
1
+ 木兰宽松许可证,第2版
2
+
3
+ 木兰宽松许可证,第2版
4
+
5
+ 2020年1月 http://license.coscl.org.cn/MulanPSL2
6
+
7
+ 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
8
+
9
+ 0. 定义
10
+
11
+ “软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
12
+
13
+ “贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
14
+
15
+ “贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
16
+
17
+ “法人实体” 是指提交贡献的机构及其“关联实体”。
18
+
19
+ “关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是
20
+ 指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
21
+
22
+ 1. 授予版权许可
23
+
24
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可
25
+ 以复制、使用、修改、分发其“贡献”,不论修改与否。
26
+
27
+ 2. 授予专利许可
28
+
29
+ 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定
30
+ 撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡
31
+ 献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软
32
+ 件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“
33
+ 关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或
34
+ 其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权
35
+ 行动之日终止。
36
+
37
+ 3. 无商标许可
38
+
39
+ “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定
40
+ 的声明义务而必须使用除外。
41
+
42
+ 4. 分发限制
43
+
44
+ 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“
45
+ 本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
46
+
47
+ 5. 免责声明与责任限制
48
+
49
+ “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对
50
+ 任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于
51
+ 何种法律理论,即使其曾被建议有此种损失的可能性。
52
+
53
+ 6. 语言
54
+
55
+ “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文
56
+ 版为准。
57
+
58
+ 条款结束
59
+
60
+ 如何将木兰宽松许可证,第2版,应用到您的软件
61
+
62
+ 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
63
+
64
+ 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
65
+
66
+ 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
67
+
68
+ 3, 请将如下声明文本放入每个源文件的头部注释中。
69
+
70
+ Copyright (c) [Year] [name of copyright holder]
71
+ [Software Name] is licensed under Mulan PSL v2.
72
+ You can use this software according to the terms and conditions of the Mulan
73
+ PSL v2.
74
+ You may obtain a copy of Mulan PSL v2 at:
75
+ http://license.coscl.org.cn/MulanPSL2
76
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
77
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
78
+ NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
79
+ See the Mulan PSL v2 for more details.
80
+
81
+ Mulan Permissive Software License,Version 2
82
+
83
+ Mulan Permissive Software License,Version 2 (Mulan PSL v2)
84
+
85
+ January 2020 http://license.coscl.org.cn/MulanPSL2
86
+
87
+ Your reproduction, use, modification and distribution of the Software shall
88
+ be subject to Mulan PSL v2 (this License) with the following terms and
89
+ conditions:
90
+
91
+ 0. Definition
92
+
93
+ Software means the program and related documents which are licensed under
94
+ this License and comprise all Contribution(s).
95
+
96
+ Contribution means the copyrightable work licensed by a particular
97
+ Contributor under this License.
98
+
99
+ Contributor means the Individual or Legal Entity who licenses its
100
+ copyrightable work under this License.
101
+
102
+ Legal Entity means the entity making a Contribution and all its
103
+ Affiliates.
104
+
105
+ Affiliates means entities that control, are controlled by, or are under
106
+ common control with the acting entity under this License, ‘control’ means
107
+ direct or indirect ownership of at least fifty percent (50%) of the voting
108
+ power, capital or other securities of controlled or commonly controlled
109
+ entity.
110
+
111
+ 1. Grant of Copyright License
112
+
113
+ Subject to the terms and conditions of this License, each Contributor hereby
114
+ grants to you a perpetual, worldwide, royalty-free, non-exclusive,
115
+ irrevocable copyright license to reproduce, use, modify, or distribute its
116
+ Contribution, with modification or not.
117
+
118
+ 2. Grant of Patent License
119
+
120
+ Subject to the terms and conditions of this License, each Contributor hereby
121
+ grants to you a perpetual, worldwide, royalty-free, non-exclusive,
122
+ irrevocable (except for revocation under this Section) patent license to
123
+ make, have made, use, offer for sale, sell, import or otherwise transfer its
124
+ Contribution, where such patent license is only limited to the patent claims
125
+ owned or controlled by such Contributor now or in future which will be
126
+ necessarily infringed by its Contribution alone, or by combination of the
127
+ Contribution with the Software to which the Contribution was contributed.
128
+ The patent license shall not apply to any modification of the Contribution,
129
+ and any other combination which includes the Contribution. If you or your
130
+ Affiliates directly or indirectly institute patent litigation (including a
131
+ cross claim or counterclaim in a litigation) or other patent enforcement
132
+ activities against any individual or entity by alleging that the Software or
133
+ any Contribution in it infringes patents, then any patent license granted to
134
+ you under this License for the Software shall terminate as of the date such
135
+ litigation or activity is filed or taken.
136
+
137
+ 3. No Trademark License
138
+
139
+ No trademark license is granted to use the trade names, trademarks, service
140
+ marks, or product names of Contributor, except as required to fulfill notice
141
+ requirements in section 4.
142
+
143
+ 4. Distribution Restriction
144
+
145
+ You may distribute the Software in any medium with or without modification,
146
+ whether in source or executable forms, provided that you provide recipients
147
+ with a copy of this License and retain copyright, patent, trademark and
148
+ disclaimer statements in the Software.
149
+
150
+ 5. Disclaimer of Warranty and Limitation of Liability
151
+
152
+ THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY
153
+ KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR
154
+ COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT
155
+ LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING
156
+ FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO
157
+ MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF
158
+ THE POSSIBILITY OF SUCH DAMAGES.
159
+
160
+ 6. Language
161
+
162
+ THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION
163
+ AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF
164
+ DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION
165
+ SHALL PREVAIL.
166
+
167
+ END OF THE TERMS AND CONDITIONS
168
+
169
+ How to Apply the Mulan Permissive Software License,Version 2
170
+ (Mulan PSL v2) to Your Software
171
+
172
+ To apply the Mulan PSL v2 to your work, for easy identification by
173
+ recipients, you are suggested to complete following three steps:
174
+
175
+ i. Fill in the blanks in following statement, including insert your software
176
+ name, the year of the first publication of your software, and your name
177
+ identified as the copyright owner;
178
+
179
+ ii. Create a file named "LICENSE" which contains the whole context of this
180
+ License in the first directory of your software package;
181
+
182
+ iii. Attach the statement to the appropriate annotated syntax at the
183
+ beginning of each source file.
184
+
185
+ Copyright (c) [Year] [name of copyright holder]
186
+ [Software Name] is licensed under Mulan PSL v2.
187
+ You can use this software according to the terms and conditions of the Mulan
188
+ PSL v2.
189
+ You may obtain a copy of Mulan PSL v2 at:
190
+ http://license.coscl.org.cn/MulanPSL2
191
+ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
192
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
193
+ NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
194
+ See the Mulan PSL v2 for more details.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - 🤖 本地命令行智能体
10
10
  - 🧠 基于大模型的任务执行与推理
11
11
  - 🔧 可扩展的工具调用机制
12
- - 🌐 支持 Brave Search 网页搜索
12
+ - 🌐 支持 Baidu Search 网页搜索
13
13
  - 📄 支持 HTTP 抓取与网页正文提取
14
14
  - 💬 支持多轮会话
15
15
  - 🖥️ 支持交互式 REPL
@@ -124,7 +124,7 @@ yuan-claw
124
124
  "MODEL_API_KEY": "your_api_key",
125
125
  "MODEL_BASE_URL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
126
126
  "MODEL_NAME": "qwen3-max-2026-01-23",
127
- "BRAVE_SEARCH_API_KEY": "your_brave_search_api_key",
127
+ "BAIDU_API_KEY": "your_baidu_search_api_key",
128
128
  "HTTP_PROXY": "http://127.0.0.1:33210",
129
129
  "HTTPS_PROXY": "http://127.0.0.1:33210"
130
130
  }
@@ -144,7 +144,7 @@ yuan-claw
144
144
 
145
145
  ```json
146
146
  {
147
- "BRAVE_SEARCH_API_KEY": "your_brave_search_api_key"
147
+ "BAIDU_API_KEY": "your_baidu_search_api_key"
148
148
  }
149
149
  ```
150
150
 
@@ -197,7 +197,7 @@ yuan-claw "帮我搜索 OpenAI 最新消息"
197
197
  - `OPENAI_API_KEY`
198
198
  - `OPENAI_BASE_URL`
199
199
  - `OPENAI_MODEL`
200
- - `BRAVE_SEARCH_API_KEY`
200
+ - `BAIDU_API_KEY`
201
201
  - `HTTP_PROXY`
202
202
  - `HTTPS_PROXY`
203
203
  - `http_proxy`
@@ -222,7 +222,7 @@ yuan-claw "帮我搜索 OpenAI 最新消息"
222
222
  "MODEL_API_KEY": "your_dashscope_api_key",
223
223
  "MODEL_BASE_URL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
224
224
  "MODEL_NAME": "qwen3-max-2026-01-23",
225
- "BRAVE_SEARCH_API_KEY": "your_brave_search_api_key",
225
+ "BAIDU_API_KEY": "your_baidu_search_api_key",
226
226
  "HTTP_PROXY": "http://127.0.0.1:33210",
227
227
  "HTTPS_PROXY": "http://127.0.0.1:33210"
228
228
  }
@@ -230,28 +230,11 @@ yuan-claw "帮我搜索 OpenAI 最新消息"
230
230
 
231
231
  ---
232
232
 
233
- ## Environment Variables(兼容方式)
233
+ ## Environment Variables(已废弃)
234
234
 
235
- 除了 `~/.yuan-claw/settings.json` 外,开发者也可以在项目根目录通过 `.env` 配置:
235
+ 项目已不再通过 `.env` 加载配置,所有配置均通过 `~/.yuan-claw/settings.json` 管理。
236
236
 
237
- ```env
238
- MODEL_API_KEY=
239
- MODEL_BASE_URL=
240
- MODEL_NAME=
241
-
242
- BRAVE_SEARCH_API_KEY=
243
-
244
- HTTP_PROXY=
245
- HTTPS_PROXY=
246
- ```
247
-
248
- 也支持 OpenAI 风格变量名:
249
-
250
- ```env
251
- OPENAI_API_KEY=
252
- OPENAI_BASE_URL=
253
- OPENAI_MODEL=
254
- ```
237
+ 如果你仍习惯使用 `.env`,可以自行在项目中通过 `dotenv` 加载,但不再推荐。
255
238
 
256
239
  > 普通 CLI 用户更推荐使用:
257
240
  >
@@ -362,7 +345,7 @@ npm run start
362
345
 
363
346
  ```json
364
347
  {
365
- "BRAVE_SEARCH_API_KEY": "your_brave_search_api_key"
348
+ "BAIDU_API_KEY": "your_baidu_search_api_key"
366
349
  }
367
350
  ```
368
351
 
@@ -482,6 +465,35 @@ EOF
482
465
 
483
466
  ---
484
467
 
468
+ ## IntelliJ IDEA / WebStorm 插件
469
+
470
+ yuan-claw 提供了 JetBrains IDE 插件,可在 IDE 内一键启动 CLI,无需切换终端。
471
+
472
+ ### 安装
473
+
474
+ 1. 下载插件:`idea-plugin/build/distributions/yuan-claw-plugin-1.0.0.zip`
475
+ (或从 [Releases](https://github.com/your-name/yuan-claw/releases) 获取)
476
+ 2. 打开 IDE → `Settings` → `Plugins` → `⚙️ 齿轮图标` → `Install Plugin from Disk`
477
+ 3. 选择 zip 文件,安装完成后 **重启 IDE**
478
+
479
+ ### 使用
480
+
481
+ - **顶部菜单栏**:`Tools` → `Run Yuan-Claw`
482
+ - **快捷键**:`Ctrl + Alt + Y`(macOS: `⌃⌥Y`)
483
+
484
+ 点击后会在 IDE 底部终端窗口打开一个名为 `yuan-claw` 的标签页,并在项目根目录下自动执行 `yuan-claw` 命令。
485
+
486
+ ### 从源码构建
487
+
488
+ ```bash
489
+ cd idea-plugin
490
+ ./gradlew buildPlugin
491
+ ```
492
+
493
+ 构建产物:`build/distributions/yuan-claw-plugin-1.0.0.zip`
494
+
495
+ ---
496
+
485
497
  ## Scripts
486
498
 
487
499
  ```json
@@ -571,11 +583,9 @@ yuan-claw
571
583
 
572
584
  ### `Missing MODEL_API_KEY / OPENAI_API_KEY in environment variables.`
573
585
 
574
- 说明模型 API Key 尚未正确配置。请至少在以下任一位置填写:
586
+ 说明模型 API Key 尚未正确配置。请在以下位置填写:
575
587
 
576
588
  - `~/.yuan-claw/settings.json`
577
- - 系统环境变量
578
- - 项目根目录 `.env`
579
589
 
580
590
  例如:
581
591
 
@@ -587,13 +597,13 @@ yuan-claw
587
597
 
588
598
  ---
589
599
 
590
- ### `web_search disabled: set BRAVE_SEARCH_API_KEY`
600
+ ### `web_search disabled: set BAIDU_API_KEY`
591
601
 
592
- 说明未配置 Brave Search API Key。请添加:
602
+ 说明未配置百度搜索 API Key。请添加:
593
603
 
594
604
  ```json
595
605
  {
596
- "BRAVE_SEARCH_API_KEY": "your_brave_search_api_key"
606
+ "BAIDU_API_KEY": "your_baidu_search_api_key"
597
607
  }
598
608
  ```
599
609
 
@@ -660,22 +670,7 @@ npm run check
660
670
  npm run dev
661
671
  ```
662
672
 
663
- 如果你使用源码开发方式,也可以在项目根目录创建 `.env` 文件辅助调试。
664
-
665
- ---
666
-
667
- ## Roadmap
668
-
669
- - [ ] 优化 approval 菜单显示体验
670
- - [ ] 增强搜索结果验证能力
671
- - [ ] 优化网页正文提取效果
672
- - [ ] 增加更多内置工具
673
- - [ ] 支持更多模型服务商
674
- - [ ] 完善自动化测试
675
- - [ ] 增加 Docker 部署支持
676
-
677
673
  ---
678
-
679
674
  ## License
680
675
 
681
676
  MIT
@@ -7,8 +7,7 @@ const DEFAULT_SETTINGS = {
7
7
  OPENAI_API_KEY: "",
8
8
  OPENAI_BASE_URL: "",
9
9
  OPENAI_MODEL: "",
10
- BRAVE_SEARCH_API_KEY: "",
11
- BRAVE_API_KEY: "",
10
+ BAIDU_API_KEY: "",
12
11
  HTTP_PROXY: "",
13
12
  HTTPS_PROXY: "",
14
13
  };
@@ -8,8 +8,7 @@ const userSettingsSchema = z.object({
8
8
  OPENAI_API_KEY: z.string().optional(),
9
9
  OPENAI_BASE_URL: z.string().optional(),
10
10
  OPENAI_MODEL: z.string().optional(),
11
- BRAVE_SEARCH_API_KEY: z.string().optional(),
12
- BRAVE_API_KEY: z.string().optional(),
11
+ BAIDU_API_KEY: z.string().optional(),
13
12
  HTTP_PROXY: z.string().optional(),
14
13
  HTTPS_PROXY: z.string().optional(),
15
14
  http_proxy: z.string().optional(),
@@ -13,6 +13,57 @@ export function createOpenAICompatibleClient(options = {}) {
13
13
  });
14
14
  return {
15
15
  async generate(messages) {
16
+ // ============================================================
17
+ // JSON Prompting 模式(当前实现)
18
+ // ============================================================
19
+ // Agent 的"工具调用"完全由 Prompt 驱动:
20
+ // 1. System Prompt 中要求 "输出严格 JSON"
21
+ // 2. 定义协议: {"type":"tool_call","toolName":"xxx","args":{}}
22
+ // 3. 在 runLocalAgentLoop 中用 parseAgentResponse 本地解析
23
+ // 4. 不传 tools 参数,LLM 不知道有哪些工具可用(通过 Prompt 告知)
24
+ //
25
+ // 优势:兼容所有 LLM(包括不支持 Function Calling 的模型)
26
+ // 劣势:依赖 LLM 遵循指令的能力,格式可能出错
27
+ // ============================================================
28
+ // ── 如果是 Function Calling 模式,代码应改为下方注释所示 ──
29
+ // const response = await client.chat.completions.create({
30
+ // model,
31
+ // messages: messages.map((message) => ({
32
+ // role: message.role === "tool" ? "tool" : message.role,
33
+ // content: message.content,
34
+ // tool_call_id: message.toolCallId, // 关联 tool_call 和 result
35
+ // })),
36
+ // tools: [ // ← 声明可用工具
37
+ // {
38
+ // type: "function",
39
+ // function: {
40
+ // name: "read_file",
41
+ // description: "Read a UTF-8 text file",
42
+ // parameters: {
43
+ // type: "object",
44
+ // properties: {
45
+ // path: { type: "string", description: "File path" },
46
+ // },
47
+ // required: ["path"],
48
+ // },
49
+ // },
50
+ // },
51
+ // ],
52
+ // tool_choice: "auto", // ← LLM 自主决定是否调用工具
53
+ // temperature: 0,
54
+ // });
55
+ //
56
+ // const choice = response.choices[0];
57
+ // if (choice.message.tool_calls?.length) {
58
+ // // Function Calling 模式:LLM 返回 tool_calls 结构
59
+ // return JSON.stringify({
60
+ // type: "tool_call",
61
+ // toolName: choice.message.tool_calls[0].function.name,
62
+ // args: JSON.parse(choice.message.tool_calls[0].function.arguments),
63
+ // });
64
+ // }
65
+ // return choice.message.content ?? "";
66
+ // ────────────────────────────────────────────────────────────
16
67
  const response = await client.chat.completions.create({
17
68
  model,
18
69
  messages: messages.map((message) => ({
@@ -5,7 +5,7 @@ import { createGrepTextTool } from "./file/grep-text.js";
5
5
  import { createShellExecTool } from "./shell/shell-exec.js";
6
6
  import { createGitStatusTool } from "./git/git-status.js";
7
7
  import { createGitDiffTool } from "./git/git-diff.js";
8
- import { createHttpFetchTool, createWebSearchTool, createExtractReadableTextTool, createBraveSearchProvider, } from "./web/index.js";
8
+ import { createHttpFetchTool, createWebSearchTool, createExtractReadableTextTool, createBaiduSearchProvider, } from "./web/index.js";
9
9
  export function createToolRegistry(options) {
10
10
  const tools = [
11
11
  createReadFileTool({ workspaceRoot: options.workspaceRoot }),
@@ -19,20 +19,17 @@ export function createToolRegistry(options) {
19
19
  createExtractReadableTextTool(),
20
20
  ];
21
21
  const config = options.config ?? {};
22
- const braveApiKey = config.BRAVE_SEARCH_API_KEY ??
23
- config.BRAVE_API_KEY ??
24
- process.env.BRAVE_SEARCH_API_KEY ??
25
- process.env.BRAVE_API_KEY;
26
- if (braveApiKey) {
22
+ const baiduApiKey = config.BAIDU_API_KEY;
23
+ if (baiduApiKey) {
27
24
  tools.push(createWebSearchTool({
28
- provider: createBraveSearchProvider({
29
- apiKey: braveApiKey,
25
+ provider: createBaiduSearchProvider({
26
+ apiKey: baiduApiKey,
30
27
  }),
31
28
  }));
32
- console.warn("[tools] web_search enabled via Brave Search API");
29
+ console.warn("[tools] web_search enabled via Baidu Search API");
33
30
  }
34
31
  else {
35
- console.warn("[tools] web_search disabled: set BRAVE_SEARCH_API_KEY or BRAVE_API_KEY");
32
+ console.warn("[tools] web_search disabled: set BAIDU_API_KEY in settings.json");
36
33
  }
37
34
  return new Map(tools.map((tool) => [tool.name, tool]));
38
35
  }
@@ -1,4 +1,4 @@
1
1
  export { createHttpFetchTool } from "./http-fetch.js";
2
2
  export { createWebSearchTool } from "./web-search.js";
3
3
  export { createExtractReadableTextTool } from "./extract-readable-text.js";
4
- export { createBraveSearchProvider } from "./search-providers/brave.js";
4
+ export { createBaiduSearchProvider } from "./search-providers/baidu.js";
@@ -0,0 +1,36 @@
1
+ export function createBaiduSearchProvider(options) {
2
+ const baseUrl = options.baseUrl ?? "https://qianfan.baidubce.com/v2/ai_search/web_search";
3
+ return async function baiduSearch(query, count) {
4
+ const response = await fetch(baseUrl, {
5
+ method: "POST",
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ Authorization: `Bearer ${options.apiKey}`,
9
+ "X-Appbuilder-From": "yuan-claw",
10
+ "User-Agent": "Mozilla/5.0 (compatible; XSimpleWebSearch/1.0)",
11
+ },
12
+ body: JSON.stringify({
13
+ messages: [{ content: query, role: "user" }],
14
+ search_source: "baidu_search_v2",
15
+ resource_type_filter: [{ type: "web", top_k: count }],
16
+ }),
17
+ });
18
+ if (!response.ok) {
19
+ const errorText = await response.text().catch(() => "");
20
+ throw new Error(`Baidu search failed: ${response.status} ${response.statusText}${errorText ? ` - ${errorText}` : ""}`);
21
+ }
22
+ const data = (await response.json());
23
+ if (data.code) {
24
+ throw new Error(`Baidu search error: ${data.message ?? data.code}`);
25
+ }
26
+ return (data.references ?? [])
27
+ .slice(0, count)
28
+ .map((item) => ({
29
+ title: item.title ?? "",
30
+ url: item.url ?? "",
31
+ snippet: item.content ?? "",
32
+ source: "baidu",
33
+ }))
34
+ .filter((item) => item.url.trim().length > 0);
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@jiangyuan1209/yuan-claw",
3
- "version": "0.1.3",
3
+ "version": "0.1.10",
4
4
  "description": "A local CLI agent with tools, search, and interactive approval.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "yuan-claw": "./dist/cli/main.js"
8
8
  },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/jiangyuan1209/yuan-claw.git"
12
+ },
9
13
  "files": [
10
14
  "dist",
11
15
  "README.md",
package/.env.example DELETED
@@ -1,28 +0,0 @@
1
- # =========================
2
- # 模型服务配置(推荐)
3
- # =========================
4
-
5
- MODEL_API_KEY=
6
- MODEL_BASE_URL=
7
- MODEL_NAME=
8
-
9
- # =========================
10
- # OpenAI 风格兼容变量(可选)
11
- # =========================
12
-
13
- OPENAI_API_KEY=
14
- OPENAI_BASE_URL=
15
- OPENAI_MODEL=
16
-
17
- # =========================
18
- # 网页搜索配置
19
- # =========================
20
-
21
- BRAVE_SEARCH_API_KEY=
22
-
23
- # =========================
24
- # 代理配置(可选)
25
- # =========================
26
-
27
- HTTP_PROXY=
28
- HTTPS_PROXY=