deepfish-ai 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
@@ -24596,42 +24613,64 @@ async function safeTool(handler) {
24596
24613
  return serializeToolResult(errorResult(error51));
24597
24614
  }
24598
24615
  }
24616
+ function jsonSchemaToZod(node) {
24617
+ if (!node || typeof node !== "object") {
24618
+ return external_exports.any();
24619
+ }
24620
+ const { type, description: desc, properties, items, required: required2, enum: enumValues } = node;
24621
+ const withDesc = (schema) => desc ? schema.describe(desc) : schema;
24622
+ if (Array.isArray(enumValues) && enumValues.length > 0) {
24623
+ const allStrings = enumValues.every((v) => typeof v === "string");
24624
+ if (allStrings) {
24625
+ return withDesc(external_exports.enum(enumValues));
24626
+ }
24627
+ }
24628
+ switch (type) {
24629
+ case "string":
24630
+ return withDesc(external_exports.string());
24631
+ case "number":
24632
+ case "integer":
24633
+ return withDesc(external_exports.number());
24634
+ case "boolean":
24635
+ return withDesc(external_exports.boolean());
24636
+ case "array": {
24637
+ const itemSchema = items ? jsonSchemaToZod(items) : external_exports.any();
24638
+ return withDesc(external_exports.array(itemSchema));
24639
+ }
24640
+ case "object": {
24641
+ const shape = {};
24642
+ if (properties && typeof properties === "object") {
24643
+ const requiredFields = Array.isArray(required2) ? required2 : [];
24644
+ for (const [key, value] of Object.entries(properties)) {
24645
+ let childSchema = jsonSchemaToZod(value);
24646
+ if (!requiredFields.includes(key)) {
24647
+ childSchema = childSchema.optional();
24648
+ }
24649
+ shape[key] = childSchema;
24650
+ }
24651
+ }
24652
+ return withDesc(external_exports.object(shape).passthrough());
24653
+ }
24654
+ default:
24655
+ return withDesc(external_exports.any());
24656
+ }
24657
+ }
24599
24658
  function toLangChainTool(func, description) {
24600
24659
  const { name, description: desc, parameters } = description.function;
24601
24660
  const { properties } = parameters;
24602
24661
  const zodProperties = {};
24603
24662
  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;
24663
+ zodProperties[key] = jsonSchemaToZod(value);
24626
24664
  }
24627
24665
  const schema = external_exports.object(zodProperties);
24628
24666
  const wrappedFunc = async (args, runtime) => {
24629
24667
  try {
24630
24668
  const boundFunc = func.bind({
24631
- createSubAgent: (prompt) => {
24632
- const subAgent = runtime.context.mainAgent.createSubAgent();
24669
+ createSubAgent: async (prompt) => {
24670
+ const subAgent = await runtime.context.curAgent.createSubAgent();
24633
24671
  return subAgent.execute(prompt);
24634
- }
24672
+ },
24673
+ curAgent: runtime.context.curAgent
24635
24674
  });
24636
24675
  const result = await boundFunc(...Object.values(args));
24637
24676
  if (typeof result === "object" && result !== null && "success" in result) {
@@ -24648,7 +24687,7 @@ function toLangChainTool(func, description) {
24648
24687
  schema
24649
24688
  });
24650
24689
  }
24651
- function scanUserTools() {
24690
+ function scanUserTools(excludeTools) {
24652
24691
  const tools = [];
24653
24692
  const scanPaths = getScanDirPaths();
24654
24693
  scanPaths.forEach((scanPath) => {
@@ -24663,20 +24702,20 @@ function scanUserTools() {
24663
24702
  if (indexFile) {
24664
24703
  const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, indexFile), indexFile);
24665
24704
  if (filePath) {
24666
- _loadToolsFromFile(filePath, tools);
24705
+ _loadToolsFromFile(filePath, tools, excludeTools);
24667
24706
  }
24668
24707
  } else {
24669
24708
  subFiles.forEach((subFile) => {
24670
24709
  const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, subFile), subFile);
24671
24710
  if (filePath) {
24672
- _loadToolsFromFile(filePath, tools);
24711
+ _loadToolsFromFile(filePath, tools, excludeTools);
24673
24712
  }
24674
24713
  });
24675
24714
  }
24676
24715
  } else {
24677
24716
  const filePath = _scanDeepFishJsFile(toolsDir, file2);
24678
24717
  if (filePath) {
24679
- _loadToolsFromFile(filePath, tools);
24718
+ _loadToolsFromFile(filePath, tools, excludeTools);
24680
24719
  }
24681
24720
  }
24682
24721
  });
@@ -24693,7 +24732,7 @@ function _scanDeepFishJsFile(filePath, fileName) {
24693
24732
  }
24694
24733
  return null;
24695
24734
  }
24696
- function _loadToolsFromFile(filePath, tools) {
24735
+ function _loadToolsFromFile(filePath, tools, excludeTools) {
24697
24736
  try {
24698
24737
  const toolModule = require(filePath);
24699
24738
  const { functions, descriptions } = toolModule;
@@ -24708,6 +24747,9 @@ function _loadToolsFromFile(filePath, tools) {
24708
24747
  function: desc
24709
24748
  };
24710
24749
  }
24750
+ if (excludeTools.includes(desc.function.name)) {
24751
+ return;
24752
+ }
24711
24753
  const func = functions[desc.function.name];
24712
24754
  if (typeof func !== "function") {
24713
24755
  logWarning(`Skip tool "${desc.function.name}": implementation not found in ${filePath}`);
@@ -24776,10 +24818,33 @@ var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => s
24776
24818
  });
24777
24819
 
24778
24820
  // src/agent/tools/executeJSCode.ts
24779
- var import_langchain4 = require("langchain");
24821
+ var import_langchain5 = require("langchain");
24780
24822
  var import_path9 = __toESM(require("path"));
24781
24823
  var import_fs_extra9 = __toESM(require("fs-extra"));
24782
- async function executeJSCode(code) {
24824
+
24825
+ // src/agent/tools/subAgent.ts
24826
+ var import_langchain4 = require("langchain");
24827
+ async function subAgentExec(prompt, runtime) {
24828
+ const curAgent = runtime.context?.curAgent;
24829
+ if (!curAgent || typeof curAgent.createSubAgent !== "function") {
24830
+ throw new Error("\u5F53\u524D\u8FD0\u884C\u4E0A\u4E0B\u6587\u4E0D\u652F\u6301\u521B\u5EFA\u5B50 agent");
24831
+ }
24832
+ const subAgent = await curAgent.createSubAgent();
24833
+ return subAgent.execute(prompt);
24834
+ }
24835
+ var subAgentTool = (0, import_langchain4.tool)(
24836
+ async ({ prompt }, runtime) => safeTool(() => subAgentExec(prompt, runtime)),
24837
+ {
24838
+ name: "subAgent_exec",
24839
+ 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",
24840
+ schema: external_exports.object({
24841
+ prompt: external_exports.string().min(1).describe("\u4EA4\u7ED9\u901A\u7528\u5B50 agent \u6267\u884C\u7684\u5B8C\u6574\u4EFB\u52A1\u63CF\u8FF0")
24842
+ })
24843
+ }
24844
+ );
24845
+
24846
+ // src/agent/tools/executeJSCode.ts
24847
+ async function executeJSCode(code, runtime) {
24783
24848
  logInfo("Executing JavaScript code: ");
24784
24849
  logInfo(code);
24785
24850
  try {
@@ -24788,7 +24853,7 @@ async function executeJSCode(code) {
24788
24853
  const result = await __main()
24789
24854
  return result || "Code executed successfully, but __main() did not return anything."
24790
24855
  })()`;
24791
- const fn = new Function("require", wrapped);
24856
+ const fn = new Function("require", "agentExec", wrapped);
24792
24857
  const _require = require;
24793
24858
  const newRequire = (modulePath) => {
24794
24859
  if (modulePath.startsWith("./")) {
@@ -24797,14 +24862,17 @@ async function executeJSCode(code) {
24797
24862
  }
24798
24863
  return _require(modulePath);
24799
24864
  };
24800
- const result = await fn(newRequire);
24865
+ const agentExec = async (prompt) => {
24866
+ return subAgentExec(prompt, runtime);
24867
+ };
24868
+ const result = await fn(newRequire, agentExec);
24801
24869
  return result;
24802
24870
  } catch (error51) {
24803
24871
  logError(`Error executing code: ${error51.stack}`);
24804
24872
  throw error51;
24805
24873
  }
24806
24874
  }
24807
- var getInstalledPackagesTool = (0, import_langchain4.tool)(
24875
+ var getInstalledPackagesTool = (0, import_langchain5.tool)(
24808
24876
  async () => safeTool(() => {
24809
24877
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24810
24878
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24816,7 +24884,7 @@ var getInstalledPackagesTool = (0, import_langchain4.tool)(
24816
24884
  schema: external_exports.object({})
24817
24885
  }
24818
24886
  );
24819
- var checkPackageInstalledTool = (0, import_langchain4.tool)(
24887
+ var checkPackageInstalledTool = (0, import_langchain5.tool)(
24820
24888
  async ({ packageName }) => safeTool(() => {
24821
24889
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24822
24890
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24831,7 +24899,7 @@ var checkPackageInstalledTool = (0, import_langchain4.tool)(
24831
24899
  })
24832
24900
  }
24833
24901
  );
24834
- var installPackageTool = (0, import_langchain4.tool)(
24902
+ var installPackageTool = (0, import_langchain5.tool)(
24835
24903
  async ({ packageName }) => safeTool(() => {
24836
24904
  const packageJson = import_path9.default.join(getCodePath(), "./package.json");
24837
24905
  const pkg = import_fs_extra9.default.readJsonSync(packageJson);
@@ -24848,12 +24916,16 @@ var installPackageTool = (0, import_langchain4.tool)(
24848
24916
  })
24849
24917
  }
24850
24918
  );
24851
- var executeJSCodeTool = (0, import_langchain4.tool)(async ({ code }) => safeTool(() => executeJSCode(code)), {
24919
+ var executeJSCodeTool = (0, import_langchain5.tool)(async ({ code }, runtime) => safeTool(() => executeJSCode(code, runtime)), {
24852
24920
  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
24921
+ 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
24922
+ \u53EF\u7528\u5185\u7F6E\u51FD\u6570\uFF1A
24923
+ - 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
24924
+ \u793A\u4F8B\u4EE3\u7801\uFF1A
24854
24925
  async function __main() {
24855
24926
  const data = await fs.readFile("data.txt", "utf-8")
24856
- return data
24927
+ const analysis = await agentExec("\u8BF7\u5206\u6790\u8FD9\u6BB5\u6587\u4EF6\u5185\u5BB9\u5E76\u603B\u7ED3\u91CD\u70B9\uFF1A" + data)
24928
+ return analysis
24857
24929
  }
24858
24930
  `,
24859
24931
  schema: external_exports.object({
@@ -24949,9 +25021,9 @@ var UserCache = class {
24949
25021
  };
24950
25022
 
24951
25023
  // src/agent/tools/learn-self.ts
24952
- var import_langchain5 = require("langchain");
25024
+ var import_langchain6 = require("langchain");
24953
25025
  var userCache = new UserCache();
24954
- var learnSelfTool = (0, import_langchain5.tool)(
25026
+ var learnSelfTool = (0, import_langchain6.tool)(
24955
25027
  ({ description, content }) => safeTool(() => {
24956
25028
  userCache.add(description, content);
24957
25029
  return `\u5DF2\u7F13\u5B58\u89E3\u51B3\u65B9\u6848: ${description}`;
@@ -24965,7 +25037,7 @@ var learnSelfTool = (0, import_langchain5.tool)(
24965
25037
  })
24966
25038
  }
24967
25039
  );
24968
- var getLearnedDetailTool = (0, import_langchain5.tool)(
25040
+ var getLearnedDetailTool = (0, import_langchain6.tool)(
24969
25041
  ({ indexOrId }) => safeTool(() => {
24970
25042
  const index = Number(indexOrId);
24971
25043
  let item;
@@ -24994,7 +25066,7 @@ ${detail.content}`;
24994
25066
  })
24995
25067
  }
24996
25068
  );
24997
- var updateLearnContentTool = (0, import_langchain5.tool)(
25069
+ var updateLearnContentTool = (0, import_langchain6.tool)(
24998
25070
  ({ id, content }) => safeTool(() => {
24999
25071
  const success2 = userCache.update(id, content);
25000
25072
  if (!success2) {
@@ -25011,7 +25083,7 @@ var updateLearnContentTool = (0, import_langchain5.tool)(
25011
25083
  })
25012
25084
  }
25013
25085
  );
25014
- var getCatalogFilePathTool = (0, import_langchain5.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
25086
+ var getCatalogFilePathTool = (0, import_langchain6.tool)(() => safeTool(() => userCache.getCatalogFilePath()), {
25015
25087
  name: "get_catalog_file_path",
25016
25088
  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
25089
  schema: external_exports.object({})
@@ -25021,7 +25093,7 @@ var learnTools = [learnSelfTool, getLearnedDetailTool, updateLearnContentTool, g
25021
25093
  // src/agent/tools/mcp.ts
25022
25094
  var import_mcp_adapters = require("@langchain/mcp-adapters");
25023
25095
  var import_fs_extra11 = __toESM(require("fs-extra"));
25024
- var import_langchain6 = require("langchain");
25096
+ var import_langchain7 = require("langchain");
25025
25097
  var import_path11 = __toESM(require("path"));
25026
25098
  function normalizeMcpToolResult(result) {
25027
25099
  if (Array.isArray(result)) {
@@ -25033,7 +25105,7 @@ function normalizeMcpToolResult(result) {
25033
25105
  return result;
25034
25106
  }
25035
25107
  function wrapMcpTool(mcpTool) {
25036
- const wrapped = (0, import_langchain6.tool)(
25108
+ const wrapped = (0, import_langchain7.tool)(
25037
25109
  async (input, runtime) => {
25038
25110
  try {
25039
25111
  const result = await mcpTool.invoke(input, runtime);
@@ -25050,7 +25122,7 @@ function wrapMcpTool(mcpTool) {
25050
25122
  );
25051
25123
  return wrapped;
25052
25124
  }
25053
- async function loadMcpToolsFromConfigPath(mcpFilePath) {
25125
+ async function loadMcpToolsFromConfigPath(mcpFilePath, excludeMCP) {
25054
25126
  const jsonContent = import_fs_extra11.default.readJSONSync(mcpFilePath);
25055
25127
  let mcpServers = jsonContent.mcpServers;
25056
25128
  if (!mcpServers || Object.keys(mcpServers).length === 0) {
@@ -25059,7 +25131,7 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
25059
25131
  try {
25060
25132
  for (const key of Object.keys(mcpServers)) {
25061
25133
  const server = mcpServers[key];
25062
- if (server.disabled) {
25134
+ if (server.disabled || excludeMCP.includes(key)) {
25063
25135
  delete mcpServers[key];
25064
25136
  continue;
25065
25137
  }
@@ -25092,13 +25164,13 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
25092
25164
  return [];
25093
25165
  }
25094
25166
  }
25095
- async function scanUserMcp() {
25167
+ async function scanUserMcp(excludeMCP) {
25096
25168
  const tools = [];
25097
25169
  const scanPaths = getScanDirPaths();
25098
25170
  for (const scanPath of scanPaths) {
25099
25171
  const mcpFilePath = import_path11.default.join(scanPath, "mcp.json");
25100
25172
  if (import_fs_extra11.default.existsSync(mcpFilePath)) {
25101
- const mcpTools = await loadMcpToolsFromConfigPath(mcpFilePath);
25173
+ const mcpTools = await loadMcpToolsFromConfigPath(mcpFilePath, excludeMCP);
25102
25174
  tools.push(...mcpTools);
25103
25175
  }
25104
25176
  }
@@ -25107,7 +25179,7 @@ async function scanUserMcp() {
25107
25179
 
25108
25180
  // src/agent/tools/edit.ts
25109
25181
  var import_fs_extra12 = __toESM(require("fs-extra"));
25110
- var import_langchain7 = require("langchain");
25182
+ var import_langchain8 = require("langchain");
25111
25183
  async function editFileByReplace(filePath, oldString, newString, replaceAll = false) {
25112
25184
  const absPath = resolveWorkspacePath(filePath);
25113
25185
  if (!await import_fs_extra12.default.pathExists(absPath)) {
@@ -25128,7 +25200,7 @@ async function editFileByReplace(filePath, oldString, newString, replaceAll = fa
25128
25200
  await import_fs_extra12.default.writeFile(absPath, nextContent, "utf-8");
25129
25201
  return `\u5DF2\u7F16\u8F91\u6587\u4EF6: ${absPath}\uFF0C\u66FF\u6362 ${replaceAll ? matches : 1} \u5904`;
25130
25202
  }
25131
- var editFileTool = (0, import_langchain7.tool)(
25203
+ var editFileTool = (0, import_langchain8.tool)(
25132
25204
  async ({ filePath, oldString, newString, replaceAll }) => safeTool(() => editFileByReplace(filePath, oldString, newString, replaceAll)),
25133
25205
  {
25134
25206
  name: "edit_file",
@@ -25144,7 +25216,7 @@ var editFileTool = (0, import_langchain7.tool)(
25144
25216
 
25145
25217
  // src/agent/tools/glob.ts
25146
25218
  var import_path12 = __toESM(require("path"));
25147
- var import_langchain8 = require("langchain");
25219
+ var import_langchain9 = require("langchain");
25148
25220
  async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false) {
25149
25221
  const rootDir = resolveWorkspacePath(cwd || ".");
25150
25222
  const allFiles = await walkFiles(rootDir, { includeHidden, maxFiles: Math.max(maxResults * 20, 1e3) });
@@ -25152,7 +25224,7 @@ async function globFiles(pattern, cwd, maxResults = 200, includeHidden = false)
25152
25224
  const matches = allFiles.map((file2) => normalizePathForMatch(import_path12.default.relative(rootDir, file2))).filter((relativePath) => matchesGlob(relativePath, normalizedPattern)).slice(0, maxResults);
25153
25225
  return truncateOutput(formatJson({ cwd: rootDir, pattern, count: matches.length, files: matches }));
25154
25226
  }
25155
- var globTool = (0, import_langchain8.tool)(
25227
+ var globTool = (0, import_langchain9.tool)(
25156
25228
  async ({ pattern, cwd, maxResults, includeHidden }) => safeTool(() => globFiles(pattern, cwd, maxResults, includeHidden)),
25157
25229
  {
25158
25230
  name: "glob_files",
@@ -25169,7 +25241,7 @@ var globTool = (0, import_langchain8.tool)(
25169
25241
  // src/agent/tools/grep.ts
25170
25242
  var import_fs_extra13 = __toESM(require("fs-extra"));
25171
25243
  var import_path13 = __toESM(require("path"));
25172
- var import_langchain9 = require("langchain");
25244
+ var import_langchain10 = require("langchain");
25173
25245
  async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false, maxResults = 100, includeHidden = false) {
25174
25246
  const rootDir = resolveWorkspacePath(cwd || ".");
25175
25247
  const matcher = isRegexp ? new RegExp(query, "i") : null;
@@ -25194,7 +25266,7 @@ async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false,
25194
25266
  }
25195
25267
  return truncateOutput(formatJson({ cwd: rootDir, query, includePattern, count: matches.length, matches }));
25196
25268
  }
25197
- var grepTool = (0, import_langchain9.tool)(
25269
+ var grepTool = (0, import_langchain10.tool)(
25198
25270
  async ({ query, pattern, cwd, includePattern, isRegexp, maxResults, includeHidden }) => safeTool(() => {
25199
25271
  const searchQuery = query || pattern;
25200
25272
  if (!searchQuery) {
@@ -25222,7 +25294,7 @@ var grepTool = (0, import_langchain9.tool)(
25222
25294
 
25223
25295
  // src/agent/tools/question.ts
25224
25296
  var import_inquirer2 = __toESM(require("inquirer"));
25225
- var import_langchain10 = require("langchain");
25297
+ var import_langchain11 = require("langchain");
25226
25298
  async function askQuestion(question, type = "input", choices = []) {
25227
25299
  const promptType = type === "select" ? "list" : type;
25228
25300
  const answer = await import_inquirer2.default.prompt([
@@ -25236,7 +25308,7 @@ async function askQuestion(question, type = "input", choices = []) {
25236
25308
  const value = answer["value"];
25237
25309
  return typeof value === "string" ? value : JSON.stringify(value);
25238
25310
  }
25239
- var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
25311
+ var questionTool = (0, import_langchain11.tool)(async ({ question, type, choices }) => safeTool(() => askQuestion(question, type, choices)), {
25240
25312
  name: "ask_question",
25241
25313
  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
25314
  schema: external_exports.object({
@@ -25249,7 +25321,7 @@ var questionTool = (0, import_langchain10.tool)(async ({ question, type, choices
25249
25321
  // src/agent/tools/read.ts
25250
25322
  var import_fs_extra14 = __toESM(require("fs-extra"));
25251
25323
  var import_iconv_lite2 = __toESM(require("iconv-lite"));
25252
- var import_langchain11 = require("langchain");
25324
+ var import_langchain12 = require("langchain");
25253
25325
  async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
25254
25326
  const absPath = resolveWorkspacePath(filePath);
25255
25327
  if (!await import_fs_extra14.default.pathExists(absPath)) {
@@ -25271,7 +25343,7 @@ async function readFile2(filePath, startLine = 1, endLine = -1, encoding) {
25271
25343
  const selected = lines.slice(safeStart - 1, safeEnd).map((line, index) => `${safeStart + index}: ${line}`).join("\n");
25272
25344
  return truncateOutput(formatJson({ filePath: absPath, totalLines: lines.length, startLine: safeStart, endLine: safeEnd, content: selected }));
25273
25345
  }
25274
- var readFileTool = (0, import_langchain11.tool)(
25346
+ var readFileTool = (0, import_langchain12.tool)(
25275
25347
  async ({ filePath, startLine, endLine, encoding }) => safeTool(() => readFile2(filePath, startLine, endLine, encoding)),
25276
25348
  {
25277
25349
  name: "read_file",
@@ -25288,7 +25360,7 @@ var readFileTool = (0, import_langchain11.tool)(
25288
25360
  // src/agent/tools/semanticMemory.ts
25289
25361
  var import_fs_extra15 = __toESM(require("fs-extra"));
25290
25362
  var import_path14 = __toESM(require("path"));
25291
- var import_langchain12 = require("langchain");
25363
+ var import_langchain13 = require("langchain");
25292
25364
  var DEFAULT_MEMORY_MARKDOWN = `# \u7528\u6237\u8BED\u4E49\u8BB0\u5FC6
25293
25365
 
25294
25366
  > \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 +25396,7 @@ async function updateSemanticMemory(memoryFilePath, content) {
25324
25396
  `, "utf-8");
25325
25397
  return `\u5DF2\u66F4\u65B0\u7528\u6237\u8BED\u4E49\u8BB0\u5FC6: ${memoryFilePath}`;
25326
25398
  }
25327
- var readSemanticMemoryTool = (0, import_langchain12.tool)(
25399
+ var readSemanticMemoryTool = (0, import_langchain13.tool)(
25328
25400
  async (_input, runtime) => safeTool(() => readSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath))),
25329
25401
  {
25330
25402
  name: "read_user_semantic_memory",
@@ -25332,7 +25404,7 @@ var readSemanticMemoryTool = (0, import_langchain12.tool)(
25332
25404
  schema: external_exports.object({})
25333
25405
  }
25334
25406
  );
25335
- var updateSemanticMemoryTool = (0, import_langchain12.tool)(
25407
+ var updateSemanticMemoryTool = (0, import_langchain13.tool)(
25336
25408
  async ({ content }, runtime) => safeTool(() => updateSemanticMemory(getMemoryFilePath(runtime.context?.memoryFilePath), content)),
25337
25409
  {
25338
25410
  name: "update_user_semantic_memory",
@@ -25392,7 +25464,7 @@ var TaskQueue = class {
25392
25464
  };
25393
25465
 
25394
25466
  // src/agent/tools/task.ts
25395
- var import_langchain13 = require("langchain");
25467
+ var import_langchain14 = require("langchain");
25396
25468
  function getCurrentTaskQueue(agentId) {
25397
25469
  return agentId ? new TaskQueue(agentId) : null;
25398
25470
  }
@@ -25424,7 +25496,7 @@ function manageTaskQueue(agentId, action, task, index) {
25424
25496
  queue.clearTasks();
25425
25497
  return "\u5DF2\u6E05\u7A7A\u4EFB\u52A1\u961F\u5217";
25426
25498
  }
25427
- var taskTool = (0, import_langchain13.tool)(
25499
+ var taskTool = (0, import_langchain14.tool)(
25428
25500
  async ({ action, task, index }, runtime) => safeTool(() => {
25429
25501
  const agentId = runtime.context?.agentId || getAgentId();
25430
25502
  return manageTaskQueue(agentId, action, task, index);
@@ -25441,7 +25513,7 @@ var taskTool = (0, import_langchain13.tool)(
25441
25513
  );
25442
25514
 
25443
25515
  // src/agent/tools/webfetch.ts
25444
- var import_langchain14 = require("langchain");
25516
+ var import_langchain15 = require("langchain");
25445
25517
  async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
25446
25518
  const controller = new AbortController();
25447
25519
  const timer = setTimeout(() => controller.abort(), timeout);
@@ -25474,7 +25546,7 @@ async function webFetch(url2, timeout = 3e4, maxLength = 6e4) {
25474
25546
  clearTimeout(timer);
25475
25547
  }
25476
25548
  }
25477
- var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
25549
+ var webFetchTool = (0, import_langchain15.tool)(async ({ url: url2, timeout, maxLength }) => safeTool(() => webFetch(url2, timeout, maxLength)), {
25478
25550
  name: "web_fetch",
25479
25551
  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
25552
  schema: external_exports.object({
@@ -25487,7 +25559,7 @@ var webFetchTool = (0, import_langchain14.tool)(async ({ url: url2, timeout, max
25487
25559
  // src/agent/tools/write.ts
25488
25560
  var import_fs_extra17 = __toESM(require("fs-extra"));
25489
25561
  var import_path15 = __toESM(require("path"));
25490
- var import_langchain15 = require("langchain");
25562
+ var import_langchain16 = require("langchain");
25491
25563
  async function writeFile2(filePath, content, mode = "overwrite") {
25492
25564
  const absPath = resolveWorkspacePath(filePath);
25493
25565
  const exists = await import_fs_extra17.default.pathExists(absPath);
@@ -25502,7 +25574,7 @@ async function writeFile2(filePath, content, mode = "overwrite") {
25502
25574
  await import_fs_extra17.default.writeFile(absPath, content, "utf-8");
25503
25575
  return `${exists ? "\u5DF2\u8986\u76D6\u5199\u5165\u6587\u4EF6" : "\u5DF2\u521B\u5EFA\u6587\u4EF6"}: ${absPath}`;
25504
25576
  }
25505
- var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile2(filePath, content, mode)), {
25577
+ var writeFileTool = (0, import_langchain16.tool)(async ({ filePath, content, mode }) => safeTool(() => writeFile2(filePath, content, mode)), {
25506
25578
  name: "write_file",
25507
25579
  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
25580
  schema: external_exports.object({
@@ -25515,6 +25587,7 @@ var writeFileTool = (0, import_langchain15.tool)(async ({ filePath, content, mod
25515
25587
  // src/agent/tools/index.ts
25516
25588
  var builtinTools = [
25517
25589
  taskTool,
25590
+ subAgentTool,
25518
25591
  executeCommandTool,
25519
25592
  readFileTool,
25520
25593
  editFileTool,
@@ -25527,8 +25600,8 @@ var builtinTools = [
25527
25600
  ...semanticMemoryTools,
25528
25601
  ...learnTools
25529
25602
  ];
25530
- async function getTools() {
25531
- return [...builtinTools, ...await scanUserTools(), ...await scanUserMcp()];
25603
+ async function getTools(excludeTools, excludeMCP) {
25604
+ return [...builtinTools, ...await scanUserTools(excludeTools), ...await scanUserMcp(excludeMCP)];
25532
25605
  }
25533
25606
 
25534
25607
  // src/agent/skills/index.ts
@@ -25540,13 +25613,14 @@ function getSkills() {
25540
25613
  // src/agent/AIAgent/index.ts
25541
25614
  var import_os4 = __toESM(require("os"));
25542
25615
 
25543
- // src/agent/AIAgent/SubAIAgent.ts
25544
- var import_langchain16 = require("langchain");
25616
+ // src/agent/AIAgent/SubAgents/SubAIAgent.ts
25617
+ var import_langchain17 = require("langchain");
25545
25618
  var import_deepagents = require("deepagents");
25546
25619
  var import_eventemitter_super = require("eventemitter-super");
25547
25620
  var import_os3 = __toESM(require("os"));
25548
25621
  var import_crypto4 = require("crypto");
25549
- var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25622
+ var import_lodash = require("lodash");
25623
+ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitterSuper {
25550
25624
  id = "";
25551
25625
  opt = {};
25552
25626
  tools = [];
@@ -25563,8 +25637,14 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25563
25637
  userStorePath = "";
25564
25638
  agentRulesPath = "";
25565
25639
  isPrintThinking = true;
25640
+ maxSubAgentCount = 2;
25641
+ excludeTools = [];
25642
+ excludeSkills = [];
25643
+ excludeMCP = [];
25644
+ systemPrompt = "";
25566
25645
  constructor(opt) {
25567
25646
  super();
25647
+ this.opt = (0, import_lodash.cloneDeep)(opt);
25568
25648
  this.id = opt.id || `agent-${(0, import_crypto4.randomUUID)()}`;
25569
25649
  this.basespace = opt.basespace;
25570
25650
  this.workspace = opt.workspace;
@@ -25573,32 +25653,53 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25573
25653
  this.userStorePath = opt.userStorePath;
25574
25654
  this.agentRulesPath = opt.agentRulesPath;
25575
25655
  this.isPrintThinking = opt.isPrintThinking;
25576
- this.opt = opt;
25656
+ this.excludeTools = opt.excludeTools || [];
25657
+ this.excludeSkills = opt.excludeSkills || [];
25658
+ this.excludeMCP = opt.excludeMCP || [];
25659
+ this.systemPrompt = opt.systemPrompt || "";
25660
+ this.subLevel = opt.subLevel || 1;
25661
+ this.maxSubAgentCount = opt.maxSubAgentCount || 2;
25577
25662
  }
25578
25663
  async init() {
25579
- this.tools = await getTools();
25664
+ if (this.subLevel > 2) {
25665
+ this.excludeTools.push("subAgent_exec");
25666
+ }
25667
+ this.tools = await getTools(this.excludeTools, this.excludeMCP);
25580
25668
  this.skills = [...getSkills(), ...this.opt.skills || []];
25581
25669
  const model = getModel(this.opt.modelOpt);
25670
+ const checkpointer = new FileSystemSaver({
25671
+ rootFolder: this.sessionDirPath
25672
+ });
25582
25673
  const contextSchema = external_exports.object({
25583
25674
  agent_name: external_exports.string(),
25584
25675
  encoding: external_exports.string(),
25585
25676
  skills: external_exports.array(external_exports.string()).optional(),
25586
25677
  memoryFilePath: external_exports.string().optional(),
25587
25678
  agentId: external_exports.string().optional(),
25588
- mainAgent: external_exports.object().optional()
25679
+ curAgent: external_exports.object().optional()
25589
25680
  });
25590
- const agent = (0, import_langchain16.createAgent)({
25681
+ const systemPrompt = this.subLevel > 2 ? getSystemPrompt({
25682
+ systemPrompt: this.systemPrompt,
25683
+ workspace: this.workspace,
25684
+ osType: import_os3.default.platform(),
25685
+ skills: this.skills,
25686
+ memoryFilePath: this.memoryFilePath,
25687
+ agentRulesPath: this.agentRulesPath,
25688
+ excludeSkills: this.excludeSkills
25689
+ }) : subSystemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.excludeSkills);
25690
+ const agent = (0, import_langchain17.createAgent)({
25591
25691
  model,
25692
+ checkpointer,
25592
25693
  tools: this.tools,
25593
25694
  contextSchema,
25594
25695
  middleware: [
25595
25696
  createAgentEventMiddleware(this),
25596
- (0, import_langchain16.summarizationMiddleware)({
25697
+ (0, import_langchain17.summarizationMiddleware)({
25597
25698
  model,
25598
25699
  trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
25599
25700
  keep: { messages: 50 }
25600
25701
  }),
25601
- (0, import_langchain16.humanInTheLoopMiddleware)({
25702
+ (0, import_langchain17.humanInTheLoopMiddleware)({
25602
25703
  interruptOn: {
25603
25704
  install_package: {
25604
25705
  allowedDecisions: ["approve", "reject"]
@@ -25606,29 +25707,17 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25606
25707
  readEmailTool: false
25607
25708
  }
25608
25709
  }),
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
- })
25710
+ (0, import_langchain17.todoListMiddleware)(),
25711
+ (0, import_deepagents.createPatchToolCallsMiddleware)()
25624
25712
  ],
25625
- systemPrompt: systemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
25713
+ systemPrompt
25626
25714
  });
25715
+ await checkpointer.init(this.id, agent);
25627
25716
  this.agent = agent;
25628
25717
  this.initEvents();
25629
25718
  }
25630
25719
  async execute(input) {
25631
- const humanMessage = new import_langchain16.HumanMessage(input);
25720
+ const humanMessage = new import_langchain17.HumanMessage(input);
25632
25721
  this.messages.push(humanMessage);
25633
25722
  const stream = await this.agent.stream(
25634
25723
  { messages: this.messages },
@@ -25643,7 +25732,7 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25643
25732
  skills: this.skills,
25644
25733
  memoryFilePath: this.memoryFilePath,
25645
25734
  agentId: this.id,
25646
- mainAgent: this
25735
+ curAgent: this
25647
25736
  }
25648
25737
  }
25649
25738
  );
@@ -25701,8 +25790,8 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25701
25790
  this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
25702
25791
  log(`[Tool Call] ${funcName}`, "#c2a654");
25703
25792
  });
25704
- this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
25705
- logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
25793
+ this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
25794
+ logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent.length > 50 ? _toolContent.slice(0, 50) + "..." : _toolContent}`);
25706
25795
  });
25707
25796
  this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
25708
25797
  logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
@@ -25710,20 +25799,29 @@ var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
25710
25799
  this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
25711
25800
  });
25712
25801
  }
25802
+ async createSubAgent() {
25803
+ const subAgent = new _SubAIAgent(this.opt);
25804
+ subAgent.subLevel = this.subLevel + 1;
25805
+ await subAgent.init();
25806
+ return subAgent;
25807
+ }
25713
25808
  destory() {
25714
25809
  this.removeAllListeners();
25715
25810
  }
25716
25811
  };
25717
25812
 
25718
25813
  // src/agent/AIAgent/index.ts
25814
+ var import_lodash2 = require("lodash");
25719
25815
  var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25720
25816
  id = "";
25817
+ threadId = "main_session_records";
25721
25818
  opt = {};
25722
25819
  tools = [];
25723
25820
  dynamicTools = [];
25724
25821
  skills = [];
25725
25822
  mcp = [];
25726
25823
  subLevel = 0;
25824
+ maxSubAgentCount = 2;
25727
25825
  agent = {};
25728
25826
  messages = [];
25729
25827
  basespace = "";
@@ -25735,8 +25833,13 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25735
25833
  roomClient = null;
25736
25834
  taskQueue = {};
25737
25835
  isPrintThinking = true;
25836
+ excludeTools = [];
25837
+ excludeSkills = [];
25838
+ excludeMCP = [];
25839
+ systemPrompt = "";
25738
25840
  constructor(opt) {
25739
25841
  super();
25842
+ this.opt = (0, import_lodash2.cloneDeep)(opt);
25740
25843
  this.id = opt.id || `agent-${Date.now()}`;
25741
25844
  this.basespace = opt.basespace;
25742
25845
  this.workspace = opt.workspace;
@@ -25745,10 +25848,15 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25745
25848
  this.userStorePath = opt.userStorePath;
25746
25849
  this.agentRulesPath = opt.agentRulesPath;
25747
25850
  this.isPrintThinking = opt.isPrintThinking;
25748
- this.opt = opt;
25851
+ this.excludeTools = opt.excludeTools || [];
25852
+ this.excludeSkills = opt.excludeSkills || [];
25853
+ this.excludeMCP = opt.excludeMCP || [];
25854
+ this.systemPrompt = opt.systemPrompt || "";
25855
+ this.subLevel = 0;
25856
+ this.maxSubAgentCount = opt.maxSubAgentCount || 2;
25749
25857
  }
25750
25858
  async init() {
25751
- this.tools = await getTools();
25859
+ this.tools = await getTools(this.excludeTools, this.excludeMCP);
25752
25860
  this.skills = [...getSkills(), ...this.opt.skills || []];
25753
25861
  const model = getModel(this.opt.modelOpt);
25754
25862
  const checkpointer = new FileSystemSaver({
@@ -25760,21 +25868,21 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25760
25868
  skills: external_exports.array(external_exports.string()).optional(),
25761
25869
  memoryFilePath: external_exports.string().optional(),
25762
25870
  agentId: external_exports.string().optional(),
25763
- mainAgent: external_exports.object().optional()
25871
+ curAgent: external_exports.object().optional()
25764
25872
  });
25765
- const agent = (0, import_langchain17.createAgent)({
25873
+ const agent = (0, import_langchain18.createAgent)({
25766
25874
  model,
25767
25875
  checkpointer,
25768
25876
  tools: this.tools,
25769
25877
  contextSchema,
25770
25878
  middleware: [
25771
25879
  createAgentEventMiddleware(this),
25772
- (0, import_langchain17.summarizationMiddleware)({
25880
+ (0, import_langchain18.summarizationMiddleware)({
25773
25881
  model,
25774
25882
  trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
25775
25883
  keep: { messages: 50 }
25776
25884
  }),
25777
- (0, import_langchain17.humanInTheLoopMiddleware)({
25885
+ (0, import_langchain18.humanInTheLoopMiddleware)({
25778
25886
  interruptOn: {
25779
25887
  install_package: {
25780
25888
  allowedDecisions: ["approve", "reject"]
@@ -25782,30 +25890,26 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25782
25890
  readEmailTool: false
25783
25891
  }
25784
25892
  }),
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
- })
25893
+ (0, import_langchain18.todoListMiddleware)(),
25894
+ (0, import_deepagents2.createPatchToolCallsMiddleware)()
25800
25895
  ],
25801
- systemPrompt: systemPrompt(this.workspace, import_os4.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
25896
+ systemPrompt: getSystemPrompt({
25897
+ systemPrompt: this.systemPrompt,
25898
+ workspace: this.workspace,
25899
+ osType: import_os4.default.platform(),
25900
+ skills: this.skills,
25901
+ memoryFilePath: this.memoryFilePath,
25902
+ agentRulesPath: this.agentRulesPath,
25903
+ excludeSkills: this.excludeSkills
25904
+ })
25802
25905
  });
25906
+ await checkpointer.init(this.threadId, agent);
25803
25907
  this.agent = agent;
25804
25908
  this.taskQueue = new TaskQueue(this.id);
25805
25909
  this.initEvents();
25806
25910
  }
25807
25911
  async execute(input) {
25808
- const humanMessage = new import_langchain17.HumanMessage(input);
25912
+ const humanMessage = new import_langchain18.HumanMessage(input);
25809
25913
  this.messages.push(humanMessage);
25810
25914
  const stream = await this.agent.stream(
25811
25915
  { messages: this.messages },
@@ -25813,21 +25917,23 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25813
25917
  streamMode: ["messages"],
25814
25918
  recursionLimit: 2e3,
25815
25919
  subgraphs: true,
25816
- configurable: { thread_id: this.id },
25920
+ configurable: { thread_id: this.threadId },
25817
25921
  context: {
25818
25922
  agent_name: "deepfish",
25819
25923
  encoding: this.opt.encoding,
25820
25924
  skills: this.skills,
25821
25925
  memoryFilePath: this.memoryFilePath,
25822
25926
  agentId: this.id,
25823
- mainAgent: this
25927
+ curAgent: this
25824
25928
  }
25825
25929
  }
25826
25930
  );
25827
25931
  for await (const [_namespace, mode, data] of stream) {
25828
25932
  if (mode === "messages") {
25829
- const message = data[0].additional_kwargs.reasoning_content;
25830
- this.emit("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, message);
25933
+ const message = data?.[0];
25934
+ const reasoning_content = message?.additional_kwargs?.reasoning_content;
25935
+ const toolcall_content = message?.tool_call_chunks?.[0]?.args;
25936
+ this.emit("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, reasoning_content || toolcall_content || "");
25831
25937
  }
25832
25938
  }
25833
25939
  const newTask = this.taskQueue.getTask();
@@ -25840,8 +25946,8 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25840
25946
  const thinking = new Thinking();
25841
25947
  this.on("TASK_BEFORE" /* TASK_BEFORE */, () => {
25842
25948
  });
25843
- this.on("TASK_AFTER" /* TASK_AFTER */, (msg) => {
25844
- logInfo(msg);
25949
+ this.on("TASK_AFTER" /* TASK_AFTER */, (_msg) => {
25950
+ logSuccess(_msg);
25845
25951
  });
25846
25952
  this.on("MODEL_BEFORE" /* MODEL_BEFORE */, () => {
25847
25953
  });
@@ -25849,6 +25955,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25849
25955
  if (this.isPrintThinking) {
25850
25956
  thinking.stop();
25851
25957
  }
25958
+ streamOutput("\n");
25852
25959
  });
25853
25960
  this.on("MODEL_ERROR" /* MODEL_ERROR */, (error51) => {
25854
25961
  if (this.isPrintThinking) {
@@ -25878,7 +25985,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25878
25985
  this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
25879
25986
  log(`[Tool Call] ${funcName}`, "#c2a654");
25880
25987
  });
25881
- this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
25988
+ this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
25882
25989
  logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
25883
25990
  });
25884
25991
  this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
@@ -25887,8 +25994,10 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
25887
25994
  this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
25888
25995
  });
25889
25996
  }
25890
- createSubAgent() {
25891
- return new SubAIAgent(this.opt);
25997
+ async createSubAgent() {
25998
+ const subAgent = new SubAIAgent(this.opt);
25999
+ await subAgent.init();
26000
+ return subAgent;
25892
26001
  }
25893
26002
  destory() {
25894
26003
  this.removeAllListeners();
@@ -26947,6 +27056,7 @@ function handleCacheList() {
26947
27056
  }
26948
27057
  catalog.forEach((item, index) => {
26949
27058
  const desc = item.description.length > 20 ? item.description.slice(0, 20) + "..." : item.description;
27059
+ logInfo(`${index}. ${item.id} - ${desc}`);
26950
27060
  });
26951
27061
  }
26952
27062
  function handleCacheEdit(input) {
@@ -27045,7 +27155,7 @@ Commands:
27045
27155
  function registerHelpCommand(program) {
27046
27156
  program.helpInformation = helpInformation;
27047
27157
  program.command("help").description("Displaying help information").action(() => {
27048
- console.log(helpInformation());
27158
+ logInfo(helpInformation());
27049
27159
  });
27050
27160
  }
27051
27161