@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
|
@@ -47,6 +47,7 @@ declare class WebPromptManager implements IPromptManager {
|
|
|
47
47
|
customTools?: any[];
|
|
48
48
|
}): string;
|
|
49
49
|
getNoUseToolInstructions(context: any): string;
|
|
50
|
+
getUsedToolResultInstructions(): string;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
declare class WebMcpManager implements IMcpManager {
|
|
@@ -66,12 +67,12 @@ declare class DefaultWebRuntime implements IAgentRuntime {
|
|
|
66
67
|
private vol;
|
|
67
68
|
private memfs;
|
|
68
69
|
fs: {
|
|
69
|
-
readFile: (filepath: string) => Promise<string>;
|
|
70
|
+
readFile: (filepath: string, options?: any) => Promise<string>;
|
|
70
71
|
writeFile: (filepath: string, content: string) => Promise<void>;
|
|
71
72
|
deleteFile: (filepath: string) => Promise<void>;
|
|
72
73
|
deleteDirectory: (dirpath: string) => Promise<void>;
|
|
73
74
|
fileExists: (filepath: string) => Promise<boolean>;
|
|
74
|
-
readDir: (dirpath: string) => any;
|
|
75
|
+
readDir: (dirpath: string, options: any) => any;
|
|
75
76
|
mkdir: (dirpath: string) => Promise<void>;
|
|
76
77
|
};
|
|
77
78
|
path: {
|
|
@@ -47,6 +47,7 @@ declare class WebPromptManager implements IPromptManager {
|
|
|
47
47
|
customTools?: any[];
|
|
48
48
|
}): string;
|
|
49
49
|
getNoUseToolInstructions(context: any): string;
|
|
50
|
+
getUsedToolResultInstructions(): string;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
declare class WebMcpManager implements IMcpManager {
|
|
@@ -66,12 +67,12 @@ declare class DefaultWebRuntime implements IAgentRuntime {
|
|
|
66
67
|
private vol;
|
|
67
68
|
private memfs;
|
|
68
69
|
fs: {
|
|
69
|
-
readFile: (filepath: string) => Promise<string>;
|
|
70
|
+
readFile: (filepath: string, options?: any) => Promise<string>;
|
|
70
71
|
writeFile: (filepath: string, content: string) => Promise<void>;
|
|
71
72
|
deleteFile: (filepath: string) => Promise<void>;
|
|
72
73
|
deleteDirectory: (dirpath: string) => Promise<void>;
|
|
73
74
|
fileExists: (filepath: string) => Promise<boolean>;
|
|
74
|
-
readDir: (dirpath: string) => any;
|
|
75
|
+
readDir: (dirpath: string, options: any) => any;
|
|
75
76
|
mkdir: (dirpath: string) => Promise<void>;
|
|
76
77
|
};
|
|
77
78
|
path: {
|
|
@@ -557,7 +557,7 @@ var ClineAgent = class {
|
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
/**
|
|
560
|
-
* 获取当前 Agent 的系统提示词
|
|
560
|
+
* 获取当前 Agent 的系统提示词
|
|
561
561
|
* 如果 force 为 true,则强制重新获取系统提示词
|
|
562
562
|
*/
|
|
563
563
|
async getPrompt(force = false) {
|
|
@@ -832,15 +832,20 @@ STDERR: ${result.stderr}` });
|
|
|
832
832
|
const path2 = tool.params.path || this.runtime.env.cwd();
|
|
833
833
|
const regexStr = tool.params.regex;
|
|
834
834
|
const filePattern = tool.params.file_pattern;
|
|
835
|
-
if (regexStr &&
|
|
835
|
+
if (regexStr && path2) {
|
|
836
836
|
try {
|
|
837
|
-
|
|
837
|
+
let result;
|
|
838
|
+
if (typeof this.runtime.fs.searchFiles === "function") {
|
|
839
|
+
result = await this.runtime.fs.searchFiles(path2, regexStr, filePattern);
|
|
840
|
+
} else {
|
|
841
|
+
result = await this.searchFiles(path2, regexStr, filePattern);
|
|
842
|
+
}
|
|
838
843
|
toolResults.push({ tool, result: `${result}` });
|
|
839
844
|
} catch (e) {
|
|
840
845
|
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
841
846
|
}
|
|
842
847
|
} else {
|
|
843
|
-
toolResults.push({ tool, result: `Error:
|
|
848
|
+
toolResults.push({ tool, result: `Error: miss path or regex params` });
|
|
844
849
|
}
|
|
845
850
|
} else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
|
|
846
851
|
const serverName = tool.params.server_name;
|
|
@@ -945,9 +950,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
|
|
|
945
950
|
}
|
|
946
951
|
}
|
|
947
952
|
if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
|
|
948
|
-
|
|
953
|
+
let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
|
|
949
954
|
${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
|
|
950
955
|
</${TOOL_RESULT_BLOCK}>`).join("\n\n");
|
|
956
|
+
const lastResult = toolResults[toolResults.length - 1];
|
|
957
|
+
if (lastResult && lastResult.tool.name !== "agent_attempt_completion" /* ATTEMPT */) {
|
|
958
|
+
toolResultsContext += `
|
|
959
|
+
${this.promptManager.getUsedToolResultInstructions()}`;
|
|
960
|
+
}
|
|
951
961
|
if (this.onStreamChunk) {
|
|
952
962
|
this.onStreamChunk({ type: "text", text: toolResultsContext });
|
|
953
963
|
}
|
|
@@ -1005,6 +1015,47 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
1005
1015
|
async getHistory() {
|
|
1006
1016
|
return this.memory.getHistory();
|
|
1007
1017
|
}
|
|
1018
|
+
async searchFiles(dirpath, regex, filePattern) {
|
|
1019
|
+
const matches = [];
|
|
1020
|
+
const contentRe = new RegExp(regex);
|
|
1021
|
+
const nameRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1022
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1023
|
+
const walk = async (dir, depth) => {
|
|
1024
|
+
if (depth > 8 || matches.length >= 100) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
let entries;
|
|
1028
|
+
try {
|
|
1029
|
+
entries = await this.runtime.fs.readDir(dir, { recursive: false });
|
|
1030
|
+
} catch {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
for (const entry of entries) {
|
|
1034
|
+
if (matches.length >= 100) {
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1038
|
+
if (entry.isDirectory()) {
|
|
1039
|
+
if (!SKIP_DIRS.has(entry.name)) {
|
|
1040
|
+
await walk(child, depth + 1);
|
|
1041
|
+
}
|
|
1042
|
+
} else if (entry.isFile()) {
|
|
1043
|
+
if (nameRe && !nameRe.test(entry.name)) {
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
const content = (await this.runtime.fs.readFile(child, "utf8")).toString();
|
|
1048
|
+
if (contentRe.test(content)) {
|
|
1049
|
+
matches.push(child);
|
|
1050
|
+
}
|
|
1051
|
+
} catch {
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
await walk(dirpath, 0);
|
|
1057
|
+
return matches.join("\n");
|
|
1058
|
+
}
|
|
1008
1059
|
};
|
|
1009
1060
|
var WebApiHandler = class {
|
|
1010
1061
|
config;
|
|
@@ -1379,6 +1430,21 @@ Otherwise, if you have not completed the task and do not need additional informa
|
|
|
1379
1430
|
(This is an automated message, so do not respond to it conversationally.)
|
|
1380
1431
|
${this?.getEnvironmentInfoPrompt?.(context)}`;
|
|
1381
1432
|
}
|
|
1433
|
+
getUsedToolResultInstructions() {
|
|
1434
|
+
return `The above are the results of the tool call. Please continue to complete the remaining tasks.
|
|
1435
|
+
|
|
1436
|
+
# TODO LIST UPDATE REQUIRED - You MUST include the task_progress parameter in your NEXT tool call.
|
|
1437
|
+
|
|
1438
|
+
1. To create or update a todo list, include the task_progress parameter in the next tool call
|
|
1439
|
+
2. Review each item and update its status:
|
|
1440
|
+
- Mark completed items with: - [x]
|
|
1441
|
+
- Keep incomplete items as: - [ ]
|
|
1442
|
+
- Add new items if you discover additional steps
|
|
1443
|
+
3. Modify the list as needed:
|
|
1444
|
+
- Add any new steps you've discovered
|
|
1445
|
+
- Reorder if the sequence has changed
|
|
1446
|
+
4. Ensure the list accurately reflects the current state`;
|
|
1447
|
+
}
|
|
1382
1448
|
};
|
|
1383
1449
|
|
|
1384
1450
|
// src/memory/WebMemoryManager.ts
|
|
@@ -1484,8 +1550,8 @@ var DefaultWebRuntime = class {
|
|
|
1484
1550
|
vol = new memfs.Volume();
|
|
1485
1551
|
memfs = memfs.createFsFromVolume(this.vol).promises;
|
|
1486
1552
|
fs = {
|
|
1487
|
-
readFile: async (filepath) => {
|
|
1488
|
-
const content = await this.memfs.readFile(filepath,
|
|
1553
|
+
readFile: async (filepath, options = "utf8") => {
|
|
1554
|
+
const content = await this.memfs.readFile(filepath, options);
|
|
1489
1555
|
return content.toString();
|
|
1490
1556
|
},
|
|
1491
1557
|
writeFile: async (filepath, content) => {
|
|
@@ -1505,8 +1571,8 @@ var DefaultWebRuntime = class {
|
|
|
1505
1571
|
return false;
|
|
1506
1572
|
}
|
|
1507
1573
|
},
|
|
1508
|
-
readDir: (dirpath) => {
|
|
1509
|
-
return this.memfs.readdir(dirpath, { withFileTypes: true });
|
|
1574
|
+
readDir: (dirpath, options) => {
|
|
1575
|
+
return this.memfs.readdir(dirpath, { withFileTypes: true, ...options || {} });
|
|
1510
1576
|
},
|
|
1511
1577
|
mkdir: async (dirpath) => {
|
|
1512
1578
|
await this.memfs.mkdir(dirpath, { recursive: true });
|