@amical/aiagent-sdk 0.1.7 → 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 +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +61 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -6
- 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 +94 -16
- package/dist/runtime/nodeRuntime.js.map +1 -1
- package/dist/runtime/nodeRuntime.mjs +93 -15
- 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 +85 -10
- package/dist/runtime/webRuntime.js.map +1 -1
- package/dist/runtime/webRuntime.mjs +85 -10
- package/dist/runtime/webRuntime.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -550,7 +550,7 @@ var ClineAgent = class {
|
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
552
|
/**
|
|
553
|
-
* 获取当前 Agent 的系统提示词
|
|
553
|
+
* 获取当前 Agent 的系统提示词
|
|
554
554
|
* 如果 force 为 true,则强制重新获取系统提示词
|
|
555
555
|
*/
|
|
556
556
|
async getPrompt(force = false) {
|
|
@@ -688,9 +688,12 @@ ${content.trim()}\`\`\``);
|
|
|
688
688
|
const history = await this.memory.getHistory();
|
|
689
689
|
const stream = this.api.createMessage(sysPrompt, history);
|
|
690
690
|
let fullResponseText = "";
|
|
691
|
+
let fullReasoningText = "";
|
|
691
692
|
for await (const chunk of stream) {
|
|
692
693
|
if (chunk.type === "text" && chunk.text) {
|
|
693
694
|
fullResponseText += chunk.text;
|
|
695
|
+
} else if (chunk.type === "reasoning" && chunk.reasoning) {
|
|
696
|
+
fullReasoningText += chunk.reasoning;
|
|
694
697
|
}
|
|
695
698
|
if (this.onStreamChunk) {
|
|
696
699
|
this.onStreamChunk(chunk);
|
|
@@ -698,7 +701,8 @@ ${content.trim()}\`\`\``);
|
|
|
698
701
|
}
|
|
699
702
|
await this.memory.appendMessage({
|
|
700
703
|
role: "assistant",
|
|
701
|
-
content: fullResponseText
|
|
704
|
+
content: fullResponseText,
|
|
705
|
+
...fullReasoningText ? { reasoning: fullReasoningText } : {}
|
|
702
706
|
});
|
|
703
707
|
const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
|
|
704
708
|
const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
|
|
@@ -821,15 +825,20 @@ STDERR: ${result.stderr}` });
|
|
|
821
825
|
const path2 = tool.params.path || this.runtime.env.cwd();
|
|
822
826
|
const regexStr = tool.params.regex;
|
|
823
827
|
const filePattern = tool.params.file_pattern;
|
|
824
|
-
if (regexStr &&
|
|
828
|
+
if (regexStr && path2) {
|
|
825
829
|
try {
|
|
826
|
-
|
|
830
|
+
let result;
|
|
831
|
+
if (typeof this.runtime.fs.searchFiles === "function") {
|
|
832
|
+
result = await this.runtime.fs.searchFiles(path2, regexStr, filePattern);
|
|
833
|
+
} else {
|
|
834
|
+
result = await this.searchFiles(path2, regexStr, filePattern);
|
|
835
|
+
}
|
|
827
836
|
toolResults.push({ tool, result: `${result}` });
|
|
828
837
|
} catch (e) {
|
|
829
838
|
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
830
839
|
}
|
|
831
840
|
} else {
|
|
832
|
-
toolResults.push({ tool, result: `Error:
|
|
841
|
+
toolResults.push({ tool, result: `Error: miss path or regex params` });
|
|
833
842
|
}
|
|
834
843
|
} else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
|
|
835
844
|
const serverName = tool.params.server_name;
|
|
@@ -934,9 +943,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
|
|
|
934
943
|
}
|
|
935
944
|
}
|
|
936
945
|
if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
|
|
937
|
-
|
|
946
|
+
let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
|
|
938
947
|
${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
|
|
939
948
|
</${TOOL_RESULT_BLOCK}>`).join("\n\n");
|
|
949
|
+
const lastResult = toolResults[toolResults.length - 1];
|
|
950
|
+
if (lastResult && lastResult.tool.name !== "agent_attempt_completion" /* ATTEMPT */) {
|
|
951
|
+
toolResultsContext += `
|
|
952
|
+
${this.promptManager.getUsedToolResultInstructions()}`;
|
|
953
|
+
}
|
|
940
954
|
if (this.onStreamChunk) {
|
|
941
955
|
this.onStreamChunk({ type: "text", text: toolResultsContext });
|
|
942
956
|
}
|
|
@@ -994,6 +1008,47 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
994
1008
|
async getHistory() {
|
|
995
1009
|
return this.memory.getHistory();
|
|
996
1010
|
}
|
|
1011
|
+
async searchFiles(dirpath, regex, filePattern) {
|
|
1012
|
+
const matches = [];
|
|
1013
|
+
const contentRe = new RegExp(regex);
|
|
1014
|
+
const nameRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1015
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1016
|
+
const walk = async (dir, depth) => {
|
|
1017
|
+
if (depth > 8 || matches.length >= 100) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
let entries;
|
|
1021
|
+
try {
|
|
1022
|
+
entries = await this.runtime.fs.readDir(dir, { recursive: false });
|
|
1023
|
+
} catch {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
for (const entry of entries) {
|
|
1027
|
+
if (matches.length >= 100) {
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1031
|
+
if (entry.isDirectory()) {
|
|
1032
|
+
if (!SKIP_DIRS.has(entry.name)) {
|
|
1033
|
+
await walk(child, depth + 1);
|
|
1034
|
+
}
|
|
1035
|
+
} else if (entry.isFile()) {
|
|
1036
|
+
if (nameRe && !nameRe.test(entry.name)) {
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
try {
|
|
1040
|
+
const content = (await this.runtime.fs.readFile(child, "utf8")).toString();
|
|
1041
|
+
if (contentRe.test(content)) {
|
|
1042
|
+
matches.push(child);
|
|
1043
|
+
}
|
|
1044
|
+
} catch {
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
await walk(dirpath, 0);
|
|
1050
|
+
return matches.join("\n");
|
|
1051
|
+
}
|
|
997
1052
|
};
|
|
998
1053
|
var WebApiHandler = class {
|
|
999
1054
|
config;
|
|
@@ -1056,6 +1111,11 @@ var WebApiHandler = class {
|
|
|
1056
1111
|
type: "text",
|
|
1057
1112
|
text: part.textDelta || part.text || ""
|
|
1058
1113
|
};
|
|
1114
|
+
} else if (part.type === "reasoning-delta") {
|
|
1115
|
+
yield {
|
|
1116
|
+
type: "reasoning",
|
|
1117
|
+
reasoning: part.delta || part.text || ""
|
|
1118
|
+
};
|
|
1059
1119
|
} else if (part.type === "finish") {
|
|
1060
1120
|
yield {
|
|
1061
1121
|
type: "usage",
|
|
@@ -1363,6 +1423,21 @@ Otherwise, if you have not completed the task and do not need additional informa
|
|
|
1363
1423
|
(This is an automated message, so do not respond to it conversationally.)
|
|
1364
1424
|
${this?.getEnvironmentInfoPrompt?.(context)}`;
|
|
1365
1425
|
}
|
|
1426
|
+
getUsedToolResultInstructions() {
|
|
1427
|
+
return `The above are the results of the tool call. Please continue to complete the remaining tasks.
|
|
1428
|
+
|
|
1429
|
+
# TODO LIST UPDATE REQUIRED - You MUST include the task_progress parameter in your NEXT tool call.
|
|
1430
|
+
|
|
1431
|
+
1. To create or update a todo list, include the task_progress parameter in the next tool call
|
|
1432
|
+
2. Review each item and update its status:
|
|
1433
|
+
- Mark completed items with: - [x]
|
|
1434
|
+
- Keep incomplete items as: - [ ]
|
|
1435
|
+
- Add new items if you discover additional steps
|
|
1436
|
+
3. Modify the list as needed:
|
|
1437
|
+
- Add any new steps you've discovered
|
|
1438
|
+
- Reorder if the sequence has changed
|
|
1439
|
+
4. Ensure the list accurately reflects the current state`;
|
|
1440
|
+
}
|
|
1366
1441
|
};
|
|
1367
1442
|
|
|
1368
1443
|
// src/memory/WebMemoryManager.ts
|
|
@@ -1468,8 +1543,8 @@ var DefaultWebRuntime = class {
|
|
|
1468
1543
|
vol = new Volume();
|
|
1469
1544
|
memfs = createFsFromVolume(this.vol).promises;
|
|
1470
1545
|
fs = {
|
|
1471
|
-
readFile: async (filepath) => {
|
|
1472
|
-
const content = await this.memfs.readFile(filepath,
|
|
1546
|
+
readFile: async (filepath, options = "utf8") => {
|
|
1547
|
+
const content = await this.memfs.readFile(filepath, options);
|
|
1473
1548
|
return content.toString();
|
|
1474
1549
|
},
|
|
1475
1550
|
writeFile: async (filepath, content) => {
|
|
@@ -1489,8 +1564,8 @@ var DefaultWebRuntime = class {
|
|
|
1489
1564
|
return false;
|
|
1490
1565
|
}
|
|
1491
1566
|
},
|
|
1492
|
-
readDir: (dirpath) => {
|
|
1493
|
-
return this.memfs.readdir(dirpath, { withFileTypes: true });
|
|
1567
|
+
readDir: (dirpath, options) => {
|
|
1568
|
+
return this.memfs.readdir(dirpath, { withFileTypes: true, ...options || {} });
|
|
1494
1569
|
},
|
|
1495
1570
|
mkdir: async (dirpath) => {
|
|
1496
1571
|
await this.memfs.mkdir(dirpath, { recursive: true });
|