@saber2pr/ai-agent 0.0.28 → 0.0.29

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.
@@ -1,65 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonSchemaToZod = jsonSchemaToZod;
4
- const zod_1 = require("zod");
4
+ const zod_from_json_schema_1 = require("zod-from-json-schema");
5
5
  function jsonSchemaToZod(parameters) {
6
- var _a;
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.28",
3
+ "version": "0.0.29",
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": {