deepfish-ai 1.0.29 → 2.0.3
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 +195 -344
- package/dist/generate-skill.md +104 -0
- package/dist/generate-tool.md +88 -0
- package/dist/index.js +26831 -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 +24405 -0
- package/dist/serve/server/entry-server.mjs +224 -0
- package/dist/view-learn-cache.md +65 -0
- package/package.json +77 -83
- 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 -424
- 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 -354
- 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,768 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Author: Roman 306863030@qq.com
|
|
3
|
-
* @Date: 2026-03-17 11:59:19
|
|
4
|
-
* @LastEditors: roman_123 306863030@qq.com
|
|
5
|
-
* @LastEditTime: 2026-04-25 01:15:56
|
|
6
|
-
* @FilePath: \deepfish\src\AgentRobot\BaseAgentRobot\tools\FileTools.js
|
|
7
|
-
* @Description: 文件处理扩展函数
|
|
8
|
-
* @
|
|
9
|
-
*/
|
|
10
|
-
const path = require('path')
|
|
11
|
-
const fs = require('fs-extra')
|
|
12
|
-
const AdmZip = require('adm-zip')
|
|
13
|
-
|
|
14
|
-
function createSuccessResult(data = null) {
|
|
15
|
-
return {
|
|
16
|
-
success: true,
|
|
17
|
-
data,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function createErrorResult(error, data = null) {
|
|
22
|
-
return {
|
|
23
|
-
success: false,
|
|
24
|
-
error: error?.message || String(error),
|
|
25
|
-
data,
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function createFile(filePath, content) {
|
|
30
|
-
try {
|
|
31
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
32
|
-
const dirPath = path.dirname(fullPath)
|
|
33
|
-
|
|
34
|
-
if (!fs.existsSync(dirPath)) {
|
|
35
|
-
fs.mkdirSync(dirPath, { recursive: true })
|
|
36
|
-
}
|
|
37
|
-
fs.writeFileSync(fullPath, content)
|
|
38
|
-
return createSuccessResult({ filePath: fullPath })
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return createErrorResult(error, { filePath })
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function modifyFile(filePath, content) {
|
|
45
|
-
try {
|
|
46
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
47
|
-
|
|
48
|
-
if (!fs.existsSync(fullPath)) {
|
|
49
|
-
return createErrorResult(`File does not exist: ${fullPath}`, {
|
|
50
|
-
filePath: fullPath,
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fs.writeFileSync(fullPath, content)
|
|
55
|
-
return createSuccessResult({ filePath: fullPath })
|
|
56
|
-
} catch (error) {
|
|
57
|
-
return createErrorResult(error, { filePath })
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function readFile(filePath) {
|
|
62
|
-
try {
|
|
63
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
64
|
-
|
|
65
|
-
if (!fs.existsSync(fullPath)) {
|
|
66
|
-
return createErrorResult(`File does not exist: ${fullPath}`, {
|
|
67
|
-
filePath: fullPath,
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const content = fs.readFileSync(fullPath, 'utf8')
|
|
72
|
-
return createSuccessResult({ filePath: fullPath, content })
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return createErrorResult(error, { filePath })
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 替换文件中的文本内容
|
|
80
|
-
* @param {string} filePath 要处理的文件路径
|
|
81
|
-
* @param {string|RegExp} searchValue 要查找的文本或正则表达式
|
|
82
|
-
* @param {string} replaceValue 替换后的文本内容
|
|
83
|
-
* @param {boolean} [isGlobal=true] 是否进行全局替换,默认开启
|
|
84
|
-
* @returns {Promise<boolean>} 操作是否成功,成功返回 true,失败返回 false
|
|
85
|
-
*/
|
|
86
|
-
async function replaceFileText(
|
|
87
|
-
filePath,
|
|
88
|
-
searchValue,
|
|
89
|
-
replaceValue,
|
|
90
|
-
isGlobal = true,
|
|
91
|
-
) {
|
|
92
|
-
try {
|
|
93
|
-
const readResult = await readFile(filePath)
|
|
94
|
-
if (!readResult.success) {
|
|
95
|
-
return readResult
|
|
96
|
-
}
|
|
97
|
-
const content = readResult.data.content
|
|
98
|
-
const replacedContent = content.replace(
|
|
99
|
-
typeof searchValue === 'string'
|
|
100
|
-
? new RegExp(searchValue, isGlobal ? 'g' : '')
|
|
101
|
-
: searchValue,
|
|
102
|
-
replaceValue,
|
|
103
|
-
)
|
|
104
|
-
const modifyResult = await modifyFile(filePath, replacedContent)
|
|
105
|
-
if (!modifyResult.success) {
|
|
106
|
-
return modifyResult
|
|
107
|
-
}
|
|
108
|
-
return createSuccessResult({
|
|
109
|
-
filePath: path.resolve(process.cwd(), filePath),
|
|
110
|
-
})
|
|
111
|
-
} catch (error) {
|
|
112
|
-
return createErrorResult(error, { filePath })
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function appendToFile(filePath, content) {
|
|
117
|
-
try {
|
|
118
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
119
|
-
|
|
120
|
-
if (!fs.existsSync(fullPath)) {
|
|
121
|
-
return createErrorResult(`File does not exist: ${fullPath}`, {
|
|
122
|
-
filePath: fullPath,
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
fs.appendFileSync(fullPath, content)
|
|
127
|
-
return createSuccessResult({ filePath: fullPath })
|
|
128
|
-
} catch (error) {
|
|
129
|
-
return createErrorResult(error, { filePath })
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function fileExists(filePath) {
|
|
134
|
-
try {
|
|
135
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
136
|
-
return createSuccessResult({
|
|
137
|
-
filePath: fullPath,
|
|
138
|
-
exists: fs.existsSync(fullPath),
|
|
139
|
-
})
|
|
140
|
-
} catch (error) {
|
|
141
|
-
return createErrorResult(error, { filePath })
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function createDirectory(dirPath) {
|
|
146
|
-
try {
|
|
147
|
-
const fullPath = path.resolve(process.cwd(), dirPath)
|
|
148
|
-
if (!fs.existsSync(fullPath)) {
|
|
149
|
-
fs.mkdirSync(fullPath, { recursive: true })
|
|
150
|
-
}
|
|
151
|
-
return createSuccessResult({ dirPath: fullPath })
|
|
152
|
-
} catch (error) {
|
|
153
|
-
return createErrorResult(error, { dirPath })
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function deleteFile(filePath) {
|
|
158
|
-
try {
|
|
159
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
160
|
-
|
|
161
|
-
if (fs.existsSync(fullPath)) {
|
|
162
|
-
fs.unlinkSync(fullPath)
|
|
163
|
-
}
|
|
164
|
-
return createSuccessResult({ filePath: fullPath })
|
|
165
|
-
} catch (error) {
|
|
166
|
-
return createErrorResult(error, { filePath })
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async function deleteDirectory(dirPath) {
|
|
171
|
-
try {
|
|
172
|
-
const fullPath = path.resolve(process.cwd(), dirPath)
|
|
173
|
-
|
|
174
|
-
if (fs.existsSync(fullPath)) {
|
|
175
|
-
fs.rmSync(fullPath, { recursive: true, force: true })
|
|
176
|
-
}
|
|
177
|
-
return createSuccessResult({ dirPath: fullPath })
|
|
178
|
-
} catch (error) {
|
|
179
|
-
return createErrorResult(error, { dirPath })
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async function rename(oldPath, newPath) {
|
|
184
|
-
try {
|
|
185
|
-
const fullOldPath = path.resolve(process.cwd(), oldPath)
|
|
186
|
-
const fullNewPath = path.resolve(process.cwd(), newPath)
|
|
187
|
-
|
|
188
|
-
if (fs.existsSync(fullOldPath)) {
|
|
189
|
-
fs.renameSync(fullOldPath, fullNewPath)
|
|
190
|
-
return createSuccessResult({ oldPath: fullOldPath, newPath: fullNewPath })
|
|
191
|
-
}
|
|
192
|
-
return createErrorResult(`Source path does not exist: ${fullOldPath}`, {
|
|
193
|
-
oldPath: fullOldPath,
|
|
194
|
-
newPath: fullNewPath,
|
|
195
|
-
})
|
|
196
|
-
} catch (error) {
|
|
197
|
-
return createErrorResult(error, { oldPath, newPath })
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function copyFile(sourcePath, destinationPath) {
|
|
202
|
-
try {
|
|
203
|
-
const fullSourcePath = path.resolve(process.cwd(), sourcePath)
|
|
204
|
-
const fullDestPath = path.resolve(process.cwd(), destinationPath)
|
|
205
|
-
const destDirPath = path.dirname(fullDestPath)
|
|
206
|
-
|
|
207
|
-
fs.ensureDirSync(destDirPath)
|
|
208
|
-
|
|
209
|
-
if (fs.existsSync(fullSourcePath)) {
|
|
210
|
-
fs.copyFileSync(fullSourcePath, fullDestPath)
|
|
211
|
-
return createSuccessResult({
|
|
212
|
-
sourcePath: fullSourcePath,
|
|
213
|
-
destinationPath: fullDestPath,
|
|
214
|
-
})
|
|
215
|
-
} else {
|
|
216
|
-
return createErrorResult(
|
|
217
|
-
`Source file does not exist: ${fullSourcePath}`,
|
|
218
|
-
{
|
|
219
|
-
sourcePath: fullSourcePath,
|
|
220
|
-
destinationPath: fullDestPath,
|
|
221
|
-
},
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
} catch (error) {
|
|
225
|
-
return createErrorResult(error, { sourcePath, destinationPath })
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async function moveFile(sourcePath, destinationPath) {
|
|
230
|
-
try {
|
|
231
|
-
const fullSourcePath = path.resolve(process.cwd(), sourcePath)
|
|
232
|
-
const fullDestPath = path.resolve(process.cwd(), destinationPath)
|
|
233
|
-
const destDirPath = path.dirname(fullDestPath)
|
|
234
|
-
|
|
235
|
-
if (!fs.existsSync(destDirPath)) {
|
|
236
|
-
fs.mkdirSync(destDirPath, { recursive: true })
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (fs.existsSync(fullSourcePath)) {
|
|
240
|
-
fs.renameSync(fullSourcePath, fullDestPath)
|
|
241
|
-
return createSuccessResult({
|
|
242
|
-
sourcePath: fullSourcePath,
|
|
243
|
-
destinationPath: fullDestPath,
|
|
244
|
-
})
|
|
245
|
-
}
|
|
246
|
-
return createErrorResult(`Source file does not exist: ${fullSourcePath}`, {
|
|
247
|
-
sourcePath: fullSourcePath,
|
|
248
|
-
destinationPath: fullDestPath,
|
|
249
|
-
})
|
|
250
|
-
} catch (error) {
|
|
251
|
-
return createErrorResult(error, { sourcePath, destinationPath })
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async function getFileInfo(filePath) {
|
|
256
|
-
try {
|
|
257
|
-
const fullPath = path.resolve(process.cwd(), filePath)
|
|
258
|
-
|
|
259
|
-
if (!fs.existsSync(fullPath)) {
|
|
260
|
-
return createErrorResult(`File does not exist: ${fullPath}`, {
|
|
261
|
-
filePath: fullPath,
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const stats = fs.statSync(fullPath)
|
|
266
|
-
return createSuccessResult({
|
|
267
|
-
path: fullPath,
|
|
268
|
-
size: stats.size,
|
|
269
|
-
birthtime: stats.birthtime,
|
|
270
|
-
mtime: stats.mtime,
|
|
271
|
-
ctime: stats.ctime,
|
|
272
|
-
isFile: stats.isFile(),
|
|
273
|
-
isDirectory: stats.isDirectory(),
|
|
274
|
-
})
|
|
275
|
-
} catch (error) {
|
|
276
|
-
return createErrorResult(error, { filePath })
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async function getFileNameList(dirPath) {
|
|
281
|
-
try {
|
|
282
|
-
const fullPath = path.resolve(process.cwd(), dirPath)
|
|
283
|
-
if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isDirectory()) {
|
|
284
|
-
return createErrorResult(
|
|
285
|
-
`Directory does not exist or is not a directory: ${fullPath}`,
|
|
286
|
-
{
|
|
287
|
-
dirPath: fullPath,
|
|
288
|
-
},
|
|
289
|
-
)
|
|
290
|
-
}
|
|
291
|
-
const files = fs.readdirSync(fullPath)
|
|
292
|
-
return createSuccessResult({ dirPath: fullPath, files })
|
|
293
|
-
} catch (error) {
|
|
294
|
-
return createErrorResult(error, { dirPath })
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async function clearDirectory(dirPath) {
|
|
299
|
-
try {
|
|
300
|
-
const fullPath = path.resolve(process.cwd(), dirPath)
|
|
301
|
-
|
|
302
|
-
if (!fs.existsSync(fullPath)) {
|
|
303
|
-
return createErrorResult(`Directory does not exist: ${fullPath}`, {
|
|
304
|
-
dirPath: fullPath,
|
|
305
|
-
})
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (!fs.statSync(fullPath).isDirectory()) {
|
|
309
|
-
return createErrorResult(`Path is not a directory: ${fullPath}`, {
|
|
310
|
-
dirPath: fullPath,
|
|
311
|
-
})
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const files = fs.readdirSync(fullPath)
|
|
315
|
-
|
|
316
|
-
for (const file of files) {
|
|
317
|
-
const filePath = path.join(fullPath, file)
|
|
318
|
-
if (fs.statSync(filePath).isDirectory()) {
|
|
319
|
-
fs.rmSync(filePath, { recursive: true, force: true })
|
|
320
|
-
} else {
|
|
321
|
-
fs.unlinkSync(filePath)
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return createSuccessResult({ dirPath: fullPath })
|
|
326
|
-
} catch (error) {
|
|
327
|
-
return createErrorResult(error, { dirPath })
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* 【跨平台】压缩 文件/文件夹 为 zip(支持中文、多层目录)
|
|
333
|
-
* @param {string} inputPath 要压缩的文件或文件夹路径
|
|
334
|
-
* @param {string} outputZipPath 输出的 zip 路径
|
|
335
|
-
* @returns {Promise<boolean>} 操作是否成功,成功返回 true,失败返回 false
|
|
336
|
-
*/
|
|
337
|
-
async function compressToZip(inputPath, outputZipPath) {
|
|
338
|
-
try {
|
|
339
|
-
const absoluteInput = path.resolve(inputPath)
|
|
340
|
-
const absoluteOutput = path.resolve(outputZipPath)
|
|
341
|
-
// 检查源路径是否存在
|
|
342
|
-
await fs.access(absoluteInput)
|
|
343
|
-
const zip = new AdmZip()
|
|
344
|
-
// 判断是文件还是文件夹
|
|
345
|
-
const stats = await fs.stat(absoluteInput)
|
|
346
|
-
if (stats.isDirectory()) {
|
|
347
|
-
// 压缩文件夹(递归添加所有子文件)
|
|
348
|
-
zip.addLocalFolder(absoluteInput)
|
|
349
|
-
} else {
|
|
350
|
-
// 压缩单个文件
|
|
351
|
-
zip.addLocalFile(absoluteInput)
|
|
352
|
-
}
|
|
353
|
-
// 写入 zip 文件
|
|
354
|
-
await zip.writeZipPromise(absoluteOutput)
|
|
355
|
-
return createSuccessResult({
|
|
356
|
-
inputPath: absoluteInput,
|
|
357
|
-
outputZipPath: absoluteOutput,
|
|
358
|
-
})
|
|
359
|
-
} catch (err) {
|
|
360
|
-
return createErrorResult(err, { inputPath, outputZipPath })
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* 【跨平台】解压 zip 文件(支持密码、中文不乱码)
|
|
366
|
-
* @param {string} zipFilePath zip 文件路径
|
|
367
|
-
* @param {string} extractToPath 解压到哪个文件夹
|
|
368
|
-
* @returns {Promise<boolean>} 操作是否成功,成功返回 true,失败返回 false
|
|
369
|
-
*/
|
|
370
|
-
async function extractZip(zipFilePath, extractToPath) {
|
|
371
|
-
try {
|
|
372
|
-
const absoluteZipPath = path.resolve(zipFilePath)
|
|
373
|
-
const absoluteExtractPath = path.resolve(extractToPath)
|
|
374
|
-
await fs.access(absoluteZipPath)
|
|
375
|
-
const zip = new AdmZip(absoluteZipPath)
|
|
376
|
-
// 自动创建目标目录
|
|
377
|
-
await fs.mkdir(absoluteExtractPath, { recursive: true })
|
|
378
|
-
// 解压所有文件
|
|
379
|
-
zip.extractAllTo(absoluteExtractPath, true)
|
|
380
|
-
return createSuccessResult({
|
|
381
|
-
zipFilePath: absoluteZipPath,
|
|
382
|
-
extractToPath: absoluteExtractPath,
|
|
383
|
-
})
|
|
384
|
-
} catch (err) {
|
|
385
|
-
return createErrorResult(err, { zipFilePath, extractToPath })
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// 文档提取功能,提取文件相关内容
|
|
390
|
-
async function extractFileContent(filePrompt, filePathList) {
|
|
391
|
-
try {
|
|
392
|
-
let result = []
|
|
393
|
-
for (const filePath of filePathList) {
|
|
394
|
-
const absolutePath = path.resolve(process.cwd(), filePath)
|
|
395
|
-
const fileName = path.basename(absolutePath)
|
|
396
|
-
if (!fs.existsSync(absolutePath) || !fs.statSync(absolutePath).isFile()) {
|
|
397
|
-
result.push({
|
|
398
|
-
filePath: absolutePath,
|
|
399
|
-
fileName,
|
|
400
|
-
errorContent: `File does not exist or is not a file: ${absolutePath}`,
|
|
401
|
-
})
|
|
402
|
-
}
|
|
403
|
-
const successContent = await this.Tools.createSubAgent(
|
|
404
|
-
`你是文件内容提取助手。请从文件 ${fileName}(路径:${absolutePath})中提取与“${filePrompt}”相关的内容。
|
|
405
|
-
要求:
|
|
406
|
-
1. 只返回与该主题直接相关的原文片段,保持原始语言与措辞。
|
|
407
|
-
2. 不要输出解释、总结、前后缀、Markdown 标记或任何额外说明。
|
|
408
|
-
3. 如果没有相关内容,只返回:null。`,
|
|
409
|
-
)
|
|
410
|
-
return createSuccessResult({
|
|
411
|
-
filePath: absolutePath,
|
|
412
|
-
fileName,
|
|
413
|
-
successContent,
|
|
414
|
-
})
|
|
415
|
-
}
|
|
416
|
-
} catch (error) {
|
|
417
|
-
return createErrorResult(error, null)
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const descriptions = [
|
|
422
|
-
{
|
|
423
|
-
type: 'function',
|
|
424
|
-
function: {
|
|
425
|
-
name: 'createFile',
|
|
426
|
-
description:
|
|
427
|
-
'创建一个包含指定内容的新文件。参数:filePath 为目标文件路径;content 为要写入的文件内容。返回值:对象,包含 success(是否成功)、data(成功数据)、error(失败错误信息);若目录不存在会自动创建目录结构。',
|
|
428
|
-
parameters: {
|
|
429
|
-
type: 'object',
|
|
430
|
-
properties: {
|
|
431
|
-
filePath: { type: 'string', description: '目标文件路径。' },
|
|
432
|
-
content: { type: 'string', description: '要写入的文件内容。' },
|
|
433
|
-
},
|
|
434
|
-
required: ['filePath', 'content'],
|
|
435
|
-
},
|
|
436
|
-
},
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
type: 'function',
|
|
440
|
-
function: {
|
|
441
|
-
name: 'modifyFile',
|
|
442
|
-
description:
|
|
443
|
-
'修改指定文件的内容。参数:filePath 为目标文件路径;content 为新的完整文件内容。返回值:对象,包含 success、data、error;如果文件不存在会在 error 中返回原因。',
|
|
444
|
-
parameters: {
|
|
445
|
-
type: 'object',
|
|
446
|
-
properties: {
|
|
447
|
-
filePath: { type: 'string', description: '目标文件路径。' },
|
|
448
|
-
content: { type: 'string', description: '新的完整文件内容。' },
|
|
449
|
-
},
|
|
450
|
-
required: ['filePath', 'content'],
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
type: 'function',
|
|
456
|
-
function: {
|
|
457
|
-
name: 'readFile',
|
|
458
|
-
description:
|
|
459
|
-
'读取指定文件的内容。参数:filePath 为要读取的文件路径。返回值:对象,包含 success、data(含 content)、error;如果文件不存在或读取失败会在 error 中返回原因。',
|
|
460
|
-
parameters: {
|
|
461
|
-
type: 'object',
|
|
462
|
-
properties: {
|
|
463
|
-
filePath: { type: 'string', description: '要读取的文件路径。' },
|
|
464
|
-
},
|
|
465
|
-
required: ['filePath'],
|
|
466
|
-
},
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
{
|
|
470
|
-
type: 'function',
|
|
471
|
-
function: {
|
|
472
|
-
name: 'appendToFile',
|
|
473
|
-
description:
|
|
474
|
-
'向指定文件追加内容。参数:filePath 为目标文件路径;content 为要追加的文本内容。返回值:对象,包含 success、data、error;如果文件不存在会在 error 中返回原因。',
|
|
475
|
-
parameters: {
|
|
476
|
-
type: 'object',
|
|
477
|
-
properties: {
|
|
478
|
-
filePath: { type: 'string', description: '目标文件路径。' },
|
|
479
|
-
content: { type: 'string', description: '要追加的文本内容。' },
|
|
480
|
-
},
|
|
481
|
-
required: ['filePath', 'content'],
|
|
482
|
-
},
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
type: 'function',
|
|
487
|
-
function: {
|
|
488
|
-
name: 'fileExists',
|
|
489
|
-
description:
|
|
490
|
-
'检查指定文件是否存在。参数:filePath 为待检查的文件路径。返回值:对象,包含 success、data(含 exists 布尔值)、error。',
|
|
491
|
-
parameters: {
|
|
492
|
-
type: 'object',
|
|
493
|
-
properties: {
|
|
494
|
-
filePath: { type: 'string', description: '待检查的文件路径。' },
|
|
495
|
-
},
|
|
496
|
-
required: ['filePath'],
|
|
497
|
-
},
|
|
498
|
-
},
|
|
499
|
-
},
|
|
500
|
-
{
|
|
501
|
-
type: 'function',
|
|
502
|
-
function: {
|
|
503
|
-
name: 'createDirectory',
|
|
504
|
-
description:
|
|
505
|
-
'创建一个新目录。参数:dirPath 为目标目录路径。返回值:对象,包含 success、data、error;支持递归创建目录结构。',
|
|
506
|
-
parameters: {
|
|
507
|
-
type: 'object',
|
|
508
|
-
properties: {
|
|
509
|
-
dirPath: { type: 'string', description: '目标目录路径。' },
|
|
510
|
-
},
|
|
511
|
-
required: ['dirPath'],
|
|
512
|
-
},
|
|
513
|
-
},
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
type: 'function',
|
|
517
|
-
function: {
|
|
518
|
-
name: 'deleteFile',
|
|
519
|
-
description:
|
|
520
|
-
'删除指定文件。参数:filePath 为要删除的文件路径。返回值:对象,包含 success、data、error。',
|
|
521
|
-
parameters: {
|
|
522
|
-
type: 'object',
|
|
523
|
-
properties: {
|
|
524
|
-
filePath: { type: 'string', description: '要删除的文件路径。' },
|
|
525
|
-
},
|
|
526
|
-
required: ['filePath'],
|
|
527
|
-
},
|
|
528
|
-
},
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
type: 'function',
|
|
532
|
-
function: {
|
|
533
|
-
name: 'deleteDirectory',
|
|
534
|
-
description:
|
|
535
|
-
'删除指定目录。参数:dirPath 为要删除的目录路径。返回值:对象,包含 success、data、error;支持递归删除目录及其内容。',
|
|
536
|
-
parameters: {
|
|
537
|
-
type: 'object',
|
|
538
|
-
properties: {
|
|
539
|
-
dirPath: { type: 'string', description: '要删除的目录路径。' },
|
|
540
|
-
},
|
|
541
|
-
required: ['dirPath'],
|
|
542
|
-
},
|
|
543
|
-
},
|
|
544
|
-
},
|
|
545
|
-
{
|
|
546
|
-
type: 'function',
|
|
547
|
-
function: {
|
|
548
|
-
name: 'rename',
|
|
549
|
-
description:
|
|
550
|
-
'重命名文件或目录。参数:oldPath 为原路径;newPath 为新路径。返回值:对象,包含 success、data、error;如果原路径不存在会在 error 中返回原因。',
|
|
551
|
-
parameters: {
|
|
552
|
-
type: 'object',
|
|
553
|
-
properties: {
|
|
554
|
-
oldPath: { type: 'string', description: '原文件或目录路径。' },
|
|
555
|
-
newPath: { type: 'string', description: '新的文件或目录路径。' },
|
|
556
|
-
},
|
|
557
|
-
required: ['oldPath', 'newPath'],
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
{
|
|
562
|
-
type: 'function',
|
|
563
|
-
function: {
|
|
564
|
-
name: 'copyFile',
|
|
565
|
-
description:
|
|
566
|
-
'复制文件。参数:sourcePath 为源文件路径;destinationPath 为目标文件路径。返回值:对象,包含 success、data、error;如果目标目录不存在会自动创建;如果源文件不存在会在 error 中返回原因。',
|
|
567
|
-
parameters: {
|
|
568
|
-
type: 'object',
|
|
569
|
-
properties: {
|
|
570
|
-
sourcePath: { type: 'string', description: '源文件路径。' },
|
|
571
|
-
destinationPath: { type: 'string', description: '目标文件路径。' },
|
|
572
|
-
},
|
|
573
|
-
required: ['sourcePath', 'destinationPath'],
|
|
574
|
-
},
|
|
575
|
-
},
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
type: 'function',
|
|
579
|
-
function: {
|
|
580
|
-
name: 'moveFile',
|
|
581
|
-
description:
|
|
582
|
-
'移动文件。参数:sourcePath 为源文件路径;destinationPath 为目标文件路径。返回值:对象,包含 success、data、error;如果目标目录不存在会自动创建;如果源文件不存在会在 error 中返回原因。',
|
|
583
|
-
parameters: {
|
|
584
|
-
type: 'object',
|
|
585
|
-
properties: {
|
|
586
|
-
sourcePath: { type: 'string', description: '源文件路径。' },
|
|
587
|
-
destinationPath: { type: 'string', description: '目标文件路径。' },
|
|
588
|
-
},
|
|
589
|
-
required: ['sourcePath', 'destinationPath'],
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
{
|
|
594
|
-
type: 'function',
|
|
595
|
-
function: {
|
|
596
|
-
name: 'getFileInfo',
|
|
597
|
-
description:
|
|
598
|
-
'获取指定文件的信息。参数:filePath 为目标文件路径。返回值:对象,包含 success、data(含 path、size、birthtime、mtime、ctime、isFile、isDirectory 等属性)、error。',
|
|
599
|
-
parameters: {
|
|
600
|
-
type: 'object',
|
|
601
|
-
properties: {
|
|
602
|
-
filePath: { type: 'string', description: '目标文件路径。' },
|
|
603
|
-
},
|
|
604
|
-
required: ['filePath'],
|
|
605
|
-
},
|
|
606
|
-
},
|
|
607
|
-
},
|
|
608
|
-
{
|
|
609
|
-
type: 'function',
|
|
610
|
-
function: {
|
|
611
|
-
name: 'getFileNameList',
|
|
612
|
-
description:
|
|
613
|
-
'获取指定目录下的所有文件名。参数:dirPath 为目标目录路径。返回值:对象,包含 success、data(含 files 数组)、error;如果目录不存在或不是目录会在 error 中返回原因。',
|
|
614
|
-
parameters: {
|
|
615
|
-
type: 'object',
|
|
616
|
-
properties: {
|
|
617
|
-
dirPath: { type: 'string', description: '目标目录路径。' },
|
|
618
|
-
},
|
|
619
|
-
required: ['dirPath'],
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
type: 'function',
|
|
625
|
-
function: {
|
|
626
|
-
name: 'clearDirectory',
|
|
627
|
-
description:
|
|
628
|
-
'清空指定目录的内容。参数:dirPath 为要清空的目录路径。返回值:对象,包含 success、data、error;如果目录不存在或不是目录会在 error 中返回原因。',
|
|
629
|
-
parameters: {
|
|
630
|
-
type: 'object',
|
|
631
|
-
properties: {
|
|
632
|
-
dirPath: { type: 'string', description: '要清空的目录路径。' },
|
|
633
|
-
},
|
|
634
|
-
required: ['dirPath'],
|
|
635
|
-
},
|
|
636
|
-
},
|
|
637
|
-
},
|
|
638
|
-
{
|
|
639
|
-
type: 'function',
|
|
640
|
-
function: {
|
|
641
|
-
name: 'replaceFileText',
|
|
642
|
-
description:
|
|
643
|
-
'替换文件中的文本。参数:filePath 为目标文件路径;searchValue 为查找文本或正则表达式字符串;replaceValue 为替换内容;isGlobal 控制是否全局替换(仅当 searchValue 为字符串时生效,默认 true)。返回值:对象,包含 success、data、error。',
|
|
644
|
-
parameters: {
|
|
645
|
-
type: 'object',
|
|
646
|
-
properties: {
|
|
647
|
-
filePath: {
|
|
648
|
-
type: 'string',
|
|
649
|
-
description: '目标文件路径。',
|
|
650
|
-
},
|
|
651
|
-
searchValue: {
|
|
652
|
-
type: 'string',
|
|
653
|
-
description:
|
|
654
|
-
'要查找的文本内容,支持按普通字符串或正则表达式字符串理解。',
|
|
655
|
-
},
|
|
656
|
-
replaceValue: {
|
|
657
|
-
type: 'string',
|
|
658
|
-
description: '用于替换匹配内容的新文本。',
|
|
659
|
-
},
|
|
660
|
-
isGlobal: {
|
|
661
|
-
type: 'boolean',
|
|
662
|
-
description: '是否执行全局替换,默认值为 true。',
|
|
663
|
-
},
|
|
664
|
-
},
|
|
665
|
-
required: ['filePath', 'searchValue', 'replaceValue'],
|
|
666
|
-
},
|
|
667
|
-
},
|
|
668
|
-
},
|
|
669
|
-
{
|
|
670
|
-
type: 'function',
|
|
671
|
-
function: {
|
|
672
|
-
name: 'compressToZip',
|
|
673
|
-
description:
|
|
674
|
-
'压缩文件或文件夹为 zip 格式。参数:inputPath 为待压缩的文件或目录路径;outputZipPath 为输出 zip 文件路径。返回值:对象,包含 success、data、error;支持中文、多层目录。',
|
|
675
|
-
parameters: {
|
|
676
|
-
type: 'object',
|
|
677
|
-
properties: {
|
|
678
|
-
inputPath: {
|
|
679
|
-
type: 'string',
|
|
680
|
-
description: '要压缩的文件或文件夹路径。',
|
|
681
|
-
},
|
|
682
|
-
outputZipPath: {
|
|
683
|
-
type: 'string',
|
|
684
|
-
description: '生成的 zip 文件输出路径。',
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
required: ['inputPath', 'outputZipPath'],
|
|
688
|
-
},
|
|
689
|
-
},
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
type: 'function',
|
|
693
|
-
function: {
|
|
694
|
-
name: 'extractZip',
|
|
695
|
-
description:
|
|
696
|
-
'解压 zip 文件。参数:zipFilePath 为待解压的 zip 文件路径;extractToPath 为解压目标目录。返回值:对象,包含 success、data、error;支持密码、中文不乱码。',
|
|
697
|
-
parameters: {
|
|
698
|
-
type: 'object',
|
|
699
|
-
properties: {
|
|
700
|
-
zipFilePath: {
|
|
701
|
-
type: 'string',
|
|
702
|
-
description: '待解压的 zip 文件路径。',
|
|
703
|
-
},
|
|
704
|
-
extractToPath: {
|
|
705
|
-
type: 'string',
|
|
706
|
-
description: '解压后的目标目录路径。',
|
|
707
|
-
},
|
|
708
|
-
},
|
|
709
|
-
required: ['zipFilePath', 'extractToPath'],
|
|
710
|
-
},
|
|
711
|
-
},
|
|
712
|
-
},
|
|
713
|
-
{
|
|
714
|
-
type: 'function',
|
|
715
|
-
function: {
|
|
716
|
-
name: 'extractFileContent',
|
|
717
|
-
description:
|
|
718
|
-
'根据给定提示词从文件列表中提取相关内容。参数:filePrompt 为提取主题;filePathList 为待提取的文件路径数组。返回值:对象,包含 success、data(含 filePath、fileName、successContent)或 error。',
|
|
719
|
-
parameters: {
|
|
720
|
-
type: 'object',
|
|
721
|
-
properties: {
|
|
722
|
-
filePrompt: {
|
|
723
|
-
type: 'string',
|
|
724
|
-
description: '需要提取的主题或关键描述。',
|
|
725
|
-
},
|
|
726
|
-
filePathList: {
|
|
727
|
-
type: 'array',
|
|
728
|
-
items: { type: 'string' },
|
|
729
|
-
description: '待提取内容的文件路径数组。',
|
|
730
|
-
},
|
|
731
|
-
},
|
|
732
|
-
required: ['filePrompt', 'filePathList'],
|
|
733
|
-
},
|
|
734
|
-
},
|
|
735
|
-
},
|
|
736
|
-
]
|
|
737
|
-
|
|
738
|
-
const functions = {
|
|
739
|
-
createFile,
|
|
740
|
-
modifyFile,
|
|
741
|
-
readFile,
|
|
742
|
-
replaceFileText,
|
|
743
|
-
appendToFile,
|
|
744
|
-
fileExists,
|
|
745
|
-
createDirectory,
|
|
746
|
-
deleteFile,
|
|
747
|
-
deleteDirectory,
|
|
748
|
-
rename,
|
|
749
|
-
moveFile,
|
|
750
|
-
getFileInfo,
|
|
751
|
-
getFileNameList,
|
|
752
|
-
clearDirectory,
|
|
753
|
-
compressToZip,
|
|
754
|
-
extractZip,
|
|
755
|
-
copyFile,
|
|
756
|
-
extractFileContent,
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
const FileTool = {
|
|
760
|
-
name: 'FileTool',
|
|
761
|
-
description:
|
|
762
|
-
'提供文件和目录的创建、读取、修改、删除、移动、重命名、信息获取等文件系统操作功能',
|
|
763
|
-
descriptions,
|
|
764
|
-
functions,
|
|
765
|
-
isSystem: true,
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
module.exports = FileTool
|