deepfish-ai 2.0.7 → 2.0.9
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 +6 -4
- package/dist/generate-tool.md +124 -3
- package/dist/index.js +384 -236
- package/dist/serve/pm2-server.js +167 -56
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8403,10 +8403,10 @@ var require_lib = __commonJS({
|
|
|
8403
8403
|
exports2.analyse = analyse;
|
|
8404
8404
|
var detectFile = (filepath, opts = {}) => new Promise((resolve, reject) => {
|
|
8405
8405
|
let fd;
|
|
8406
|
-
const
|
|
8406
|
+
const fs24 = (0, node_1.default)();
|
|
8407
8407
|
const handler = (err, buffer) => {
|
|
8408
8408
|
if (fd) {
|
|
8409
|
-
|
|
8409
|
+
fs24.closeSync(fd);
|
|
8410
8410
|
}
|
|
8411
8411
|
if (err) {
|
|
8412
8412
|
reject(err);
|
|
@@ -8418,9 +8418,9 @@ var require_lib = __commonJS({
|
|
|
8418
8418
|
};
|
|
8419
8419
|
const sampleSize = (opts === null || opts === void 0 ? void 0 : opts.sampleSize) || 0;
|
|
8420
8420
|
if (sampleSize > 0) {
|
|
8421
|
-
fd =
|
|
8421
|
+
fd = fs24.openSync(filepath, "r");
|
|
8422
8422
|
let sample = Buffer.allocUnsafe(sampleSize);
|
|
8423
|
-
|
|
8423
|
+
fs24.read(fd, sample, 0, sampleSize, opts.offset, (err, bytesRead) => {
|
|
8424
8424
|
if (err) {
|
|
8425
8425
|
handler(err, null);
|
|
8426
8426
|
} else {
|
|
@@ -8432,22 +8432,22 @@ var require_lib = __commonJS({
|
|
|
8432
8432
|
});
|
|
8433
8433
|
return;
|
|
8434
8434
|
}
|
|
8435
|
-
|
|
8435
|
+
fs24.readFile(filepath, handler);
|
|
8436
8436
|
});
|
|
8437
8437
|
exports2.detectFile = detectFile;
|
|
8438
8438
|
var detectFileSync = (filepath, opts = {}) => {
|
|
8439
|
-
const
|
|
8439
|
+
const fs24 = (0, node_1.default)();
|
|
8440
8440
|
if (opts && opts.sampleSize) {
|
|
8441
|
-
const fd =
|
|
8441
|
+
const fd = fs24.openSync(filepath, "r");
|
|
8442
8442
|
let sample = Buffer.allocUnsafe(opts.sampleSize);
|
|
8443
|
-
const bytesRead =
|
|
8443
|
+
const bytesRead = fs24.readSync(fd, sample, 0, opts.sampleSize, opts.offset);
|
|
8444
8444
|
if (bytesRead < opts.sampleSize) {
|
|
8445
8445
|
sample = sample.subarray(0, bytesRead);
|
|
8446
8446
|
}
|
|
8447
|
-
|
|
8447
|
+
fs24.closeSync(fd);
|
|
8448
8448
|
return (0, exports2.detect)(sample);
|
|
8449
8449
|
}
|
|
8450
|
-
return (0, exports2.detect)(
|
|
8450
|
+
return (0, exports2.detect)(fs24.readFileSync(filepath));
|
|
8451
8451
|
};
|
|
8452
8452
|
exports2.detectFileSync = detectFileSync;
|
|
8453
8453
|
exports2.default = {
|
|
@@ -8938,8 +8938,8 @@ function registerModelsCommands(program) {
|
|
|
8938
8938
|
// src/cli/cli-core/skills.ts
|
|
8939
8939
|
var import_crypto6 = require("crypto");
|
|
8940
8940
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
8941
|
-
var
|
|
8942
|
-
var
|
|
8941
|
+
var import_fs_extra20 = __toESM(require("fs-extra"));
|
|
8942
|
+
var import_path20 = __toESM(require("path"));
|
|
8943
8943
|
|
|
8944
8944
|
// src/cli/cli-utils/init-config.ts
|
|
8945
8945
|
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
@@ -8996,12 +8996,12 @@ function getConfig() {
|
|
|
8996
8996
|
}
|
|
8997
8997
|
|
|
8998
8998
|
// src/cli/cli-utils/init-agent.ts
|
|
8999
|
-
var
|
|
9000
|
-
var
|
|
8999
|
+
var import_fs_extra19 = __toESM(require("fs-extra"));
|
|
9000
|
+
var import_path19 = __toESM(require("path"));
|
|
9001
9001
|
var import_crypto5 = require("crypto");
|
|
9002
9002
|
|
|
9003
9003
|
// src/agent/AIAgent/index.ts
|
|
9004
|
-
var
|
|
9004
|
+
var import_langchain19 = require("langchain");
|
|
9005
9005
|
var import_deepagents2 = require("deepagents");
|
|
9006
9006
|
|
|
9007
9007
|
// src/agent/AIAgent/utils/langgraph-checkpoint-filesystem/filesystem-saver.ts
|
|
@@ -10494,10 +10494,10 @@ function mergeDefs(...defs) {
|
|
|
10494
10494
|
function cloneDef(schema) {
|
|
10495
10495
|
return mergeDefs(schema._zod.def);
|
|
10496
10496
|
}
|
|
10497
|
-
function getElementAtPath(obj,
|
|
10498
|
-
if (!
|
|
10497
|
+
function getElementAtPath(obj, path22) {
|
|
10498
|
+
if (!path22)
|
|
10499
10499
|
return obj;
|
|
10500
|
-
return
|
|
10500
|
+
return path22.reduce((acc, key) => acc?.[key], obj);
|
|
10501
10501
|
}
|
|
10502
10502
|
function promiseAllObject(promisesObj) {
|
|
10503
10503
|
const keys = Object.keys(promisesObj);
|
|
@@ -10906,11 +10906,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
10906
10906
|
}
|
|
10907
10907
|
return false;
|
|
10908
10908
|
}
|
|
10909
|
-
function prefixIssues(
|
|
10909
|
+
function prefixIssues(path22, issues) {
|
|
10910
10910
|
return issues.map((iss) => {
|
|
10911
10911
|
var _a3;
|
|
10912
10912
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
10913
|
-
iss.path.unshift(
|
|
10913
|
+
iss.path.unshift(path22);
|
|
10914
10914
|
return iss;
|
|
10915
10915
|
});
|
|
10916
10916
|
}
|
|
@@ -11057,16 +11057,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
11057
11057
|
}
|
|
11058
11058
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
11059
11059
|
const fieldErrors = { _errors: [] };
|
|
11060
|
-
const processError = (error52,
|
|
11060
|
+
const processError = (error52, path22 = []) => {
|
|
11061
11061
|
for (const issue2 of error52.issues) {
|
|
11062
11062
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
11063
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
11063
|
+
issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
|
|
11064
11064
|
} else if (issue2.code === "invalid_key") {
|
|
11065
|
-
processError({ issues: issue2.issues }, [...
|
|
11065
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
11066
11066
|
} else if (issue2.code === "invalid_element") {
|
|
11067
|
-
processError({ issues: issue2.issues }, [...
|
|
11067
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
11068
11068
|
} else {
|
|
11069
|
-
const fullpath = [...
|
|
11069
|
+
const fullpath = [...path22, ...issue2.path];
|
|
11070
11070
|
if (fullpath.length === 0) {
|
|
11071
11071
|
fieldErrors._errors.push(mapper(issue2));
|
|
11072
11072
|
} else {
|
|
@@ -11093,17 +11093,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
11093
11093
|
}
|
|
11094
11094
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
11095
11095
|
const result = { errors: [] };
|
|
11096
|
-
const processError = (error52,
|
|
11096
|
+
const processError = (error52, path22 = []) => {
|
|
11097
11097
|
var _a3, _b;
|
|
11098
11098
|
for (const issue2 of error52.issues) {
|
|
11099
11099
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
11100
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
11100
|
+
issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
|
|
11101
11101
|
} else if (issue2.code === "invalid_key") {
|
|
11102
|
-
processError({ issues: issue2.issues }, [...
|
|
11102
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
11103
11103
|
} else if (issue2.code === "invalid_element") {
|
|
11104
|
-
processError({ issues: issue2.issues }, [...
|
|
11104
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
11105
11105
|
} else {
|
|
11106
|
-
const fullpath = [...
|
|
11106
|
+
const fullpath = [...path22, ...issue2.path];
|
|
11107
11107
|
if (fullpath.length === 0) {
|
|
11108
11108
|
result.errors.push(mapper(issue2));
|
|
11109
11109
|
continue;
|
|
@@ -11135,8 +11135,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
11135
11135
|
}
|
|
11136
11136
|
function toDotPath(_path) {
|
|
11137
11137
|
const segs = [];
|
|
11138
|
-
const
|
|
11139
|
-
for (const seg of
|
|
11138
|
+
const path22 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
11139
|
+
for (const seg of path22) {
|
|
11140
11140
|
if (typeof seg === "number")
|
|
11141
11141
|
segs.push(`[${seg}]`);
|
|
11142
11142
|
else if (typeof seg === "symbol")
|
|
@@ -23828,13 +23828,13 @@ function resolveRef(ref, ctx) {
|
|
|
23828
23828
|
if (!ref.startsWith("#")) {
|
|
23829
23829
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
23830
23830
|
}
|
|
23831
|
-
const
|
|
23832
|
-
if (
|
|
23831
|
+
const path22 = ref.slice(1).split("/").filter(Boolean);
|
|
23832
|
+
if (path22.length === 0) {
|
|
23833
23833
|
return ctx.rootSchema;
|
|
23834
23834
|
}
|
|
23835
23835
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
23836
|
-
if (
|
|
23837
|
-
const key =
|
|
23836
|
+
if (path22[0] === defsKey) {
|
|
23837
|
+
const key = path22[1];
|
|
23838
23838
|
if (!key || !ctx.defs[key]) {
|
|
23839
23839
|
throw new Error(`Reference not found: ${ref}`);
|
|
23840
23840
|
}
|
|
@@ -24247,6 +24247,7 @@ var import_eventemitter_super2 = require("eventemitter-super");
|
|
|
24247
24247
|
|
|
24248
24248
|
// src/agent/AIAgent/middleware/eventEmitMiddleware.ts
|
|
24249
24249
|
var import_langchain = require("langchain");
|
|
24250
|
+
var import_messages = require("@langchain/core/messages");
|
|
24250
24251
|
function createAgentEventMiddleware(emitter) {
|
|
24251
24252
|
return (0, import_langchain.createMiddleware)({
|
|
24252
24253
|
name: "AgentEventMiddleware",
|
|
@@ -24276,7 +24277,7 @@ function createAgentEventMiddleware(emitter) {
|
|
|
24276
24277
|
return await handler(request);
|
|
24277
24278
|
} catch (error51) {
|
|
24278
24279
|
emitter.emit("MODEL_ERROR" /* MODEL_ERROR */, error51);
|
|
24279
|
-
|
|
24280
|
+
return new import_messages.AIMessage(error51.message);
|
|
24280
24281
|
}
|
|
24281
24282
|
},
|
|
24282
24283
|
// Around each tool call
|
|
@@ -24291,7 +24292,7 @@ function createAgentEventMiddleware(emitter) {
|
|
|
24291
24292
|
} catch (err) {
|
|
24292
24293
|
emitter.emit("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, toolCall.id, toolCall.name, err);
|
|
24293
24294
|
emitter.emit("USE_TOOL_AFTER" /* USE_TOOL_AFTER */, toolCall.id, toolCall.name, toolCall.args);
|
|
24294
|
-
|
|
24295
|
+
return new import_langchain.ToolMessage(err.message);
|
|
24295
24296
|
}
|
|
24296
24297
|
}
|
|
24297
24298
|
});
|
|
@@ -24403,12 +24404,12 @@ ${params.systemPrompt || `\u8FD9\u662FDeepfish Cli\u7CFB\u7EDF,\u4F60\u662F\u7CF
|
|
|
24403
24404
|
# \u6CE8\u610F\u6CE8\u610F\u4E8B\u9879:
|
|
24404
24405
|
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
|
|
24405
24406
|
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
|
|
24406
|
-
3.\u5C3D\u91CF\u4F7F\u7528"execute_command"\u3001"execute_js_code"\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1
|
|
24407
|
+
3.\u5C3D\u91CF\u4F7F\u7528"execute_command"\u3001"execute_js_code"\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1
|
|
24408
|
+
4.\u786C\u6027\u89C4\u5219\uFF1A\u65E0\u8BBA\u6846\u67B6\u5185\u7F6E\u82F1\u6587\u6A21\u677F\uFF0C\u4F60\u7684\u6BCF\u4E00\u6B65\u601D\u8003\uFF08Thought\uFF09\u3001\u89C2\u5BDF\u5206\u6790\u3001\u7ED3\u8BBA\u56DE\u7B54\uFF0C**\u4E25\u683C\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587**\uFF0C\u7981\u6B62\u82F1\u6587\u3002`}
|
|
24407
24409
|
|
|
24408
24410
|
# \u57FA\u7840\u73AF\u5883\u4FE1\u606F
|
|
24409
24411
|
\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${params.workspace}
|
|
24410
24412
|
\u64CD\u4F5C\u7CFB\u7EDF\u7C7B\u578B\uFF1A${params.osType}
|
|
24411
|
-
\u8BED\u8A00\u7C7B\u578B: \u4E0E\u7528\u6237\u8F93\u5165\u8BED\u8A00\u4E00\u81F4
|
|
24412
24413
|
|
|
24413
24414
|
${skillPrompt}
|
|
24414
24415
|
${memoryPrompt}
|
|
@@ -24422,12 +24423,12 @@ var subSystemPrompt = (workspace, osType, skills, excludeSkills) => {
|
|
|
24422
24423
|
### \u57FA\u7840\u73AF\u5883\u4FE1\u606F
|
|
24423
24424
|
\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\uFF1A${workspace}
|
|
24424
24425
|
\u64CD\u4F5C\u7CFB\u7EDF\u7C7B\u578B\uFF1A${osType}
|
|
24425
|
-
\u8BED\u8A00\u7C7B\u578B: \u4E0E\u7528\u6237\u8F93\u5165\u8BED\u8A00\u4E00\u81F4
|
|
24426
24426
|
|
|
24427
24427
|
\u6CE8\u610F:
|
|
24428
24428
|
1.\u5B50\u667A\u80FD\u4F53\u53EA\u80FD\u5B8C\u6210\u5355\u4E2A\u4EFB\u52A1,\u4E0D\u80FD\u521B\u5EFA\u65B0\u7684\u5B50\u667A\u80FD\u4F53\u3002
|
|
24429
24429
|
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
|
|
24430
24430
|
3.\u5C3D\u91CF\u4F7F\u7528"execute_command"\u3001"execute_js_code"\u5DE5\u5177\u5B8C\u6210\u4EFB\u52A1
|
|
24431
|
+
4.\u786C\u6027\u89C4\u5219\uFF1A\u65E0\u8BBA\u6846\u67B6\u5185\u7F6E\u82F1\u6587\u6A21\u677F\uFF0C\u4F60\u7684\u6BCF\u4E00\u6B65\u601D\u8003\uFF08Thought\uFF09\u3001\u89C2\u5BDF\u5206\u6790\u3001\u7ED3\u8BBA\u56DE\u7B54\uFF0C**\u4E25\u683C\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587**\uFF0C\u7981\u6B62\u82F1\u6587\u3002
|
|
24431
24432
|
|
|
24432
24433
|
${skillPrompt}
|
|
24433
24434
|
`;
|
|
@@ -24613,33 +24614,54 @@ async function safeTool(handler) {
|
|
|
24613
24614
|
return serializeToolResult(errorResult(error51));
|
|
24614
24615
|
}
|
|
24615
24616
|
}
|
|
24617
|
+
function jsonSchemaToZod(node) {
|
|
24618
|
+
if (!node || typeof node !== "object") {
|
|
24619
|
+
return external_exports.any();
|
|
24620
|
+
}
|
|
24621
|
+
const { type, description: desc, properties, items, required: required2, enum: enumValues } = node;
|
|
24622
|
+
const withDesc = (schema) => desc ? schema.describe(desc) : schema;
|
|
24623
|
+
if (Array.isArray(enumValues) && enumValues.length > 0) {
|
|
24624
|
+
const allStrings = enumValues.every((v) => typeof v === "string");
|
|
24625
|
+
if (allStrings) {
|
|
24626
|
+
return withDesc(external_exports.enum(enumValues));
|
|
24627
|
+
}
|
|
24628
|
+
}
|
|
24629
|
+
switch (type) {
|
|
24630
|
+
case "string":
|
|
24631
|
+
return withDesc(external_exports.string());
|
|
24632
|
+
case "number":
|
|
24633
|
+
case "integer":
|
|
24634
|
+
return withDesc(external_exports.number());
|
|
24635
|
+
case "boolean":
|
|
24636
|
+
return withDesc(external_exports.boolean());
|
|
24637
|
+
case "array": {
|
|
24638
|
+
const itemSchema = items ? jsonSchemaToZod(items) : external_exports.any();
|
|
24639
|
+
return withDesc(external_exports.array(itemSchema));
|
|
24640
|
+
}
|
|
24641
|
+
case "object": {
|
|
24642
|
+
const shape = {};
|
|
24643
|
+
if (properties && typeof properties === "object") {
|
|
24644
|
+
const requiredFields = Array.isArray(required2) ? required2 : [];
|
|
24645
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
24646
|
+
let childSchema = jsonSchemaToZod(value);
|
|
24647
|
+
if (!requiredFields.includes(key)) {
|
|
24648
|
+
childSchema = childSchema.optional();
|
|
24649
|
+
}
|
|
24650
|
+
shape[key] = childSchema;
|
|
24651
|
+
}
|
|
24652
|
+
}
|
|
24653
|
+
return withDesc(external_exports.object(shape).passthrough());
|
|
24654
|
+
}
|
|
24655
|
+
default:
|
|
24656
|
+
return withDesc(external_exports.any());
|
|
24657
|
+
}
|
|
24658
|
+
}
|
|
24616
24659
|
function toLangChainTool(func, description) {
|
|
24617
24660
|
const { name, description: desc, parameters } = description.function;
|
|
24618
24661
|
const { properties } = parameters;
|
|
24619
24662
|
const zodProperties = {};
|
|
24620
24663
|
for (const [key, value] of Object.entries(properties)) {
|
|
24621
|
-
|
|
24622
|
-
let zodType;
|
|
24623
|
-
switch (type) {
|
|
24624
|
-
case "string":
|
|
24625
|
-
zodType = desc2 ? external_exports.string().describe(desc2) : external_exports.string();
|
|
24626
|
-
break;
|
|
24627
|
-
case "number":
|
|
24628
|
-
zodType = desc2 ? external_exports.number().describe(desc2) : external_exports.number();
|
|
24629
|
-
break;
|
|
24630
|
-
case "boolean":
|
|
24631
|
-
zodType = desc2 ? external_exports.boolean().describe(desc2) : external_exports.boolean();
|
|
24632
|
-
break;
|
|
24633
|
-
case "object":
|
|
24634
|
-
zodType = desc2 ? external_exports.object({}).describe(desc2) : external_exports.object({});
|
|
24635
|
-
break;
|
|
24636
|
-
case "array":
|
|
24637
|
-
zodType = desc2 ? external_exports.array(external_exports.string()).describe(desc2) : external_exports.array(external_exports.string());
|
|
24638
|
-
break;
|
|
24639
|
-
default:
|
|
24640
|
-
zodType = external_exports.any();
|
|
24641
|
-
}
|
|
24642
|
-
zodProperties[key] = zodType;
|
|
24664
|
+
zodProperties[key] = jsonSchemaToZod(value);
|
|
24643
24665
|
}
|
|
24644
24666
|
const schema = external_exports.object(zodProperties);
|
|
24645
24667
|
const wrappedFunc = async (args, runtime) => {
|
|
@@ -24667,7 +24689,41 @@ function toLangChainTool(func, description) {
|
|
|
24667
24689
|
});
|
|
24668
24690
|
}
|
|
24669
24691
|
function scanUserTools(excludeTools) {
|
|
24692
|
+
const files = _scanUserToolsFile();
|
|
24670
24693
|
const tools = [];
|
|
24694
|
+
files.forEach((toolFile) => {
|
|
24695
|
+
_loadToolsFromFile(toolFile.filePath, tools, excludeTools);
|
|
24696
|
+
});
|
|
24697
|
+
return tools;
|
|
24698
|
+
}
|
|
24699
|
+
function getUserToolList() {
|
|
24700
|
+
const files = _scanUserToolsFile();
|
|
24701
|
+
const toolOpts = [];
|
|
24702
|
+
files.forEach((toolFile) => {
|
|
24703
|
+
const toolModule = require(toolFile.filePath);
|
|
24704
|
+
const { functions, descriptions } = toolModule;
|
|
24705
|
+
descriptions.forEach((desc) => {
|
|
24706
|
+
if (!desc.type) {
|
|
24707
|
+
desc = {
|
|
24708
|
+
type: "function",
|
|
24709
|
+
function: desc
|
|
24710
|
+
};
|
|
24711
|
+
}
|
|
24712
|
+
const func = functions[desc.function.name];
|
|
24713
|
+
if (typeof func !== "function") {
|
|
24714
|
+
return;
|
|
24715
|
+
}
|
|
24716
|
+
toolOpts.push({
|
|
24717
|
+
name: desc.function.name,
|
|
24718
|
+
path: toolFile.filePath,
|
|
24719
|
+
dir: toolFile.dir
|
|
24720
|
+
});
|
|
24721
|
+
});
|
|
24722
|
+
});
|
|
24723
|
+
return toolOpts;
|
|
24724
|
+
}
|
|
24725
|
+
function _scanUserToolsFile() {
|
|
24726
|
+
const toolFiles = [];
|
|
24671
24727
|
const scanPaths = getScanDirPaths();
|
|
24672
24728
|
scanPaths.forEach((scanPath) => {
|
|
24673
24729
|
const toolsDir = import_path8.default.resolve(scanPath, "tools");
|
|
@@ -24681,26 +24737,35 @@ function scanUserTools(excludeTools) {
|
|
|
24681
24737
|
if (indexFile) {
|
|
24682
24738
|
const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, indexFile), indexFile);
|
|
24683
24739
|
if (filePath) {
|
|
24684
|
-
|
|
24740
|
+
toolFiles.push({
|
|
24741
|
+
filePath,
|
|
24742
|
+
dir: subDirPath
|
|
24743
|
+
});
|
|
24685
24744
|
}
|
|
24686
24745
|
} else {
|
|
24687
24746
|
subFiles.forEach((subFile) => {
|
|
24688
24747
|
const filePath = _scanDeepFishJsFile(import_path8.default.resolve(subDirPath, subFile), subFile);
|
|
24689
24748
|
if (filePath) {
|
|
24690
|
-
|
|
24749
|
+
toolFiles.push({
|
|
24750
|
+
filePath,
|
|
24751
|
+
dir: subDirPath
|
|
24752
|
+
});
|
|
24691
24753
|
}
|
|
24692
24754
|
});
|
|
24693
24755
|
}
|
|
24694
24756
|
} else {
|
|
24695
24757
|
const filePath = _scanDeepFishJsFile(toolsDir, file2);
|
|
24696
24758
|
if (filePath) {
|
|
24697
|
-
|
|
24759
|
+
toolFiles.push({
|
|
24760
|
+
filePath,
|
|
24761
|
+
dir: null
|
|
24762
|
+
});
|
|
24698
24763
|
}
|
|
24699
24764
|
}
|
|
24700
24765
|
});
|
|
24701
24766
|
}
|
|
24702
24767
|
});
|
|
24703
|
-
return
|
|
24768
|
+
return toolFiles;
|
|
24704
24769
|
}
|
|
24705
24770
|
function _scanDeepFishJsFile(filePath, fileName) {
|
|
24706
24771
|
if (fileName.endsWith(".js") || fileName.endsWith(".cjs")) {
|
|
@@ -25247,15 +25312,15 @@ async function grepFiles(query, cwd, includePattern = "**/*", isRegexp = false,
|
|
|
25247
25312
|
}
|
|
25248
25313
|
var grepTool = (0, import_langchain10.tool)(
|
|
25249
25314
|
async ({ query, pattern, cwd, includePattern, isRegexp, maxResults, includeHidden }) => safeTool(() => {
|
|
25250
|
-
const searchQuery = query
|
|
25315
|
+
const searchQuery = (query ?? pattern ?? "").trim();
|
|
25251
25316
|
if (!searchQuery) {
|
|
25252
|
-
|
|
25317
|
+
return '\u8BF7\u63D0\u4F9B query \u6216 pattern \u4E4B\u4E00\uFF1B\u4F8B\u5982 query: "foo" \u6216 pattern: "foo"';
|
|
25253
25318
|
}
|
|
25254
25319
|
return grepFiles(searchQuery, cwd, includePattern, isRegexp, maxResults, includeHidden);
|
|
25255
25320
|
}),
|
|
25256
25321
|
{
|
|
25257
25322
|
name: "grep_files",
|
|
25258
|
-
description: "\u5728\u6587\u672C\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9\uFF0C\u652F\u6301\u666E\u901A\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F\uFF0C\u53EF\u7528 includePattern \u9650\u5B9A\u6587\u4EF6\u8303\u56F4\u3002query \u4E3A\u641C\u7D22\u5185\u5BB9\uFF1B\u517C\u5BB9 pattern \u4F5C\u4E3A query \u7684\u522B\u540D\u3002",
|
|
25323
|
+
description: "\u5728\u6587\u672C\u6587\u4EF6\u4E2D\u641C\u7D22\u5185\u5BB9\uFF0C\u652F\u6301\u666E\u901A\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F\uFF0C\u53EF\u7528 includePattern \u9650\u5B9A\u6587\u4EF6\u8303\u56F4\u3002query \u4E3A\u641C\u7D22\u5185\u5BB9\uFF1B\u517C\u5BB9 pattern \u4F5C\u4E3A query \u7684\u522B\u540D\uFF1B\u5982\u679C\u672A\u63D0\u4F9B\u641C\u7D22\u8BCD\uFF0C\u4F1A\u8FD4\u56DE\u63D0\u793A\u3002",
|
|
25259
25324
|
schema: external_exports.object({
|
|
25260
25325
|
query: external_exports.string().optional().describe("\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25261
25326
|
pattern: external_exports.string().optional().describe("query \u7684\u517C\u5BB9\u522B\u540D\uFF0C\u8981\u641C\u7D22\u7684\u5B57\u7B26\u4E32\u6216\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
@@ -25264,9 +25329,6 @@ var grepTool = (0, import_langchain10.tool)(
|
|
|
25264
25329
|
isRegexp: external_exports.boolean().default(false).describe("query/pattern \u662F\u5426\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F"),
|
|
25265
25330
|
maxResults: external_exports.number().default(100).describe("\u6700\u5927\u8FD4\u56DE\u5339\u914D\u6570\u91CF"),
|
|
25266
25331
|
includeHidden: external_exports.boolean().default(false).describe("\u662F\u5426\u5305\u542B\u9690\u85CF\u6587\u4EF6\u6216\u9690\u85CF\u76EE\u5F55")
|
|
25267
|
-
}).refine((input) => input.query || input.pattern, {
|
|
25268
|
-
message: "query \u6216 pattern \u81F3\u5C11\u9700\u8981\u63D0\u4F9B\u4E00\u4E2A",
|
|
25269
|
-
path: ["query"]
|
|
25270
25332
|
})
|
|
25271
25333
|
}
|
|
25272
25334
|
);
|
|
@@ -25563,6 +25625,124 @@ var writeFileTool = (0, import_langchain16.tool)(async ({ filePath, content, mod
|
|
|
25563
25625
|
})
|
|
25564
25626
|
});
|
|
25565
25627
|
|
|
25628
|
+
// src/agent/tools/getFishInfo.ts
|
|
25629
|
+
var import_langchain17 = require("langchain");
|
|
25630
|
+
|
|
25631
|
+
// src/cli/cli-help.ts
|
|
25632
|
+
var import_commander = require("commander");
|
|
25633
|
+
function helpInformation() {
|
|
25634
|
+
return `Usage: ai [options] [command]
|
|
25635
|
+
|
|
25636
|
+
Commands:
|
|
25637
|
+
ai "xxx" \u76F4\u63A5\u5411 AI \u53D1\u8D77\u4E00\u6B21\u4EFB\u52A1\u6216\u5BF9\u8BDD
|
|
25638
|
+
|
|
25639
|
+
# Configuration commands
|
|
25640
|
+
ai config edit \u6253\u5F00\u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8FDB\u884C\u7F16\u8F91
|
|
25641
|
+
ai config view \u67E5\u770B\u5F53\u524D\u5168\u5C40\u914D\u7F6E\u5185\u5BB9
|
|
25642
|
+
ai config reset \u91CD\u7F6E\u5168\u5C40\u914D\u7F6E\u4E3A\u9ED8\u8BA4\u503C
|
|
25643
|
+
ai config dir \u6253\u5F00\u6216\u8F93\u51FA\u5168\u5C40\u914D\u7F6E\u76EE\u5F55
|
|
25644
|
+
|
|
25645
|
+
# Model commands
|
|
25646
|
+
ai models add \u6DFB\u52A0\u4E00\u4E2A\u65B0\u7684\u6A21\u578B\u914D\u7F6E
|
|
25647
|
+
ai models ls \u67E5\u770B\u5DF2\u914D\u7F6E\u7684\u6A21\u578B\u5217\u8868
|
|
25648
|
+
ai models use <name> \u5207\u6362\u5F53\u524D\u9ED8\u8BA4\u4F7F\u7528\u7684\u6A21\u578B
|
|
25649
|
+
ai models del <name> \u5220\u9664\u6307\u5B9A\u540D\u79F0\u7684\u6A21\u578B\u914D\u7F6E
|
|
25650
|
+
|
|
25651
|
+
# Skill commands
|
|
25652
|
+
ai skills ls \u67E5\u770B\u5DF2\u5B89\u88C5\u6216\u5DF2\u914D\u7F6E\u7684\u6280\u80FD\u5217\u8868
|
|
25653
|
+
ai skills add <name> \u6DFB\u52A0\u6307\u5B9A\u540D\u79F0\u7684\u6280\u80FD
|
|
25654
|
+
ai skills del <index> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u6280\u80FD
|
|
25655
|
+
ai skills enable <name|index> \u542F\u7528\u6307\u5B9A\u540D\u79F0\u6216\u5E8F\u53F7\u7684\u6280\u80FD
|
|
25656
|
+
ai skills disable <name|index> \u7981\u7528\u6307\u5B9A\u540D\u79F0\u6216\u5E8F\u53F7\u7684\u6280\u80FD
|
|
25657
|
+
ai skills dir \u6253\u5F00\u6216\u8F93\u51FA\u6280\u80FD\u76EE\u5F55
|
|
25658
|
+
ai skills generate xxx \u6839\u636E\u63CF\u8FF0\u751F\u6210\u4E00\u4E2A\u65B0\u7684\u6280\u80FD\u6A21\u677F
|
|
25659
|
+
|
|
25660
|
+
# Tools commands
|
|
25661
|
+
ai tools dir \u6253\u5F00\u6216\u8F93\u51FA\u7528\u6237\u81EA\u5B9A\u4E49\u5DE5\u5177\u76EE\u5F55
|
|
25662
|
+
ai tools generate xxx \u6839\u636E\u63CF\u8FF0\u751F\u6210\u4E00\u4E2A\u65B0\u7684\u5DE5\u5177\u6A21\u677F
|
|
25663
|
+
|
|
25664
|
+
# Session commands
|
|
25665
|
+
ai session clear \u6E05\u7A7A\u5F53\u524D\u4F1A\u8BDD\u8BB0\u5F55
|
|
25666
|
+
ai session dir \u6253\u5F00\u6216\u8F93\u51FA\u4F1A\u8BDD\u6570\u636E\u76EE\u5F55
|
|
25667
|
+
|
|
25668
|
+
# Task commands
|
|
25669
|
+
ai task ls \u67E5\u770B\u5F53\u524D\u4EFB\u52A1\u961F\u5217
|
|
25670
|
+
ai task add <task> \u5411\u4EFB\u52A1\u961F\u5217\u6DFB\u52A0\u4E00\u4E2A\u540E\u7EED\u4EFB\u52A1
|
|
25671
|
+
ai task del <index> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u4EFB\u52A1
|
|
25672
|
+
ai task clear \u6E05\u7A7A\u5F53\u524D\u4EFB\u52A1\u961F\u5217
|
|
25673
|
+
|
|
25674
|
+
# MCP commands
|
|
25675
|
+
ai mcp edit \u6253\u5F00 MCP \u914D\u7F6E\u6587\u4EF6\u8FDB\u884C\u7F16\u8F91
|
|
25676
|
+
|
|
25677
|
+
# Serve commands
|
|
25678
|
+
ai serve \u542F\u52A8\u670D\u52A1\u6216\u8FDB\u5165\u670D\u52A1\u7BA1\u7406\u5165\u53E3
|
|
25679
|
+
ai serve start \u542F\u52A8\u540E\u53F0\u670D\u52A1
|
|
25680
|
+
ai serve stop \u505C\u6B62\u540E\u53F0\u670D\u52A1
|
|
25681
|
+
ai serve restart \u91CD\u542F\u540E\u53F0\u670D\u52A1
|
|
25682
|
+
|
|
25683
|
+
# Cache commands
|
|
25684
|
+
ai cache ls \u67E5\u770B\u5DF2\u7F13\u5B58\u7684\u5B66\u4E60\u5185\u5BB9\u5217\u8868
|
|
25685
|
+
ai cache edit <index|id> \u7F16\u8F91\u6307\u5B9A\u5E8F\u53F7\u6216 ID \u7684\u7F13\u5B58\u5185\u5BB9
|
|
25686
|
+
ai cache del <index|id> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u6216 ID \u7684\u7F13\u5B58\u5185\u5BB9
|
|
25687
|
+
`;
|
|
25688
|
+
}
|
|
25689
|
+
function registerHelpCommand(program) {
|
|
25690
|
+
program.helpInformation = helpInformation;
|
|
25691
|
+
program.command("help").description("Displaying help information").action(() => {
|
|
25692
|
+
logInfo(helpInformation());
|
|
25693
|
+
});
|
|
25694
|
+
}
|
|
25695
|
+
|
|
25696
|
+
// src/agent/tools/getFishInfo.ts
|
|
25697
|
+
var import_path16 = __toESM(require("path"));
|
|
25698
|
+
var import_fs_extra18 = __toESM(require("fs-extra"));
|
|
25699
|
+
var getFishCodePathTool = (0, import_langchain17.tool)(
|
|
25700
|
+
async () => safeTool(() => {
|
|
25701
|
+
const codePath = getCodePath();
|
|
25702
|
+
return { codePath };
|
|
25703
|
+
}),
|
|
25704
|
+
{
|
|
25705
|
+
name: "get_fish_code_path",
|
|
25706
|
+
description: "\u83B7\u53D6 Deepfish CLI \u7CFB\u7EDF\u7684\u4EE3\u7801\u6839\u76EE\u5F55\u8DEF\u5F84",
|
|
25707
|
+
schema: external_exports.object({})
|
|
25708
|
+
}
|
|
25709
|
+
);
|
|
25710
|
+
var getFishReadmeTool = (0, import_langchain17.tool)(
|
|
25711
|
+
async ({ lang }) => safeTool(() => {
|
|
25712
|
+
const codePath = getCodePath();
|
|
25713
|
+
const readmePath = lang === "en" ? import_path16.default.join(codePath, "README_EN.md") : import_path16.default.join(codePath, "README.md");
|
|
25714
|
+
const fallbackPath = lang === "en" ? import_path16.default.join(codePath, "README.md") : import_path16.default.join(codePath, "README_EN.md");
|
|
25715
|
+
let targetPath = readmePath;
|
|
25716
|
+
if (!import_fs_extra18.default.existsSync(targetPath)) {
|
|
25717
|
+
targetPath = fallbackPath;
|
|
25718
|
+
}
|
|
25719
|
+
if (!import_fs_extra18.default.existsSync(targetPath)) {
|
|
25720
|
+
return { error: "\u672A\u627E\u5230 README \u6587\u4EF6", readmePath: targetPath };
|
|
25721
|
+
}
|
|
25722
|
+
const content = import_fs_extra18.default.readFileSync(targetPath, "utf-8");
|
|
25723
|
+
return { readmePath: targetPath, content };
|
|
25724
|
+
}),
|
|
25725
|
+
{
|
|
25726
|
+
name: "get_fish_readme",
|
|
25727
|
+
description: "\u83B7\u53D6 Deepfish CLI \u7CFB\u7EDF\u7684 README \u6587\u4EF6\u5185\u5BB9\uFF0C\u7528\u4E8E\u4E86\u89E3\u7CFB\u7EDF\u7684\u529F\u80FD\u3001\u7528\u6CD5\u548C\u7279\u6027\u3002\u53EF\u9009\u53C2\u6570 lang \u6307\u5B9A\u8BED\u8A00\uFF08zh \u6216 en\uFF09\uFF0C\u9ED8\u8BA4\u4E2D\u6587\u3002",
|
|
25728
|
+
schema: external_exports.object({
|
|
25729
|
+
lang: external_exports.string().optional().default("zh").describe("\u8BED\u8A00\uFF0Czh \u4E3A\u4E2D\u6587 README\uFF0Cen \u4E3A\u82F1\u6587 README")
|
|
25730
|
+
})
|
|
25731
|
+
}
|
|
25732
|
+
);
|
|
25733
|
+
var getFishHelpTool = (0, import_langchain17.tool)(
|
|
25734
|
+
async () => safeTool(() => {
|
|
25735
|
+
const help = helpInformation();
|
|
25736
|
+
return { help };
|
|
25737
|
+
}),
|
|
25738
|
+
{
|
|
25739
|
+
name: "get_fish_help",
|
|
25740
|
+
description: "\u83B7\u53D6 Deepfish CLI \u7CFB\u7EDF\u7684\u6240\u6709\u53EF\u7528\u547D\u4EE4\u53CA\u4F7F\u7528\u8BF4\u660E\uFF0C\u5305\u62EC\u914D\u7F6E\u3001\u6A21\u578B\u3001\u6280\u80FD\u3001\u5DE5\u5177\u3001\u4F1A\u8BDD\u3001\u4EFB\u52A1\u3001MCP\u3001\u670D\u52A1\u3001\u7F13\u5B58\u7B49\u5B50\u547D\u4EE4\u7684\u8BE6\u7EC6\u7528\u6CD5",
|
|
25741
|
+
schema: external_exports.object({})
|
|
25742
|
+
}
|
|
25743
|
+
);
|
|
25744
|
+
var fishInfoTools = [getFishCodePathTool, getFishReadmeTool, getFishHelpTool];
|
|
25745
|
+
|
|
25566
25746
|
// src/agent/tools/index.ts
|
|
25567
25747
|
var builtinTools = [
|
|
25568
25748
|
taskTool,
|
|
@@ -25577,23 +25757,24 @@ var builtinTools = [
|
|
|
25577
25757
|
webFetchTool,
|
|
25578
25758
|
...packageTools,
|
|
25579
25759
|
...semanticMemoryTools,
|
|
25580
|
-
...learnTools
|
|
25760
|
+
...learnTools,
|
|
25761
|
+
...fishInfoTools
|
|
25581
25762
|
];
|
|
25582
25763
|
async function getTools(excludeTools, excludeMCP) {
|
|
25583
25764
|
return [...builtinTools, ...await scanUserTools(excludeTools), ...await scanUserMcp(excludeMCP)];
|
|
25584
25765
|
}
|
|
25585
25766
|
|
|
25586
25767
|
// src/agent/skills/index.ts
|
|
25587
|
-
var
|
|
25768
|
+
var import_path17 = __toESM(require("path"));
|
|
25588
25769
|
function getSkills() {
|
|
25589
|
-
return [...getRegisteredSkills(),
|
|
25770
|
+
return [...getRegisteredSkills(), import_path17.default.join(__dirname, "./view-learn-cache.md")];
|
|
25590
25771
|
}
|
|
25591
25772
|
|
|
25592
25773
|
// src/agent/AIAgent/index.ts
|
|
25593
25774
|
var import_os4 = __toESM(require("os"));
|
|
25594
25775
|
|
|
25595
25776
|
// src/agent/AIAgent/SubAgents/SubAIAgent.ts
|
|
25596
|
-
var
|
|
25777
|
+
var import_langchain18 = require("langchain");
|
|
25597
25778
|
var import_deepagents = require("deepagents");
|
|
25598
25779
|
var import_eventemitter_super = require("eventemitter-super");
|
|
25599
25780
|
var import_os3 = __toESM(require("os"));
|
|
@@ -25666,19 +25847,19 @@ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitte
|
|
|
25666
25847
|
agentRulesPath: this.agentRulesPath,
|
|
25667
25848
|
excludeSkills: this.excludeSkills
|
|
25668
25849
|
}) : subSystemPrompt(this.workspace, import_os3.default.platform(), this.skills, this.excludeSkills);
|
|
25669
|
-
const agent = (0,
|
|
25850
|
+
const agent = (0, import_langchain18.createAgent)({
|
|
25670
25851
|
model,
|
|
25671
25852
|
checkpointer,
|
|
25672
25853
|
tools: this.tools,
|
|
25673
25854
|
contextSchema,
|
|
25674
25855
|
middleware: [
|
|
25675
25856
|
createAgentEventMiddleware(this),
|
|
25676
|
-
(0,
|
|
25857
|
+
(0, import_langchain18.summarizationMiddleware)({
|
|
25677
25858
|
model,
|
|
25678
25859
|
trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
|
|
25679
25860
|
keep: { messages: 50 }
|
|
25680
25861
|
}),
|
|
25681
|
-
(0,
|
|
25862
|
+
(0, import_langchain18.humanInTheLoopMiddleware)({
|
|
25682
25863
|
interruptOn: {
|
|
25683
25864
|
install_package: {
|
|
25684
25865
|
allowedDecisions: ["approve", "reject"]
|
|
@@ -25686,7 +25867,7 @@ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitte
|
|
|
25686
25867
|
readEmailTool: false
|
|
25687
25868
|
}
|
|
25688
25869
|
}),
|
|
25689
|
-
(0,
|
|
25870
|
+
(0, import_langchain18.todoListMiddleware)(),
|
|
25690
25871
|
(0, import_deepagents.createPatchToolCallsMiddleware)()
|
|
25691
25872
|
],
|
|
25692
25873
|
systemPrompt
|
|
@@ -25696,7 +25877,7 @@ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitte
|
|
|
25696
25877
|
this.initEvents();
|
|
25697
25878
|
}
|
|
25698
25879
|
async execute(input) {
|
|
25699
|
-
const humanMessage = new
|
|
25880
|
+
const humanMessage = new import_langchain18.HumanMessage(input);
|
|
25700
25881
|
this.messages.push(humanMessage);
|
|
25701
25882
|
const stream = await this.agent.stream(
|
|
25702
25883
|
{ messages: this.messages },
|
|
@@ -25769,8 +25950,8 @@ var SubAIAgent = class _SubAIAgent extends import_eventemitter_super.EventEmitte
|
|
|
25769
25950
|
this.on("USE_TOOL_BEFORE" /* USE_TOOL_BEFORE */, (_toolId, funcName, _funcArgs) => {
|
|
25770
25951
|
log(`[Tool Call] ${funcName}`, "#c2a654");
|
|
25771
25952
|
});
|
|
25772
|
-
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent) => {
|
|
25773
|
-
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
|
|
25953
|
+
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
|
|
25954
|
+
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent.length > 50 ? _toolContent.slice(0, 50) + "..." : _toolContent}`);
|
|
25774
25955
|
});
|
|
25775
25956
|
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
|
|
25776
25957
|
logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
|
|
@@ -25849,19 +26030,19 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
|
|
|
25849
26030
|
agentId: external_exports.string().optional(),
|
|
25850
26031
|
curAgent: external_exports.object().optional()
|
|
25851
26032
|
});
|
|
25852
|
-
const agent = (0,
|
|
26033
|
+
const agent = (0, import_langchain19.createAgent)({
|
|
25853
26034
|
model,
|
|
25854
26035
|
checkpointer,
|
|
25855
26036
|
tools: this.tools,
|
|
25856
26037
|
contextSchema,
|
|
25857
26038
|
middleware: [
|
|
25858
26039
|
createAgentEventMiddleware(this),
|
|
25859
|
-
(0,
|
|
26040
|
+
(0, import_langchain19.summarizationMiddleware)({
|
|
25860
26041
|
model,
|
|
25861
26042
|
trigger: { tokens: this.opt.modelOpt.maxContextLength || 1e5 },
|
|
25862
26043
|
keep: { messages: 50 }
|
|
25863
26044
|
}),
|
|
25864
|
-
(0,
|
|
26045
|
+
(0, import_langchain19.humanInTheLoopMiddleware)({
|
|
25865
26046
|
interruptOn: {
|
|
25866
26047
|
install_package: {
|
|
25867
26048
|
allowedDecisions: ["approve", "reject"]
|
|
@@ -25869,7 +26050,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
|
|
|
25869
26050
|
readEmailTool: false
|
|
25870
26051
|
}
|
|
25871
26052
|
}),
|
|
25872
|
-
(0,
|
|
26053
|
+
(0, import_langchain19.todoListMiddleware)(),
|
|
25873
26054
|
(0, import_deepagents2.createPatchToolCallsMiddleware)()
|
|
25874
26055
|
],
|
|
25875
26056
|
systemPrompt: getSystemPrompt({
|
|
@@ -25888,7 +26069,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
|
|
|
25888
26069
|
this.initEvents();
|
|
25889
26070
|
}
|
|
25890
26071
|
async execute(input) {
|
|
25891
|
-
const humanMessage = new
|
|
26072
|
+
const humanMessage = new import_langchain19.HumanMessage(input);
|
|
25892
26073
|
this.messages.push(humanMessage);
|
|
25893
26074
|
const stream = await this.agent.stream(
|
|
25894
26075
|
{ messages: this.messages },
|
|
@@ -25965,7 +26146,7 @@ var AIAgent = class extends import_eventemitter_super2.EventEmitterSuper {
|
|
|
25965
26146
|
log(`[Tool Call] ${funcName}`, "#c2a654");
|
|
25966
26147
|
});
|
|
25967
26148
|
this.on("USE_TOOL_RETURN" /* USE_TOOL_RETURN */, (_toolId, _funcName, _toolContent = "") => {
|
|
25968
|
-
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent
|
|
26149
|
+
logInfo(`[Tool Return] ${_funcName} returned: ${_toolContent}`);
|
|
25969
26150
|
});
|
|
25970
26151
|
this.on("USE_TOOL_ERROR" /* USE_TOOL_ERROR */, (_toolId, _funcName, _error) => {
|
|
25971
26152
|
logError(`Error in tool ${_funcName}: ${_error instanceof Error ? _error.message : String(_error)}`);
|
|
@@ -26073,12 +26254,12 @@ var AgentRoomClient = class {
|
|
|
26073
26254
|
};
|
|
26074
26255
|
|
|
26075
26256
|
// src/cli/cli-core/serve.ts
|
|
26076
|
-
var
|
|
26257
|
+
var import_path18 = __toESM(require("path"));
|
|
26077
26258
|
var import_pm2 = __toESM(require("pm2"));
|
|
26078
26259
|
var PM2_APP_NAME = "deepfish-ai-server";
|
|
26079
26260
|
function getPm2Config() {
|
|
26080
26261
|
const port = getServePort();
|
|
26081
|
-
const serverScript =
|
|
26262
|
+
const serverScript = import_path18.default.join(getCodePath(), "dist/serve/pm2-server");
|
|
26082
26263
|
return {
|
|
26083
26264
|
name: PM2_APP_NAME,
|
|
26084
26265
|
script: serverScript,
|
|
@@ -26090,8 +26271,8 @@ function getPm2Config() {
|
|
|
26090
26271
|
autorestart: true,
|
|
26091
26272
|
watch: false,
|
|
26092
26273
|
max_memory_restart: "1G",
|
|
26093
|
-
error_file:
|
|
26094
|
-
out_file:
|
|
26274
|
+
error_file: import_path18.default.join(getCodePath(), "logs", "pm2-error.log"),
|
|
26275
|
+
out_file: import_path18.default.join(getCodePath(), "logs", "pm2-out.log"),
|
|
26095
26276
|
log_date_format: "YYYY-MM-DD HH:mm:ss Z"
|
|
26096
26277
|
};
|
|
26097
26278
|
}
|
|
@@ -26323,20 +26504,20 @@ function removeSessionById(agentId) {
|
|
|
26323
26504
|
return;
|
|
26324
26505
|
}
|
|
26325
26506
|
const sessionDir = getSessionPath(agentId);
|
|
26326
|
-
|
|
26507
|
+
import_fs_extra19.default.removeSync(sessionDir);
|
|
26327
26508
|
const sessionsPath = getSessionsPath();
|
|
26328
|
-
const sessionsFilePath =
|
|
26329
|
-
if (!
|
|
26509
|
+
const sessionsFilePath = import_path19.default.join(sessionsPath, "sessions.json");
|
|
26510
|
+
if (!import_fs_extra19.default.pathExistsSync(sessionsFilePath)) {
|
|
26330
26511
|
logSuccess("Current session history cleared");
|
|
26331
26512
|
return;
|
|
26332
26513
|
}
|
|
26333
|
-
const content =
|
|
26514
|
+
const content = import_fs_extra19.default.readFileSync(sessionsFilePath, "utf-8");
|
|
26334
26515
|
const parsed = JSON.parse(content);
|
|
26335
26516
|
const sessions = Array.isArray(parsed) ? parsed : [];
|
|
26336
26517
|
const existingSessionIndex = sessions.findIndex((s) => s.id === agentId);
|
|
26337
26518
|
if (existingSessionIndex !== -1) {
|
|
26338
26519
|
sessions.splice(existingSessionIndex, 1);
|
|
26339
|
-
|
|
26520
|
+
import_fs_extra19.default.writeFileSync(sessionsFilePath, JSON.stringify(sessions, null, 2), "utf-8");
|
|
26340
26521
|
}
|
|
26341
26522
|
logSuccess("Current session history cleared");
|
|
26342
26523
|
}
|
|
@@ -26352,15 +26533,15 @@ function openSessionDir() {
|
|
|
26352
26533
|
}
|
|
26353
26534
|
function initSession() {
|
|
26354
26535
|
const sessionsPath = getSessionsPath();
|
|
26355
|
-
const sessionsFilePath =
|
|
26536
|
+
const sessionsFilePath = import_path19.default.join(sessionsPath, "sessions.json");
|
|
26356
26537
|
let sessions = [];
|
|
26357
|
-
if (
|
|
26358
|
-
const content =
|
|
26538
|
+
if (import_fs_extra19.default.pathExistsSync(sessionsFilePath)) {
|
|
26539
|
+
const content = import_fs_extra19.default.readFileSync(sessionsFilePath, "utf-8");
|
|
26359
26540
|
const parsed = JSON.parse(content);
|
|
26360
26541
|
sessions = Array.isArray(parsed) ? parsed : [];
|
|
26361
26542
|
} else {
|
|
26362
|
-
|
|
26363
|
-
|
|
26543
|
+
import_fs_extra19.default.ensureDirSync(sessionsPath);
|
|
26544
|
+
import_fs_extra19.default.writeFileSync(sessionsFilePath, "[]", "utf-8");
|
|
26364
26545
|
}
|
|
26365
26546
|
const workspace = getWorkspacePath();
|
|
26366
26547
|
const existingSession = sessions.find((s) => s.workspace === workspace);
|
|
@@ -26371,23 +26552,23 @@ function initSession() {
|
|
|
26371
26552
|
const agentId = (0, import_crypto5.randomUUID)();
|
|
26372
26553
|
const newSession = {
|
|
26373
26554
|
id: agentId,
|
|
26374
|
-
name:
|
|
26555
|
+
name: import_path19.default.basename(workspace),
|
|
26375
26556
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26376
26557
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26377
26558
|
workspace
|
|
26378
26559
|
};
|
|
26379
26560
|
sessions.push(newSession);
|
|
26380
|
-
|
|
26561
|
+
import_fs_extra19.default.writeFileSync(sessionsFilePath, JSON.stringify(sessions, null, 2), "utf-8");
|
|
26381
26562
|
initSessionDir(newSession.id);
|
|
26382
26563
|
return newSession;
|
|
26383
26564
|
}
|
|
26384
26565
|
function initSessionDir(agentId) {
|
|
26385
26566
|
const sessionDir = getSessionPath(agentId);
|
|
26386
|
-
|
|
26567
|
+
import_fs_extra19.default.ensureDirSync(sessionDir);
|
|
26387
26568
|
const mainSessionPath = `${sessionDir}/main-session/`;
|
|
26388
26569
|
const mainMsgQueuePath = `${sessionDir}/main-msg-queue.json`;
|
|
26389
|
-
|
|
26390
|
-
|
|
26570
|
+
import_fs_extra19.default.ensureDirSync(mainSessionPath);
|
|
26571
|
+
import_fs_extra19.default.ensureFileSync(mainMsgQueuePath);
|
|
26391
26572
|
}
|
|
26392
26573
|
function _getCurrentAIConfig(config2) {
|
|
26393
26574
|
const currentModelName = config2.currentModel;
|
|
@@ -26402,11 +26583,11 @@ function _getCurrentAIConfig(config2) {
|
|
|
26402
26583
|
}
|
|
26403
26584
|
function getAgentId() {
|
|
26404
26585
|
const sessionsPath = getSessionsPath();
|
|
26405
|
-
const sessionsFilePath =
|
|
26406
|
-
if (!
|
|
26586
|
+
const sessionsFilePath = import_path19.default.join(sessionsPath, "sessions.json");
|
|
26587
|
+
if (!import_fs_extra19.default.pathExistsSync(sessionsFilePath)) {
|
|
26407
26588
|
return;
|
|
26408
26589
|
}
|
|
26409
|
-
const content =
|
|
26590
|
+
const content = import_fs_extra19.default.readFileSync(sessionsFilePath, "utf-8");
|
|
26410
26591
|
const parsed = JSON.parse(content);
|
|
26411
26592
|
const sessions = Array.isArray(parsed) ? parsed : [];
|
|
26412
26593
|
const workspace = getWorkspacePath();
|
|
@@ -26434,8 +26615,8 @@ function handleSkillsLs() {
|
|
|
26434
26615
|
async function handleSkillsAdd(name) {
|
|
26435
26616
|
logInfo(`Adding skill: ${name}`);
|
|
26436
26617
|
const workspace = getWorkspacePath();
|
|
26437
|
-
const skillDir =
|
|
26438
|
-
if (!
|
|
26618
|
+
const skillDir = import_path20.default.join(workspace, name);
|
|
26619
|
+
if (!import_fs_extra20.default.existsSync(skillDir)) {
|
|
26439
26620
|
logError(`Skill directory does not exist: ${skillDir}`);
|
|
26440
26621
|
return;
|
|
26441
26622
|
}
|
|
@@ -26451,16 +26632,16 @@ async function handleSkillsAdd(name) {
|
|
|
26451
26632
|
}
|
|
26452
26633
|
]);
|
|
26453
26634
|
const homePath = getHomePath();
|
|
26454
|
-
const globalSkillDir =
|
|
26455
|
-
const localSkillDir =
|
|
26635
|
+
const globalSkillDir = import_path20.default.join(homePath, "skills");
|
|
26636
|
+
const localSkillDir = import_path20.default.join(workspace, ".deepfish-ai", "skills");
|
|
26456
26637
|
if (scope === "local") {
|
|
26457
|
-
|
|
26638
|
+
import_fs_extra20.default.ensureDirSync(localSkillDir);
|
|
26458
26639
|
} else {
|
|
26459
|
-
|
|
26640
|
+
import_fs_extra20.default.ensureDirSync(globalSkillDir);
|
|
26460
26641
|
}
|
|
26461
26642
|
const targetDir = scope === "local" ? localSkillDir : globalSkillDir;
|
|
26462
|
-
const targetPath =
|
|
26463
|
-
if (
|
|
26643
|
+
const targetPath = import_path20.default.join(targetDir, name);
|
|
26644
|
+
if (import_fs_extra20.default.existsSync(targetPath)) {
|
|
26464
26645
|
const { overwrite } = await import_inquirer3.default.prompt([
|
|
26465
26646
|
{
|
|
26466
26647
|
type: "confirm",
|
|
@@ -26473,9 +26654,9 @@ async function handleSkillsAdd(name) {
|
|
|
26473
26654
|
logWarning("Add cancelled");
|
|
26474
26655
|
return;
|
|
26475
26656
|
}
|
|
26476
|
-
|
|
26657
|
+
import_fs_extra20.default.removeSync(targetPath);
|
|
26477
26658
|
}
|
|
26478
|
-
|
|
26659
|
+
import_fs_extra20.default.moveSync(skillDir, targetPath, { overwrite: true });
|
|
26479
26660
|
logSuccess(`Skill ${scope === "local" ? "locally" : "globally"} added: ${targetPath}`);
|
|
26480
26661
|
_updateRegister(targetDir);
|
|
26481
26662
|
}
|
|
@@ -26487,13 +26668,13 @@ function handleSkillsDel(index) {
|
|
|
26487
26668
|
return;
|
|
26488
26669
|
}
|
|
26489
26670
|
const skill = skills[skillIndex];
|
|
26490
|
-
|
|
26671
|
+
import_fs_extra20.default.removeSync(skill.skillPath);
|
|
26491
26672
|
const skillDir = skill.skillDir;
|
|
26492
|
-
const registerPath =
|
|
26493
|
-
if (
|
|
26494
|
-
let register =
|
|
26673
|
+
const registerPath = import_path20.default.join(skillDir, "skills", "register.json");
|
|
26674
|
+
if (import_fs_extra20.default.existsSync(registerPath)) {
|
|
26675
|
+
let register = import_fs_extra20.default.readJSONSync(registerPath);
|
|
26495
26676
|
register = register.filter((item) => item.skillPath !== skill.skillPath);
|
|
26496
|
-
|
|
26677
|
+
import_fs_extra20.default.writeJSONSync(registerPath, register, { spaces: 2 });
|
|
26497
26678
|
}
|
|
26498
26679
|
logSuccess(`Skill deleted: ${skill.name}`);
|
|
26499
26680
|
}
|
|
@@ -26507,8 +26688,8 @@ function handleSkillsEnable(index) {
|
|
|
26507
26688
|
const skill = skills[skillIndex];
|
|
26508
26689
|
skill.isEnabled = true;
|
|
26509
26690
|
const skillDir = skill.skillDir;
|
|
26510
|
-
const registerPath =
|
|
26511
|
-
|
|
26691
|
+
const registerPath = import_path20.default.join(skillDir, "skills", "register.json");
|
|
26692
|
+
import_fs_extra20.default.writeJSONSync(
|
|
26512
26693
|
registerPath,
|
|
26513
26694
|
skills.filter((item) => item.skillDir === skillDir),
|
|
26514
26695
|
{ spaces: 2 }
|
|
@@ -26525,8 +26706,8 @@ function handleSkillsDisable(index) {
|
|
|
26525
26706
|
const skill = skills[skillIndex];
|
|
26526
26707
|
skill.isEnabled = false;
|
|
26527
26708
|
const skillDir = skill.skillDir;
|
|
26528
|
-
const registerPath =
|
|
26529
|
-
|
|
26709
|
+
const registerPath = import_path20.default.join(skillDir, "skills", "register.json");
|
|
26710
|
+
import_fs_extra20.default.writeJSONSync(
|
|
26530
26711
|
registerPath,
|
|
26531
26712
|
skills.filter((item) => item.skillDir === skillDir),
|
|
26532
26713
|
{ spaces: 2 }
|
|
@@ -26536,7 +26717,7 @@ function handleSkillsDisable(index) {
|
|
|
26536
26717
|
function handleSkillsDir() {
|
|
26537
26718
|
logInfo("Opening skills directory");
|
|
26538
26719
|
const homePath = getHomePath();
|
|
26539
|
-
const globalSkillDir =
|
|
26720
|
+
const globalSkillDir = import_path20.default.join(homePath, "skills");
|
|
26540
26721
|
openDirectory(globalSkillDir);
|
|
26541
26722
|
}
|
|
26542
26723
|
async function handleSkillsGenerate(target) {
|
|
@@ -26560,7 +26741,7 @@ async function handleSkillsGenerate(target) {
|
|
|
26560
26741
|
logError("Failed to start service, please check config or port availability");
|
|
26561
26742
|
return;
|
|
26562
26743
|
}
|
|
26563
|
-
const generateSkillPath =
|
|
26744
|
+
const generateSkillPath = import_path20.default.join(__dirname, "./generate-skill.md");
|
|
26564
26745
|
const agent = await initAgent(config2, [generateSkillPath]);
|
|
26565
26746
|
const prompt = `\u8BF7\u6839\u636E\u4EE5\u4E0B\u9700\u6C42\u751F\u6210\u4E00\u4E2ASkill\u6A21\u5757\uFF1A${target}
|
|
26566
26747
|
|
|
@@ -26578,13 +26759,13 @@ async function handleSkillsGenerate(target) {
|
|
|
26578
26759
|
}
|
|
26579
26760
|
function _scanSkills(skillsDir) {
|
|
26580
26761
|
const skills = [];
|
|
26581
|
-
if (
|
|
26582
|
-
const files =
|
|
26762
|
+
if (import_fs_extra20.default.existsSync(skillsDir)) {
|
|
26763
|
+
const files = import_fs_extra20.default.readdirSync(skillsDir);
|
|
26583
26764
|
files.forEach((file2) => {
|
|
26584
|
-
const filePath =
|
|
26585
|
-
if (
|
|
26586
|
-
const skillMdPath =
|
|
26587
|
-
if (
|
|
26765
|
+
const filePath = import_path20.default.resolve(skillsDir, file2);
|
|
26766
|
+
if (import_fs_extra20.default.statSync(filePath).isDirectory()) {
|
|
26767
|
+
const skillMdPath = import_path20.default.resolve(filePath, "SKILL.md");
|
|
26768
|
+
if (import_fs_extra20.default.existsSync(skillMdPath)) {
|
|
26588
26769
|
skills.push(filePath);
|
|
26589
26770
|
}
|
|
26590
26771
|
}
|
|
@@ -26593,17 +26774,17 @@ function _scanSkills(skillsDir) {
|
|
|
26593
26774
|
return skills;
|
|
26594
26775
|
}
|
|
26595
26776
|
function _updateRegister(skillsDir) {
|
|
26596
|
-
const registerPath =
|
|
26597
|
-
if (
|
|
26598
|
-
|
|
26599
|
-
} else if (!
|
|
26777
|
+
const registerPath = import_path20.default.resolve(skillsDir, "register.json");
|
|
26778
|
+
if (import_fs_extra20.default.existsSync(skillsDir) && !import_fs_extra20.default.existsSync(registerPath)) {
|
|
26779
|
+
import_fs_extra20.default.writeJSONSync(registerPath, [], { spaces: 2 });
|
|
26780
|
+
} else if (!import_fs_extra20.default.existsSync(skillsDir)) {
|
|
26600
26781
|
return;
|
|
26601
26782
|
}
|
|
26602
26783
|
const skills = _scanSkills(skillsDir);
|
|
26603
|
-
let register =
|
|
26784
|
+
let register = import_fs_extra20.default.readJSONSync(registerPath);
|
|
26604
26785
|
const newRegister = [];
|
|
26605
26786
|
skills.forEach((skillPath) => {
|
|
26606
|
-
const skillName =
|
|
26787
|
+
const skillName = import_path20.default.basename(skillPath);
|
|
26607
26788
|
const existItem = register.find((item) => item.skillPath === skillPath);
|
|
26608
26789
|
if (!existItem) {
|
|
26609
26790
|
newRegister.push({
|
|
@@ -26616,16 +26797,16 @@ function _updateRegister(skillsDir) {
|
|
|
26616
26797
|
});
|
|
26617
26798
|
register = register.filter((item) => skills.includes(item.skillPath));
|
|
26618
26799
|
register.push(...newRegister);
|
|
26619
|
-
|
|
26800
|
+
import_fs_extra20.default.writeJSONSync(registerPath, register, { spaces: 2 });
|
|
26620
26801
|
}
|
|
26621
26802
|
function getRegisteredSkills() {
|
|
26622
26803
|
const scanPaths = getScanDirPaths();
|
|
26623
26804
|
const skills = [];
|
|
26624
26805
|
scanPaths.forEach((scanPath) => {
|
|
26625
26806
|
_updateRegister(scanPath);
|
|
26626
|
-
const registerPath =
|
|
26627
|
-
if (
|
|
26628
|
-
const register =
|
|
26807
|
+
const registerPath = import_path20.default.join(scanPath, "skills", "register.json");
|
|
26808
|
+
if (import_fs_extra20.default.existsSync(registerPath)) {
|
|
26809
|
+
const register = import_fs_extra20.default.readJSONSync(registerPath);
|
|
26629
26810
|
register.forEach((item) => {
|
|
26630
26811
|
if (item.isEnabled) {
|
|
26631
26812
|
skills.push(item.skillPath);
|
|
@@ -26637,10 +26818,10 @@ function getRegisteredSkills() {
|
|
|
26637
26818
|
}
|
|
26638
26819
|
function _getSkillList(skillsDir) {
|
|
26639
26820
|
let allSkills = [];
|
|
26640
|
-
const registerPath =
|
|
26641
|
-
if (
|
|
26821
|
+
const registerPath = import_path20.default.join(skillsDir, "skills", "register.json");
|
|
26822
|
+
if (import_fs_extra20.default.existsSync(registerPath)) {
|
|
26642
26823
|
_updateRegister(skillsDir);
|
|
26643
|
-
const register =
|
|
26824
|
+
const register = import_fs_extra20.default.readJSONSync(registerPath);
|
|
26644
26825
|
allSkills = allSkills.concat(register);
|
|
26645
26826
|
}
|
|
26646
26827
|
return allSkills;
|
|
@@ -26673,8 +26854,38 @@ function registerSkillsCommands(program) {
|
|
|
26673
26854
|
|
|
26674
26855
|
// src/cli/cli-core/tools.ts
|
|
26675
26856
|
var import_inquirer4 = __toESM(require("inquirer"));
|
|
26676
|
-
var
|
|
26677
|
-
var
|
|
26857
|
+
var import_fs_extra21 = __toESM(require("fs-extra"));
|
|
26858
|
+
var import_path21 = __toESM(require("path"));
|
|
26859
|
+
function handleToolsLs() {
|
|
26860
|
+
const toolNames = getUserToolList().map((tool17) => {
|
|
26861
|
+
return tool17.name;
|
|
26862
|
+
});
|
|
26863
|
+
logInfo("=".repeat(50));
|
|
26864
|
+
if (toolNames.length === 0) {
|
|
26865
|
+
logInfo("No tools registered yet");
|
|
26866
|
+
} else {
|
|
26867
|
+
toolNames.forEach((name, index) => {
|
|
26868
|
+
logInfo(`[${index}] ${name}`);
|
|
26869
|
+
});
|
|
26870
|
+
}
|
|
26871
|
+
logInfo("=".repeat(50));
|
|
26872
|
+
}
|
|
26873
|
+
function handleToolsDel(index) {
|
|
26874
|
+
const toolList = getUserToolList();
|
|
26875
|
+
const toolIndex = parseInt(index, 10);
|
|
26876
|
+
if (isNaN(toolIndex) || toolIndex < 0 || toolIndex >= toolList.length) {
|
|
26877
|
+
logError("Invalid tool index");
|
|
26878
|
+
return;
|
|
26879
|
+
}
|
|
26880
|
+
const tool17 = toolList[toolIndex];
|
|
26881
|
+
if (tool17.dir) {
|
|
26882
|
+
import_fs_extra21.default.removeSync(tool17.dir);
|
|
26883
|
+
logSuccess(`Tool directory deleted: ${tool17.dir}`);
|
|
26884
|
+
} else {
|
|
26885
|
+
import_fs_extra21.default.removeSync(tool17.path);
|
|
26886
|
+
logSuccess(`Tool file deleted: ${tool17.path}`);
|
|
26887
|
+
}
|
|
26888
|
+
}
|
|
26678
26889
|
function handleToolsDir() {
|
|
26679
26890
|
const toolsPath = getToolsPath();
|
|
26680
26891
|
openDirectory(toolsPath);
|
|
@@ -26683,8 +26894,8 @@ function handleToolsDir() {
|
|
|
26683
26894
|
async function handleToolsAdd(name) {
|
|
26684
26895
|
logInfo(`Adding tool: ${name}`);
|
|
26685
26896
|
const workspace = getWorkspacePath();
|
|
26686
|
-
const toolDir =
|
|
26687
|
-
if (!
|
|
26897
|
+
const toolDir = import_path21.default.join(workspace, name);
|
|
26898
|
+
if (!import_fs_extra21.default.existsSync(toolDir)) {
|
|
26688
26899
|
logError(`Tool directory does not exist: ${toolDir}`);
|
|
26689
26900
|
return;
|
|
26690
26901
|
}
|
|
@@ -26700,12 +26911,12 @@ async function handleToolsAdd(name) {
|
|
|
26700
26911
|
}
|
|
26701
26912
|
]);
|
|
26702
26913
|
const homePath = getHomePath();
|
|
26703
|
-
const globalToolDir =
|
|
26704
|
-
const localToolDir =
|
|
26914
|
+
const globalToolDir = import_path21.default.join(homePath, "tools");
|
|
26915
|
+
const localToolDir = import_path21.default.join(workspace, ".deepfish-ai", "tools");
|
|
26705
26916
|
const targetDir = scope === "local" ? localToolDir : globalToolDir;
|
|
26706
|
-
const targetPath =
|
|
26707
|
-
|
|
26708
|
-
if (
|
|
26917
|
+
const targetPath = import_path21.default.join(targetDir, name);
|
|
26918
|
+
import_fs_extra21.default.ensureDirSync(targetDir);
|
|
26919
|
+
if (import_fs_extra21.default.existsSync(targetPath)) {
|
|
26709
26920
|
const { overwrite } = await import_inquirer4.default.prompt([
|
|
26710
26921
|
{
|
|
26711
26922
|
type: "confirm",
|
|
@@ -26718,9 +26929,9 @@ async function handleToolsAdd(name) {
|
|
|
26718
26929
|
logWarning("Add cancelled");
|
|
26719
26930
|
return;
|
|
26720
26931
|
}
|
|
26721
|
-
|
|
26932
|
+
import_fs_extra21.default.removeSync(targetPath);
|
|
26722
26933
|
}
|
|
26723
|
-
|
|
26934
|
+
import_fs_extra21.default.moveSync(toolDir, targetPath, { overwrite: true });
|
|
26724
26935
|
logSuccess(`Tool ${scope === "local" ? "locally" : "globally"} added: ${targetPath}`);
|
|
26725
26936
|
}
|
|
26726
26937
|
async function handleToolsGenerate(target) {
|
|
@@ -26744,7 +26955,7 @@ async function handleToolsGenerate(target) {
|
|
|
26744
26955
|
logError("Failed to start service, please check config or port availability");
|
|
26745
26956
|
return;
|
|
26746
26957
|
}
|
|
26747
|
-
const generateSkillPath =
|
|
26958
|
+
const generateSkillPath = import_path21.default.join(__dirname, "./generate-tool.md");
|
|
26748
26959
|
const agent = await initAgent(config2, [generateSkillPath]);
|
|
26749
26960
|
const prompt = `Please use the "generate-tool" SKILL to generate a tool module according to the following requirements: ${target}
|
|
26750
26961
|
|
|
@@ -26763,8 +26974,10 @@ async function handleToolsGenerate(target) {
|
|
|
26763
26974
|
// src/cli/cli-tools.ts
|
|
26764
26975
|
function registerToolsCommands(program) {
|
|
26765
26976
|
const tools = program.command("tools");
|
|
26977
|
+
tools.command("ls").description("\u5217\u51FA\u6240\u6709\u5DE5\u5177").action(handleToolsLs);
|
|
26766
26978
|
tools.command("dir").description("\u6253\u5F00\u5DE5\u5177\u76EE\u5F55").action(handleToolsDir);
|
|
26767
26979
|
tools.command("add <name>").description("\u6DFB\u52A0\u672C\u5730\u5DE5\u5177\u76EE\u5F55").action(handleToolsAdd);
|
|
26980
|
+
tools.command("del <index>").description("\u6309\u7D22\u5F15\u5220\u9664\u5DE5\u5177").action(handleToolsDel);
|
|
26768
26981
|
tools.command("generate <target>").description("\u751F\u6210\u5DE5\u5177").action(handleToolsGenerate);
|
|
26769
26982
|
}
|
|
26770
26983
|
|
|
@@ -26870,10 +27083,10 @@ function handleTaskClear() {
|
|
|
26870
27083
|
|
|
26871
27084
|
// src/cli/cli-task.ts
|
|
26872
27085
|
function registerTaskCommands(program) {
|
|
26873
|
-
const task = program.command("
|
|
27086
|
+
const task = program.command("tasks");
|
|
26874
27087
|
task.command("ls").description("\u5217\u51FA\u6240\u6709\u4EFB\u52A1").action(handleTaskLs);
|
|
26875
27088
|
task.command("add <task>").description("\u6DFB\u52A0\u4EFB\u52A1").action(handleTaskAdd);
|
|
26876
|
-
task.command("del <index>").description("\u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u4EFB\
|
|
27089
|
+
task.command("del <index>").description("\u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u4EFB\u52A1").action(handleTaskDel);
|
|
26877
27090
|
task.command("clear").description("\u6E05\u9664\u6240\u6709\u4EFB\u52A1").action(handleTaskClear);
|
|
26878
27091
|
}
|
|
26879
27092
|
|
|
@@ -26890,7 +27103,7 @@ function registerMcpCommands(program) {
|
|
|
26890
27103
|
}
|
|
26891
27104
|
|
|
26892
27105
|
// src/cli/cli-core/input.ts
|
|
26893
|
-
var
|
|
27106
|
+
var import_fs_extra22 = __toESM(require("fs-extra"));
|
|
26894
27107
|
var readline = __toESM(require("readline"));
|
|
26895
27108
|
async function handleInput(args) {
|
|
26896
27109
|
const input = args.join(" ");
|
|
@@ -26900,7 +27113,7 @@ async function handleInput(args) {
|
|
|
26900
27113
|
}
|
|
26901
27114
|
try {
|
|
26902
27115
|
const configPath = getConfigPath();
|
|
26903
|
-
if (!
|
|
27116
|
+
if (!import_fs_extra22.default.pathExistsSync(configPath)) {
|
|
26904
27117
|
logError("Config file not found, please run init first");
|
|
26905
27118
|
return;
|
|
26906
27119
|
}
|
|
@@ -26937,7 +27150,7 @@ async function handleInput(args) {
|
|
|
26937
27150
|
async function multiInput() {
|
|
26938
27151
|
try {
|
|
26939
27152
|
const configPath = getConfigPath();
|
|
26940
|
-
if (!
|
|
27153
|
+
if (!import_fs_extra22.default.pathExistsSync(configPath)) {
|
|
26941
27154
|
logError("Config file not found, please run init first");
|
|
26942
27155
|
return;
|
|
26943
27156
|
}
|
|
@@ -27007,7 +27220,7 @@ function registerInputCommand(program) {
|
|
|
27007
27220
|
}
|
|
27008
27221
|
|
|
27009
27222
|
// src/cli/cli-core/cache.ts
|
|
27010
|
-
var
|
|
27223
|
+
var import_path22 = __toESM(require("path"));
|
|
27011
27224
|
var userCache2 = new UserCache();
|
|
27012
27225
|
function resolveId(input) {
|
|
27013
27226
|
const index = Number(input);
|
|
@@ -27041,7 +27254,7 @@ function handleCacheList() {
|
|
|
27041
27254
|
function handleCacheEdit(input) {
|
|
27042
27255
|
const id = resolveId(input);
|
|
27043
27256
|
if (!id) return;
|
|
27044
|
-
const filePath =
|
|
27257
|
+
const filePath = import_path22.default.join(getUserStorePath(), `${id}.md`);
|
|
27045
27258
|
editFile(filePath);
|
|
27046
27259
|
}
|
|
27047
27260
|
function handleCacheDel(input) {
|
|
@@ -27073,71 +27286,6 @@ function registerCommonFlags(program) {
|
|
|
27073
27286
|
program.version(handleVersion(), "-v, --version", "Show version");
|
|
27074
27287
|
}
|
|
27075
27288
|
|
|
27076
|
-
// src/cli/cli-help.ts
|
|
27077
|
-
var import_commander = require("commander");
|
|
27078
|
-
function helpInformation() {
|
|
27079
|
-
return `Usage: ai [options] [command]
|
|
27080
|
-
|
|
27081
|
-
Commands:
|
|
27082
|
-
ai "xxx" \u76F4\u63A5\u5411 AI \u53D1\u8D77\u4E00\u6B21\u4EFB\u52A1\u6216\u5BF9\u8BDD
|
|
27083
|
-
|
|
27084
|
-
# Configuration commands
|
|
27085
|
-
ai config edit \u6253\u5F00\u5168\u5C40\u914D\u7F6E\u6587\u4EF6\u8FDB\u884C\u7F16\u8F91
|
|
27086
|
-
ai config view \u67E5\u770B\u5F53\u524D\u5168\u5C40\u914D\u7F6E\u5185\u5BB9
|
|
27087
|
-
ai config reset \u91CD\u7F6E\u5168\u5C40\u914D\u7F6E\u4E3A\u9ED8\u8BA4\u503C
|
|
27088
|
-
ai config dir \u6253\u5F00\u6216\u8F93\u51FA\u5168\u5C40\u914D\u7F6E\u76EE\u5F55
|
|
27089
|
-
|
|
27090
|
-
# Model commands
|
|
27091
|
-
ai models add \u6DFB\u52A0\u4E00\u4E2A\u65B0\u7684\u6A21\u578B\u914D\u7F6E
|
|
27092
|
-
ai models ls \u67E5\u770B\u5DF2\u914D\u7F6E\u7684\u6A21\u578B\u5217\u8868
|
|
27093
|
-
ai models use <name> \u5207\u6362\u5F53\u524D\u9ED8\u8BA4\u4F7F\u7528\u7684\u6A21\u578B
|
|
27094
|
-
ai models del <name> \u5220\u9664\u6307\u5B9A\u540D\u79F0\u7684\u6A21\u578B\u914D\u7F6E
|
|
27095
|
-
|
|
27096
|
-
# Skill commands
|
|
27097
|
-
ai skills ls \u67E5\u770B\u5DF2\u5B89\u88C5\u6216\u5DF2\u914D\u7F6E\u7684\u6280\u80FD\u5217\u8868
|
|
27098
|
-
ai skills add <name> \u6DFB\u52A0\u6307\u5B9A\u540D\u79F0\u7684\u6280\u80FD
|
|
27099
|
-
ai skills del <index> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u6280\u80FD
|
|
27100
|
-
ai skills enable <name|index> \u542F\u7528\u6307\u5B9A\u540D\u79F0\u6216\u5E8F\u53F7\u7684\u6280\u80FD
|
|
27101
|
-
ai skills disable <name|index> \u7981\u7528\u6307\u5B9A\u540D\u79F0\u6216\u5E8F\u53F7\u7684\u6280\u80FD
|
|
27102
|
-
ai skills dir \u6253\u5F00\u6216\u8F93\u51FA\u6280\u80FD\u76EE\u5F55
|
|
27103
|
-
ai skills generate xxx \u6839\u636E\u63CF\u8FF0\u751F\u6210\u4E00\u4E2A\u65B0\u7684\u6280\u80FD\u6A21\u677F
|
|
27104
|
-
|
|
27105
|
-
# Tools commands
|
|
27106
|
-
ai tools dir \u6253\u5F00\u6216\u8F93\u51FA\u7528\u6237\u81EA\u5B9A\u4E49\u5DE5\u5177\u76EE\u5F55
|
|
27107
|
-
ai tools generate xxx \u6839\u636E\u63CF\u8FF0\u751F\u6210\u4E00\u4E2A\u65B0\u7684\u5DE5\u5177\u6A21\u677F
|
|
27108
|
-
|
|
27109
|
-
# Session commands
|
|
27110
|
-
ai session clear \u6E05\u7A7A\u5F53\u524D\u4F1A\u8BDD\u8BB0\u5F55
|
|
27111
|
-
ai session dir \u6253\u5F00\u6216\u8F93\u51FA\u4F1A\u8BDD\u6570\u636E\u76EE\u5F55
|
|
27112
|
-
|
|
27113
|
-
# Task commands
|
|
27114
|
-
ai task ls \u67E5\u770B\u5F53\u524D\u4EFB\u52A1\u961F\u5217
|
|
27115
|
-
ai task add <task> \u5411\u4EFB\u52A1\u961F\u5217\u6DFB\u52A0\u4E00\u4E2A\u540E\u7EED\u4EFB\u52A1
|
|
27116
|
-
ai task del <index> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u7684\u4EFB\u52A1
|
|
27117
|
-
ai task clear \u6E05\u7A7A\u5F53\u524D\u4EFB\u52A1\u961F\u5217
|
|
27118
|
-
|
|
27119
|
-
# MCP commands
|
|
27120
|
-
ai mcp edit \u6253\u5F00 MCP \u914D\u7F6E\u6587\u4EF6\u8FDB\u884C\u7F16\u8F91
|
|
27121
|
-
|
|
27122
|
-
# Serve commands
|
|
27123
|
-
ai serve \u542F\u52A8\u670D\u52A1\u6216\u8FDB\u5165\u670D\u52A1\u7BA1\u7406\u5165\u53E3
|
|
27124
|
-
ai serve start \u542F\u52A8\u540E\u53F0\u670D\u52A1
|
|
27125
|
-
ai serve stop \u505C\u6B62\u540E\u53F0\u670D\u52A1
|
|
27126
|
-
ai serve restart \u91CD\u542F\u540E\u53F0\u670D\u52A1
|
|
27127
|
-
|
|
27128
|
-
# Cache commands
|
|
27129
|
-
ai cache ls \u67E5\u770B\u5DF2\u7F13\u5B58\u7684\u5B66\u4E60\u5185\u5BB9\u5217\u8868
|
|
27130
|
-
ai cache edit <index|id> \u7F16\u8F91\u6307\u5B9A\u5E8F\u53F7\u6216 ID \u7684\u7F13\u5B58\u5185\u5BB9
|
|
27131
|
-
ai cache del <index|id> \u5220\u9664\u6307\u5B9A\u5E8F\u53F7\u6216 ID \u7684\u7F13\u5B58\u5185\u5BB9
|
|
27132
|
-
`;
|
|
27133
|
-
}
|
|
27134
|
-
function registerHelpCommand(program) {
|
|
27135
|
-
program.helpInformation = helpInformation;
|
|
27136
|
-
program.command("help").description("Displaying help information").action(() => {
|
|
27137
|
-
console.log(helpInformation());
|
|
27138
|
-
});
|
|
27139
|
-
}
|
|
27140
|
-
|
|
27141
27289
|
// src/cli/index.ts
|
|
27142
27290
|
function main() {
|
|
27143
27291
|
initConfig();
|