deepfish-ai 1.0.28 → 2.0.2
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 +126 -368
- package/dist/index.js +23320 -0
- package/dist/serve/client/assets/index-DUHYC91l.js +1 -0
- package/dist/serve/client/assets/index-zcrdNLZs.css +1 -0
- package/dist/serve/client/index.html +14 -0
- package/dist/serve/pm2-server.js +21015 -0
- package/dist/serve/server/entry-server.mjs +224 -0
- package/package.json +50 -70
- package/LICENSE +0 -21
- package/README_CN.md +0 -460
- package/src/AgentRobot/AgentRobotFactory/MainAgentRobot.js +0 -88
- package/src/AgentRobot/AgentRobotFactory/SubAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/SubSkillAgentRobot.js +0 -45
- package/src/AgentRobot/AgentRobotFactory/index.js +0 -48
- package/src/AgentRobot/BaseAgentRobot/Brain.js +0 -210
- package/src/AgentRobot/BaseAgentRobot/BrainEvent.js +0 -17
- package/src/AgentRobot/BaseAgentRobot/Hand.js +0 -119
- package/src/AgentRobot/BaseAgentRobot/Heart.js +0 -0
- package/src/AgentRobot/BaseAgentRobot/Logger.js +0 -114
- package/src/AgentRobot/BaseAgentRobot/ScreenPrinter.js +0 -49
- package/src/AgentRobot/BaseAgentRobot/index.js +0 -266
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/AliBailian.js +0 -997
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/doc-transform.js +0 -204
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/docx.js +0 -1286
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/img.js +0 -765
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pdf.js +0 -736
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/pptx.js +0 -567
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/video.js +0 -36
- package/src/AgentRobot/BaseAgentRobot/lazy-tools/xlsx.js +0 -611
- package/src/AgentRobot/BaseAgentRobot/tools/BaseTools.js +0 -13
- package/src/AgentRobot/BaseAgentRobot/tools/CreateAgentTools.js +0 -158
- package/src/AgentRobot/BaseAgentRobot/tools/FileTools.js +0 -768
- package/src/AgentRobot/BaseAgentRobot/tools/GenerateTools.js +0 -441
- package/src/AgentRobot/BaseAgentRobot/tools/InquirerTools.js +0 -244
- package/src/AgentRobot/BaseAgentRobot/tools/SystemTools.js +0 -263
- package/src/AgentRobot/BaseAgentRobot/tools/TaskTools.js +0 -211
- package/src/AgentRobot/BaseAgentRobot/tools/TestTools.js +0 -100
- package/src/AgentRobot/BaseAgentRobot/tools/UserTool.js +0 -87
- package/src/AgentRobot/BaseAgentRobot/tools/WebTools.js +0 -257
- package/src/AgentRobot/BaseAgentRobot/utils/AIRequest.js +0 -297
- package/src/AgentRobot/BaseAgentRobot/utils/AIToolManager.js +0 -131
- package/src/AgentRobot/BaseAgentRobot/utils/AgentTree.js +0 -66
- package/src/AgentRobot/BaseAgentRobot/utils/AttachmentToolScanner.js +0 -235
- package/src/AgentRobot/BaseAgentRobot/utils/MessageCompresser.js +0 -236
- package/src/AgentRobot/BaseAgentRobot/utils/aiConsole.js +0 -74
- package/src/AgentRobot/BaseAgentRobot/utils/aiInquirer.js +0 -78
- package/src/AgentRobot/BaseAgentRobot/utils/analyzeReturn.test.js +0 -104
- package/src/AgentRobot/BaseAgentRobot/utils/copilot.js +0 -117
- package/src/AgentRobot/BaseAgentRobot/utils/node-root.js +0 -138
- package/src/AgentRobot/BaseAgentRobot/utils/normal.js +0 -399
- package/src/cli/ConfigManager.js +0 -283
- package/src/cli/DefaultConfig.js +0 -98
- package/src/cli/GlobalVariable.js +0 -8
- package/src/cli/MemoryManager.js +0 -53
- package/src/cli/SkillConfigManager.js +0 -343
- package/src/cli/SkillParser.js +0 -58
- package/src/cli/ai-auth.js +0 -231
- package/src/cli/ai-config.js +0 -225
- package/src/cli/ai-memory.js +0 -22
- package/src/cli/ai-skill.js +0 -65
- package/src/cli/index.js +0 -77
- package/src/index.js +0 -54
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const os = require('os')
|
|
3
|
-
const { Brain } = require('./Brain.js')
|
|
4
|
-
const BrainEvent = require('./BrainEvent.js')
|
|
5
|
-
const ScreenPrinter = require('./ScreenPrinter.js')
|
|
6
|
-
const { HandEvent, Hand } = require('./Hand.js')
|
|
7
|
-
const AIToolManager = require('./utils/AIToolManager.js')
|
|
8
|
-
const dayjs = require('dayjs')
|
|
9
|
-
|
|
10
|
-
class BaseAgentRobot {
|
|
11
|
-
id = '' // Agentid
|
|
12
|
-
name = '' // Agent名字
|
|
13
|
-
|
|
14
|
-
brain = null // 大脑,负责思考、记忆、决策
|
|
15
|
-
hand = null // 手,负责使用工具
|
|
16
|
-
|
|
17
|
-
heart = null // 心脏,负责心跳、连接
|
|
18
|
-
sender = null // 发送器,负责发送消息
|
|
19
|
-
receiver = null // 接收器,负责接收消息
|
|
20
|
-
screenPrinter = null // Agent连接的打印机,能向屏幕输出文字
|
|
21
|
-
logger = null // Agent连接的日志系统,能记录日志
|
|
22
|
-
children = [] // 子Agent,能分担任务
|
|
23
|
-
parent = null // 父Agent,能分配任务
|
|
24
|
-
root = null // 根Agent
|
|
25
|
-
state = 0 // Agent状态,-1表示销毁 0表示空闲,1表示思考中 2表示工作中
|
|
26
|
-
type = 'main' // Agent类型,main表示主Agent,sub表示子Agent,sub-skill表示子技能Agent
|
|
27
|
-
|
|
28
|
-
workspace = null
|
|
29
|
-
basespace = null
|
|
30
|
-
userspace = null
|
|
31
|
-
memorySpace = null
|
|
32
|
-
agentRecordFilePath = null
|
|
33
|
-
agentSpace = null
|
|
34
|
-
agentTree = null
|
|
35
|
-
memoryFilePath = null
|
|
36
|
-
logDirPath = null
|
|
37
|
-
toolManager = null
|
|
38
|
-
|
|
39
|
-
constructor(
|
|
40
|
-
opt = {
|
|
41
|
-
id: '',
|
|
42
|
-
name: '',
|
|
43
|
-
attachTools: [], // 附加工具, Agent后续安装的工具函数
|
|
44
|
-
workspace: process.cwd(), // 工作空间,目录
|
|
45
|
-
basespace: path.join(os.homedir(), '.deepfish-ai'), // 记忆空间,目录
|
|
46
|
-
maxIterations: -1, // 思考的最大迭代次数,-1表示无限制
|
|
47
|
-
maxMemoryExpireTime: 30, // 最大记忆过期时间,单位天,-1表示无限制, 0表示不记录
|
|
48
|
-
maxLogExpireTime: 3, // 最大日志过期时间,单位天, -1表示无限制,0表示不记录
|
|
49
|
-
maxBlockFileSize: 20, // 大文件分块阈值,单位KB;超过该大小的文件需要分块处理
|
|
50
|
-
systemPrompt: '', // 系统提示语
|
|
51
|
-
encoding: 'auto', // 命令行编码格式, 可设置为utf-8、gbk等, 也可以设置成auto或空值自动判断
|
|
52
|
-
isThinkPrint: true, // 是否打印思考过程
|
|
53
|
-
aiConfig: {
|
|
54
|
-
name: 'deepseek',
|
|
55
|
-
type: 'deepseek',
|
|
56
|
-
baseUrl: 'https://api.deepseek.com',
|
|
57
|
-
model: 'deepseek-reasoner',
|
|
58
|
-
apiKey: '',
|
|
59
|
-
temperature: 0.7,
|
|
60
|
-
maxTokens: 8, // 最大输出长度,单位KB
|
|
61
|
-
maxContextLength: 64, // 最大上下文大小,单位KB
|
|
62
|
-
stream: true,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
) {
|
|
66
|
-
this.opt = opt
|
|
67
|
-
this.config = opt
|
|
68
|
-
this.aiConfig = opt.aiConfig || {}
|
|
69
|
-
this.id = opt.id || Date.now().toString()
|
|
70
|
-
this.name = opt.name || 'AgentRobot'
|
|
71
|
-
this.screenPrinter = new ScreenPrinter() // 屏幕打印机
|
|
72
|
-
this._initFiles(opt) // 初始化文件
|
|
73
|
-
this.toolManager = new AIToolManager(this)
|
|
74
|
-
this.systemPrompt = opt.systemPrompt || this._getDefaultSystemPrompt(opt) // 系统提示语
|
|
75
|
-
this.brain = new Brain(this) // 初始化大脑
|
|
76
|
-
this.hand = new Hand(this) // 初始化手
|
|
77
|
-
this._initEvents() // 初始化大脑事件
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 初始化文件
|
|
81
|
-
_initFiles(opt) {}
|
|
82
|
-
|
|
83
|
-
_initEvents() {
|
|
84
|
-
const aiConfig = this.opt.aiConfig
|
|
85
|
-
const isThinkPrint = this.opt.isThinkPrint
|
|
86
|
-
let stopLoading = null
|
|
87
|
-
this.brain.on(BrainEvent.THINK_BEFORE, () => {})
|
|
88
|
-
this.brain.on(BrainEvent.SUB_THINK_BEFORE, (messages) => {
|
|
89
|
-
if (!aiConfig.stream || !isThinkPrint) {
|
|
90
|
-
if (stopLoading) {
|
|
91
|
-
stopLoading('I have finished thinking.')
|
|
92
|
-
}
|
|
93
|
-
stopLoading = this.screenPrinter.loading('Thinking...')
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
this.brain.on(BrainEvent.SUB_THINK_AFTER, (messages) => {
|
|
97
|
-
if ((!aiConfig.stream && stopLoading) || !isThinkPrint) {
|
|
98
|
-
stopLoading('I have finished thinking.')
|
|
99
|
-
stopLoading = null
|
|
100
|
-
// const lastMessage = messages[messages.length - 1]
|
|
101
|
-
// this.screenPrinter.logInfo(lastMessage?.content)
|
|
102
|
-
}
|
|
103
|
-
})
|
|
104
|
-
this.brain.on(BrainEvent.SUB_STREAM_THINK_OUTPUT, (messages, output) => {
|
|
105
|
-
isThinkPrint && this.screenPrinter.streamOutput(output, '#47854a')
|
|
106
|
-
})
|
|
107
|
-
this.brain.on(BrainEvent.SUB_STREAM_CONTENT_OUTPUT, (messages, content) => {
|
|
108
|
-
isThinkPrint && this.screenPrinter.streamOutput(content, '#c2a654')
|
|
109
|
-
})
|
|
110
|
-
this.brain.on(
|
|
111
|
-
BrainEvent.SUB_STREAM_TOOL_CALLS_OUTPUT,
|
|
112
|
-
(messages, toolCalls) => {
|
|
113
|
-
isThinkPrint && this.screenPrinter.streamOutput(toolCalls, '#47854a')
|
|
114
|
-
},
|
|
115
|
-
)
|
|
116
|
-
this.brain.on(BrainEvent.SUB_STREAM_END, () => {
|
|
117
|
-
isThinkPrint && this.screenPrinter.streamLineBreak()
|
|
118
|
-
})
|
|
119
|
-
this.brain.on(BrainEvent.SUB_USE_TOOL, async (toolCalls) => {
|
|
120
|
-
await this.hand.useTools(toolCalls)
|
|
121
|
-
})
|
|
122
|
-
this.brain.on(
|
|
123
|
-
BrainEvent.COMPRESS_MESSAGES_BEFORE,
|
|
124
|
-
(messages, currentLength) => {
|
|
125
|
-
this.screenPrinter.logInfo(
|
|
126
|
-
`compressing messages: current length ${currentLength}, count ${messages.length}`,
|
|
127
|
-
)
|
|
128
|
-
},
|
|
129
|
-
)
|
|
130
|
-
this.brain.on(
|
|
131
|
-
BrainEvent.COMPRESS_MESSAGES_AFTER,
|
|
132
|
-
(newMessages, currentLength) => {
|
|
133
|
-
this.screenPrinter.logInfo(
|
|
134
|
-
`compressed messages: new length ${currentLength}, count ${newMessages.length}`,
|
|
135
|
-
)
|
|
136
|
-
this.logger.logCompress(newMessages)
|
|
137
|
-
},
|
|
138
|
-
)
|
|
139
|
-
this.brain.on(BrainEvent.THINK_AFTER, (content) => {
|
|
140
|
-
if (this.type === 'main') {
|
|
141
|
-
this.screenPrinter.logSuccess(content)
|
|
142
|
-
} else if (this.type === 'sub') {
|
|
143
|
-
this.screenPrinter.logSuccess(
|
|
144
|
-
`${this.name} have finished thinking and got the result.`,
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
this.brain.on(BrainEvent.SUB_THINK_ERROR, (messages, error) => {
|
|
149
|
-
this.screenPrinter.logError(
|
|
150
|
-
`I have an error during thinking: ${error} ${error.message}:${error.stack || ''}`,
|
|
151
|
-
)
|
|
152
|
-
this.logger.logInfo(
|
|
153
|
-
`I have an error during thinking: ${error.message}:${error.stack || ''}`,
|
|
154
|
-
)
|
|
155
|
-
})
|
|
156
|
-
this.brain.on(BrainEvent.NEW_MESSAGE, (message) => {
|
|
157
|
-
this.logger.logMessage(message)
|
|
158
|
-
})
|
|
159
|
-
this.hand.on(HandEvent.USE_TOOL_BEFORE, (toolId, funcName, funcArgs) => {
|
|
160
|
-
this.screenPrinter.logInfo(`I'm using tool ${funcName}`)
|
|
161
|
-
})
|
|
162
|
-
this.hand.on(HandEvent.USE_TOOL_REPORT, (toolId, funcName, toolContent) => {
|
|
163
|
-
this.brain.storeToolReport(toolId, toolContent)
|
|
164
|
-
})
|
|
165
|
-
this.hand.on(HandEvent.USE_TOOL_ERROR, (toolId, funcName, error) => {
|
|
166
|
-
this.brain.storeToolReport(toolId, error)
|
|
167
|
-
this.screenPrinter.logError(
|
|
168
|
-
`I have an error when using tool ${funcName}: ${error.message},${error.stack || ''}`,
|
|
169
|
-
)
|
|
170
|
-
this.logger.logInfo(
|
|
171
|
-
`I have an error when using tool ${funcName}: ${error.message},${error.stack || ''}`,
|
|
172
|
-
)
|
|
173
|
-
})
|
|
174
|
-
this.hand.on(HandEvent.USE_TOOL_AFTER, (toolId, funcName, funcArgs) => {
|
|
175
|
-
this.screenPrinter.logInfo(`I have finished using tool ${funcName}`)
|
|
176
|
-
this.logger.logInfo(`I have finished using tool ${funcName}`)
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
_getDefaultSystemPrompt(opt) {
|
|
181
|
-
const osType = process.platform
|
|
182
|
-
const workspace = this.workspace
|
|
183
|
-
const maxBlockFileSize = opt.maxBlockFileSize || 20
|
|
184
|
-
const id = this.id
|
|
185
|
-
const name = this.name
|
|
186
|
-
return `
|
|
187
|
-
你叫${name}, 编号${id}, 是一个严格按规则执行任务的智能体,不能违反任何系统限制,具有INTJ人格,高冷、做事以及回复问题精简、准确、不废话。
|
|
188
|
-
### 基础环境信息
|
|
189
|
-
当前工作目录:${workspace}
|
|
190
|
-
操作系统类型:${osType}
|
|
191
|
-
语言类型: 与用户输入语言一致
|
|
192
|
-
会话开始时间: ${dayjs().format('YYYY-MM-DD HH')}
|
|
193
|
-
|
|
194
|
-
### 工具使用
|
|
195
|
-
执行任务前,应仔细阅读工具描述以及可以使用的Skills的描述内容,优先使用匹配到的工具或技能,避免自己发挥。
|
|
196
|
-
|
|
197
|
-
### 大文本文件处理规则(分步执行)
|
|
198
|
-
处理长文档等大文件(单文件>${maxBlockFileSize}KB)时,必须按以下步骤分块处理:
|
|
199
|
-
1. 预处理:先执行文件大小/结构检查(如通过命令行/JS 代码获取文件大小、判断文件格式),输出检查结果;
|
|
200
|
-
2. 分块规则:按5KB-10KB/块拆分文件,拆分后每个块生成独立临时文件(命名格式:tmp_block_{原文件名}_chunk{序号}.tmp);
|
|
201
|
-
3. 处理逻辑:翻译/总结/分析类任务逐块处理,每块处理完成后记录结果,最后合并所有块的结果生成最终文件;
|
|
202
|
-
4. 合并校验:合并后需校验结果完整性(如总字符数匹配、无内容缺失),确保分块处理无遗漏。
|
|
203
|
-
|
|
204
|
-
### 核心执行原则
|
|
205
|
-
1. 最优路径优先:执行前必须先规划最少步骤的操作路径,明确「先做什么、再做什么、哪些可省略」,避免重复操作和无效步骤;
|
|
206
|
-
2. 异常反馈:操作失败(如命令执行报错、文件不存在)时,需明确说明「失败原因+可尝试的解决方案」,而非仅提示“操作失败”;
|
|
207
|
-
3. 结果校验:任务完成后,需简单校验结果是否符合用户目标(如文件是否生成、内容是否完整),并向用户反馈校验结果。
|
|
208
|
-
4. 如果执行任务过程中需要安装依赖、软件或工具,必须通过调用用户交互函数与用户交互,等待用户确认后再执行安装,除非用户明确说明执行过程中使用静默模式。
|
|
209
|
-
5. 任务执行过程中,产生的所有临时文件(如分块文件、测试文件等)必须以"tmp_"为前缀命名,如"tmp_block_filename.txt、tmp_test_filename.txt、tmp_bak_filename.txt",并在任务完成后删除这些临时文件,确保工作目录整洁。
|
|
210
|
-
|
|
211
|
-
### 用户信息
|
|
212
|
-
#### 用户信息记录规则
|
|
213
|
-
当对话中出现用户信息时,如个人基础信息(如姓名、昵称、年龄、职业、兴趣、性格特征等)、AI的基础信息(如昵称、性格特征等)、操作习惯、代码习惯、阅读习惯、用户常用目录等,必须使用用户信息读写函数进行记录。
|
|
214
|
-
|
|
215
|
-
#### 当前用户信息
|
|
216
|
-
----user info start----
|
|
217
|
-
${this.toolManager.functions.readUserInfo()}
|
|
218
|
-
----user info end----
|
|
219
|
-
`
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 更新系统提示词中的会话开始时间
|
|
223
|
-
updateSessionTime() {
|
|
224
|
-
const newTime = dayjs().format('YYYY-MM-DD HH')
|
|
225
|
-
this.systemPrompt = this.systemPrompt.replace(
|
|
226
|
-
/会话开始时间: \d{4}-\d{2}-\d{2} \d{2}/,
|
|
227
|
-
`会话开始时间: ${newTime}`,
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async executeTask(goal) {
|
|
232
|
-
const taskId = `task-${Date.now()}`
|
|
233
|
-
this.logger.logExecTime(taskId, 'execute task goal')
|
|
234
|
-
const res = await this.brain.thinkLoop(goal)
|
|
235
|
-
this.logger.logExecTime(taskId, 'execute task end')
|
|
236
|
-
return res
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
_getAgentRobotFactory() {
|
|
240
|
-
if (!this._agentRobotFactory) {
|
|
241
|
-
const AgentRobotFactory = require('../AgentRobotFactory/index.js')
|
|
242
|
-
this._agentRobotFactory = new AgentRobotFactory()
|
|
243
|
-
}
|
|
244
|
-
return this._agentRobotFactory
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// 创建子技能Agent
|
|
248
|
-
createSubSkillAgent(id, attachTools = []) {
|
|
249
|
-
const agentRobotFactory = this._getAgentRobotFactory()
|
|
250
|
-
return agentRobotFactory.createSubSkillAgent(this, id, attachTools)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 创建子Agent
|
|
254
|
-
createSubAgent(id) {
|
|
255
|
-
const agentRobotFactory = this._getAgentRobotFactory()
|
|
256
|
-
return agentRobotFactory.createSubAgent(this, id)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
destroy() {
|
|
260
|
-
this.brain.removeAllListeners()
|
|
261
|
-
this.state = -1
|
|
262
|
-
this.agentTree.clear()
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
module.exports = BaseAgentRobot
|