@amical/aiagent-sdk 0.1.9 → 0.1.11

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 CHANGED
@@ -21,7 +21,8 @@ interface IAgentRuntime {
21
21
  * @param filePattern (可选) 文件名匹配模式,比如 '*.ts'
22
22
  * @returns 返回格式化后的包含上下文的搜索结果字符串
23
23
  */
24
- searchFiles?(path: string, regex: string, filePattern?: string): Promise<string>;
24
+ searchFiles?(path: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
25
+ searchFileContent?(path: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
25
26
  };
26
27
  path: {
27
28
  join(...paths: string[]): string;
@@ -59,6 +60,7 @@ declare enum AgentDefaultTool {
59
60
  FILE_DELETE = "agent_delete_file",
60
61
  DIR_DELETE = "agent_delete_directory",
61
62
  SEARCH = "agent_search_files",
63
+ SEARCH_CONTENT = "agent_search_file_content",
62
64
  LIST_FILES = "agent_list_files",
63
65
  LIST_CODE_DEF = "agent_list_code_definition_names",
64
66
  BROWSER = "agent_browser_action",
@@ -137,11 +139,21 @@ declare const defaultTools: readonly [{
137
139
  };
138
140
  }, {
139
141
  readonly name: AgentDefaultTool.SEARCH;
140
- readonly description: "Search for files in a directory that match a regex pattern or glob pattern.";
142
+ readonly 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.";
141
143
  readonly params: {
142
144
  readonly path: "(required) The absolute or relative directory path to search.";
143
- readonly regex: "(required) The regex pattern to match files against.";
145
+ readonly regex: "(required) The regex pattern to match file or directory names against.";
144
146
  readonly file_pattern: "(optional) glob pattern like *.ts.";
147
+ readonly include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped.";
148
+ };
149
+ }, {
150
+ readonly name: AgentDefaultTool.SEARCH_CONTENT;
151
+ readonly 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.";
152
+ readonly params: {
153
+ readonly path: "(required) The absolute or relative directory path to search.";
154
+ readonly regex: "(required) The regex pattern to match file content against.";
155
+ readonly file_pattern: "(optional) glob pattern like *.ts to limit which files are searched.";
156
+ readonly include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped.";
145
157
  };
146
158
  }, {
147
159
  readonly name: AgentDefaultTool.LIST_FILES;
@@ -166,7 +178,44 @@ declare const defaultTools: readonly [{
166
178
  declare const toolUseNames: AgentDefaultTool[];
167
179
  declare function setDynamicToolUseNames(namespace: string, names: string[]): void;
168
180
  declare function getToolUseNames(): string[];
169
- declare const READ_ONLY_TOOLS: readonly [AgentDefaultTool.LIST_FILES, AgentDefaultTool.FILE_READ, AgentDefaultTool.SEARCH, AgentDefaultTool.LIST_CODE_DEF, AgentDefaultTool.BROWSER, AgentDefaultTool.ASK, AgentDefaultTool.WEB_SEARCH, AgentDefaultTool.WEB_FETCH, AgentDefaultTool.LOAD_SKILL, AgentDefaultTool.USE_SUBAGENTS];
181
+ declare const READ_ONLY_TOOLS: readonly [AgentDefaultTool.LIST_FILES, AgentDefaultTool.FILE_READ, AgentDefaultTool.SEARCH, AgentDefaultTool.SEARCH_CONTENT, AgentDefaultTool.LIST_CODE_DEF, AgentDefaultTool.BROWSER, AgentDefaultTool.ASK, AgentDefaultTool.WEB_SEARCH, AgentDefaultTool.WEB_FETCH, AgentDefaultTool.LOAD_SKILL, AgentDefaultTool.USE_SUBAGENTS];
182
+
183
+ /**
184
+ * 自定义工具的数据结构与渲染辅助函数。
185
+ *
186
+ * 自定义工具支持“工具集(tool group)”结构:
187
+ * - 顶层只展示工具集入口(name/description/params),避免系统提示词臃肿。
188
+ * - 当 Agent 调用某个工具集入口时,才把该集合的 children 注册为可用工具,
189
+ * 并将其 prompt 描述作为工具调用结果返回给模型。
190
+ */
191
+ interface CustomToolDefinition {
192
+ name: string;
193
+ description: string;
194
+ params?: Record<string, string>;
195
+ onCall?: (params: Record<string, any>) => Promise<any> | any;
196
+ /**
197
+ * 子工具。存在时表示该工具为“工具集入口”,初始不展开 children。
198
+ */
199
+ children?: CustomToolDefinition[];
200
+ }
201
+ /**
202
+ * 判断一个自定义工具是否为工具集入口。
203
+ */
204
+ declare function isCustomToolGroup(tool: CustomToolDefinition): boolean;
205
+ /**
206
+ * 递归收集所有自定义工具名(含嵌套 children),用于全局唯一性校验。
207
+ */
208
+ declare function collectCustomToolNames(tools: CustomToolDefinition[]): string[];
209
+ /**
210
+ * 将单个工具定义渲染为系统提示词中的工具说明块。
211
+ *
212
+ * 注意:该函数只渲染工具自身的 name/description/params,不会展开 children。
213
+ */
214
+ declare function renderCustomToolPrompt(tool: CustomToolDefinition, cwd?: string): string;
215
+ /**
216
+ * 批量渲染工具说明。
217
+ */
218
+ declare function renderCustomToolsPrompt(tools: CustomToolDefinition[], cwd?: string): string;
170
219
 
171
220
  /**
172
221
  * @description **Version 2**
@@ -198,7 +247,7 @@ interface TextStreamContent {
198
247
  content: string;
199
248
  partial: boolean;
200
249
  }
201
- declare const toolParamNames: readonly ["command", "requires_approval", "path", "absolutePath", "content", "diff", "regex", "file_pattern", "recursive", "action", "url", "coordinate", "text", "query", "allowed_domains", "blocked_domains", "prompt", "server_name", "tool_name", "arguments", "uri", "question", "options", "response", "result", "context", "title", "what_happened", "steps_to_reproduce", "api_request_output", "additional_context", "needs_more_exploration", "task_progress", "timeout", "input", "from_ref", "to_ref", "skill_name", "prompt_1", "prompt_2", "prompt_3", "prompt_4", "prompt_5", "start_line", "end_line"];
250
+ declare const toolParamNames: readonly ["command", "requires_approval", "path", "absolutePath", "content", "diff", "regex", "file_pattern", "include_node_modules", "recursive", "action", "url", "coordinate", "text", "query", "allowed_domains", "blocked_domains", "prompt", "server_name", "tool_name", "arguments", "uri", "question", "options", "response", "result", "context", "title", "what_happened", "steps_to_reproduce", "api_request_output", "additional_context", "needs_more_exploration", "task_progress", "timeout", "input", "from_ref", "to_ref", "skill_name", "prompt_1", "prompt_2", "prompt_3", "prompt_4", "prompt_5", "start_line", "end_line"];
202
251
  type ToolParamName = (typeof toolParamNames)[number];
203
252
  interface ToolUse {
204
253
  type: "tool_use";
@@ -405,7 +454,7 @@ interface AgentOptions {
405
454
  promptManager: IPromptManager;
406
455
  memory: IMemoryManager;
407
456
  mcp?: IMcpManager;
408
- customTools?: any[];
457
+ customTools?: CustomToolDefinition[];
409
458
  allowDefaultTools?: string[];
410
459
  customInstructions?: string;
411
460
  /** 最大循环次数,默认150 */
@@ -439,10 +488,20 @@ declare class ClineAgent {
439
488
  private maxLoopCount;
440
489
  skillDir: string;
441
490
  rulesDir: string;
442
- customTools: any[];
491
+ customTools: CustomToolDefinition[];
492
+ /** 当前可用(已展开集合)的顶层工具列表,传给 PromptManager 渲染 */
493
+ activeCustomTools: CustomToolDefinition[];
494
+ /** 所有已知工具名(含未激活 children),便于查找定义 */
495
+ customToolsByName: Map<string, CustomToolDefinition>;
443
496
  customToolNames: Set<string>;
444
497
  allowDefaultTools?: string[];
445
498
  customInstructions?: string;
499
+ /** 已激活的工具集入口名 */
500
+ private activatedGroups;
501
+ /** activeCustomTools 变更版本号,用于 Prompt 缓存失效 */
502
+ private activeToolsVersion;
503
+ /** 缓存 sysPrompt 时记录的版本号 */
504
+ private promptActiveToolsVersion;
446
505
  sysPrompt?: string;
447
506
  noUseTollSysPrompt?: string;
448
507
  onStateChange?: (state: AgentState) => void;
@@ -474,6 +533,14 @@ declare class ClineAgent {
474
533
  * 核心任务循环
475
534
  */
476
535
  private loop;
536
+ /**
537
+ * 激活自定义工具集:将入口的 children 注册到活跃工具列表并返回渲染后的 prompt。
538
+ */
539
+ private activateCustomToolGroup;
540
+ /**
541
+ * 检查自上次获取 prompt 后是否有工具集被激活,若有则刷新缓存。
542
+ */
543
+ private getCurrentPrompt;
477
544
  /**
478
545
  * 简单的 Diff 解析与替换辅助方法
479
546
  */
@@ -484,9 +551,21 @@ declare class ClineAgent {
484
551
  resume(userInput?: string): Promise<void>;
485
552
  appendHistory(history: AgentMessage[]): Promise<void>;
486
553
  getHistory(): Promise<AgentMessage[]>;
487
- searchFiles(dirpath: string, regex: string, filePattern?: string): Promise<string>;
554
+ /**
555
+ * 判断文件是否为可进行内容搜索的文本类文件
556
+ */
557
+ private isTextFile;
558
+ /**
559
+ * 按文件名/目录名搜索,层级优先(BFS):
560
+ * 每一层先匹配完当前层级的所有条目,再进入更深的子目录。
561
+ */
562
+ searchFiles(dirpath: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
563
+ /**
564
+ * 按文件内容搜索:正则匹配文件内容,返回匹配文件路径。
565
+ */
566
+ searchFileContent(dirpath: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
488
567
  }
489
568
 
490
569
  declare const VERSION = "0.1.0";
491
570
 
492
- export { AgentDefaultTool, type AgentMessage, type AgentOptions, AgentState, type ApiProviderInfo, type ApiStreamChunk, type AssistantMessageContent, ClineAgent, type IAgentRuntime, type IApiHandler, type IMcpManager, type IMemoryManager, type IPromptManager, type McpServerInfo, type McpTool, type McpToolCallResult, READ_ONLY_TOOLS, type ReasoningStreamContent, TOOL_RESULT_BLOCK, type TextStreamContent, type ToolParamName, type ToolUse, VERSION, defaultTools, getToolUseNames, parseAssistantMessageV2, setDynamicToolUseNames, toolParamNames, toolUseNames };
571
+ export { AgentDefaultTool, type AgentMessage, type AgentOptions, AgentState, type ApiProviderInfo, type ApiStreamChunk, type AssistantMessageContent, ClineAgent, type CustomToolDefinition, type IAgentRuntime, type IApiHandler, type IMcpManager, type IMemoryManager, type IPromptManager, type McpServerInfo, type McpTool, type McpToolCallResult, READ_ONLY_TOOLS, type ReasoningStreamContent, TOOL_RESULT_BLOCK, type TextStreamContent, type ToolParamName, type ToolUse, VERSION, collectCustomToolNames, defaultTools, getToolUseNames, isCustomToolGroup, parseAssistantMessageV2, renderCustomToolPrompt, renderCustomToolsPrompt, setDynamicToolUseNames, toolParamNames, toolUseNames };
package/dist/index.d.ts CHANGED
@@ -21,7 +21,8 @@ interface IAgentRuntime {
21
21
  * @param filePattern (可选) 文件名匹配模式,比如 '*.ts'
22
22
  * @returns 返回格式化后的包含上下文的搜索结果字符串
23
23
  */
24
- searchFiles?(path: string, regex: string, filePattern?: string): Promise<string>;
24
+ searchFiles?(path: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
25
+ searchFileContent?(path: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
25
26
  };
26
27
  path: {
27
28
  join(...paths: string[]): string;
@@ -59,6 +60,7 @@ declare enum AgentDefaultTool {
59
60
  FILE_DELETE = "agent_delete_file",
60
61
  DIR_DELETE = "agent_delete_directory",
61
62
  SEARCH = "agent_search_files",
63
+ SEARCH_CONTENT = "agent_search_file_content",
62
64
  LIST_FILES = "agent_list_files",
63
65
  LIST_CODE_DEF = "agent_list_code_definition_names",
64
66
  BROWSER = "agent_browser_action",
@@ -137,11 +139,21 @@ declare const defaultTools: readonly [{
137
139
  };
138
140
  }, {
139
141
  readonly name: AgentDefaultTool.SEARCH;
140
- readonly description: "Search for files in a directory that match a regex pattern or glob pattern.";
142
+ readonly 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.";
141
143
  readonly params: {
142
144
  readonly path: "(required) The absolute or relative directory path to search.";
143
- readonly regex: "(required) The regex pattern to match files against.";
145
+ readonly regex: "(required) The regex pattern to match file or directory names against.";
144
146
  readonly file_pattern: "(optional) glob pattern like *.ts.";
147
+ readonly include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped.";
148
+ };
149
+ }, {
150
+ readonly name: AgentDefaultTool.SEARCH_CONTENT;
151
+ readonly 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.";
152
+ readonly params: {
153
+ readonly path: "(required) The absolute or relative directory path to search.";
154
+ readonly regex: "(required) The regex pattern to match file content against.";
155
+ readonly file_pattern: "(optional) glob pattern like *.ts to limit which files are searched.";
156
+ readonly include_node_modules: "(optional) set to true to include node_modules in the search. Defaults to false, so node_modules is skipped.";
145
157
  };
146
158
  }, {
147
159
  readonly name: AgentDefaultTool.LIST_FILES;
@@ -166,7 +178,44 @@ declare const defaultTools: readonly [{
166
178
  declare const toolUseNames: AgentDefaultTool[];
167
179
  declare function setDynamicToolUseNames(namespace: string, names: string[]): void;
168
180
  declare function getToolUseNames(): string[];
169
- declare const READ_ONLY_TOOLS: readonly [AgentDefaultTool.LIST_FILES, AgentDefaultTool.FILE_READ, AgentDefaultTool.SEARCH, AgentDefaultTool.LIST_CODE_DEF, AgentDefaultTool.BROWSER, AgentDefaultTool.ASK, AgentDefaultTool.WEB_SEARCH, AgentDefaultTool.WEB_FETCH, AgentDefaultTool.LOAD_SKILL, AgentDefaultTool.USE_SUBAGENTS];
181
+ declare const READ_ONLY_TOOLS: readonly [AgentDefaultTool.LIST_FILES, AgentDefaultTool.FILE_READ, AgentDefaultTool.SEARCH, AgentDefaultTool.SEARCH_CONTENT, AgentDefaultTool.LIST_CODE_DEF, AgentDefaultTool.BROWSER, AgentDefaultTool.ASK, AgentDefaultTool.WEB_SEARCH, AgentDefaultTool.WEB_FETCH, AgentDefaultTool.LOAD_SKILL, AgentDefaultTool.USE_SUBAGENTS];
182
+
183
+ /**
184
+ * 自定义工具的数据结构与渲染辅助函数。
185
+ *
186
+ * 自定义工具支持“工具集(tool group)”结构:
187
+ * - 顶层只展示工具集入口(name/description/params),避免系统提示词臃肿。
188
+ * - 当 Agent 调用某个工具集入口时,才把该集合的 children 注册为可用工具,
189
+ * 并将其 prompt 描述作为工具调用结果返回给模型。
190
+ */
191
+ interface CustomToolDefinition {
192
+ name: string;
193
+ description: string;
194
+ params?: Record<string, string>;
195
+ onCall?: (params: Record<string, any>) => Promise<any> | any;
196
+ /**
197
+ * 子工具。存在时表示该工具为“工具集入口”,初始不展开 children。
198
+ */
199
+ children?: CustomToolDefinition[];
200
+ }
201
+ /**
202
+ * 判断一个自定义工具是否为工具集入口。
203
+ */
204
+ declare function isCustomToolGroup(tool: CustomToolDefinition): boolean;
205
+ /**
206
+ * 递归收集所有自定义工具名(含嵌套 children),用于全局唯一性校验。
207
+ */
208
+ declare function collectCustomToolNames(tools: CustomToolDefinition[]): string[];
209
+ /**
210
+ * 将单个工具定义渲染为系统提示词中的工具说明块。
211
+ *
212
+ * 注意:该函数只渲染工具自身的 name/description/params,不会展开 children。
213
+ */
214
+ declare function renderCustomToolPrompt(tool: CustomToolDefinition, cwd?: string): string;
215
+ /**
216
+ * 批量渲染工具说明。
217
+ */
218
+ declare function renderCustomToolsPrompt(tools: CustomToolDefinition[], cwd?: string): string;
170
219
 
171
220
  /**
172
221
  * @description **Version 2**
@@ -198,7 +247,7 @@ interface TextStreamContent {
198
247
  content: string;
199
248
  partial: boolean;
200
249
  }
201
- declare const toolParamNames: readonly ["command", "requires_approval", "path", "absolutePath", "content", "diff", "regex", "file_pattern", "recursive", "action", "url", "coordinate", "text", "query", "allowed_domains", "blocked_domains", "prompt", "server_name", "tool_name", "arguments", "uri", "question", "options", "response", "result", "context", "title", "what_happened", "steps_to_reproduce", "api_request_output", "additional_context", "needs_more_exploration", "task_progress", "timeout", "input", "from_ref", "to_ref", "skill_name", "prompt_1", "prompt_2", "prompt_3", "prompt_4", "prompt_5", "start_line", "end_line"];
250
+ declare const toolParamNames: readonly ["command", "requires_approval", "path", "absolutePath", "content", "diff", "regex", "file_pattern", "include_node_modules", "recursive", "action", "url", "coordinate", "text", "query", "allowed_domains", "blocked_domains", "prompt", "server_name", "tool_name", "arguments", "uri", "question", "options", "response", "result", "context", "title", "what_happened", "steps_to_reproduce", "api_request_output", "additional_context", "needs_more_exploration", "task_progress", "timeout", "input", "from_ref", "to_ref", "skill_name", "prompt_1", "prompt_2", "prompt_3", "prompt_4", "prompt_5", "start_line", "end_line"];
202
251
  type ToolParamName = (typeof toolParamNames)[number];
203
252
  interface ToolUse {
204
253
  type: "tool_use";
@@ -405,7 +454,7 @@ interface AgentOptions {
405
454
  promptManager: IPromptManager;
406
455
  memory: IMemoryManager;
407
456
  mcp?: IMcpManager;
408
- customTools?: any[];
457
+ customTools?: CustomToolDefinition[];
409
458
  allowDefaultTools?: string[];
410
459
  customInstructions?: string;
411
460
  /** 最大循环次数,默认150 */
@@ -439,10 +488,20 @@ declare class ClineAgent {
439
488
  private maxLoopCount;
440
489
  skillDir: string;
441
490
  rulesDir: string;
442
- customTools: any[];
491
+ customTools: CustomToolDefinition[];
492
+ /** 当前可用(已展开集合)的顶层工具列表,传给 PromptManager 渲染 */
493
+ activeCustomTools: CustomToolDefinition[];
494
+ /** 所有已知工具名(含未激活 children),便于查找定义 */
495
+ customToolsByName: Map<string, CustomToolDefinition>;
443
496
  customToolNames: Set<string>;
444
497
  allowDefaultTools?: string[];
445
498
  customInstructions?: string;
499
+ /** 已激活的工具集入口名 */
500
+ private activatedGroups;
501
+ /** activeCustomTools 变更版本号,用于 Prompt 缓存失效 */
502
+ private activeToolsVersion;
503
+ /** 缓存 sysPrompt 时记录的版本号 */
504
+ private promptActiveToolsVersion;
446
505
  sysPrompt?: string;
447
506
  noUseTollSysPrompt?: string;
448
507
  onStateChange?: (state: AgentState) => void;
@@ -474,6 +533,14 @@ declare class ClineAgent {
474
533
  * 核心任务循环
475
534
  */
476
535
  private loop;
536
+ /**
537
+ * 激活自定义工具集:将入口的 children 注册到活跃工具列表并返回渲染后的 prompt。
538
+ */
539
+ private activateCustomToolGroup;
540
+ /**
541
+ * 检查自上次获取 prompt 后是否有工具集被激活,若有则刷新缓存。
542
+ */
543
+ private getCurrentPrompt;
477
544
  /**
478
545
  * 简单的 Diff 解析与替换辅助方法
479
546
  */
@@ -484,9 +551,21 @@ declare class ClineAgent {
484
551
  resume(userInput?: string): Promise<void>;
485
552
  appendHistory(history: AgentMessage[]): Promise<void>;
486
553
  getHistory(): Promise<AgentMessage[]>;
487
- searchFiles(dirpath: string, regex: string, filePattern?: string): Promise<string>;
554
+ /**
555
+ * 判断文件是否为可进行内容搜索的文本类文件
556
+ */
557
+ private isTextFile;
558
+ /**
559
+ * 按文件名/目录名搜索,层级优先(BFS):
560
+ * 每一层先匹配完当前层级的所有条目,再进入更深的子目录。
561
+ */
562
+ searchFiles(dirpath: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
563
+ /**
564
+ * 按文件内容搜索:正则匹配文件内容,返回匹配文件路径。
565
+ */
566
+ searchFileContent(dirpath: string, regex: string, filePattern?: string, includeNodeModules?: boolean): Promise<string>;
488
567
  }
489
568
 
490
569
  declare const VERSION = "0.1.0";
491
570
 
492
- export { AgentDefaultTool, type AgentMessage, type AgentOptions, AgentState, type ApiProviderInfo, type ApiStreamChunk, type AssistantMessageContent, ClineAgent, type IAgentRuntime, type IApiHandler, type IMcpManager, type IMemoryManager, type IPromptManager, type McpServerInfo, type McpTool, type McpToolCallResult, READ_ONLY_TOOLS, type ReasoningStreamContent, TOOL_RESULT_BLOCK, type TextStreamContent, type ToolParamName, type ToolUse, VERSION, defaultTools, getToolUseNames, parseAssistantMessageV2, setDynamicToolUseNames, toolParamNames, toolUseNames };
571
+ export { AgentDefaultTool, type AgentMessage, type AgentOptions, AgentState, type ApiProviderInfo, type ApiStreamChunk, type AssistantMessageContent, ClineAgent, type CustomToolDefinition, type IAgentRuntime, type IApiHandler, type IMcpManager, type IMemoryManager, type IPromptManager, type McpServerInfo, type McpTool, type McpToolCallResult, READ_ONLY_TOOLS, type ReasoningStreamContent, TOOL_RESULT_BLOCK, type TextStreamContent, type ToolParamName, type ToolUse, VERSION, collectCustomToolNames, defaultTools, getToolUseNames, isCustomToolGroup, parseAssistantMessageV2, renderCustomToolPrompt, renderCustomToolsPrompt, setDynamicToolUseNames, toolParamNames, toolUseNames };