deepfish-ai 2.0.3 → 2.0.4
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/dist/index.js +454 -429
- package/dist/serve/pm2-server.js +312 -315
- package/package.json +1 -1
package/dist/serve/pm2-server.js
CHANGED
|
@@ -8703,7 +8703,7 @@ var import_fs_extra17 = __toESM(require("fs-extra"));
|
|
|
8703
8703
|
var import_path12 = __toESM(require("path"));
|
|
8704
8704
|
|
|
8705
8705
|
// src/agent/AIAgent/index.ts
|
|
8706
|
-
var
|
|
8706
|
+
var import_langchain16 = require("langchain");
|
|
8707
8707
|
var import_deepagents = require("deepagents");
|
|
8708
8708
|
|
|
8709
8709
|
// src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
|
|
@@ -23283,7 +23283,166 @@ var import_child_process = require("child_process");
|
|
|
23283
23283
|
var import_chardet = __toESM(require_lib());
|
|
23284
23284
|
var import_os3 = __toESM(require("os"));
|
|
23285
23285
|
var import_iconv_lite = __toESM(require("iconv-lite"));
|
|
23286
|
+
var import_langchain3 = require("langchain");
|
|
23287
|
+
|
|
23288
|
+
// src/agent/tools/utils.ts
|
|
23286
23289
|
var import_langchain2 = require("langchain");
|
|
23290
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
23291
|
+
|
|
23292
|
+
// src/agent/tools/fileTools.ts
|
|
23293
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
23294
|
+
var import_path5 = __toESM(require("path"));
|
|
23295
|
+
var DEFAULT_MAX_OUTPUT = 6e4;
|
|
23296
|
+
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
23297
|
+
".txt",
|
|
23298
|
+
".md",
|
|
23299
|
+
".json",
|
|
23300
|
+
".json5",
|
|
23301
|
+
".js",
|
|
23302
|
+
".jsx",
|
|
23303
|
+
".ts",
|
|
23304
|
+
".tsx",
|
|
23305
|
+
".mjs",
|
|
23306
|
+
".cjs",
|
|
23307
|
+
".css",
|
|
23308
|
+
".less",
|
|
23309
|
+
".scss",
|
|
23310
|
+
".html",
|
|
23311
|
+
".xml",
|
|
23312
|
+
".yaml",
|
|
23313
|
+
".yml",
|
|
23314
|
+
".toml",
|
|
23315
|
+
".ini",
|
|
23316
|
+
".env",
|
|
23317
|
+
".gitignore",
|
|
23318
|
+
".sql",
|
|
23319
|
+
".py",
|
|
23320
|
+
".java",
|
|
23321
|
+
".c",
|
|
23322
|
+
".cpp",
|
|
23323
|
+
".h",
|
|
23324
|
+
".hpp",
|
|
23325
|
+
".cs",
|
|
23326
|
+
".go",
|
|
23327
|
+
".rs",
|
|
23328
|
+
".php",
|
|
23329
|
+
".rb",
|
|
23330
|
+
".sh",
|
|
23331
|
+
".bat",
|
|
23332
|
+
".ps1",
|
|
23333
|
+
".vue",
|
|
23334
|
+
".svelte",
|
|
23335
|
+
".log",
|
|
23336
|
+
".csv"
|
|
23337
|
+
]);
|
|
23338
|
+
function resolveWorkspacePath(inputPath, cwd = getTrueCwd()) {
|
|
23339
|
+
if (!inputPath?.trim()) {
|
|
23340
|
+
throw new Error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
23341
|
+
}
|
|
23342
|
+
return import_path5.default.resolve(cwd, inputPath);
|
|
23343
|
+
}
|
|
23344
|
+
function normalizePathForMatch(filePath) {
|
|
23345
|
+
return filePath.replace(/\\/g, "/");
|
|
23346
|
+
}
|
|
23347
|
+
function truncateOutput(content, maxLength = DEFAULT_MAX_OUTPUT) {
|
|
23348
|
+
if (content.length <= maxLength) {
|
|
23349
|
+
return content;
|
|
23350
|
+
}
|
|
23351
|
+
return `${content.slice(0, maxLength)}
|
|
23352
|
+
|
|
23353
|
+
[\u5185\u5BB9\u5DF2\u622A\u65AD\uFF0C\u4EC5\u663E\u793A\u524D ${maxLength} \u4E2A\u5B57\u7B26\uFF0C\u603B\u957F\u5EA6 ${content.length} \u4E2A\u5B57\u7B26]`;
|
|
23354
|
+
}
|
|
23355
|
+
function isProbablyTextFile(filePath) {
|
|
23356
|
+
const ext = import_path5.default.extname(filePath).toLowerCase();
|
|
23357
|
+
const base = import_path5.default.basename(filePath).toLowerCase();
|
|
23358
|
+
return TEXT_FILE_EXTENSIONS.has(ext) || TEXT_FILE_EXTENSIONS.has(base) || base.startsWith(".env");
|
|
23359
|
+
}
|
|
23360
|
+
function globToRegExp(pattern) {
|
|
23361
|
+
const normalized = normalizePathForMatch(pattern);
|
|
23362
|
+
let regex = "^";
|
|
23363
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
23364
|
+
const char = normalized[i];
|
|
23365
|
+
const next = normalized[i + 1];
|
|
23366
|
+
if (char === "*") {
|
|
23367
|
+
if (next === "*") {
|
|
23368
|
+
const after = normalized[i + 2];
|
|
23369
|
+
if (after === "/") {
|
|
23370
|
+
regex += "(?:.*/)?";
|
|
23371
|
+
i += 2;
|
|
23372
|
+
} else {
|
|
23373
|
+
regex += ".*";
|
|
23374
|
+
i += 1;
|
|
23375
|
+
}
|
|
23376
|
+
} else {
|
|
23377
|
+
regex += "[^/]*";
|
|
23378
|
+
}
|
|
23379
|
+
} else if (char === "?") {
|
|
23380
|
+
regex += "[^/]";
|
|
23381
|
+
} else {
|
|
23382
|
+
regex += char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
23383
|
+
}
|
|
23384
|
+
}
|
|
23385
|
+
regex += "$";
|
|
23386
|
+
return new RegExp(regex, "i");
|
|
23387
|
+
}
|
|
23388
|
+
function matchesGlob(relativePath, pattern) {
|
|
23389
|
+
return globToRegExp(pattern).test(normalizePathForMatch(relativePath));
|
|
23390
|
+
}
|
|
23391
|
+
async function walkFiles(rootDir, options = {}) {
|
|
23392
|
+
const files = [];
|
|
23393
|
+
const includeHidden = options.includeHidden ?? false;
|
|
23394
|
+
const maxFiles = options.maxFiles ?? 5e3;
|
|
23395
|
+
async function walk(currentDir) {
|
|
23396
|
+
if (files.length >= maxFiles) {
|
|
23397
|
+
return;
|
|
23398
|
+
}
|
|
23399
|
+
const entries = await import_fs_extra5.default.readdir(currentDir, { withFileTypes: true });
|
|
23400
|
+
for (const entry of entries) {
|
|
23401
|
+
if (files.length >= maxFiles) {
|
|
23402
|
+
return;
|
|
23403
|
+
}
|
|
23404
|
+
if (!includeHidden && entry.name.startsWith(".")) {
|
|
23405
|
+
continue;
|
|
23406
|
+
}
|
|
23407
|
+
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") {
|
|
23408
|
+
continue;
|
|
23409
|
+
}
|
|
23410
|
+
const fullPath = import_path5.default.join(currentDir, entry.name);
|
|
23411
|
+
if (entry.isDirectory()) {
|
|
23412
|
+
await walk(fullPath);
|
|
23413
|
+
} else if (entry.isFile()) {
|
|
23414
|
+
files.push(fullPath);
|
|
23415
|
+
}
|
|
23416
|
+
}
|
|
23417
|
+
}
|
|
23418
|
+
await walk(rootDir);
|
|
23419
|
+
return files;
|
|
23420
|
+
}
|
|
23421
|
+
function formatJson(data) {
|
|
23422
|
+
return JSON.stringify(data, null, 2);
|
|
23423
|
+
}
|
|
23424
|
+
|
|
23425
|
+
// src/agent/tools/utils.ts
|
|
23426
|
+
function successResult(data) {
|
|
23427
|
+
return { success: true, data };
|
|
23428
|
+
}
|
|
23429
|
+
function errorResult(error51, data) {
|
|
23430
|
+
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
23431
|
+
return data === void 0 ? { success: false, error: message } : { success: false, error: message, data };
|
|
23432
|
+
}
|
|
23433
|
+
function serializeToolResult(result) {
|
|
23434
|
+
return truncateOutput(JSON.stringify(result, null, 2));
|
|
23435
|
+
}
|
|
23436
|
+
async function safeTool(handler) {
|
|
23437
|
+
try {
|
|
23438
|
+
const data = await handler();
|
|
23439
|
+
return serializeToolResult(successResult(data));
|
|
23440
|
+
} catch (error51) {
|
|
23441
|
+
return serializeToolResult(errorResult(error51));
|
|
23442
|
+
}
|
|
23443
|
+
}
|
|
23444
|
+
|
|
23445
|
+
// src/agent/tools/executeCommand.ts
|
|
23287
23446
|
function executeCommand(command, timeout = -1, cwd) {
|
|
23288
23447
|
logSuccess(`Executing system command: ${command}; ${timeout > 0 ? `Timeout: ${timeout}ms` : "No timeout limit"}`);
|
|
23289
23448
|
try {
|
|
@@ -23303,16 +23462,14 @@ function executeCommand(command, timeout = -1, cwd) {
|
|
|
23303
23462
|
const stderr = import_iconv_lite.default.decode(result.stderr, targetEncoding);
|
|
23304
23463
|
const code = result.status;
|
|
23305
23464
|
if (stderr && !stderr.trim().startsWith("WARNING")) {
|
|
23306
|
-
|
|
23307
|
-
logError(`Execute error: ${error51.message}`);
|
|
23308
|
-
return `Execute error: ${error51.message}`;
|
|
23465
|
+
throw new Error(`Command failed (code ${code}): ${stderr.trim()}`);
|
|
23309
23466
|
}
|
|
23310
23467
|
logSuccess(`${stdout}
|
|
23311
23468
|
Command executed successfully`);
|
|
23312
23469
|
return stdout || "Command executed successfully";
|
|
23313
|
-
} catch (
|
|
23314
|
-
logError(`
|
|
23315
|
-
|
|
23470
|
+
} catch (error51) {
|
|
23471
|
+
logError(`Execute error: ${error51.message}`);
|
|
23472
|
+
throw error51;
|
|
23316
23473
|
}
|
|
23317
23474
|
}
|
|
23318
23475
|
function detectEncoding(buffer) {
|
|
@@ -23329,24 +23486,19 @@ function detectEncoding(buffer) {
|
|
|
23329
23486
|
}
|
|
23330
23487
|
return import_os3.default.platform() === "win32" ? "gbk" : "utf-8";
|
|
23331
23488
|
}
|
|
23332
|
-
var executeCommandTool = (0,
|
|
23333
|
-
|
|
23334
|
-
|
|
23335
|
-
|
|
23336
|
-
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
command: external_exports.string().describe("\u8981\u6267\u884C\u7684 shell \u547D\u4EE4"),
|
|
23341
|
-
timeout: external_exports.number().default(-1).describe("\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C-1 \u8868\u793A\u4E0D\u9650\u5236")
|
|
23342
|
-
})
|
|
23343
|
-
}
|
|
23344
|
-
);
|
|
23489
|
+
var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => safeTool(() => executeCommand(command, timeout)), {
|
|
23490
|
+
name: "execute_command",
|
|
23491
|
+
description: `\u5728\u672C\u5730\u7CFB\u7EDF(${import_os3.default.platform()})\u4E0A\u6267\u884C\u4E00\u6761 shell \u547D\u4EE4\u5E76\u8FD4\u56DE\u8F93\u51FA\u7ED3\u679C\u3002\u9002\u7528\u4E8Erunning\u811A\u672C\u3001\u64CD\u4F5C\u6587\u4EF6\u7CFB\u7EDF\u3001\u542F\u52A8\u8FDB\u7A0B\u7B49\u573A\u666F\u3002\u5FC5\u987B\u6CE8\u610F\u64CD\u4F5C\u7CFB\u7EDF\u7684\u517C\u5BB9\u6027\uFF0C\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u4E3A ${import_os3.default.platform()}\u3002`,
|
|
23492
|
+
schema: external_exports.object({
|
|
23493
|
+
command: external_exports.string().describe("\u8981\u6267\u884C\u7684 shell \u547D\u4EE4"),
|
|
23494
|
+
timeout: external_exports.number().default(-1).describe("\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C-1 \u8868\u793A\u4E0D\u9650\u5236")
|
|
23495
|
+
})
|
|
23496
|
+
});
|
|
23345
23497
|
|
|
23346
23498
|
// src/agent/tools/executeJSCode.ts
|
|
23347
|
-
var
|
|
23348
|
-
var
|
|
23349
|
-
var
|
|
23499
|
+
var import_langchain4 = require("langchain");
|
|
23500
|
+
var import_path6 = __toESM(require("path"));
|
|
23501
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
23350
23502
|
var _require = require;
|
|
23351
23503
|
async function executeJSCode(code) {
|
|
23352
23504
|
logInfo("Executing JavaScript code: ");
|
|
@@ -23365,25 +23517,25 @@ async function executeJSCode(code) {
|
|
|
23365
23517
|
throw error51;
|
|
23366
23518
|
}
|
|
23367
23519
|
}
|
|
23368
|
-
var getInstalledPackagesTool = (0,
|
|
23369
|
-
async () => {
|
|
23370
|
-
const packageJson =
|
|
23371
|
-
const pkg =
|
|
23372
|
-
return
|
|
23373
|
-
},
|
|
23520
|
+
var getInstalledPackagesTool = (0, import_langchain4.tool)(
|
|
23521
|
+
async () => safeTool(() => {
|
|
23522
|
+
const packageJson = import_path6.default.join(getCodePath(), "./package.json");
|
|
23523
|
+
const pkg = import_fs_extra7.default.readJsonSync(packageJson);
|
|
23524
|
+
return pkg.dependencies;
|
|
23525
|
+
}),
|
|
23374
23526
|
{
|
|
23375
23527
|
name: "get_installed_packages",
|
|
23376
23528
|
description: "\u83B7\u53D6 deepfish-ai CLI \u5DE5\u5177\u81EA\u8EAB\u5DF2\u5B89\u88C5\u7684 npm \u4F9D\u8D56\u5305\u5217\u8868",
|
|
23377
23529
|
schema: external_exports.object({})
|
|
23378
23530
|
}
|
|
23379
23531
|
);
|
|
23380
|
-
var checkPackageInstalledTool = (0,
|
|
23381
|
-
async ({ packageName }) => {
|
|
23382
|
-
const packageJson =
|
|
23383
|
-
const pkg =
|
|
23532
|
+
var checkPackageInstalledTool = (0, import_langchain4.tool)(
|
|
23533
|
+
async ({ packageName }) => safeTool(() => {
|
|
23534
|
+
const packageJson = import_path6.default.join(getCodePath(), "./package.json");
|
|
23535
|
+
const pkg = import_fs_extra7.default.readJsonSync(packageJson);
|
|
23384
23536
|
const installed = Object.prototype.hasOwnProperty.call(pkg.dependencies, packageName);
|
|
23385
|
-
return
|
|
23386
|
-
},
|
|
23537
|
+
return { packageName, installed };
|
|
23538
|
+
}),
|
|
23387
23539
|
{
|
|
23388
23540
|
name: "check_package_installed",
|
|
23389
23541
|
description: "\u68C0\u67E5\u6307\u5B9A\u7684 npm \u5305\u662F\u5426\u5DF2\u5728 deepfish-ai CLI \u5DE5\u5177\u4E2D\u5B89\u88C5",
|
|
@@ -23392,15 +23544,15 @@ var checkPackageInstalledTool = (0, import_langchain3.tool)(
|
|
|
23392
23544
|
})
|
|
23393
23545
|
}
|
|
23394
23546
|
);
|
|
23395
|
-
var installPackageTool = (0,
|
|
23396
|
-
async ({ packageName }) => {
|
|
23397
|
-
const packageJson =
|
|
23398
|
-
const pkg =
|
|
23547
|
+
var installPackageTool = (0, import_langchain4.tool)(
|
|
23548
|
+
async ({ packageName }) => safeTool(() => {
|
|
23549
|
+
const packageJson = import_path6.default.join(getCodePath(), "./package.json");
|
|
23550
|
+
const pkg = import_fs_extra7.default.readJsonSync(packageJson);
|
|
23399
23551
|
if (Object.prototype.hasOwnProperty.call(pkg.dependencies, packageName)) {
|
|
23400
23552
|
return `Package "${packageName}" is already installed.`;
|
|
23401
23553
|
}
|
|
23402
23554
|
return executeCommand(`npm install ${packageName}`, 12e4, getCodePath());
|
|
23403
|
-
},
|
|
23555
|
+
}),
|
|
23404
23556
|
{
|
|
23405
23557
|
name: "install_package",
|
|
23406
23558
|
description: "\u5728 deepfish-ai CLI \u5DE5\u5177\u4E2D\u5B89\u88C5\u6307\u5B9A\u7684 npm \u5305\uFF0C\u4F7F execute_js_code \u53EF\u4EE5 require \u8BE5\u5305",
|
|
@@ -23409,53 +23561,47 @@ var installPackageTool = (0, import_langchain3.tool)(
|
|
|
23409
23561
|
})
|
|
23410
23562
|
}
|
|
23411
23563
|
);
|
|
23412
|
-
var executeJSCodeTool = (0,
|
|
23413
|
-
|
|
23414
|
-
|
|
23415
|
-
return result;
|
|
23416
|
-
},
|
|
23417
|
-
{
|
|
23418
|
-
name: "execute_js_code",
|
|
23419
|
-
description: `\u6267\u884C\u4E00\u6BB5Node.js\u4EE3\u7801\u5E76\u8FD4\u56DE\u6267\u884C\u7ED3\u679C\u3002\u6CE8\u610F\uFF1A\u4EE3\u7801\u5FC5\u987B\u5305\u542B\u4E00\u4E2A__main()\u51FD\u6570\u4F5C\u4E3A\u6267\u884C\u5165\u53E3\uFF0C__main()\u51FD\u6570\u5185\u5FC5\u987B\u662F\u4E00\u4E2A\u4F7F\u7528async\u524D\u7F00\u7684\u51FD\u6570\u3002\u793A\u4F8B\u4EE3\u7801\uFF1A
|
|
23564
|
+
var executeJSCodeTool = (0, import_langchain4.tool)(async ({ code }) => safeTool(() => executeJSCode(code)), {
|
|
23565
|
+
name: "execute_js_code",
|
|
23566
|
+
description: `\u6267\u884C\u4E00\u6BB5Node.js\u4EE3\u7801\u5E76\u8FD4\u56DE\u6267\u884C\u7ED3\u679C\u3002\u6CE8\u610F\uFF1A\u4EE3\u7801\u5FC5\u987B\u5305\u542B\u4E00\u4E2A__main()\u51FD\u6570\u4F5C\u4E3A\u6267\u884C\u5165\u53E3\uFF0C__main()\u51FD\u6570\u5185\u5FC5\u987B\u662F\u4E00\u4E2A\u4F7F\u7528async\u524D\u7F00\u7684\u51FD\u6570\u3002\u793A\u4F8B\u4EE3\u7801\uFF1A
|
|
23420
23567
|
async function __main() {
|
|
23421
23568
|
const data = await fs.readFile("data.txt", "utf-8")
|
|
23422
23569
|
return data
|
|
23423
23570
|
}
|
|
23424
23571
|
`,
|
|
23425
|
-
|
|
23426
|
-
|
|
23427
|
-
|
|
23428
|
-
|
|
23429
|
-
);
|
|
23572
|
+
schema: external_exports.object({
|
|
23573
|
+
code: external_exports.string().describe("\u8981\u6267\u884C\u7684Node.js\u4EE3\u7801")
|
|
23574
|
+
})
|
|
23575
|
+
});
|
|
23430
23576
|
var packageTools = [getInstalledPackagesTool, checkPackageInstalledTool, installPackageTool, executeJSCodeTool];
|
|
23431
23577
|
|
|
23432
23578
|
// src/cli/cli-utils/UserCache.ts
|
|
23433
|
-
var
|
|
23434
|
-
var
|
|
23579
|
+
var import_path7 = __toESM(require("path"));
|
|
23580
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
23435
23581
|
var import_crypto = require("crypto");
|
|
23436
23582
|
var UserCache = class {
|
|
23437
23583
|
cacheDir;
|
|
23438
23584
|
catalogPath;
|
|
23439
23585
|
constructor() {
|
|
23440
23586
|
const cacheDir = getUserStorePath();
|
|
23441
|
-
const catalog =
|
|
23442
|
-
|
|
23587
|
+
const catalog = import_path7.default.join(cacheDir, "catalog.json");
|
|
23588
|
+
import_fs_extra8.default.ensureFileSync(catalog);
|
|
23443
23589
|
this.cacheDir = cacheDir;
|
|
23444
23590
|
this.catalogPath = catalog;
|
|
23445
23591
|
}
|
|
23446
23592
|
getCatalog() {
|
|
23447
|
-
return
|
|
23593
|
+
return import_fs_extra8.default.readJSONSync(this.catalogPath, { throws: false }) || [];
|
|
23448
23594
|
}
|
|
23449
23595
|
getCatalogFilePath() {
|
|
23450
23596
|
return this.catalogPath;
|
|
23451
23597
|
}
|
|
23452
23598
|
updateCatalog(catalog) {
|
|
23453
|
-
|
|
23599
|
+
import_fs_extra8.default.writeJSONSync(this.catalogPath, catalog);
|
|
23454
23600
|
}
|
|
23455
23601
|
add(description, content) {
|
|
23456
23602
|
const id = (0, import_crypto.randomUUID)();
|
|
23457
|
-
const filePath =
|
|
23458
|
-
|
|
23603
|
+
const filePath = import_path7.default.join(this.cacheDir, `${id}.md`);
|
|
23604
|
+
import_fs_extra8.default.writeFileSync(filePath, content, "utf-8");
|
|
23459
23605
|
const catalog = this.getCatalog();
|
|
23460
23606
|
catalog.push({ id, description });
|
|
23461
23607
|
this.updateCatalog(catalog);
|
|
@@ -23464,9 +23610,9 @@ var UserCache = class {
|
|
|
23464
23610
|
const catalog = this.getCatalog();
|
|
23465
23611
|
const item = catalog.find((item2) => item2.id === id);
|
|
23466
23612
|
if (item) {
|
|
23467
|
-
const filePath =
|
|
23468
|
-
if (
|
|
23469
|
-
return { description: item.description, content:
|
|
23613
|
+
const filePath = import_path7.default.join(this.cacheDir, `${id}.md`);
|
|
23614
|
+
if (import_fs_extra8.default.existsSync(filePath)) {
|
|
23615
|
+
return { description: item.description, content: import_fs_extra8.default.readFileSync(filePath, "utf-8") };
|
|
23470
23616
|
}
|
|
23471
23617
|
}
|
|
23472
23618
|
return { description: "", content: "" };
|
|
@@ -23489,9 +23635,9 @@ var UserCache = class {
|
|
|
23489
23635
|
}
|
|
23490
23636
|
catalog.splice(idx, 1);
|
|
23491
23637
|
this.updateCatalog(catalog);
|
|
23492
|
-
const filePath =
|
|
23493
|
-
if (
|
|
23494
|
-
|
|
23638
|
+
const filePath = import_path7.default.join(this.cacheDir, `${id}.md`);
|
|
23639
|
+
if (import_fs_extra8.default.existsSync(filePath)) {
|
|
23640
|
+
import_fs_extra8.default.removeSync(filePath);
|
|
23495
23641
|
}
|
|
23496
23642
|
return true;
|
|
23497
23643
|
}
|
|
@@ -23509,20 +23655,20 @@ var UserCache = class {
|
|
|
23509
23655
|
if (!item) {
|
|
23510
23656
|
return false;
|
|
23511
23657
|
}
|
|
23512
|
-
const filePath =
|
|
23513
|
-
|
|
23658
|
+
const filePath = import_path7.default.join(this.cacheDir, `${id}.md`);
|
|
23659
|
+
import_fs_extra8.default.writeFileSync(filePath, content, "utf-8");
|
|
23514
23660
|
return true;
|
|
23515
23661
|
}
|
|
23516
23662
|
};
|
|
23517
23663
|
|
|
23518
23664
|
// src/agent/tools/learn-self.ts
|
|
23519
|
-
var
|
|
23665
|
+
var import_langchain5 = require("langchain");
|
|
23520
23666
|
var userCache = new UserCache();
|
|
23521
|
-
var learnSelfTool = (0,
|
|
23522
|
-
({ description, content }) => {
|
|
23667
|
+
var learnSelfTool = (0, import_langchain5.tool)(
|
|
23668
|
+
({ description, content }) => safeTool(() => {
|
|
23523
23669
|
userCache.add(description, content);
|
|
23524
23670
|
return `\u5DF2\u7F13\u5B58\u89E3\u51B3\u65B9\u6848: ${description}`;
|
|
23525
|
-
},
|
|
23671
|
+
}),
|
|
23526
23672
|
{
|
|
23527
23673
|
name: "learn_self",
|
|
23528
23674
|
description: "\u5C06\u89E3\u51B3\u590D\u6742\u95EE\u9898\u7684\u65B9\u6848\u7F13\u5B58\u5230\u672C\u5730\u77E5\u8BC6\u5E93\u3002\u5F53\u4F60\u6210\u529F\u89E3\u51B3\u4E86\u4E00\u4E2A\u590D\u6742\u95EE\u9898\u540E\uFF0C\u8C03\u7528\u6B64\u5DE5\u5177\u4FDD\u5B58\u89E3\u51B3\u65B9\u6848\uFF0C\u4EE5\u4FBF\u5C06\u6765\u9047\u5230\u7C7B\u4F3C\u95EE\u9898\u65F6\u53EF\u4EE5\u590D\u7528\u3002description \u5FC5\u987B\u7B80\u6D01\uFF0C\u4E0D\u8D85\u8FC750\u5B57\uFF1Bcontent \u5FC5\u987B\u4F7F\u7528 Markdown \u683C\u5F0F\u7F16\u5199\uFF0C\u5305\u542B\u5B8C\u6574\u7684\u89E3\u51B3\u6B65\u9AA4\u548C\u5173\u952E\u4FE1\u606F\u3002",
|
|
@@ -23532,27 +23678,27 @@ var learnSelfTool = (0, import_langchain4.tool)(
|
|
|
23532
23678
|
})
|
|
23533
23679
|
}
|
|
23534
23680
|
);
|
|
23535
|
-
var getLearnedDetailTool = (0,
|
|
23536
|
-
({ indexOrId }) => {
|
|
23681
|
+
var getLearnedDetailTool = (0, import_langchain5.tool)(
|
|
23682
|
+
({ indexOrId }) => safeTool(() => {
|
|
23537
23683
|
const index = Number(indexOrId);
|
|
23538
23684
|
let item;
|
|
23539
23685
|
if (!isNaN(index) && Number.isInteger(index)) {
|
|
23540
23686
|
item = userCache.getByIndex(index);
|
|
23541
23687
|
if (!item) {
|
|
23542
|
-
|
|
23688
|
+
throw new Error(`\u65E0\u6548\u7684\u7D22\u5F15: ${indexOrId}\uFF0C\u8BF7\u8BFB\u53D6 catalog.json \u67E5\u770B\u6709\u6548\u7D22\u5F15\u3002`);
|
|
23543
23689
|
}
|
|
23544
23690
|
} else {
|
|
23545
23691
|
const catalog = userCache.list();
|
|
23546
23692
|
item = catalog.find((c) => c.id === indexOrId);
|
|
23547
23693
|
if (!item) {
|
|
23548
|
-
|
|
23694
|
+
throw new Error(`\u672A\u627E\u5230 id \u4E3A "${indexOrId}" \u7684\u7F13\u5B58\u9879\uFF0C\u8BF7\u8BFB\u53D6 catalog.json \u67E5\u770B\u6240\u6709\u7F13\u5B58\u3002`);
|
|
23549
23695
|
}
|
|
23550
23696
|
}
|
|
23551
23697
|
const detail = userCache.getContentById(item.id);
|
|
23552
23698
|
return `## ${detail.description}
|
|
23553
23699
|
|
|
23554
23700
|
${detail.content}`;
|
|
23555
|
-
},
|
|
23701
|
+
}),
|
|
23556
23702
|
{
|
|
23557
23703
|
name: "get_learned_detail",
|
|
23558
23704
|
description: "\u8BFB\u53D6\u6307\u5B9A\u7F13\u5B58\u65B9\u6848\u7684\u5B8C\u6574\u8BE6\u7EC6\u4FE1\u606F\u3002\u4F20\u5165\u7D22\u5F15\u53F7\uFF08\u6570\u5B57\uFF09\u6216 id\uFF08uuid \u5B57\u7B26\u4E32\uFF09\u6765\u83B7\u53D6\u65B9\u6848\u7684\u5B8C\u6574\u5185\u5BB9\u3002",
|
|
@@ -23561,14 +23707,14 @@ ${detail.content}`;
|
|
|
23561
23707
|
})
|
|
23562
23708
|
}
|
|
23563
23709
|
);
|
|
23564
|
-
var updateLearnContentTool = (0,
|
|
23565
|
-
({ id, content }) => {
|
|
23710
|
+
var updateLearnContentTool = (0, import_langchain5.tool)(
|
|
23711
|
+
({ id, content }) => safeTool(() => {
|
|
23566
23712
|
const success2 = userCache.update(id, content);
|
|
23567
23713
|
if (!success2) {
|
|
23568
|
-
|
|
23714
|
+
throw new Error(`\u66F4\u65B0\u5931\u8D25: \u672A\u627E\u5230 id \u4E3A "${id}" \u7684\u7F13\u5B58\u9879\uFF0C\u8BF7\u8BFB\u53D6 catalog.json \u67E5\u770B\u6240\u6709\u7F13\u5B58\u3002`);
|
|
23569
23715
|
}
|
|
23570
23716
|
return `\u5DF2\u66F4\u65B0\u7F13\u5B58\u65B9\u6848: ${id}`;
|
|
23571
|
-
},
|
|
23717
|
+
}),
|
|
23572
23718
|
{
|
|
23573
23719
|
name: "update_learned_content",
|
|
23574
23720
|
description: "\u66F4\u65B0\u5DF2\u6709\u7F13\u5B58\u65B9\u6848\u7684\u5185\u5BB9\u3002\u4F20\u5165\u7F13\u5B58\u9879\u7684 id\uFF08uuid \u5B57\u7B26\u4E32\uFF09\u548C\u65B0\u7684 Markdown \u5185\u5BB9\uFF0C\u8986\u76D6\u539F\u6709\u6587\u4EF6\u3002\u9002\u7528\u4E8E\u8865\u5145\u66F4\u591A\u7EC6\u8282\u6216\u4FEE\u6B63\u4E4B\u524D\u7684\u65B9\u6848\u3002",
|
|
@@ -23578,186 +23724,43 @@ var updateLearnContentTool = (0, import_langchain4.tool)(
|
|
|
23578
23724
|
})
|
|
23579
23725
|
}
|
|
23580
23726
|
);
|
|
23581
|
-
var getCatalogFilePathTool = (0,
|
|
23582
|
-
|
|
23583
|
-
|
|
23584
|
-
}
|
|
23585
|
-
|
|
23586
|
-
name: "get_catalog_file_path",
|
|
23587
|
-
description: "\u83B7\u53D6\u7F13\u5B58\u7D22\u5F15\u6587\u4EF6 catalog.json \u7684\u7EDD\u5BF9\u8DEF\u5F84\u3002\u8BE5\u6587\u4EF6\u5305\u542B\u6240\u6709\u5DF2\u7F13\u5B58\u65B9\u6848\u7684 id \u548C description \u5217\u8868\u3002\u83B7\u53D6\u8DEF\u5F84\u540E\uFF0C\u4F7F\u7528 read_file \u5DE5\u5177\u8BFB\u53D6\u8BE5\u6587\u4EF6\u5373\u53EF\u67E5\u770B\u6240\u6709\u7F13\u5B58\u9879\u3002",
|
|
23588
|
-
schema: external_exports.object({})
|
|
23589
|
-
}
|
|
23590
|
-
);
|
|
23727
|
+
var getCatalogFilePathTool = (0, import_langchain5.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
|
|
23728
|
+
name: "get_catalog_file_path",
|
|
23729
|
+
description: "\u83B7\u53D6\u7F13\u5B58\u7D22\u5F15\u6587\u4EF6 catalog.json \u7684\u7EDD\u5BF9\u8DEF\u5F84\u3002\u8BE5\u6587\u4EF6\u5305\u542B\u6240\u6709\u5DF2\u7F13\u5B58\u65B9\u6848\u7684 id \u548C description \u5217\u8868\u3002\u83B7\u53D6\u8DEF\u5F84\u540E\uFF0C\u4F7F\u7528 read_file \u5DE5\u5177\u8BFB\u53D6\u8BE5\u6587\u4EF6\u5373\u53EF\u67E5\u770B\u6240\u6709\u7F13\u5B58\u9879\u3002",
|
|
23730
|
+
schema: external_exports.object({})
|
|
23731
|
+
});
|
|
23591
23732
|
var learnTools = [learnSelfTool, getLearnedDetailTool, updateLearnContentTool, getCatalogFilePathTool];
|
|
23592
23733
|
|
|
23593
23734
|
// src/agent/tools/mcp.ts
|
|
23594
23735
|
var import_mcp_adapters = require("@langchain/mcp-adapters");
|
|
23595
|
-
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
23596
|
-
|
|
23597
|
-
// src/agent/tools/utils.ts
|
|
23598
|
-
var import_langchain5 = require("langchain");
|
|
23599
|
-
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
23600
|
-
|
|
23601
|
-
// src/agent/tools/edit.ts
|
|
23602
|
-
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
23603
|
-
var import_langchain6 = require("langchain");
|
|
23604
|
-
|
|
23605
|
-
// src/agent/tools/fileTools.ts
|
|
23606
23736
|
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
23607
|
-
var
|
|
23608
|
-
var DEFAULT_MAX_OUTPUT = 6e4;
|
|
23609
|
-
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
23610
|
-
".txt",
|
|
23611
|
-
".md",
|
|
23612
|
-
".json",
|
|
23613
|
-
".json5",
|
|
23614
|
-
".js",
|
|
23615
|
-
".jsx",
|
|
23616
|
-
".ts",
|
|
23617
|
-
".tsx",
|
|
23618
|
-
".mjs",
|
|
23619
|
-
".cjs",
|
|
23620
|
-
".css",
|
|
23621
|
-
".less",
|
|
23622
|
-
".scss",
|
|
23623
|
-
".html",
|
|
23624
|
-
".xml",
|
|
23625
|
-
".yaml",
|
|
23626
|
-
".yml",
|
|
23627
|
-
".toml",
|
|
23628
|
-
".ini",
|
|
23629
|
-
".env",
|
|
23630
|
-
".gitignore",
|
|
23631
|
-
".sql",
|
|
23632
|
-
".py",
|
|
23633
|
-
".java",
|
|
23634
|
-
".c",
|
|
23635
|
-
".cpp",
|
|
23636
|
-
".h",
|
|
23637
|
-
".hpp",
|
|
23638
|
-
".cs",
|
|
23639
|
-
".go",
|
|
23640
|
-
".rs",
|
|
23641
|
-
".php",
|
|
23642
|
-
".rb",
|
|
23643
|
-
".sh",
|
|
23644
|
-
".bat",
|
|
23645
|
-
".ps1",
|
|
23646
|
-
".vue",
|
|
23647
|
-
".svelte",
|
|
23648
|
-
".log",
|
|
23649
|
-
".csv"
|
|
23650
|
-
]);
|
|
23651
|
-
function resolveWorkspacePath(inputPath, cwd = getTrueCwd()) {
|
|
23652
|
-
if (!inputPath?.trim()) {
|
|
23653
|
-
throw new Error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
23654
|
-
}
|
|
23655
|
-
return import_path7.default.resolve(cwd, inputPath);
|
|
23656
|
-
}
|
|
23657
|
-
function normalizePathForMatch(filePath) {
|
|
23658
|
-
return filePath.replace(/\\/g, "/");
|
|
23659
|
-
}
|
|
23660
|
-
function truncateOutput(content, maxLength = DEFAULT_MAX_OUTPUT) {
|
|
23661
|
-
if (content.length <= maxLength) {
|
|
23662
|
-
return content;
|
|
23663
|
-
}
|
|
23664
|
-
return `${content.slice(0, maxLength)}
|
|
23665
|
-
|
|
23666
|
-
[\u5185\u5BB9\u5DF2\u622A\u65AD\uFF0C\u4EC5\u663E\u793A\u524D ${maxLength} \u4E2A\u5B57\u7B26\uFF0C\u603B\u957F\u5EA6 ${content.length} \u4E2A\u5B57\u7B26]`;
|
|
23667
|
-
}
|
|
23668
|
-
function isProbablyTextFile(filePath) {
|
|
23669
|
-
const ext = import_path7.default.extname(filePath).toLowerCase();
|
|
23670
|
-
const base = import_path7.default.basename(filePath).toLowerCase();
|
|
23671
|
-
return TEXT_FILE_EXTENSIONS.has(ext) || TEXT_FILE_EXTENSIONS.has(base) || base.startsWith(".env");
|
|
23672
|
-
}
|
|
23673
|
-
function globToRegExp(pattern) {
|
|
23674
|
-
const normalized = normalizePathForMatch(pattern);
|
|
23675
|
-
let regex = "^";
|
|
23676
|
-
for (let i = 0; i < normalized.length; i++) {
|
|
23677
|
-
const char = normalized[i];
|
|
23678
|
-
const next = normalized[i + 1];
|
|
23679
|
-
if (char === "*") {
|
|
23680
|
-
if (next === "*") {
|
|
23681
|
-
const after = normalized[i + 2];
|
|
23682
|
-
if (after === "/") {
|
|
23683
|
-
regex += "(?:.*/)?";
|
|
23684
|
-
i += 2;
|
|
23685
|
-
} else {
|
|
23686
|
-
regex += ".*";
|
|
23687
|
-
i += 1;
|
|
23688
|
-
}
|
|
23689
|
-
} else {
|
|
23690
|
-
regex += "[^/]*";
|
|
23691
|
-
}
|
|
23692
|
-
} else if (char === "?") {
|
|
23693
|
-
regex += "[^/]";
|
|
23694
|
-
} else {
|
|
23695
|
-
regex += char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
23696
|
-
}
|
|
23697
|
-
}
|
|
23698
|
-
regex += "$";
|
|
23699
|
-
return new RegExp(regex, "i");
|
|
23700
|
-
}
|
|
23701
|
-
function matchesGlob(relativePath, pattern) {
|
|
23702
|
-
return globToRegExp(pattern).test(normalizePathForMatch(relativePath));
|
|
23703
|
-
}
|
|
23704
|
-
async function walkFiles(rootDir, options = {}) {
|
|
23705
|
-
const files = [];
|
|
23706
|
-
const includeHidden = options.includeHidden ?? false;
|
|
23707
|
-
const maxFiles = options.maxFiles ?? 5e3;
|
|
23708
|
-
async function walk(currentDir) {
|
|
23709
|
-
if (files.length >= maxFiles) {
|
|
23710
|
-
return;
|
|
23711
|
-
}
|
|
23712
|
-
const entries = await import_fs_extra9.default.readdir(currentDir, { withFileTypes: true });
|
|
23713
|
-
for (const entry of entries) {
|
|
23714
|
-
if (files.length >= maxFiles) {
|
|
23715
|
-
return;
|
|
23716
|
-
}
|
|
23717
|
-
if (!includeHidden && entry.name.startsWith(".")) {
|
|
23718
|
-
continue;
|
|
23719
|
-
}
|
|
23720
|
-
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") {
|
|
23721
|
-
continue;
|
|
23722
|
-
}
|
|
23723
|
-
const fullPath = import_path7.default.join(currentDir, entry.name);
|
|
23724
|
-
if (entry.isDirectory()) {
|
|
23725
|
-
await walk(fullPath);
|
|
23726
|
-
} else if (entry.isFile()) {
|
|
23727
|
-
files.push(fullPath);
|
|
23728
|
-
}
|
|
23729
|
-
}
|
|
23730
|
-
}
|
|
23731
|
-
await walk(rootDir);
|
|
23732
|
-
return files;
|
|
23733
|
-
}
|
|
23734
|
-
function formatJson(data) {
|
|
23735
|
-
return JSON.stringify(data, null, 2);
|
|
23736
|
-
}
|
|
23737
|
+
var import_langchain6 = require("langchain");
|
|
23737
23738
|
|
|
23738
23739
|
// src/agent/tools/edit.ts
|
|
23740
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
23741
|
+
var import_langchain7 = require("langchain");
|
|
23739
23742
|
async function editFileByReplace(filePath, oldString, newString, replaceAll = false) {
|
|
23740
23743
|
const absPath = resolveWorkspacePath(filePath);
|
|
23741
23744
|
if (!await import_fs_extra10.default.pathExists(absPath)) {
|
|
23742
|
-
|
|
23745
|
+
throw new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728 ${absPath}`);
|
|
23743
23746
|
}
|
|
23744
23747
|
const content = await import_fs_extra10.default.readFile(absPath, "utf-8");
|
|
23745
23748
|
const matches = content.split(oldString).length - 1;
|
|
23746
23749
|
if (!oldString) {
|
|
23747
|
-
|
|
23750
|
+
throw new Error("oldString \u4E0D\u80FD\u4E3A\u7A7A");
|
|
23748
23751
|
}
|
|
23749
23752
|
if (matches === 0) {
|
|
23750
|
-
|
|
23753
|
+
throw new Error("\u672A\u627E\u5230 oldString\uFF0C\u8BF7\u5148\u8BFB\u53D6\u6587\u4EF6\u786E\u8BA4\u7CBE\u786E\u5185\u5BB9");
|
|
23751
23754
|
}
|
|
23752
23755
|
if (!replaceAll && matches > 1) {
|
|
23753
|
-
|
|
23756
|
+
throw new Error(`oldString \u5339\u914D\u5230 ${matches} \u5904\u3002\u8BF7\u63D0\u4F9B\u66F4\u591A\u4E0A\u4E0B\u6587\u4F7F\u5176\u552F\u4E00\uFF0C\u6216\u8BBE\u7F6E replaceAll=true`);
|
|
23754
23757
|
}
|
|
23755
23758
|
const nextContent = replaceAll ? content.split(oldString).join(newString) : content.replace(oldString, newString);
|
|
23756
23759
|
await import_fs_extra10.default.writeFile(absPath, nextContent, "utf-8");
|
|
23757
23760
|
return `\u5DF2\u7F16\u8F91\u6587\u4EF6: ${absPath}\uFF0C\u66FF\u6362 ${replaceAll ? matches : 1} \u5904`;
|
|
23758
23761
|
}
|
|
23759
|
-
var editFileTool = (0,
|
|
23760
|
-
async ({ filePath, oldString, newString, replaceAll }) => editFileByReplace(filePath, oldString, newString, replaceAll),
|
|
23762
|
+
var editFileTool = (0, import_langchain7.tool)(
|
|
23763
|
+
async ({ filePath, oldString, newString, replaceAll }) => safeTool(() => editFileByReplace(filePath, oldString, newString, replaceAll)),
|
|
23761
23764
|
{
|
|
23762
23765
|
name: "edit_file",
|
|
23763
23766
|
description: "\u7F16\u8F91\u5DF2\u6709\u6587\u672C\u6587\u4EF6\uFF1A\u4F7F\u7528\u7CBE\u786E oldString \u66FF\u6362\u4E3A newString\u3002\u9ED8\u8BA4\u8981\u6C42 oldString \u5728\u6587\u4EF6\u4E2D\u552F\u4E00\uFF0C\u4EE5\u907F\u514D\u8BEF\u6539\u3002",
|
|
@@ -23772,7 +23775,7 @@ var editFileTool = (0, import_langchain6.tool)(
|
|
|
23772
23775
|
|
|
23773
23776
|
// src/agent/tools/glob.ts
|
|
23774
23777
|
var import_path8 = __toESM(require("path"));
|
|
23775
|
-
var
|
|
23778
|
+
var import_langchain8 = require("langchain");
|
|
23776
23779
|
async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false) {
|
|
23777
23780
|
const rootDir = resolveWorkspacePath(cwd || ".");
|
|
23778
23781
|
const allFiles = await walkFiles(rootDir, { includeHidden, maxFiles: Math.max(maxResults * 20, 1e3) });
|
|
@@ -23780,8 +23783,8 @@ async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false)
|
|
|
23780
23783
|
const matches = allFiles.map((file2) => normalizePathForMatch(import_path8.default.relative(rootDir, file2))).filter((relativePath) => matchesGlob(relativePath, normalizedPattern)).slice(0, maxResults);
|
|
23781
23784
|
return truncateOutput(formatJson({ cwd: rootDir, pattern, count: matches.length, files: matches }));
|
|
23782
23785
|
}
|
|
23783
|
-
var globTool = (0,
|
|
23784
|
-
async ({ pattern, cwd, maxResults, includeHidden }) => globFiles(pattern, cwd, maxResults, includeHidden),
|
|
23786
|
+
var globTool = (0, import_langchain8.tool)(
|
|
23787
|
+
async ({ pattern, cwd, maxResults, includeHidden }) => safeTool(() => globFiles(pattern, cwd, maxResults, includeHidden)),
|
|
23785
23788
|
{
|
|
23786
23789
|
name: "glob_files",
|
|
23787
23790
|
description: "\u6309 glob \u6A21\u5F0F\u67E5\u627E\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u4E0B\u7684\u6587\u4EF6\uFF0C\u4F8B\u5982 **/*.ts\u3001src/**/*.tsx\u3002\u9ED8\u8BA4\u5FFD\u7565\u9690\u85CF\u76EE\u5F55\u3001node_modules\u3001dist\u3001.git\u3002",
|
|
@@ -23797,7 +23800,7 @@ var globTool = (0, import_langchain7.tool)(
|
|
|
23797
23800
|
// src/agent/tools/grep.ts
|
|
23798
23801
|
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
23799
23802
|
var import_path9 = __toESM(require("path"));
|
|
23800
|
-
var
|
|
23803
|
+
var import_langchain9 = require("langchain");
|
|
23801
23804
|
async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false, maxResults = 100, includeHidden = false) {
|
|
23802
23805
|
const rootDir = resolveWorkspacePath(cwd || ".");
|
|
23803
23806
|
const matcher = isRegexp ? new RegExp(query, "i") : null;
|
|
@@ -23822,25 +23825,35 @@ async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false,
|
|
|
23822
23825
|
}
|
|
23823
23826
|
return truncateOutput(formatJson({ cwd: rootDir, query, includePattern, count: matches.length, matches }));
|
|
23824
23827
|
}
|
|
23825
|
-
var grepTool = (0,
|
|
23826
|
-
async ({ query, cwd, includePattern, isRegexp, maxResults, includeHidden }) =>
|
|
23828
|
+
var grepTool = (0, import_langchain9.tool)(
|
|
23829
|
+
async ({ query, pattern, cwd, includePattern, isRegexp, maxResults, includeHidden }) => safeTool(() => {
|
|
23830
|
+
const searchQuery = query || pattern;
|
|
23831
|
+
if (!searchQuery) {
|
|
23832
|
+
throw new Error("query \u6216 pattern \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A");
|
|
23833
|
+
}
|
|
23834
|
+
return grepFiles(searchQuery, cwd, includePattern, isRegexp, maxResults, includeHidden);
|
|
23835
|
+
}),
|
|
23827
23836
|
{
|
|
23828
23837
|
name: "grep_files",
|
|
23829
|
-
description: "\u5728\u6587\u672C\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9\uFF0C\u652F\u6301\u666E\u901A\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F\uFF0C\u53EF\u7528 includePattern \u9650\u5B9A\u6587\u4EF6\u8303\u56F4\u3002",
|
|
23838
|
+
description: "\u5728\u6587\u672C\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9\uFF0C\u652F\u6301\u666E\u901A\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F\uFF0C\u53EF\u7528 includePattern \u9650\u5B9A\u6587\u4EF6\u8303\u56F4\u3002query \u4E3A\u641C\u7D22\u5185\u5BB9\uFF1B\u517C\u5BB9 pattern \u4F5C\u4E3A query \u7684\u522B\u540D\u3002",
|
|
23830
23839
|
schema: external_exports.object({
|
|
23831
|
-
query: external_exports.string().describe("\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
23840
|
+
query: external_exports.string().optional().describe("\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
23841
|
+
pattern: external_exports.string().optional().describe("query \u7684\u517C\u5BB9\u522B\u540D\uFF0C\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
23832
23842
|
cwd: external_exports.string().optional().describe("\u641C\u7D22\u6839\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55"),
|
|
23833
23843
|
includePattern: external_exports.string().default("**/*").describe("\u9650\u5B9A\u641C\u7D22\u6587\u4EF6\u7684 glob \u6A21\u5F0F\uFF0C\u4F8B\u5982 src/**/*.ts"),
|
|
23834
|
-
isRegexp: external_exports.boolean().default(false).describe("query \u662F\u5426\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
23844
|
+
isRegexp: external_exports.boolean().default(false).describe("query/pattern \u662F\u5426\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
23835
23845
|
maxResults: external_exports.number().default(100).describe("\u6700\u5927\u8FD4\u56DE\u5339\u914D\u6570\u91CF"),
|
|
23836
23846
|
includeHidden: external_exports.boolean().default(false).describe("\u662F\u5426\u5305\u542B\u9690\u85CF\u6587\u4EF6\u6216\u9690\u85CF\u76EE\u5F55")
|
|
23847
|
+
}).refine((input) => input.query || input.pattern, {
|
|
23848
|
+
message: "query \u6216 pattern \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A",
|
|
23849
|
+
path: ["query"]
|
|
23837
23850
|
})
|
|
23838
23851
|
}
|
|
23839
23852
|
);
|
|
23840
23853
|
|
|
23841
23854
|
// src/agent/tools/question.ts
|
|
23842
23855
|
var import_inquirer = __toESM(require("inquirer"));
|
|
23843
|
-
var
|
|
23856
|
+
var import_langchain10 = require("langchain");
|
|
23844
23857
|
async function askQuestion(question, type = "input", choices = []) {
|
|
23845
23858
|
const promptType = type === "select" ? "list" : type;
|
|
23846
23859
|
const answer = await import_inquirer.default.prompt([
|
|
@@ -23854,31 +23867,28 @@ async function askQuestion(question, type = "input", choices = []) {
|
|
|
23854
23867
|
const value = answer["value"];
|
|
23855
23868
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
23856
23869
|
}
|
|
23857
|
-
var questionTool = (0,
|
|
23858
|
-
|
|
23859
|
-
|
|
23860
|
-
|
|
23861
|
-
|
|
23862
|
-
|
|
23863
|
-
|
|
23864
|
-
|
|
23865
|
-
|
|
23866
|
-
})
|
|
23867
|
-
}
|
|
23868
|
-
);
|
|
23870
|
+
var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
|
|
23871
|
+
name: "ask_question",
|
|
23872
|
+
description: "\u5F53\u7EE7\u7EED\u4EFB\u52A1\u5FC5\u987B\u83B7\u53D6\u7528\u6237\u6F84\u6E05\u3001\u786E\u8BA4\u6216\u9009\u62E9\u65F6\uFF0C\u5411\u7528\u6237\u53D1\u8D77\u547D\u4EE4\u884C\u63D0\u95EE\u5E76\u8FD4\u56DE\u7B54\u6848\u3002\u4E0D\u8981\u8BE2\u95EE\u5BC6\u7801\u3001\u5BC6\u94A5\u7B49\u654F\u611F\u4FE1\u606F\u3002",
|
|
23873
|
+
schema: external_exports.object({
|
|
23874
|
+
question: external_exports.string().describe("\u8981\u8BE2\u95EE\u7528\u6237\u7684\u95EE\u9898"),
|
|
23875
|
+
type: external_exports.enum(["input", "confirm", "select"]).default("input").describe("\u95EE\u9898\u7C7B\u578B\uFF1Ainput \u6587\u672C\u8F93\u5165\u3001confirm \u786E\u8BA4\u3001select \u5355\u9009"),
|
|
23876
|
+
choices: external_exports.array(external_exports.string()).default([]).describe("select \u5355\u9009\u9879\u5217\u8868\uFF1B\u975E select \u7C7B\u578B\u53EF\u4E3A\u7A7A")
|
|
23877
|
+
})
|
|
23878
|
+
});
|
|
23869
23879
|
|
|
23870
23880
|
// src/agent/tools/read.ts
|
|
23871
23881
|
var import_fs_extra12 = __toESM(require("fs-extra"));
|
|
23872
23882
|
var import_iconv_lite2 = __toESM(require("iconv-lite"));
|
|
23873
|
-
var
|
|
23883
|
+
var import_langchain11 = require("langchain");
|
|
23874
23884
|
async function readFile(filePath, startLine = 1, endLine = -1, encoding) {
|
|
23875
23885
|
const absPath = resolveWorkspacePath(filePath);
|
|
23876
23886
|
if (!await import_fs_extra12.default.pathExists(absPath)) {
|
|
23877
|
-
|
|
23887
|
+
throw new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728 ${absPath}`);
|
|
23878
23888
|
}
|
|
23879
23889
|
const stat = await import_fs_extra12.default.stat(absPath);
|
|
23880
23890
|
if (!stat.isFile()) {
|
|
23881
|
-
|
|
23891
|
+
throw new Error(`\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6 ${absPath}`);
|
|
23882
23892
|
}
|
|
23883
23893
|
const buffer = await import_fs_extra12.default.readFile(absPath);
|
|
23884
23894
|
const targetEncoding = encoding || getEncoding() || "utf-8";
|
|
@@ -23887,13 +23897,13 @@ async function readFile(filePath, startLine = 1, endLine = -1, encoding) {
|
|
|
23887
23897
|
const safeStart = Math.max(1, startLine || 1);
|
|
23888
23898
|
const safeEnd = endLine && endLine > 0 ? Math.min(endLine, lines.length) : lines.length;
|
|
23889
23899
|
if (safeStart > safeEnd) {
|
|
23890
|
-
|
|
23900
|
+
throw new Error(`\u884C\u53F7\u8303\u56F4\u65E0\u6548\uFF0C\u6587\u4EF6\u5171 ${lines.length} \u884C`);
|
|
23891
23901
|
}
|
|
23892
23902
|
const selected = lines.slice(safeStart - 1, safeEnd).map((line, index) => `${safeStart + index}: ${line}`).join("\n");
|
|
23893
23903
|
return truncateOutput(formatJson({ filePath: absPath, totalLines: lines.length, startLine: safeStart, endLine: safeEnd, content: selected }));
|
|
23894
23904
|
}
|
|
23895
|
-
var readFileTool = (0,
|
|
23896
|
-
async ({ filePath, startLine, endLine, encoding }) => readFile(filePath, startLine, endLine, encoding),
|
|
23905
|
+
var readFileTool = (0, import_langchain11.tool)(
|
|
23906
|
+
async ({ filePath, startLine, endLine, encoding }) => safeTool(() => readFile(filePath, startLine, endLine, encoding)),
|
|
23897
23907
|
{
|
|
23898
23908
|
name: "read_file",
|
|
23899
23909
|
description: "\u8BFB\u53D6\u672C\u5730\u6587\u672C\u6587\u4EF6\u5185\u5BB9\u3002\u652F\u6301\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u7684\u8DEF\u5F84\uFF0C\u53EF\u6307\u5B9A\u8D77\u6B62\u884C\u53F7\uFF1B\u8FD4\u56DE\u5E26\u884C\u53F7\u7684\u5185\u5BB9\u3002",
|
|
@@ -23909,7 +23919,7 @@ var readFileTool = (0, import_langchain10.tool)(
|
|
|
23909
23919
|
// src/agent/tools/semanticMemory.ts
|
|
23910
23920
|
var import_fs_extra13 = __toESM(require("fs-extra"));
|
|
23911
23921
|
var import_path10 = __toESM(require("path"));
|
|
23912
|
-
var
|
|
23922
|
+
var import_langchain12 = require("langchain");
|
|
23913
23923
|
var DEFAULT_MEMORY_MARKDOWN = `# \u7528\u6237\u8BED\u4E49\u8BB0\u5FC6
|
|
23914
23924
|
|
|
23915
23925
|
> \u8BE5\u6587\u4EF6\u7531\u8BED\u4E49\u8BB0\u5FC6\u5DE5\u5177\u7EF4\u62A4\u3002\u4EC5\u8BB0\u5F55\u53EF\u957F\u671F\u590D\u7528\u7684\u7528\u6237\u4FE1\u606F\u3001\u4E60\u60EF\u548C\u504F\u597D\uFF1B\u4E0D\u8981\u8BB0\u5F55\u5BC6\u7801\u3001\u5BC6\u94A5\u3001\u4EE4\u724C\u7B49\u654F\u611F\u4FE1\u606F\u3002
|
|
@@ -23929,7 +23939,7 @@ function getMemoryFilePath(runtimeMemoryFilePath) {
|
|
|
23929
23939
|
}
|
|
23930
23940
|
async function readSemanticMemory(memoryFilePath) {
|
|
23931
23941
|
if (!memoryFilePath) {
|
|
23932
|
-
|
|
23942
|
+
throw new Error("\u5F53\u524D\u8FD0\u884C\u4E0A\u4E0B\u6587\u672A\u63D0\u4F9B memoryFilePath\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6");
|
|
23933
23943
|
}
|
|
23934
23944
|
if (!await import_fs_extra13.default.pathExists(memoryFilePath)) {
|
|
23935
23945
|
return DEFAULT_MEMORY_MARKDOWN;
|
|
@@ -23938,27 +23948,23 @@ async function readSemanticMemory(memoryFilePath) {
|
|
|
23938
23948
|
}
|
|
23939
23949
|
async function updateSemanticMemory(memoryFilePath, content) {
|
|
23940
23950
|
if (!memoryFilePath) {
|
|
23941
|
-
|
|
23951
|
+
throw new Error("\u5F53\u524D\u8FD0\u884C\u4E0A\u4E0B\u6587\u672A\u63D0\u4F9B memoryFilePath\uFF0C\u65E0\u6CD5\u66F4\u65B0\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6");
|
|
23942
23952
|
}
|
|
23943
23953
|
await import_fs_extra13.default.ensureDir(import_path10.default.dirname(memoryFilePath));
|
|
23944
23954
|
await import_fs_extra13.default.writeFile(memoryFilePath, `${content.trim()}
|
|
23945
23955
|
`, "utf-8");
|
|
23946
23956
|
return `\u5DF2\u66F4\u65B0\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6: ${memoryFilePath}`;
|
|
23947
23957
|
}
|
|
23948
|
-
var readSemanticMemoryTool = (0,
|
|
23949
|
-
async (_input, runtime) =>
|
|
23950
|
-
return readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath));
|
|
23951
|
-
},
|
|
23958
|
+
var readSemanticMemoryTool = (0, import_langchain12.tool)(
|
|
23959
|
+
async (_input, runtime) => safeTool(() => readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath))),
|
|
23952
23960
|
{
|
|
23953
23961
|
name: "read_user_semantic_memory",
|
|
23954
23962
|
description: "\u8BFB\u53D6\u5F53\u524D\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6 Markdown \u6587\u4EF6\u3002\u51C6\u5907\u65B0\u589E\u3001\u4FEE\u6B63\u6216\u5408\u5E76\u7528\u6237\u957F\u671F\u504F\u597D\u524D\uFF0C\u5E94\u5148\u8C03\u7528\u672C\u5DE5\u5177\u8BFB\u53D6\u73B0\u6709\u5185\u5BB9\uFF0C\u907F\u514D\u91CD\u590D\u548C\u8986\u76D6\u5DF2\u6709\u4FE1\u606F\u3002\u82E5\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u4F1A\u8FD4\u56DE\u63A8\u8350\u7684 Markdown \u6A21\u677F\u3002",
|
|
23955
23963
|
schema: external_exports.object({})
|
|
23956
23964
|
}
|
|
23957
23965
|
);
|
|
23958
|
-
var updateSemanticMemoryTool = (0,
|
|
23959
|
-
async ({ content }, runtime) =>
|
|
23960
|
-
return updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content);
|
|
23961
|
-
},
|
|
23966
|
+
var updateSemanticMemoryTool = (0, import_langchain12.tool)(
|
|
23967
|
+
async ({ content }, runtime) => safeTool(() => updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content)),
|
|
23962
23968
|
{
|
|
23963
23969
|
name: "update_user_semantic_memory",
|
|
23964
23970
|
description: "\u8986\u76D6\u66F4\u65B0\u5F53\u524D\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6 Markdown \u6587\u4EF6\u3002content \u5FC5\u987B\u662F\u5B8C\u6574\u7684 Markdown \u6587\u4EF6\u5185\u5BB9\uFF0C\u800C\u4E0D\u662F\u7247\u6BB5\u3002\u4EC5\u8BB0\u5F55\u660E\u786E\u3001\u7A33\u5B9A\u3001\u53EF\u957F\u671F\u590D\u7528\u7684\u4FE1\u606F\uFF0C\u4F8B\u5982\u7528\u6237\u79F0\u547C\u3001\u64CD\u4F5C\u4E60\u60EF\u3001\u7F16\u7801\u4E60\u60EF\u3001\u4E2A\u4EBA\u504F\u597D\u7B49\uFF1B\u4E0D\u8981\u8BB0\u5F55\u4E00\u6B21\u6027\u4EFB\u52A1\u4FE1\u606F\u3001\u4E34\u65F6\u4E0A\u4E0B\u6587\u3001\u63A8\u6D4B\u5185\u5BB9\u3001\u5BC6\u7801\u3001\u5BC6\u94A5\u3001\u4EE4\u724C\u3001\u9690\u79C1\u654F\u611F\u4FE1\u606F\u3002\u66F4\u65B0\u524D\u5E94\u5148\u8C03\u7528 read_user_semantic_memory \u8BFB\u53D6\u73B0\u6709\u5185\u5BB9\uFF0C\u7136\u540E\u5728\u4FDD\u7559\u5DF2\u6709\u6709\u6548\u8BB0\u5FC6\u7684\u57FA\u7840\u4E0A\u5408\u5E76\u65B0\u4FE1\u606F\uFF0C\u6309 Markdown \u6807\u9898\u548C\u5217\u8868\u6574\u7406\uFF0C\u5E76\u81EA\u884C\u53BB\u91CD\u3002",
|
|
@@ -24017,21 +24023,21 @@ var TaskQueue = class {
|
|
|
24017
24023
|
};
|
|
24018
24024
|
|
|
24019
24025
|
// src/agent/tools/task.ts
|
|
24020
|
-
var
|
|
24026
|
+
var import_langchain13 = require("langchain");
|
|
24021
24027
|
function getCurrentTaskQueue(agentId) {
|
|
24022
24028
|
return agentId ? new TaskQueue(agentId) : null;
|
|
24023
24029
|
}
|
|
24024
24030
|
function manageTaskQueue(agentId, action, task, index) {
|
|
24025
24031
|
const queue = getCurrentTaskQueue(agentId);
|
|
24026
24032
|
if (!queue) {
|
|
24027
|
-
|
|
24033
|
+
throw new Error("\u672A\u627E\u5230\u5F53\u524D\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u521B\u5EFA agent \u4F1A\u8BDD");
|
|
24028
24034
|
}
|
|
24029
24035
|
if (action === "list") {
|
|
24030
24036
|
return formatJson({ tasks: queue.loadTasks() });
|
|
24031
24037
|
}
|
|
24032
24038
|
if (action === "add") {
|
|
24033
24039
|
if (!task?.trim()) {
|
|
24034
|
-
|
|
24040
|
+
throw new Error("\u6DFB\u52A0\u4EFB\u52A1\u65F6 task \u4E0D\u80FD\u4E3A\u7A7A");
|
|
24035
24041
|
}
|
|
24036
24042
|
queue.pushTask(task.trim());
|
|
24037
24043
|
return `\u5DF2\u6DFB\u52A0\u4EFB\u52A1: ${task.trim()}`;
|
|
@@ -24040,7 +24046,7 @@ function manageTaskQueue(agentId, action, task, index) {
|
|
|
24040
24046
|
const tasks = queue.loadTasks();
|
|
24041
24047
|
const safeIndex = Number(index);
|
|
24042
24048
|
if (!Number.isInteger(safeIndex) || safeIndex < 1 || safeIndex > tasks.length) {
|
|
24043
|
-
|
|
24049
|
+
throw new Error(`\u4EFB\u52A1\u5E8F\u53F7\u65E0\u6548\uFF0C\u5F53\u524D\u4EFB\u52A1\u6570 ${tasks.length}`);
|
|
24044
24050
|
}
|
|
24045
24051
|
const removed = tasks[safeIndex - 1];
|
|
24046
24052
|
queue.delTask(safeIndex - 1);
|
|
@@ -24049,11 +24055,11 @@ function manageTaskQueue(agentId, action, task, index) {
|
|
|
24049
24055
|
queue.clearTasks();
|
|
24050
24056
|
return "\u5DF2\u6E05\u7A7A\u4EFB\u52A1\u961F\u5217";
|
|
24051
24057
|
}
|
|
24052
|
-
var taskTool = (0,
|
|
24053
|
-
async ({ action, task, index }, runtime) => {
|
|
24058
|
+
var taskTool = (0, import_langchain13.tool)(
|
|
24059
|
+
async ({ action, task, index }, runtime) => safeTool(() => {
|
|
24054
24060
|
const agentId = runtime.context?.agentId || getAgentId();
|
|
24055
24061
|
return manageTaskQueue(agentId, action, task, index);
|
|
24056
|
-
},
|
|
24062
|
+
}),
|
|
24057
24063
|
{
|
|
24058
24064
|
name: "manage_task_queue",
|
|
24059
24065
|
description: "\u7BA1\u7406\u5F53\u524D agent \u4F1A\u8BDD\u4EFB\u52A1\u961F\u5217\uFF1A\u67E5\u770B\u3001\u6DFB\u52A0\u540E\u7EED\u4EFB\u52A1\u3001\u5220\u9664\u6307\u5B9A\u4EFB\u52A1\u6216\u6E05\u7A7A\u4EFB\u52A1\u3002\u6DFB\u52A0\u7684\u4EFB\u52A1\u4F1A\u5728\u5F53\u524D\u4EFB\u52A1\u7ED3\u675F\u540E\u7EE7\u7EED\u6267\u884C\u3002",
|
|
@@ -24066,7 +24072,7 @@ var taskTool = (0, import_langchain12.tool)(
|
|
|
24066
24072
|
);
|
|
24067
24073
|
|
|
24068
24074
|
// src/agent/tools/webfetch.ts
|
|
24069
|
-
var
|
|
24075
|
+
var import_langchain14 = require("langchain");
|
|
24070
24076
|
async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
|
|
24071
24077
|
const controller = new AbortController();
|
|
24072
24078
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
@@ -24095,35 +24101,29 @@ async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
|
|
|
24095
24101
|
),
|
|
24096
24102
|
maxLength
|
|
24097
24103
|
);
|
|
24098
|
-
} catch (error51) {
|
|
24099
|
-
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
24100
|
-
return `Web fetch error: ${message}`;
|
|
24101
24104
|
} finally {
|
|
24102
24105
|
clearTimeout(timer);
|
|
24103
24106
|
}
|
|
24104
24107
|
}
|
|
24105
|
-
var webFetchTool = (0,
|
|
24106
|
-
|
|
24107
|
-
|
|
24108
|
-
|
|
24109
|
-
|
|
24110
|
-
|
|
24111
|
-
|
|
24112
|
-
|
|
24113
|
-
|
|
24114
|
-
})
|
|
24115
|
-
}
|
|
24116
|
-
);
|
|
24108
|
+
var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
|
|
24109
|
+
name: "web_fetch",
|
|
24110
|
+
description: "\u901A\u8FC7 HTTP GET \u83B7\u53D6\u7F51\u9875\u3001\u63A5\u53E3\u6216\u8FDC\u7A0B\u6587\u672C\u5185\u5BB9\uFF0C\u5E76\u8FD4\u56DE\u72B6\u6001\u7801\u3001content-type \u548C\u54CD\u5E94\u6B63\u6587\u3002",
|
|
24111
|
+
schema: external_exports.object({
|
|
24112
|
+
url: external_exports.string().url().describe("\u8981\u8BF7\u6C42\u7684\u5B8C\u6574 URL\uFF0C\u4F8B\u5982 https://example.com"),
|
|
24113
|
+
timeout: external_exports.number().default(3e4).describe("\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09"),
|
|
24114
|
+
maxLength: external_exports.number().default(6e4).describe("\u6700\u5927\u8FD4\u56DE\u5B57\u7B26\u6570\uFF0C\u8D85\u51FA\u4F1A\u622A\u65AD")
|
|
24115
|
+
})
|
|
24116
|
+
});
|
|
24117
24117
|
|
|
24118
24118
|
// src/agent/tools/write.ts
|
|
24119
24119
|
var import_fs_extra15 = __toESM(require("fs-extra"));
|
|
24120
24120
|
var import_path11 = __toESM(require("path"));
|
|
24121
|
-
var
|
|
24121
|
+
var import_langchain15 = require("langchain");
|
|
24122
24122
|
async function writeFile(filePath, content, mode = "overwrite") {
|
|
24123
24123
|
const absPath = resolveWorkspacePath(filePath);
|
|
24124
24124
|
const exists = await import_fs_extra15.default.pathExists(absPath);
|
|
24125
24125
|
if (mode === "create" && exists) {
|
|
24126
|
-
|
|
24126
|
+
throw new Error(`\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0Ccreate \u6A21\u5F0F\u4E0D\u4F1A\u8986\u76D6 ${absPath}`);
|
|
24127
24127
|
}
|
|
24128
24128
|
await import_fs_extra15.default.ensureDir(import_path11.default.dirname(absPath));
|
|
24129
24129
|
if (mode === "append") {
|
|
@@ -24133,18 +24133,15 @@ async function writeFile(filePath, content, mode = "overwrite") {
|
|
|
24133
24133
|
await import_fs_extra15.default.writeFile(absPath, content, "utf-8");
|
|
24134
24134
|
return `${exists ? "\u5DF2\u8986\u76D6\u5199\u5165\u6587\u4EF6" : "\u5DF2\u521B\u5EFA\u6587\u4EF6"}: ${absPath}`;
|
|
24135
24135
|
}
|
|
24136
|
-
var writeFileTool = (0,
|
|
24137
|
-
|
|
24138
|
-
|
|
24139
|
-
|
|
24140
|
-
|
|
24141
|
-
|
|
24142
|
-
|
|
24143
|
-
|
|
24144
|
-
|
|
24145
|
-
})
|
|
24146
|
-
}
|
|
24147
|
-
);
|
|
24136
|
+
var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile(filePath, content, mode)), {
|
|
24137
|
+
name: "write_file",
|
|
24138
|
+
description: "\u5411\u672C\u5730\u6587\u4EF6\u5199\u5165\u6587\u672C\u5185\u5BB9\u3002\u53EF\u521B\u5EFA\u65B0\u6587\u4EF6\u3001\u8986\u76D6\u5DF2\u6709\u6587\u4EF6\u6216\u8FFD\u52A0\u5185\u5BB9\uFF0C\u4F1A\u81EA\u52A8\u521B\u5EFA\u7236\u76EE\u5F55\u3002",
|
|
24139
|
+
schema: external_exports.object({
|
|
24140
|
+
filePath: external_exports.string().describe("\u76EE\u6807\u6587\u4EF6\u8DEF\u5F84\uFF0C\u652F\u6301\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u7684\u8DEF\u5F84"),
|
|
24141
|
+
content: external_exports.string().describe("\u8981\u5199\u5165\u7684\u5B8C\u6574\u6587\u672C\u5185\u5BB9"),
|
|
24142
|
+
mode: external_exports.enum(["overwrite", "append", "create"]).default("overwrite").describe("\u5199\u5165\u6A21\u5F0F\uFF1Aoverwrite \u8986\u76D6\u3001append \u8FFD\u52A0\u3001create \u4EC5\u65B0\u5EFA")
|
|
24143
|
+
})
|
|
24144
|
+
});
|
|
24148
24145
|
|
|
24149
24146
|
// src/agent/tools/index.ts
|
|
24150
24147
|
var builtinTools = [
|