@devries-cameron20 / composio Mirror · read-only / commits / dc87f401c
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 22:00 UTC

Fix zodschema parsing (#1801)

Musthaq Ahamad committed Jul 28, 2025 at 17:07 UTC dc87f401ce1da8904bb905a8fff77b28a2d2608a
28 files changed +503 -132
pnpm-lock.yaml
+11 -24
@@ -285,6 +285,9 @@ importers:
285 '@composio/core':
286 specifier: workspace:*
287 version: link:../../packages/core
288 + '@composio/vercel':
289 + specifier: workspace:^
290 + version: link:../../packages/providers/vercel
291 dotenv:
292 specifier: ^16.4.1
293 version: 16.5.0
@@ -603,8 +606,8 @@ importers:
606 specifier: 0.1.0-alpha.29
607 version: 0.1.0-alpha.29
608 '@composio/json-schema-to-zod':
606 - specifier: 0.1.10
607 - version: 0.1.10
609 + specifier: 0.1.11
610 + version: 0.1.11
611 '@types/json-schema':
612 specifier: ^7.0.15
613 version: 7.0.15
@@ -1156,8 +1159,8 @@ packages:
1159 '@composio/client@0.1.0-alpha.29':
1160 resolution: {integrity: sha512-0oI38Kl8LVEK/fFF7rTdvO11uwSWHzavTTUWE/ExnhIoik3wmHse1CRKywb06M+hkLO4+Vdkh46sXbNFs7YZyQ==}
1161
1159 - '@composio/json-schema-to-zod@0.1.10':
1160 - resolution: {integrity: sha512-U+sdd+/+C6TDXeljXEN7pJ4YjH2Tda8U1S7S0ceXyZt5lF2YQIxE6YYKAdcV0ojUUfL7Mwsmbe8va3rDOud1pA==}
1162 + '@composio/json-schema-to-zod@0.1.11':
1163 + resolution: {integrity: sha512-6gcCof9xqLhmmHSCvWLW/E16PKr5C1dWJ9AOk4FJU8JA7gSt8JEdFHBwx80dyprBJdwPF6R54nlkmpXrEwApzg==}
1164
1165 '@composio/mcp@1.0.3-0':
1166 resolution: {integrity: sha512-IpbfST0SSs/CEv+PIf6+EL0feNuJhQyUrOHJLPge8NhyLLrCyVqvujRIPyRUUjy0NDsked/Mm5VpJmYM6OACbg==}
@@ -7169,7 +7172,7 @@ snapshots:
7172
7173 '@composio/client@0.1.0-alpha.29': {}
7174
7172 - '@composio/json-schema-to-zod@0.1.10':
7175 + '@composio/json-schema-to-zod@0.1.11':
7176 dependencies:
7177 '@types/json-schema': 7.0.15
7178 zod: 3.25.67
@@ -9616,14 +9619,6 @@ snapshots:
9619 chai: 5.2.0
9620 tinyrainbow: 2.0.0
9621
9619 - '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9620 - dependencies:
9621 - '@vitest/spy': 3.2.4
9622 - estree-walker: 3.0.3
9623 - magic-string: 0.30.17
9624 - optionalDependencies:
9625 - vite: 6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9626 -
9622 '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9623 dependencies:
9624 '@vitest/spy': 3.2.4
@@ -9632,14 +9627,6 @@ snapshots:
9627 optionalDependencies:
9628 vite: 6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9629
9635 - '@vitest/mocker@3.2.4(vite@6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))':
9636 - dependencies:
9637 - '@vitest/spy': 3.2.4
9638 - estree-walker: 3.0.3
9639 - magic-string: 0.30.17
9640 - optionalDependencies:
9641 - vite: 6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9642 -
9630 '@vitest/pretty-format@3.2.4':
9631 dependencies:
9632 tinyrainbow: 2.0.0
@@ -9669,7 +9656,7 @@ snapshots:
9656 sirv: 3.0.1
9657 tinyglobby: 0.2.14
9658 tinyrainbow: 2.0.0
9672 - vitest: 3.2.4(@types/node@24.0.3)(@vitest/ui@3.2.4)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9659 + vitest: 3.2.4(@types/node@22.15.32)(@vitest/ui@3.2.4)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0)
9660
9661 '@vitest/utils@3.2.4':
9662 dependencies:
@@ -12733,7 +12720,7 @@ snapshots:
12720 dependencies:
12721 '@types/chai': 5.2.2
12722 '@vitest/expect': 3.2.4
12736 - '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@20.19.1)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12723 + '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12724 '@vitest/pretty-format': 3.2.4
12725 '@vitest/runner': 3.2.4
12726 '@vitest/snapshot': 3.2.4
@@ -12817,7 +12804,7 @@ snapshots:
12804 dependencies:
12805 '@types/chai': 5.2.2
12806 '@vitest/expect': 3.2.4
12820 - '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@24.0.3)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12807 + '@vitest/mocker': 3.2.4(vite@6.3.5(@types/node@22.15.32)(jiti@1.21.7)(tsx@4.20.3)(yaml@2.8.0))
12808 '@vitest/pretty-format': 3.2.4
12809 '@vitest/runner': 3.2.4
12810 '@vitest/snapshot': 3.2.4
ts/examples/json-schema-to-zod/package.json
+1
@@ -20,6 +20,7 @@
20 "packageManager": "pnpm@10.8.0",
21 "dependencies": {
22 "@composio/core": "workspace:*",
23 + "@composio/vercel": "workspace:^",
24 "dotenv": "^16.4.1",
25 "zod-to-json-schema": "^3.24.5"
26 },
ts/packages/core/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/core
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/json-schema-to-zod@0.1.11
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/core/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/core",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -45,7 +45,7 @@
45 },
46 "dependencies": {
47 "@composio/client": "0.1.0-alpha.29",
48 - "@composio/json-schema-to-zod": "0.1.10",
48 + "@composio/json-schema-to-zod": "0.1.11",
49 "@types/json-schema": "^7.0.15",
50 "chalk": "^4.1.2",
51 "openai": "^4.94.0",
ts/packages/json-schema-to-zod/CHANGELOG.md
+6
@@ -1,5 +1,11 @@
1 # @composio/json-schema-to-zod
2
3 +## 0.1.11
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +
9 ## 0.1.10
10
11 ### Patch Changes
ts/packages/json-schema-to-zod/package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/json-schema-to-zod",
3 - "version": "0.1.10",
3 + "version": "0.1.11",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
ts/packages/json-schema-to-zod/src/parsers/parse-array.ts
+26
@@ -83,5 +83,31 @@ export const parseArray = (jsonSchema: JsonSchemaObject & { type: 'array' }, ref
83 (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
84 );
85
86 + // Handle generic 'min' property as alias for 'minItems'
87 + if (
88 + typeof (jsonSchema as unknown as { min?: number }).min === 'number' &&
89 + typeof jsonSchema.minItems !== 'number'
90 + ) {
91 + zodSchema = extendSchemaWithMessage(
92 + zodSchema,
93 + { ...jsonSchema, minItems: (jsonSchema as unknown as { min?: number }).min },
94 + 'minItems',
95 + (zs, minItems, errorMessage) => zs.min(minItems, errorMessage)
96 + );
97 + }
98 +
99 + // Handle generic 'max' property as alias for 'maxItems'
100 + if (
101 + typeof (jsonSchema as unknown as { max?: number }).max === 'number' &&
102 + typeof jsonSchema.maxItems !== 'number'
103 + ) {
104 + zodSchema = extendSchemaWithMessage(
105 + zodSchema,
106 + { ...jsonSchema, maxItems: (jsonSchema as unknown as { max?: number }).max },
107 + 'maxItems',
108 + (zs, maxItems, errorMessage) => zs.max(maxItems, errorMessage)
109 + );
110 + }
111 +
112 return zodSchema;
113 };
ts/packages/json-schema-to-zod/src/parsers/parse-number.ts
+100 -74
@@ -4,85 +4,111 @@ import type { JsonSchemaObject } from '../types';
4 import { extendSchemaWithMessage } from '../utils/extend-schema';
5
6 export const parseNumber = (jsonSchema: JsonSchemaObject & { type: 'number' | 'integer' }) => {
7 - let zodSchema = z.number();
7 + let zodSchema = z.number();
8
9 - let isInteger = false;
10 - if (jsonSchema.type === 'integer') {
11 - isInteger = true;
12 - zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'type', (zs, _, errorMsg) =>
13 - zs.int(errorMsg),
14 - );
15 - } else if (jsonSchema.format === 'int64') {
16 - isInteger = true;
17 - zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'format', (zs, _, errorMsg) =>
18 - zs.int(errorMsg),
19 - );
20 - }
9 + let isInteger = false;
10 + if (jsonSchema.type === 'integer') {
11 + isInteger = true;
12 + zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'type', (zs, _, errorMsg) =>
13 + zs.int(errorMsg)
14 + );
15 + } else if (jsonSchema.format === 'int64') {
16 + isInteger = true;
17 + zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'format', (zs, _, errorMsg) =>
18 + zs.int(errorMsg)
19 + );
20 + }
21
22 - zodSchema = extendSchemaWithMessage(
23 - zodSchema,
24 - jsonSchema,
25 - 'multipleOf',
26 - (zs, multipleOf, errorMsg) => {
27 - if (multipleOf === 1) {
28 - if (isInteger) return zs;
22 + zodSchema = extendSchemaWithMessage(
23 + zodSchema,
24 + jsonSchema,
25 + 'multipleOf',
26 + (zs, multipleOf, errorMsg) => {
27 + if (multipleOf === 1) {
28 + if (isInteger) return zs;
29
30 - return zs.int(errorMsg);
31 - }
30 + return zs.int(errorMsg);
31 + }
32
33 - return zs.multipleOf(multipleOf, errorMsg);
34 - },
35 - );
33 + return zs.multipleOf(multipleOf, errorMsg);
34 + }
35 + );
36
37 - if (typeof jsonSchema.minimum === 'number') {
38 - if (jsonSchema.exclusiveMinimum === true) {
39 - zodSchema = extendSchemaWithMessage(
40 - zodSchema,
41 - jsonSchema,
42 - 'minimum',
43 - (zs, minimum, errorMsg) => zs.gt(minimum, errorMsg),
44 - );
45 - } else {
46 - zodSchema = extendSchemaWithMessage(
47 - zodSchema,
48 - jsonSchema,
49 - 'minimum',
50 - (zs, minimum, errorMsg) => zs.gte(minimum, errorMsg),
51 - );
52 - }
53 - } else if (typeof jsonSchema.exclusiveMinimum === 'number') {
54 - zodSchema = extendSchemaWithMessage(
55 - zodSchema,
56 - jsonSchema,
57 - 'exclusiveMinimum',
58 - (zs, exclusiveMinimum, errorMsg) => zs.gt(exclusiveMinimum as number, errorMsg),
59 - );
60 - }
37 + if (typeof jsonSchema.minimum === 'number') {
38 + if ((jsonSchema as unknown as { exclusiveMinimum?: boolean }).exclusiveMinimum === true) {
39 + zodSchema = extendSchemaWithMessage(
40 + zodSchema,
41 + jsonSchema,
42 + 'minimum',
43 + (zs, minimum, errorMsg) => zs.gt(minimum, errorMsg)
44 + );
45 + } else {
46 + zodSchema = extendSchemaWithMessage(
47 + zodSchema,
48 + jsonSchema,
49 + 'minimum',
50 + (zs, minimum, errorMsg) => zs.gte(minimum, errorMsg)
51 + );
52 + }
53 + } else if (typeof jsonSchema.exclusiveMinimum === 'number') {
54 + zodSchema = extendSchemaWithMessage(
55 + zodSchema,
56 + jsonSchema,
57 + 'exclusiveMinimum',
58 + (zs, exclusiveMinimum, errorMsg) => zs.gt(exclusiveMinimum as number, errorMsg)
59 + );
60 + }
61
62 - if (typeof jsonSchema.maximum === 'number') {
63 - if (jsonSchema.exclusiveMaximum === true) {
64 - zodSchema = extendSchemaWithMessage(
65 - zodSchema,
66 - jsonSchema,
67 - 'maximum',
68 - (zs, maximum, errorMsg) => zs.lt(maximum, errorMsg),
69 - );
70 - } else {
71 - zodSchema = extendSchemaWithMessage(
72 - zodSchema,
73 - jsonSchema,
74 - 'maximum',
75 - (zs, maximum, errorMsg) => zs.lte(maximum, errorMsg),
76 - );
77 - }
78 - } else if (typeof jsonSchema.exclusiveMaximum === 'number') {
79 - zodSchema = extendSchemaWithMessage(
80 - zodSchema,
81 - jsonSchema,
82 - 'exclusiveMaximum',
83 - (zs, exclusiveMaximum, errorMsg) => zs.lt(exclusiveMaximum as number, errorMsg),
84 - );
85 - }
62 + if (typeof jsonSchema.maximum === 'number') {
63 + if ((jsonSchema as unknown as { exclusiveMaximum?: boolean }).exclusiveMaximum === true) {
64 + zodSchema = extendSchemaWithMessage(
65 + zodSchema,
66 + jsonSchema,
67 + 'maximum',
68 + (zs, maximum, errorMsg) => zs.lt(maximum, errorMsg)
69 + );
70 + } else {
71 + zodSchema = extendSchemaWithMessage(
72 + zodSchema,
73 + jsonSchema,
74 + 'maximum',
75 + (zs, maximum, errorMsg) => zs.lte(maximum, errorMsg)
76 + );
77 + }
78 + } else if (typeof jsonSchema.exclusiveMaximum === 'number') {
79 + zodSchema = extendSchemaWithMessage(
80 + zodSchema,
81 + jsonSchema,
82 + 'exclusiveMaximum',
83 + (zs, exclusiveMaximum, errorMsg) => zs.lt(exclusiveMaximum as number, errorMsg)
84 + );
85 + }
86
87 - return zodSchema;
87 + // Handle generic 'min' property as alias for 'minimum'
88 + if (
89 + typeof (jsonSchema as unknown as { min?: number }).min === 'number' &&
90 + typeof jsonSchema.minimum !== 'number'
91 + ) {
92 + zodSchema = extendSchemaWithMessage(
93 + zodSchema,
94 + { ...jsonSchema, minimum: (jsonSchema as unknown as { min?: number }).min },
95 + 'minimum',
96 + (zs, minimum, errorMsg) => zs.gte(minimum, errorMsg)
97 + );
98 + }
99 +
100 + // Handle generic 'max' property as alias for 'maximum'
101 + if (
102 + typeof (jsonSchema as unknown as { max?: number }).max === 'number' &&
103 + typeof jsonSchema.maximum !== 'number'
104 + ) {
105 + zodSchema = extendSchemaWithMessage(
106 + zodSchema,
107 + { ...jsonSchema, maximum: (jsonSchema as unknown as { max?: number }).max },
108 + 'maximum',
109 + (zs, maximum, errorMsg) => zs.lte(maximum, errorMsg)
110 + );
111 + }
112 +
113 + return zodSchema;
114 };
ts/packages/json-schema-to-zod/src/parsers/parse-schema.ts
+26 -2
@@ -20,10 +20,34 @@ import type { ParserSelector, Refs, JsonSchemaObject, JsonSchema } from '../type
20 import { its } from '../utils/its';
21
22 const addDescribes = (jsonSchema: JsonSchemaObject, zodSchema: z.ZodTypeAny): z.ZodTypeAny => {
23 + let description = '';
24 +
25 if (jsonSchema.description) {
24 - zodSchema = zodSchema.describe(jsonSchema.description);
26 + description = jsonSchema.description;
27 } else if (jsonSchema.title) {
26 - zodSchema = zodSchema.describe(jsonSchema.title);
28 + description = jsonSchema.title;
29 + }
30 +
31 + // Append example(s) if they exist
32 + if ((jsonSchema as unknown as { example?: unknown }).example !== undefined) {
33 + const exampleText = `Example: ${JSON.stringify((jsonSchema as unknown as { example?: unknown }).example)}`;
34 + description = description ? `${description}\n${exampleText}` : exampleText;
35 + } else if (
36 + (jsonSchema as unknown as { examples?: unknown[] }).examples !== undefined &&
37 + Array.isArray((jsonSchema as unknown as { examples?: unknown[] }).examples)
38 + ) {
39 + const examples = (jsonSchema as unknown as { examples?: unknown[] }).examples;
40 + if (examples && examples.length && examples.length > 0) {
41 + const exampleText =
42 + examples.length === 1
43 + ? `Example: ${JSON.stringify(examples[0])}`
44 + : `Examples:\n${examples.map((ex: unknown) => ` ${JSON.stringify(ex)}`).join('\n')}`;
45 + description = description ? `${description}\n${exampleText}` : exampleText;
46 + }
47 + }
48 +
49 + if (description) {
50 + zodSchema = zodSchema.describe(description);
51 }
52
53 return zodSchema;
ts/packages/json-schema-to-zod/src/parsers/parse-string.ts
+26
@@ -54,5 +54,31 @@ export const parseString = (jsonSchema: JsonSchemaObject & { type: 'string' }) =
54 (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
55 );
56
57 + // Handle generic 'min' property as alias for 'minLength'
58 + if (
59 + typeof (jsonSchema as unknown as { min?: number }).min === 'number' &&
60 + typeof jsonSchema.minLength !== 'number'
61 + ) {
62 + zodSchema = extendSchemaWithMessage(
63 + zodSchema,
64 + { ...jsonSchema, minLength: (jsonSchema as unknown as { min?: number }).min },
65 + 'minLength',
66 + (zs, minLength, errorMsg) => zs.min(minLength, errorMsg)
67 + );
68 + }
69 +
70 + // Handle generic 'max' property as alias for 'maxLength'
71 + if (
72 + typeof (jsonSchema as unknown as { max?: number }).max === 'number' &&
73 + typeof jsonSchema.maxLength !== 'number'
74 + ) {
75 + zodSchema = extendSchemaWithMessage(
76 + zodSchema,
77 + { ...jsonSchema, maxLength: (jsonSchema as unknown as { max?: number }).max },
78 + 'maxLength',
79 + (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg)
80 + );
81 + }
82 +
83 return zodSchema;
84 };
ts/packages/json-schema-to-zod/src/utils/extend-schema.ts
+14 -13
@@ -3,21 +3,22 @@ import type { z } from 'zod';
3 import type { JsonSchemaObject } from '../types';
4
5 export function extendSchemaWithMessage<
6 - TZod extends z.ZodTypeAny,
7 - TJson extends JsonSchemaObject,
8 - TKey extends keyof TJson,
6 + TZod extends z.ZodTypeAny,
7 + TJson extends JsonSchemaObject,
8 + TKey extends keyof TJson,
9 >(
10 - zodSchema: TZod,
11 - jsonSchema: TJson,
12 - key: TKey,
13 - extend: (zodSchema: TZod, value: NonNullable<TJson[TKey]>, errorMessage?: string) => TZod,
10 + zodSchema: TZod,
11 + jsonSchema: TJson,
12 + key: TKey,
13 + extend: (zodSchema: TZod, value: NonNullable<TJson[TKey]>, errorMessage?: string) => TZod
14 ) {
15 - const value = jsonSchema[key];
15 + const value = jsonSchema[key];
16
17 - if (value !== undefined) {
18 - const errorMessage = jsonSchema.errorMessage?.[key as string];
19 - return extend(zodSchema, value as NonNullable<TJson[TKey]>, errorMessage);
20 - }
17 + if (value !== undefined) {
18 + const errorMessage = (jsonSchema as unknown as { errorMessage?: Record<string, string> })
19 + .errorMessage?.[key as string];
20 + return extend(zodSchema, value as NonNullable<TJson[TKey]>, errorMessage);
21 + }
22
22 - return zodSchema;
23 + return zodSchema;
24 }
ts/packages/json-schema-to-zod/test/json-to-zod.test.ts
+202
@@ -123,6 +123,63 @@ describe('jsonSchemaToZod', () => {
123 expect(zodSchema.parse(15)).toBe(15);
124 expect(() => zodSchema.parse(17)).toThrow();
125 });
126 +
127 + it('should handle generic min and max properties for numbers', () => {
128 + const schema: JsonSchema = {
129 + type: 'number',
130 + min: 0,
131 + max: 100,
132 + } as any;
133 + const zodSchema = jsonSchemaToZod(schema);
134 + expect(zodSchema.parse(50)).toBe(50);
135 + expect(() => zodSchema.parse(-1)).toThrow();
136 + expect(() => zodSchema.parse(101)).toThrow();
137 + });
138 +
139 + it('should prioritize minimum/maximum over min/max for numbers', () => {
140 + const schema: JsonSchema = {
141 + type: 'number',
142 + minimum: 10,
143 + maximum: 90,
144 + min: 0,
145 + max: 100,
146 + } as any;
147 + const zodSchema = jsonSchemaToZod(schema);
148 + expect(zodSchema.parse(50)).toBe(50);
149 + expect(zodSchema.parse(10)).toBe(10);
150 + expect(zodSchema.parse(90)).toBe(90);
151 + expect(() => zodSchema.parse(5)).toThrow(); // Uses minimum (10), not min (0)
152 + expect(() => zodSchema.parse(95)).toThrow(); // Uses maximum (90), not max (100)
153 + });
154 + });
155 +
156 + describe('String Validations', () => {
157 + it('should handle generic min and max properties for strings', () => {
158 + const schema: JsonSchema = {
159 + type: 'string',
160 + min: 3,
161 + max: 10,
162 + } as any;
163 + const zodSchema = jsonSchemaToZod(schema);
164 + expect(zodSchema.parse('hello')).toBe('hello');
165 + expect(() => zodSchema.parse('hi')).toThrow();
166 + expect(() => zodSchema.parse('this is too long')).toThrow();
167 + });
168 +
169 + it('should prioritize minLength/maxLength over min/max for strings', () => {
170 + const schema: JsonSchema = {
171 + type: 'string',
172 + minLength: 5,
173 + maxLength: 8,
174 + min: 3,
175 + max: 10,
176 + } as any;
177 + const zodSchema = jsonSchemaToZod(schema);
178 + expect(zodSchema.parse('hello')).toBe('hello');
179 + expect(zodSchema.parse('testing')).toBe('testing');
180 + expect(() => zodSchema.parse('test')).toThrow(); // Uses minLength (5), not min (3)
181 + expect(() => zodSchema.parse('toolongstring')).toThrow(); // Uses maxLength (8), not max (10)
182 + });
183 });
184
185 describe('Object Schemas', () => {
@@ -205,6 +262,41 @@ describe('jsonSchemaToZod', () => {
262 expect(() => zodSchema.parse(['one', 'two', 'three', 'four'])).toThrow();
263 });
264
265 + it('should handle generic min and max properties for arrays', () => {
266 + const schema: JsonSchema = {
267 + type: 'array',
268 + items: { type: 'string' },
269 + min: 1,
270 + max: 3,
271 + } as any;
272 + const zodSchema = jsonSchemaToZod(schema);
273 + expect(zodSchema.parse(['one'])).toEqual(['one']);
274 + expect(zodSchema.parse(['one', 'two', 'three'])).toEqual(['one', 'two', 'three']);
275 + expect(() => zodSchema.parse([])).toThrow();
276 + expect(() => zodSchema.parse(['one', 'two', 'three', 'four'])).toThrow();
277 + });
278 +
279 + it('should prioritize minItems/maxItems over min/max for arrays', () => {
280 + const schema: JsonSchema = {
281 + type: 'array',
282 + items: { type: 'string' },
283 + minItems: 2,
284 + maxItems: 4,
285 + min: 1,
286 + max: 3,
287 + } as any;
288 + const zodSchema = jsonSchemaToZod(schema);
289 + expect(zodSchema.parse(['one', 'two'])).toEqual(['one', 'two']);
290 + expect(zodSchema.parse(['one', 'two', 'three', 'four'])).toEqual([
291 + 'one',
292 + 'two',
293 + 'three',
294 + 'four',
295 + ]);
296 + expect(() => zodSchema.parse(['one'])).toThrow(); // Uses minItems (2), not min (1)
297 + expect(() => zodSchema.parse(['one', 'two', 'three', 'four', 'five'])).toThrow(); // Uses maxItems (4), not max (3)
298 + });
299 +
300 it('should handle arrays with anyOf patterns', () => {
301 const schema: JsonSchema = {
302 type: 'array',
@@ -654,5 +746,115 @@ describe('jsonSchemaToZod', () => {
746 const shape = (zodSchema as any)._def.shape();
747 expect(shape.username.description).toBe('The username of the Hacker News user to retrieve.');
748 });
749 +
750 + it('should append example to description', () => {
751 + const schema: JsonSchema = {
752 + type: 'string',
753 + description: 'User name',
754 + example: 'john_doe',
755 + } as any;
756 + const zodSchema = jsonSchemaToZod(schema);
757 + expect(zodSchema.description).toBe('User name\nExample: "john_doe"');
758 + });
759 +
760 + it('should handle example without description', () => {
761 + const schema: JsonSchema = {
762 + type: 'number',
763 + example: 42,
764 + } as any;
765 + const zodSchema = jsonSchemaToZod(schema);
766 + expect(zodSchema.description).toBe('Example: 42');
767 + });
768 +
769 + it('should handle example with title but no description', () => {
770 + const schema: JsonSchema = {
771 + type: 'object',
772 + title: 'User Object',
773 + example: { name: 'John', age: 30 },
774 + } as any;
775 + const zodSchema = jsonSchemaToZod(schema);
776 + expect(zodSchema.description).toBe('User Object\nExample: {"name":"John","age":30}');
777 + });
778 +
779 + it('should handle single example in examples array', () => {
780 + const schema: JsonSchema = {
781 + type: 'string',
782 + description: 'Property name',
783 + examples: ['lifecyclestage'],
784 + } as any;
785 + const zodSchema = jsonSchemaToZod(schema);
786 + expect(zodSchema.description).toBe('Property name\nExample: "lifecyclestage"');
787 + });
788 +
789 + it('should handle multiple examples in examples array', () => {
790 + const schema: JsonSchema = {
791 + type: 'array',
792 + description: 'List of property names',
793 + examples: ["['lifecyclestage', 'hs_lead_status']", "['hubspot_owner_id']"],
794 + } as any;
795 + const zodSchema = jsonSchemaToZod(schema);
796 + expect(zodSchema.description).toBe(
797 + "List of property names\nExamples:\n \"['lifecyclestage', 'hs_lead_status']\"\n \"['hubspot_owner_id']\""
798 + );
799 + });
800 +
801 + it('should prioritize example over examples', () => {
802 + const schema: JsonSchema = {
803 + type: 'string',
804 + description: 'Property name',
805 + example: 'single_example',
806 + examples: ['example1', 'example2'],
807 + } as any;
808 + const zodSchema = jsonSchemaToZod(schema);
809 + expect(zodSchema.description).toBe('Property name\nExample: "single_example"');
810 + });
811 +
812 + it('should handle empty examples array', () => {
813 + const schema: JsonSchema = {
814 + type: 'string',
815 + description: 'Property name',
816 + examples: [],
817 + } as any;
818 + const zodSchema = jsonSchemaToZod(schema);
819 + expect(zodSchema.description).toBe('Property name');
820 + });
821 +
822 + it('should preserve array structure in examples', () => {
823 + const schema: JsonSchema = {
824 + type: 'array',
825 + description: 'Property combinations',
826 + examples: [
827 + ['lifecyclestage', 'hs_lead_status'],
828 + ['hubspot_owner_id'],
829 + ['created_date', 'modified_date', 'status'],
830 + ],
831 + } as any;
832 + const zodSchema = jsonSchemaToZod(schema);
833 + expect(zodSchema.description).toBe(
834 + 'Property combinations\nExamples:\n ["lifecyclestage","hs_lead_status"]\n ["hubspot_owner_id"]\n ["created_date","modified_date","status"]'
835 + );
836 + });
837 +
838 + it('should handle primitive types in examples array', () => {
839 + const schema: JsonSchema = {
840 + type: 'string',
841 + description: 'Status values',
842 + examples: ['active', 'inactive', 'pending'],
843 + } as any;
844 + const zodSchema = jsonSchemaToZod(schema);
845 + expect(zodSchema.description).toBe(
846 + 'Status values\nExamples:\n "active"\n "inactive"\n "pending"'
847 + );
848 + });
849 +
850 + it('should handle mixed primitive types in examples array', () => {
851 + const schema: JsonSchema = {
852 + type: 'number',
853 + description: 'Various numbers',
854 + examples: [42, 3.14, 0, -5],
855 + } as any;
856 + const zodSchema = jsonSchemaToZod(schema);
857 + expect(zodSchema.description).toBe('Various numbers\nExamples:\n 42\n 3.14\n 0\n -5');
858 + });
859 });
860 });
ts/packages/providers/anthropic/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/anthropic
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/anthropic/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/anthropic",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "Non-Agentic Provider for Anthropic in Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -35,7 +35,7 @@
35 "packageManager": "pnpm@10.8.0",
36 "peerDependencies": {
37 "@anthropic-ai/sdk": "^0.52.0",
38 - "@composio/core": "0.1.38"
38 + "@composio/core": "0.1.39"
39 },
40 "devDependencies": {
41 "@composio/core": "workspace:*",
ts/packages/providers/cloudflare/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/cloudflare
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/cloudflare/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/cloudflare",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -31,7 +31,7 @@
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 "@cloudflare/workers-types": "^4.20250416.0",
34 - "@composio/core": "0.1.38"
34 + "@composio/core": "0.1.39"
35 },
36 "devDependencies": {
37 "@composio/core": "workspace:*",
ts/packages/providers/google/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/google
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/google/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/google",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "Google GenAI Provider for Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -36,7 +36,7 @@
36 "license": "ISC",
37 "packageManager": "pnpm@10.8.0",
38 "peerDependencies": {
39 - "@composio/core": "0.1.38",
39 + "@composio/core": "0.1.39",
40 "@google/genai": "^1.1.0"
41 },
42 "devDependencies": {
ts/packages/providers/langchain/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/langchain
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/langchain/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/langchain",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "dist/index.js",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.38",
33 + "@composio/core": "0.1.39",
34 "@langchain/core": "^0.3.63"
35 },
36 "devDependencies": {
ts/packages/providers/mastra/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/mastra
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/mastra/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/mastra",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "Agentic Provider for mastra in Composio SDK",
5 "main": "src/index.ts",
6 "type": "module",
@@ -34,7 +34,7 @@
34 "license": "ISC",
35 "packageManager": "pnpm@10.8.0",
36 "peerDependencies": {
37 - "@composio/core": "0.1.38",
37 + "@composio/core": "0.1.39",
38 "@mastra/core": "^0.10.0"
39 },
40 "devDependencies": {
ts/packages/providers/openai-agents/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/vercel
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/openai-agents/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/openai-agents",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.38",
33 + "@composio/core": "0.1.39",
34 "@openai/agents": "^0.0.7"
35 },
36 "devDependencies": {
ts/packages/providers/openai/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/openai
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/openai/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/openai",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.38",
33 + "@composio/core": "0.1.39",
34 "openai": "^4.3.8"
35 },
36 "devDependencies": {
ts/packages/providers/vercel/CHANGELOG.md
+8
@@ -1,5 +1,13 @@
1 # @composio/vercel
2
3 +## 0.1.39
4 +
5 +### Patch Changes
6 +
7 +- Fix jsonSchema to zod parsing which used to eliminate min/max and examples proeperties
8 +- Updated dependencies
9 + - @composio/core@0.1.39
10 +
11 ## 0.1.38
12
13 ### Patch Changes
ts/packages/providers/vercel/package.json
+2 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "@composio/vercel",
3 - "version": "0.1.38",
3 + "version": "0.1.39",
4 "description": "",
5 "main": "src/index.ts",
6 "type": "module",
@@ -30,7 +30,7 @@
30 "license": "ISC",
31 "packageManager": "pnpm@10.8.0",
32 "peerDependencies": {
33 - "@composio/core": "0.1.38",
33 + "@composio/core": "0.1.39",
34 "ai": "^4.3.8"
35 },
36 "devDependencies": {