deepfish-ai 1.0.18 → 1.0.20
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/README.md +24 -41
- package/README_CN.md +25 -42
- package/package.json +19 -2
- package/src/AgentRobot/AgentRobotFactory/MainAgentRobot.js +90 -0
- package/src/AgentRobot/AgentRobotFactory/SubAgentRobot.js +50 -0
- package/src/AgentRobot/AgentRobotFactory/SubSkillAgentRobot.js +50 -0
- package/src/AgentRobot/AgentRobotFactory/index.js +48 -0
- package/src/AgentRobot/BaseAgentRobot/Brain.js +209 -0
- package/src/AgentRobot/BaseAgentRobot/BrainEvent.js +17 -0
- package/src/AgentRobot/BaseAgentRobot/Hand.js +119 -0
- package/src/AgentRobot/BaseAgentRobot/Heart.js +0 -0
- package/src/AgentRobot/BaseAgentRobot/Logger.js +108 -0
- package/src/AgentRobot/BaseAgentRobot/ScreenPrinter.js +49 -0
- package/src/AgentRobot/BaseAgentRobot/index.js +324 -0
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/docx.js +708 -0
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/img.js +737 -0
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pdf.js +734 -0
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pptx.js +539 -0
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/xlsx.js +586 -0
- package/src/AgentRobot/BaseAgentRobot/tools/BaseTools.js +12 -0
- package/src/AgentRobot/BaseAgentRobot/tools/CreateAgentTools.js +156 -0
- package/src/AgentRobot/BaseAgentRobot/tools/FileTools.js +675 -0
- package/src/{core/extension/GenerateExtension.js → AgentRobot/BaseAgentRobot/tools/GenerateTools.js} +139 -72
- package/src/{core/extension/InquirerExtension.js → AgentRobot/BaseAgentRobot/tools/InquirerTools.js} +11 -9
- package/src/{core/extension/SystemExtension.js → AgentRobot/BaseAgentRobot/tools/SystemTools.js} +42 -109
- package/src/AgentRobot/BaseAgentRobot/tools/TaskTools.js +210 -0
- package/src/AgentRobot/BaseAgentRobot/tools/TestTools.js +99 -0
- package/src/AgentRobot/BaseAgentRobot/utils/AIRequest.js +241 -0
- package/src/AgentRobot/BaseAgentRobot/utils/AgentTree.js +66 -0
- package/src/AgentRobot/BaseAgentRobot/utils/AttachmentToolScanner.js +234 -0
- package/src/AgentRobot/BaseAgentRobot/utils/MessageCompresser.js +236 -0
- package/src/AgentRobot/BaseAgentRobot/utils/aiConsole.js +74 -0
- package/src/AgentRobot/BaseAgentRobot/utils/aiInquirer.js +78 -0
- package/src/{core → AgentRobot/BaseAgentRobot}/utils/node-root.js +32 -34
- package/src/{core → AgentRobot/BaseAgentRobot}/utils/normal.js +8 -4
- package/src/cli/ConfigManager.js +56 -38
- package/src/cli/DefaultConfig.js +50 -28
- package/src/{core → cli}/GlobalVariable.js +2 -4
- package/src/cli/MemoryManager.js +53 -0
- package/src/cli/SkillConfigManager.js +70 -93
- package/src/cli/SkillParser.js +19 -22
- package/src/cli/ai-config.js +17 -14
- package/src/cli/ai-memory.js +22 -0
- package/src/cli/ai-skill.js +33 -33
- package/src/cli/index.js +45 -39
- package/src/index.js +53 -6
- package/src/cli/ExtConfigManager.js +0 -90
- package/src/cli/HistoryManager.js +0 -293
- package/src/cli/ai-ext.js +0 -36
- package/src/cli/ai-history.js +0 -36
- package/src/core/AICLI.js +0 -98
- package/src/core/ai-services/AiWorker/AIMessageManager.js +0 -173
- package/src/core/ai-services/AiWorker/AiAgent.js +0 -150
- package/src/core/ai-services/AiWorker/AiPrompt.js +0 -141
- package/src/core/ai-services/AiWorker/AiTools.js +0 -368
- package/src/core/ai-services/AiWorker/index.js +0 -180
- package/src/core/ai-services/index.js +0 -39
- package/src/core/extension/BaseExtension.js +0 -9
- package/src/core/extension/ExtensionManager.js +0 -208
- package/src/core/extension/FileExtension.js +0 -438
- package/src/core/extension/TaskExtension.js +0 -169
- package/src/core/extension/TestExtension.js +0 -67
- package/src/core/utils/log.js +0 -157
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ npm link
|
|
|
109
109
|
|
|
110
110
|
```bash
|
|
111
111
|
ai config add # Enter a name, then select deepseek, and enter your DeepSeek API key
|
|
112
|
-
ai use [the_name_you_entered]
|
|
112
|
+
ai config use [the_name_you_entered]
|
|
113
113
|
ai "Help me write an article about future technology in the current directory, output in markdown format"
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -145,13 +145,6 @@ ai config view [name] # View details of the specified AI configuration
|
|
|
145
145
|
ai config edit # Edit the configuration file manually
|
|
146
146
|
ai config dir # Open the configuration file directory
|
|
147
147
|
ai config reset # Reset configuration
|
|
148
|
-
ai config clear # Delete the configuration file
|
|
149
|
-
|
|
150
|
-
# Extension commands
|
|
151
|
-
ai ext add <filename> # Add an extension tool
|
|
152
|
-
ai ext del <filepath> # Remove an extension tool by file path
|
|
153
|
-
ai ext del <index> # Remove an extension tool by index
|
|
154
|
-
ai ext ls # List all extension tools
|
|
155
148
|
|
|
156
149
|
# Skill commands
|
|
157
150
|
ai skill ls # List all registered skills
|
|
@@ -162,11 +155,9 @@ ai skill enable <name|index> # Enable a skill by name or index, exp: ai skill en
|
|
|
162
155
|
ai skill disable <name|index> # Disable a skill by name or index, exp: ai skill disable 1
|
|
163
156
|
ai skill dir # Open the skill directory
|
|
164
157
|
|
|
165
|
-
#
|
|
166
|
-
ai
|
|
167
|
-
ai
|
|
168
|
-
ai history dir # Open the history directory
|
|
169
|
-
ai history reset # Reset all history for all directories
|
|
158
|
+
# Memory commands
|
|
159
|
+
ai memery clear # Clear the history messages for the current directory
|
|
160
|
+
ai memery dir # Open the memory directory
|
|
170
161
|
```
|
|
171
162
|
|
|
172
163
|
### Configuration File Structure
|
|
@@ -174,7 +165,7 @@ ai history reset # Reset all history for all directories
|
|
|
174
165
|
The configuration file (`~/.deepfish-ai/config.js`) has the following structure:
|
|
175
166
|
|
|
176
167
|
```javascript
|
|
177
|
-
|
|
168
|
+
export default {
|
|
178
169
|
ai: [
|
|
179
170
|
{
|
|
180
171
|
name: "default", // AI configuration name
|
|
@@ -182,8 +173,9 @@ module.exports = {
|
|
|
182
173
|
baseUrl: "https://api.deepseek.com", // API base URL
|
|
183
174
|
model: "deepseek-reasoner", // AI model name
|
|
184
175
|
apiKey: "", // API key (required for DeepSeek and OpenAI)
|
|
185
|
-
temperature:
|
|
186
|
-
maxTokens:
|
|
176
|
+
temperature: 0.7, // Response randomness (0-2)
|
|
177
|
+
maxTokens: 8, // Maximum response length (KB)
|
|
178
|
+
maxContextLength: 64, // Maximum context length (KB)
|
|
187
179
|
stream: true, // Enable/disable streaming output
|
|
188
180
|
}
|
|
189
181
|
],
|
|
@@ -191,12 +183,11 @@ module.exports = {
|
|
|
191
183
|
maxIterations: -1, // Maximum iterations for AI to complete the workflow, -1 for unlimited
|
|
192
184
|
maxMessagesLength: 150000, // Maximum compression length, -1 for unlimited
|
|
193
185
|
maxMessagesCount: 100, // Maximum compression count, -1 for unlimited
|
|
194
|
-
|
|
186
|
+
maxMemoryExpireTime: 30, // Maximum session expiration time in days, -1 for unlimited, 0 to disable recording
|
|
195
187
|
maxLogExpireTime: 3, // Log expiration time in days, -1 for unlimited, 0 to disable recording
|
|
196
188
|
maxBlockFileSize: 20, // Maximum block file size in KB; files exceeding this size need to be processed in blocks
|
|
197
|
-
extensions: [], // List of extension file paths
|
|
198
189
|
skills: [], // List of skill configurations
|
|
199
|
-
encoding: "
|
|
190
|
+
encoding: "auto", // Command line encoding format, can be set to utf-8, gbk, etc., or auto/empty for auto-detection
|
|
200
191
|
};
|
|
201
192
|
```
|
|
202
193
|
|
|
@@ -251,7 +242,6 @@ ai "Check disk usage for the current directory"
|
|
|
251
242
|
|
|
252
243
|
```bash
|
|
253
244
|
ai "Create a weather.js extension tool for querying weather"
|
|
254
|
-
ai ext add weather.js
|
|
255
245
|
```
|
|
256
246
|
|
|
257
247
|
**Skill Management:**
|
|
@@ -341,20 +331,13 @@ module.exports = {
|
|
|
341
331
|
|
|
342
332
|
### Registering Extensions
|
|
343
333
|
|
|
344
|
-
**Method 1:
|
|
345
|
-
|
|
346
|
-
```bash
|
|
347
|
-
ai ext add <filename> # ai ext add weather.js
|
|
348
|
-
ai ext add . # Traverse the current directory, automatically scan and add extensions
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
**Method 2: Manual Configuration**
|
|
334
|
+
**Method 1: Manual Configuration**
|
|
352
335
|
|
|
353
336
|
1. ai config edit
|
|
354
337
|
2. Add it to your configuration:
|
|
355
338
|
|
|
356
339
|
```javascript
|
|
357
|
-
|
|
340
|
+
export default {
|
|
358
341
|
// ... other configurations
|
|
359
342
|
extensions: [
|
|
360
343
|
'/path/to/weather-extension.js'
|
|
@@ -362,19 +345,19 @@ module.exports = {
|
|
|
362
345
|
};
|
|
363
346
|
```
|
|
364
347
|
|
|
365
|
-
**Method
|
|
348
|
+
**Method 2: Automatic Scanning**
|
|
366
349
|
|
|
367
350
|
Rules for automatic scanning of extension modules upon program startup:
|
|
368
351
|
|
|
369
352
|
1. Scanning locations:
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
353
|
+
- the DeepFish installation directory (where `deepfish-ai` is located)
|
|
354
|
+
- `node_modules` under the current working directory
|
|
355
|
+
- the current working directory itself
|
|
373
356
|
|
|
374
357
|
2. Scanned files:
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
358
|
+
- scoped packages under `@deepfish-ai/*` in the locations above
|
|
359
|
+
- packages starting with `deepfish-` in the locations above (excluding `deepfish-ai` itself)
|
|
360
|
+
- top-level `.js` / `.mjs` files in the current working directory are scanned additionally; files containing `module.exports`, `descriptions`, and `functions` are treated as auto-loadable extensions
|
|
378
361
|
|
|
379
362
|
## 7. Recommendations
|
|
380
363
|
|
|
@@ -401,12 +384,12 @@ AI always uses paths relative to the current working directory.
|
|
|
401
384
|
|
|
402
385
|
Conversation history is created on a per-directory basis — each execution directory corresponds to its own Agent context. This means that conversations started in different directories are independent of each other.
|
|
403
386
|
|
|
404
|
-
|
|
387
|
+
> **⚠️ Important Note:** AI context is directory-based — each directory corresponds to one context. **Please do not open two command-line dialogs in the same directory**, as this may cause context conflicts and unexpected behavior.
|
|
388
|
+
|
|
389
|
+
Conversation history will be automatically cleared after a configurable period (controlled by the `maxMemoryExpireTime` field in the configuration file, default is 30 days). You can also manage it manually:
|
|
405
390
|
|
|
406
|
-
- `ai
|
|
407
|
-
- `ai
|
|
408
|
-
- `ai history output` — Export the conversation history to the current directory
|
|
409
|
-
- `ai history reset` — Reset all conversation history for all directories
|
|
391
|
+
- `ai memery dir` — Open the memory directory to view stored conversation contexts
|
|
392
|
+
- `ai memery clear` — Manually clear the conversation history for the current directory
|
|
410
393
|
|
|
411
394
|
## 9. Troubleshooting
|
|
412
395
|
|
package/README_CN.md
CHANGED
|
@@ -107,7 +107,7 @@ npm link
|
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
109
|
ai config add # 输入名称, 然后选择deepseek,并输入你的deepseek api key
|
|
110
|
-
ai use 你输入的名称
|
|
110
|
+
ai config use 你输入的名称
|
|
111
111
|
ai ”帮我在当前目录写一篇关于未来科技的文章,用markdown格式输出“
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -143,13 +143,6 @@ ai config view [name] # 查看指定AI配置的详细信息
|
|
|
143
143
|
ai config edit # 编辑配置文件手动编辑配置文件
|
|
144
144
|
ai config dir # 打开配置文件所在目录
|
|
145
145
|
ai config reset # 重置配置
|
|
146
|
-
ai config clear # 删除配置文件
|
|
147
|
-
|
|
148
|
-
# 扩展命令
|
|
149
|
-
ai ext add <filename> # 添加扩展工具
|
|
150
|
-
ai ext del <filepath> # 通过文件路径移除扩展工具
|
|
151
|
-
ai ext del <index> # 通过索引移除扩展工具
|
|
152
|
-
ai ext ls # 列出所有扩展工具
|
|
153
146
|
|
|
154
147
|
# Skill 命令
|
|
155
148
|
ai skill ls # 列出所有已注册的 skill
|
|
@@ -160,11 +153,9 @@ ai skill enable <name|index> # 通过名称或索引启用 skill, exp: ai skill
|
|
|
160
153
|
ai skill disable <name|index> # 通过名称或索引禁用 skill, exp: ai skill disable 1
|
|
161
154
|
ai skill dir # 打开 skill 目录
|
|
162
155
|
|
|
163
|
-
#
|
|
164
|
-
ai
|
|
165
|
-
ai
|
|
166
|
-
ai history dir # 打开历史记录目录
|
|
167
|
-
ai history reset # 清除所有目录的对话历史
|
|
156
|
+
# 记忆命令
|
|
157
|
+
ai memery clear # 清除当前目录的对话历史
|
|
158
|
+
ai memery dir # 打开记忆目录
|
|
168
159
|
```
|
|
169
160
|
|
|
170
161
|
### 配置文件结构
|
|
@@ -172,7 +163,7 @@ ai history reset # 清除所有目录的对话历史
|
|
|
172
163
|
配置文件 (`~/.deepfish-ai/config.js`) 具有以下结构:
|
|
173
164
|
|
|
174
165
|
```javascript
|
|
175
|
-
|
|
166
|
+
export default {
|
|
176
167
|
ai: [
|
|
177
168
|
{
|
|
178
169
|
name: "default", // AI配置名称
|
|
@@ -180,8 +171,9 @@ module.exports = {
|
|
|
180
171
|
baseUrl: "https://api.deepseek.com", // API基础URL
|
|
181
172
|
model: "deepseek-reasoner", // AI模型名称
|
|
182
173
|
apiKey: "", // API密钥(DeepSeek和OpenAI需要)
|
|
183
|
-
temperature:
|
|
184
|
-
maxTokens:
|
|
174
|
+
temperature: 0.7, // 响应随机性(0-2)
|
|
175
|
+
maxTokens: 8, // 最大响应长度(KB)
|
|
176
|
+
maxContextLength: 64, // 最大上下文长度(KB)
|
|
185
177
|
stream: true, // 启用/禁用流式输出
|
|
186
178
|
}
|
|
187
179
|
],
|
|
@@ -189,12 +181,11 @@ module.exports = {
|
|
|
189
181
|
maxIterations: -1, // ai完成工作流的最大迭代次数,-1表示无限制
|
|
190
182
|
maxMessagesLength: 150000, // 最大压缩长度,-1表示无限制
|
|
191
183
|
maxMessagesCount: 100, // 最大压缩数量,-1表示无限制
|
|
192
|
-
|
|
184
|
+
maxMemoryExpireTime: 30, // 整个会话的最大过期时间,单位天,-1表示无限制,0表示不记录
|
|
193
185
|
maxLogExpireTime: 3, // 日志过期时间,单位天,-1表示无限制,0表示不记录
|
|
194
186
|
maxBlockFileSize: 20, // 最大分块文件大小,单位KB;超过该大小的文件需要分块处理
|
|
195
|
-
extensions: [], // 扩展文件路径列表
|
|
196
187
|
skills: [], // 技能配置列表
|
|
197
|
-
encoding: "
|
|
188
|
+
encoding: "auto", // 命令行编码格式,可设置为utf-8、gbk等,也可以设置成auto或空值自动判断
|
|
198
189
|
};
|
|
199
190
|
```
|
|
200
191
|
|
|
@@ -249,7 +240,6 @@ ai "检查当前目录的磁盘使用情况"
|
|
|
249
240
|
|
|
250
241
|
```bash
|
|
251
242
|
ai "创建一个用于查询天气的扩展工具weather.js"
|
|
252
|
-
ai ext add weather.js
|
|
253
243
|
```
|
|
254
244
|
|
|
255
245
|
**Skill 管理:**
|
|
@@ -339,20 +329,13 @@ module.exports = {
|
|
|
339
329
|
|
|
340
330
|
### 注册扩展
|
|
341
331
|
|
|
342
|
-
**方法1
|
|
343
|
-
|
|
344
|
-
```bash
|
|
345
|
-
ai ext add <filename> # ai ext add weather.js
|
|
346
|
-
ai ext add . # 遍历当前目录,自动扫描并添加扩展
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
**方法2:手动配置**
|
|
332
|
+
**方法1:手动配置**
|
|
350
333
|
|
|
351
334
|
1. ai config edit
|
|
352
335
|
2. 将其添加到您的配置中:
|
|
353
336
|
|
|
354
337
|
```javascript
|
|
355
|
-
|
|
338
|
+
export default {
|
|
356
339
|
// ... 其他配置
|
|
357
340
|
extensions: [
|
|
358
341
|
'/path/to/weather-extension.js'
|
|
@@ -360,17 +343,17 @@ module.exports = {
|
|
|
360
343
|
};
|
|
361
344
|
```
|
|
362
345
|
|
|
363
|
-
**方法
|
|
346
|
+
**方法2:自动扫描**
|
|
364
347
|
|
|
365
348
|
程序启动时自动扫描扩展模块的规则:
|
|
366
349
|
1. 扫描位置:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
350
|
+
- 程序安装目录(deepfish-ai 程序所在目录)
|
|
351
|
+
- 当前工作目录的 node_modules 目录
|
|
352
|
+
- 当前工作目录
|
|
370
353
|
2. 扫描文件:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
354
|
+
- 在以上目录中扫描 `@deepfish-ai/*` 作用域包
|
|
355
|
+
- 在以上目录中扫描 `deepfish-` 开头的包(排除 `deepfish-ai` 本体)
|
|
356
|
+
- 在当前工作目录额外扫描顶层 `.js` / `.mjs` 文件, 文件内容包含 `module.exports`、`descriptions`、`functions` 字符串时视为可自动加载扩展
|
|
374
357
|
|
|
375
358
|
## 7. 建议
|
|
376
359
|
|
|
@@ -395,14 +378,14 @@ AI始终使用相对于当前工作目录的相对路径。
|
|
|
395
378
|
|
|
396
379
|
### 对话历史
|
|
397
380
|
|
|
398
|
-
对话历史是以程序执行目录为单位创建的,每个程序的执行目录会对应一个独立的 Agent 上下文。这意味着在不同目录下启动的对话是相互独立的。
|
|
381
|
+
对话历史是以程序执行目录为单位创建的,每个程序的执行目录会对应一个独立的 Agent 上下文。这意味着在不同目录下启动的对话是相互独立的。
|
|
382
|
+
|
|
383
|
+
> **⚠️ 重要提示:** AI上下文是以目录为单位的,一个目录对应一个上下文。**请不要在同一个目录下开启两个命令行对话框**,以免造成上下文冲突和意外行为。
|
|
399
384
|
|
|
400
|
-
对话历史会在一定时间内自动清除(通过配置文件中的 `
|
|
385
|
+
对话历史会在一定时间内自动清除(通过配置文件中的 `maxMemoryExpireTime` 字段控制,默认为 30 天)。您也可以手动管理对话历史:
|
|
401
386
|
|
|
402
|
-
- `ai
|
|
403
|
-
- `ai
|
|
404
|
-
- `ai history output` — 将对话历史导出到当前目录
|
|
405
|
-
- `ai history reset` — 清除所有目录的对话历史
|
|
387
|
+
- `ai memery dir` — 打开记忆目录,查看已存储的对话上下文
|
|
388
|
+
- `ai memery clear` — 清除当前目录的对话历史
|
|
406
389
|
|
|
407
390
|
## 9. 故障排除
|
|
408
391
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepfish-ai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "This is an AI-driven command-line tool built on Node.js, equipped with AI agent and workflow capabilities. It is compatible with a wide range of AI models, can convert natural language into cross-system terminal and file operation commands, and features high extensibility. It supports complex tasks such as translation, content creation, and format conversion, while allowing custom extensions to be automatically generated via AI.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"bin": {
|
|
7
8
|
"ai": "src/cli/index.js"
|
|
8
9
|
},
|
|
@@ -33,20 +34,36 @@
|
|
|
33
34
|
},
|
|
34
35
|
"homepage": "https://github.com/qq306863030/deepfish-ai#readme",
|
|
35
36
|
"dependencies": {
|
|
37
|
+
"adm-zip": "^0.5.16",
|
|
36
38
|
"axios": "^1.13.5",
|
|
39
|
+
"canvas": "^3.2.3",
|
|
37
40
|
"chalk": "^4.1.0",
|
|
38
41
|
"chardet": "^2.1.1",
|
|
39
42
|
"cheerio": "^1.2.0",
|
|
40
43
|
"commander": "^11.0.0",
|
|
41
44
|
"dayjs": "^1.11.19",
|
|
45
|
+
"docx": "^9.6.1",
|
|
46
|
+
"docxtemplater": "^3.68.4",
|
|
47
|
+
"echarts": "^6.0.0",
|
|
48
|
+
"eventemitter-super": "^1.0.8",
|
|
42
49
|
"extract-zip": "^2.0.1",
|
|
43
50
|
"fs-extra": "^11.3.3",
|
|
44
51
|
"iconv-lite": "^0.7.2",
|
|
45
52
|
"inquirer": "^9.0.0",
|
|
46
53
|
"js-yaml": "^4.1.1",
|
|
47
54
|
"lodash": "^4.17.23",
|
|
55
|
+
"mammoth": "^1.12.0",
|
|
48
56
|
"openai": "^6.18.0",
|
|
49
|
-
"
|
|
57
|
+
"pdf-lib": "^1.17.1",
|
|
58
|
+
"pdf-parse": "^2.4.5",
|
|
59
|
+
"pdf-to-img": "^6.0.0",
|
|
60
|
+
"pdfkit": "^0.18.0",
|
|
61
|
+
"pizzip": "^3.2.0",
|
|
62
|
+
"pptxgenjs": "^4.0.1",
|
|
63
|
+
"puppeteer": "^24.41.0",
|
|
64
|
+
"sharp": "^0.34.5",
|
|
65
|
+
"uuid": "^13.0.0",
|
|
66
|
+
"xlsx": "^0.18.5"
|
|
50
67
|
},
|
|
51
68
|
"devDependencies": {
|
|
52
69
|
"@eslint/js": "^10.0.1",
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const fs = require('fs-extra')
|
|
4
|
+
const dayjs = require('dayjs')
|
|
5
|
+
const Logger = require('../BaseAgentRobot/Logger.js')
|
|
6
|
+
const BaseAgentRobot = require('../BaseAgentRobot/index.js')
|
|
7
|
+
const {AttachmentToolScanner} = require('../BaseAgentRobot/utils/AttachmentToolScanner.js')
|
|
8
|
+
const AgentTree = require('../BaseAgentRobot/utils/AgentTree.js')
|
|
9
|
+
|
|
10
|
+
class MainAgentRobot extends BaseAgentRobot {
|
|
11
|
+
// toolCollection = null // 工具集合,包含所有工具函数
|
|
12
|
+
constructor(opt) {
|
|
13
|
+
super(opt)
|
|
14
|
+
this.type = 'main'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 初始化文件
|
|
18
|
+
_initFiles(opt) {
|
|
19
|
+
this.workspace = opt.workspace || process.cwd() // 工作空间,目录
|
|
20
|
+
this.basespace = opt.basespace || path.join(os.homedir(), '.deepfish-ai') // 记忆空间,目录
|
|
21
|
+
this.memorySpace = path.join(this.basespace, 'memory') // 记忆空间,目录
|
|
22
|
+
this.agentRecordFilePath = path.join(this.memorySpace, 'agentRecord.json')
|
|
23
|
+
fs.ensureDirSync(this.memorySpace)
|
|
24
|
+
// 查看agentRecord.json文件是否存在,不存在则创建
|
|
25
|
+
if (!fs.pathExistsSync(this.agentRecordFilePath)) {
|
|
26
|
+
fs.writeJsonSync(this.agentRecordFilePath, [], { spaces: 2 })
|
|
27
|
+
}
|
|
28
|
+
// 判断是否已经存在workspace
|
|
29
|
+
let agentRecord = fs.readJsonSync(this.agentRecordFilePath)
|
|
30
|
+
const record = agentRecord.find(
|
|
31
|
+
(record) => record.workspace === this.workspace,
|
|
32
|
+
)
|
|
33
|
+
if (record) {
|
|
34
|
+
this.id = record.agentId
|
|
35
|
+
this.name = record.name
|
|
36
|
+
this.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
37
|
+
} else {
|
|
38
|
+
agentRecord.push({
|
|
39
|
+
agentId: this.id,
|
|
40
|
+
name: this.name,
|
|
41
|
+
workspace: this.workspace,
|
|
42
|
+
createTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
43
|
+
updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
fs.writeJsonSync(this.agentRecordFilePath, agentRecord, { spaces: 2 })
|
|
47
|
+
this.agentSpace = path.join(this.memorySpace, this.id) // Agent空间,目录
|
|
48
|
+
fs.ensureDirSync(this.agentSpace)
|
|
49
|
+
this.agentTree = new AgentTree(this)
|
|
50
|
+
this.agentTree.init()
|
|
51
|
+
this.memoryFilePath = path.join(this.agentSpace, 'memory.json')
|
|
52
|
+
this.logDirPath = path.join(this.agentSpace, 'logs')
|
|
53
|
+
fs.ensureDirSync(this.logDirPath)
|
|
54
|
+
|
|
55
|
+
// 自动清除过期的记忆和日志
|
|
56
|
+
const currentDate = dayjs()
|
|
57
|
+
agentRecord = agentRecord.filter((record) => {
|
|
58
|
+
if (
|
|
59
|
+
currentDate.diff(dayjs(record.updateTime), 'day') >
|
|
60
|
+
opt.maxMemoryExpireTime
|
|
61
|
+
) {
|
|
62
|
+
// 删除Agent空间
|
|
63
|
+
fs.removeSync(path.join(this.memorySpace, record.agentId))
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
return true
|
|
67
|
+
})
|
|
68
|
+
fs.writeJsonSync(this.agentRecordFilePath, agentRecord, { spaces: 2 })
|
|
69
|
+
this.logger = new Logger(this) // 初始化日志系统
|
|
70
|
+
this.logger.clearAllLogs()
|
|
71
|
+
this.toolCollection = AttachmentToolScanner.getToolCollection(
|
|
72
|
+
this.workspace,
|
|
73
|
+
) // 加载工具集合
|
|
74
|
+
this.clawSkillCollection = AttachmentToolScanner.getClawSkillCollection(
|
|
75
|
+
this.basespace,
|
|
76
|
+
) // 加载Claw技能集合
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_getDefaultSystemPrompt(opt) {
|
|
80
|
+
const systemPrompt = super._getDefaultSystemPrompt(opt)
|
|
81
|
+
return `
|
|
82
|
+
${systemPrompt}
|
|
83
|
+
### 工具调用
|
|
84
|
+
对于复杂的任务,先从可以使用的Skills中查找并使用合适的Skill,如果没有合适的Skill,再使用内置工具函数,使用时请严格按照工具函数的调用方式进行调用。
|
|
85
|
+
${AttachmentToolScanner.getAttachToolPrompt(this.toolCollection, this.clawSkillCollection)}
|
|
86
|
+
`
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = MainAgentRobot
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const fs = require('fs-extra')
|
|
4
|
+
const BaseAgentRobot = require('../BaseAgentRobot/index.js')
|
|
5
|
+
const Logger = require('../BaseAgentRobot/Logger.js')
|
|
6
|
+
const {AttachmentToolScanner} = require('../BaseAgentRobot/utils/AttachmentToolScanner.js')
|
|
7
|
+
const AgentTree = require('../BaseAgentRobot/utils/AgentTree.js')
|
|
8
|
+
|
|
9
|
+
class SubAgentRobot extends BaseAgentRobot {
|
|
10
|
+
// opt: { root, parent, ...MainAgentOpt }
|
|
11
|
+
constructor(opt) {
|
|
12
|
+
super(opt)
|
|
13
|
+
this.type = 'sub'
|
|
14
|
+
this.parent = opt.parent
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_initFiles(opt) {
|
|
18
|
+
this.root = opt.root
|
|
19
|
+
this.parent = opt.parent
|
|
20
|
+
this.attachTools = opt.attachTools || []
|
|
21
|
+
this.workspace = opt.workspace || process.cwd() // 工作空间,目录
|
|
22
|
+
this.basespace = opt.basespace || path.join(os.homedir(), '.deepfish-ai') // 记忆空间,目录
|
|
23
|
+
this.memorySpace = path.join(this.basespace, 'memory') // 记忆空间,目录
|
|
24
|
+
this.agentRecordFilePath = path.join(this.memorySpace, 'agentRecord.json')
|
|
25
|
+
this.agentSpace = path.join(this.memorySpace, this.root.id) // Agent空间,目录
|
|
26
|
+
this.memoryFilePath = path.join(this.agentSpace, `memory-${this.id}.json`)
|
|
27
|
+
this.logDirPath = path.join(this.agentSpace, 'logs')
|
|
28
|
+
this.logger = new Logger(this) // 初始化日志系统
|
|
29
|
+
this.agentTree = new AgentTree(this)
|
|
30
|
+
this.agentTree.init()
|
|
31
|
+
this.toolCollection = AttachmentToolScanner.getToolCollection(
|
|
32
|
+
this.workspace,
|
|
33
|
+
) // 加载工具集合
|
|
34
|
+
this.clawSkillCollection = AttachmentToolScanner.getClawSkillCollection(
|
|
35
|
+
this.basespace,
|
|
36
|
+
) // 加载Claw技能集合
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_getDefaultSystemPrompt(opt) {
|
|
40
|
+
const systemPrompt = super._getDefaultSystemPrompt(opt)
|
|
41
|
+
return `
|
|
42
|
+
${systemPrompt}
|
|
43
|
+
### 工具调用
|
|
44
|
+
对于复杂的任务,先从可以使用的Skills中查找并使用合适的Skill,如果没有合适的Skill,再使用内置工具函数,使用时请严格按照工具函数的调用方式进行调用。
|
|
45
|
+
${AttachmentToolScanner.getAttachToolPrompt(this.toolCollection, this.clawSkillCollection)}
|
|
46
|
+
`
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = SubAgentRobot
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const BaseAgentRobot = require('../BaseAgentRobot/index.js')
|
|
4
|
+
const Logger = require('../BaseAgentRobot/Logger.js')
|
|
5
|
+
const AgentTree = require('../BaseAgentRobot/utils/AgentTree.js')
|
|
6
|
+
const {
|
|
7
|
+
AttachmentToolScanner,
|
|
8
|
+
} = require('../BaseAgentRobot/utils/AttachmentToolScanner.js')
|
|
9
|
+
|
|
10
|
+
class SubSkillAgentRobot extends BaseAgentRobot {
|
|
11
|
+
// opt: { root, parent, ...MainAgentOpt }
|
|
12
|
+
constructor(opt) {
|
|
13
|
+
super(opt)
|
|
14
|
+
this.type = 'sub-skill'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_initFiles(opt) {
|
|
18
|
+
this.root = opt.root
|
|
19
|
+
this.parent = opt.parent
|
|
20
|
+
this.attachTools = opt.attachTools || []
|
|
21
|
+
this.workspace = opt.workspace || process.cwd() // 工作空间,目录
|
|
22
|
+
this.basespace = opt.basespace || path.join(os.homedir(), '.deepfish-ai') // 记忆空间,目录
|
|
23
|
+
this.memorySpace = path.join(this.basespace, 'memory') // 记忆空间,目录
|
|
24
|
+
this.agentRecordFilePath = path.join(this.memorySpace, 'agentRecord.json')
|
|
25
|
+
this.agentSpace = path.join(this.memorySpace, this.root.id) // Agent空间,目录
|
|
26
|
+
this.agentTreeFilePath = path.join(this.agentSpace, 'agentTree.json')
|
|
27
|
+
this.memoryFilePath = path.join(this.agentSpace, `memory-${this.id}.json`)
|
|
28
|
+
this.logDirPath = path.join(this.agentSpace, 'logs')
|
|
29
|
+
this.logger = new Logger(this) // 初始化日志系统
|
|
30
|
+
this.agentTree = new AgentTree(this)
|
|
31
|
+
this.agentTree.init()
|
|
32
|
+
|
|
33
|
+
this.toolCollection = AttachmentToolScanner.getToolCollection(
|
|
34
|
+
this.workspace,
|
|
35
|
+
) // 加载工具集合
|
|
36
|
+
this.clawSkillCollection = AttachmentToolScanner.getClawSkillCollection(
|
|
37
|
+
this.basespace,
|
|
38
|
+
) // 加载Claw技能集合
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_getDefaultSystemPrompt(opt) {
|
|
42
|
+
const clawSkills = opt.clawSkills || []
|
|
43
|
+
let systemPrompt = super._getDefaultSystemPrompt(opt)
|
|
44
|
+
systemPrompt =
|
|
45
|
+
systemPrompt + '\n' + AttachmentToolScanner.getClawSkillPrompt(clawSkills, this.toolCollection, this.clawSkillCollection)
|
|
46
|
+
return systemPrompt
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = SubSkillAgentRobot
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { AttachmentToolType, AttachmentToolScanner } = require('../BaseAgentRobot/utils/AttachmentToolScanner.js')
|
|
2
|
+
const MainAgentRobot = require('./MainAgentRobot.js')
|
|
3
|
+
const SubAgentRobot = require('./SubAgentRobot.js')
|
|
4
|
+
const SubSkillAgentRobot = require('./SubSkillAgentRobot.js')
|
|
5
|
+
|
|
6
|
+
class AgentRobotFactory {
|
|
7
|
+
createMainAgent(opt) {
|
|
8
|
+
return new MainAgentRobot(opt)
|
|
9
|
+
}
|
|
10
|
+
// 创建子技能Agent
|
|
11
|
+
createSubSkillAgent(parent, id, attachTools = []) {
|
|
12
|
+
const baseSkill = []
|
|
13
|
+
const clawSkill = []
|
|
14
|
+
for (const tool of attachTools) {
|
|
15
|
+
if (tool.type === AttachmentToolType.BASE_SKILL) {
|
|
16
|
+
baseSkill.push(tool)
|
|
17
|
+
} else if (tool.type === AttachmentToolType.CLAW_SKILL) {
|
|
18
|
+
clawSkill.push(tool)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const subAgent = new SubSkillAgentRobot({
|
|
22
|
+
...parent.opt,
|
|
23
|
+
id,
|
|
24
|
+
name: `SubSkillAgent-${attachTools[0].name}`,
|
|
25
|
+
parent: parent,
|
|
26
|
+
root: parent.root || parent,
|
|
27
|
+
attachTools: baseSkill,
|
|
28
|
+
clawSkills: clawSkill
|
|
29
|
+
})
|
|
30
|
+
parent.children.push(subAgent)
|
|
31
|
+
return subAgent
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 创建子Agent
|
|
35
|
+
createSubAgent(parent, id) {
|
|
36
|
+
const subAgent = new SubAgentRobot({
|
|
37
|
+
...parent.opt,
|
|
38
|
+
id,
|
|
39
|
+
name: `SubAgent-${id}`,
|
|
40
|
+
parent: parent,
|
|
41
|
+
root: parent.root || parent,
|
|
42
|
+
})
|
|
43
|
+
parent.children.push(subAgent)
|
|
44
|
+
return subAgent
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = AgentRobotFactory
|