@amical/aiagent-sdk 0.1.8 → 0.1.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/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +56 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -5
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/nodeRuntime.d.mts +3 -3
- package/dist/runtime/nodeRuntime.d.ts +3 -3
- package/dist/runtime/nodeRuntime.js +84 -15
- package/dist/runtime/nodeRuntime.js.map +1 -1
- package/dist/runtime/nodeRuntime.mjs +83 -14
- package/dist/runtime/nodeRuntime.mjs.map +1 -1
- package/dist/runtime/webRuntime.d.mts +3 -2
- package/dist/runtime/webRuntime.d.ts +3 -2
- package/dist/runtime/webRuntime.js +75 -9
- package/dist/runtime/webRuntime.js.map +1 -1
- package/dist/runtime/webRuntime.mjs +75 -9
- package/dist/runtime/webRuntime.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ var ai = require('ai');
|
|
|
6
6
|
var openai = require('@ai-sdk/openai');
|
|
7
7
|
var difyAiProvider = require('dify-ai-provider');
|
|
8
8
|
var fs2 = require('fs/promises');
|
|
9
|
-
var
|
|
9
|
+
var path = require('path');
|
|
10
10
|
var os = require('os');
|
|
11
11
|
var child_process = require('child_process');
|
|
12
12
|
var util = require('util');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
|
|
36
36
|
var matter__default = /*#__PURE__*/_interopDefault(matter);
|
|
37
37
|
var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
|
|
38
|
-
var
|
|
38
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
39
39
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
40
40
|
|
|
41
41
|
// src/shared/tools.ts
|
|
@@ -582,7 +582,7 @@ var ClineAgent = class {
|
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
584
|
/**
|
|
585
|
-
* 获取当前 Agent 的系统提示词
|
|
585
|
+
* 获取当前 Agent 的系统提示词
|
|
586
586
|
* 如果 force 为 true,则强制重新获取系统提示词
|
|
587
587
|
*/
|
|
588
588
|
async getPrompt(force = false) {
|
|
@@ -857,15 +857,20 @@ STDERR: ${result.stderr}` });
|
|
|
857
857
|
const path3 = tool.params.path || this.runtime.env.cwd();
|
|
858
858
|
const regexStr = tool.params.regex;
|
|
859
859
|
const filePattern = tool.params.file_pattern;
|
|
860
|
-
if (regexStr &&
|
|
860
|
+
if (regexStr && path3) {
|
|
861
861
|
try {
|
|
862
|
-
|
|
862
|
+
let result;
|
|
863
|
+
if (typeof this.runtime.fs.searchFiles === "function") {
|
|
864
|
+
result = await this.runtime.fs.searchFiles(path3, regexStr, filePattern);
|
|
865
|
+
} else {
|
|
866
|
+
result = await this.searchFiles(path3, regexStr, filePattern);
|
|
867
|
+
}
|
|
863
868
|
toolResults.push({ tool, result: `${result}` });
|
|
864
869
|
} catch (e) {
|
|
865
870
|
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
866
871
|
}
|
|
867
872
|
} else {
|
|
868
|
-
toolResults.push({ tool, result: `Error:
|
|
873
|
+
toolResults.push({ tool, result: `Error: miss path or regex params` });
|
|
869
874
|
}
|
|
870
875
|
} else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
|
|
871
876
|
const serverName = tool.params.server_name;
|
|
@@ -970,9 +975,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
|
|
|
970
975
|
}
|
|
971
976
|
}
|
|
972
977
|
if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
|
|
973
|
-
|
|
978
|
+
let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
|
|
974
979
|
${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
|
|
975
980
|
</${TOOL_RESULT_BLOCK}>`).join("\n\n");
|
|
981
|
+
const lastResult = toolResults[toolResults.length - 1];
|
|
982
|
+
if (lastResult && lastResult.tool.name !== "agent_attempt_completion" /* ATTEMPT */) {
|
|
983
|
+
toolResultsContext += `
|
|
984
|
+
${this.promptManager.getUsedToolResultInstructions()}`;
|
|
985
|
+
}
|
|
976
986
|
if (this.onStreamChunk) {
|
|
977
987
|
this.onStreamChunk({ type: "text", text: toolResultsContext });
|
|
978
988
|
}
|
|
@@ -1030,6 +1040,47 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
1030
1040
|
async getHistory() {
|
|
1031
1041
|
return this.memory.getHistory();
|
|
1032
1042
|
}
|
|
1043
|
+
async searchFiles(dirpath, regex, filePattern) {
|
|
1044
|
+
const matches = [];
|
|
1045
|
+
const contentRe = new RegExp(regex);
|
|
1046
|
+
const nameRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1047
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1048
|
+
const walk = async (dir, depth) => {
|
|
1049
|
+
if (depth > 8 || matches.length >= 100) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
let entries;
|
|
1053
|
+
try {
|
|
1054
|
+
entries = await this.runtime.fs.readDir(dir, { recursive: false });
|
|
1055
|
+
} catch {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
for (const entry of entries) {
|
|
1059
|
+
if (matches.length >= 100) {
|
|
1060
|
+
break;
|
|
1061
|
+
}
|
|
1062
|
+
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1063
|
+
if (entry.isDirectory()) {
|
|
1064
|
+
if (!SKIP_DIRS.has(entry.name)) {
|
|
1065
|
+
await walk(child, depth + 1);
|
|
1066
|
+
}
|
|
1067
|
+
} else if (entry.isFile()) {
|
|
1068
|
+
if (nameRe && !nameRe.test(entry.name)) {
|
|
1069
|
+
continue;
|
|
1070
|
+
}
|
|
1071
|
+
try {
|
|
1072
|
+
const content = (await this.runtime.fs.readFile(child, "utf8")).toString();
|
|
1073
|
+
if (contentRe.test(content)) {
|
|
1074
|
+
matches.push(child);
|
|
1075
|
+
}
|
|
1076
|
+
} catch {
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
await walk(dirpath, 0);
|
|
1082
|
+
return matches.join("\n");
|
|
1083
|
+
}
|
|
1033
1084
|
};
|
|
1034
1085
|
var NodeApiHandler = class {
|
|
1035
1086
|
config;
|
|
@@ -1404,6 +1455,21 @@ Otherwise, if you have not completed the task and do not need additional informa
|
|
|
1404
1455
|
(This is an automated message, so do not respond to it conversationally.)
|
|
1405
1456
|
${this?.getEnvironmentInfoPrompt?.(context)}`;
|
|
1406
1457
|
}
|
|
1458
|
+
getUsedToolResultInstructions() {
|
|
1459
|
+
return `The above are the results of the tool call. Please continue to complete the remaining tasks.
|
|
1460
|
+
|
|
1461
|
+
# TODO LIST UPDATE REQUIRED - You MUST include the task_progress parameter in your NEXT tool call.
|
|
1462
|
+
|
|
1463
|
+
1. To create or update a todo list, include the task_progress parameter in the next tool call
|
|
1464
|
+
2. Review each item and update its status:
|
|
1465
|
+
- Mark completed items with: - [x]
|
|
1466
|
+
- Keep incomplete items as: - [ ]
|
|
1467
|
+
- Add new items if you discover additional steps
|
|
1468
|
+
3. Modify the list as needed:
|
|
1469
|
+
- Add any new steps you've discovered
|
|
1470
|
+
- Reorder if the sequence has changed
|
|
1471
|
+
4. Ensure the list accurately reflects the current state`;
|
|
1472
|
+
}
|
|
1407
1473
|
};
|
|
1408
1474
|
var NodeMemoryManager = class {
|
|
1409
1475
|
filePath;
|
|
@@ -1413,14 +1479,14 @@ var NodeMemoryManager = class {
|
|
|
1413
1479
|
* @param maxMessages 保留的最大消息数量,用于简单的历史截断(默认 150)
|
|
1414
1480
|
*/
|
|
1415
1481
|
constructor(dbPath, maxMessages = 150) {
|
|
1416
|
-
this.filePath =
|
|
1482
|
+
this.filePath = path__namespace.resolve(dbPath);
|
|
1417
1483
|
this.maxMessages = maxMessages;
|
|
1418
1484
|
}
|
|
1419
1485
|
async ensureFile() {
|
|
1420
1486
|
try {
|
|
1421
1487
|
await fs2__namespace.access(this.filePath);
|
|
1422
1488
|
} catch {
|
|
1423
|
-
const dir =
|
|
1489
|
+
const dir = path__namespace.dirname(this.filePath);
|
|
1424
1490
|
await fs2__namespace.mkdir(dir, { recursive: true });
|
|
1425
1491
|
await fs2__namespace.writeFile(this.filePath, "[]", "utf-8");
|
|
1426
1492
|
}
|
|
@@ -1596,10 +1662,13 @@ var NodeMcpManager = class {
|
|
|
1596
1662
|
var execAsync = util.promisify(child_process.exec);
|
|
1597
1663
|
var DefaultNodeRuntime = class {
|
|
1598
1664
|
fs = {
|
|
1599
|
-
readFile: async (filepath) => fs2__namespace.readFile(filepath,
|
|
1665
|
+
readFile: async (filepath, options = "utf8") => fs2__namespace.readFile(filepath, options),
|
|
1600
1666
|
writeFile: async (filepath, content) => {
|
|
1601
|
-
|
|
1602
|
-
|
|
1667
|
+
const dir = filepath.substring(0, filepath.lastIndexOf("/"));
|
|
1668
|
+
if (dir && dir !== filepath) {
|
|
1669
|
+
await fs2__namespace.mkdir(dir, { recursive: true });
|
|
1670
|
+
}
|
|
1671
|
+
await fs2__namespace.writeFile(filepath, content, "utf8");
|
|
1603
1672
|
},
|
|
1604
1673
|
deleteFile: (filepath) => fs2__namespace.unlink(filepath),
|
|
1605
1674
|
deleteDirectory: (dirpath) => fs2__namespace.rm(dirpath, { recursive: true, force: true }),
|
|
@@ -1611,13 +1680,13 @@ var DefaultNodeRuntime = class {
|
|
|
1611
1680
|
return false;
|
|
1612
1681
|
}
|
|
1613
1682
|
},
|
|
1614
|
-
readDir: (dirpath) => fs2__namespace.readdir(dirpath, { withFileTypes: true }),
|
|
1683
|
+
readDir: (dirpath, options) => fs2__namespace.readdir(dirpath, { withFileTypes: true, ...options || {} }),
|
|
1615
1684
|
mkdir: async (dirpath) => {
|
|
1616
1685
|
await fs2__namespace.mkdir(dirpath, { recursive: true });
|
|
1617
1686
|
}
|
|
1618
1687
|
};
|
|
1619
1688
|
path = {
|
|
1620
|
-
join: (...paths) =>
|
|
1689
|
+
join: (...paths) => path__namespace.join(...paths)
|
|
1621
1690
|
};
|
|
1622
1691
|
env = {
|
|
1623
1692
|
get: (key) => process.env[key],
|
|
@@ -1639,7 +1708,7 @@ var DefaultNodeRuntime = class {
|
|
|
1639
1708
|
function createNodeAgent(options) {
|
|
1640
1709
|
const runtime = new DefaultNodeRuntime();
|
|
1641
1710
|
const api = new NodeApiHandler(options.apiConfig);
|
|
1642
|
-
const memory = options.memory || new NodeMemoryManager(options.dbPath ||
|
|
1711
|
+
const memory = options.memory || new NodeMemoryManager(options.dbPath || path__namespace.join(runtime.env.cwd(), ".cline_memory.json"));
|
|
1643
1712
|
const customTools = options.customTools || [];
|
|
1644
1713
|
const customToolNames = new Set(customTools.map((t) => t.name));
|
|
1645
1714
|
const promptManager = new NodePromptManager();
|