deepfish-ai 2.0.3 → 2.0.5
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 +14 -4
- package/dist/index.js +479 -464
- package/dist/serve/client/assets/index-CXCKvQL3.css +1 -0
- package/dist/serve/client/assets/index-Cr3CJSQU.js +1 -0
- package/dist/serve/client/index.html +4 -4
- package/dist/serve/pm2-server.js +312 -315
- package/dist/serve/server/entry-server.mjs +27 -14
- package/package.json +1 -1
- package/dist/serve/client/assets/index-DUHYC91l.js +0 -1
- package/dist/serve/client/assets/index-zcrdNLZs.css +0 -1
package/dist/index.js
CHANGED
|
@@ -8891,12 +8891,12 @@ async function handleModelUse(nameOrIndex) {
|
|
|
8891
8891
|
targetIndex = aiList.findIndex((item) => item.name === nameOrIndex);
|
|
8892
8892
|
}
|
|
8893
8893
|
if (targetIndex === -1) {
|
|
8894
|
-
logError(
|
|
8894
|
+
logError(`AI config not found: ${nameOrIndex}`);
|
|
8895
8895
|
return;
|
|
8896
8896
|
}
|
|
8897
8897
|
config2.currentModel = aiList[targetIndex].name;
|
|
8898
8898
|
writeConfig(config2);
|
|
8899
|
-
logSuccess(
|
|
8899
|
+
logSuccess(`Switched to AI config: ${aiList[targetIndex].name}`);
|
|
8900
8900
|
}
|
|
8901
8901
|
async function handleModelDel(nameOrIndex) {
|
|
8902
8902
|
const config2 = readConfig();
|
|
@@ -8913,7 +8913,7 @@ async function handleModelDel(nameOrIndex) {
|
|
|
8913
8913
|
targetIndex = aiList.findIndex((item) => item.name === nameOrIndex);
|
|
8914
8914
|
}
|
|
8915
8915
|
if (targetIndex === -1) {
|
|
8916
|
-
logError(
|
|
8916
|
+
logError(`AI config not found: ${nameOrIndex}`);
|
|
8917
8917
|
return;
|
|
8918
8918
|
}
|
|
8919
8919
|
const deletedName = aiList[targetIndex].name;
|
|
@@ -8923,7 +8923,7 @@ async function handleModelDel(nameOrIndex) {
|
|
|
8923
8923
|
config2.currentModel = "";
|
|
8924
8924
|
}
|
|
8925
8925
|
writeConfig(config2);
|
|
8926
|
-
logSuccess(
|
|
8926
|
+
logSuccess(`Deleted AI config: ${deletedName}`);
|
|
8927
8927
|
}
|
|
8928
8928
|
|
|
8929
8929
|
// src/cli/cli-model.ts
|
|
@@ -9001,7 +9001,7 @@ var import_path18 = __toESM(require("path"));
|
|
|
9001
9001
|
var import_crypto4 = require("crypto");
|
|
9002
9002
|
|
|
9003
9003
|
// src/agent/AIAgent/index.ts
|
|
9004
|
-
var
|
|
9004
|
+
var import_langchain16 = require("langchain");
|
|
9005
9005
|
var import_deepagents = require("deepagents");
|
|
9006
9006
|
|
|
9007
9007
|
// src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
|
|
@@ -9284,17 +9284,10 @@ var BaseCheckpointSaver = class {
|
|
|
9284
9284
|
while (cursorConfig != null && remaining.size > 0) {
|
|
9285
9285
|
const tup = await this.getTuple(cursorConfig);
|
|
9286
9286
|
if (tup === void 0) break;
|
|
9287
|
-
if (tup.pendingWrites && tup.pendingWrites.length > 0) {
|
|
9288
|
-
const
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
if (remaining.has(ch)) (perChannel[ch] ??= []).push(write);
|
|
9292
|
-
}
|
|
9293
|
-
for (const ch of Object.keys(perChannel)) {
|
|
9294
|
-
const block = perChannel[ch];
|
|
9295
|
-
block.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
9296
|
-
for (let i = block.length - 1; i >= 0; i -= 1) collectedByCh[ch].push(block[i]);
|
|
9297
|
-
}
|
|
9287
|
+
if (tup.pendingWrites && tup.pendingWrites.length > 0) for (let i = tup.pendingWrites.length - 1; i >= 0; i -= 1) {
|
|
9288
|
+
const write = tup.pendingWrites[i];
|
|
9289
|
+
const ch = write[1];
|
|
9290
|
+
if (remaining.has(ch)) collectedByCh[ch].push(write);
|
|
9298
9291
|
}
|
|
9299
9292
|
for (const ch of Array.from(remaining)) if (Object.prototype.hasOwnProperty.call(tup.checkpoint.channel_values, ch)) {
|
|
9300
9293
|
seedByCh[ch] = tup.checkpoint.channel_values[ch];
|
|
@@ -9373,7 +9366,7 @@ var StorePathResolver = class {
|
|
|
9373
9366
|
getThreadPath(threadId) {
|
|
9374
9367
|
return (0, import_path4.join)(this.rootFolder, this.joinWithSplitter(threadId));
|
|
9375
9368
|
}
|
|
9376
|
-
getCheckpointNsPath(
|
|
9369
|
+
getCheckpointNsPath(_threadId, _checkpointNs) {
|
|
9377
9370
|
return (0, import_path4.join)(this.rootFolder);
|
|
9378
9371
|
}
|
|
9379
9372
|
getCheckpointFolderPath(threadId, checkpointNs, checkpointId) {
|
|
@@ -24428,7 +24421,7 @@ var import_child_process2 = require("child_process");
|
|
|
24428
24421
|
var import_chardet = __toESM(require_lib());
|
|
24429
24422
|
var import_os2 = __toESM(require("os"));
|
|
24430
24423
|
var import_iconv_lite = __toESM(require("iconv-lite"));
|
|
24431
|
-
var
|
|
24424
|
+
var import_langchain3 = require("langchain");
|
|
24432
24425
|
|
|
24433
24426
|
// src/cli/cli-utils/getGlobalData.ts
|
|
24434
24427
|
var import_path6 = __toESM(require("path"));
|
|
@@ -24445,6 +24438,267 @@ function getEncoding() {
|
|
|
24445
24438
|
return (getConfig()?.encoding || "auto").toLowerCase();
|
|
24446
24439
|
}
|
|
24447
24440
|
|
|
24441
|
+
// src/agent/tools/utils.ts
|
|
24442
|
+
var import_langchain2 = require("langchain");
|
|
24443
|
+
var import_path8 = __toESM(require("path"));
|
|
24444
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
24445
|
+
var import_crypto = require("crypto");
|
|
24446
|
+
|
|
24447
|
+
// src/agent/tools/fileTools.ts
|
|
24448
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
24449
|
+
var import_path7 = __toESM(require("path"));
|
|
24450
|
+
var DEFAULT_MAX_OUTPUT = 6e4;
|
|
24451
|
+
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
24452
|
+
".txt",
|
|
24453
|
+
".md",
|
|
24454
|
+
".json",
|
|
24455
|
+
".json5",
|
|
24456
|
+
".js",
|
|
24457
|
+
".jsx",
|
|
24458
|
+
".ts",
|
|
24459
|
+
".tsx",
|
|
24460
|
+
".mjs",
|
|
24461
|
+
".cjs",
|
|
24462
|
+
".css",
|
|
24463
|
+
".less",
|
|
24464
|
+
".scss",
|
|
24465
|
+
".html",
|
|
24466
|
+
".xml",
|
|
24467
|
+
".yaml",
|
|
24468
|
+
".yml",
|
|
24469
|
+
".toml",
|
|
24470
|
+
".ini",
|
|
24471
|
+
".env",
|
|
24472
|
+
".gitignore",
|
|
24473
|
+
".sql",
|
|
24474
|
+
".py",
|
|
24475
|
+
".java",
|
|
24476
|
+
".c",
|
|
24477
|
+
".cpp",
|
|
24478
|
+
".h",
|
|
24479
|
+
".hpp",
|
|
24480
|
+
".cs",
|
|
24481
|
+
".go",
|
|
24482
|
+
".rs",
|
|
24483
|
+
".php",
|
|
24484
|
+
".rb",
|
|
24485
|
+
".sh",
|
|
24486
|
+
".bat",
|
|
24487
|
+
".ps1",
|
|
24488
|
+
".vue",
|
|
24489
|
+
".svelte",
|
|
24490
|
+
".log",
|
|
24491
|
+
".csv"
|
|
24492
|
+
]);
|
|
24493
|
+
function resolveWorkspacePath(inputPath, cwd = getTrueCwd()) {
|
|
24494
|
+
if (!inputPath?.trim()) {
|
|
24495
|
+
throw new Error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
24496
|
+
}
|
|
24497
|
+
return import_path7.default.resolve(cwd, inputPath);
|
|
24498
|
+
}
|
|
24499
|
+
function normalizePathForMatch(filePath) {
|
|
24500
|
+
return filePath.replace(/\\/g, "/");
|
|
24501
|
+
}
|
|
24502
|
+
function truncateOutput(content, maxLength = DEFAULT_MAX_OUTPUT) {
|
|
24503
|
+
if (content.length <= maxLength) {
|
|
24504
|
+
return content;
|
|
24505
|
+
}
|
|
24506
|
+
return `${content.slice(0, maxLength)}
|
|
24507
|
+
|
|
24508
|
+
[\u5185\u5BB9\u5DF2\u622A\u65AD\uFF0C\u4EC5\u663E\u793A\u524D ${maxLength} \u4E2A\u5B57\u7B26\uFF0C\u603B\u957F\u5EA6 ${content.length} \u4E2A\u5B57\u7B26]`;
|
|
24509
|
+
}
|
|
24510
|
+
function isProbablyTextFile(filePath) {
|
|
24511
|
+
const ext = import_path7.default.extname(filePath).toLowerCase();
|
|
24512
|
+
const base = import_path7.default.basename(filePath).toLowerCase();
|
|
24513
|
+
return TEXT_FILE_EXTENSIONS.has(ext) || TEXT_FILE_EXTENSIONS.has(base) || base.startsWith(".env");
|
|
24514
|
+
}
|
|
24515
|
+
function globToRegExp(pattern) {
|
|
24516
|
+
const normalized = normalizePathForMatch(pattern);
|
|
24517
|
+
let regex = "^";
|
|
24518
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
24519
|
+
const char = normalized[i];
|
|
24520
|
+
const next = normalized[i + 1];
|
|
24521
|
+
if (char === "*") {
|
|
24522
|
+
if (next === "*") {
|
|
24523
|
+
const after = normalized[i + 2];
|
|
24524
|
+
if (after === "/") {
|
|
24525
|
+
regex += "(?:.*/)?";
|
|
24526
|
+
i += 2;
|
|
24527
|
+
} else {
|
|
24528
|
+
regex += ".*";
|
|
24529
|
+
i += 1;
|
|
24530
|
+
}
|
|
24531
|
+
} else {
|
|
24532
|
+
regex += "[^/]*";
|
|
24533
|
+
}
|
|
24534
|
+
} else if (char === "?") {
|
|
24535
|
+
regex += "[^/]";
|
|
24536
|
+
} else {
|
|
24537
|
+
regex += char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
24538
|
+
}
|
|
24539
|
+
}
|
|
24540
|
+
regex += "$";
|
|
24541
|
+
return new RegExp(regex, "i");
|
|
24542
|
+
}
|
|
24543
|
+
function matchesGlob(relativePath, pattern) {
|
|
24544
|
+
return globToRegExp(pattern).test(normalizePathForMatch(relativePath));
|
|
24545
|
+
}
|
|
24546
|
+
async function walkFiles(rootDir, options = {}) {
|
|
24547
|
+
const files = [];
|
|
24548
|
+
const includeHidden = options.includeHidden ?? false;
|
|
24549
|
+
const maxFiles = options.maxFiles ?? 5e3;
|
|
24550
|
+
async function walk(currentDir) {
|
|
24551
|
+
if (files.length >= maxFiles) {
|
|
24552
|
+
return;
|
|
24553
|
+
}
|
|
24554
|
+
const entries = await import_fs_extra7.default.readdir(currentDir, { withFileTypes: true });
|
|
24555
|
+
for (const entry of entries) {
|
|
24556
|
+
if (files.length >= maxFiles) {
|
|
24557
|
+
return;
|
|
24558
|
+
}
|
|
24559
|
+
if (!includeHidden && entry.name.startsWith(".")) {
|
|
24560
|
+
continue;
|
|
24561
|
+
}
|
|
24562
|
+
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") {
|
|
24563
|
+
continue;
|
|
24564
|
+
}
|
|
24565
|
+
const fullPath = import_path7.default.join(currentDir, entry.name);
|
|
24566
|
+
if (entry.isDirectory()) {
|
|
24567
|
+
await walk(fullPath);
|
|
24568
|
+
} else if (entry.isFile()) {
|
|
24569
|
+
files.push(fullPath);
|
|
24570
|
+
}
|
|
24571
|
+
}
|
|
24572
|
+
}
|
|
24573
|
+
await walk(rootDir);
|
|
24574
|
+
return files;
|
|
24575
|
+
}
|
|
24576
|
+
function formatJson(data) {
|
|
24577
|
+
return JSON.stringify(data, null, 2);
|
|
24578
|
+
}
|
|
24579
|
+
|
|
24580
|
+
// src/agent/tools/utils.ts
|
|
24581
|
+
function successResult(data) {
|
|
24582
|
+
return { success: true, data };
|
|
24583
|
+
}
|
|
24584
|
+
function errorResult(error51, data) {
|
|
24585
|
+
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
24586
|
+
return data === void 0 ? { success: false, error: message } : { success: false, error: message, data };
|
|
24587
|
+
}
|
|
24588
|
+
function serializeToolResult(result) {
|
|
24589
|
+
return truncateOutput(JSON.stringify(result, null, 2));
|
|
24590
|
+
}
|
|
24591
|
+
async function safeTool(handler) {
|
|
24592
|
+
try {
|
|
24593
|
+
const data = await handler();
|
|
24594
|
+
return serializeToolResult(successResult(data));
|
|
24595
|
+
} catch (error51) {
|
|
24596
|
+
return serializeToolResult(errorResult(error51));
|
|
24597
|
+
}
|
|
24598
|
+
}
|
|
24599
|
+
function toLangChainTool(func, description) {
|
|
24600
|
+
const { name, description: desc, parameters } = description.function;
|
|
24601
|
+
const { properties } = parameters;
|
|
24602
|
+
const zodProperties = {};
|
|
24603
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
24604
|
+
const { type, description: desc2 } = value;
|
|
24605
|
+
let zodType;
|
|
24606
|
+
switch (type) {
|
|
24607
|
+
case "string":
|
|
24608
|
+
zodType = desc2 ? external_exports.string().describe(desc2) : external_exports.string();
|
|
24609
|
+
break;
|
|
24610
|
+
case "number":
|
|
24611
|
+
zodType = desc2 ? external_exports.number().describe(desc2) : external_exports.number();
|
|
24612
|
+
break;
|
|
24613
|
+
case "boolean":
|
|
24614
|
+
zodType = desc2 ? external_exports.boolean().describe(desc2) : external_exports.boolean();
|
|
24615
|
+
break;
|
|
24616
|
+
case "object":
|
|
24617
|
+
zodType = desc2 ? external_exports.object({}).describe(desc2) : external_exports.object({});
|
|
24618
|
+
break;
|
|
24619
|
+
case "array":
|
|
24620
|
+
zodType = desc2 ? external_exports.array(external_exports.string()).describe(desc2) : external_exports.array(external_exports.string());
|
|
24621
|
+
break;
|
|
24622
|
+
default:
|
|
24623
|
+
zodType = external_exports.any();
|
|
24624
|
+
}
|
|
24625
|
+
zodProperties[key] = zodType;
|
|
24626
|
+
}
|
|
24627
|
+
const schema = external_exports.object(zodProperties);
|
|
24628
|
+
const wrappedFunc = async (args) => {
|
|
24629
|
+
try {
|
|
24630
|
+
const result = await func(...Object.values(args));
|
|
24631
|
+
if (typeof result === "object" && result !== null && "success" in result) {
|
|
24632
|
+
return serializeToolResult(result);
|
|
24633
|
+
}
|
|
24634
|
+
return serializeToolResult(successResult(result));
|
|
24635
|
+
} catch (error51) {
|
|
24636
|
+
return serializeToolResult(errorResult(error51));
|
|
24637
|
+
}
|
|
24638
|
+
};
|
|
24639
|
+
return (0, import_langchain2.tool)(wrappedFunc, {
|
|
24640
|
+
name: `${name}_${(0, import_crypto.randomUUID)().slice(0, 3)}`,
|
|
24641
|
+
description: desc,
|
|
24642
|
+
schema
|
|
24643
|
+
});
|
|
24644
|
+
}
|
|
24645
|
+
function scanUserTools() {
|
|
24646
|
+
const tools = [];
|
|
24647
|
+
const scanPaths = getScanDirPaths();
|
|
24648
|
+
scanPaths.forEach((scanPath) => {
|
|
24649
|
+
const toolsDir = import_path8.default.resolve(scanPath, "tools");
|
|
24650
|
+
if (import_fs_extra8.default.pathExistsSync(toolsDir)) {
|
|
24651
|
+
const files = import_fs_extra8.default.readdirSync(toolsDir);
|
|
24652
|
+
files.forEach((file2) => {
|
|
24653
|
+
if (import_fs_extra8.default.statSync(import_path8.default.resolve(toolsDir, file2)).isDirectory()) {
|
|
24654
|
+
const subDirPath = import_path8.default.resolve(toolsDir, file2);
|
|
24655
|
+
const subFiles = import_fs_extra8.default.readdirSync(subDirPath);
|
|
24656
|
+
const indexFile = subFiles.find((f) => f === "index" || f === "index.cjs");
|
|
24657
|
+
if (indexFile) {
|
|
24658
|
+
const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, indexFile), indexFile);
|
|
24659
|
+
if (filePath) {
|
|
24660
|
+
_loadToolsFromFile(filePath, tools);
|
|
24661
|
+
}
|
|
24662
|
+
} else {
|
|
24663
|
+
subFiles.forEach((subFile) => {
|
|
24664
|
+
const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, subFile), subFile);
|
|
24665
|
+
if (filePath) {
|
|
24666
|
+
_loadToolsFromFile(filePath, tools);
|
|
24667
|
+
}
|
|
24668
|
+
});
|
|
24669
|
+
}
|
|
24670
|
+
} else {
|
|
24671
|
+
const filePath = _scanDeepFishJsFile(toolsDir, file2);
|
|
24672
|
+
if (filePath) {
|
|
24673
|
+
_loadToolsFromFile(filePath, tools);
|
|
24674
|
+
}
|
|
24675
|
+
}
|
|
24676
|
+
});
|
|
24677
|
+
}
|
|
24678
|
+
});
|
|
24679
|
+
return tools;
|
|
24680
|
+
}
|
|
24681
|
+
function _scanDeepFishJsFile(filePath, fileName) {
|
|
24682
|
+
if (fileName.endsWith(".js") || fileName.endsWith(".cjs")) {
|
|
24683
|
+
const fileContent = import_fs_extra8.default.readFileSync(filePath, "utf-8");
|
|
24684
|
+
if (fileContent.includes("module.exports") && fileContent.includes("descriptions") && fileContent.includes("functions")) {
|
|
24685
|
+
return filePath;
|
|
24686
|
+
}
|
|
24687
|
+
}
|
|
24688
|
+
return null;
|
|
24689
|
+
}
|
|
24690
|
+
function _loadToolsFromFile(filePath, tools) {
|
|
24691
|
+
const toolModule = require(filePath);
|
|
24692
|
+
const { functions, descriptions } = toolModule;
|
|
24693
|
+
descriptions.forEach((desc) => {
|
|
24694
|
+
const func = functions[desc.function.name];
|
|
24695
|
+
if (func) {
|
|
24696
|
+
const langChainTool = toLangChainTool(func, desc);
|
|
24697
|
+
tools.push(langChainTool);
|
|
24698
|
+
}
|
|
24699
|
+
});
|
|
24700
|
+
}
|
|
24701
|
+
|
|
24448
24702
|
// src/agent/tools/executeCommand.ts
|
|
24449
24703
|
function executeCommand(command, timeout = -1, cwd) {
|
|
24450
24704
|
logSuccess(`Executing system command: ${command}; ${timeout > 0 ? `Timeout: ${timeout}ms` : "No timeout limit"}`);
|
|
@@ -24465,16 +24719,14 @@ function executeCommand(command, timeout = -1, cwd) {
|
|
|
24465
24719
|
const stderr = import_iconv_lite.default.decode(result.stderr, targetEncoding);
|
|
24466
24720
|
const code = result.status;
|
|
24467
24721
|
if (stderr && !stderr.trim().startsWith("WARNING")) {
|
|
24468
|
-
|
|
24469
|
-
logError(`Execute error: ${error51.message}`);
|
|
24470
|
-
return `Execute error: ${error51.message}`;
|
|
24722
|
+
throw new Error(`Command failed (code ${code}): ${stderr.trim()}`);
|
|
24471
24723
|
}
|
|
24472
24724
|
logSuccess(`${stdout}
|
|
24473
24725
|
Command executed successfully`);
|
|
24474
24726
|
return stdout || "Command executed successfully";
|
|
24475
|
-
} catch (
|
|
24476
|
-
logError(`
|
|
24477
|
-
|
|
24727
|
+
} catch (error51) {
|
|
24728
|
+
logError(`Execute error: ${error51.message}`);
|
|
24729
|
+
throw error51;
|
|
24478
24730
|
}
|
|
24479
24731
|
}
|
|
24480
24732
|
function detectEncoding(buffer) {
|
|
@@ -24491,24 +24743,19 @@ function detectEncoding(buffer) {
|
|
|
24491
24743
|
}
|
|
24492
24744
|
return import_os2.default.platform() === "win32" ? "gbk" : "utf-8";
|
|
24493
24745
|
}
|
|
24494
|
-
var executeCommandTool = (0,
|
|
24495
|
-
|
|
24496
|
-
|
|
24497
|
-
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24502
|
-
command: external_exports.string().describe("\u8981\u6267\u884C\u7684 shell \u547D\u4EE4"),
|
|
24503
|
-
timeout: external_exports.number().default(-1).describe("\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C-1 \u8868\u793A\u4E0D\u9650\u5236")
|
|
24504
|
-
})
|
|
24505
|
-
}
|
|
24506
|
-
);
|
|
24746
|
+
var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => safeTool(() => executeCommand(command, timeout)), {
|
|
24747
|
+
name: "execute_command",
|
|
24748
|
+
description: `\u5728\u672C\u5730\u7CFB\u7EDF(${import_os2.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_os2.default.platform()}\u3002`,
|
|
24749
|
+
schema: external_exports.object({
|
|
24750
|
+
command: external_exports.string().describe("\u8981\u6267\u884C\u7684 shell \u547D\u4EE4"),
|
|
24751
|
+
timeout: external_exports.number().default(-1).describe("\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09\uFF0C-1 \u8868\u793A\u4E0D\u9650\u5236")
|
|
24752
|
+
})
|
|
24753
|
+
});
|
|
24507
24754
|
|
|
24508
24755
|
// src/agent/tools/executeJSCode.ts
|
|
24509
|
-
var
|
|
24510
|
-
var
|
|
24511
|
-
var
|
|
24756
|
+
var import_langchain4 = require("langchain");
|
|
24757
|
+
var import_path9 = __toESM(require("path"));
|
|
24758
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
24512
24759
|
var _require = require;
|
|
24513
24760
|
async function executeJSCode(code) {
|
|
24514
24761
|
logInfo("Executing JavaScript code: ");
|
|
@@ -24527,25 +24774,25 @@ async function executeJSCode(code) {
|
|
|
24527
24774
|
throw error51;
|
|
24528
24775
|
}
|
|
24529
24776
|
}
|
|
24530
|
-
var getInstalledPackagesTool = (0,
|
|
24531
|
-
async () => {
|
|
24532
|
-
const packageJson =
|
|
24533
|
-
const pkg =
|
|
24534
|
-
return
|
|
24535
|
-
},
|
|
24777
|
+
var getInstalledPackagesTool = (0, import_langchain4.tool)(
|
|
24778
|
+
async () => safeTool(() => {
|
|
24779
|
+
const packageJson = import_path9.default.join(getCodePath(), "./package.json");
|
|
24780
|
+
const pkg = import_fs_extra9.default.readJsonSync(packageJson);
|
|
24781
|
+
return pkg.dependencies;
|
|
24782
|
+
}),
|
|
24536
24783
|
{
|
|
24537
24784
|
name: "get_installed_packages",
|
|
24538
24785
|
description: "\u83B7\u53D6 deepfish-ai CLI \u5DE5\u5177\u81EA\u8EAB\u5DF2\u5B89\u88C5\u7684 npm \u4F9D\u8D56\u5305\u5217\u8868",
|
|
24539
24786
|
schema: external_exports.object({})
|
|
24540
24787
|
}
|
|
24541
24788
|
);
|
|
24542
|
-
var checkPackageInstalledTool = (0,
|
|
24543
|
-
async ({ packageName }) => {
|
|
24544
|
-
const packageJson =
|
|
24545
|
-
const pkg =
|
|
24789
|
+
var checkPackageInstalledTool = (0, import_langchain4.tool)(
|
|
24790
|
+
async ({ packageName }) => safeTool(() => {
|
|
24791
|
+
const packageJson = import_path9.default.join(getCodePath(), "./package.json");
|
|
24792
|
+
const pkg = import_fs_extra9.default.readJsonSync(packageJson);
|
|
24546
24793
|
const installed = Object.prototype.hasOwnProperty.call(pkg.dependencies, packageName);
|
|
24547
|
-
return
|
|
24548
|
-
},
|
|
24794
|
+
return { packageName, installed };
|
|
24795
|
+
}),
|
|
24549
24796
|
{
|
|
24550
24797
|
name: "check_package_installed",
|
|
24551
24798
|
description: "\u68C0\u67E5\u6307\u5B9A\u7684 npm \u5305\u662F\u5426\u5DF2\u5728 deepfish-ai CLI \u5DE5\u5177\u4E2D\u5B89\u88C5",
|
|
@@ -24554,15 +24801,15 @@ var checkPackageInstalledTool = (0, import_langchain3.tool)(
|
|
|
24554
24801
|
})
|
|
24555
24802
|
}
|
|
24556
24803
|
);
|
|
24557
|
-
var installPackageTool = (0,
|
|
24558
|
-
async ({ packageName }) => {
|
|
24559
|
-
const packageJson =
|
|
24560
|
-
const pkg =
|
|
24804
|
+
var installPackageTool = (0, import_langchain4.tool)(
|
|
24805
|
+
async ({ packageName }) => safeTool(() => {
|
|
24806
|
+
const packageJson = import_path9.default.join(getCodePath(), "./package.json");
|
|
24807
|
+
const pkg = import_fs_extra9.default.readJsonSync(packageJson);
|
|
24561
24808
|
if (Object.prototype.hasOwnProperty.call(pkg.dependencies, packageName)) {
|
|
24562
24809
|
return `Package "${packageName}" is already installed.`;
|
|
24563
24810
|
}
|
|
24564
24811
|
return executeCommand(`npm install ${packageName}`, 12e4, getCodePath());
|
|
24565
|
-
},
|
|
24812
|
+
}),
|
|
24566
24813
|
{
|
|
24567
24814
|
name: "install_package",
|
|
24568
24815
|
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",
|
|
@@ -24571,53 +24818,47 @@ var installPackageTool = (0, import_langchain3.tool)(
|
|
|
24571
24818
|
})
|
|
24572
24819
|
}
|
|
24573
24820
|
);
|
|
24574
|
-
var executeJSCodeTool = (0,
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
return result;
|
|
24578
|
-
},
|
|
24579
|
-
{
|
|
24580
|
-
name: "execute_js_code",
|
|
24581
|
-
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
|
|
24821
|
+
var executeJSCodeTool = (0, import_langchain4.tool)(async ({ code }) => safeTool(() => executeJSCode(code)), {
|
|
24822
|
+
name: "execute_js_code",
|
|
24823
|
+
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
|
|
24582
24824
|
async function __main() {
|
|
24583
24825
|
const data = await fs.readFile("data.txt", "utf-8")
|
|
24584
24826
|
return data
|
|
24585
24827
|
}
|
|
24586
24828
|
`,
|
|
24587
|
-
|
|
24588
|
-
|
|
24589
|
-
|
|
24590
|
-
|
|
24591
|
-
);
|
|
24829
|
+
schema: external_exports.object({
|
|
24830
|
+
code: external_exports.string().describe("\u8981\u6267\u884C\u7684Node.js\u4EE3\u7801")
|
|
24831
|
+
})
|
|
24832
|
+
});
|
|
24592
24833
|
var packageTools = [getInstalledPackagesTool, checkPackageInstalledTool, installPackageTool, executeJSCodeTool];
|
|
24593
24834
|
|
|
24594
24835
|
// src/cli/cli-utils/UserCache.ts
|
|
24595
|
-
var
|
|
24596
|
-
var
|
|
24597
|
-
var
|
|
24836
|
+
var import_path10 = __toESM(require("path"));
|
|
24837
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
24838
|
+
var import_crypto2 = require("crypto");
|
|
24598
24839
|
var UserCache = class {
|
|
24599
24840
|
cacheDir;
|
|
24600
24841
|
catalogPath;
|
|
24601
24842
|
constructor() {
|
|
24602
24843
|
const cacheDir = getUserStorePath();
|
|
24603
|
-
const catalog =
|
|
24604
|
-
|
|
24844
|
+
const catalog = import_path10.default.join(cacheDir, "catalog.json");
|
|
24845
|
+
import_fs_extra10.default.ensureFileSync(catalog);
|
|
24605
24846
|
this.cacheDir = cacheDir;
|
|
24606
24847
|
this.catalogPath = catalog;
|
|
24607
24848
|
}
|
|
24608
24849
|
getCatalog() {
|
|
24609
|
-
return
|
|
24850
|
+
return import_fs_extra10.default.readJSONSync(this.catalogPath, { throws: false }) || [];
|
|
24610
24851
|
}
|
|
24611
24852
|
getCatalogFilePath() {
|
|
24612
24853
|
return this.catalogPath;
|
|
24613
24854
|
}
|
|
24614
24855
|
updateCatalog(catalog) {
|
|
24615
|
-
|
|
24856
|
+
import_fs_extra10.default.writeJSONSync(this.catalogPath, catalog);
|
|
24616
24857
|
}
|
|
24617
24858
|
add(description, content) {
|
|
24618
|
-
const id = (0,
|
|
24619
|
-
const filePath =
|
|
24620
|
-
|
|
24859
|
+
const id = (0, import_crypto2.randomUUID)();
|
|
24860
|
+
const filePath = import_path10.default.join(this.cacheDir, `${id}.md`);
|
|
24861
|
+
import_fs_extra10.default.writeFileSync(filePath, content, "utf-8");
|
|
24621
24862
|
const catalog = this.getCatalog();
|
|
24622
24863
|
catalog.push({ id, description });
|
|
24623
24864
|
this.updateCatalog(catalog);
|
|
@@ -24626,9 +24867,9 @@ var UserCache = class {
|
|
|
24626
24867
|
const catalog = this.getCatalog();
|
|
24627
24868
|
const item = catalog.find((item2) => item2.id === id);
|
|
24628
24869
|
if (item) {
|
|
24629
|
-
const filePath =
|
|
24630
|
-
if (
|
|
24631
|
-
return { description: item.description, content:
|
|
24870
|
+
const filePath = import_path10.default.join(this.cacheDir, `${id}.md`);
|
|
24871
|
+
if (import_fs_extra10.default.existsSync(filePath)) {
|
|
24872
|
+
return { description: item.description, content: import_fs_extra10.default.readFileSync(filePath, "utf-8") };
|
|
24632
24873
|
}
|
|
24633
24874
|
}
|
|
24634
24875
|
return { description: "", content: "" };
|
|
@@ -24651,9 +24892,9 @@ var UserCache = class {
|
|
|
24651
24892
|
}
|
|
24652
24893
|
catalog.splice(idx, 1);
|
|
24653
24894
|
this.updateCatalog(catalog);
|
|
24654
|
-
const filePath =
|
|
24655
|
-
if (
|
|
24656
|
-
|
|
24895
|
+
const filePath = import_path10.default.join(this.cacheDir, `${id}.md`);
|
|
24896
|
+
if (import_fs_extra10.default.existsSync(filePath)) {
|
|
24897
|
+
import_fs_extra10.default.removeSync(filePath);
|
|
24657
24898
|
}
|
|
24658
24899
|
return true;
|
|
24659
24900
|
}
|
|
@@ -24671,20 +24912,20 @@ var UserCache = class {
|
|
|
24671
24912
|
if (!item) {
|
|
24672
24913
|
return false;
|
|
24673
24914
|
}
|
|
24674
|
-
const filePath =
|
|
24675
|
-
|
|
24915
|
+
const filePath = import_path10.default.join(this.cacheDir, `${id}.md`);
|
|
24916
|
+
import_fs_extra10.default.writeFileSync(filePath, content, "utf-8");
|
|
24676
24917
|
return true;
|
|
24677
24918
|
}
|
|
24678
24919
|
};
|
|
24679
24920
|
|
|
24680
24921
|
// src/agent/tools/learn-self.ts
|
|
24681
|
-
var
|
|
24922
|
+
var import_langchain5 = require("langchain");
|
|
24682
24923
|
var userCache = new UserCache();
|
|
24683
|
-
var learnSelfTool = (0,
|
|
24684
|
-
({ description, content }) => {
|
|
24924
|
+
var learnSelfTool = (0, import_langchain5.tool)(
|
|
24925
|
+
({ description, content }) => safeTool(() => {
|
|
24685
24926
|
userCache.add(description, content);
|
|
24686
24927
|
return `\u5DF2\u7F13\u5B58\u89E3\u51B3\u65B9\u6848: ${description}`;
|
|
24687
|
-
},
|
|
24928
|
+
}),
|
|
24688
24929
|
{
|
|
24689
24930
|
name: "learn_self",
|
|
24690
24931
|
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",
|
|
@@ -24694,27 +24935,27 @@ var learnSelfTool = (0, import_langchain4.tool)(
|
|
|
24694
24935
|
})
|
|
24695
24936
|
}
|
|
24696
24937
|
);
|
|
24697
|
-
var getLearnedDetailTool = (0,
|
|
24698
|
-
({ indexOrId }) => {
|
|
24938
|
+
var getLearnedDetailTool = (0, import_langchain5.tool)(
|
|
24939
|
+
({ indexOrId }) => safeTool(() => {
|
|
24699
24940
|
const index = Number(indexOrId);
|
|
24700
24941
|
let item;
|
|
24701
24942
|
if (!isNaN(index) && Number.isInteger(index)) {
|
|
24702
24943
|
item = userCache.getByIndex(index);
|
|
24703
24944
|
if (!item) {
|
|
24704
|
-
|
|
24945
|
+
throw new Error(`\u65E0\u6548\u7684\u7D22\u5F15: ${indexOrId}\uFF0C\u8BF7\u8BFB\u53D6 catalog.json \u67E5\u770B\u6709\u6548\u7D22\u5F15\u3002`);
|
|
24705
24946
|
}
|
|
24706
24947
|
} else {
|
|
24707
24948
|
const catalog = userCache.list();
|
|
24708
24949
|
item = catalog.find((c) => c.id === indexOrId);
|
|
24709
24950
|
if (!item) {
|
|
24710
|
-
|
|
24951
|
+
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`);
|
|
24711
24952
|
}
|
|
24712
24953
|
}
|
|
24713
24954
|
const detail = userCache.getContentById(item.id);
|
|
24714
24955
|
return `## ${detail.description}
|
|
24715
24956
|
|
|
24716
24957
|
${detail.content}`;
|
|
24717
|
-
},
|
|
24958
|
+
}),
|
|
24718
24959
|
{
|
|
24719
24960
|
name: "get_learned_detail",
|
|
24720
24961
|
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",
|
|
@@ -24723,14 +24964,14 @@ ${detail.content}`;
|
|
|
24723
24964
|
})
|
|
24724
24965
|
}
|
|
24725
24966
|
);
|
|
24726
|
-
var updateLearnContentTool = (0,
|
|
24727
|
-
({ id, content }) => {
|
|
24967
|
+
var updateLearnContentTool = (0, import_langchain5.tool)(
|
|
24968
|
+
({ id, content }) => safeTool(() => {
|
|
24728
24969
|
const success2 = userCache.update(id, content);
|
|
24729
24970
|
if (!success2) {
|
|
24730
|
-
|
|
24971
|
+
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`);
|
|
24731
24972
|
}
|
|
24732
24973
|
return `\u5DF2\u66F4\u65B0\u7F13\u5B58\u65B9\u6848: ${id}`;
|
|
24733
|
-
},
|
|
24974
|
+
}),
|
|
24734
24975
|
{
|
|
24735
24976
|
name: "update_learned_content",
|
|
24736
24977
|
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",
|
|
@@ -24740,24 +24981,47 @@ var updateLearnContentTool = (0, import_langchain4.tool)(
|
|
|
24740
24981
|
})
|
|
24741
24982
|
}
|
|
24742
24983
|
);
|
|
24743
|
-
var getCatalogFilePathTool = (0,
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
}
|
|
24747
|
-
|
|
24748
|
-
name: "get_catalog_file_path",
|
|
24749
|
-
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",
|
|
24750
|
-
schema: external_exports.object({})
|
|
24751
|
-
}
|
|
24752
|
-
);
|
|
24984
|
+
var getCatalogFilePathTool = (0, import_langchain5.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
|
|
24985
|
+
name: "get_catalog_file_path",
|
|
24986
|
+
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",
|
|
24987
|
+
schema: external_exports.object({})
|
|
24988
|
+
});
|
|
24753
24989
|
var learnTools = [learnSelfTool, getLearnedDetailTool, updateLearnContentTool, getCatalogFilePathTool];
|
|
24754
24990
|
|
|
24755
24991
|
// src/agent/tools/mcp.ts
|
|
24756
24992
|
var import_mcp_adapters = require("@langchain/mcp-adapters");
|
|
24757
|
-
var
|
|
24758
|
-
var
|
|
24993
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
24994
|
+
var import_langchain6 = require("langchain");
|
|
24995
|
+
var import_path11 = __toESM(require("path"));
|
|
24996
|
+
function normalizeMcpToolResult(result) {
|
|
24997
|
+
if (Array.isArray(result)) {
|
|
24998
|
+
return result.map((item) => normalizeMcpToolResult(item));
|
|
24999
|
+
}
|
|
25000
|
+
if (result && typeof result === "object" && "content" in result) {
|
|
25001
|
+
return result;
|
|
25002
|
+
}
|
|
25003
|
+
return result;
|
|
25004
|
+
}
|
|
25005
|
+
function wrapMcpTool(mcpTool) {
|
|
25006
|
+
const wrapped = (0, import_langchain6.tool)(
|
|
25007
|
+
async (input, runtime) => {
|
|
25008
|
+
try {
|
|
25009
|
+
const result = await mcpTool.invoke(input, runtime);
|
|
25010
|
+
return serializeToolResult(successResult(normalizeMcpToolResult(result)));
|
|
25011
|
+
} catch (error51) {
|
|
25012
|
+
return serializeToolResult(errorResult(error51));
|
|
25013
|
+
}
|
|
25014
|
+
},
|
|
25015
|
+
{
|
|
25016
|
+
name: mcpTool.name,
|
|
25017
|
+
description: mcpTool.description,
|
|
25018
|
+
schema: mcpTool.schema ?? external_exports.object({})
|
|
25019
|
+
}
|
|
25020
|
+
);
|
|
25021
|
+
return wrapped;
|
|
25022
|
+
}
|
|
24759
25023
|
async function loadMcpToolsFromConfigPath(mcpFilePath) {
|
|
24760
|
-
const jsonContent =
|
|
25024
|
+
const jsonContent = import_fs_extra11.default.readJSONSync(mcpFilePath);
|
|
24761
25025
|
const { mcpServers } = jsonContent;
|
|
24762
25026
|
if (!mcpServers || Object.keys(mcpServers).length === 0) {
|
|
24763
25027
|
return [];
|
|
@@ -24785,7 +25049,7 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
|
|
|
24785
25049
|
const client = new import_mcp_adapters.MultiServerMCPClient(jsonContent.mcpServers);
|
|
24786
25050
|
const tools = await client.getTools();
|
|
24787
25051
|
logInfo(`Loaded ${tools.length} tools from MCP config.`);
|
|
24788
|
-
return tools;
|
|
25052
|
+
return tools.map(wrapMcpTool);
|
|
24789
25053
|
} catch (error51) {
|
|
24790
25054
|
console.log("Error loading MCP tools:", error51);
|
|
24791
25055
|
return [];
|
|
@@ -24795,8 +25059,8 @@ async function scanUserMcp() {
|
|
|
24795
25059
|
const tools = [];
|
|
24796
25060
|
const scanPaths = getScanDirPaths();
|
|
24797
25061
|
for (const scanPath of scanPaths) {
|
|
24798
|
-
const mcpFilePath =
|
|
24799
|
-
if (
|
|
25062
|
+
const mcpFilePath = import_path11.default.join(scanPath, "mcp.json");
|
|
25063
|
+
if (import_fs_extra11.default.existsSync(mcpFilePath)) {
|
|
24800
25064
|
const mcpTools = await loadMcpToolsFromConfigPath(mcpFilePath);
|
|
24801
25065
|
tools.push(...mcpTools);
|
|
24802
25066
|
}
|
|
@@ -24804,271 +25068,31 @@ async function scanUserMcp() {
|
|
|
24804
25068
|
return tools;
|
|
24805
25069
|
}
|
|
24806
25070
|
|
|
24807
|
-
// src/agent/tools/utils.ts
|
|
24808
|
-
var import_langchain5 = require("langchain");
|
|
24809
|
-
var import_path10 = __toESM(require("path"));
|
|
24810
|
-
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
24811
|
-
var import_crypto2 = require("crypto");
|
|
24812
|
-
function toLangChainTool(func, description) {
|
|
24813
|
-
const { name, description: desc, parameters } = description.function;
|
|
24814
|
-
const { properties, required: required2 } = parameters;
|
|
24815
|
-
const zodProperties = {};
|
|
24816
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
24817
|
-
const { type, description: desc2, ...rest } = value;
|
|
24818
|
-
let zodType;
|
|
24819
|
-
switch (type) {
|
|
24820
|
-
case "string":
|
|
24821
|
-
zodType = desc2 ? external_exports.string().describe(desc2) : external_exports.string();
|
|
24822
|
-
break;
|
|
24823
|
-
case "number":
|
|
24824
|
-
zodType = desc2 ? external_exports.number().describe(desc2) : external_exports.number();
|
|
24825
|
-
break;
|
|
24826
|
-
case "boolean":
|
|
24827
|
-
zodType = desc2 ? external_exports.boolean().describe(desc2) : external_exports.boolean();
|
|
24828
|
-
break;
|
|
24829
|
-
case "object":
|
|
24830
|
-
zodType = desc2 ? external_exports.object({}).describe(desc2) : external_exports.object({});
|
|
24831
|
-
break;
|
|
24832
|
-
case "array":
|
|
24833
|
-
zodType = desc2 ? external_exports.array(external_exports.string()).describe(desc2) : external_exports.array(external_exports.string());
|
|
24834
|
-
break;
|
|
24835
|
-
default:
|
|
24836
|
-
zodType = external_exports.any();
|
|
24837
|
-
}
|
|
24838
|
-
zodProperties[key] = zodType;
|
|
24839
|
-
}
|
|
24840
|
-
const schema = external_exports.object(zodProperties);
|
|
24841
|
-
const wrappedFunc = (args) => {
|
|
24842
|
-
const result = func(...Object.values(args));
|
|
24843
|
-
if (typeof result === "object") {
|
|
24844
|
-
return JSON.stringify(result);
|
|
24845
|
-
} else {
|
|
24846
|
-
return result;
|
|
24847
|
-
}
|
|
24848
|
-
};
|
|
24849
|
-
return (0, import_langchain5.tool)(wrappedFunc, {
|
|
24850
|
-
name: `${name}_${(0, import_crypto2.randomUUID)().slice(0, 3)}`,
|
|
24851
|
-
description: desc,
|
|
24852
|
-
schema
|
|
24853
|
-
});
|
|
24854
|
-
}
|
|
24855
|
-
function scanUserTools() {
|
|
24856
|
-
const tools = [];
|
|
24857
|
-
const scanPaths = getScanDirPaths();
|
|
24858
|
-
scanPaths.forEach((scanPath) => {
|
|
24859
|
-
const toolsDir = import_path10.default.resolve(scanPath, "tools");
|
|
24860
|
-
if (import_fs_extra10.default.pathExistsSync(toolsDir)) {
|
|
24861
|
-
const files = import_fs_extra10.default.readdirSync(toolsDir);
|
|
24862
|
-
files.forEach((file2) => {
|
|
24863
|
-
if (import_fs_extra10.default.statSync(import_path10.default.resolve(toolsDir, file2)).isDirectory()) {
|
|
24864
|
-
const subDirPath = import_path10.default.resolve(toolsDir, file2);
|
|
24865
|
-
const subFiles = import_fs_extra10.default.readdirSync(subDirPath);
|
|
24866
|
-
const indexFile = subFiles.find((f) => f === "index" || f === "index.cjs");
|
|
24867
|
-
if (indexFile) {
|
|
24868
|
-
const filePath = _scanDeepFishJsFile(import_path10.default.resolve(subDirPath, indexFile), indexFile);
|
|
24869
|
-
if (filePath) {
|
|
24870
|
-
_loadToolsFromFile(filePath, tools);
|
|
24871
|
-
}
|
|
24872
|
-
} else {
|
|
24873
|
-
subFiles.forEach((subFile) => {
|
|
24874
|
-
const filePath = _scanDeepFishJsFile(import_path10.default.resolve(subDirPath, subFile), subFile);
|
|
24875
|
-
if (filePath) {
|
|
24876
|
-
_loadToolsFromFile(filePath, tools);
|
|
24877
|
-
}
|
|
24878
|
-
});
|
|
24879
|
-
}
|
|
24880
|
-
} else {
|
|
24881
|
-
const filePath = _scanDeepFishJsFile(toolsDir, file2);
|
|
24882
|
-
if (filePath) {
|
|
24883
|
-
_loadToolsFromFile(filePath, tools);
|
|
24884
|
-
}
|
|
24885
|
-
}
|
|
24886
|
-
});
|
|
24887
|
-
}
|
|
24888
|
-
});
|
|
24889
|
-
return tools;
|
|
24890
|
-
}
|
|
24891
|
-
function _scanDeepFishJsFile(filePath, fileName) {
|
|
24892
|
-
if (fileName.endsWith(".js") || fileName.endsWith(".cjs")) {
|
|
24893
|
-
const fileContent = import_fs_extra10.default.readFileSync(filePath, "utf-8");
|
|
24894
|
-
if (fileContent.includes("module.exports") && fileContent.includes("descriptions") && fileContent.includes("functions")) {
|
|
24895
|
-
return filePath;
|
|
24896
|
-
}
|
|
24897
|
-
}
|
|
24898
|
-
return null;
|
|
24899
|
-
}
|
|
24900
|
-
function _loadToolsFromFile(filePath, tools) {
|
|
24901
|
-
const toolModule = require(filePath);
|
|
24902
|
-
const { functions, descriptions } = toolModule;
|
|
24903
|
-
descriptions.forEach((desc) => {
|
|
24904
|
-
const func = functions[desc.function.name];
|
|
24905
|
-
if (func) {
|
|
24906
|
-
const langChainTool = toLangChainTool(func, desc);
|
|
24907
|
-
tools.push(langChainTool);
|
|
24908
|
-
}
|
|
24909
|
-
});
|
|
24910
|
-
}
|
|
24911
|
-
|
|
24912
25071
|
// src/agent/tools/edit.ts
|
|
24913
25072
|
var import_fs_extra12 = __toESM(require("fs-extra"));
|
|
24914
|
-
var
|
|
24915
|
-
|
|
24916
|
-
// src/agent/tools/fileTools.ts
|
|
24917
|
-
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
24918
|
-
var import_path11 = __toESM(require("path"));
|
|
24919
|
-
var DEFAULT_MAX_OUTPUT = 6e4;
|
|
24920
|
-
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
24921
|
-
".txt",
|
|
24922
|
-
".md",
|
|
24923
|
-
".json",
|
|
24924
|
-
".json5",
|
|
24925
|
-
".js",
|
|
24926
|
-
".jsx",
|
|
24927
|
-
".ts",
|
|
24928
|
-
".tsx",
|
|
24929
|
-
".mjs",
|
|
24930
|
-
".cjs",
|
|
24931
|
-
".css",
|
|
24932
|
-
".less",
|
|
24933
|
-
".scss",
|
|
24934
|
-
".html",
|
|
24935
|
-
".xml",
|
|
24936
|
-
".yaml",
|
|
24937
|
-
".yml",
|
|
24938
|
-
".toml",
|
|
24939
|
-
".ini",
|
|
24940
|
-
".env",
|
|
24941
|
-
".gitignore",
|
|
24942
|
-
".sql",
|
|
24943
|
-
".py",
|
|
24944
|
-
".java",
|
|
24945
|
-
".c",
|
|
24946
|
-
".cpp",
|
|
24947
|
-
".h",
|
|
24948
|
-
".hpp",
|
|
24949
|
-
".cs",
|
|
24950
|
-
".go",
|
|
24951
|
-
".rs",
|
|
24952
|
-
".php",
|
|
24953
|
-
".rb",
|
|
24954
|
-
".sh",
|
|
24955
|
-
".bat",
|
|
24956
|
-
".ps1",
|
|
24957
|
-
".vue",
|
|
24958
|
-
".svelte",
|
|
24959
|
-
".log",
|
|
24960
|
-
".csv"
|
|
24961
|
-
]);
|
|
24962
|
-
function resolveWorkspacePath(inputPath, cwd = getTrueCwd()) {
|
|
24963
|
-
if (!inputPath?.trim()) {
|
|
24964
|
-
throw new Error("\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
24965
|
-
}
|
|
24966
|
-
return import_path11.default.resolve(cwd, inputPath);
|
|
24967
|
-
}
|
|
24968
|
-
function normalizePathForMatch(filePath) {
|
|
24969
|
-
return filePath.replace(/\\/g, "/");
|
|
24970
|
-
}
|
|
24971
|
-
function truncateOutput(content, maxLength = DEFAULT_MAX_OUTPUT) {
|
|
24972
|
-
if (content.length <= maxLength) {
|
|
24973
|
-
return content;
|
|
24974
|
-
}
|
|
24975
|
-
return `${content.slice(0, maxLength)}
|
|
24976
|
-
|
|
24977
|
-
[\u5185\u5BB9\u5DF2\u622A\u65AD\uFF0C\u4EC5\u663E\u793A\u524D ${maxLength} \u4E2A\u5B57\u7B26\uFF0C\u603B\u957F\u5EA6 ${content.length} \u4E2A\u5B57\u7B26]`;
|
|
24978
|
-
}
|
|
24979
|
-
function isProbablyTextFile(filePath) {
|
|
24980
|
-
const ext = import_path11.default.extname(filePath).toLowerCase();
|
|
24981
|
-
const base = import_path11.default.basename(filePath).toLowerCase();
|
|
24982
|
-
return TEXT_FILE_EXTENSIONS.has(ext) || TEXT_FILE_EXTENSIONS.has(base) || base.startsWith(".env");
|
|
24983
|
-
}
|
|
24984
|
-
function globToRegExp(pattern) {
|
|
24985
|
-
const normalized = normalizePathForMatch(pattern);
|
|
24986
|
-
let regex = "^";
|
|
24987
|
-
for (let i = 0; i < normalized.length; i++) {
|
|
24988
|
-
const char = normalized[i];
|
|
24989
|
-
const next = normalized[i + 1];
|
|
24990
|
-
if (char === "*") {
|
|
24991
|
-
if (next === "*") {
|
|
24992
|
-
const after = normalized[i + 2];
|
|
24993
|
-
if (after === "/") {
|
|
24994
|
-
regex += "(?:.*/)?";
|
|
24995
|
-
i += 2;
|
|
24996
|
-
} else {
|
|
24997
|
-
regex += ".*";
|
|
24998
|
-
i += 1;
|
|
24999
|
-
}
|
|
25000
|
-
} else {
|
|
25001
|
-
regex += "[^/]*";
|
|
25002
|
-
}
|
|
25003
|
-
} else if (char === "?") {
|
|
25004
|
-
regex += "[^/]";
|
|
25005
|
-
} else {
|
|
25006
|
-
regex += char.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
|
|
25007
|
-
}
|
|
25008
|
-
}
|
|
25009
|
-
regex += "$";
|
|
25010
|
-
return new RegExp(regex, "i");
|
|
25011
|
-
}
|
|
25012
|
-
function matchesGlob(relativePath, pattern) {
|
|
25013
|
-
return globToRegExp(pattern).test(normalizePathForMatch(relativePath));
|
|
25014
|
-
}
|
|
25015
|
-
async function walkFiles(rootDir, options = {}) {
|
|
25016
|
-
const files = [];
|
|
25017
|
-
const includeHidden = options.includeHidden ?? false;
|
|
25018
|
-
const maxFiles = options.maxFiles ?? 5e3;
|
|
25019
|
-
async function walk(currentDir) {
|
|
25020
|
-
if (files.length >= maxFiles) {
|
|
25021
|
-
return;
|
|
25022
|
-
}
|
|
25023
|
-
const entries = await import_fs_extra11.default.readdir(currentDir, { withFileTypes: true });
|
|
25024
|
-
for (const entry of entries) {
|
|
25025
|
-
if (files.length >= maxFiles) {
|
|
25026
|
-
return;
|
|
25027
|
-
}
|
|
25028
|
-
if (!includeHidden && entry.name.startsWith(".")) {
|
|
25029
|
-
continue;
|
|
25030
|
-
}
|
|
25031
|
-
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".git") {
|
|
25032
|
-
continue;
|
|
25033
|
-
}
|
|
25034
|
-
const fullPath = import_path11.default.join(currentDir, entry.name);
|
|
25035
|
-
if (entry.isDirectory()) {
|
|
25036
|
-
await walk(fullPath);
|
|
25037
|
-
} else if (entry.isFile()) {
|
|
25038
|
-
files.push(fullPath);
|
|
25039
|
-
}
|
|
25040
|
-
}
|
|
25041
|
-
}
|
|
25042
|
-
await walk(rootDir);
|
|
25043
|
-
return files;
|
|
25044
|
-
}
|
|
25045
|
-
function formatJson(data) {
|
|
25046
|
-
return JSON.stringify(data, null, 2);
|
|
25047
|
-
}
|
|
25048
|
-
|
|
25049
|
-
// src/agent/tools/edit.ts
|
|
25073
|
+
var import_langchain7 = require("langchain");
|
|
25050
25074
|
async function editFileByReplace(filePath, oldString, newString, replaceAll = false) {
|
|
25051
25075
|
const absPath = resolveWorkspacePath(filePath);
|
|
25052
25076
|
if (!await import_fs_extra12.default.pathExists(absPath)) {
|
|
25053
|
-
|
|
25077
|
+
throw new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728 ${absPath}`);
|
|
25054
25078
|
}
|
|
25055
25079
|
const content = await import_fs_extra12.default.readFile(absPath, "utf-8");
|
|
25056
25080
|
const matches = content.split(oldString).length - 1;
|
|
25057
25081
|
if (!oldString) {
|
|
25058
|
-
|
|
25082
|
+
throw new Error("oldString \u4E0D\u80FD\u4E3A\u7A7A");
|
|
25059
25083
|
}
|
|
25060
25084
|
if (matches === 0) {
|
|
25061
|
-
|
|
25085
|
+
throw new Error("\u672A\u627E\u5230 oldString\uFF0C\u8BF7\u5148\u8BFB\u53D6\u6587\u4EF6\u786E\u8BA4\u7CBE\u786E\u5185\u5BB9");
|
|
25062
25086
|
}
|
|
25063
25087
|
if (!replaceAll && matches > 1) {
|
|
25064
|
-
|
|
25088
|
+
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`);
|
|
25065
25089
|
}
|
|
25066
25090
|
const nextContent = replaceAll ? content.split(oldString).join(newString) : content.replace(oldString, newString);
|
|
25067
25091
|
await import_fs_extra12.default.writeFile(absPath, nextContent, "utf-8");
|
|
25068
25092
|
return `\u5DF2\u7F16\u8F91\u6587\u4EF6: ${absPath}\uFF0C\u66FF\u6362 ${replaceAll ? matches : 1} \u5904`;
|
|
25069
25093
|
}
|
|
25070
|
-
var editFileTool = (0,
|
|
25071
|
-
async ({ filePath, oldString, newString, replaceAll }) => editFileByReplace(filePath, oldString, newString, replaceAll),
|
|
25094
|
+
var editFileTool = (0, import_langchain7.tool)(
|
|
25095
|
+
async ({ filePath, oldString, newString, replaceAll }) => safeTool(() => editFileByReplace(filePath, oldString, newString, replaceAll)),
|
|
25072
25096
|
{
|
|
25073
25097
|
name: "edit_file",
|
|
25074
25098
|
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",
|
|
@@ -25083,7 +25107,7 @@ var editFileTool = (0, import_langchain6.tool)(
|
|
|
25083
25107
|
|
|
25084
25108
|
// src/agent/tools/glob.ts
|
|
25085
25109
|
var import_path12 = __toESM(require("path"));
|
|
25086
|
-
var
|
|
25110
|
+
var import_langchain8 = require("langchain");
|
|
25087
25111
|
async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false) {
|
|
25088
25112
|
const rootDir = resolveWorkspacePath(cwd || ".");
|
|
25089
25113
|
const allFiles = await walkFiles(rootDir, { includeHidden, maxFiles: Math.max(maxResults * 20, 1e3) });
|
|
@@ -25091,8 +25115,8 @@ async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false)
|
|
|
25091
25115
|
const matches = allFiles.map((file2) => normalizePathForMatch(import_path12.default.relative(rootDir, file2))).filter((relativePath) => matchesGlob(relativePath, normalizedPattern)).slice(0, maxResults);
|
|
25092
25116
|
return truncateOutput(formatJson({ cwd: rootDir, pattern, count: matches.length, files: matches }));
|
|
25093
25117
|
}
|
|
25094
|
-
var globTool = (0,
|
|
25095
|
-
async ({ pattern, cwd, maxResults, includeHidden }) => globFiles(pattern, cwd, maxResults, includeHidden),
|
|
25118
|
+
var globTool = (0, import_langchain8.tool)(
|
|
25119
|
+
async ({ pattern, cwd, maxResults, includeHidden }) => safeTool(() => globFiles(pattern, cwd, maxResults, includeHidden)),
|
|
25096
25120
|
{
|
|
25097
25121
|
name: "glob_files",
|
|
25098
25122
|
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",
|
|
@@ -25108,7 +25132,7 @@ var globTool = (0, import_langchain7.tool)(
|
|
|
25108
25132
|
// src/agent/tools/grep.ts
|
|
25109
25133
|
var import_fs_extra13 = __toESM(require("fs-extra"));
|
|
25110
25134
|
var import_path13 = __toESM(require("path"));
|
|
25111
|
-
var
|
|
25135
|
+
var import_langchain9 = require("langchain");
|
|
25112
25136
|
async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false, maxResults = 100, includeHidden = false) {
|
|
25113
25137
|
const rootDir = resolveWorkspacePath(cwd || ".");
|
|
25114
25138
|
const matcher = isRegexp ? new RegExp(query, "i") : null;
|
|
@@ -25133,25 +25157,35 @@ async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false,
|
|
|
25133
25157
|
}
|
|
25134
25158
|
return truncateOutput(formatJson({ cwd: rootDir, query, includePattern, count: matches.length, matches }));
|
|
25135
25159
|
}
|
|
25136
|
-
var grepTool = (0,
|
|
25137
|
-
async ({ query, cwd, includePattern, isRegexp, maxResults, includeHidden }) =>
|
|
25160
|
+
var grepTool = (0, import_langchain9.tool)(
|
|
25161
|
+
async ({ query, pattern, cwd, includePattern, isRegexp, maxResults, includeHidden }) => safeTool(() => {
|
|
25162
|
+
const searchQuery = query || pattern;
|
|
25163
|
+
if (!searchQuery) {
|
|
25164
|
+
throw new Error("query \u6216 pattern \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A");
|
|
25165
|
+
}
|
|
25166
|
+
return grepFiles(searchQuery, cwd, includePattern, isRegexp, maxResults, includeHidden);
|
|
25167
|
+
}),
|
|
25138
25168
|
{
|
|
25139
25169
|
name: "grep_files",
|
|
25140
|
-
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",
|
|
25170
|
+
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",
|
|
25141
25171
|
schema: external_exports.object({
|
|
25142
|
-
query: external_exports.string().describe("\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25172
|
+
query: external_exports.string().optional().describe("\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25173
|
+
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"),
|
|
25143
25174
|
cwd: external_exports.string().optional().describe("\u641C\u7D22\u6839\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55"),
|
|
25144
25175
|
includePattern: external_exports.string().default("**/*").describe("\u9650\u5B9A\u641C\u7D22\u6587\u4EF6\u7684 glob \u6A21\u5F0F\uFF0C\u4F8B\u5982 src/**/*.ts"),
|
|
25145
|
-
isRegexp: external_exports.boolean().default(false).describe("query \u662F\u5426\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25176
|
+
isRegexp: external_exports.boolean().default(false).describe("query/pattern \u662F\u5426\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25146
25177
|
maxResults: external_exports.number().default(100).describe("\u6700\u5927\u8FD4\u56DE\u5339\u914D\u6570\u91CF"),
|
|
25147
25178
|
includeHidden: external_exports.boolean().default(false).describe("\u662F\u5426\u5305\u542B\u9690\u85CF\u6587\u4EF6\u6216\u9690\u85CF\u76EE\u5F55")
|
|
25179
|
+
}).refine((input) => input.query || input.pattern, {
|
|
25180
|
+
message: "query \u6216 pattern \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A",
|
|
25181
|
+
path: ["query"]
|
|
25148
25182
|
})
|
|
25149
25183
|
}
|
|
25150
25184
|
);
|
|
25151
25185
|
|
|
25152
25186
|
// src/agent/tools/question.ts
|
|
25153
25187
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
25154
|
-
var
|
|
25188
|
+
var import_langchain10 = require("langchain");
|
|
25155
25189
|
async function askQuestion(question, type = "input", choices = []) {
|
|
25156
25190
|
const promptType = type === "select" ? "list" : type;
|
|
25157
25191
|
const answer = await import_inquirer2.default.prompt([
|
|
@@ -25165,31 +25199,28 @@ async function askQuestion(question, type = "input", choices = []) {
|
|
|
25165
25199
|
const value = answer["value"];
|
|
25166
25200
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
25167
25201
|
}
|
|
25168
|
-
var questionTool = (0,
|
|
25169
|
-
|
|
25170
|
-
|
|
25171
|
-
|
|
25172
|
-
|
|
25173
|
-
|
|
25174
|
-
|
|
25175
|
-
|
|
25176
|
-
|
|
25177
|
-
})
|
|
25178
|
-
}
|
|
25179
|
-
);
|
|
25202
|
+
var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
|
|
25203
|
+
name: "ask_question",
|
|
25204
|
+
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",
|
|
25205
|
+
schema: external_exports.object({
|
|
25206
|
+
question: external_exports.string().describe("\u8981\u8BE2\u95EE\u7528\u6237\u7684\u95EE\u9898"),
|
|
25207
|
+
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"),
|
|
25208
|
+
choices: external_exports.array(external_exports.string()).default([]).describe("select \u5355\u9009\u9879\u5217\u8868\uFF1B\u975E select \u7C7B\u578B\u53EF\u4E3A\u7A7A")
|
|
25209
|
+
})
|
|
25210
|
+
});
|
|
25180
25211
|
|
|
25181
25212
|
// src/agent/tools/read.ts
|
|
25182
25213
|
var import_fs_extra14 = __toESM(require("fs-extra"));
|
|
25183
25214
|
var import_iconv_lite2 = __toESM(require("iconv-lite"));
|
|
25184
|
-
var
|
|
25215
|
+
var import_langchain11 = require("langchain");
|
|
25185
25216
|
async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
|
|
25186
25217
|
const absPath = resolveWorkspacePath(filePath);
|
|
25187
25218
|
if (!await import_fs_extra14.default.pathExists(absPath)) {
|
|
25188
|
-
|
|
25219
|
+
throw new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728 ${absPath}`);
|
|
25189
25220
|
}
|
|
25190
25221
|
const stat = await import_fs_extra14.default.stat(absPath);
|
|
25191
25222
|
if (!stat.isFile()) {
|
|
25192
|
-
|
|
25223
|
+
throw new Error(`\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6 ${absPath}`);
|
|
25193
25224
|
}
|
|
25194
25225
|
const buffer = await import_fs_extra14.default.readFile(absPath);
|
|
25195
25226
|
const targetEncoding = encoding || getEncoding() || "utf-8";
|
|
@@ -25198,13 +25229,13 @@ async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
|
|
|
25198
25229
|
const safeStart = Math.max(1, startLine || 1);
|
|
25199
25230
|
const safeEnd = endLine && endLine > 0 ? Math.min(endLine, lines.length) : lines.length;
|
|
25200
25231
|
if (safeStart > safeEnd) {
|
|
25201
|
-
|
|
25232
|
+
throw new Error(`\u884C\u53F7\u8303\u56F4\u65E0\u6548\uFF0C\u6587\u4EF6\u5171 ${lines.length} \u884C`);
|
|
25202
25233
|
}
|
|
25203
25234
|
const selected = lines.slice(safeStart - 1, safeEnd).map((line, index) => `${safeStart + index}: ${line}`).join("\n");
|
|
25204
25235
|
return truncateOutput(formatJson({ filePath: absPath, totalLines: lines.length, startLine: safeStart, endLine: safeEnd, content: selected }));
|
|
25205
25236
|
}
|
|
25206
|
-
var readFileTool = (0,
|
|
25207
|
-
async ({ filePath, startLine, endLine, encoding }) => readFile2(filePath, startLine, endLine, encoding),
|
|
25237
|
+
var readFileTool = (0, import_langchain11.tool)(
|
|
25238
|
+
async ({ filePath, startLine, endLine, encoding }) => safeTool(() => readFile2(filePath, startLine, endLine, encoding)),
|
|
25208
25239
|
{
|
|
25209
25240
|
name: "read_file",
|
|
25210
25241
|
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",
|
|
@@ -25220,7 +25251,7 @@ var readFileTool = (0, import_langchain10.tool)(
|
|
|
25220
25251
|
// src/agent/tools/semanticMemory.ts
|
|
25221
25252
|
var import_fs_extra15 = __toESM(require("fs-extra"));
|
|
25222
25253
|
var import_path14 = __toESM(require("path"));
|
|
25223
|
-
var
|
|
25254
|
+
var import_langchain12 = require("langchain");
|
|
25224
25255
|
var DEFAULT_MEMORY_MARKDOWN = `# \u7528\u6237\u8BED\u4E49\u8BB0\u5FC6
|
|
25225
25256
|
|
|
25226
25257
|
> \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
|
|
@@ -25240,7 +25271,7 @@ function getMemoryFilePath(runtimeMemoryFilePath) {
|
|
|
25240
25271
|
}
|
|
25241
25272
|
async function readSemanticMemory(memoryFilePath) {
|
|
25242
25273
|
if (!memoryFilePath) {
|
|
25243
|
-
|
|
25274
|
+
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");
|
|
25244
25275
|
}
|
|
25245
25276
|
if (!await import_fs_extra15.default.pathExists(memoryFilePath)) {
|
|
25246
25277
|
return DEFAULT_MEMORY_MARKDOWN;
|
|
@@ -25249,27 +25280,23 @@ async function readSemanticMemory(memoryFilePath) {
|
|
|
25249
25280
|
}
|
|
25250
25281
|
async function updateSemanticMemory(memoryFilePath, content) {
|
|
25251
25282
|
if (!memoryFilePath) {
|
|
25252
|
-
|
|
25283
|
+
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");
|
|
25253
25284
|
}
|
|
25254
25285
|
await import_fs_extra15.default.ensureDir(import_path14.default.dirname(memoryFilePath));
|
|
25255
25286
|
await import_fs_extra15.default.writeFile(memoryFilePath, `${content.trim()}
|
|
25256
25287
|
`, "utf-8");
|
|
25257
25288
|
return `\u5DF2\u66F4\u65B0\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6: ${memoryFilePath}`;
|
|
25258
25289
|
}
|
|
25259
|
-
var readSemanticMemoryTool = (0,
|
|
25260
|
-
async (_input, runtime) =>
|
|
25261
|
-
return readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath));
|
|
25262
|
-
},
|
|
25290
|
+
var readSemanticMemoryTool = (0, import_langchain12.tool)(
|
|
25291
|
+
async (_input, runtime) => safeTool(() => readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath))),
|
|
25263
25292
|
{
|
|
25264
25293
|
name: "read_user_semantic_memory",
|
|
25265
25294
|
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",
|
|
25266
25295
|
schema: external_exports.object({})
|
|
25267
25296
|
}
|
|
25268
25297
|
);
|
|
25269
|
-
var updateSemanticMemoryTool = (0,
|
|
25270
|
-
async ({ content }, runtime) =>
|
|
25271
|
-
return updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content);
|
|
25272
|
-
},
|
|
25298
|
+
var updateSemanticMemoryTool = (0, import_langchain12.tool)(
|
|
25299
|
+
async ({ content }, runtime) => safeTool(() => updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content)),
|
|
25273
25300
|
{
|
|
25274
25301
|
name: "update_user_semantic_memory",
|
|
25275
25302
|
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",
|
|
@@ -25328,21 +25355,21 @@ var TaskQueue = class {
|
|
|
25328
25355
|
};
|
|
25329
25356
|
|
|
25330
25357
|
// src/agent/tools/task.ts
|
|
25331
|
-
var
|
|
25358
|
+
var import_langchain13 = require("langchain");
|
|
25332
25359
|
function getCurrentTaskQueue(agentId) {
|
|
25333
25360
|
return agentId ? new TaskQueue(agentId) : null;
|
|
25334
25361
|
}
|
|
25335
25362
|
function manageTaskQueue(agentId, action, task, index) {
|
|
25336
25363
|
const queue = getCurrentTaskQueue(agentId);
|
|
25337
25364
|
if (!queue) {
|
|
25338
|
-
|
|
25365
|
+
throw new Error("\u672A\u627E\u5230\u5F53\u524D\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u521B\u5EFA agent \u4F1A\u8BDD");
|
|
25339
25366
|
}
|
|
25340
25367
|
if (action === "list") {
|
|
25341
25368
|
return formatJson({ tasks: queue.loadTasks() });
|
|
25342
25369
|
}
|
|
25343
25370
|
if (action === "add") {
|
|
25344
25371
|
if (!task?.trim()) {
|
|
25345
|
-
|
|
25372
|
+
throw new Error("\u6DFB\u52A0\u4EFB\u52A1\u65F6 task \u4E0D\u80FD\u4E3A\u7A7A");
|
|
25346
25373
|
}
|
|
25347
25374
|
queue.pushTask(task.trim());
|
|
25348
25375
|
return `\u5DF2\u6DFB\u52A0\u4EFB\u52A1: ${task.trim()}`;
|
|
@@ -25351,7 +25378,7 @@ function manageTaskQueue(agentId, action, task, index) {
|
|
|
25351
25378
|
const tasks = queue.loadTasks();
|
|
25352
25379
|
const safeIndex = Number(index);
|
|
25353
25380
|
if (!Number.isInteger(safeIndex) || safeIndex < 1 || safeIndex > tasks.length) {
|
|
25354
|
-
|
|
25381
|
+
throw new Error(`\u4EFB\u52A1\u5E8F\u53F7\u65E0\u6548\uFF0C\u5F53\u524D\u4EFB\u52A1\u6570 ${tasks.length}`);
|
|
25355
25382
|
}
|
|
25356
25383
|
const removed = tasks[safeIndex - 1];
|
|
25357
25384
|
queue.delTask(safeIndex - 1);
|
|
@@ -25360,11 +25387,11 @@ function manageTaskQueue(agentId, action, task, index) {
|
|
|
25360
25387
|
queue.clearTasks();
|
|
25361
25388
|
return "\u5DF2\u6E05\u7A7A\u4EFB\u52A1\u961F\u5217";
|
|
25362
25389
|
}
|
|
25363
|
-
var taskTool = (0,
|
|
25364
|
-
async ({ action, task, index }, runtime) => {
|
|
25390
|
+
var taskTool = (0, import_langchain13.tool)(
|
|
25391
|
+
async ({ action, task, index }, runtime) => safeTool(() => {
|
|
25365
25392
|
const agentId = runtime.context?.agentId || getAgentId();
|
|
25366
25393
|
return manageTaskQueue(agentId, action, task, index);
|
|
25367
|
-
},
|
|
25394
|
+
}),
|
|
25368
25395
|
{
|
|
25369
25396
|
name: "manage_task_queue",
|
|
25370
25397
|
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",
|
|
@@ -25377,7 +25404,7 @@ var taskTool = (0, import_langchain12.tool)(
|
|
|
25377
25404
|
);
|
|
25378
25405
|
|
|
25379
25406
|
// src/agent/tools/webfetch.ts
|
|
25380
|
-
var
|
|
25407
|
+
var import_langchain14 = require("langchain");
|
|
25381
25408
|
async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
|
|
25382
25409
|
const controller = new AbortController();
|
|
25383
25410
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
@@ -25406,35 +25433,29 @@ async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
|
|
|
25406
25433
|
),
|
|
25407
25434
|
maxLength
|
|
25408
25435
|
);
|
|
25409
|
-
} catch (error51) {
|
|
25410
|
-
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
25411
|
-
return `Web fetch error: ${message}`;
|
|
25412
25436
|
} finally {
|
|
25413
25437
|
clearTimeout(timer);
|
|
25414
25438
|
}
|
|
25415
25439
|
}
|
|
25416
|
-
var webFetchTool = (0,
|
|
25417
|
-
|
|
25418
|
-
|
|
25419
|
-
|
|
25420
|
-
|
|
25421
|
-
|
|
25422
|
-
|
|
25423
|
-
|
|
25424
|
-
|
|
25425
|
-
})
|
|
25426
|
-
}
|
|
25427
|
-
);
|
|
25440
|
+
var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
|
|
25441
|
+
name: "web_fetch",
|
|
25442
|
+
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",
|
|
25443
|
+
schema: external_exports.object({
|
|
25444
|
+
url: external_exports.string().url().describe("\u8981\u8BF7\u6C42\u7684\u5B8C\u6574 URL\uFF0C\u4F8B\u5982 https://example.com"),
|
|
25445
|
+
timeout: external_exports.number().default(3e4).describe("\u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09"),
|
|
25446
|
+
maxLength: external_exports.number().default(6e4).describe("\u6700\u5927\u8FD4\u56DE\u5B57\u7B26\u6570\uFF0C\u8D85\u51FA\u4F1A\u622A\u65AD")
|
|
25447
|
+
})
|
|
25448
|
+
});
|
|
25428
25449
|
|
|
25429
25450
|
// src/agent/tools/write.ts
|
|
25430
25451
|
var import_fs_extra17 = __toESM(require("fs-extra"));
|
|
25431
25452
|
var import_path15 = __toESM(require("path"));
|
|
25432
|
-
var
|
|
25453
|
+
var import_langchain15 = require("langchain");
|
|
25433
25454
|
async function writeFile2(filePath, content, mode = "overwrite") {
|
|
25434
25455
|
const absPath = resolveWorkspacePath(filePath);
|
|
25435
25456
|
const exists = await import_fs_extra17.default.pathExists(absPath);
|
|
25436
25457
|
if (mode === "create" && exists) {
|
|
25437
|
-
|
|
25458
|
+
throw new Error(`\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0Ccreate \u6A21\u5F0F\u4E0D\u4F1A\u8986\u76D6 ${absPath}`);
|
|
25438
25459
|
}
|
|
25439
25460
|
await import_fs_extra17.default.ensureDir(import_path15.default.dirname(absPath));
|
|
25440
25461
|
if (mode === "append") {
|
|
@@ -25444,18 +25465,15 @@ async function writeFile2(filePath, content, mode = "overwrite") {
|
|
|
25444
25465
|
await import_fs_extra17.default.writeFile(absPath, content, "utf-8");
|
|
25445
25466
|
return `${exists ? "\u5DF2\u8986\u76D6\u5199\u5165\u6587\u4EF6" : "\u5DF2\u521B\u5EFA\u6587\u4EF6"}: ${absPath}`;
|
|
25446
25467
|
}
|
|
25447
|
-
var writeFileTool = (0,
|
|
25448
|
-
|
|
25449
|
-
|
|
25450
|
-
|
|
25451
|
-
|
|
25452
|
-
|
|
25453
|
-
|
|
25454
|
-
|
|
25455
|
-
|
|
25456
|
-
})
|
|
25457
|
-
}
|
|
25458
|
-
);
|
|
25468
|
+
var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile2(filePath, content, mode)), {
|
|
25469
|
+
name: "write_file",
|
|
25470
|
+
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",
|
|
25471
|
+
schema: external_exports.object({
|
|
25472
|
+
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"),
|
|
25473
|
+
content: external_exports.string().describe("\u8981\u5199\u5165\u7684\u5B8C\u6574\u6587\u672C\u5185\u5BB9"),
|
|
25474
|
+
mode: external_exports.enum(["overwrite", "append", "create"]).default("overwrite").describe("\u5199\u5165\u6A21\u5F0F\uFF1Aoverwrite \u8986\u76D6\u3001append \u8FFD\u52A0\u3001create \u4EC5\u65B0\u5EFA")
|
|
25475
|
+
})
|
|
25476
|
+
});
|
|
25459
25477
|
|
|
25460
25478
|
// src/agent/tools/index.ts
|
|
25461
25479
|
var builtinTools = [
|
|
@@ -25529,19 +25547,19 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25529
25547
|
memoryFilePath: external_exports.string().optional(),
|
|
25530
25548
|
agentId: external_exports.string().optional()
|
|
25531
25549
|
});
|
|
25532
|
-
const agent = (0,
|
|
25550
|
+
const agent = (0, import_langchain16.createAgent)({
|
|
25533
25551
|
model,
|
|
25534
25552
|
checkpointer,
|
|
25535
25553
|
tools: this.tools,
|
|
25536
25554
|
contextSchema,
|
|
25537
25555
|
middleware: [
|
|
25538
25556
|
createAgentEventMiddleware(this),
|
|
25539
|
-
(0,
|
|
25557
|
+
(0, import_langchain16.summarizationMiddleware)({
|
|
25540
25558
|
model,
|
|
25541
25559
|
trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
|
|
25542
25560
|
keep: { messages: 50 }
|
|
25543
25561
|
}),
|
|
25544
|
-
(0,
|
|
25562
|
+
(0, import_langchain16.humanInTheLoopMiddleware)({
|
|
25545
25563
|
interruptOn: {
|
|
25546
25564
|
install_package: {
|
|
25547
25565
|
allowedDecisions: ["approve", "reject"]
|
|
@@ -25549,7 +25567,7 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25549
25567
|
readEmailTool: false
|
|
25550
25568
|
}
|
|
25551
25569
|
}),
|
|
25552
|
-
(0,
|
|
25570
|
+
(0, import_langchain16.todoListMiddleware)(),
|
|
25553
25571
|
(0, import_deepagents.createPatchToolCallsMiddleware)(),
|
|
25554
25572
|
(0, import_deepagents.createSubAgentMiddleware)({
|
|
25555
25573
|
defaultModel: model,
|
|
@@ -25572,7 +25590,7 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25572
25590
|
this.initEvents();
|
|
25573
25591
|
}
|
|
25574
25592
|
async execute(input) {
|
|
25575
|
-
const humanMessage = new
|
|
25593
|
+
const humanMessage = new import_langchain16.HumanMessage(input);
|
|
25576
25594
|
this.messages.push(humanMessage);
|
|
25577
25595
|
const stream = await this.agent.stream(
|
|
25578
25596
|
{ messages: this.messages },
|
|
@@ -25592,7 +25610,7 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25592
25610
|
}
|
|
25593
25611
|
const newTask = this.taskQueue.getTask();
|
|
25594
25612
|
if (newTask) {
|
|
25595
|
-
log(`[
|
|
25613
|
+
log(`[Task Queue] New task found, executing: ${newTask.taskStr}`, "#7fded1");
|
|
25596
25614
|
await this.execute(newTask.taskStr);
|
|
25597
25615
|
}
|
|
25598
25616
|
}
|
|
@@ -25609,7 +25627,6 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25609
25627
|
if (this.isPrintThinking) {
|
|
25610
25628
|
thinking.stop();
|
|
25611
25629
|
}
|
|
25612
|
-
streamOutput("\n");
|
|
25613
25630
|
});
|
|
25614
25631
|
this.on("MODEL_ERROR" /* MODEL_ERROR */, (error51) => {
|
|
25615
25632
|
if (this.isPrintThinking) {
|
|
@@ -25637,13 +25654,13 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25637
25654
|
this.on("NEW_MESSAGE" /* NEW_MESSAGE */, (_msg) => {
|
|
25638
25655
|
});
|
|
25639
25656
|
this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
|
|
25640
|
-
log(`[
|
|
25657
|
+
log(`[Tool Call] ${funcName}`, "#c2a654");
|
|
25641
25658
|
});
|
|
25642
|
-
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId,
|
|
25659
|
+
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
|
|
25643
25660
|
});
|
|
25644
|
-
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId,
|
|
25661
|
+
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
|
|
25645
25662
|
});
|
|
25646
|
-
this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId,
|
|
25663
|
+
this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
|
|
25647
25664
|
});
|
|
25648
25665
|
}
|
|
25649
25666
|
destory() {
|
|
@@ -25923,7 +25940,6 @@ function connectAgentRoom(agent) {
|
|
|
25923
25940
|
reconnectInterval: 0,
|
|
25924
25941
|
// Disable auto-reconnect during Promise phase
|
|
25925
25942
|
onReady: () => {
|
|
25926
|
-
logSuccess(`[agent-room] agent online: ${id}`);
|
|
25927
25943
|
done({ ok: true, client });
|
|
25928
25944
|
},
|
|
25929
25945
|
onError: (_c, code) => {
|
|
@@ -25950,7 +25966,6 @@ async function testServer() {
|
|
|
25950
25966
|
const res = await fetch(url2, { method: "GET" });
|
|
25951
25967
|
const text = await res.text();
|
|
25952
25968
|
if (text === "pong") {
|
|
25953
|
-
logSuccess(`Service already running: http://localhost:${port}`);
|
|
25954
25969
|
return true;
|
|
25955
25970
|
}
|
|
25956
25971
|
logError(`Port ${port} is occupied but /ping did not return expected result (received: ${text}), please check for port conflict`);
|
|
@@ -26165,7 +26180,7 @@ function handleSkillsDel(index) {
|
|
|
26165
26180
|
register = register.filter((item) => item.skillPath !== skill.skillPath);
|
|
26166
26181
|
import_fs_extra19.default.writeJSONSync(registerPath, register, { spaces: 2 });
|
|
26167
26182
|
}
|
|
26168
|
-
logSuccess(`Skill
|
|
26183
|
+
logSuccess(`Skill deleted: ${skill.name}`);
|
|
26169
26184
|
}
|
|
26170
26185
|
function handleSkillsEnable(index) {
|
|
26171
26186
|
const skills = _getAllSkills();
|
|
@@ -26225,8 +26240,8 @@ async function handleSkillsGenerate(target) {
|
|
|
26225
26240
|
return;
|
|
26226
26241
|
}
|
|
26227
26242
|
try {
|
|
26228
|
-
const
|
|
26229
|
-
if (!
|
|
26243
|
+
const isServerRunning = await testServer();
|
|
26244
|
+
if (!isServerRunning) {
|
|
26230
26245
|
logError("Failed to start service, please check config or port availability");
|
|
26231
26246
|
return;
|
|
26232
26247
|
}
|
|
@@ -26409,8 +26424,8 @@ async function handleToolsGenerate(target) {
|
|
|
26409
26424
|
return;
|
|
26410
26425
|
}
|
|
26411
26426
|
try {
|
|
26412
|
-
const
|
|
26413
|
-
if (!
|
|
26427
|
+
const isServerRunning = await testServer();
|
|
26428
|
+
if (!isServerRunning) {
|
|
26414
26429
|
logError("Failed to start service, please check config or port availability");
|
|
26415
26430
|
return;
|
|
26416
26431
|
}
|
|
@@ -26471,7 +26486,7 @@ function registerServeCommands(program) {
|
|
|
26471
26486
|
openDirectory(url2);
|
|
26472
26487
|
return;
|
|
26473
26488
|
}
|
|
26474
|
-
logError(`Port ${port} is occupied but did not respond with expected content
|
|
26489
|
+
logError(`Port ${port} is occupied but did not respond with expected content (received: ${text})`);
|
|
26475
26490
|
} catch (err) {
|
|
26476
26491
|
logWarning("Service not started, please run `ai serve start`");
|
|
26477
26492
|
}
|
|
@@ -26512,7 +26527,7 @@ function handleTaskAdd(taskStr) {
|
|
|
26512
26527
|
const queue = getTaskQueue();
|
|
26513
26528
|
if (!queue) return;
|
|
26514
26529
|
queue.pushTask(taskStr.trim());
|
|
26515
|
-
logSuccess(
|
|
26530
|
+
logSuccess(`Task added: ${taskStr.trim()}`);
|
|
26516
26531
|
}
|
|
26517
26532
|
function handleTaskDel(indexStr) {
|
|
26518
26533
|
const index = parseInt(indexStr, 10);
|
|
@@ -26580,8 +26595,8 @@ async function handleInput(args) {
|
|
|
26580
26595
|
logError("No AI model configured, please run ai model use <name>");
|
|
26581
26596
|
return;
|
|
26582
26597
|
}
|
|
26583
|
-
const
|
|
26584
|
-
if (!
|
|
26598
|
+
const isServerRunning = await testServer();
|
|
26599
|
+
if (!isServerRunning) {
|
|
26585
26600
|
logError("Failed to start service, please check config or port availability");
|
|
26586
26601
|
return;
|
|
26587
26602
|
}
|
|
@@ -26617,8 +26632,8 @@ async function multiInput() {
|
|
|
26617
26632
|
logError("No AI model configured, please run ai model use <name>");
|
|
26618
26633
|
return;
|
|
26619
26634
|
}
|
|
26620
|
-
const
|
|
26621
|
-
if (!
|
|
26635
|
+
const isServerRunning = await testServer();
|
|
26636
|
+
if (!isServerRunning) {
|
|
26622
26637
|
logError("Failed to start service, please check config or port availability");
|
|
26623
26638
|
return;
|
|
26624
26639
|
}
|