@tambo-ai/react 0.69.0 → 0.70.0

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.
Files changed (202) hide show
  1. package/README.md +7 -7
  2. package/dist/hooks/use-tambo-threads.test.js.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/mcp/index.d.ts +4 -5
  7. package/dist/mcp/index.d.ts.map +1 -1
  8. package/dist/mcp/index.js +4 -5
  9. package/dist/mcp/index.js.map +1 -1
  10. package/dist/model/component-metadata.d.ts +88 -241
  11. package/dist/model/component-metadata.d.ts.map +1 -1
  12. package/dist/model/component-metadata.js.map +1 -1
  13. package/dist/model/mcp-server-info.d.ts +3 -3
  14. package/dist/model/mcp-server-info.js.map +1 -1
  15. package/dist/providers/hooks/use-tambo-session-token.test.js.map +1 -1
  16. package/dist/providers/tambo-component-provider.d.ts +2 -2
  17. package/dist/providers/tambo-component-provider.d.ts.map +1 -1
  18. package/dist/providers/tambo-component-provider.js.map +1 -1
  19. package/dist/providers/tambo-interactable-provider.d.ts +1 -1
  20. package/dist/providers/tambo-registry-provider.d.ts +4 -4
  21. package/dist/providers/tambo-registry-provider.d.ts.map +1 -1
  22. package/dist/providers/tambo-registry-provider.js +11 -8
  23. package/dist/providers/tambo-registry-provider.js.map +1 -1
  24. package/dist/providers/tambo-registry-provider.test.js +31 -0
  25. package/dist/providers/tambo-registry-provider.test.js.map +1 -1
  26. package/dist/providers/tambo-registry-schema-compat.test.js +42 -52
  27. package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
  28. package/dist/providers/tambo-stubs.d.ts +2 -2
  29. package/dist/providers/tambo-stubs.d.ts.map +1 -1
  30. package/dist/providers/tambo-stubs.js.map +1 -1
  31. package/dist/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  32. package/dist/providers/tambo-thread-provider.d.ts.map +1 -1
  33. package/dist/providers/tambo-thread-provider.js +110 -142
  34. package/dist/providers/tambo-thread-provider.js.map +1 -1
  35. package/dist/providers/tambo-thread-provider.test.js +362 -445
  36. package/dist/providers/tambo-thread-provider.test.js.map +1 -1
  37. package/dist/schema/index.d.ts +1 -2
  38. package/dist/schema/index.d.ts.map +1 -1
  39. package/dist/schema/index.js +1 -5
  40. package/dist/schema/index.js.map +1 -1
  41. package/dist/schema/schema.d.ts +7 -24
  42. package/dist/schema/schema.d.ts.map +1 -1
  43. package/dist/schema/schema.js +34 -105
  44. package/dist/schema/schema.js.map +1 -1
  45. package/dist/schema/schema.test.js +26 -124
  46. package/dist/schema/schema.test.js.map +1 -1
  47. package/dist/testing/tools.d.ts +2 -12
  48. package/dist/testing/tools.d.ts.map +1 -1
  49. package/dist/testing/tools.js +1 -20
  50. package/dist/testing/tools.js.map +1 -1
  51. package/dist/testing/types.d.ts +2 -2
  52. package/dist/testing/types.d.ts.map +1 -1
  53. package/dist/testing/types.js.map +1 -1
  54. package/dist/util/registry-validators.d.ts +2 -2
  55. package/dist/util/registry-validators.d.ts.map +1 -1
  56. package/dist/util/registry-validators.js +37 -17
  57. package/dist/util/registry-validators.js.map +1 -1
  58. package/dist/util/registry-validators.test.js +64 -25
  59. package/dist/util/registry-validators.test.js.map +1 -1
  60. package/dist/util/registry.d.ts +4 -10
  61. package/dist/util/registry.d.ts.map +1 -1
  62. package/dist/util/registry.js +6 -22
  63. package/dist/util/registry.js.map +1 -1
  64. package/dist/util/registry.test.js +1 -47
  65. package/dist/util/registry.test.js.map +1 -1
  66. package/dist/util/tool-caller.d.ts +2 -2
  67. package/dist/util/tool-caller.d.ts.map +1 -1
  68. package/dist/util/tool-caller.js +5 -12
  69. package/dist/util/tool-caller.js.map +1 -1
  70. package/dist/v1/index.d.ts +35 -0
  71. package/dist/v1/index.d.ts.map +1 -0
  72. package/dist/v1/index.js +47 -0
  73. package/dist/v1/index.js.map +1 -0
  74. package/dist/v1/types/component.d.ts +47 -0
  75. package/dist/v1/types/component.d.ts.map +1 -0
  76. package/dist/v1/types/component.js +11 -0
  77. package/dist/v1/types/component.js.map +1 -0
  78. package/dist/v1/types/event.d.ts +63 -0
  79. package/dist/v1/types/event.d.ts.map +1 -0
  80. package/dist/v1/types/event.js +9 -0
  81. package/dist/v1/types/event.js.map +1 -0
  82. package/dist/v1/types/message.d.ts +39 -0
  83. package/dist/v1/types/message.d.ts.map +1 -0
  84. package/dist/v1/types/message.js +10 -0
  85. package/dist/v1/types/message.js.map +1 -0
  86. package/dist/v1/types/thread.d.ts +54 -0
  87. package/dist/v1/types/thread.d.ts.map +1 -0
  88. package/dist/v1/types/thread.js +9 -0
  89. package/dist/v1/types/thread.js.map +1 -0
  90. package/dist/v1/types/tool.d.ts +52 -0
  91. package/dist/v1/types/tool.d.ts.map +1 -0
  92. package/dist/v1/types/tool.js +11 -0
  93. package/dist/v1/types/tool.js.map +1 -0
  94. package/esm/hooks/use-tambo-threads.test.js.map +1 -1
  95. package/esm/index.d.ts +1 -1
  96. package/esm/index.d.ts.map +1 -1
  97. package/esm/index.js.map +1 -1
  98. package/esm/mcp/index.d.ts +4 -5
  99. package/esm/mcp/index.d.ts.map +1 -1
  100. package/esm/mcp/index.js +4 -5
  101. package/esm/mcp/index.js.map +1 -1
  102. package/esm/model/component-metadata.d.ts +88 -241
  103. package/esm/model/component-metadata.d.ts.map +1 -1
  104. package/esm/model/component-metadata.js.map +1 -1
  105. package/esm/model/mcp-server-info.d.ts +3 -3
  106. package/esm/model/mcp-server-info.js.map +1 -1
  107. package/esm/providers/hooks/use-tambo-session-token.test.js.map +1 -1
  108. package/esm/providers/tambo-component-provider.d.ts +2 -2
  109. package/esm/providers/tambo-component-provider.d.ts.map +1 -1
  110. package/esm/providers/tambo-component-provider.js.map +1 -1
  111. package/esm/providers/tambo-interactable-provider.d.ts +1 -1
  112. package/esm/providers/tambo-registry-provider.d.ts +4 -4
  113. package/esm/providers/tambo-registry-provider.d.ts.map +1 -1
  114. package/esm/providers/tambo-registry-provider.js +11 -8
  115. package/esm/providers/tambo-registry-provider.js.map +1 -1
  116. package/esm/providers/tambo-registry-provider.test.js +31 -0
  117. package/esm/providers/tambo-registry-provider.test.js.map +1 -1
  118. package/esm/providers/tambo-registry-schema-compat.test.js +42 -52
  119. package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
  120. package/esm/providers/tambo-stubs.d.ts +2 -2
  121. package/esm/providers/tambo-stubs.d.ts.map +1 -1
  122. package/esm/providers/tambo-stubs.js.map +1 -1
  123. package/esm/providers/tambo-thread-provider-initial-messages.test.js.map +1 -1
  124. package/esm/providers/tambo-thread-provider.d.ts.map +1 -1
  125. package/esm/providers/tambo-thread-provider.js +110 -142
  126. package/esm/providers/tambo-thread-provider.js.map +1 -1
  127. package/esm/providers/tambo-thread-provider.test.js +329 -445
  128. package/esm/providers/tambo-thread-provider.test.js.map +1 -1
  129. package/esm/schema/index.d.ts +1 -2
  130. package/esm/schema/index.d.ts.map +1 -1
  131. package/esm/schema/index.js +1 -2
  132. package/esm/schema/index.js.map +1 -1
  133. package/esm/schema/schema.d.ts +7 -24
  134. package/esm/schema/schema.d.ts.map +1 -1
  135. package/esm/schema/schema.js +34 -103
  136. package/esm/schema/schema.js.map +1 -1
  137. package/esm/schema/schema.test.js +27 -125
  138. package/esm/schema/schema.test.js.map +1 -1
  139. package/esm/testing/tools.d.ts +2 -12
  140. package/esm/testing/tools.d.ts.map +1 -1
  141. package/esm/testing/tools.js +2 -20
  142. package/esm/testing/tools.js.map +1 -1
  143. package/esm/testing/types.d.ts +2 -2
  144. package/esm/testing/types.d.ts.map +1 -1
  145. package/esm/testing/types.js.map +1 -1
  146. package/esm/util/registry-validators.d.ts +2 -2
  147. package/esm/util/registry-validators.d.ts.map +1 -1
  148. package/esm/util/registry-validators.js +38 -18
  149. package/esm/util/registry-validators.js.map +1 -1
  150. package/esm/util/registry-validators.test.js +64 -25
  151. package/esm/util/registry-validators.test.js.map +1 -1
  152. package/esm/util/registry.d.ts +4 -10
  153. package/esm/util/registry.d.ts.map +1 -1
  154. package/esm/util/registry.js +7 -22
  155. package/esm/util/registry.js.map +1 -1
  156. package/esm/util/registry.test.js +3 -49
  157. package/esm/util/registry.test.js.map +1 -1
  158. package/esm/util/tool-caller.d.ts +2 -2
  159. package/esm/util/tool-caller.d.ts.map +1 -1
  160. package/esm/util/tool-caller.js +5 -12
  161. package/esm/util/tool-caller.js.map +1 -1
  162. package/esm/v1/index.d.ts +35 -0
  163. package/esm/v1/index.d.ts.map +1 -0
  164. package/esm/v1/index.js +46 -0
  165. package/esm/v1/index.js.map +1 -0
  166. package/esm/v1/types/component.d.ts +47 -0
  167. package/esm/v1/types/component.d.ts.map +1 -0
  168. package/esm/v1/types/component.js +10 -0
  169. package/esm/v1/types/component.js.map +1 -0
  170. package/esm/v1/types/event.d.ts +63 -0
  171. package/esm/v1/types/event.d.ts.map +1 -0
  172. package/esm/v1/types/event.js +8 -0
  173. package/esm/v1/types/event.js.map +1 -0
  174. package/esm/v1/types/message.d.ts +39 -0
  175. package/esm/v1/types/message.d.ts.map +1 -0
  176. package/esm/v1/types/message.js +9 -0
  177. package/esm/v1/types/message.js.map +1 -0
  178. package/esm/v1/types/thread.d.ts +54 -0
  179. package/esm/v1/types/thread.d.ts.map +1 -0
  180. package/esm/v1/types/thread.js +8 -0
  181. package/esm/v1/types/thread.js.map +1 -0
  182. package/esm/v1/types/tool.d.ts +52 -0
  183. package/esm/v1/types/tool.d.ts.map +1 -0
  184. package/esm/v1/types/tool.js +10 -0
  185. package/esm/v1/types/tool.js.map +1 -0
  186. package/package.json +18 -8
  187. package/dist/schema/zod.d.ts +0 -57
  188. package/dist/schema/zod.d.ts.map +0 -1
  189. package/dist/schema/zod.js +0 -191
  190. package/dist/schema/zod.js.map +0 -1
  191. package/dist/schema/zod.test.d.ts +0 -2
  192. package/dist/schema/zod.test.d.ts.map +0 -1
  193. package/dist/schema/zod.test.js +0 -663
  194. package/dist/schema/zod.test.js.map +0 -1
  195. package/esm/schema/zod.d.ts +0 -57
  196. package/esm/schema/zod.d.ts.map +0 -1
  197. package/esm/schema/zod.js +0 -180
  198. package/esm/schema/zod.js.map +0 -1
  199. package/esm/schema/zod.test.d.ts +0 -2
  200. package/esm/schema/zod.test.d.ts.map +0 -1
  201. package/esm/schema/zod.test.js +0 -628
  202. package/esm/schema/zod.test.js.map +0 -1
@@ -1,663 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const z3 = __importStar(require("zod/v3"));
37
- const z4 = __importStar(require("zod/v4"));
38
- const zod_1 = require("./zod");
39
- // Test helper: assumes `value` is JSON-serializable (plain objects/arrays/primitives).
40
- // Conservative helper: returns true if any object in the tree has an own `key`
41
- // property at any depth. This lets us assert against JSON Schema `$ref` keys
42
- // structurally (not via incidental substrings in string values).
43
- function hasKeyDeep(value, key) {
44
- const seen = new Set();
45
- function isPlainObject(v) {
46
- if (!v || typeof v !== "object" || Array.isArray(v))
47
- return false;
48
- const proto = Object.getPrototypeOf(v);
49
- return proto === Object.prototype || proto === null;
50
- }
51
- function visit(node) {
52
- if (!node || typeof node !== "object")
53
- return false;
54
- if (seen.has(node))
55
- return false;
56
- seen.add(node);
57
- if (Array.isArray(node)) {
58
- return node.some(visit);
59
- }
60
- if (!isPlainObject(node))
61
- return false;
62
- if (Object.prototype.hasOwnProperty.call(node, key))
63
- return true;
64
- return Object.values(node).some(visit);
65
- }
66
- return visit(value);
67
- }
68
- function resolveJsonPointer(doc, pointer) {
69
- if (!pointer.startsWith("#"))
70
- return undefined;
71
- if (pointer === "#")
72
- return doc;
73
- if (!pointer.startsWith("#/"))
74
- return undefined;
75
- return pointer
76
- .slice(2)
77
- .split("/")
78
- .map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"))
79
- .reduce((current, segment) => {
80
- if (!current || typeof current !== "object")
81
- return undefined;
82
- if (Array.isArray(current)) {
83
- const index = Number(segment);
84
- if (!Number.isInteger(index))
85
- return undefined;
86
- return current[index];
87
- }
88
- return current[segment];
89
- }, doc);
90
- }
91
- function createRecursiveZod4NodeSchema() {
92
- // Placeholder schema so we can self-reference via `z4.lazy` without
93
- // fighting ESLint `prefer-const`.
94
- let nodeSchema = z4.any();
95
- nodeSchema = z4.object({ next: z4.lazy(() => nodeSchema).optional() });
96
- return nodeSchema;
97
- }
98
- describe("zod schema utilities", () => {
99
- describe("isZod3Schema", () => {
100
- it("returns true for Zod 3 schemas", () => {
101
- const schema = z3.object({ name: z3.string() });
102
- expect((0, zod_1.isZod3Schema)(schema)).toBe(true);
103
- expect((0, zod_1.isZod4Schema)(schema)).toBe(false);
104
- });
105
- it("returns true for Zod 4 schemas (they also have _def)", () => {
106
- // Note: Zod 4 schemas have both _def and _zod, so isZod3Schema returns true.
107
- // This is fine because handleZodSchemaToJson checks isZod4Schema first.
108
- const schema = z4.object({ name: z4.string() });
109
- expect((0, zod_1.isZod4Schema)(schema)).toBe(true);
110
- expect((0, zod_1.isZod3Schema)(schema)).toBe(false);
111
- });
112
- it("returns false for non-Zod values", () => {
113
- expect((0, zod_1.isZod3Schema)({})).toBe(false);
114
- expect((0, zod_1.isZod3Schema)(null)).toBe(false);
115
- expect((0, zod_1.isZod3Schema)("string")).toBe(false);
116
- });
117
- });
118
- describe("isZod4Schema", () => {
119
- it("returns true for Zod 4 schemas", () => {
120
- const schema = z4.object({ name: z4.string() });
121
- expect((0, zod_1.isZod4Schema)(schema)).toBe(true);
122
- });
123
- it("returns false for Zod 3 schemas", () => {
124
- const schema = z3.object({ name: z3.string() });
125
- expect((0, zod_1.isZod4Schema)(schema)).toBe(false);
126
- });
127
- it("returns false for non-Zod values", () => {
128
- expect((0, zod_1.isZod4Schema)({})).toBe(false);
129
- expect((0, zod_1.isZod4Schema)(null)).toBe(false);
130
- expect((0, zod_1.isZod4Schema)("string")).toBe(false);
131
- });
132
- });
133
- describe("isZodSchema", () => {
134
- it("returns true for Zod 3 schemas", () => {
135
- expect((0, zod_1.isZodSchema)(z3.string())).toBe(true);
136
- expect((0, zod_1.isZodSchema)(z3.object({ a: z3.string() }))).toBe(true);
137
- });
138
- it("returns true for Zod 4 schemas", () => {
139
- expect((0, zod_1.isZodSchema)(z4.string())).toBe(true);
140
- expect((0, zod_1.isZodSchema)(z4.object({ a: z4.string() }))).toBe(true);
141
- });
142
- it("returns false for non-objects", () => {
143
- expect((0, zod_1.isZodSchema)(null)).toBe(false);
144
- expect((0, zod_1.isZodSchema)(undefined)).toBe(false);
145
- expect((0, zod_1.isZodSchema)("string")).toBe(false);
146
- expect((0, zod_1.isZodSchema)(123)).toBe(false);
147
- });
148
- it("returns false for objects without ~standard", () => {
149
- expect((0, zod_1.isZodSchema)({})).toBe(false);
150
- expect((0, zod_1.isZodSchema)({ foo: "bar" })).toBe(false);
151
- });
152
- it("returns false for objects with invalid ~standard", () => {
153
- expect((0, zod_1.isZodSchema)({ "~standard": null })).toBe(false);
154
- expect((0, zod_1.isZodSchema)({ "~standard": "not-object" })).toBe(false);
155
- expect((0, zod_1.isZodSchema)({ "~standard": {} })).toBe(false);
156
- expect((0, zod_1.isZodSchema)({ "~standard": { vendor: "not-zod" } })).toBe(false);
157
- });
158
- });
159
- describe("isZodFunctionSchema", () => {
160
- it("returns true for Zod 3 function schemas", () => {
161
- const schema = z3.function().args(z3.string()).returns(z3.void());
162
- expect((0, zod_1.isZodFunctionSchema)(schema)).toBe(true);
163
- expect((0, zod_1.isZod3FunctionSchema)(schema)).toBe(true);
164
- expect((0, zod_1.isZod4FunctionSchema)(schema)).toBe(false);
165
- });
166
- it("returns true for Zod 4 function schemas", () => {
167
- const schema = z4.function({
168
- input: z4.tuple([z4.string()]),
169
- output: z4.void(),
170
- });
171
- expect((0, zod_1.isZodFunctionSchema)(schema)).toBe(true);
172
- expect((0, zod_1.isZod3FunctionSchema)(schema)).toBe(false);
173
- expect((0, zod_1.isZod4FunctionSchema)(schema)).toBe(true);
174
- });
175
- it("returns false for non-function Zod schemas", () => {
176
- expect((0, zod_1.isZodFunctionSchema)(z3.string())).toBe(false);
177
- expect((0, zod_1.isZodFunctionSchema)(z3.object({ a: z3.string() }))).toBe(false);
178
- expect((0, zod_1.isZodFunctionSchema)(z4.string())).toBe(false);
179
- expect((0, zod_1.isZodFunctionSchema)(z4.object({ a: z4.string() }))).toBe(false);
180
- });
181
- it("returns false for non-Zod values", () => {
182
- expect((0, zod_1.isZodFunctionSchema)(null)).toBe(false);
183
- expect((0, zod_1.isZodFunctionSchema)({})).toBe(false);
184
- expect((0, zod_1.isZodFunctionSchema)("function")).toBe(false);
185
- });
186
- });
187
- describe("handleZodSchemaToJson", () => {
188
- describe("basic conversion", () => {
189
- it("converts Zod 3 schema to JSON Schema", () => {
190
- const schema = z3.object({
191
- name: z3.string(),
192
- age: z3.number(),
193
- });
194
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
195
- expect(result).toMatchObject({
196
- type: "object",
197
- properties: {
198
- name: { type: "string" },
199
- age: { type: "number" },
200
- },
201
- });
202
- });
203
- it("converts Zod 4 schema to JSON Schema", () => {
204
- const schema = z4.object({
205
- name: z4.string(),
206
- age: z4.number(),
207
- });
208
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
209
- expect(result).toMatchObject({
210
- type: "object",
211
- properties: {
212
- name: { type: "string" },
213
- age: { type: "number" },
214
- },
215
- });
216
- });
217
- });
218
- describe("reused schemas - no $ref references", () => {
219
- it("inlines reused Zod 3 schemas without any $ref in output", () => {
220
- // Define a shared schema that will be reused
221
- const dataSchema = z3.object({
222
- name: z3.string(),
223
- value: z3.number(),
224
- });
225
- // Use the same schema in multiple places
226
- const props = z3.object({
227
- data: z3.array(dataSchema),
228
- historicalData: z3.array(dataSchema),
229
- });
230
- const result = (0, zod_1.handleZodSchemaToJson)(props);
231
- // Ensure there are no JSON Schema `$ref` keys anywhere in the produced schema.
232
- expect(hasKeyDeep(result, "$ref")).toBe(false);
233
- // Both arrays should have the full schema inline
234
- expect(result).toMatchObject({
235
- type: "object",
236
- properties: {
237
- data: {
238
- type: "array",
239
- items: {
240
- type: "object",
241
- properties: {
242
- name: { type: "string" },
243
- value: { type: "number" },
244
- },
245
- },
246
- },
247
- historicalData: {
248
- type: "array",
249
- items: {
250
- type: "object",
251
- properties: {
252
- name: { type: "string" },
253
- value: { type: "number" },
254
- },
255
- },
256
- },
257
- },
258
- });
259
- });
260
- it("inlines reused Zod 4 schemas without any $ref in output", () => {
261
- // Define a shared schema that will be reused
262
- const dataSchema = z4.object({
263
- name: z4.string(),
264
- value: z4.number(),
265
- });
266
- // Use the same schema in multiple places
267
- const props = z4.object({
268
- data: z4.array(dataSchema),
269
- historicalData: z4.array(dataSchema),
270
- });
271
- const result = (0, zod_1.handleZodSchemaToJson)(props);
272
- expect(hasKeyDeep(result, "$ref")).toBe(false);
273
- // Both arrays should have the full schema inline
274
- expect(result).toMatchObject({
275
- type: "object",
276
- properties: {
277
- data: {
278
- type: "array",
279
- items: {
280
- type: "object",
281
- properties: {
282
- name: { type: "string" },
283
- value: { type: "number" },
284
- },
285
- },
286
- },
287
- historicalData: {
288
- type: "array",
289
- items: {
290
- type: "object",
291
- properties: {
292
- name: { type: "string" },
293
- value: { type: "number" },
294
- },
295
- },
296
- },
297
- },
298
- });
299
- });
300
- it("handles deeply nested reused Zod 3 schemas without any $ref", () => {
301
- const addressSchema = z3.object({
302
- street: z3.string(),
303
- city: z3.string(),
304
- });
305
- const personSchema = z3.object({
306
- name: z3.string(),
307
- homeAddress: addressSchema,
308
- workAddress: addressSchema,
309
- });
310
- const result = (0, zod_1.handleZodSchemaToJson)(personSchema);
311
- expect(hasKeyDeep(result, "$ref")).toBe(false);
312
- expect(result).toMatchObject({
313
- type: "object",
314
- properties: {
315
- name: { type: "string" },
316
- homeAddress: {
317
- type: "object",
318
- properties: {
319
- street: { type: "string" },
320
- city: { type: "string" },
321
- },
322
- },
323
- workAddress: {
324
- type: "object",
325
- properties: {
326
- street: { type: "string" },
327
- city: { type: "string" },
328
- },
329
- },
330
- },
331
- });
332
- });
333
- it("handles deeply nested reused Zod 4 schemas without any $ref", () => {
334
- const addressSchema = z4.object({
335
- street: z4.string(),
336
- city: z4.string(),
337
- });
338
- const personSchema = z4.object({
339
- name: z4.string(),
340
- homeAddress: addressSchema,
341
- workAddress: addressSchema,
342
- });
343
- const result = (0, zod_1.handleZodSchemaToJson)(personSchema);
344
- expect(hasKeyDeep(result, "$ref")).toBe(false);
345
- expect(result).toMatchObject({
346
- type: "object",
347
- properties: {
348
- name: { type: "string" },
349
- homeAddress: {
350
- type: "object",
351
- properties: {
352
- street: { type: "string" },
353
- city: { type: "string" },
354
- },
355
- },
356
- workAddress: {
357
- type: "object",
358
- properties: {
359
- street: { type: "string" },
360
- city: { type: "string" },
361
- },
362
- },
363
- },
364
- });
365
- });
366
- it("handles triple-nested reused Zod 4 schemas without any $ref", () => {
367
- const pointSchema = z4.object({
368
- x: z4.number(),
369
- y: z4.number(),
370
- });
371
- const lineSchema = z4.object({
372
- start: pointSchema,
373
- end: pointSchema,
374
- });
375
- const shapeSchema = z4.object({
376
- outline: z4.array(lineSchema),
377
- boundingBox: z4.object({
378
- topLeft: pointSchema,
379
- bottomRight: pointSchema,
380
- }),
381
- });
382
- const result = (0, zod_1.handleZodSchemaToJson)(shapeSchema);
383
- expect(result).toMatchInlineSnapshot(`
384
- {
385
- "$schema": "https://json-schema.org/draft/2020-12/schema",
386
- "additionalProperties": false,
387
- "properties": {
388
- "boundingBox": {
389
- "additionalProperties": false,
390
- "properties": {
391
- "bottomRight": {
392
- "additionalProperties": false,
393
- "properties": {
394
- "x": {
395
- "type": "number",
396
- },
397
- "y": {
398
- "type": "number",
399
- },
400
- },
401
- "required": [
402
- "x",
403
- "y",
404
- ],
405
- "type": "object",
406
- },
407
- "topLeft": {
408
- "additionalProperties": false,
409
- "properties": {
410
- "x": {
411
- "type": "number",
412
- },
413
- "y": {
414
- "type": "number",
415
- },
416
- },
417
- "required": [
418
- "x",
419
- "y",
420
- ],
421
- "type": "object",
422
- },
423
- },
424
- "required": [
425
- "topLeft",
426
- "bottomRight",
427
- ],
428
- "type": "object",
429
- },
430
- "outline": {
431
- "items": {
432
- "additionalProperties": false,
433
- "properties": {
434
- "end": {
435
- "additionalProperties": false,
436
- "properties": {
437
- "x": {
438
- "type": "number",
439
- },
440
- "y": {
441
- "type": "number",
442
- },
443
- },
444
- "required": [
445
- "x",
446
- "y",
447
- ],
448
- "type": "object",
449
- },
450
- "start": {
451
- "additionalProperties": false,
452
- "properties": {
453
- "x": {
454
- "type": "number",
455
- },
456
- "y": {
457
- "type": "number",
458
- },
459
- },
460
- "required": [
461
- "x",
462
- "y",
463
- ],
464
- "type": "object",
465
- },
466
- },
467
- "required": [
468
- "start",
469
- "end",
470
- ],
471
- "type": "object",
472
- },
473
- "type": "array",
474
- },
475
- },
476
- "required": [
477
- "outline",
478
- "boundingBox",
479
- ],
480
- "type": "object",
481
- }
482
- `);
483
- expect(hasKeyDeep(result, "$ref")).toBe(false);
484
- });
485
- });
486
- describe("recursive schemas", () => {
487
- it("represents Zod 4 recursive schemas using $ref", () => {
488
- const nodeSchema = createRecursiveZod4NodeSchema();
489
- const result = (0, zod_1.handleZodSchemaToJson)(nodeSchema);
490
- const schema = result;
491
- const properties = schema.properties;
492
- const next = properties?.next;
493
- const ref = next?.$ref;
494
- expect(hasKeyDeep(result, "$ref")).toBe(true);
495
- expect(result).toMatchObject({
496
- type: "object",
497
- properties: {
498
- next: {
499
- $ref: expect.stringMatching(/^#(\/.*)?$/),
500
- },
501
- },
502
- });
503
- expect(ref).toEqual(expect.stringMatching(/^#(\/.*)?$/));
504
- const resolved = typeof ref === "string" ? resolveJsonPointer(result, ref) : undefined;
505
- expect(resolved).toBe(result);
506
- expect(resolved).toMatchObject({
507
- type: "object",
508
- });
509
- });
510
- });
511
- describe("complex schemas", () => {
512
- it("handles optional fields in Zod 3", () => {
513
- const schema = z3.object({
514
- required: z3.string(),
515
- optional: z3.string().optional(),
516
- });
517
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
518
- expect(result).toMatchObject({
519
- type: "object",
520
- properties: {
521
- required: { type: "string" },
522
- optional: { type: "string" },
523
- },
524
- required: ["required"],
525
- });
526
- });
527
- it("handles optional fields in Zod 4", () => {
528
- const schema = z4.object({
529
- required: z4.string(),
530
- optional: z4.string().optional(),
531
- });
532
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
533
- expect(result).toMatchObject({
534
- type: "object",
535
- properties: {
536
- required: { type: "string" },
537
- optional: { type: "string" },
538
- },
539
- required: ["required"],
540
- });
541
- });
542
- it("handles enums in Zod 3", () => {
543
- const schema = z3.object({
544
- status: z3.enum(["active", "inactive", "pending"]),
545
- });
546
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
547
- expect(result).toMatchObject({
548
- type: "object",
549
- properties: {
550
- status: {
551
- type: "string",
552
- enum: ["active", "inactive", "pending"],
553
- },
554
- },
555
- });
556
- });
557
- it("handles enums in Zod 4", () => {
558
- const schema = z4.object({
559
- status: z4.enum(["active", "inactive", "pending"]),
560
- });
561
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
562
- expect(result).toMatchObject({
563
- type: "object",
564
- properties: {
565
- status: {
566
- type: "string",
567
- enum: ["active", "inactive", "pending"],
568
- },
569
- },
570
- });
571
- });
572
- it("handles descriptions in Zod 3", () => {
573
- const schema = z3.object({
574
- name: z3.string().describe("The user name"),
575
- });
576
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
577
- expect(result).toMatchObject({
578
- type: "object",
579
- properties: {
580
- name: {
581
- type: "string",
582
- description: "The user name",
583
- },
584
- },
585
- });
586
- });
587
- it("handles descriptions in Zod 4", () => {
588
- const schema = z4.object({
589
- name: z4.string().describe("The user name"),
590
- });
591
- const result = (0, zod_1.handleZodSchemaToJson)(schema);
592
- expect(result).toMatchObject({
593
- type: "object",
594
- properties: {
595
- name: {
596
- type: "string",
597
- description: "The user name",
598
- },
599
- },
600
- });
601
- });
602
- });
603
- });
604
- describe("getZodFunctionArgs", () => {
605
- it("extracts args from Zod 3 function schema", () => {
606
- const schema = z3
607
- .function()
608
- .args(z3.string(), z3.number())
609
- .returns(z3.boolean());
610
- const args = (0, zod_1.getZodFunctionArgs)(schema);
611
- expect(args).toBeDefined();
612
- // Zod 3 args is a ZodTuple - check the _def property exists
613
- expect(args._def.typeName).toBe("ZodTuple");
614
- });
615
- it("extracts args from Zod 4 function schema", () => {
616
- const schema = z4.function({
617
- input: z4.tuple([z4.string(), z4.number()]),
618
- output: z4.boolean(),
619
- });
620
- const args = (0, zod_1.getZodFunctionArgs)(schema);
621
- expect(args).toBeDefined();
622
- // Zod 4 args is accessed via .def.input - it's the tuple schema
623
- expect(args).toHaveProperty("def");
624
- });
625
- it("throws for non-function schemas", () => {
626
- expect(() => (0, zod_1.getZodFunctionArgs)(z3.string())).toThrow("Unable to determine parameters from zod function schema");
627
- expect(() => (0, zod_1.getZodFunctionArgs)(z4.string())).toThrow("Unable to determine parameters from zod function schema");
628
- });
629
- it("throws for non-Zod values", () => {
630
- expect(() => (0, zod_1.getZodFunctionArgs)({})).toThrow("Unable to determine parameters from zod function schema");
631
- });
632
- });
633
- describe("getZodFunctionReturns", () => {
634
- it("extracts returns from Zod 3 function schema", () => {
635
- const schema = z3
636
- .function()
637
- .args(z3.string())
638
- .returns(z3.object({ result: z3.boolean() }));
639
- const returns = (0, zod_1.getZodFunctionReturns)(schema);
640
- expect(returns).toBeDefined();
641
- // Cast to access _def property on Zod 3 schema
642
- expect(returns._def.typeName).toBe("ZodObject");
643
- });
644
- it("extracts returns from Zod 4 function schema", () => {
645
- const schema = z4.function({
646
- input: z4.tuple([z4.string()]),
647
- output: z4.object({ result: z4.boolean() }),
648
- });
649
- const returns = (0, zod_1.getZodFunctionReturns)(schema);
650
- expect(returns).toBeDefined();
651
- // Zod 4 returns is accessed via .def.output - it's the object schema
652
- expect(returns).toHaveProperty("def");
653
- });
654
- it("throws for non-function schemas", () => {
655
- expect(() => (0, zod_1.getZodFunctionReturns)(z3.string())).toThrow("Unable to determine return type from zod function schema");
656
- expect(() => (0, zod_1.getZodFunctionReturns)(z4.string())).toThrow("Unable to determine return type from zod function schema");
657
- });
658
- it("throws for non-Zod values", () => {
659
- expect(() => (0, zod_1.getZodFunctionReturns)({})).toThrow("Unable to determine return type from zod function schema");
660
- });
661
- });
662
- });
663
- //# sourceMappingURL=zod.test.js.map