@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
package/dist/index.d.mts
CHANGED
|
@@ -7,12 +7,12 @@ interface IAgentRuntime {
|
|
|
7
7
|
* 文件系统相关操作
|
|
8
8
|
*/
|
|
9
9
|
fs: {
|
|
10
|
-
readFile(path: string): Promise<
|
|
10
|
+
readFile(path: string, options?: any): Promise<any>;
|
|
11
11
|
writeFile(path: string, content: string): Promise<void>;
|
|
12
12
|
deleteFile(path: string): Promise<void>;
|
|
13
13
|
deleteDirectory(path: string): Promise<void>;
|
|
14
14
|
fileExists(path: string): Promise<boolean>;
|
|
15
|
-
readDir(path: string): Promise<any[]>;
|
|
15
|
+
readDir(path: string, options?: any): Promise<any[]>;
|
|
16
16
|
mkdir(path: string): Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* 跨文件正则搜索
|
|
@@ -269,6 +269,10 @@ interface IPromptManager {
|
|
|
269
269
|
* 获取未使用工具的错误提示词
|
|
270
270
|
*/
|
|
271
271
|
getNoUseToolInstructions(context: any): string;
|
|
272
|
+
/**
|
|
273
|
+
* 工具调用后,提醒继续完成任务
|
|
274
|
+
*/
|
|
275
|
+
getUsedToolResultInstructions(): string;
|
|
272
276
|
}
|
|
273
277
|
|
|
274
278
|
/**
|
|
@@ -277,6 +281,8 @@ interface IPromptManager {
|
|
|
277
281
|
interface AgentMessage {
|
|
278
282
|
role: 'user' | 'assistant' | 'system';
|
|
279
283
|
content: string | any[];
|
|
284
|
+
/** 大模型思考内容(reasoning),仅在 role 为 assistant 时可能携带 */
|
|
285
|
+
reasoning?: string;
|
|
280
286
|
}
|
|
281
287
|
/**
|
|
282
288
|
* 抽象的 Memory 管理器。
|
|
@@ -305,8 +311,9 @@ interface IMemoryManager {
|
|
|
305
311
|
* 统一的 API 响应流数据块
|
|
306
312
|
*/
|
|
307
313
|
interface ApiStreamChunk {
|
|
308
|
-
type: "text" | "usage" | "error";
|
|
314
|
+
type: "text" | "reasoning" | "usage" | "error";
|
|
309
315
|
text?: string;
|
|
316
|
+
reasoning?: string;
|
|
310
317
|
usage?: {
|
|
311
318
|
inputTokens: number;
|
|
312
319
|
outputTokens: number;
|
|
@@ -477,6 +484,7 @@ declare class ClineAgent {
|
|
|
477
484
|
resume(userInput?: string): Promise<void>;
|
|
478
485
|
appendHistory(history: AgentMessage[]): Promise<void>;
|
|
479
486
|
getHistory(): Promise<AgentMessage[]>;
|
|
487
|
+
searchFiles(dirpath: string, regex: string, filePattern?: string): Promise<string>;
|
|
480
488
|
}
|
|
481
489
|
|
|
482
490
|
declare const VERSION = "0.1.0";
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ interface IAgentRuntime {
|
|
|
7
7
|
* 文件系统相关操作
|
|
8
8
|
*/
|
|
9
9
|
fs: {
|
|
10
|
-
readFile(path: string): Promise<
|
|
10
|
+
readFile(path: string, options?: any): Promise<any>;
|
|
11
11
|
writeFile(path: string, content: string): Promise<void>;
|
|
12
12
|
deleteFile(path: string): Promise<void>;
|
|
13
13
|
deleteDirectory(path: string): Promise<void>;
|
|
14
14
|
fileExists(path: string): Promise<boolean>;
|
|
15
|
-
readDir(path: string): Promise<any[]>;
|
|
15
|
+
readDir(path: string, options?: any): Promise<any[]>;
|
|
16
16
|
mkdir(path: string): Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* 跨文件正则搜索
|
|
@@ -269,6 +269,10 @@ interface IPromptManager {
|
|
|
269
269
|
* 获取未使用工具的错误提示词
|
|
270
270
|
*/
|
|
271
271
|
getNoUseToolInstructions(context: any): string;
|
|
272
|
+
/**
|
|
273
|
+
* 工具调用后,提醒继续完成任务
|
|
274
|
+
*/
|
|
275
|
+
getUsedToolResultInstructions(): string;
|
|
272
276
|
}
|
|
273
277
|
|
|
274
278
|
/**
|
|
@@ -277,6 +281,8 @@ interface IPromptManager {
|
|
|
277
281
|
interface AgentMessage {
|
|
278
282
|
role: 'user' | 'assistant' | 'system';
|
|
279
283
|
content: string | any[];
|
|
284
|
+
/** 大模型思考内容(reasoning),仅在 role 为 assistant 时可能携带 */
|
|
285
|
+
reasoning?: string;
|
|
280
286
|
}
|
|
281
287
|
/**
|
|
282
288
|
* 抽象的 Memory 管理器。
|
|
@@ -305,8 +311,9 @@ interface IMemoryManager {
|
|
|
305
311
|
* 统一的 API 响应流数据块
|
|
306
312
|
*/
|
|
307
313
|
interface ApiStreamChunk {
|
|
308
|
-
type: "text" | "usage" | "error";
|
|
314
|
+
type: "text" | "reasoning" | "usage" | "error";
|
|
309
315
|
text?: string;
|
|
316
|
+
reasoning?: string;
|
|
310
317
|
usage?: {
|
|
311
318
|
inputTokens: number;
|
|
312
319
|
outputTokens: number;
|
|
@@ -477,6 +484,7 @@ declare class ClineAgent {
|
|
|
477
484
|
resume(userInput?: string): Promise<void>;
|
|
478
485
|
appendHistory(history: AgentMessage[]): Promise<void>;
|
|
479
486
|
getHistory(): Promise<AgentMessage[]>;
|
|
487
|
+
searchFiles(dirpath: string, regex: string, filePattern?: string): Promise<string>;
|
|
480
488
|
}
|
|
481
489
|
|
|
482
490
|
declare const VERSION = "0.1.0";
|
package/dist/index.js
CHANGED
|
@@ -551,7 +551,7 @@ var ClineAgent = class {
|
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
/**
|
|
554
|
-
* 获取当前 Agent 的系统提示词
|
|
554
|
+
* 获取当前 Agent 的系统提示词
|
|
555
555
|
* 如果 force 为 true,则强制重新获取系统提示词
|
|
556
556
|
*/
|
|
557
557
|
async getPrompt(force = false) {
|
|
@@ -689,9 +689,12 @@ ${content.trim()}\`\`\``);
|
|
|
689
689
|
const history = await this.memory.getHistory();
|
|
690
690
|
const stream = this.api.createMessage(sysPrompt, history);
|
|
691
691
|
let fullResponseText = "";
|
|
692
|
+
let fullReasoningText = "";
|
|
692
693
|
for await (const chunk of stream) {
|
|
693
694
|
if (chunk.type === "text" && chunk.text) {
|
|
694
695
|
fullResponseText += chunk.text;
|
|
696
|
+
} else if (chunk.type === "reasoning" && chunk.reasoning) {
|
|
697
|
+
fullReasoningText += chunk.reasoning;
|
|
695
698
|
}
|
|
696
699
|
if (this.onStreamChunk) {
|
|
697
700
|
this.onStreamChunk(chunk);
|
|
@@ -699,7 +702,8 @@ ${content.trim()}\`\`\``);
|
|
|
699
702
|
}
|
|
700
703
|
await this.memory.appendMessage({
|
|
701
704
|
role: "assistant",
|
|
702
|
-
content: fullResponseText
|
|
705
|
+
content: fullResponseText,
|
|
706
|
+
...fullReasoningText ? { reasoning: fullReasoningText } : {}
|
|
703
707
|
});
|
|
704
708
|
const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
|
|
705
709
|
const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
|
|
@@ -822,15 +826,20 @@ STDERR: ${result.stderr}` });
|
|
|
822
826
|
const path = tool.params.path || this.runtime.env.cwd();
|
|
823
827
|
const regexStr = tool.params.regex;
|
|
824
828
|
const filePattern = tool.params.file_pattern;
|
|
825
|
-
if (regexStr &&
|
|
829
|
+
if (regexStr && path) {
|
|
826
830
|
try {
|
|
827
|
-
|
|
831
|
+
let result;
|
|
832
|
+
if (typeof this.runtime.fs.searchFiles === "function") {
|
|
833
|
+
result = await this.runtime.fs.searchFiles(path, regexStr, filePattern);
|
|
834
|
+
} else {
|
|
835
|
+
result = await this.searchFiles(path, regexStr, filePattern);
|
|
836
|
+
}
|
|
828
837
|
toolResults.push({ tool, result: `${result}` });
|
|
829
838
|
} catch (e) {
|
|
830
839
|
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
831
840
|
}
|
|
832
841
|
} else {
|
|
833
|
-
toolResults.push({ tool, result: `Error:
|
|
842
|
+
toolResults.push({ tool, result: `Error: miss path or regex params` });
|
|
834
843
|
}
|
|
835
844
|
} else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
|
|
836
845
|
const serverName = tool.params.server_name;
|
|
@@ -935,9 +944,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
|
|
|
935
944
|
}
|
|
936
945
|
}
|
|
937
946
|
if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
|
|
938
|
-
|
|
947
|
+
let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
|
|
939
948
|
${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
|
|
940
949
|
</${TOOL_RESULT_BLOCK}>`).join("\n\n");
|
|
950
|
+
const lastResult = toolResults[toolResults.length - 1];
|
|
951
|
+
if (lastResult && lastResult.tool.name !== "agent_attempt_completion" /* ATTEMPT */) {
|
|
952
|
+
toolResultsContext += `
|
|
953
|
+
${this.promptManager.getUsedToolResultInstructions()}`;
|
|
954
|
+
}
|
|
941
955
|
if (this.onStreamChunk) {
|
|
942
956
|
this.onStreamChunk({ type: "text", text: toolResultsContext });
|
|
943
957
|
}
|
|
@@ -995,6 +1009,47 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
995
1009
|
async getHistory() {
|
|
996
1010
|
return this.memory.getHistory();
|
|
997
1011
|
}
|
|
1012
|
+
async searchFiles(dirpath, regex, filePattern) {
|
|
1013
|
+
const matches = [];
|
|
1014
|
+
const contentRe = new RegExp(regex);
|
|
1015
|
+
const nameRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1016
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1017
|
+
const walk = async (dir, depth) => {
|
|
1018
|
+
if (depth > 8 || matches.length >= 100) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
let entries;
|
|
1022
|
+
try {
|
|
1023
|
+
entries = await this.runtime.fs.readDir(dir, { recursive: false });
|
|
1024
|
+
} catch {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
for (const entry of entries) {
|
|
1028
|
+
if (matches.length >= 100) {
|
|
1029
|
+
break;
|
|
1030
|
+
}
|
|
1031
|
+
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1032
|
+
if (entry.isDirectory()) {
|
|
1033
|
+
if (!SKIP_DIRS.has(entry.name)) {
|
|
1034
|
+
await walk(child, depth + 1);
|
|
1035
|
+
}
|
|
1036
|
+
} else if (entry.isFile()) {
|
|
1037
|
+
if (nameRe && !nameRe.test(entry.name)) {
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
try {
|
|
1041
|
+
const content = (await this.runtime.fs.readFile(child, "utf8")).toString();
|
|
1042
|
+
if (contentRe.test(content)) {
|
|
1043
|
+
matches.push(child);
|
|
1044
|
+
}
|
|
1045
|
+
} catch {
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
await walk(dirpath, 0);
|
|
1051
|
+
return matches.join("\n");
|
|
1052
|
+
}
|
|
998
1053
|
};
|
|
999
1054
|
|
|
1000
1055
|
// src/index.ts
|