@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.
@@ -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) {
@@ -695,9 +695,12 @@ ${content.trim()}\`\`\``);
695
695
  const history = await this.memory.getHistory();
696
696
  const stream = this.api.createMessage(sysPrompt, history);
697
697
  let fullResponseText = "";
698
+ let fullReasoningText = "";
698
699
  for await (const chunk of stream) {
699
700
  if (chunk.type === "text" && chunk.text) {
700
701
  fullResponseText += chunk.text;
702
+ } else if (chunk.type === "reasoning" && chunk.reasoning) {
703
+ fullReasoningText += chunk.reasoning;
701
704
  }
702
705
  if (this.onStreamChunk) {
703
706
  this.onStreamChunk(chunk);
@@ -705,7 +708,8 @@ ${content.trim()}\`\`\``);
705
708
  }
706
709
  await this.memory.appendMessage({
707
710
  role: "assistant",
708
- content: fullResponseText
711
+ content: fullResponseText,
712
+ ...fullReasoningText ? { reasoning: fullReasoningText } : {}
709
713
  });
710
714
  const parsedBlocks = parseAssistantMessageV2(fullResponseText, this.allToolParamNames);
711
715
  const toolUses = parsedBlocks.filter((b) => b.type === "tool_use");
@@ -828,15 +832,20 @@ STDERR: ${result.stderr}` });
828
832
  const path2 = tool.params.path || this.runtime.env.cwd();
829
833
  const regexStr = tool.params.regex;
830
834
  const filePattern = tool.params.file_pattern;
831
- if (regexStr && this.runtime.fs.searchFiles) {
835
+ if (regexStr && path2) {
832
836
  try {
833
- const result = await this.runtime.fs.searchFiles(path2, regexStr, filePattern);
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
+ }
834
843
  toolResults.push({ tool, result: `${result}` });
835
844
  } catch (e) {
836
845
  toolResults.push({ tool, result: `Error: ${e.message}` });
837
846
  }
838
847
  } else {
839
- toolResults.push({ tool, result: `Error: searchFiles not supported by runtime or missing regex.` });
848
+ toolResults.push({ tool, result: `Error: miss path or regex params` });
840
849
  }
841
850
  } else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
842
851
  const serverName = tool.params.server_name;
@@ -941,9 +950,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
941
950
  }
942
951
  }
943
952
  if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
944
- const toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
953
+ let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
945
954
  ${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
946
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
+ }
947
961
  if (this.onStreamChunk) {
948
962
  this.onStreamChunk({ type: "text", text: toolResultsContext });
949
963
  }
@@ -1001,6 +1015,47 @@ ${searchBlock.substring(0, 100)}...`);
1001
1015
  async getHistory() {
1002
1016
  return this.memory.getHistory();
1003
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
+ }
1004
1059
  };
1005
1060
  var WebApiHandler = class {
1006
1061
  config;
@@ -1063,6 +1118,11 @@ var WebApiHandler = class {
1063
1118
  type: "text",
1064
1119
  text: part.textDelta || part.text || ""
1065
1120
  };
1121
+ } else if (part.type === "reasoning-delta") {
1122
+ yield {
1123
+ type: "reasoning",
1124
+ reasoning: part.delta || part.text || ""
1125
+ };
1066
1126
  } else if (part.type === "finish") {
1067
1127
  yield {
1068
1128
  type: "usage",
@@ -1370,6 +1430,21 @@ Otherwise, if you have not completed the task and do not need additional informa
1370
1430
  (This is an automated message, so do not respond to it conversationally.)
1371
1431
  ${this?.getEnvironmentInfoPrompt?.(context)}`;
1372
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
+ }
1373
1448
  };
1374
1449
 
1375
1450
  // src/memory/WebMemoryManager.ts
@@ -1475,8 +1550,8 @@ var DefaultWebRuntime = class {
1475
1550
  vol = new memfs.Volume();
1476
1551
  memfs = memfs.createFsFromVolume(this.vol).promises;
1477
1552
  fs = {
1478
- readFile: async (filepath) => {
1479
- const content = await this.memfs.readFile(filepath, "utf-8");
1553
+ readFile: async (filepath, options = "utf8") => {
1554
+ const content = await this.memfs.readFile(filepath, options);
1480
1555
  return content.toString();
1481
1556
  },
1482
1557
  writeFile: async (filepath, content) => {
@@ -1496,8 +1571,8 @@ var DefaultWebRuntime = class {
1496
1571
  return false;
1497
1572
  }
1498
1573
  },
1499
- readDir: (dirpath) => {
1500
- return this.memfs.readdir(dirpath, { withFileTypes: true });
1574
+ readDir: (dirpath, options) => {
1575
+ return this.memfs.readdir(dirpath, { withFileTypes: true, ...options || {} });
1501
1576
  },
1502
1577
  mkdir: async (dirpath) => {
1503
1578
  await this.memfs.mkdir(dirpath, { recursive: true });