@amical/aiagent-sdk 0.1.9 → 0.1.10
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 +30 -6
- package/dist/index.d.ts +30 -6
- package/dist/index.js +182 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -14
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/nodeRuntime.js +182 -14
- package/dist/runtime/nodeRuntime.js.map +1 -1
- package/dist/runtime/nodeRuntime.mjs +182 -14
- package/dist/runtime/nodeRuntime.mjs.map +1 -1
- package/dist/runtime/webRuntime.js +182 -14
- package/dist/runtime/webRuntime.js.map +1 -1
- package/dist/runtime/webRuntime.mjs +182 -14
- package/dist/runtime/webRuntime.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ var AgentDefaultTool = /* @__PURE__ */ ((AgentDefaultTool2) => {
|
|
|
22
22
|
AgentDefaultTool2["FILE_DELETE"] = "agent_delete_file";
|
|
23
23
|
AgentDefaultTool2["DIR_DELETE"] = "agent_delete_directory";
|
|
24
24
|
AgentDefaultTool2["SEARCH"] = "agent_search_files";
|
|
25
|
+
AgentDefaultTool2["SEARCH_CONTENT"] = "agent_search_file_content";
|
|
25
26
|
AgentDefaultTool2["LIST_FILES"] = "agent_list_files";
|
|
26
27
|
AgentDefaultTool2["LIST_CODE_DEF"] = "agent_list_code_definition_names";
|
|
27
28
|
AgentDefaultTool2["BROWSER"] = "agent_browser_action";
|
|
@@ -195,11 +196,22 @@ return (
|
|
|
195
196
|
},
|
|
196
197
|
{
|
|
197
198
|
name: "agent_search_files" /* SEARCH */,
|
|
198
|
-
description: "Search for files in a directory
|
|
199
|
+
description: "Search for files or directories by name in a directory tree, matching the name against a regex (and optionally a glob). Directories are traversed level by level: all matches in the current level are returned before descending into deeper levels. Use this tool only to locate files/directories by name.",
|
|
199
200
|
params: {
|
|
200
201
|
path: "(required) The absolute or relative directory path to search.",
|
|
201
|
-
regex: "(required) The regex pattern to match
|
|
202
|
-
file_pattern: "(optional) glob pattern like *.ts."
|
|
202
|
+
regex: "(required) The regex pattern to match file or directory names against.",
|
|
203
|
+
file_pattern: "(optional) glob pattern like *.ts.",
|
|
204
|
+
include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped."
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "agent_search_file_content" /* SEARCH_CONTENT */,
|
|
209
|
+
description: "Search the contents of files in a directory tree for a regex pattern. Use this tool when you need to find text or code inside files rather than matching file or directory names.",
|
|
210
|
+
params: {
|
|
211
|
+
path: "(required) The absolute or relative directory path to search.",
|
|
212
|
+
regex: "(required) The regex pattern to match file content against.",
|
|
213
|
+
file_pattern: "(optional) glob pattern like *.ts to limit which files are searched.",
|
|
214
|
+
include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped."
|
|
203
215
|
}
|
|
204
216
|
},
|
|
205
217
|
{
|
|
@@ -268,6 +280,7 @@ var READ_ONLY_TOOLS = [
|
|
|
268
280
|
"agent_list_files" /* LIST_FILES */,
|
|
269
281
|
"agent_read_file" /* FILE_READ */,
|
|
270
282
|
"agent_search_files" /* SEARCH */,
|
|
283
|
+
"agent_search_file_content" /* SEARCH_CONTENT */,
|
|
271
284
|
"agent_list_code_definition_names" /* LIST_CODE_DEF */,
|
|
272
285
|
"agent_browser_action" /* BROWSER */,
|
|
273
286
|
"agent_ask_followup_question" /* ASK */,
|
|
@@ -437,6 +450,7 @@ var toolParamNames = [
|
|
|
437
450
|
"diff",
|
|
438
451
|
"regex",
|
|
439
452
|
"file_pattern",
|
|
453
|
+
"include_node_modules",
|
|
440
454
|
"recursive",
|
|
441
455
|
"action",
|
|
442
456
|
"url",
|
|
@@ -475,6 +489,66 @@ var toolParamNames = [
|
|
|
475
489
|
"start_line",
|
|
476
490
|
"end_line"
|
|
477
491
|
];
|
|
492
|
+
var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
493
|
+
"txt",
|
|
494
|
+
"md",
|
|
495
|
+
"markdown",
|
|
496
|
+
"json",
|
|
497
|
+
"js",
|
|
498
|
+
"mjs",
|
|
499
|
+
"cjs",
|
|
500
|
+
"ts",
|
|
501
|
+
"tsx",
|
|
502
|
+
"jsx",
|
|
503
|
+
"html",
|
|
504
|
+
"htm",
|
|
505
|
+
"css",
|
|
506
|
+
"scss",
|
|
507
|
+
"sass",
|
|
508
|
+
"less",
|
|
509
|
+
"py",
|
|
510
|
+
"java",
|
|
511
|
+
"c",
|
|
512
|
+
"cpp",
|
|
513
|
+
"cc",
|
|
514
|
+
"cxx",
|
|
515
|
+
"h",
|
|
516
|
+
"hpp",
|
|
517
|
+
"cs",
|
|
518
|
+
"go",
|
|
519
|
+
"rs",
|
|
520
|
+
"rb",
|
|
521
|
+
"php",
|
|
522
|
+
"sh",
|
|
523
|
+
"bash",
|
|
524
|
+
"zsh",
|
|
525
|
+
"bat",
|
|
526
|
+
"cmd",
|
|
527
|
+
"ps1",
|
|
528
|
+
"yaml",
|
|
529
|
+
"yml",
|
|
530
|
+
"toml",
|
|
531
|
+
"ini",
|
|
532
|
+
"cfg",
|
|
533
|
+
"conf",
|
|
534
|
+
"xml",
|
|
535
|
+
"svg",
|
|
536
|
+
"csv",
|
|
537
|
+
"log",
|
|
538
|
+
"sql",
|
|
539
|
+
"vue",
|
|
540
|
+
"svelte",
|
|
541
|
+
"astro",
|
|
542
|
+
"graphql",
|
|
543
|
+
"gql",
|
|
544
|
+
"prisma",
|
|
545
|
+
"env",
|
|
546
|
+
"gitignore",
|
|
547
|
+
"dockerfile",
|
|
548
|
+
"makefile",
|
|
549
|
+
"properties",
|
|
550
|
+
"lock"
|
|
551
|
+
]);
|
|
478
552
|
var AgentState = /* @__PURE__ */ ((AgentState2) => {
|
|
479
553
|
AgentState2["IDLE"] = "idle";
|
|
480
554
|
AgentState2["THINKING"] = "thinking";
|
|
@@ -830,15 +904,36 @@ STDERR: ${result.stderr}` });
|
|
|
830
904
|
const path3 = tool.params.path || this.runtime.env.cwd();
|
|
831
905
|
const regexStr = tool.params.regex;
|
|
832
906
|
const filePattern = tool.params.file_pattern;
|
|
907
|
+
const includeNodeModules = tool.params.include_node_modules === "true";
|
|
833
908
|
if (regexStr && path3) {
|
|
834
909
|
try {
|
|
835
910
|
let result;
|
|
836
911
|
if (typeof this.runtime.fs.searchFiles === "function") {
|
|
837
912
|
result = await this.runtime.fs.searchFiles(path3, regexStr, filePattern);
|
|
838
913
|
} else {
|
|
839
|
-
result = await this.searchFiles(path3, regexStr, filePattern);
|
|
914
|
+
result = await this.searchFiles(path3, regexStr, filePattern, includeNodeModules);
|
|
915
|
+
}
|
|
916
|
+
toolResults.push({ tool, result });
|
|
917
|
+
} catch (e) {
|
|
918
|
+
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
919
|
+
}
|
|
920
|
+
} else {
|
|
921
|
+
toolResults.push({ tool, result: `Error: miss path or regex params` });
|
|
922
|
+
}
|
|
923
|
+
} else if (tool.name === "agent_search_file_content" /* SEARCH_CONTENT */) {
|
|
924
|
+
const path3 = tool.params.path || this.runtime.env.cwd();
|
|
925
|
+
const regexStr = tool.params.regex;
|
|
926
|
+
const filePattern = tool.params.file_pattern;
|
|
927
|
+
const includeNodeModules = tool.params.include_node_modules === "true";
|
|
928
|
+
if (regexStr && path3) {
|
|
929
|
+
try {
|
|
930
|
+
let result;
|
|
931
|
+
if (typeof this.runtime.fs.searchFileContent === "function") {
|
|
932
|
+
result = await this.runtime.fs.searchFileContent(path3, regexStr, filePattern);
|
|
933
|
+
} else {
|
|
934
|
+
result = await this.searchFileContent(path3, regexStr, filePattern, includeNodeModules);
|
|
840
935
|
}
|
|
841
|
-
toolResults.push({ tool, result
|
|
936
|
+
toolResults.push({ tool, result });
|
|
842
937
|
} catch (e) {
|
|
843
938
|
toolResults.push({ tool, result: `Error: ${e.message}` });
|
|
844
939
|
}
|
|
@@ -1013,13 +1108,80 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
1013
1108
|
async getHistory() {
|
|
1014
1109
|
return this.memory.getHistory();
|
|
1015
1110
|
}
|
|
1016
|
-
|
|
1111
|
+
/**
|
|
1112
|
+
* 判断文件是否为可进行内容搜索的文本类文件
|
|
1113
|
+
*/
|
|
1114
|
+
isTextFile(name) {
|
|
1115
|
+
const ext = name.includes(".") ? String(name.split(".").pop()).toLowerCase() : "";
|
|
1116
|
+
if (!ext) {
|
|
1117
|
+
return true;
|
|
1118
|
+
}
|
|
1119
|
+
return TEXT_FILE_EXTENSIONS.has(ext);
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* 按文件名/目录名搜索,层级优先(BFS):
|
|
1123
|
+
* 每一层先匹配完当前层级的所有条目,再进入更深的子目录。
|
|
1124
|
+
*/
|
|
1125
|
+
async searchFiles(dirpath, regex, filePattern, includeNodeModules = false) {
|
|
1017
1126
|
const matches = [];
|
|
1018
|
-
const
|
|
1019
|
-
const
|
|
1127
|
+
const MAX_RESULTS = 100;
|
|
1128
|
+
const MAX_DEPTH = 8;
|
|
1020
1129
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1130
|
+
const shouldSkipDir = (name) => SKIP_DIRS.has(name) || name === "node_modules" && !includeNodeModules;
|
|
1131
|
+
const nameRe = new RegExp(regex);
|
|
1132
|
+
const globRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1133
|
+
const queue = [{ dir: dirpath, depth: 0 }];
|
|
1134
|
+
while (queue.length > 0 && matches.length < MAX_RESULTS) {
|
|
1135
|
+
const { dir, depth } = queue.shift();
|
|
1136
|
+
if (depth > MAX_DEPTH) {
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
let entries;
|
|
1140
|
+
try {
|
|
1141
|
+
entries = await this.runtime.fs.readDir(dir, { recursive: false });
|
|
1142
|
+
} catch {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
for (const entry of entries) {
|
|
1146
|
+
if (matches.length >= MAX_RESULTS) {
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1150
|
+
if (entry.isDirectory()) {
|
|
1151
|
+
if (!shouldSkipDir(entry.name)) {
|
|
1152
|
+
if (nameRe.test(entry.name)) {
|
|
1153
|
+
matches.push(`${child}/`);
|
|
1154
|
+
}
|
|
1155
|
+
queue.push({ dir: child, depth: depth + 1 });
|
|
1156
|
+
}
|
|
1157
|
+
} else if (entry.isFile()) {
|
|
1158
|
+
if (globRe && !globRe.test(entry.name)) {
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
if (nameRe.test(entry.name)) {
|
|
1162
|
+
matches.push(child);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (matches.length === 0) {
|
|
1168
|
+
return "No files found.";
|
|
1169
|
+
}
|
|
1170
|
+
return matches.join("\n");
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* 按文件内容搜索:正则匹配文件内容,返回匹配文件路径。
|
|
1174
|
+
*/
|
|
1175
|
+
async searchFileContent(dirpath, regex, filePattern, includeNodeModules = false) {
|
|
1176
|
+
const matches = [];
|
|
1177
|
+
const MAX_RESULTS = 100;
|
|
1178
|
+
const MAX_DEPTH = 8;
|
|
1179
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
|
|
1180
|
+
const shouldSkipDir = (name) => SKIP_DIRS.has(name) || name === "node_modules" && !includeNodeModules;
|
|
1181
|
+
const contentRe = new RegExp(regex);
|
|
1182
|
+
const globRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
|
|
1021
1183
|
const walk = async (dir, depth) => {
|
|
1022
|
-
if (depth >
|
|
1184
|
+
if (depth > MAX_DEPTH || matches.length >= MAX_RESULTS) {
|
|
1023
1185
|
return;
|
|
1024
1186
|
}
|
|
1025
1187
|
let entries;
|
|
@@ -1029,21 +1191,24 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
1029
1191
|
return;
|
|
1030
1192
|
}
|
|
1031
1193
|
for (const entry of entries) {
|
|
1032
|
-
if (matches.length >=
|
|
1194
|
+
if (matches.length >= MAX_RESULTS) {
|
|
1033
1195
|
break;
|
|
1034
1196
|
}
|
|
1035
1197
|
const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
|
|
1036
1198
|
if (entry.isDirectory()) {
|
|
1037
|
-
if (!
|
|
1199
|
+
if (!shouldSkipDir(entry.name)) {
|
|
1038
1200
|
await walk(child, depth + 1);
|
|
1039
1201
|
}
|
|
1040
1202
|
} else if (entry.isFile()) {
|
|
1041
|
-
if (
|
|
1203
|
+
if (!this.isTextFile(entry.name)) {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if (globRe && !globRe.test(entry.name)) {
|
|
1042
1207
|
continue;
|
|
1043
1208
|
}
|
|
1044
1209
|
try {
|
|
1045
|
-
const content =
|
|
1046
|
-
if (contentRe.test(content)) {
|
|
1210
|
+
const content = await this.runtime.fs.readFile(child);
|
|
1211
|
+
if (typeof content === "string" && contentRe.test(content)) {
|
|
1047
1212
|
matches.push(child);
|
|
1048
1213
|
}
|
|
1049
1214
|
} catch {
|
|
@@ -1052,6 +1217,9 @@ ${searchBlock.substring(0, 100)}...`);
|
|
|
1052
1217
|
}
|
|
1053
1218
|
};
|
|
1054
1219
|
await walk(dirpath, 0);
|
|
1220
|
+
if (matches.length === 0) {
|
|
1221
|
+
return "No files found with matching content.";
|
|
1222
|
+
}
|
|
1055
1223
|
return matches.join("\n");
|
|
1056
1224
|
}
|
|
1057
1225
|
};
|