deepfish-ai 1.0.8
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 +21 -0
- package/README.md +344 -0
- package/README_CN.md +344 -0
- package/package.json +56 -0
- package/src/cli.js +650 -0
- package/src/core/AICLI.js +93 -0
- package/src/core/DefaultConfig.js +14 -0
- package/src/core/GlobalVariable.js +10 -0
- package/src/core/ai-services/AIService.js +25 -0
- package/src/core/ai-services/AiWorker/AIMessageManager.js +155 -0
- package/src/core/ai-services/AiWorker/AiAgent.js +151 -0
- package/src/core/ai-services/AiWorker/AiPrompt.js +37 -0
- package/src/core/ai-services/AiWorker/AiRecorder.js +120 -0
- package/src/core/ai-services/AiWorker/AiTools.js +219 -0
- package/src/core/ai-services/AiWorker/index.js +88 -0
- package/src/core/extension/BaseExtension.js +7 -0
- package/src/core/extension/DefaultExtension.js +696 -0
- package/src/core/extension/ExtensionManager.js +172 -0
- package/src/core/utils.js +261 -0
- package/src/index.js +7 -0
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { logError, logSuccess, logInfo, getConfigPath } = require("../utils");
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const shelljs = require("shelljs");
|
|
5
|
+
const iconv = require("iconv-lite"); // 用于编码转换
|
|
6
|
+
const os = require("os"); // 用于判断系统类型
|
|
7
|
+
const { cloneDeep } = require("lodash");
|
|
8
|
+
const { aiRequestSingle } = require("../ai-services/AiWorker/AiTools");
|
|
9
|
+
|
|
10
|
+
// 执行系统命令
|
|
11
|
+
// 执行系统命令(全平台兼容:Windows/PowerShell/CentOS)
|
|
12
|
+
async function executeCommand(command) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
logSuccess(`Executing system command: ${command}`);
|
|
15
|
+
const platform = os.platform();
|
|
16
|
+
const targetEncoding = platform === "win32" ? "gbk" : "utf-8"; // Windows(含PowerShell)用gbk,Linux/macOS用utf-8
|
|
17
|
+
shelljs.exec(
|
|
18
|
+
command,
|
|
19
|
+
{
|
|
20
|
+
async: true,
|
|
21
|
+
cwd: process.cwd(),
|
|
22
|
+
encoding: "binary",
|
|
23
|
+
silent: true,
|
|
24
|
+
},
|
|
25
|
+
(code, stdout, stderr) => {
|
|
26
|
+
try {
|
|
27
|
+
let stdoutUtf8 = iconv.decode(
|
|
28
|
+
Buffer.from(stdout, "binary"),
|
|
29
|
+
targetEncoding,
|
|
30
|
+
);
|
|
31
|
+
const stderrUtf8 = iconv.decode(
|
|
32
|
+
Buffer.from(stderr, "binary"),
|
|
33
|
+
targetEncoding,
|
|
34
|
+
);
|
|
35
|
+
if (stderrUtf8 && !stderrUtf8.trim().startsWith("WARNING")) {
|
|
36
|
+
// 过滤无关警告
|
|
37
|
+
const error = new Error(
|
|
38
|
+
`Command failed (code ${code}): ${stderrUtf8}`,
|
|
39
|
+
);
|
|
40
|
+
logError(`Execute error: ${error.message}`);
|
|
41
|
+
reject(error);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (stdoutUtf8 === "undefined") {
|
|
45
|
+
stdoutUtf8 = "";
|
|
46
|
+
}
|
|
47
|
+
logSuccess(`${stdoutUtf8} \n Command executed successfully`);
|
|
48
|
+
resolve(stdoutUtf8 || "Command executed successfully");
|
|
49
|
+
} catch (decodeError) {
|
|
50
|
+
logError(`Encoding convert error: ${decodeError.message}`);
|
|
51
|
+
reject(
|
|
52
|
+
new Error(`Failed to parse command output: ${decodeError.message}`),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 请求ai服务
|
|
61
|
+
async function requestAI(
|
|
62
|
+
systemDescription,
|
|
63
|
+
prompt,
|
|
64
|
+
temperature = this.aiConfig.temperature,
|
|
65
|
+
) {
|
|
66
|
+
logSuccess(`Requesting AI`);
|
|
67
|
+
if (
|
|
68
|
+
typeof systemDescription === "object" &&
|
|
69
|
+
systemDescription.systemDescription
|
|
70
|
+
) {
|
|
71
|
+
prompt = systemDescription.prompt || prompt || "";
|
|
72
|
+
systemDescription = systemDescription.systemDescription || "";
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
logInfo(`aiSystem: ${systemDescription}`);
|
|
76
|
+
logInfo(`aiPrompt: ${prompt}`);
|
|
77
|
+
let aiConfig = this.aiConfig;
|
|
78
|
+
if (temperature !== aiConfig.temperature) {
|
|
79
|
+
aiConfig = cloneDeep(aiConfig);
|
|
80
|
+
aiConfig.temperature = temperature;
|
|
81
|
+
}
|
|
82
|
+
const response = await aiRequestSingle(
|
|
83
|
+
this.aiService.client,
|
|
84
|
+
aiConfig,
|
|
85
|
+
systemDescription,
|
|
86
|
+
prompt,
|
|
87
|
+
);
|
|
88
|
+
logInfo(`aiResponse: ${response}`);
|
|
89
|
+
return response;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logError(`Error executing AI function: ${error.message}`);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 执行js代码
|
|
97
|
+
async function executeJSCode(code) {
|
|
98
|
+
logSuccess("Executing JavaScript code: ");
|
|
99
|
+
logSuccess(code);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const { functions } = this.extensionManager.extensions;
|
|
103
|
+
const Func = new Function(
|
|
104
|
+
"Tools",
|
|
105
|
+
"require",
|
|
106
|
+
"return (async () => { " + code + " })()",
|
|
107
|
+
);
|
|
108
|
+
const originalRequire = require;
|
|
109
|
+
const newRequire = (modulePath) => {
|
|
110
|
+
if (modulePath.startsWith("./")) {
|
|
111
|
+
const resolvedPath = path.resolve(".", modulePath);
|
|
112
|
+
return originalRequire(resolvedPath);
|
|
113
|
+
}
|
|
114
|
+
return originalRequire(modulePath);
|
|
115
|
+
};
|
|
116
|
+
const result = await Func(functions, newRequire);
|
|
117
|
+
return result || "";
|
|
118
|
+
} catch (error) {
|
|
119
|
+
logError(`Error executing code: ${error.stack}`);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// 生成一个扩展函数文件 关键字:内置函数、扩展工具
|
|
124
|
+
async function getExtensionFileRule(goal) {
|
|
125
|
+
const newGoal = `
|
|
126
|
+
创建一个js文件或一个包含主文件的node项目,使用逻辑清晰的nodejs代码完成用户目标: ${goal}。主函数输出两个字段:descriptions(openai能识别的函数描述)和functions(key为函数名称,value为方法体的对象)。注意:1.函数体的参数必须与descriptions中描述的参数一致,可以包含一个或多个可以被AI工作流调用的函数。2.函数名称开头增加"领域用途+分隔符"作为命名空间,函数描述的开头使用统一的自然语言”领域用途+分隔符“来描述。3.函数中可以直接调用requestAI、executeCommand和其他内置文件处理类函数,程序运行中将内置函数自动注入到this.Tools中,如this.Tools.requestAI(systemDescription, prompt, temperature)、this.Tools.readFile(filePath),如下所示:
|
|
127
|
+
“”“
|
|
128
|
+
const descriptions = []
|
|
129
|
+
const functions = {}
|
|
130
|
+
module.exports = {
|
|
131
|
+
descriptions,
|
|
132
|
+
functions,
|
|
133
|
+
}
|
|
134
|
+
”“”
|
|
135
|
+
以下是示例:
|
|
136
|
+
“”“
|
|
137
|
+
const descriptions = [
|
|
138
|
+
{
|
|
139
|
+
name: 'systemFileManagement_renameFile',
|
|
140
|
+
description: '系统文件管理:重命名文件',
|
|
141
|
+
parameters: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
oldPath: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
description: '旧文件路径',
|
|
147
|
+
},
|
|
148
|
+
newPath: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: '新文件路径',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
]
|
|
156
|
+
const functions = {
|
|
157
|
+
systemFileManagement_renameFile: (oldPath, newPath) => {
|
|
158
|
+
return this.Tools.rename(oldPath, newPath)
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
module.exports = {
|
|
162
|
+
descriptions,
|
|
163
|
+
functions,
|
|
164
|
+
}
|
|
165
|
+
”“”
|
|
166
|
+
|
|
167
|
+
`;
|
|
168
|
+
return newGoal;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 获取ai的配置
|
|
172
|
+
function getAiConfig() {
|
|
173
|
+
return cloneDeep(this.aiConfig);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 获取ai的配置文件所在目录
|
|
177
|
+
function getAiConfigPath() {
|
|
178
|
+
return getConfigPath();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function createFile(filePath, content) {
|
|
182
|
+
try {
|
|
183
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
184
|
+
const dirPath = path.dirname(fullPath);
|
|
185
|
+
|
|
186
|
+
if (!fs.existsSync(dirPath)) {
|
|
187
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
188
|
+
}
|
|
189
|
+
fs.writeFileSync(fullPath, content);
|
|
190
|
+
return true;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function modifyFile(filePath, content) {
|
|
197
|
+
try {
|
|
198
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
199
|
+
|
|
200
|
+
if (!fs.existsSync(fullPath)) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
fs.writeFileSync(fullPath, content);
|
|
205
|
+
return true;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function readFile(filePath) {
|
|
212
|
+
try {
|
|
213
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
214
|
+
|
|
215
|
+
if (!fs.existsSync(fullPath)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const content = fs.readFileSync(fullPath, "utf8");
|
|
220
|
+
return content;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function appendToFile(filePath, content) {
|
|
227
|
+
try {
|
|
228
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
229
|
+
|
|
230
|
+
if (!fs.existsSync(fullPath)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fs.appendFileSync(fullPath, content);
|
|
235
|
+
return true;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function fileExists(filePath) {
|
|
242
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
243
|
+
return fs.existsSync(fullPath);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function createDirectory(dirPath) {
|
|
247
|
+
try {
|
|
248
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
249
|
+
if (!fs.existsSync(fullPath)) {
|
|
250
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function deleteFile(filePath) {
|
|
259
|
+
try {
|
|
260
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
261
|
+
|
|
262
|
+
if (fs.existsSync(fullPath)) {
|
|
263
|
+
fs.unlinkSync(fullPath);
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function deleteDirectory(dirPath) {
|
|
272
|
+
try {
|
|
273
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
274
|
+
|
|
275
|
+
if (fs.existsSync(fullPath)) {
|
|
276
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function rename(oldPath, newPath) {
|
|
285
|
+
try {
|
|
286
|
+
const fullOldPath = path.resolve(process.cwd(), oldPath);
|
|
287
|
+
const fullNewPath = path.resolve(process.cwd(), newPath);
|
|
288
|
+
|
|
289
|
+
if (fs.existsSync(fullOldPath)) {
|
|
290
|
+
fs.renameSync(fullOldPath, fullNewPath);
|
|
291
|
+
}
|
|
292
|
+
return true;
|
|
293
|
+
} catch (error) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function moveFile(sourcePath, destinationPath) {
|
|
299
|
+
try {
|
|
300
|
+
const fullSourcePath = path.resolve(process.cwd(), sourcePath);
|
|
301
|
+
const fullDestPath = path.resolve(process.cwd(), destinationPath);
|
|
302
|
+
const destDirPath = path.dirname(fullDestPath);
|
|
303
|
+
|
|
304
|
+
if (!fs.existsSync(destDirPath)) {
|
|
305
|
+
fs.mkdirSync(destDirPath, { recursive: true });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (fs.existsSync(fullSourcePath)) {
|
|
309
|
+
fs.renameSync(fullSourcePath, fullDestPath);
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function getFileInfo(filePath) {
|
|
318
|
+
try {
|
|
319
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
320
|
+
|
|
321
|
+
if (!fs.existsSync(fullPath)) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const stats = fs.statSync(fullPath);
|
|
326
|
+
return {
|
|
327
|
+
path: fullPath,
|
|
328
|
+
size: stats.size,
|
|
329
|
+
birthtime: stats.birthtime,
|
|
330
|
+
mtime: stats.mtime,
|
|
331
|
+
ctime: stats.ctime,
|
|
332
|
+
isFile: stats.isFile(),
|
|
333
|
+
isDirectory: stats.isDirectory(),
|
|
334
|
+
};
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async function getFileNameList(dirPath) {
|
|
341
|
+
try {
|
|
342
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
343
|
+
if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isDirectory()) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
const files = fs
|
|
347
|
+
.readdirSync(fullPath)
|
|
348
|
+
.filter((file) => file !== "ai-history" && file !== "ai-log");
|
|
349
|
+
return files;
|
|
350
|
+
} catch (error) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async function clearDirectory(dirPath) {
|
|
356
|
+
try {
|
|
357
|
+
const fullPath = path.resolve(process.cwd(), dirPath);
|
|
358
|
+
|
|
359
|
+
if (!fs.existsSync(fullPath)) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (!fs.statSync(fullPath).isDirectory()) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const files = fs.readdirSync(fullPath);
|
|
368
|
+
|
|
369
|
+
for (const file of files) {
|
|
370
|
+
const filePath = path.join(fullPath, file);
|
|
371
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
372
|
+
fs.rmSync(filePath, { recursive: true, force: true });
|
|
373
|
+
} else {
|
|
374
|
+
fs.unlinkSync(filePath);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return true;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const descriptions = [
|
|
385
|
+
{
|
|
386
|
+
type: "function",
|
|
387
|
+
function: {
|
|
388
|
+
name: "executeCommand",
|
|
389
|
+
description:
|
|
390
|
+
'执行系统命令,返回执行结果。适用于运行shell命令、系统工具等。命令执行失败时会抛出错误,成功时返回命令执行结果字符串或"System command executed successfully"。',
|
|
391
|
+
parameters: {
|
|
392
|
+
type: "object",
|
|
393
|
+
properties: {
|
|
394
|
+
command: { type: "string" },
|
|
395
|
+
},
|
|
396
|
+
required: ["command"],
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
type: "function",
|
|
402
|
+
function: {
|
|
403
|
+
name: "requestAI",
|
|
404
|
+
description:
|
|
405
|
+
"请求AI服务处理简单任务,如随机生成一段话、翻译文本、数学计算、代码分析、知识检索等。通过systemDescription参数指定AI的行为和限制,prompt参数输入任务描述, temperature参数指定AI的温度(0-2之间的浮点数,默认为用户配置)。返回AI处理后的结果字符串,执行失败时会抛出错误。",
|
|
406
|
+
parameters: {
|
|
407
|
+
type: "object",
|
|
408
|
+
properties: {
|
|
409
|
+
systemDescription: { type: "string" },
|
|
410
|
+
prompt: { type: "string" },
|
|
411
|
+
temperature: { type: "number" },
|
|
412
|
+
},
|
|
413
|
+
required: ["systemDescription", "prompt"],
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
type: "function",
|
|
419
|
+
function: {
|
|
420
|
+
name: "executeJSCode",
|
|
421
|
+
description:
|
|
422
|
+
'执行JavaScript代码,返回代码执行结果。代码中可通过Tools命名空间直接调用其他工具函数(如await Tools.createFile(),注意:不需要使用require引入),Tools中引入了一些常用库可直接调用(Tools.fs="fs-extra", Tool.dayjs="dayjs", Tool.axios="axios", Tool.lodash="lodash"),支持引入自定义模块(需使用绝对路径)。注意:1.代码中不要使用__dirname获取当前目录,请使用path.resolve(".")来获取当前目录。2.console.log打印的结果不能被程序捕获,代码体需要使用return来返回结果,不能通过控制台中打印捕获结果。3.执行失败时会抛出错误,成功时返回代码执行结果或空字符串。',
|
|
423
|
+
parameters: {
|
|
424
|
+
type: "object",
|
|
425
|
+
properties: {
|
|
426
|
+
code: { type: "string" },
|
|
427
|
+
},
|
|
428
|
+
required: ["code"],
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
type: "function",
|
|
434
|
+
function: {
|
|
435
|
+
name: "createFile",
|
|
436
|
+
description:
|
|
437
|
+
"创建一个包含指定内容的新文件,返回布尔值表示操作是否成功。如果目录不存在会自动创建目录结构。",
|
|
438
|
+
parameters: {
|
|
439
|
+
type: "object",
|
|
440
|
+
properties: {
|
|
441
|
+
filePath: { type: "string" },
|
|
442
|
+
content: { type: "string" },
|
|
443
|
+
},
|
|
444
|
+
required: ["filePath", "content"],
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
type: "function",
|
|
450
|
+
function: {
|
|
451
|
+
name: "modifyFile",
|
|
452
|
+
description:
|
|
453
|
+
"修改指定文件的内容,返回布尔值表示操作是否成功。如果文件不存在则返回false。",
|
|
454
|
+
parameters: {
|
|
455
|
+
type: "object",
|
|
456
|
+
properties: {
|
|
457
|
+
filePath: { type: "string" },
|
|
458
|
+
content: { type: "string" },
|
|
459
|
+
},
|
|
460
|
+
required: ["filePath", "content"],
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
type: "function",
|
|
466
|
+
function: {
|
|
467
|
+
name: "readFile",
|
|
468
|
+
description:
|
|
469
|
+
"读取指定文件的内容,返回文件内容字符串。如果文件不存在或读取失败则返回null。",
|
|
470
|
+
parameters: {
|
|
471
|
+
type: "object",
|
|
472
|
+
properties: {
|
|
473
|
+
filePath: { type: "string" },
|
|
474
|
+
},
|
|
475
|
+
required: ["filePath"],
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
type: "function",
|
|
481
|
+
function: {
|
|
482
|
+
name: "appendToFile",
|
|
483
|
+
description:
|
|
484
|
+
"向指定文件追加内容,返回布尔值表示操作是否成功。如果文件不存在则返回false。",
|
|
485
|
+
parameters: {
|
|
486
|
+
type: "object",
|
|
487
|
+
properties: {
|
|
488
|
+
filePath: { type: "string" },
|
|
489
|
+
content: { type: "string" },
|
|
490
|
+
},
|
|
491
|
+
required: ["filePath", "content"],
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
type: "function",
|
|
497
|
+
function: {
|
|
498
|
+
name: "fileExists",
|
|
499
|
+
description: "检查指定文件是否存在,返回布尔值。",
|
|
500
|
+
parameters: {
|
|
501
|
+
type: "object",
|
|
502
|
+
properties: {
|
|
503
|
+
filePath: { type: "string" },
|
|
504
|
+
},
|
|
505
|
+
required: ["filePath"],
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
type: "function",
|
|
511
|
+
function: {
|
|
512
|
+
name: "createDirectory",
|
|
513
|
+
description:
|
|
514
|
+
"创建一个新目录,返回布尔值表示操作是否成功。支持递归创建目录结构。",
|
|
515
|
+
parameters: {
|
|
516
|
+
type: "object",
|
|
517
|
+
properties: {
|
|
518
|
+
dirPath: { type: "string" },
|
|
519
|
+
},
|
|
520
|
+
required: ["dirPath"],
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
type: "function",
|
|
526
|
+
function: {
|
|
527
|
+
name: "deleteFile",
|
|
528
|
+
description:
|
|
529
|
+
"删除指定文件,返回布尔值表示操作是否成功。如果文件不存在也会返回true。",
|
|
530
|
+
parameters: {
|
|
531
|
+
type: "object",
|
|
532
|
+
properties: {
|
|
533
|
+
filePath: { type: "string" },
|
|
534
|
+
},
|
|
535
|
+
required: ["filePath"],
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
type: "function",
|
|
541
|
+
function: {
|
|
542
|
+
name: "deleteDirectory",
|
|
543
|
+
description:
|
|
544
|
+
"删除指定目录,返回布尔值表示操作是否成功。支持递归删除目录及其内容。如果目录不存在也会返回true。",
|
|
545
|
+
parameters: {
|
|
546
|
+
type: "object",
|
|
547
|
+
properties: {
|
|
548
|
+
dirPath: { type: "string" },
|
|
549
|
+
},
|
|
550
|
+
required: ["dirPath"],
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
type: "function",
|
|
556
|
+
function: {
|
|
557
|
+
name: "rename",
|
|
558
|
+
description:
|
|
559
|
+
"重命名文件或目录,返回布尔值表示操作是否成功。如果原文件不存在也会返回true。",
|
|
560
|
+
parameters: {
|
|
561
|
+
type: "object",
|
|
562
|
+
properties: {
|
|
563
|
+
oldPath: { type: "string" },
|
|
564
|
+
newPath: { type: "string" },
|
|
565
|
+
},
|
|
566
|
+
required: ["oldPath", "newPath"],
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
type: "function",
|
|
572
|
+
function: {
|
|
573
|
+
name: "moveFile",
|
|
574
|
+
description:
|
|
575
|
+
"移动文件,返回布尔值表示操作是否成功。如果目标目录不存在会自动创建。如果源文件不存在也会返回true。",
|
|
576
|
+
parameters: {
|
|
577
|
+
type: "object",
|
|
578
|
+
properties: {
|
|
579
|
+
sourcePath: { type: "string" },
|
|
580
|
+
destinationPath: { type: "string" },
|
|
581
|
+
},
|
|
582
|
+
required: ["sourcePath", "destinationPath"],
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
type: "function",
|
|
588
|
+
function: {
|
|
589
|
+
name: "getFileInfo",
|
|
590
|
+
description:
|
|
591
|
+
"获取指定文件的信息,返回文件信息对象。如果文件不存在或获取失败则返回null。返回对象包含path、size、birthtime、mtime、ctime、isFile、isDirectory等属性。",
|
|
592
|
+
parameters: {
|
|
593
|
+
type: "object",
|
|
594
|
+
properties: {
|
|
595
|
+
filePath: { type: "string" },
|
|
596
|
+
},
|
|
597
|
+
required: ["filePath"],
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
type: "function",
|
|
603
|
+
function: {
|
|
604
|
+
name: "getFileNameList",
|
|
605
|
+
description:
|
|
606
|
+
"获取指定目录下的所有文件名,返回文件名数组。如果目录不存在或不是目录则返回空数组。",
|
|
607
|
+
parameters: {
|
|
608
|
+
type: "object",
|
|
609
|
+
properties: {
|
|
610
|
+
dirPath: { type: "string" },
|
|
611
|
+
},
|
|
612
|
+
required: ["dirPath"],
|
|
613
|
+
},
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
type: "function",
|
|
618
|
+
function: {
|
|
619
|
+
name: "clearDirectory",
|
|
620
|
+
description:
|
|
621
|
+
"清空指定目录的内容,返回布尔值表示操作是否成功。如果目录不存在或不是目录则返回false。",
|
|
622
|
+
parameters: {
|
|
623
|
+
type: "object",
|
|
624
|
+
properties: {
|
|
625
|
+
dirPath: { type: "string" },
|
|
626
|
+
},
|
|
627
|
+
required: ["dirPath"],
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
type: "function",
|
|
633
|
+
function: {
|
|
634
|
+
name: "getExtensionFileRule",
|
|
635
|
+
description:
|
|
636
|
+
"如果用户需要为本程序ai工作流生成一个或多个工具函数作为一个工作流执行过程中调用的扩展工具,则需要先调用此函数获取生成扩展文件的规则;示例:生成一个扩展工具: 能够产生一个随机数的函数;",
|
|
637
|
+
parameters: {
|
|
638
|
+
type: "object",
|
|
639
|
+
properties: {
|
|
640
|
+
goal: { type: "string" },
|
|
641
|
+
},
|
|
642
|
+
required: ["goal"],
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
type: "function",
|
|
648
|
+
function: {
|
|
649
|
+
name: "getAiConfig",
|
|
650
|
+
description: "获取ai的配置参数",
|
|
651
|
+
parameters: {
|
|
652
|
+
type: "object",
|
|
653
|
+
properties: {},
|
|
654
|
+
required: [],
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
type: "function",
|
|
660
|
+
function: {
|
|
661
|
+
name: "getAiConfigPath",
|
|
662
|
+
description: "获取ai的配置文件地址",
|
|
663
|
+
parameters: {
|
|
664
|
+
type: "object",
|
|
665
|
+
properties: {},
|
|
666
|
+
required: [],
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
];
|
|
671
|
+
const functions = {
|
|
672
|
+
executeCommand,
|
|
673
|
+
requestAI,
|
|
674
|
+
executeJSCode,
|
|
675
|
+
createFile,
|
|
676
|
+
modifyFile,
|
|
677
|
+
readFile,
|
|
678
|
+
appendToFile,
|
|
679
|
+
fileExists,
|
|
680
|
+
createDirectory,
|
|
681
|
+
deleteFile,
|
|
682
|
+
deleteDirectory,
|
|
683
|
+
rename,
|
|
684
|
+
moveFile,
|
|
685
|
+
getFileInfo,
|
|
686
|
+
getFileNameList,
|
|
687
|
+
clearDirectory,
|
|
688
|
+
getExtensionFileRule,
|
|
689
|
+
getAiConfig,
|
|
690
|
+
getAiConfigPath,
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
module.exports = {
|
|
694
|
+
descriptions,
|
|
695
|
+
functions,
|
|
696
|
+
};
|