@saber2pr/ai-agent 0.0.28 → 0.0.30
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/lib/core/agent-graph.js +2 -2
- package/lib/core/agent.js +1 -1
- package/lib/tools/ts-lsp/index.js +1 -1
- package/lib/types/type.d.ts +1 -1
- package/lib/utils/convertToLangChainTool.d.ts +2 -2
- package/lib/utils/createTool.d.ts +1 -1
- package/lib/utils/jsonSchemaToZod.js +2 -60
- package/package.json +2 -1
package/lib/core/agent-graph.js
CHANGED
|
@@ -14,10 +14,10 @@ const prompts_1 = require("@langchain/core/prompts");
|
|
|
14
14
|
const langgraph_1 = require("@langchain/langgraph");
|
|
15
15
|
const prebuilt_1 = require("@langchain/langgraph/prebuilt");
|
|
16
16
|
const openai_1 = require("@langchain/openai");
|
|
17
|
-
const builtin_1 = require("../tools/builtin");
|
|
18
|
-
const convertToLangChainTool_1 = require("../utils/convertToLangChainTool");
|
|
19
17
|
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
20
18
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
19
|
+
const builtin_1 = require("../tools/builtin");
|
|
20
|
+
const convertToLangChainTool_1 = require("../utils/convertToLangChainTool");
|
|
21
21
|
const jsonSchemaToZod_1 = require("../utils/jsonSchemaToZod");
|
|
22
22
|
exports.CONFIG_FILE = path_1.default.join(os_1.default.homedir(), ".saber2pr-agent.json");
|
|
23
23
|
// ✅ 全局设置:修复 AbortSignal 监听器数量警告
|
package/lib/core/agent.js
CHANGED
|
@@ -42,11 +42,11 @@ const openai_1 = __importDefault(require("openai"));
|
|
|
42
42
|
const os_1 = __importDefault(require("os"));
|
|
43
43
|
const path_1 = __importDefault(require("path"));
|
|
44
44
|
const readline = __importStar(require("readline"));
|
|
45
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
45
46
|
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
46
47
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
47
48
|
const config_1 = require("../config/config");
|
|
48
49
|
const builtin_1 = require("../tools/builtin");
|
|
49
|
-
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
50
50
|
const jsonSchemaToZod_1 = require("../utils/jsonSchemaToZod");
|
|
51
51
|
class McpAgent {
|
|
52
52
|
constructor(options) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTsLspTools = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
4
5
|
const ts_context_mcp_1 = require("@saber2pr/ts-context-mcp");
|
|
5
6
|
const createTool_1 = require("../../utils/createTool");
|
|
6
|
-
const zod_1 = require("zod");
|
|
7
7
|
const getTsLspTools = (targetDir) => {
|
|
8
8
|
const engine = new ts_context_mcp_1.PromptEngine(targetDir);
|
|
9
9
|
return [
|
package/lib/types/type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index';
|
|
2
1
|
import { z } from 'zod';
|
|
2
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index';
|
|
3
3
|
import { AgentGraphModel } from '../model/AgentGraphModel';
|
|
4
4
|
export interface ApiConfig {
|
|
5
5
|
baseURL: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicStructuredTool } from
|
|
2
|
-
import { ToolInfo } from
|
|
1
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { ToolInfo } from '../types/type';
|
|
3
3
|
export declare function convertToLangChainTool(info: ToolInfo): DynamicStructuredTool<import("zod").ZodObject<any, import("zod").UnknownKeysParam, import("zod").ZodTypeAny, {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
}, {
|
|
@@ -1,65 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsonSchemaToZod = jsonSchemaToZod;
|
|
4
|
-
const
|
|
4
|
+
const zod_from_json_schema_1 = require("zod-from-json-schema");
|
|
5
5
|
function jsonSchemaToZod(parameters) {
|
|
6
|
-
|
|
7
|
-
// ✅ 跨版本/跨实例的特征检测
|
|
8
|
-
const isZod = parameters && (typeof parameters.safeParse === 'function' || // 所有 Zod 类型都有
|
|
9
|
-
!!parameters._def || // Zod 内部定义属性
|
|
10
|
-
!!parameters.shape // 专门针对 ZodObject 的特征
|
|
11
|
-
);
|
|
12
|
-
if (isZod) {
|
|
13
|
-
return parameters;
|
|
14
|
-
}
|
|
15
|
-
if (!parameters || typeof parameters !== 'object') {
|
|
16
|
-
return zod_1.z.object({}).passthrough();
|
|
17
|
-
}
|
|
18
|
-
// 辅助函数:递归转换单个属性
|
|
19
|
-
function convertProp(prop) {
|
|
20
|
-
let schema = zod_1.z.any();
|
|
21
|
-
if (prop.type === "string") {
|
|
22
|
-
schema = zod_1.z.string();
|
|
23
|
-
}
|
|
24
|
-
else if (prop.type === "number") {
|
|
25
|
-
schema = zod_1.z.number();
|
|
26
|
-
}
|
|
27
|
-
else if (prop.type === "boolean") {
|
|
28
|
-
schema = zod_1.z.boolean();
|
|
29
|
-
}
|
|
30
|
-
else if (prop.type === "array") {
|
|
31
|
-
// 递归处理数组项
|
|
32
|
-
if (prop.items) {
|
|
33
|
-
schema = zod_1.z.array(convertProp(prop.items));
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
schema = zod_1.z.array(zod_1.z.any());
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (prop.type === "object") {
|
|
40
|
-
// 递归处理嵌套对象
|
|
41
|
-
const nestedObj = {};
|
|
42
|
-
if (prop.properties) {
|
|
43
|
-
for (const key in prop.properties) {
|
|
44
|
-
nestedObj[key] = convertProp(prop.properties[key]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
schema = zod_1.z.object(nestedObj).passthrough();
|
|
48
|
-
}
|
|
49
|
-
if (prop.description) {
|
|
50
|
-
schema = schema.describe(prop.description);
|
|
51
|
-
}
|
|
52
|
-
return schema;
|
|
53
|
-
}
|
|
54
|
-
const obj = {};
|
|
55
|
-
const properties = parameters.properties || {};
|
|
56
|
-
for (const key in properties) {
|
|
57
|
-
const prop = properties[key];
|
|
58
|
-
let schema = convertProp(prop);
|
|
59
|
-
// 处理必填项
|
|
60
|
-
const isRequired = (_a = parameters.required) === null || _a === void 0 ? void 0 : _a.includes(key);
|
|
61
|
-
obj[key] = isRequired ? schema : schema.nullable();
|
|
62
|
-
}
|
|
63
|
-
// 使用 passthrough 或 loose 以增加容错性
|
|
64
|
-
return zod_1.z.object(obj);
|
|
6
|
+
return (0, zod_from_json_schema_1.convertJsonSchemaToZod)(parameters);
|
|
65
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saber2pr/ai-agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "AI Assistant CLI.",
|
|
5
5
|
"author": "saber2pr",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"minimatch": "^10.0.1",
|
|
36
36
|
"openai": "^6.16.0",
|
|
37
37
|
"zod": "3.25",
|
|
38
|
+
"zod-from-json-schema": "^0.1.0",
|
|
38
39
|
"zod-to-json-schema": "3.23.2"
|
|
39
40
|
},
|
|
40
41
|
"resolutions": {
|