deepfish-ai 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/generate-tool.md +1 -1
- package/dist/index.js +264 -38
- package/dist/serve/pm2-server.js +17 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -230,6 +230,7 @@ MCP(Model Context Protocol)允许 AI 连接外部工具和服务。通过 `a
|
|
|
230
230
|
DeepFish 支持通过 Tool 和 Skill 扩展 AI 的能力。扩展文件可以放在当前工作目录的 `.deepfish-ai` 目录中,也可以放在全局配置目录中。
|
|
231
231
|
|
|
232
232
|
- **Tool 扩展**:用于定义 AI 可直接调用的自定义函数工具,适合封装 API 调用、数据库操作、文件处理等能力。可以使用 `ai tools generate xxx` 命令让 AI 根据描述生成 Tool。
|
|
233
|
+
- 在 Tool 函数中,可以通过调用 `this.createSubAgent(prompt: string)` 创建子 Agent,并将任务说明作为 `prompt` 传入。
|
|
233
234
|
- **Skill 扩展**:用于定义 AI 的工作流知识包,适合沉淀某类任务的执行步骤、规范和最佳实践。可以使用 `ai skills generate xxx` 命令让 AI 根据描述生成 Skill。
|
|
234
235
|
|
|
235
236
|
### 当前目录扩展
|
package/dist/generate-tool.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -8936,7 +8936,7 @@ function registerModelsCommands(program) {
|
|
|
8936
8936
|
}
|
|
8937
8937
|
|
|
8938
8938
|
// src/cli/cli-core/skills.ts
|
|
8939
|
-
var
|
|
8939
|
+
var import_crypto6 = require("crypto");
|
|
8940
8940
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
8941
8941
|
var import_fs_extra19 = __toESM(require("fs-extra"));
|
|
8942
8942
|
var import_path19 = __toESM(require("path"));
|
|
@@ -8998,11 +8998,11 @@ function getConfig() {
|
|
|
8998
8998
|
// src/cli/cli-utils/init-agent.ts
|
|
8999
8999
|
var import_fs_extra18 = __toESM(require("fs-extra"));
|
|
9000
9000
|
var import_path18 = __toESM(require("path"));
|
|
9001
|
-
var
|
|
9001
|
+
var import_crypto5 = require("crypto");
|
|
9002
9002
|
|
|
9003
9003
|
// src/agent/AIAgent/index.ts
|
|
9004
|
-
var
|
|
9005
|
-
var
|
|
9004
|
+
var import_langchain17 = require("langchain");
|
|
9005
|
+
var import_deepagents2 = require("deepagents");
|
|
9006
9006
|
|
|
9007
9007
|
// src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
|
|
9008
9008
|
var import_path5 = require("path");
|
|
@@ -24228,7 +24228,7 @@ function date4(params) {
|
|
|
24228
24228
|
config(en_default());
|
|
24229
24229
|
|
|
24230
24230
|
// src/agent/AIAgent/index.ts
|
|
24231
|
-
var
|
|
24231
|
+
var import_eventemitter_super2 = require("eventemitter-super");
|
|
24232
24232
|
|
|
24233
24233
|
// src/agent/AIAgent/middleware/eventEmitMiddleware.ts
|
|
24234
24234
|
var import_langchain = require("langchain");
|
|
@@ -24625,9 +24625,15 @@ function toLangChainTool(func, description) {
|
|
|
24625
24625
|
zodProperties[key] = zodType;
|
|
24626
24626
|
}
|
|
24627
24627
|
const schema = external_exports.object(zodProperties);
|
|
24628
|
-
const wrappedFunc = async (args) => {
|
|
24628
|
+
const wrappedFunc = async (args, runtime) => {
|
|
24629
24629
|
try {
|
|
24630
|
-
const
|
|
24630
|
+
const boundFunc = func.bind({
|
|
24631
|
+
createSubAgent: (prompt) => {
|
|
24632
|
+
const subAgent = runtime.context.mainAgent.createSubAgent();
|
|
24633
|
+
return subAgent.execute(prompt);
|
|
24634
|
+
}
|
|
24635
|
+
});
|
|
24636
|
+
const result = await boundFunc(...Object.values(args));
|
|
24631
24637
|
if (typeof result === "object" && result !== null && "success" in result) {
|
|
24632
24638
|
return serializeToolResult(result);
|
|
24633
24639
|
}
|
|
@@ -24653,7 +24659,7 @@ function scanUserTools() {
|
|
|
24653
24659
|
if (import_fs_extra8.default.statSync(import_path8.default.resolve(toolsDir, file2)).isDirectory()) {
|
|
24654
24660
|
const subDirPath = import_path8.default.resolve(toolsDir, file2);
|
|
24655
24661
|
const subFiles = import_fs_extra8.default.readdirSync(subDirPath);
|
|
24656
|
-
const indexFile = subFiles.find((f) => f === "index" || f === "index.cjs");
|
|
24662
|
+
const indexFile = subFiles.find((f) => f === "index.js" || f === "index.cjs");
|
|
24657
24663
|
if (indexFile) {
|
|
24658
24664
|
const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, indexFile), indexFile);
|
|
24659
24665
|
if (filePath) {
|
|
@@ -24688,15 +24694,32 @@ function _scanDeepFishJsFile(filePath, fileName) {
|
|
|
24688
24694
|
return null;
|
|
24689
24695
|
}
|
|
24690
24696
|
function _loadToolsFromFile(filePath, tools) {
|
|
24691
|
-
|
|
24692
|
-
|
|
24693
|
-
|
|
24694
|
-
|
|
24695
|
-
|
|
24697
|
+
try {
|
|
24698
|
+
const toolModule = require(filePath);
|
|
24699
|
+
const { functions, descriptions } = toolModule;
|
|
24700
|
+
if (!functions || typeof functions !== "object" || !Array.isArray(descriptions)) {
|
|
24701
|
+
logWarning(`Skip invalid tool file: ${filePath}`);
|
|
24702
|
+
return;
|
|
24703
|
+
}
|
|
24704
|
+
descriptions.forEach((desc) => {
|
|
24705
|
+
if (!desc.type) {
|
|
24706
|
+
desc = {
|
|
24707
|
+
type: "function",
|
|
24708
|
+
function: desc
|
|
24709
|
+
};
|
|
24710
|
+
}
|
|
24711
|
+
const func = functions[desc.function.name];
|
|
24712
|
+
if (typeof func !== "function") {
|
|
24713
|
+
logWarning(`Skip tool "${desc.function.name}": implementation not found in ${filePath}`);
|
|
24714
|
+
return;
|
|
24715
|
+
}
|
|
24696
24716
|
const langChainTool = toLangChainTool(func, desc);
|
|
24697
24717
|
tools.push(langChainTool);
|
|
24698
|
-
}
|
|
24699
|
-
})
|
|
24718
|
+
});
|
|
24719
|
+
} catch (error51) {
|
|
24720
|
+
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
24721
|
+
logWarning(`Failed to load tool file: ${filePath}. ${message}`);
|
|
24722
|
+
}
|
|
24700
24723
|
}
|
|
24701
24724
|
|
|
24702
24725
|
// src/agent/tools/executeCommand.ts
|
|
@@ -24756,7 +24779,6 @@ var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => s
|
|
|
24756
24779
|
var import_langchain4 = require("langchain");
|
|
24757
24780
|
var import_path9 = __toESM(require("path"));
|
|
24758
24781
|
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
24759
|
-
var _require = require;
|
|
24760
24782
|
async function executeJSCode(code) {
|
|
24761
24783
|
logInfo("Executing JavaScript code: ");
|
|
24762
24784
|
logInfo(code);
|
|
@@ -24767,7 +24789,15 @@ async function executeJSCode(code) {
|
|
|
24767
24789
|
return result || "Code executed successfully, but __main() did not return anything."
|
|
24768
24790
|
})()`;
|
|
24769
24791
|
const fn = new Function("require", wrapped);
|
|
24770
|
-
const
|
|
24792
|
+
const _require = require;
|
|
24793
|
+
const newRequire = (modulePath) => {
|
|
24794
|
+
if (modulePath.startsWith("./")) {
|
|
24795
|
+
const resolvedPath = import_path9.default.resolve(process.cwd(), modulePath);
|
|
24796
|
+
return _require(resolvedPath);
|
|
24797
|
+
}
|
|
24798
|
+
return _require(modulePath);
|
|
24799
|
+
};
|
|
24800
|
+
const result = await fn(newRequire);
|
|
24771
24801
|
return result;
|
|
24772
24802
|
} catch (error51) {
|
|
24773
24803
|
logError(`Error executing code: ${error51.stack}`);
|
|
@@ -25022,13 +25052,17 @@ function wrapMcpTool(mcpTool) {
|
|
|
25022
25052
|
}
|
|
25023
25053
|
async function loadMcpToolsFromConfigPath(mcpFilePath) {
|
|
25024
25054
|
const jsonContent = import_fs_extra11.default.readJSONSync(mcpFilePath);
|
|
25025
|
-
|
|
25055
|
+
let mcpServers = jsonContent.mcpServers;
|
|
25026
25056
|
if (!mcpServers || Object.keys(mcpServers).length === 0) {
|
|
25027
25057
|
return [];
|
|
25028
25058
|
}
|
|
25029
25059
|
try {
|
|
25030
25060
|
for (const key of Object.keys(mcpServers)) {
|
|
25031
25061
|
const server = mcpServers[key];
|
|
25062
|
+
if (server.disabled) {
|
|
25063
|
+
delete mcpServers[key];
|
|
25064
|
+
continue;
|
|
25065
|
+
}
|
|
25032
25066
|
if (!server.transport) {
|
|
25033
25067
|
if (server.url) {
|
|
25034
25068
|
if (server.url.startsWith("ws://") || server.url.startsWith("wss://")) {
|
|
@@ -25045,6 +25079,9 @@ async function loadMcpToolsFromConfigPath(mcpFilePath) {
|
|
|
25045
25079
|
delete mcpServers[key];
|
|
25046
25080
|
}
|
|
25047
25081
|
}
|
|
25082
|
+
if (Object.keys(mcpServers).length === 0) {
|
|
25083
|
+
return [];
|
|
25084
|
+
}
|
|
25048
25085
|
logInfo(`Loading MCP tools from config path: ${mcpFilePath}`);
|
|
25049
25086
|
const client = new import_mcp_adapters.MultiServerMCPClient(jsonContent.mcpServers);
|
|
25050
25087
|
const tools = await client.getTools();
|
|
@@ -25501,15 +25538,22 @@ function getSkills() {
|
|
|
25501
25538
|
}
|
|
25502
25539
|
|
|
25503
25540
|
// src/agent/AIAgent/index.ts
|
|
25541
|
+
var import_os4 = __toESM(require("os"));
|
|
25542
|
+
|
|
25543
|
+
// src/agent/AIAgent/SubAIAgent.ts
|
|
25544
|
+
var import_langchain16 = require("langchain");
|
|
25545
|
+
var import_deepagents = require("deepagents");
|
|
25546
|
+
var import_eventemitter_super = require("eventemitter-super");
|
|
25504
25547
|
var import_os3 = __toESM(require("os"));
|
|
25505
|
-
var
|
|
25548
|
+
var import_crypto4 = require("crypto");
|
|
25549
|
+
var SubAIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
25506
25550
|
id = "";
|
|
25507
25551
|
opt = {};
|
|
25508
25552
|
tools = [];
|
|
25509
25553
|
dynamicTools = [];
|
|
25510
25554
|
skills = [];
|
|
25511
25555
|
mcp = [];
|
|
25512
|
-
subLevel =
|
|
25556
|
+
subLevel = 1;
|
|
25513
25557
|
agent = {};
|
|
25514
25558
|
messages = [];
|
|
25515
25559
|
basespace = "";
|
|
@@ -25518,12 +25562,10 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25518
25562
|
sessionDirPath = "";
|
|
25519
25563
|
userStorePath = "";
|
|
25520
25564
|
agentRulesPath = "";
|
|
25521
|
-
roomClient = null;
|
|
25522
|
-
taskQueue = {};
|
|
25523
25565
|
isPrintThinking = true;
|
|
25524
25566
|
constructor(opt) {
|
|
25525
25567
|
super();
|
|
25526
|
-
this.id = opt.id || `agent-${
|
|
25568
|
+
this.id = opt.id || `agent-${(0, import_crypto4.randomUUID)()}`;
|
|
25527
25569
|
this.basespace = opt.basespace;
|
|
25528
25570
|
this.workspace = opt.workspace;
|
|
25529
25571
|
this.memoryFilePath = opt.memoryFilePath;
|
|
@@ -25537,19 +25579,16 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25537
25579
|
this.tools = await getTools();
|
|
25538
25580
|
this.skills = [...getSkills(), ...this.opt.skills || []];
|
|
25539
25581
|
const model = getModel(this.opt.modelOpt);
|
|
25540
|
-
const checkpointer = new FileSystemSaver({
|
|
25541
|
-
rootFolder: this.sessionDirPath
|
|
25542
|
-
});
|
|
25543
25582
|
const contextSchema = external_exports.object({
|
|
25544
25583
|
agent_name: external_exports.string(),
|
|
25545
25584
|
encoding: external_exports.string(),
|
|
25546
25585
|
skills: external_exports.array(external_exports.string()).optional(),
|
|
25547
25586
|
memoryFilePath: external_exports.string().optional(),
|
|
25548
|
-
agentId: external_exports.string().optional()
|
|
25587
|
+
agentId: external_exports.string().optional(),
|
|
25588
|
+
mainAgent: external_exports.object().optional()
|
|
25549
25589
|
});
|
|
25550
25590
|
const agent = (0, import_langchain16.createAgent)({
|
|
25551
25591
|
model,
|
|
25552
|
-
checkpointer,
|
|
25553
25592
|
tools: this.tools,
|
|
25554
25593
|
contextSchema,
|
|
25555
25594
|
middleware: [
|
|
@@ -25586,7 +25625,6 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25586
25625
|
systemPrompt: systemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
|
|
25587
25626
|
});
|
|
25588
25627
|
this.agent = agent;
|
|
25589
|
-
this.taskQueue = new TaskQueue(this.id);
|
|
25590
25628
|
this.initEvents();
|
|
25591
25629
|
}
|
|
25592
25630
|
async execute(input) {
|
|
@@ -25599,7 +25637,191 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25599
25637
|
recursionLimit: 2e3,
|
|
25600
25638
|
subgraphs: true,
|
|
25601
25639
|
configurable: { thread_id: this.id },
|
|
25602
|
-
context: {
|
|
25640
|
+
context: {
|
|
25641
|
+
agent_name: "deepfish",
|
|
25642
|
+
encoding: this.opt.encoding,
|
|
25643
|
+
skills: this.skills,
|
|
25644
|
+
memoryFilePath: this.memoryFilePath,
|
|
25645
|
+
agentId: this.id,
|
|
25646
|
+
mainAgent: this
|
|
25647
|
+
}
|
|
25648
|
+
}
|
|
25649
|
+
);
|
|
25650
|
+
return new Promise(async (resolve) => {
|
|
25651
|
+
this.once("TASK_AFTER" /* TASK_AFTER */, (msg) => {
|
|
25652
|
+
resolve(msg);
|
|
25653
|
+
});
|
|
25654
|
+
for await (const [_namespace, mode, data] of stream) {
|
|
25655
|
+
if (mode === "messages") {
|
|
25656
|
+
const message = data[0].additional_kwargs.reasoning_content;
|
|
25657
|
+
this.emit("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, message);
|
|
25658
|
+
}
|
|
25659
|
+
}
|
|
25660
|
+
});
|
|
25661
|
+
}
|
|
25662
|
+
initEvents() {
|
|
25663
|
+
const thinking = new Thinking();
|
|
25664
|
+
this.on("TASK_BEFORE" /* TASK_BEFORE */, () => {
|
|
25665
|
+
});
|
|
25666
|
+
this.on("TASK_AFTER" /* TASK_AFTER */, (msg) => {
|
|
25667
|
+
logInfo(msg);
|
|
25668
|
+
});
|
|
25669
|
+
this.on("MODEL_BEFORE" /* MODEL_BEFORE */, () => {
|
|
25670
|
+
});
|
|
25671
|
+
this.on("MODEL_AFTER" /* MODEL_AFTER */, () => {
|
|
25672
|
+
if (this.isPrintThinking) {
|
|
25673
|
+
thinking.stop();
|
|
25674
|
+
}
|
|
25675
|
+
});
|
|
25676
|
+
this.on("MODEL_ERROR" /* MODEL_ERROR */, (error51) => {
|
|
25677
|
+
if (this.isPrintThinking) {
|
|
25678
|
+
thinking.stop();
|
|
25679
|
+
}
|
|
25680
|
+
logError(error51?.message + "\n" + error51?.stack);
|
|
25681
|
+
});
|
|
25682
|
+
this.on("STREAM_CONTENT_OUTPUT" /* STREAM_CONTENT_OUTPUT */, (content) => {
|
|
25683
|
+
if (this.isPrintThinking) {
|
|
25684
|
+
if (content && typeof content === "string") {
|
|
25685
|
+
streamOutput(content, "#f2c97d");
|
|
25686
|
+
}
|
|
25687
|
+
} else {
|
|
25688
|
+
if (content && typeof content === "string") {
|
|
25689
|
+
thinking.start();
|
|
25690
|
+
} else {
|
|
25691
|
+
thinking.stop();
|
|
25692
|
+
}
|
|
25693
|
+
}
|
|
25694
|
+
});
|
|
25695
|
+
this.on("COMPRESS_MESSAGES_BEFORE" /* COMPRESS_MESSAGES_BEFORE */, (_currentLength) => {
|
|
25696
|
+
});
|
|
25697
|
+
this.on("COMPRESS_MESSAGES_AFTER" /* COMPRESS_MESSAGES_AFTER */, (_currentLength) => {
|
|
25698
|
+
});
|
|
25699
|
+
this.on("NEW_MESSAGE" /* NEW_MESSAGE */, (_msg) => {
|
|
25700
|
+
});
|
|
25701
|
+
this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
|
|
25702
|
+
log(`[Tool Call] ${funcName}`, "#c2a654");
|
|
25703
|
+
});
|
|
25704
|
+
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
|
|
25705
|
+
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
|
|
25706
|
+
});
|
|
25707
|
+
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
|
|
25708
|
+
logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
|
|
25709
|
+
});
|
|
25710
|
+
this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
|
|
25711
|
+
});
|
|
25712
|
+
}
|
|
25713
|
+
destory() {
|
|
25714
|
+
this.removeAllListeners();
|
|
25715
|
+
}
|
|
25716
|
+
};
|
|
25717
|
+
|
|
25718
|
+
// src/agent/AIAgent/index.ts
|
|
25719
|
+
var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
|
|
25720
|
+
id = "";
|
|
25721
|
+
opt = {};
|
|
25722
|
+
tools = [];
|
|
25723
|
+
dynamicTools = [];
|
|
25724
|
+
skills = [];
|
|
25725
|
+
mcp = [];
|
|
25726
|
+
subLevel = 0;
|
|
25727
|
+
agent = {};
|
|
25728
|
+
messages = [];
|
|
25729
|
+
basespace = "";
|
|
25730
|
+
workspace = "";
|
|
25731
|
+
memoryFilePath = "";
|
|
25732
|
+
sessionDirPath = "";
|
|
25733
|
+
userStorePath = "";
|
|
25734
|
+
agentRulesPath = "";
|
|
25735
|
+
roomClient = null;
|
|
25736
|
+
taskQueue = {};
|
|
25737
|
+
isPrintThinking = true;
|
|
25738
|
+
constructor(opt) {
|
|
25739
|
+
super();
|
|
25740
|
+
this.id = opt.id || `agent-${Date.now()}`;
|
|
25741
|
+
this.basespace = opt.basespace;
|
|
25742
|
+
this.workspace = opt.workspace;
|
|
25743
|
+
this.memoryFilePath = opt.memoryFilePath;
|
|
25744
|
+
this.sessionDirPath = opt.sessionDirPath;
|
|
25745
|
+
this.userStorePath = opt.userStorePath;
|
|
25746
|
+
this.agentRulesPath = opt.agentRulesPath;
|
|
25747
|
+
this.isPrintThinking = opt.isPrintThinking;
|
|
25748
|
+
this.opt = opt;
|
|
25749
|
+
}
|
|
25750
|
+
async init() {
|
|
25751
|
+
this.tools = await getTools();
|
|
25752
|
+
this.skills = [...getSkills(), ...this.opt.skills || []];
|
|
25753
|
+
const model = getModel(this.opt.modelOpt);
|
|
25754
|
+
const checkpointer = new FileSystemSaver({
|
|
25755
|
+
rootFolder: this.sessionDirPath
|
|
25756
|
+
});
|
|
25757
|
+
const contextSchema = external_exports.object({
|
|
25758
|
+
agent_name: external_exports.string(),
|
|
25759
|
+
encoding: external_exports.string(),
|
|
25760
|
+
skills: external_exports.array(external_exports.string()).optional(),
|
|
25761
|
+
memoryFilePath: external_exports.string().optional(),
|
|
25762
|
+
agentId: external_exports.string().optional(),
|
|
25763
|
+
mainAgent: external_exports.object().optional()
|
|
25764
|
+
});
|
|
25765
|
+
const agent = (0, import_langchain17.createAgent)({
|
|
25766
|
+
model,
|
|
25767
|
+
checkpointer,
|
|
25768
|
+
tools: this.tools,
|
|
25769
|
+
contextSchema,
|
|
25770
|
+
middleware: [
|
|
25771
|
+
createAgentEventMiddleware(this),
|
|
25772
|
+
(0, import_langchain17.summarizationMiddleware)({
|
|
25773
|
+
model,
|
|
25774
|
+
trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
|
|
25775
|
+
keep: { messages: 50 }
|
|
25776
|
+
}),
|
|
25777
|
+
(0, import_langchain17.humanInTheLoopMiddleware)({
|
|
25778
|
+
interruptOn: {
|
|
25779
|
+
install_package: {
|
|
25780
|
+
allowedDecisions: ["approve", "reject"]
|
|
25781
|
+
},
|
|
25782
|
+
readEmailTool: false
|
|
25783
|
+
}
|
|
25784
|
+
}),
|
|
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
|
+
})
|
|
25800
|
+
],
|
|
25801
|
+
systemPrompt: systemPrompt(this.workspace, import_os4.default.platform(), this.skills, this.memoryFilePath, this.agentRulesPath)
|
|
25802
|
+
});
|
|
25803
|
+
this.agent = agent;
|
|
25804
|
+
this.taskQueue = new TaskQueue(this.id);
|
|
25805
|
+
this.initEvents();
|
|
25806
|
+
}
|
|
25807
|
+
async execute(input) {
|
|
25808
|
+
const humanMessage = new import_langchain17.HumanMessage(input);
|
|
25809
|
+
this.messages.push(humanMessage);
|
|
25810
|
+
const stream = await this.agent.stream(
|
|
25811
|
+
{ messages: this.messages },
|
|
25812
|
+
{
|
|
25813
|
+
streamMode: ["messages"],
|
|
25814
|
+
recursionLimit: 2e3,
|
|
25815
|
+
subgraphs: true,
|
|
25816
|
+
configurable: { thread_id: this.id },
|
|
25817
|
+
context: {
|
|
25818
|
+
agent_name: "deepfish",
|
|
25819
|
+
encoding: this.opt.encoding,
|
|
25820
|
+
skills: this.skills,
|
|
25821
|
+
memoryFilePath: this.memoryFilePath,
|
|
25822
|
+
agentId: this.id,
|
|
25823
|
+
mainAgent: this
|
|
25824
|
+
}
|
|
25603
25825
|
}
|
|
25604
25826
|
);
|
|
25605
25827
|
for await (const [_namespace, mode, data] of stream) {
|
|
@@ -25657,12 +25879,17 @@ var AIAgent = class extends import_eventemitter_super.EventEmitterSuper {
|
|
|
25657
25879
|
log(`[Tool Call] ${funcName}`, "#c2a654");
|
|
25658
25880
|
});
|
|
25659
25881
|
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
|
|
25882
|
+
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
|
|
25660
25883
|
});
|
|
25661
25884
|
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
|
|
25885
|
+
logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
|
|
25662
25886
|
});
|
|
25663
25887
|
this.on("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, (_toolId, _funcName, _funcArgs) => {
|
|
25664
25888
|
});
|
|
25665
25889
|
}
|
|
25890
|
+
createSubAgent() {
|
|
25891
|
+
return new SubAIAgent(this.opt);
|
|
25892
|
+
}
|
|
25666
25893
|
destory() {
|
|
25667
25894
|
this.removeAllListeners();
|
|
25668
25895
|
}
|
|
@@ -26053,7 +26280,7 @@ function initSession() {
|
|
|
26053
26280
|
initSessionDir(existingSession.id);
|
|
26054
26281
|
return existingSession;
|
|
26055
26282
|
}
|
|
26056
|
-
const agentId = (0,
|
|
26283
|
+
const agentId = (0, import_crypto5.randomUUID)();
|
|
26057
26284
|
const newSession = {
|
|
26058
26285
|
id: agentId,
|
|
26059
26286
|
name: import_path18.default.basename(workspace),
|
|
@@ -26106,15 +26333,15 @@ function getAgentId() {
|
|
|
26106
26333
|
// src/cli/cli-core/skills.ts
|
|
26107
26334
|
function handleSkillsLs() {
|
|
26108
26335
|
const skills = _getAllSkills();
|
|
26109
|
-
|
|
26336
|
+
logInfo("=".repeat(50));
|
|
26110
26337
|
if (skills.length === 0) {
|
|
26111
26338
|
logInfo("No skills registered yet");
|
|
26112
26339
|
} else {
|
|
26113
26340
|
skills.forEach((skill, index) => {
|
|
26114
|
-
|
|
26341
|
+
logInfo(`[${index}] ${skill.name} (${skill.isEnabled ? "enabled" : "disabled"})`);
|
|
26115
26342
|
});
|
|
26116
26343
|
}
|
|
26117
|
-
|
|
26344
|
+
logInfo("=".repeat(50));
|
|
26118
26345
|
}
|
|
26119
26346
|
async function handleSkillsAdd(name) {
|
|
26120
26347
|
logInfo(`Adding skill: ${name}`);
|
|
@@ -26126,7 +26353,7 @@ async function handleSkillsAdd(name) {
|
|
|
26126
26353
|
}
|
|
26127
26354
|
const { scope } = await import_inquirer3.default.prompt([
|
|
26128
26355
|
{
|
|
26129
|
-
type: "
|
|
26356
|
+
type: "select",
|
|
26130
26357
|
name: "scope",
|
|
26131
26358
|
message: "Select skill scope:",
|
|
26132
26359
|
choices: [
|
|
@@ -26292,7 +26519,7 @@ function _updateRegister(skillsDir) {
|
|
|
26292
26519
|
const existItem = register.find((item) => item.skillPath === skillPath);
|
|
26293
26520
|
if (!existItem) {
|
|
26294
26521
|
newRegister.push({
|
|
26295
|
-
id: (0,
|
|
26522
|
+
id: (0, import_crypto6.randomUUID)(),
|
|
26296
26523
|
name: skillName,
|
|
26297
26524
|
isEnabled: true,
|
|
26298
26525
|
skillPath
|
|
@@ -26375,7 +26602,7 @@ async function handleToolsAdd(name) {
|
|
|
26375
26602
|
}
|
|
26376
26603
|
const { scope } = await import_inquirer4.default.prompt([
|
|
26377
26604
|
{
|
|
26378
|
-
type: "
|
|
26605
|
+
type: "select",
|
|
26379
26606
|
name: "scope",
|
|
26380
26607
|
message: "Select tool scope:",
|
|
26381
26608
|
choices: [
|
|
@@ -26720,7 +26947,6 @@ function handleCacheList() {
|
|
|
26720
26947
|
}
|
|
26721
26948
|
catalog.forEach((item, index) => {
|
|
26722
26949
|
const desc = item.description.length > 20 ? item.description.slice(0, 20) + "..." : item.description;
|
|
26723
|
-
console.log(`[${index}] ${item.id} ${desc}`);
|
|
26724
26950
|
});
|
|
26725
26951
|
}
|
|
26726
26952
|
function handleCacheEdit(input) {
|
package/dist/serve/pm2-server.js
CHANGED
|
@@ -8703,8 +8703,8 @@ var import_fs_extra17 = __toESM(require("fs-extra"));
|
|
|
8703
8703
|
var import_path12 = __toESM(require("path"));
|
|
8704
8704
|
|
|
8705
8705
|
// src/agent/AIAgent/index.ts
|
|
8706
|
-
var
|
|
8707
|
-
var
|
|
8706
|
+
var import_langchain17 = require("langchain");
|
|
8707
|
+
var import_deepagents2 = require("deepagents");
|
|
8708
8708
|
|
|
8709
8709
|
// src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
|
|
8710
8710
|
var import_runnables = require("@langchain/core/runnables");
|
|
@@ -23265,7 +23265,7 @@ function date4(params) {
|
|
|
23265
23265
|
config(en_default());
|
|
23266
23266
|
|
|
23267
23267
|
// src/agent/AIAgent/index.ts
|
|
23268
|
-
var
|
|
23268
|
+
var import_eventemitter_super2 = require("eventemitter-super");
|
|
23269
23269
|
|
|
23270
23270
|
// src/agent/AIAgent/middleware/eventEmitMiddleware.ts
|
|
23271
23271
|
var import_langchain = require("langchain");
|
|
@@ -23499,7 +23499,6 @@ var executeCommandTool = (0, import_langchain3.tool)(({ command, timeout }) => s
|
|
|
23499
23499
|
var import_langchain4 = require("langchain");
|
|
23500
23500
|
var import_path6 = __toESM(require("path"));
|
|
23501
23501
|
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
23502
|
-
var _require = require;
|
|
23503
23502
|
async function executeJSCode(code) {
|
|
23504
23503
|
logInfo("Executing JavaScript code: ");
|
|
23505
23504
|
logInfo(code);
|
|
@@ -23510,7 +23509,15 @@ async function executeJSCode(code) {
|
|
|
23510
23509
|
return result || "Code executed successfully, but __main() did not return anything."
|
|
23511
23510
|
})()`;
|
|
23512
23511
|
const fn = new Function("require", wrapped);
|
|
23513
|
-
const
|
|
23512
|
+
const _require = require;
|
|
23513
|
+
const newRequire = (modulePath) => {
|
|
23514
|
+
if (modulePath.startsWith("./")) {
|
|
23515
|
+
const resolvedPath = import_path6.default.resolve(process.cwd(), modulePath);
|
|
23516
|
+
return _require(resolvedPath);
|
|
23517
|
+
}
|
|
23518
|
+
return _require(modulePath);
|
|
23519
|
+
};
|
|
23520
|
+
const result = await fn(newRequire);
|
|
23514
23521
|
return result;
|
|
23515
23522
|
} catch (error51) {
|
|
23516
23523
|
logError(`Error executing code: ${error51.stack}`);
|
|
@@ -24163,6 +24170,11 @@ var builtinTools = [
|
|
|
24163
24170
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
24164
24171
|
var import_fs_extra16 = __toESM(require("fs-extra"));
|
|
24165
24172
|
|
|
24173
|
+
// src/agent/AIAgent/SubAIAgent.ts
|
|
24174
|
+
var import_langchain16 = require("langchain");
|
|
24175
|
+
var import_deepagents = require("deepagents");
|
|
24176
|
+
var import_eventemitter_super = require("eventemitter-super");
|
|
24177
|
+
|
|
24166
24178
|
// src/serve/service/agent-room/agent-client.ts
|
|
24167
24179
|
var import_ws = __toESM(require("ws"));
|
|
24168
24180
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepfish-ai",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "An efficient AI-driven command-line tool designed to bridge the gap between natural language and operating system commands, file operations, and more. It enables non-developers to quickly generate executable instructions through simple natural language descriptions, significantly improving terminal operation efficiency.",
|
|
6
6
|
"repository": {
|