deepfish-ai 2.0.6 → 2.0.7

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 CHANGED
@@ -9001,7 +9001,7 @@ var import_path18 = __toESM(require("path"));
9001
9001
  var import_crypto5 = require("crypto");
9002
9002
 
9003
9003
  // src/agent/AIAgent/index.ts
9004
- var import_langchain17 = require("langchain");
9004
+ var import_langchain18 = require("langchain");
9005
9005
  var import_deepagents2 = require("deepagents");
9006
9006
 
9007
9007
  // src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
@@ -9363,11 +9363,11 @@ var StorePathResolver = class {
9363
9363
  splitWithSplitter(str) {
9364
9364
  return str.split(this.splitter).map(decodeFilename);
9365
9365
  }
9366
- getThreadPath(threadId) {
9367
- return (0, import_path4.join)(this.rootFolder, this.joinWithSplitter(threadId));
9366
+ getThreadPath(_threadId) {
9367
+ return (0, import_path4.join)(this.rootFolder, _threadId);
9368
9368
  }
9369
9369
  getCheckpointNsPath(_threadId, _checkpointNs) {
9370
- return (0, import_path4.join)(this.rootFolder);
9370
+ return (0, import_path4.join)(this.rootFolder, _threadId, _checkpointNs || this.defaultCheckpointNs);
9371
9371
  }
9372
9372
  getCheckpointFolderPath(threadId, checkpointNs, checkpointId) {
9373
9373
  return (0, import_path4.join)(this.getCheckpointNsPath(threadId, checkpointNs), checkpointId);
@@ -9450,6 +9450,35 @@ var FileSystemSaver = class extends BaseCheckpointSaver {
9450
9450
  super(serde);
9451
9451
  this.pathResolver = new StorePathResolver(rootFolder, splitter);
9452
9452
  }
9453
+ // 还原到最后一次会话结束时的检查点
9454
+ async init(agentId, agent) {
9455
+ const { lastCheckPointId, allCheckPointId } = await this.getLastCheckPointId(agentId, agent);
9456
+ if (lastCheckPointId && allCheckPointId.includes(lastCheckPointId)) {
9457
+ for (const checkpointId of allCheckPointId) {
9458
+ if (checkpointId !== lastCheckPointId) {
9459
+ const checkpointPath = this.pathResolver.getCheckpointFolderPath(agentId, this.pathResolver.defaultCheckpointNs, checkpointId);
9460
+ await safeDeleteFile(checkpointPath);
9461
+ } else {
9462
+ break;
9463
+ }
9464
+ }
9465
+ }
9466
+ }
9467
+ async getLastCheckPointId(agentId, agent) {
9468
+ const threadConfig = { configurable: { thread_id: agentId } };
9469
+ const history = [];
9470
+ const compiledGraph = agent.graph;
9471
+ const checkPointIds = [];
9472
+ for await (const state of compiledGraph.getStateHistory(threadConfig)) {
9473
+ history.push(state);
9474
+ checkPointIds.push(state.config.configurable?.["checkpoint_id"]);
9475
+ }
9476
+ const finishSnap = history.find((s) => s.next.length === 0);
9477
+ return {
9478
+ lastCheckPointId: finishSnap?.config.configurable?.["checkpoint_id"],
9479
+ allCheckPointId: checkPointIds
9480
+ };
9481
+ }
9453
9482
  async *list(config2, options) {
9454
9483
  const { before, limit, filter } = options ?? {};
9455
9484
  const threadIds = config2.configurable?.["thread_id"] ? [config2.configurable["thread_id"]] : await listDirs(this.pathResolver.rootFolder);
@@ -9514,11 +9543,7 @@ var FileSystemSaver = class extends BaseCheckpointSaver {
9514
9543
  const extraPath = (0, import_path5.join)(checkpointsPath, "extra.json");
9515
9544
  const metadataPath = (0, import_path5.join)(checkpointsPath, "metadata");
9516
9545
  const checkpointPath = (0, import_path5.join)(checkpointsPath, "checkpoint");
9517
- const [extraJson, metadata, checkpoint] = await Promise.all([
9518
- readJSON(extraPath),
9519
- readBinary(metadataPath),
9520
- readBinary(checkpointPath)
9521
- ]);
9546
+ const [extraJson, metadata, checkpoint] = await Promise.all([readJSON(extraPath), readBinary(metadataPath), readBinary(checkpointPath)]);
9522
9547
  const [deserializedMetadata, deserializedCheckpoint] = await Promise.all([
9523
9548
  this.serde.loadsTyped("json", metadata),
9524
9549
  this.serde.loadsTyped("json", checkpoint)
@@ -9565,11 +9590,7 @@ var FileSystemSaver = class extends BaseCheckpointSaver {
9565
9590
  const extraPath = (0, import_path5.join)(checkpointsPath, "extra.json");
9566
9591
  const metadataPath = (0, import_path5.join)(checkpointsPath, "metadata");
9567
9592
  const checkpointPath = (0, import_path5.join)(checkpointsPath, "checkpoint");
9568
- const [extraJson, metadata, checkpoint] = await Promise.all([
9569
- readJSON(extraPath),
9570
- readBinary(metadataPath),
9571
- readBinary(checkpointPath)
9572
- ]);
9593
+ const [extraJson, metadata, checkpoint] = await Promise.all([readJSON(extraPath), readBinary(metadataPath), readBinary(checkpointPath)]);
9573
9594
  const [deserializedMetadata, deserializedCheckpoint] = await Promise.all([
9574
9595
  this.serde.loadsTyped("json", metadata),
9575
9596
  this.serde.loadsTyped("json", checkpoint)
@@ -9618,9 +9639,7 @@ var FileSystemSaver = class extends BaseCheckpointSaver {
9618
9639
  const parentCheckpointId = config2.configurable?.["checkpoint_id"];
9619
9640
  const checkpointId = checkpoint.id;
9620
9641
  if (threadId === void 0) {
9621
- throw new Error(
9622
- `Failed to put checkpoint. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property.`
9623
- );
9642
+ throw new Error(`Failed to put checkpoint. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property.`);
9624
9643
  }
9625
9644
  const checkpointsPath = this.pathResolver.getCheckpointsPath(threadId, checkpointNs, checkpointId);
9626
9645
  await checkOrCreateFolder(checkpointsPath);
@@ -9644,14 +9663,10 @@ var FileSystemSaver = class extends BaseCheckpointSaver {
9644
9663
  const checkpointId = config2.configurable?.["checkpoint_id"];
9645
9664
  const checkpointNs = config2.configurable?.["checkpoint_ns"];
9646
9665
  if (threadId === void 0) {
9647
- throw new Error(
9648
- `Failed to put writes. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property`
9649
- );
9666
+ throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property`);
9650
9667
  }
9651
9668
  if (checkpointId === void 0) {
9652
- throw new Error(
9653
- `Failed to put writes. The passed RunnableConfig is missing a required "checkpoint_id" field in its "configurable" property.`
9654
- );
9669
+ throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "checkpoint_id" field in its "configurable" property.`);
9655
9670
  }
9656
9671
  const writesPath = this.pathResolver.getWritesPath(threadId, checkpointNs, checkpointId);
9657
9672
  await checkOrCreateFolder(writesPath);
@@ -24329,15 +24344,15 @@ function parseSkillMetadataYaml(skillPath) {
24329
24344
 
24330
24345
  // src/agent/AIAgent/system-prompt.ts
24331
24346
  var import_fs_extra5 = __toESM(require("fs-extra"));
24332
- function getSkillPrompt(skills) {
24347
+ function getSkillPrompt(skills, excludeSkills) {
24333
24348
  const parsedSkills = skills.map((skill) => {
24334
24349
  return parseSkillMetadataYaml(skill);
24335
- });
24350
+ }).filter((skill) => skill !== null && !excludeSkills.includes(skill.name));
24336
24351
  let skillPrompt = "";
24337
24352
  if (parsedSkills.length > 0) {
24338
24353
  const skillTable = parsedSkills.map((s) => `| ${s.name} | ${s.description} | ${s.location} | ${s.skillFilePath} |`).join("\n");
24339
24354
  skillPrompt = `
24340
- ### \u53EF\u4EE5\u4F7F\u7528\u7684Skills
24355
+ # \u53EF\u4EE5\u4F7F\u7528\u7684Skills
24341
24356
  \u53EF\u4EE5\u8C03\u7528\u4EE5\u4E0BSkill\u6765\u5B8C\u6210\u7528\u6237\u4EFB\u52A1\u76EE\u6807,Skill\u7684\u8C03\u7528\u65B9\u5F0F:
24342
24357
  - \u4F7F\u7528\u7528\u6237\u8BF7\u6C42\u5339\u914D skill description,
24343
24358
  - \u4E00\u6B21\u53EA\u52A0\u8F7D\u4E00\u4E2ASkill,\u4F18\u5148\u5339\u914D\u6700\u5177\u4F53\u7684Skill
@@ -24360,8 +24375,10 @@ function getUserMemoryPrompt(memoryFilePath) {
24360
24375
  if (import_fs_extra5.default.existsSync(memoryFilePath)) {
24361
24376
  const content = import_fs_extra5.default.readFileSync(memoryFilePath, "utf-8");
24362
24377
  return `
24363
- ### \u7528\u6237\u4FE1\u606F
24378
+ # \u7528\u6237\u4FE1\u606F
24379
+ \`\`\`
24364
24380
  ${content}
24381
+ \`\`\`
24365
24382
  `;
24366
24383
  }
24367
24384
  return "";
@@ -24372,34 +24389,34 @@ function getAgentRulesPrompt(agentRulesPath) {
24372
24389
  }
24373
24390
  if (import_fs_extra5.default.existsSync(agentRulesPath)) {
24374
24391
  const content = import_fs_extra5.default.readFileSync(agentRulesPath, "utf-8");
24375
- return `### \u4EE5\u4E0B\u662FAgent\u884C\u4E3A\u89C4\u8303\uFF0C\u5FC5\u987B\u4E25\u683C\u9075\u5B88\uFF1A
24392
+ return `# \u4EE5\u4E0B\u662FAgent\u884C\u4E3A\u89C4\u8303\uFF0C\u5FC5\u987B\u4E25\u683C\u9075\u5B88\uFF1A
24376
24393
  ${content}
24377
24394
  `;
24378
24395
  }
24379
24396
  }
24380
- var systemPrompt = (workspace, osType, skills, memoryFilePath, agentRulesPath) => {
24381
- const skillPrompt = getSkillPrompt(skills);
24382
- const memoryPrompt = getUserMemoryPrompt(memoryFilePath);
24383
- const agentRulesPrompt = getAgentRulesPrompt(agentRulesPath);
24397
+ var getSystemPrompt = (params) => {
24398
+ const skillPrompt = getSkillPrompt(params.skills, params.excludeSkills);
24399
+ const memoryPrompt = getUserMemoryPrompt(params.memoryFilePath);
24400
+ const agentRulesPrompt = getAgentRulesPrompt(params.agentRulesPath);
24384
24401
  return `
24385
- \u8FD9\u662FDeepfish Cli\u7CFB\u7EDF,\u4F60\u662F\u7CFB\u7EDF\u4E2D\u4E25\u683C\u6309\u89C4\u5219\u6267\u884C\u4EFB\u52A1\u7684\u667A\u80FD\u4F53,\u4E0D\u80FD\u8FDD\u53CD\u4EFB\u4F55\u7CFB\u7EDF\u9650\u5236\u3002
24386
- ### \u57FA\u7840\u73AF\u5883\u4FE1\u606F
24387
- \u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${workspace}
24388
- \u64CD\u4F5C\u7CFB\u7EDF\u7C7B\u578B\uFF1A${osType}
24389
- \u8BED\u8A00\u7C7B\u578B: \u4E0E\u7528\u6237\u8F93\u5165\u8BED\u8A00\u4E00\u81F4
24390
-
24391
- \u6CE8\u610F:
24402
+ ${params.systemPrompt || `\u8FD9\u662FDeepfish Cli\u7CFB\u7EDF,\u4F60\u662F\u7CFB\u7EDF\u4E2D\u4E25\u683C\u6309\u89C4\u5219\u6267\u884C\u4EFB\u52A1\u7684\u667A\u80FD\u4F53,\u4E0D\u80FD\u8FDD\u53CD\u4EFB\u4F55\u7CFB\u7EDF\u9650\u5236\u3002
24403
+ # \u6CE8\u610F\u6CE8\u610F\u4E8B\u9879:
24392
24404
  1.\u5982\u679C\u4EFB\u52A1\u6BD4\u8F83\u590D\u6742\uFF0C\u5E94\u8BE5\u5148\u8FDB\u884C\u62C6\u5206\uFF0C\u5206\u89E3\u6210\u591A\u4E2A\u6B65\u9AA4\uFF0C\u521B\u5EFA\u5B50\u667A\u80FD\u4F53\u6765\u9010\u6B65\u5B8C\u6210\u3002
24393
24405
  2.\u4E34\u65F6\u6587\u4EF6\u5FC5\u987B\u4F7F\u7528"tmp_"\u4F5C\u4E3A\u524D\u7F00\u547D\u540D\uFF0C\u5E76\u5728\u4EFB\u52A1\u7ED3\u675F\u540E\u5220\u9664\uFF0C\u4E0D\u80FD\u5728\u5DE5\u4F5C\u76EE\u5F55\u4E2D\u7559\u4E0B\u4EFB\u4F55\u4E34\u65F6\u6587\u4EF6\u3002
24394
- 3.\u5C3D\u91CF\u4F7F\u7528"execute_command"\u3001"execute_js_code"\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1
24406
+ 3.\u5C3D\u91CF\u4F7F\u7528"execute_command"\u3001"execute_js_code"\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1`}
24407
+
24408
+ # \u57FA\u7840\u73AF\u5883\u4FE1\u606F
24409
+ \u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${params.workspace}
24410
+ \u64CD\u4F5C\u7CFB\u7EDF\u7C7B\u578B\uFF1A${params.osType}
24411
+ \u8BED\u8A00\u7C7B\u578B: \u4E0E\u7528\u6237\u8F93\u5165\u8BED\u8A00\u4E00\u81F4
24395
24412
 
24396
24413
  ${skillPrompt}
24397
24414
  ${memoryPrompt}
24398
24415
  ${agentRulesPrompt}
24399
24416
  `;
24400
24417
  };
24401
- var subSystemPrompt = (workspace, osType, skills) => {
24402
- let skillPrompt = getSkillPrompt(skills);
24418
+ var subSystemPrompt = (workspace, osType, skills, excludeSkills) => {
24419
+ let skillPrompt = getSkillPrompt(skills, excludeSkills);
24403
24420
  return `
24404
24421
  \u8FD9\u662FDeepfish Cli\u7CFB\u7EDF,\u4F60\u662F\u7CFB\u7EDF\u4E2D\u4E25\u683C\u6309\u89C4\u5219\u6267\u884C\u4EFB\u52A1\u7684\u5B50\u667A\u80FD\u4F53,\u4E0D\u80FD\u8FDD\u53CD\u4EFB\u4F55\u7CFB\u7EDF\u9650\u5236\u3002
24405
24422
  ### \u57FA\u7840\u73AF\u5883\u4FE1\u606F
@@ -24628,10 +24645,11 @@ function toLangChainTool(func, description) {
24628
24645
  const wrappedFunc = async (args, runtime) => {
24629
24646
  try {
24630
24647
  const boundFunc = func.bind({
24631
- createSubAgent: (prompt) => {
24632
- const subAgent = runtime.context.mainAgent.createSubAgent();
24648
+ createSubAgent: async (prompt) => {
24649
+ const subAgent = await runtime.context.curAgent.createSubAgent();
24633
24650
  return subAgent.execute(prompt);
24634
- }
24651
+ },
24652
+ curAgent: runtime.context.curAgent
24635
24653
  });
24636
24654
  const result = await boundFunc(...Object.values(args));
24637
24655
  if (typeof result === "object" && result !== null && "success" in result) {
@@ -24648,7 +24666,7 @@ function toLangChainTool(func, description) {
24648
24666
  schema
24649
24667
  });
24650
24668
  }
24651
- function scanUserTools() {
24669
+ function scanUserTools(excludeTools) {
24652
24670
  const tools = [];
24653
24671
  const scanPaths = getScanDirPaths();
24654
24672
  scanPaths.forEach((scanPath) => {
@@ -24663,20 +24681,20 @@ function scanUserTools() {
24663
24681
  if (indexFile) {
24664
24682
  const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, indexFile), indexFile);
24665
24683
  if (filePath) {
24666
- _loadToolsFromFile(filePath, tools);
24684
+ _loadToolsFromFile(filePath, tools, excludeTools);
24667
24685
  }
24668
24686
  } else {
24669
24687
  subFiles.forEach((subFile) => {
24670
24688
  const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, subFile), subFile);
24671
24689
  if (filePath) {
24672
- _loadToolsFromFile(filePath, tools);
24690
+ _loadToolsFromFile(filePath, tools, excludeTools);
24673
24691
  }
24674
24692
  });
24675
24693
  }
24676
24694
  } else {
24677
24695
  const filePath = _scanDeepFishJsFile(toolsDir, file2);
24678
24696
  if (filePath) {
24679
- _loadToolsFromFile(filePath, tools);
24697
+ _loadToolsFromFile(filePath, tools, excludeTools);
24680
24698
  }
24681
24699
  }
24682
24700
  });
@@ -24693,7 +24711,7 @@ function _scanDeepFishJsFile(filePath, fileName) {
24693
24711
  }
24694
24712
  return null;
24695
24713
  }
24696
- function _loadToolsFromFile(filePath, tools) {
24714
+ function _loadToolsFromFile(filePath, tools, excludeTools) {
24697
24715
  try {
24698
24716
  const toolModule = require(filePath);
24699
24717
  const { functions, descriptions } = toolModule;
@@ -24708,6 +24726,9 @@ function _loadToolsFromFile(filePath, tools) {
24708
24726
  function: desc
24709
24727
  };
24710
24728
  }
24729
+ if (excludeTools.includes(desc.function.name)) {
24730
+ return;
24731
+ }
24711
24732
  const func = functions[desc.function.name];
24712
24733
  if (typeof func !== "function") {
24713
24734
  logWarning(`Skip tool "${desc.function.name}": implementation not found in ${filePath}`);
@@ -24776,10 +24797,33 @@ var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => s
24776
24797
  });
24777
24798
 
24778
24799
  // src/agent/tools/executeJSCode.ts
24779
- var import_langchain4 = require("langchain");
24800
+ var import_langchain5 = require("langchain");
24780
24801
  var import_path9 = __toESM(require("path"));
24781
24802
  var import_fs_extra9 = __toESM(require("fs-extra"));
24782
- async function executeJSCode(code) {
24803
+
24804
+ // src/agent/tools/subAgent.ts
24805
+ var import_langchain4 = require("langchain");
24806
+ async function subAgentExec(prompt, runtime) {
24807
+ const curAgent = runtime.context?.curAgent;
24808
+ if (!curAgent || typeof curAgent.createSubAgent !== "function") {
24809
+ throw new Error("\u5F53\u524D\u8FD0\u884C\u4E0A\u4E0B\u6587\u4E0D\u652F\u6301\u521B\u5EFA\u5B50 agent");
24810
+ }
24811
+ const subAgent = await curAgent.createSubAgent();
24812
+ return subAgent.execute(prompt);
24813
+ }
24814
+ var subAgentTool = (0, import_langchain4.tool)(
24815
+ async ({ prompt }, runtime) => safeTool(() => subAgentExec(prompt, runtime)),
24816
+ {
24817
+ name: "subAgent_exec",
24818
+ description: "\u521B\u5EFA\u4E00\u4E2A\u901A\u7528\u5B50 agent \u6765\u6267\u884C\u72EC\u7ACB\u4EFB\u52A1\uFF0C\u5E76\u8FD4\u56DE\u5B50 agent \u7684\u6267\u884C\u7ED3\u679C\u3002\u9002\u5408\u62C6\u5206\u590D\u6742\u4EFB\u52A1\u3001\u5E76\u884C\u8C03\u7814\u6216\u59D4\u6D3E\u5B50\u4EFB\u52A1\u3002",
24819
+ schema: external_exports.object({
24820
+ prompt: external_exports.string().min(1).describe("\u4EA4\u7ED9\u901A\u7528\u5B50 agent \u6267\u884C\u7684\u5B8C\u6574\u4EFB\u52A1\u63CF\u8FF0")
24821
+ })
24822
+ }
24823
+ );
24824
+
24825
+ // src/agent/tools/executeJSCode.ts
24826
+ async function executeJSCode(code, runtime) {
24783
24827
  logInfo("Executing JavaScript code: ");
24784
24828
  logInfo(code);
24785
24829
  try {
@@ -24788,7 +24832,7 @@ async function executeJSCode(code) {
24788
24832
  const result = await __main()
24789
24833
  return result || "Code executed successfully, but __main() did not return anything."
24790
24834
  })()`;
24791
- const fn = new Function("require", wrapped);
24835
+ const fn = new Function("require", "agentExec", wrapped);
24792
24836
  const _require = require;
24793
24837
  const newRequire = (modulePath) => {
24794
24838
  if (modulePath.startsWith("./")) {
@@ -24797,14 +24841,17 @@ async function executeJSCode(code) {
24797
24841
  }
24798
24842
  return _require(modulePath);
24799
24843
  };
24800
- const result = await fn(newRequire);
24844
+ const agentExec = async (prompt) => {
24845
+ return subAgentExec(prompt, runtime);
24846
+ };
24847
+ const result = await fn(newRequire, agentExec);
24801
24848
  return result;
24802
24849
  } catch (error51) {
24803
24850
  logError(`Error executing code: ${error51.stack}`);
24804
24851
  throw error51;
24805
24852
  }
24806
24853
  }
24807
- var getInstalledPackagesTool = (0, import_langchain4.tool)(
24854
+ var getInstalledPackagesTool = (0, import_langchain5.tool)(
24808
24855
  async () => safeTool(() => {
24809
24856
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24810
24857
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24816,7 +24863,7 @@ var getInstalledPackagesTool = (0, import_langchain4.tool)(
24816
24863
  schema: external_exports.object({})
24817
24864
  }
24818
24865
  );
24819
- var checkPackageInstalledTool = (0, import_langchain4.tool)(
24866
+ var checkPackageInstalledTool = (0, import_langchain5.tool)(
24820
24867
  async ({ packageName }) => safeTool(() => {
24821
24868
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24822
24869
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24831,7 +24878,7 @@ var checkPackageInstalledTool = (0, import_langchain4.tool)(
24831
24878
  })
24832
24879
  }
24833
24880
  );
24834
- var installPackageTool = (0, import_langchain4.tool)(
24881
+ var installPackageTool = (0, import_langchain5.tool)(
24835
24882
  async ({ packageName }) => safeTool(() => {
24836
24883
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24837
24884
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24848,12 +24895,16 @@ var installPackageTool = (0, import_langchain4.tool)(
24848
24895
  })
24849
24896
  }
24850
24897
  );
24851
- var executeJSCodeTool = (0, import_langchain4.tool)(async ({ code }) => safeTool(() => executeJSCode(code)), {
24898
+ var executeJSCodeTool = (0, import_langchain5.tool)(async ({ code }, runtime) => safeTool(() => executeJSCode(code, runtime)), {
24852
24899
  name: "execute_js_code",
24853
- 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
24900
+ 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
24901
+ \u53EF\u7528\u5185\u7F6E\u51FD\u6570\uFF1A
24902
+ - agentExec(prompt: string): Promise<string>\uFF0C\u521B\u5EFA\u4E00\u4E2A\u901A\u7528\u5B50 agent \u6267\u884C\u6307\u5B9A\u4EFB\u52A1\u5E76\u8FD4\u56DE\u7ED3\u679C\uFF0C\u9002\u5408\u5C06\u590D\u6742\u4EFB\u52A1\u62C6\u5206\u7ED9\u5B50 agent \u5B8C\u6210\u3002
24903
+ \u793A\u4F8B\u4EE3\u7801\uFF1A
24854
24904
  async function __main() {
24855
24905
  const data = await fs.readFile("data.txt", "utf-8")
24856
- return data
24906
+ const analysis = await agentExec("\u8BF7\u5206\u6790\u8FD9\u6BB5\u6587\u4EF6\u5185\u5BB9\u5E76\u603B\u7ED3\u91CD\u70B9\uFF1A" + data)
24907
+ return analysis
24857
24908
  }
24858
24909
  `,
24859
24910
  schema: external_exports.object({
@@ -24949,9 +25000,9 @@ var UserCache = class {
24949
25000
  };
24950
25001
 
24951
25002
  // src/agent/tools/learn-self.ts
24952
- var import_langchain5 = require("langchain");
25003
+ var import_langchain6 = require("langchain");
24953
25004
  var userCache = new UserCache();
24954
- var learnSelfTool = (0, import_langchain5.tool)(
25005
+ var learnSelfTool = (0, import_langchain6.tool)(
24955
25006
  ({ description, content }) => safeTool(() => {
24956
25007
  userCache.add(description, content);
24957
25008
  return `\u5DF2\u7F13\u5B58\u89E3\u51B3\u65B9\u6848: ${description}`;
@@ -24965,7 +25016,7 @@ var learnSelfTool = (0, import_langchain5.tool)(
24965
25016
  })
24966
25017
  }
24967
25018
  );
24968
- var getLearnedDetailTool = (0, import_langchain5.tool)(
25019
+ var getLearnedDetailTool = (0, import_langchain6.tool)(
24969
25020
  ({ indexOrId }) => safeTool(() => {
24970
25021
  const index = Number(indexOrId);
24971
25022
  let item;
@@ -24994,7 +25045,7 @@ ${detail.content}`;
24994
25045
  })
24995
25046
  }
24996
25047
  );
24997
- var updateLearnContentTool = (0, import_langchain5.tool)(
25048
+ var updateLearnContentTool = (0, import_langchain6.tool)(
24998
25049
  ({ id, content }) => safeTool(() => {
24999
25050
  const success2 = userCache.update(id, content);
25000
25051
  if (!success2) {
@@ -25011,7 +25062,7 @@ var updateLearnContentTool = (0, import_langchain5.tool)(
25011
25062
  })
25012
25063
  }
25013
25064
  );
25014
- var getCatalogFilePathTool = (0, import_langchain5.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
25065
+ var getCatalogFilePathTool = (0, import_langchain6.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
25015
25066
  name: "get_catalog_file_path",
25016
25067
  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",
25017
25068
  schema: external_exports.object({})
@@ -25021,7 +25072,7 @@ var learnTools = [learnSelfTool, getLearnedDetailTool, updateLearnContentTool, g
25021
25072
  // src/agent/tools/mcp.ts
25022
25073
  var import_mcp_adapters = require("@langchain/mcp-adapters");
25023
25074
  var import_fs_extra11 = __toESM(require("fs-extra"));
25024
- var import_langchain6 = require("langchain");
25075
+ var import_langchain7 = require("langchain");
25025
25076
  var import_path11 = __toESM(require("path"));
25026
25077
  function normalizeMcpToolResult(result) {
25027
25078
  if (Array.isArray(result)) {
@@ -25033,7 +25084,7 @@ function normalizeMcpToolResult(result) {
25033
25084
  return result;
25034
25085
  }
25035
25086
  function wrapMcpTool(mcpTool) {
25036
- const wrapped = (0, import_langchain6.tool)(
25087
+ const wrapped = (0, import_langchain7.tool)(
25037
25088
  async (input, runtime) => {
25038
25089
  try {
25039
25090
  const result = await mcpTool.invoke(input, runtime);
@@ -25050,7 +25101,7 @@ function wrapMcpTool(mcpTool) {
25050
25101
  );
25051
25102
  return wrapped;
25052
25103
  }
25053
- async function loadMcpToolsFromConfigPath(mcpFilePath) {
25104
+ async function loadMcpToolsFromConfigPath(mcpFilePath, excludeMCP) {
25054
25105
  const jsonContent = import_fs_extra11.default.readJSONSync(mcpFilePath);
25055
25106
  let mcpServers = jsonContent.mcpServers;
25056
25107
  if (!mcpServers || Object.keys(mcpServers).length === 0) {
@@ -25059,7 +25110,7 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
25059
25110
  try {
25060
25111
  for (const key of Object.keys(mcpServers)) {
25061
25112
  const server = mcpServers[key];
25062
- if (server.disabled) {
25113
+ if (server.disabled || excludeMCP.includes(key)) {
25063
25114
  delete mcpServers[key];
25064
25115
  continue;
25065
25116
  }
@@ -25092,13 +25143,13 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
25092
25143
  return [];
25093
25144
  }
25094
25145
  }
25095
- async function scanUserMcp() {
25146
+ async function scanUserMcp(excludeMCP) {
25096
25147
  const tools = [];
25097
25148
  const scanPaths = getScanDirPaths();
25098
25149
  for (const scanPath of scanPaths) {
25099
25150
  const mcpFilePath = import_path11.default.join(scanPath, "mcp.json");
25100
25151
  if (import_fs_extra11.default.existsSync(mcpFilePath)) {
25101
- const mcpTools = await loadMcpToolsFromConfigPath(mcpFilePath);
25152
+ const mcpTools = await loadMcpToolsFromConfigPath(mcpFilePath, excludeMCP);
25102
25153
  tools.push(...mcpTools);
25103
25154
  }
25104
25155
  }
@@ -25107,7 +25158,7 @@ async function scanUserMcp() {
25107
25158
 
25108
25159
  // src/agent/tools/edit.ts
25109
25160
  var import_fs_extra12 = __toESM(require("fs-extra"));
25110
- var import_langchain7 = require("langchain");
25161
+ var import_langchain8 = require("langchain");
25111
25162
  async function editFileByReplace(filePath, oldString, newString, replaceAll = false) {
25112
25163
  const absPath = resolveWorkspacePath(filePath);
25113
25164
  if (!await import_fs_extra12.default.pathExists(absPath)) {
@@ -25128,7 +25179,7 @@ async function editFileByReplace(filePath, oldString, newString, replaceAll = fa
25128
25179
  await import_fs_extra12.default.writeFile(absPath, nextContent, "utf-8");
25129
25180
  return `\u5DF2\u7F16\u8F91\u6587\u4EF6: ${absPath}\uFF0C\u66FF\u6362 ${replaceAll ? matches : 1} \u5904`;
25130
25181
  }
25131
- var editFileTool = (0, import_langchain7.tool)(
25182
+ var editFileTool = (0, import_langchain8.tool)(
25132
25183
  async ({ filePath, oldString, newString, replaceAll }) => safeTool(() => editFileByReplace(filePath, oldString, newString, replaceAll)),
25133
25184
  {
25134
25185
  name: "edit_file",
@@ -25144,7 +25195,7 @@ var editFileTool = (0, import_langchain7.tool)(
25144
25195
 
25145
25196
  // src/agent/tools/glob.ts
25146
25197
  var import_path12 = __toESM(require("path"));
25147
- var import_langchain8 = require("langchain");
25198
+ var import_langchain9 = require("langchain");
25148
25199
  async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false) {
25149
25200
  const rootDir = resolveWorkspacePath(cwd || ".");
25150
25201
  const allFiles = await walkFiles(rootDir, { includeHidden, maxFiles: Math.max(maxResults * 20, 1e3) });
@@ -25152,7 +25203,7 @@ async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false)
25152
25203
  const matches = allFiles.map((file2) => normalizePathForMatch(import_path12.default.relative(rootDir, file2))).filter((relativePath) => matchesGlob(relativePath, normalizedPattern)).slice(0, maxResults);
25153
25204
  return truncateOutput(formatJson({ cwd: rootDir, pattern, count: matches.length, files: matches }));
25154
25205
  }
25155
- var globTool = (0, import_langchain8.tool)(
25206
+ var globTool = (0, import_langchain9.tool)(
25156
25207
  async ({ pattern, cwd, maxResults, includeHidden }) => safeTool(() => globFiles(pattern, cwd, maxResults, includeHidden)),
25157
25208
  {
25158
25209
  name: "glob_files",
@@ -25169,7 +25220,7 @@ var globTool = (0, import_langchain8.tool)(
25169
25220
  // src/agent/tools/grep.ts
25170
25221
  var import_fs_extra13 = __toESM(require("fs-extra"));
25171
25222
  var import_path13 = __toESM(require("path"));
25172
- var import_langchain9 = require("langchain");
25223
+ var import_langchain10 = require("langchain");
25173
25224
  async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false, maxResults = 100, includeHidden = false) {
25174
25225
  const rootDir = resolveWorkspacePath(cwd || ".");
25175
25226
  const matcher = isRegexp ? new RegExp(query, "i") : null;
@@ -25194,7 +25245,7 @@ async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false,
25194
25245
  }
25195
25246
  return truncateOutput(formatJson({ cwd: rootDir, query, includePattern, count: matches.length, matches }));
25196
25247
  }
25197
- var grepTool = (0, import_langchain9.tool)(
25248
+ var grepTool = (0, import_langchain10.tool)(
25198
25249
  async ({ query, pattern, cwd, includePattern, isRegexp, maxResults, includeHidden }) => safeTool(() => {
25199
25250
  const searchQuery = query || pattern;
25200
25251
  if (!searchQuery) {
@@ -25222,7 +25273,7 @@ var grepTool = (0, import_langchain9.tool)(
25222
25273
 
25223
25274
  // src/agent/tools/question.ts
25224
25275
  var import_inquirer2 = __toESM(require("inquirer"));
25225
- var import_langchain10 = require("langchain");
25276
+ var import_langchain11 = require("langchain");
25226
25277
  async function askQuestion(question, type = "input", choices = []) {
25227
25278
  const promptType = type === "select" ? "list" : type;
25228
25279
  const answer = await import_inquirer2.default.prompt([
@@ -25236,7 +25287,7 @@ async function askQuestion(question, type = "input", choices = []) {
25236
25287
  const value = answer["value"];
25237
25288
  return typeof value === "string" ? value : JSON.stringify(value);
25238
25289
  }
25239
- var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
25290
+ var questionTool = (0, import_langchain11.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
25240
25291
  name: "ask_question",
25241
25292
  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",
25242
25293
  schema: external_exports.object({
@@ -25249,7 +25300,7 @@ var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices
25249
25300
  // src/agent/tools/read.ts
25250
25301
  var import_fs_extra14 = __toESM(require("fs-extra"));
25251
25302
  var import_iconv_lite2 = __toESM(require("iconv-lite"));
25252
- var import_langchain11 = require("langchain");
25303
+ var import_langchain12 = require("langchain");
25253
25304
  async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
25254
25305
  const absPath = resolveWorkspacePath(filePath);
25255
25306
  if (!await import_fs_extra14.default.pathExists(absPath)) {
@@ -25271,7 +25322,7 @@ async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
25271
25322
  const selected = lines.slice(safeStart - 1, safeEnd).map((line, index) => `${safeStart + index}: ${line}`).join("\n");
25272
25323
  return truncateOutput(formatJson({ filePath: absPath, totalLines: lines.length, startLine: safeStart, endLine: safeEnd, content: selected }));
25273
25324
  }
25274
- var readFileTool = (0, import_langchain11.tool)(
25325
+ var readFileTool = (0, import_langchain12.tool)(
25275
25326
  async ({ filePath, startLine, endLine, encoding }) => safeTool(() => readFile2(filePath, startLine, endLine, encoding)),
25276
25327
  {
25277
25328
  name: "read_file",
@@ -25288,7 +25339,7 @@ var readFileTool = (0, import_langchain11.tool)(
25288
25339
  // src/agent/tools/semanticMemory.ts
25289
25340
  var import_fs_extra15 = __toESM(require("fs-extra"));
25290
25341
  var import_path14 = __toESM(require("path"));
25291
- var import_langchain12 = require("langchain");
25342
+ var import_langchain13 = require("langchain");
25292
25343
  var DEFAULT_MEMORY_MARKDOWN = `# \u7528\u6237\u8BED\u4E49\u8BB0\u5FC6
25293
25344
 
25294
25345
  > \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
@@ -25324,7 +25375,7 @@ async function updateSemanticMemory(memoryFilePath, content) {
25324
25375
  `, "utf-8");
25325
25376
  return `\u5DF2\u66F4\u65B0\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6: ${memoryFilePath}`;
25326
25377
  }
25327
- var readSemanticMemoryTool = (0, import_langchain12.tool)(
25378
+ var readSemanticMemoryTool = (0, import_langchain13.tool)(
25328
25379
  async (_input, runtime) => safeTool(() => readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath))),
25329
25380
  {
25330
25381
  name: "read_user_semantic_memory",
@@ -25332,7 +25383,7 @@ var readSemanticMemoryTool = (0, import_langchain12.tool)(
25332
25383
  schema: external_exports.object({})
25333
25384
  }
25334
25385
  );
25335
- var updateSemanticMemoryTool = (0, import_langchain12.tool)(
25386
+ var updateSemanticMemoryTool = (0, import_langchain13.tool)(
25336
25387
  async ({ content }, runtime) => safeTool(() => updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content)),
25337
25388
  {
25338
25389
  name: "update_user_semantic_memory",
@@ -25392,7 +25443,7 @@ var TaskQueue = class {
25392
25443
  };
25393
25444
 
25394
25445
  // src/agent/tools/task.ts
25395
- var import_langchain13 = require("langchain");
25446
+ var import_langchain14 = require("langchain");
25396
25447
  function getCurrentTaskQueue(agentId) {
25397
25448
  return agentId ? new TaskQueue(agentId) : null;
25398
25449
  }
@@ -25424,7 +25475,7 @@ function manageTaskQueue(agentId, action, task, index) {
25424
25475
  queue.clearTasks();
25425
25476
  return "\u5DF2\u6E05\u7A7A\u4EFB\u52A1\u961F\u5217";
25426
25477
  }
25427
- var taskTool = (0, import_langchain13.tool)(
25478
+ var taskTool = (0, import_langchain14.tool)(
25428
25479
  async ({ action, task, index }, runtime) => safeTool(() => {
25429
25480
  const agentId = runtime.context?.agentId || getAgentId();
25430
25481
  return manageTaskQueue(agentId, action, task, index);
@@ -25441,7 +25492,7 @@ var taskTool = (0, import_langchain13.tool)(
25441
25492
  );
25442
25493
 
25443
25494
  // src/agent/tools/webfetch.ts
25444
- var import_langchain14 = require("langchain");
25495
+ var import_langchain15 = require("langchain");
25445
25496
  async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
25446
25497
  const controller = new AbortController();
25447
25498
  const timer = setTimeout(() => controller.abort(), timeout);
@@ -25474,7 +25525,7 @@ async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
25474
25525
  clearTimeout(timer);
25475
25526
  }
25476
25527
  }
25477
- var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
25528
+ var webFetchTool = (0, import_langchain15.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
25478
25529
  name: "web_fetch",
25479
25530
  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",
25480
25531
  schema: external_exports.object({
@@ -25487,7 +25538,7 @@ var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, max
25487
25538
  // src/agent/tools/write.ts
25488
25539
  var import_fs_extra17 = __toESM(require("fs-extra"));
25489
25540
  var import_path15 = __toESM(require("path"));
25490
- var import_langchain15 = require("langchain");
25541
+ var import_langchain16 = require("langchain");
25491
25542
  async function writeFile2(filePath, content, mode = "overwrite") {
25492
25543
  const absPath = resolveWorkspacePath(filePath);
25493
25544
  const exists = await import_fs_extra17.default.pathExists(absPath);
@@ -25502,7 +25553,7 @@ async function writeFile2(filePath, content, mode = "overwrite") {
25502
25553
  await import_fs_extra17.default.writeFile(absPath, content, "utf-8");
25503
25554
  return `${exists ? "\u5DF2\u8986\u76D6\u5199\u5165\u6587\u4EF6" : "\u5DF2\u521B\u5EFA\u6587\u4EF6"}: ${absPath}`;
25504
25555
  }
25505
- var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile2(filePath, content, mode)), {
25556
+ var writeFileTool = (0, import_langchain16.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile2(filePath, content, mode)), {
25506
25557
  name: "write_file",
25507
25558
  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",
25508
25559
  schema: external_exports.object({
@@ -25515,6 +25566,7 @@ var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mod
25515
25566
  // src/agent/tools/index.ts
25516
25567
  var builtinTools = [
25517
25568
  taskTool,
25569
+ subAgentTool,
25518
25570
  executeCommandTool,
25519
25571
  readFileTool,
25520
25572
  editFileTool,
@@ -25527,8 +25579,8 @@ var builtinTools = [
25527
25579
  ...semanticMemoryTools,
25528
25580
  ...learnTools
25529
25581
  ];
25530
- async function getTools() {
25531
- return [...builtinTools, ...await scanUserTools(), ...await scanUserMcp()];
25582
+ async function getTools(excludeTools, excludeMCP) {
25583
+ return [...builtinTools, ...await scanUserTools(excludeTools), ...await scanUserMcp(excludeMCP)];
25532
25584
  }
25533
25585
 
25534
25586
  // src/agent/skills/index.ts
@@ -25540,13 +25592,14 @@ function getSkills() {
25540
25592
  // src/agent/AIAgent/index.ts
25541
25593
  var import_os4 = __toESM(require("os"));
25542
25594
 
25543
- // src/agent/AIAgent/SubAIAgent.ts
25544
- var import_langchain16 = require("langchain");
25595
+ // src/agent/AIAgent/SubAgents/SubAIAgent.ts
25596
+ var import_langchain17 = require("langchain");
25545
25597
  var import_deepagents = require("deepagents");
25546
25598
  var import_eventemitter_super = require("eventemitter-super");
25547
25599
  var import_os3 = __toESM(require("os"));
25548
25600
  var import_crypto4 = require("crypto");
25549
- var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25601
+ var import_lodash = require("lodash");
25602
+ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitterSuper {
25550
25603
  id = "";
25551
25604
  opt = {};
25552
25605
  tools = [];
@@ -25563,8 +25616,14 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25563
25616
  userStorePath = "";
25564
25617
  agentRulesPath = "";
25565
25618
  isPrintThinking = true;
25619
+ maxSubAgentCount = 2;
25620
+ excludeTools = [];
25621
+ excludeSkills = [];
25622
+ excludeMCP = [];
25623
+ systemPrompt = "";
25566
25624
  constructor(opt) {
25567
25625
  super();
25626
+ this.opt = (0, import_lodash.cloneDeep)(opt);
25568
25627
  this.id = opt.id || `agent-${(0, import_crypto4.randomUUID)()}`;
25569
25628
  this.basespace = opt.basespace;
25570
25629
  this.workspace = opt.workspace;
@@ -25573,32 +25632,53 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25573
25632
  this.userStorePath = opt.userStorePath;
25574
25633
  this.agentRulesPath = opt.agentRulesPath;
25575
25634
  this.isPrintThinking = opt.isPrintThinking;
25576
- this.opt = opt;
25635
+ this.excludeTools = opt.excludeTools || [];
25636
+ this.excludeSkills = opt.excludeSkills || [];
25637
+ this.excludeMCP = opt.excludeMCP || [];
25638
+ this.systemPrompt = opt.systemPrompt || "";
25639
+ this.subLevel = opt.subLevel || 1;
25640
+ this.maxSubAgentCount = opt.maxSubAgentCount || 2;
25577
25641
  }
25578
25642
  async init() {
25579
- this.tools = await getTools();
25643
+ if (this.subLevel > 2) {
25644
+ this.excludeTools.push("subAgent_exec");
25645
+ }
25646
+ this.tools = await getTools(this.excludeTools, this.excludeMCP);
25580
25647
  this.skills = [...getSkills(), ...this.opt.skills || []];
25581
25648
  const model = getModel(this.opt.modelOpt);
25649
+ const checkpointer = new FileSystemSaver({
25650
+ rootFolder: this.sessionDirPath
25651
+ });
25582
25652
  const contextSchema = external_exports.object({
25583
25653
  agent_name: external_exports.string(),
25584
25654
  encoding: external_exports.string(),
25585
25655
  skills: external_exports.array(external_exports.string()).optional(),
25586
25656
  memoryFilePath: external_exports.string().optional(),
25587
25657
  agentId: external_exports.string().optional(),
25588
- mainAgent: external_exports.object().optional()
25658
+ curAgent: external_exports.object().optional()
25589
25659
  });
25590
- const agent = (0, import_langchain16.createAgent)({
25660
+ const systemPrompt = this.subLevel > 2 ? getSystemPrompt({
25661
+ systemPrompt: this.systemPrompt,
25662
+ workspace: this.workspace,
25663
+ osType: import_os3.default.platform(),
25664
+ skills: this.skills,
25665
+ memoryFilePath: this.memoryFilePath,
25666
+ agentRulesPath: this.agentRulesPath,
25667
+ excludeSkills: this.excludeSkills
25668
+ }) : subSystemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.excludeSkills);
25669
+ const agent = (0, import_langchain17.createAgent)({
25591
25670
  model,
25671
+ checkpointer,
25592
25672
  tools: this.tools,
25593
25673
  contextSchema,
25594
25674
  middleware: [
25595
25675
  createAgentEventMiddleware(this),
25596
- (0, import_langchain16.summarizationMiddleware)({
25676
+ (0, import_langchain17.summarizationMiddleware)({
25597
25677
  model,
25598
25678
  trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
25599
25679
  keep: { messages: 50 }
25600
25680
  }),
25601
- (0, import_langchain16.humanInTheLoopMiddleware)({
25681
+ (0, import_langchain17.humanInTheLoopMiddleware)({
25602
25682
  interruptOn: {
25603
25683
  install_package: {
25604
25684
  allowedDecisions: ["approve", "reject"]
@@ -25606,29 +25686,17 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25606
25686
  readEmailTool: false
25607
25687
  }
25608
25688
  }),
25609
- (0, import_langchain16.todoListMiddleware)(),
25610
- (0, import_deepagents.createPatchToolCallsMiddleware)(),
25611
- (0, import_deepagents.createSubAgentMiddleware)({
25612
- defaultModel: model,
25613
- subagents: [
25614
- {
25615
- name: "subagent",
25616
- description: "This subagent can execute sub tasks.",
25617
- systemPrompt: subSystemPrompt(this.workspace, import_os3.default.platform(), this.skills),
25618
- tools: this.tools,
25619
- model,
25620
- middleware: []
25621
- }
25622
- ]
25623
- })
25689
+ (0, import_langchain17.todoListMiddleware)(),
25690
+ (0, import_deepagents.createPatchToolCallsMiddleware)()
25624
25691
  ],
25625
- systemPrompt: systemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
25692
+ systemPrompt
25626
25693
  });
25694
+ await checkpointer.init(this.id, agent);
25627
25695
  this.agent = agent;
25628
25696
  this.initEvents();
25629
25697
  }
25630
25698
  async execute(input) {
25631
- const humanMessage = new import_langchain16.HumanMessage(input);
25699
+ const humanMessage = new import_langchain17.HumanMessage(input);
25632
25700
  this.messages.push(humanMessage);
25633
25701
  const stream = await this.agent.stream(
25634
25702
  { messages: this.messages },
@@ -25643,7 +25711,7 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25643
25711
  skills: this.skills,
25644
25712
  memoryFilePath: this.memoryFilePath,
25645
25713
  agentId: this.id,
25646
- mainAgent: this
25714
+ curAgent: this
25647
25715
  }
25648
25716
  }
25649
25717
  );
@@ -25710,20 +25778,29 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25710
25778
  this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
25711
25779
  });
25712
25780
  }
25781
+ async createSubAgent() {
25782
+ const subAgent = new _SubAIAgent(this.opt);
25783
+ subAgent.subLevel = this.subLevel + 1;
25784
+ await subAgent.init();
25785
+ return subAgent;
25786
+ }
25713
25787
  destory() {
25714
25788
  this.removeAllListeners();
25715
25789
  }
25716
25790
  };
25717
25791
 
25718
25792
  // src/agent/AIAgent/index.ts
25793
+ var import_lodash2 = require("lodash");
25719
25794
  var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25720
25795
  id = "";
25796
+ threadId = "main_session_records";
25721
25797
  opt = {};
25722
25798
  tools = [];
25723
25799
  dynamicTools = [];
25724
25800
  skills = [];
25725
25801
  mcp = [];
25726
25802
  subLevel = 0;
25803
+ maxSubAgentCount = 2;
25727
25804
  agent = {};
25728
25805
  messages = [];
25729
25806
  basespace = "";
@@ -25735,8 +25812,13 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25735
25812
  roomClient = null;
25736
25813
  taskQueue = {};
25737
25814
  isPrintThinking = true;
25815
+ excludeTools = [];
25816
+ excludeSkills = [];
25817
+ excludeMCP = [];
25818
+ systemPrompt = "";
25738
25819
  constructor(opt) {
25739
25820
  super();
25821
+ this.opt = (0, import_lodash2.cloneDeep)(opt);
25740
25822
  this.id = opt.id || `agent-${Date.now()}`;
25741
25823
  this.basespace = opt.basespace;
25742
25824
  this.workspace = opt.workspace;
@@ -25745,10 +25827,15 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25745
25827
  this.userStorePath = opt.userStorePath;
25746
25828
  this.agentRulesPath = opt.agentRulesPath;
25747
25829
  this.isPrintThinking = opt.isPrintThinking;
25748
- this.opt = opt;
25830
+ this.excludeTools = opt.excludeTools || [];
25831
+ this.excludeSkills = opt.excludeSkills || [];
25832
+ this.excludeMCP = opt.excludeMCP || [];
25833
+ this.systemPrompt = opt.systemPrompt || "";
25834
+ this.subLevel = 0;
25835
+ this.maxSubAgentCount = opt.maxSubAgentCount || 2;
25749
25836
  }
25750
25837
  async init() {
25751
- this.tools = await getTools();
25838
+ this.tools = await getTools(this.excludeTools, this.excludeMCP);
25752
25839
  this.skills = [...getSkills(), ...this.opt.skills || []];
25753
25840
  const model = getModel(this.opt.modelOpt);
25754
25841
  const checkpointer = new FileSystemSaver({
@@ -25760,21 +25847,21 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25760
25847
  skills: external_exports.array(external_exports.string()).optional(),
25761
25848
  memoryFilePath: external_exports.string().optional(),
25762
25849
  agentId: external_exports.string().optional(),
25763
- mainAgent: external_exports.object().optional()
25850
+ curAgent: external_exports.object().optional()
25764
25851
  });
25765
- const agent = (0, import_langchain17.createAgent)({
25852
+ const agent = (0, import_langchain18.createAgent)({
25766
25853
  model,
25767
25854
  checkpointer,
25768
25855
  tools: this.tools,
25769
25856
  contextSchema,
25770
25857
  middleware: [
25771
25858
  createAgentEventMiddleware(this),
25772
- (0, import_langchain17.summarizationMiddleware)({
25859
+ (0, import_langchain18.summarizationMiddleware)({
25773
25860
  model,
25774
25861
  trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
25775
25862
  keep: { messages: 50 }
25776
25863
  }),
25777
- (0, import_langchain17.humanInTheLoopMiddleware)({
25864
+ (0, import_langchain18.humanInTheLoopMiddleware)({
25778
25865
  interruptOn: {
25779
25866
  install_package: {
25780
25867
  allowedDecisions: ["approve", "reject"]
@@ -25782,30 +25869,26 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25782
25869
  readEmailTool: false
25783
25870
  }
25784
25871
  }),
25785
- (0, import_langchain17.todoListMiddleware)(),
25786
- (0, import_deepagents2.createPatchToolCallsMiddleware)(),
25787
- (0, import_deepagents2.createSubAgentMiddleware)({
25788
- defaultModel: model,
25789
- subagents: [
25790
- {
25791
- name: "subagent",
25792
- description: "This subagent can execute sub tasks.",
25793
- systemPrompt: subSystemPrompt(this.workspace, import_os4.default.platform(), this.skills),
25794
- tools: this.tools,
25795
- model,
25796
- middleware: []
25797
- }
25798
- ]
25799
- })
25872
+ (0, import_langchain18.todoListMiddleware)(),
25873
+ (0, import_deepagents2.createPatchToolCallsMiddleware)()
25800
25874
  ],
25801
- systemPrompt: systemPrompt(this.workspace, import_os4.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
25875
+ systemPrompt: getSystemPrompt({
25876
+ systemPrompt: this.systemPrompt,
25877
+ workspace: this.workspace,
25878
+ osType: import_os4.default.platform(),
25879
+ skills: this.skills,
25880
+ memoryFilePath: this.memoryFilePath,
25881
+ agentRulesPath: this.agentRulesPath,
25882
+ excludeSkills: this.excludeSkills
25883
+ })
25802
25884
  });
25885
+ await checkpointer.init(this.threadId, agent);
25803
25886
  this.agent = agent;
25804
25887
  this.taskQueue = new TaskQueue(this.id);
25805
25888
  this.initEvents();
25806
25889
  }
25807
25890
  async execute(input) {
25808
- const humanMessage = new import_langchain17.HumanMessage(input);
25891
+ const humanMessage = new import_langchain18.HumanMessage(input);
25809
25892
  this.messages.push(humanMessage);
25810
25893
  const stream = await this.agent.stream(
25811
25894
  { messages: this.messages },
@@ -25813,21 +25896,23 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25813
25896
  streamMode: ["messages"],
25814
25897
  recursionLimit: 2e3,
25815
25898
  subgraphs: true,
25816
- configurable: { thread_id: this.id },
25899
+ configurable: { thread_id: this.threadId },
25817
25900
  context: {
25818
25901
  agent_name: "deepfish",
25819
25902
  encoding: this.opt.encoding,
25820
25903
  skills: this.skills,
25821
25904
  memoryFilePath: this.memoryFilePath,
25822
25905
  agentId: this.id,
25823
- mainAgent: this
25906
+ curAgent: this
25824
25907
  }
25825
25908
  }
25826
25909
  );
25827
25910
  for await (const [_namespace, mode, data] of stream) {
25828
25911
  if (mode === "messages") {
25829
- const message = data[0].additional_kwargs.reasoning_content;
25830
- this.emit("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, message);
25912
+ const message = data?.[0];
25913
+ const reasoning_content = message?.additional_kwargs?.reasoning_content;
25914
+ const toolcall_content = message?.tool_call_chunks?.[0]?.args;
25915
+ this.emit("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, reasoning_content || toolcall_content || "");
25831
25916
  }
25832
25917
  }
25833
25918
  const newTask = this.taskQueue.getTask();
@@ -25840,8 +25925,8 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25840
25925
  const thinking = new Thinking();
25841
25926
  this.on("TASK_BEFORE" /* TASK_BEFORE */, () => {
25842
25927
  });
25843
- this.on("TASK_AFTER" /* TASK_AFTER */, (msg) => {
25844
- logInfo(msg);
25928
+ this.on("TASK_AFTER" /* TASK_AFTER */, (_msg) => {
25929
+ logSuccess(_msg);
25845
25930
  });
25846
25931
  this.on("MODEL_BEFORE" /* MODEL_BEFORE */, () => {
25847
25932
  });
@@ -25849,6 +25934,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25849
25934
  if (this.isPrintThinking) {
25850
25935
  thinking.stop();
25851
25936
  }
25937
+ streamOutput("\n");
25852
25938
  });
25853
25939
  this.on("MODEL_ERROR" /* MODEL_ERROR */, (error51) => {
25854
25940
  if (this.isPrintThinking) {
@@ -25878,8 +25964,8 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25878
25964
  this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
25879
25965
  log(`[Tool Call] ${funcName}`, "#c2a654");
25880
25966
  });
25881
- this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
25882
- logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
25967
+ this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
25968
+ logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent.length > 50 ? _toolContent.slice(0, 50) + "..." : _toolContent}`);
25883
25969
  });
25884
25970
  this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
25885
25971
  logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
@@ -25887,8 +25973,10 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25887
25973
  this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
25888
25974
  });
25889
25975
  }
25890
- createSubAgent() {
25891
- return new SubAIAgent(this.opt);
25976
+ async createSubAgent() {
25977
+ const subAgent = new SubAIAgent(this.opt);
25978
+ await subAgent.init();
25979
+ return subAgent;
25892
25980
  }
25893
25981
  destory() {
25894
25982
  this.removeAllListeners();
@@ -26947,6 +27035,7 @@ function handleCacheList() {
26947
27035
  }
26948
27036
  catalog.forEach((item, index) => {
26949
27037
  const desc = item.description.length > 20 ? item.description.slice(0, 20) + "..." : item.description;
27038
+ logInfo(`${index}. ${item.id} - ${desc}`);
26950
27039
  });
26951
27040
  }
26952
27041
  function handleCacheEdit(input) {