@saber2pr/ai-agent 0.0.10 → 0.0.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/README.md +1 -1
- package/lib/core/agent-chain.d.ts +1 -2
- package/lib/core/agent-chain.js +42 -51
- package/lib/core/agent.d.ts +1 -1
- package/lib/core/agent.js +15 -25
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/tools/builtin.d.ts +0 -2
- package/lib/tools/builtin.js +5 -91
- package/lib/tools/filesystem/index.d.ts +1 -0
- package/lib/tools/filesystem/index.js +338 -0
- package/lib/tools/filesystem/lib.d.ts +34 -0
- package/lib/tools/filesystem/lib.js +330 -0
- package/lib/tools/filesystem/path-utils.d.ts +18 -0
- package/lib/tools/filesystem/path-utils.js +111 -0
- package/lib/tools/filesystem/path-validation.d.ts +9 -0
- package/lib/tools/filesystem/path-validation.js +81 -0
- package/lib/tools/filesystem/roots-utils.d.ts +12 -0
- package/lib/tools/filesystem/roots-utils.js +76 -0
- package/lib/tools/ts-lsp/index.d.ts +1 -0
- package/lib/tools/ts-lsp/index.js +56 -0
- package/lib/types/type.d.ts +1 -8
- package/lib/utils/createTool.d.ts +1 -3
- package/lib/utils/createTool.js +0 -3
- package/package.json +5 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTsLspTools = void 0;
|
|
4
|
+
const ts_context_mcp_1 = require("@saber2pr/ts-context-mcp");
|
|
5
|
+
const createTool_1 = require("../../utils/createTool");
|
|
6
|
+
const getTsLspTools = (targetDir) => {
|
|
7
|
+
const engine = new ts_context_mcp_1.PromptEngine(targetDir);
|
|
8
|
+
return [
|
|
9
|
+
(0, createTool_1.createTool)({
|
|
10
|
+
name: "get_repo_map",
|
|
11
|
+
description: "获取项目全局文件结构及导出清单,用于快速定位代码",
|
|
12
|
+
parameters: { type: "object", properties: {} },
|
|
13
|
+
handler: async () => {
|
|
14
|
+
engine.refresh();
|
|
15
|
+
return engine.getRepoMap();
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
(0, createTool_1.createTool)({
|
|
19
|
+
name: "analyze_deps",
|
|
20
|
+
description: "分析指定文件的依赖关系,支持 tsconfig 路径别名解析",
|
|
21
|
+
parameters: { type: "object", properties: { filePath: { type: "string", description: "文件相对路径" } } },
|
|
22
|
+
validateParams: ["filePath"],
|
|
23
|
+
handler: async ({ filePath }) => engine.getDeps(filePath),
|
|
24
|
+
}),
|
|
25
|
+
(0, createTool_1.createTool)({
|
|
26
|
+
name: "read_skeleton",
|
|
27
|
+
description: "提取文件的结构定义(接口、类、方法签名),忽略具体实现以节省 Token",
|
|
28
|
+
parameters: { type: "object", properties: { filePath: { type: "string", description: "文件相对路径" } } },
|
|
29
|
+
validateParams: ["filePath"],
|
|
30
|
+
handler: async (args) => {
|
|
31
|
+
const pathArg = args === null || args === void 0 ? void 0 : args.filePath;
|
|
32
|
+
if (typeof pathArg !== "string" || pathArg.trim() === "") {
|
|
33
|
+
return `Error: 参数 'filePath' 无效。收到的是: ${JSON.stringify(pathArg)}`;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
engine.refresh();
|
|
37
|
+
const result = engine.getSkeleton(pathArg);
|
|
38
|
+
return result || `// Warning: 文件 ${pathArg} 存在但未找到任何可提取的结构。`;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return `Error: 解析文件 ${pathArg} 时发生内部错误: ${error.message}`;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
(0, createTool_1.createTool)({
|
|
46
|
+
name: "get_method_body",
|
|
47
|
+
description: "获取指定文件内某个方法或函数的完整实现代码",
|
|
48
|
+
parameters: { type: "object", properties: { filePath: { type: "string", description: "文件相对路径" }, methodName: { type: "string", description: "方法名或函数名" } } },
|
|
49
|
+
validateParams: ["filePath", 'methodName'],
|
|
50
|
+
handler: async ({ filePath, methodName }) => {
|
|
51
|
+
return engine.getMethodImplementation(filePath, methodName);
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
exports.getTsLspTools = getTsLspTools;
|
package/lib/types/type.d.ts
CHANGED
|
@@ -16,12 +16,6 @@ export interface ToolInfo {
|
|
|
16
16
|
_client?: Client;
|
|
17
17
|
_originalName?: string;
|
|
18
18
|
}
|
|
19
|
-
export interface CustomTool {
|
|
20
|
-
name: string;
|
|
21
|
-
description: string;
|
|
22
|
-
parameters: any;
|
|
23
|
-
handler: (args: any) => Promise<any>;
|
|
24
|
-
}
|
|
25
19
|
export interface McpConfig {
|
|
26
20
|
mcpServers: {
|
|
27
21
|
[key: string]: {
|
|
@@ -34,8 +28,7 @@ export interface McpConfig {
|
|
|
34
28
|
export interface AgentOptions {
|
|
35
29
|
targetDir?: string;
|
|
36
30
|
/** 外部传入的内置工具列表,不传则使用默认的 registerBuiltinTools */
|
|
37
|
-
|
|
38
|
-
tools?: CustomTool[];
|
|
31
|
+
tools?: ToolInfo[];
|
|
39
32
|
extraSystemPrompt?: any;
|
|
40
33
|
maxTokens?: number;
|
|
41
34
|
apiConfig?: ApiConfig;
|
|
@@ -3,9 +3,7 @@ export interface CreateToolOptions {
|
|
|
3
3
|
name: string;
|
|
4
4
|
description: string;
|
|
5
5
|
parameters: any;
|
|
6
|
-
handler: (args: any) => Promise<
|
|
7
|
-
maxTokens: number;
|
|
8
|
-
getCurrentTokens: () => number;
|
|
6
|
+
handler: (args: any) => Promise<string>;
|
|
9
7
|
validateParams?: string[];
|
|
10
8
|
}
|
|
11
9
|
export declare function createTool(options: CreateToolOptions): ToolInfo;
|
package/lib/utils/createTool.js
CHANGED
|
@@ -11,9 +11,6 @@ function createTool(options) {
|
|
|
11
11
|
},
|
|
12
12
|
_handler: async (input) => {
|
|
13
13
|
var _a;
|
|
14
|
-
if (options.getCurrentTokens && options.maxTokens != null && options.getCurrentTokens() > options.maxTokens) {
|
|
15
|
-
return `[SYSTEM WARNING]: Token 消耗已达上限,禁止获取详细方法体。请利用已获取的 Skeleton 信息进行分析。`;
|
|
16
|
-
}
|
|
17
14
|
// 兼容处理:如果 input 是字符串,尝试解析为 JSON 对象
|
|
18
15
|
let args = input;
|
|
19
16
|
if (typeof input === 'string') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saber2pr/ai-agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "AI Assistant CLI.",
|
|
5
5
|
"author": "saber2pr",
|
|
6
6
|
"license": "ISC",
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"@saber2pr/ts-context-mcp": "^0.0.6",
|
|
29
29
|
"js-tiktoken": "^1.0.21",
|
|
30
30
|
"langchain": "~0.3",
|
|
31
|
-
"openai": "^6.16.0"
|
|
31
|
+
"openai": "^6.16.0",
|
|
32
|
+
"diff": "^8.0.3",
|
|
33
|
+
"glob": "^10.5.0",
|
|
34
|
+
"minimatch": "^10.0.1"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"@types/node": "^16.3.3",
|