@flink-app/flink 2.0.0-alpha.55 → 2.0.0-alpha.56

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @flink-app/flink
2
2
 
3
+ ## 2.0.0-alpha.56
4
+
5
+ ### Patch Changes
6
+
7
+ - Zod 3.x compat
8
+ - 0203256: fix: add Zod 3.x compatibility for tool schema generation
9
+
10
+ Tools now work with both Zod 3.25+ and Zod 4.x. The `ToolExecutor` will use:
11
+
12
+ - Zod 4's built-in `z.toJSONSchema()` if available
13
+ - `zod-to-json-schema` package for Zod 3.x compatibility (fallback)
14
+
15
+ This allows apps to use their preferred Zod version without upgrading to 4.x.
16
+
17
+ **Changes:**
18
+
19
+ - Improved `fallbackSchema()` to use `zod-to-json-schema` instead of returning empty schema
20
+ - Added Zod as peer dependency (>=3.25.0 <5.0.0) for version flexibility
21
+ - Better error handling and logging for schema generation failures
22
+
23
+ **Migration:** No action needed - fully backward compatible.
24
+
3
25
  ## 2.0.0-alpha.55
4
26
 
5
27
  ### Minor Changes
@@ -9,7 +9,8 @@ export declare class ToolExecutor<Ctx extends FlinkContext> {
9
9
  execute(input: any, user?: any, userPermissions?: string[]): Promise<ToolResult<any>>;
10
10
  getToolSchema(): FlinkToolSchema;
11
11
  /**
12
- * Fallback schema generation if toJSONSchema is not available
12
+ * Fallback schema generation for Zod 3.x compatibility
13
+ * Uses zod-to-json-schema package which supports both Zod 3.x and 4.x
13
14
  */
14
15
  private fallbackSchema;
15
16
  /**
@@ -35,6 +35,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __rest = (this && this.__rest) || function (s, e) {
39
+ var t = {};
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
+ t[p] = s[p];
42
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
+ t[p[i]] = s[p[i]];
46
+ }
47
+ return t;
48
+ };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.ToolExecutor = void 0;
40
51
  var FlinkLog_1 = require("../FlinkLog");
@@ -123,7 +134,7 @@ var ToolExecutor = /** @class */ (function () {
123
134
  });
124
135
  };
125
136
  ToolExecutor.prototype.getToolSchema = function () {
126
- // Use Zod 4's built-in z.toJSONSchema()
137
+ // Use Zod 4's built-in z.toJSONSchema() if available, otherwise use zod-to-json-schema (Zod 3.x support)
127
138
  var zodSchema = this.toolProps.inputSchema;
128
139
  var z = require("zod");
129
140
  return {
@@ -133,16 +144,28 @@ var ToolExecutor = /** @class */ (function () {
133
144
  };
134
145
  };
135
146
  /**
136
- * Fallback schema generation if toJSONSchema is not available
147
+ * Fallback schema generation for Zod 3.x compatibility
148
+ * Uses zod-to-json-schema package which supports both Zod 3.x and 4.x
137
149
  */
138
150
  ToolExecutor.prototype.fallbackSchema = function (zodSchema) {
139
- // Try to use _def to extract basic schema info
140
- FlinkLog_1.log.warn("Tool ".concat(this.toolProps.id, ": z.toJSONSchema() not available, using fallback schema generation"));
141
- return {
142
- type: "object",
143
- properties: {},
144
- required: [],
145
- };
151
+ try {
152
+ // Use zod-to-json-schema for Zod 3.x compatibility
153
+ var zodToJsonSchema = require("zod-to-json-schema").zodToJsonSchema;
154
+ var jsonSchema = zodToJsonSchema(zodSchema, { target: "openApi3" });
155
+ // Remove top-level $schema field that zod-to-json-schema adds (not needed for tool schemas)
156
+ var _a = jsonSchema, $schema = _a.$schema, schemaWithoutMeta = __rest(_a, ["$schema"]);
157
+ FlinkLog_1.log.debug("Tool ".concat(this.toolProps.id, ": Using zod-to-json-schema for Zod 3.x compatibility"));
158
+ return schemaWithoutMeta;
159
+ }
160
+ catch (err) {
161
+ FlinkLog_1.log.error("Tool ".concat(this.toolProps.id, ": Failed to generate JSON Schema from Zod schema:"), err.message);
162
+ // Last resort fallback - return minimal valid schema
163
+ return {
164
+ type: "object",
165
+ properties: {},
166
+ required: [],
167
+ };
168
+ }
146
169
  };
147
170
  /**
148
171
  * Get tool result for AI consumption
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "2.0.0-alpha.55",
3
+ "version": "2.0.0-alpha.56",
4
4
  "description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "main": "dist/src/index.js",
@@ -68,7 +68,8 @@
68
68
  "ts-node": "^10.9.2"
69
69
  },
70
70
  "peerDependencies": {
71
- "mongodb": ">=3.7.0 <7.0.0"
71
+ "mongodb": ">=3.7.0 <7.0.0",
72
+ "zod": ">=3.25.0 <5.0.0"
72
73
  },
73
74
  "gitHead": "4243e3b3cd6d4e1ca001a61baa8436bf2bbe4113",
74
75
  "scripts": {
@@ -35,6 +35,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __rest = (this && this.__rest) || function (s, e) {
39
+ var t = {};
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
41
+ t[p] = s[p];
42
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
43
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
44
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
45
+ t[p[i]] = s[p[i]];
46
+ }
47
+ return t;
48
+ };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.ToolExecutor = void 0;
40
51
  var FlinkLog_1 = require("../FlinkLog");
@@ -123,7 +134,7 @@ var ToolExecutor = /** @class */ (function () {
123
134
  });
124
135
  };
125
136
  ToolExecutor.prototype.getToolSchema = function () {
126
- // Use Zod 4's built-in z.toJSONSchema()
137
+ // Use Zod 4's built-in z.toJSONSchema() if available, otherwise use zod-to-json-schema (Zod 3.x support)
127
138
  var zodSchema = this.toolProps.inputSchema;
128
139
  var z = require("zod");
129
140
  return {
@@ -133,16 +144,28 @@ var ToolExecutor = /** @class */ (function () {
133
144
  };
134
145
  };
135
146
  /**
136
- * Fallback schema generation if toJSONSchema is not available
147
+ * Fallback schema generation for Zod 3.x compatibility
148
+ * Uses zod-to-json-schema package which supports both Zod 3.x and 4.x
137
149
  */
138
150
  ToolExecutor.prototype.fallbackSchema = function (zodSchema) {
139
- // Try to use _def to extract basic schema info
140
- FlinkLog_1.log.warn("Tool ".concat(this.toolProps.id, ": z.toJSONSchema() not available, using fallback schema generation"));
141
- return {
142
- type: "object",
143
- properties: {},
144
- required: [],
145
- };
151
+ try {
152
+ // Use zod-to-json-schema for Zod 3.x compatibility
153
+ var zodToJsonSchema = require("zod-to-json-schema").zodToJsonSchema;
154
+ var jsonSchema = zodToJsonSchema(zodSchema, { target: "openApi3" });
155
+ // Remove top-level $schema field that zod-to-json-schema adds (not needed for tool schemas)
156
+ var _a = jsonSchema, $schema = _a.$schema, schemaWithoutMeta = __rest(_a, ["$schema"]);
157
+ FlinkLog_1.log.debug("Tool ".concat(this.toolProps.id, ": Using zod-to-json-schema for Zod 3.x compatibility"));
158
+ return schemaWithoutMeta;
159
+ }
160
+ catch (err) {
161
+ FlinkLog_1.log.error("Tool ".concat(this.toolProps.id, ": Failed to generate JSON Schema from Zod schema:"), err.message);
162
+ // Last resort fallback - return minimal valid schema
163
+ return {
164
+ type: "object",
165
+ properties: {},
166
+ required: [],
167
+ };
168
+ }
146
169
  };
147
170
  /**
148
171
  * Get tool result for AI consumption
@@ -83,7 +83,7 @@ export class ToolExecutor<Ctx extends FlinkContext> {
83
83
  }
84
84
 
85
85
  getToolSchema(): FlinkToolSchema {
86
- // Use Zod 4's built-in z.toJSONSchema()
86
+ // Use Zod 4's built-in z.toJSONSchema() if available, otherwise use zod-to-json-schema (Zod 3.x support)
87
87
  const zodSchema = this.toolProps.inputSchema;
88
88
  const z = require("zod") as any;
89
89
 
@@ -95,16 +95,29 @@ export class ToolExecutor<Ctx extends FlinkContext> {
95
95
  }
96
96
 
97
97
  /**
98
- * Fallback schema generation if toJSONSchema is not available
98
+ * Fallback schema generation for Zod 3.x compatibility
99
+ * Uses zod-to-json-schema package which supports both Zod 3.x and 4.x
99
100
  */
100
101
  private fallbackSchema(zodSchema: any): any {
101
- // Try to use _def to extract basic schema info
102
- log.warn(`Tool ${this.toolProps.id}: z.toJSONSchema() not available, using fallback schema generation`);
103
- return {
104
- type: "object",
105
- properties: {},
106
- required: [],
107
- };
102
+ try {
103
+ // Use zod-to-json-schema for Zod 3.x compatibility
104
+ const { zodToJsonSchema } = require("zod-to-json-schema");
105
+ const jsonSchema = zodToJsonSchema(zodSchema, { target: "openApi3" });
106
+
107
+ // Remove top-level $schema field that zod-to-json-schema adds (not needed for tool schemas)
108
+ const { $schema, ...schemaWithoutMeta } = jsonSchema as any;
109
+
110
+ log.debug(`Tool ${this.toolProps.id}: Using zod-to-json-schema for Zod 3.x compatibility`);
111
+ return schemaWithoutMeta;
112
+ } catch (err: any) {
113
+ log.error(`Tool ${this.toolProps.id}: Failed to generate JSON Schema from Zod schema:`, err.message);
114
+ // Last resort fallback - return minimal valid schema
115
+ return {
116
+ type: "object",
117
+ properties: {},
118
+ required: [],
119
+ };
120
+ }
108
121
  }
109
122
 
110
123
  /**