mcp-use 1.7.0-canary.1 → 1.7.0-canary.2

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 (52) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-PE7UMCVO.js → chunk-3R5PDYIN.js} +27 -1
  3. package/dist/{chunk-QSLJXXMG.js → chunk-AGKMD2ZM.js} +4 -4
  4. package/dist/{chunk-XN2PU4PS.js → chunk-BG2APH43.js} +22 -5
  5. package/dist/{chunk-YURRUCIM.js → chunk-CPG2WZUL.js} +9 -11
  6. package/dist/{chunk-R5DJJ4IV.js → chunk-F4UHAA5L.js} +3 -91
  7. package/dist/chunk-MTHLLDCX.js +97 -0
  8. package/dist/{chunk-GVVPUU5K.js → chunk-S6K5QZBJ.js} +739 -29
  9. package/dist/{display-YIYC6WJE.js → display-A5IEINAP.js} +79 -17
  10. package/dist/index.cjs +923 -107
  11. package/dist/index.js +10 -9
  12. package/dist/{langfuse-C4HKZ3NL.js → langfuse-N5Y5BSXK.js} +1 -1
  13. package/dist/{oauth-CNGBFOZW.js → oauth-U4NNKN4B.js} +2 -1
  14. package/dist/src/agents/display.d.ts.map +1 -1
  15. package/dist/src/agents/index.cjs +854 -78
  16. package/dist/src/agents/index.js +3 -2
  17. package/dist/src/auth/index.cjs +30 -5
  18. package/dist/src/auth/index.js +1 -1
  19. package/dist/src/browser.cjs +888 -90
  20. package/dist/src/browser.js +5 -4
  21. package/dist/src/connectors/base.d.ts +52 -121
  22. package/dist/src/connectors/base.d.ts.map +1 -1
  23. package/dist/src/managers/server_manager.d.ts.map +1 -1
  24. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +2 -2
  25. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
  26. package/dist/src/managers/tools/add_server_from_config.d.ts +1 -7
  27. package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
  28. package/dist/src/managers/tools/connect_mcp_server.d.ts +2 -10
  29. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
  30. package/dist/src/managers/tools/list_mcp_servers.d.ts +2 -2
  31. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
  32. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +2 -2
  33. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
  34. package/dist/src/observability/langfuse.d.ts +4 -0
  35. package/dist/src/observability/langfuse.d.ts.map +1 -1
  36. package/dist/src/react/McpUseProvider.d.ts.map +1 -1
  37. package/dist/src/react/index.cjs +57 -12
  38. package/dist/src/react/index.js +4 -3
  39. package/dist/src/server/connect-adapter.d.ts.map +1 -1
  40. package/dist/src/server/index.cjs +5 -9
  41. package/dist/src/server/index.js +15 -17
  42. package/dist/src/server/mcp-server.d.ts.map +1 -1
  43. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts +270 -0
  44. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts.map +1 -0
  45. package/dist/src/utils/json-schema-to-zod/Type.d.ts +24 -0
  46. package/dist/src/utils/json-schema-to-zod/Type.d.ts.map +1 -0
  47. package/dist/src/utils/json-schema-to-zod/index.d.ts +3 -0
  48. package/dist/src/utils/json-schema-to-zod/index.d.ts.map +1 -0
  49. package/dist/src/utils/url-sanitize.d.ts +17 -0
  50. package/dist/src/utils/url-sanitize.d.ts.map +1 -0
  51. package/dist/tsup.config.d.ts.map +1 -1
  52. package/package.json +19 -36
@@ -1,3 +1,6 @@
1
+ import {
2
+ generateUUID
3
+ } from "./chunk-MTHLLDCX.js";
1
4
  import {
2
5
  logger
3
6
  } from "./chunk-34R6SIER.js";
@@ -118,16 +121,703 @@ var BaseAdapter = class {
118
121
  }
119
122
  };
120
123
 
124
+ // src/utils/json-schema-to-zod/JSONSchemaToZod.ts
125
+ import { z } from "zod";
126
+ var JSONSchemaToZod = class {
127
+ static {
128
+ __name(this, "JSONSchemaToZod");
129
+ }
130
+ /**
131
+ * Converts a JSON schema to a Zod schema.
132
+ *
133
+ * @param {JSONSchema} schema - The JSON schema.
134
+ * @returns {ZodSchema} - The Zod schema.
135
+ */
136
+ static convert(schema) {
137
+ return this.parseSchema(schema);
138
+ }
139
+ /**
140
+ * Checks if data matches a condition schema.
141
+ *
142
+ * @param {JSONValue} data - The data to check.
143
+ * @param {JSONSchema} condition - The condition schema.
144
+ * @returns {boolean} - Whether the data matches the condition.
145
+ */
146
+ static matchesCondition(data, condition) {
147
+ if (!condition.properties) {
148
+ return true;
149
+ }
150
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
151
+ return false;
152
+ }
153
+ const objectData = data;
154
+ for (const [key, propCondition] of Object.entries(condition.properties)) {
155
+ if (!(key in objectData)) {
156
+ if ("const" in propCondition) {
157
+ return false;
158
+ }
159
+ continue;
160
+ }
161
+ const value = objectData[key];
162
+ if ("const" in propCondition && value !== propCondition["const"]) {
163
+ return false;
164
+ }
165
+ if ("minimum" in propCondition && typeof value === "number" && value < propCondition["minimum"]) {
166
+ return false;
167
+ }
168
+ if ("maximum" in propCondition && typeof value === "number" && value > propCondition["maximum"]) {
169
+ return false;
170
+ }
171
+ }
172
+ return true;
173
+ }
174
+ /**
175
+ * Validates data against a conditional schema and adds issues to context if validation fails.
176
+ *
177
+ * @param {JSONValue} data - The data to validate.
178
+ * @param {JSONSchema} schema - The conditional schema.
179
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
180
+ */
181
+ static validateConditionalSchema(data, schema, ctx) {
182
+ this.validateRequiredProperties(data, schema, ctx);
183
+ this.validatePropertyPatterns(data, schema, ctx);
184
+ this.validateNestedConditions(data, schema, ctx);
185
+ }
186
+ /**
187
+ * Validates that all required properties are present in the data.
188
+ *
189
+ * @param {JSONValue} data - The data to validate.
190
+ * @param {JSONSchema} schema - The schema containing required properties.
191
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
192
+ */
193
+ static validateRequiredProperties(data, schema, ctx) {
194
+ if (!schema.required) {
195
+ return;
196
+ }
197
+ if (typeof data !== "object" || data === null) {
198
+ for (const requiredProp of schema.required) {
199
+ ctx.addIssue({
200
+ code: z.ZodIssueCode.custom,
201
+ message: `Required property '${requiredProp}' is missing`,
202
+ path: [requiredProp]
203
+ });
204
+ }
205
+ return;
206
+ }
207
+ for (const requiredProp of schema.required) {
208
+ if (!(requiredProp in data)) {
209
+ ctx.addIssue({
210
+ code: z.ZodIssueCode.custom,
211
+ message: `Required property '${requiredProp}' is missing`,
212
+ path: [requiredProp]
213
+ });
214
+ }
215
+ }
216
+ }
217
+ /**
218
+ * Validates property patterns for string properties.
219
+ *
220
+ * @param {JSONValue} data - The data to validate.
221
+ * @param {JSONSchema} schema - The schema containing property patterns.
222
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
223
+ */
224
+ static validatePropertyPatterns(data, schema, ctx) {
225
+ if (!schema.properties) {
226
+ return;
227
+ }
228
+ if (typeof data !== "object" || data === null) {
229
+ return;
230
+ }
231
+ if (Array.isArray(data)) {
232
+ return;
233
+ }
234
+ const objectData = data;
235
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
236
+ if (!(key in objectData)) {
237
+ continue;
238
+ }
239
+ const value = objectData[key];
240
+ if (propSchema["pattern"] && typeof value === "string") {
241
+ const regex = new RegExp(propSchema["pattern"]);
242
+ if (!regex.test(value)) {
243
+ ctx.addIssue({
244
+ code: z.ZodIssueCode.custom,
245
+ message: `String '${value}' does not match pattern '${propSchema["pattern"]}'`,
246
+ path: [key]
247
+ });
248
+ }
249
+ }
250
+ }
251
+ }
252
+ /**
253
+ * Validates nested if-then-else conditions.
254
+ *
255
+ * @param {JSONValue} data - The data to validate.
256
+ * @param {JSONSchema} schema - The schema containing if-then-else conditions.
257
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
258
+ */
259
+ static validateNestedConditions(data, schema, ctx) {
260
+ if (!schema["if"] || !schema["then"]) {
261
+ return;
262
+ }
263
+ const matchesIf = this.matchesCondition(data, schema["if"]);
264
+ if (matchesIf) {
265
+ this.validateConditionalSchema(data, schema["then"], ctx);
266
+ } else if (schema["else"]) {
267
+ this.validateConditionalSchema(data, schema["else"], ctx);
268
+ }
269
+ }
270
+ /**
271
+ * Parses a JSON schema and returns the corresponding Zod schema.
272
+ * This is the main entry point for schema conversion.
273
+ *
274
+ * @param {JSONSchema} schema - The JSON schema.
275
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
276
+ */
277
+ static parseSchema(schema) {
278
+ if (Array.isArray(schema.type)) {
279
+ return this.handleTypeArray(schema);
280
+ }
281
+ if (schema.oneOf || schema.anyOf || schema.allOf) {
282
+ return this.parseCombinator(schema);
283
+ }
284
+ if (schema["if"] && schema["then"]) {
285
+ return this.parseObject(schema);
286
+ }
287
+ if (schema.properties && (!schema.type || schema.type === "object")) {
288
+ return this.parseObject(schema);
289
+ }
290
+ return this.handleSingleType(schema);
291
+ }
292
+ /**
293
+ * Handles schemas with an array of types.
294
+ *
295
+ * @param {JSONSchema} schema - The JSON schema with type array.
296
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
297
+ */
298
+ static handleTypeArray(schema) {
299
+ if (!Array.isArray(schema.type)) {
300
+ throw new Error("Expected schema.type to be an array");
301
+ }
302
+ if (schema.type.includes("null")) {
303
+ return this.handleNullableType(schema);
304
+ }
305
+ return this.createUnionFromTypes(schema.type, schema);
306
+ }
307
+ /**
308
+ * Handles nullable types by creating a nullable schema.
309
+ *
310
+ * @param {JSONSchema} schema - The JSON schema with nullable type.
311
+ * @returns {ZodTypeAny} - The nullable Zod schema.
312
+ */
313
+ static handleNullableType(schema) {
314
+ if (!Array.isArray(schema.type)) {
315
+ throw new Error("Expected schema.type to be an array");
316
+ }
317
+ const nonNullSchema = { ...schema };
318
+ nonNullSchema.type = schema.type.filter((t) => t !== "null");
319
+ if (nonNullSchema.type.length === 1) {
320
+ const singleTypeSchema = this.handleSingleType({
321
+ ...schema,
322
+ type: nonNullSchema.type[0]
323
+ });
324
+ return singleTypeSchema.nullable();
325
+ }
326
+ const unionSchema = this.parseSchema(nonNullSchema);
327
+ return unionSchema.nullable();
328
+ }
329
+ /**
330
+ * Creates a union type from an array of types.
331
+ *
332
+ * @param {string[]} types - Array of type strings.
333
+ * @param {JSONSchema} baseSchema - The base schema to apply to each type.
334
+ * @returns {ZodTypeAny} - The union Zod schema.
335
+ */
336
+ static createUnionFromTypes(types, baseSchema) {
337
+ const schemas = types.map((type) => {
338
+ const singleTypeSchema = { ...baseSchema, type };
339
+ return this.parseSchema(singleTypeSchema);
340
+ });
341
+ return z.union(schemas);
342
+ }
343
+ /**
344
+ * Handles schemas with a single type.
345
+ *
346
+ * @param {JSONSchema} schema - The JSON schema with single type.
347
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
348
+ */
349
+ static handleSingleType(schema) {
350
+ if (schema.type === void 0) {
351
+ if (schema.oneOf || schema.anyOf || schema.allOf) {
352
+ return this.parseCombinator(schema);
353
+ }
354
+ if (schema.properties) {
355
+ return this.parseObject(schema);
356
+ }
357
+ return z.any();
358
+ }
359
+ switch (schema.type) {
360
+ case "string":
361
+ return this.parseString(schema);
362
+ case "number":
363
+ case "integer":
364
+ return this.parseNumberSchema(schema);
365
+ case "boolean":
366
+ return z.boolean();
367
+ case "array":
368
+ return this.parseArray(schema);
369
+ case "object":
370
+ return this.parseObject(schema);
371
+ default:
372
+ throw new Error("Unsupported schema type");
373
+ }
374
+ }
375
+ /**
376
+ * Parses a number schema.
377
+ *
378
+ * @param {JSONSchema} schema - The JSON schema for a number.
379
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
380
+ */
381
+ static parseNumberSchema(schema) {
382
+ const numberSchema = z.number();
383
+ let result = numberSchema;
384
+ result = this.applyNumberBounds(numberSchema, schema);
385
+ result = this.applyNumberMultipleOf(numberSchema, schema);
386
+ result = this.applyNumberEnum(numberSchema, schema);
387
+ result = this.applyIntegerConstraint(numberSchema, schema);
388
+ return result;
389
+ }
390
+ /**
391
+ * Applies bounds validation to a number schema.
392
+ *
393
+ * @param {z.ZodNumber} numberSchema - The base number schema.
394
+ * @param {JSONSchema} schema - The JSON schema with bounds.
395
+ * @returns {z.ZodNumber} - The updated schema with bounds validation.
396
+ */
397
+ static applyNumberBounds(numberSchema, schema) {
398
+ let result = numberSchema;
399
+ if (schema["minimum"] !== void 0) {
400
+ result = schema["exclusiveMinimum"] ? result.gt(schema["minimum"]) : result.gte(schema["minimum"]);
401
+ }
402
+ if (schema["maximum"] !== void 0) {
403
+ result = schema["exclusiveMaximum"] ? result.lt(schema["maximum"]) : result.lte(schema["maximum"]);
404
+ }
405
+ return result;
406
+ }
407
+ /**
408
+ * Applies multipleOf validation to a number schema.
409
+ *
410
+ * @param {z.ZodNumber} numberSchema - The base number schema.
411
+ * @param {JSONSchema} schema - The JSON schema with multipleOf.
412
+ * @returns {z.ZodNumber} - The updated schema with multipleOf validation.
413
+ */
414
+ static applyNumberMultipleOf(numberSchema, schema) {
415
+ if (schema["multipleOf"] === void 0) {
416
+ return numberSchema;
417
+ }
418
+ return numberSchema.refine((val) => val % schema["multipleOf"] === 0, {
419
+ message: `Number must be a multiple of ${schema["multipleOf"]}`
420
+ });
421
+ }
422
+ /**
423
+ * Applies enum validation to a number schema.
424
+ *
425
+ * @param {z.ZodNumber} numberSchema - The base number schema.
426
+ * @param {JSONSchema} schema - The JSON schema with enum.
427
+ * @returns {z.ZodNumber} - The updated schema with enum validation.
428
+ */
429
+ static applyNumberEnum(numberSchema, schema) {
430
+ if (!schema.enum) {
431
+ return numberSchema;
432
+ }
433
+ const numberEnums = schema.enum.filter(
434
+ (val) => typeof val === "number"
435
+ );
436
+ if (numberEnums.length === 0) {
437
+ return numberSchema;
438
+ }
439
+ return numberSchema.refine((val) => numberEnums.includes(val), {
440
+ message: `Number must be one of: ${numberEnums.join(", ")}`
441
+ });
442
+ }
443
+ /**
444
+ * Applies integer constraint to a number schema if needed.
445
+ *
446
+ * @param {z.ZodNumber} numberSchema - The base number schema.
447
+ * @param {JSONSchema} schema - The JSON schema.
448
+ * @returns {z.ZodNumber} - The updated schema with integer validation if needed.
449
+ */
450
+ static applyIntegerConstraint(numberSchema, schema) {
451
+ if (schema.type !== "integer") {
452
+ return numberSchema;
453
+ }
454
+ return numberSchema.refine((val) => Number.isInteger(val), {
455
+ message: "Number must be an integer"
456
+ });
457
+ }
458
+ /**
459
+ * Parses a string schema.
460
+ *
461
+ * @param {JSONSchema} schema - The JSON schema for a string.
462
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
463
+ */
464
+ static parseString(schema) {
465
+ const stringSchema = z.string();
466
+ let result = stringSchema;
467
+ if (schema.format) {
468
+ return this.applyStringFormat(stringSchema, schema);
469
+ } else {
470
+ result = this.applyStringPattern(stringSchema, schema);
471
+ result = this.applyStringLength(stringSchema, schema);
472
+ result = this.applyStringEnum(stringSchema, schema);
473
+ }
474
+ return result;
475
+ }
476
+ /**
477
+ * Applies format validation to a string schema.
478
+ *
479
+ * @param {z.ZodString} stringSchema - The base string schema.
480
+ * @param {JSONSchema} schema - The JSON schema with format.
481
+ * @returns {ZodTypeAny} - The updated schema with format validation.
482
+ */
483
+ static applyStringFormat(stringSchema, schema) {
484
+ if (!schema.format) {
485
+ return stringSchema;
486
+ }
487
+ switch (schema.format) {
488
+ case "email":
489
+ return stringSchema.email();
490
+ case "date-time":
491
+ return stringSchema.datetime();
492
+ case "uri":
493
+ return stringSchema.url();
494
+ case "uuid":
495
+ return stringSchema.uuid();
496
+ case "date":
497
+ return stringSchema.date();
498
+ default:
499
+ return stringSchema;
500
+ }
501
+ }
502
+ /**
503
+ * Applies pattern validation to a string schema.
504
+ *
505
+ * @param {z.ZodString} stringSchema - The base string schema.
506
+ * @param {JSONSchema} schema - The JSON schema with pattern.
507
+ * @returns {z.ZodString} - The updated schema with pattern validation.
508
+ */
509
+ static applyStringPattern(stringSchema, schema) {
510
+ if (!schema["pattern"]) {
511
+ return stringSchema;
512
+ }
513
+ const regex = new RegExp(schema["pattern"]);
514
+ return stringSchema.regex(regex, {
515
+ message: `String must match pattern: ${schema["pattern"]}`
516
+ });
517
+ }
518
+ /**
519
+ * Applies length constraints to a string schema.
520
+ *
521
+ * @param {z.ZodString} stringSchema - The base string schema.
522
+ * @param {JSONSchema} schema - The JSON schema with length constraints.
523
+ * @returns {z.ZodString} - The updated schema with length validation.
524
+ */
525
+ static applyStringLength(stringSchema, schema) {
526
+ const result = stringSchema;
527
+ if (schema["minLength"] !== void 0) {
528
+ stringSchema = stringSchema.min(schema["minLength"]);
529
+ }
530
+ if (schema["maxLength"] !== void 0) {
531
+ stringSchema = stringSchema.max(schema["maxLength"]);
532
+ }
533
+ return result;
534
+ }
535
+ /**
536
+ * Applies enum validation to a string schema.
537
+ *
538
+ * @param {z.ZodString} stringSchema - The base string schema.
539
+ * @param {JSONSchema} schema - The JSON schema with enum.
540
+ * @returns {ZodTypeAny} - The updated schema with enum validation.
541
+ */
542
+ static applyStringEnum(stringSchema, schema) {
543
+ if (!schema.enum) {
544
+ return stringSchema;
545
+ }
546
+ return stringSchema.refine((val) => schema.enum?.includes(val), {
547
+ message: `Value must be one of: ${schema.enum?.join(", ")}`
548
+ });
549
+ }
550
+ /**
551
+ * Parses a JSON schema of type array and returns the corresponding Zod schema.
552
+ *
553
+ * @param {JSONSchema} schema - The JSON schema.
554
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
555
+ */
556
+ static parseArray(schema) {
557
+ if (Array.isArray(schema.items)) {
558
+ const tupleSchemas = schema.items.map((item) => this.parseSchema(item));
559
+ return z.union(tupleSchemas);
560
+ }
561
+ const itemSchema = schema.items ? this.parseSchema(schema.items) : z.any();
562
+ const arraySchema = z.array(itemSchema);
563
+ let result = arraySchema;
564
+ result = this.applyArrayConstraints(arraySchema, schema);
565
+ return result;
566
+ }
567
+ /**
568
+ * Applies constraints to an array schema.
569
+ *
570
+ * @param {z.ZodArray<any>} arraySchema - The base array schema.
571
+ * @param {JSONSchema} schema - The JSON schema with array constraints.
572
+ * @returns {z.ZodTypeAny} - The updated array schema with constraints.
573
+ */
574
+ static applyArrayConstraints(arraySchema, schema) {
575
+ if (schema["minItems"] !== void 0) {
576
+ arraySchema = arraySchema.min(schema["minItems"]);
577
+ }
578
+ if (schema["maxItems"] !== void 0) {
579
+ arraySchema = arraySchema.max(schema["maxItems"]);
580
+ }
581
+ if (schema["uniqueItems"]) {
582
+ return arraySchema.refine(
583
+ (items) => new Set(items).size === items.length,
584
+ { message: "Array items must be unique" }
585
+ );
586
+ }
587
+ return arraySchema;
588
+ }
589
+ /**
590
+ * Parses an object schema.
591
+ *
592
+ * @param {JSONSchema} schema - The JSON schema for an object.
593
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
594
+ */
595
+ static parseObject(schema) {
596
+ if (schema["if"] && schema["then"]) {
597
+ return this.parseConditional(schema);
598
+ }
599
+ const shape = {};
600
+ this.processObjectProperties(schema, shape);
601
+ return this.processAdditionalProperties(schema, z.object(shape));
602
+ }
603
+ /**
604
+ * Processes object properties and builds the shape object.
605
+ *
606
+ * @param {JSONSchema} schema - The JSON schema for an object.
607
+ * @param {Record<string, ZodTypeAny>} shape - The shape object to populate.
608
+ */
609
+ static processObjectProperties(schema, shape) {
610
+ const required = new Set(schema.required || []);
611
+ if (!schema.properties) {
612
+ return;
613
+ }
614
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
615
+ const zodSchema = this.parseSchema(propSchema);
616
+ shape[key] = required.has(key) ? zodSchema : zodSchema.optional();
617
+ }
618
+ }
619
+ /**
620
+ * Processes additionalProperties configuration.
621
+ *
622
+ * @param {JSONSchema} schema - The JSON schema for an object.
623
+ * @param {z.ZodObject<any, any>} objectSchema - The Zod object schema.
624
+ * @returns {z.ZodObject<any, any>} - The updated Zod object schema.
625
+ */
626
+ static processAdditionalProperties(schema, objectSchema) {
627
+ if (schema.additionalProperties === true) {
628
+ return objectSchema.passthrough();
629
+ } else if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
630
+ const additionalPropSchema = this.parseSchema(
631
+ schema.additionalProperties
632
+ );
633
+ return objectSchema.catchall(additionalPropSchema);
634
+ } else {
635
+ return objectSchema.strict();
636
+ }
637
+ }
638
+ /**
639
+ * Parses a conditional schema with if-then-else.
640
+ *
641
+ * @param {JSONSchema} schema - The JSON schema with conditional validation.
642
+ * @returns {ZodTypeAny} - The conditional Zod schema.
643
+ */
644
+ static parseConditional(schema) {
645
+ const zodObject = this.createBaseObjectSchema(schema);
646
+ const ifCondition = schema["if"];
647
+ const thenSchema = schema["then"];
648
+ const elseSchema = schema["else"];
649
+ return zodObject.superRefine((data, ctx) => {
650
+ const dataWithDefaults = this.applyDefaultValues(
651
+ data,
652
+ schema
653
+ );
654
+ if (this.matchesCondition(dataWithDefaults, ifCondition)) {
655
+ this.validateConditionalSchema(dataWithDefaults, thenSchema, ctx);
656
+ } else if (elseSchema) {
657
+ this.validateConditionalSchema(dataWithDefaults, elseSchema, ctx);
658
+ }
659
+ });
660
+ }
661
+ /**
662
+ * Creates a base object schema from the given JSON schema.
663
+ *
664
+ * @param {JSONSchema} schema - The JSON schema.
665
+ * @returns {z.ZodObject<any, any>} - The base Zod object schema.
666
+ */
667
+ static createBaseObjectSchema(schema) {
668
+ const shape = {};
669
+ const required = new Set(schema.required || []);
670
+ for (const [key, value] of Object.entries(schema.properties || {})) {
671
+ const zodSchema = this.parseSchema(value);
672
+ shape[key] = required.has(key) ? zodSchema : zodSchema.optional();
673
+ }
674
+ const zodObject = z.object(shape);
675
+ return this.processAdditionalProperties(schema, zodObject);
676
+ }
677
+ /**
678
+ * Applies default values from schema properties to data object.
679
+ *
680
+ * @param {JSONValue} data - The original data object.
681
+ * @param {JSONSchema} schema - The schema with default values.
682
+ * @returns {JSONValue} - The data object with defaults applied.
683
+ */
684
+ static applyDefaultValues(data, schema) {
685
+ if (typeof data !== "object" || data === null) {
686
+ return data;
687
+ }
688
+ if (Array.isArray(data)) {
689
+ return data;
690
+ }
691
+ const objectData = data;
692
+ const dataWithDefaults = { ...objectData };
693
+ if (!schema.properties) {
694
+ return dataWithDefaults;
695
+ }
696
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
697
+ if (!(key in dataWithDefaults) && "default" in propSchema) {
698
+ dataWithDefaults[key] = propSchema["default"];
699
+ }
700
+ }
701
+ return dataWithDefaults;
702
+ }
703
+ /**
704
+ * Parses a schema with combinators (oneOf, anyOf, allOf).
705
+ * Delegates to the appropriate combinator parser based on which combinator is present.
706
+ *
707
+ * @param {JSONSchema} schema - The JSON schema with combinators.
708
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
709
+ */
710
+ static parseCombinator(schema) {
711
+ if (schema.oneOf) {
712
+ return this.parseOneOf(schema.oneOf);
713
+ }
714
+ if (schema.anyOf) {
715
+ return this.parseAnyOf(schema.anyOf);
716
+ }
717
+ if (schema.allOf) {
718
+ return this.parseAllOf(schema.allOf);
719
+ }
720
+ throw new Error("Unsupported schema type");
721
+ }
722
+ /**
723
+ * Parses a oneOf combinator schema.
724
+ *
725
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the oneOf.
726
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
727
+ */
728
+ static parseOneOf(schemas) {
729
+ return this.createUnionFromSchemas(schemas);
730
+ }
731
+ /**
732
+ * Parses an anyOf combinator schema.
733
+ *
734
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the anyOf.
735
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
736
+ */
737
+ static parseAnyOf(schemas) {
738
+ return this.createUnionFromSchemas(schemas);
739
+ }
740
+ /**
741
+ * Creates a union from an array of schemas, handling special cases.
742
+ *
743
+ * @param {JSONSchema[]} schemas - Array of JSON schemas to create a union from.
744
+ * @returns {ZodTypeAny} - The union Zod schema.
745
+ */
746
+ static createUnionFromSchemas(schemas) {
747
+ if (schemas.length === 0) {
748
+ return z.any();
749
+ }
750
+ if (schemas.length === 1) {
751
+ return this.parseSchema(schemas[0]);
752
+ }
753
+ const zodSchemas = [];
754
+ for (const subSchema of schemas) {
755
+ if (subSchema.type === "null") {
756
+ zodSchemas.push(z.null());
757
+ } else {
758
+ zodSchemas.push(this.parseSchema(subSchema));
759
+ }
760
+ }
761
+ if (zodSchemas.length >= 2) {
762
+ return z.union(zodSchemas);
763
+ } else if (zodSchemas.length === 1) {
764
+ return zodSchemas[0];
765
+ }
766
+ return z.any();
767
+ }
768
+ /**
769
+ * Parses an allOf combinator schema by merging all schemas.
770
+ *
771
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the allOf.
772
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
773
+ */
774
+ static parseAllOf(schemas) {
775
+ if (schemas.length === 0) {
776
+ return z.any();
777
+ }
778
+ if (schemas.length === 1) {
779
+ return this.parseSchema(schemas[0]);
780
+ }
781
+ const mergedSchema = schemas.reduce(
782
+ (acc, currentSchema) => this.mergeSchemas(acc, currentSchema)
783
+ );
784
+ return this.parseSchema(mergedSchema);
785
+ }
786
+ /**
787
+ * Merges two JSON schemas together.
788
+ *
789
+ * @param {JSONSchema} baseSchema - The base JSON schema.
790
+ * @param {JSONSchema} addSchema - The JSON schema to add.
791
+ * @returns {JSONSchema} - The merged JSON schema
792
+ */
793
+ static mergeSchemas(baseSchema, addSchema) {
794
+ const merged = { ...baseSchema, ...addSchema };
795
+ if (baseSchema.properties && addSchema.properties) {
796
+ const mergedProperties = {
797
+ ...baseSchema.properties,
798
+ ...addSchema.properties
799
+ };
800
+ merged.properties = mergedProperties;
801
+ }
802
+ if (baseSchema.required && addSchema.required) {
803
+ const mergedRequired = [
804
+ .../* @__PURE__ */ new Set([...baseSchema.required, ...addSchema.required])
805
+ ];
806
+ merged.required = mergedRequired;
807
+ }
808
+ return merged;
809
+ }
810
+ };
811
+
121
812
  // src/adapters/langchain_adapter.ts
122
- import { JSONSchemaToZod } from "@dmitryrechkin/json-schema-to-zod";
123
813
  import { DynamicStructuredTool } from "@langchain/core/tools";
124
- import { z } from "zod";
814
+ import { z as z2 } from "zod";
125
815
  function schemaToZod(schema) {
126
816
  try {
127
817
  return JSONSchemaToZod.convert(schema);
128
818
  } catch (err) {
129
819
  logger.warn(`Failed to convert JSON schema to Zod: ${err}`);
130
- return z.any();
820
+ return z2.any();
131
821
  }
132
822
  }
133
823
  __name(schemaToZod, "schemaToZod");
@@ -145,7 +835,7 @@ var LangChainAdapter = class extends BaseAdapter {
145
835
  if (this.disallowedTools.includes(mcpTool.name)) {
146
836
  return null;
147
837
  }
148
- const argsSchema = mcpTool.inputSchema ? schemaToZod(mcpTool.inputSchema) : z.object({}).optional();
838
+ const argsSchema = mcpTool.inputSchema ? schemaToZod(mcpTool.inputSchema) : z2.object({}).optional();
149
839
  const tool = new DynamicStructuredTool({
150
840
  name: mcpTool.name ?? "NO NAME",
151
841
  description: mcpTool.description ?? "",
@@ -172,7 +862,7 @@ var LangChainAdapter = class extends BaseAdapter {
172
862
  };
173
863
 
174
864
  // src/managers/tools/acquire_active_mcp_server.ts
175
- import { z as z2 } from "zod";
865
+ import { z as z3 } from "zod";
176
866
 
177
867
  // src/managers/tools/base.ts
178
868
  import { StructuredTool } from "@langchain/core/tools";
@@ -197,7 +887,7 @@ var MCPServerTool = class extends StructuredTool {
197
887
  };
198
888
 
199
889
  // src/managers/tools/acquire_active_mcp_server.ts
200
- var PresentActiveServerSchema = z2.object({});
890
+ var PresentActiveServerSchema = z3.object({});
201
891
  var AcquireActiveMCPServerTool = class extends MCPServerTool {
202
892
  static {
203
893
  __name(this, "AcquireActiveMCPServerTool");
@@ -218,16 +908,16 @@ var AcquireActiveMCPServerTool = class extends MCPServerTool {
218
908
 
219
909
  // src/managers/tools/add_server_from_config.ts
220
910
  import { StructuredTool as StructuredTool2 } from "@langchain/core/tools";
221
- import { z as z3 } from "zod";
911
+ import { z as z4 } from "zod";
222
912
  var AddMCPServerFromConfigTool = class extends StructuredTool2 {
223
913
  static {
224
914
  __name(this, "AddMCPServerFromConfigTool");
225
915
  }
226
916
  name = "add_mcp_server_from_config";
227
917
  description = "Adds a new MCP server to the client from a configuration object and connects to it, making its tools available.";
228
- schema = z3.object({
229
- serverName: z3.string().describe("The name for the new MCP server."),
230
- serverConfig: z3.any().describe(
918
+ schema = z4.object({
919
+ serverName: z4.string().describe("The name for the new MCP server."),
920
+ serverConfig: z4.any().describe(
231
921
  'The configuration object for the server. This should not include the top-level "mcpServers" key.'
232
922
  )
233
923
  });
@@ -269,9 +959,9 @@ ${tools.map((t) => t.name).join("\n")}`;
269
959
  };
270
960
 
271
961
  // src/managers/tools/connect_mcp_server.ts
272
- import { z as z4 } from "zod";
273
- var ConnectMCPServerSchema = z4.object({
274
- serverName: z4.string().describe("The name of the MCP server.")
962
+ import { z as z5 } from "zod";
963
+ var ConnectMCPServerSchema = z5.object({
964
+ serverName: z5.string().describe("The name of the MCP server.")
275
965
  });
276
966
  var ConnectMCPServerTool = class extends MCPServerTool {
277
967
  static {
@@ -319,8 +1009,8 @@ var ConnectMCPServerTool = class extends MCPServerTool {
319
1009
  };
320
1010
 
321
1011
  // src/managers/tools/list_mcp_servers.ts
322
- import { z as z5 } from "zod";
323
- var EnumerateServersSchema = z5.object({});
1012
+ import { z as z6 } from "zod";
1013
+ var EnumerateServersSchema = z6.object({});
324
1014
  var ListMCPServersTool = class extends MCPServerTool {
325
1015
  static {
326
1016
  __name(this, "ListMCPServersTool");
@@ -357,8 +1047,8 @@ var ListMCPServersTool = class extends MCPServerTool {
357
1047
  };
358
1048
 
359
1049
  // src/managers/tools/release_mcp_server_connection.ts
360
- import { z as z6 } from "zod";
361
- var ReleaseConnectionSchema = z6.object({});
1050
+ import { z as z7 } from "zod";
1051
+ var ReleaseConnectionSchema = z7.object({});
362
1052
  var ReleaseMCPServerConnectionTool = class extends MCPServerTool {
363
1053
  static {
364
1054
  __name(this, "ReleaseMCPServerConnectionTool");
@@ -380,7 +1070,28 @@ var ReleaseMCPServerConnectionTool = class extends MCPServerTool {
380
1070
  };
381
1071
 
382
1072
  // src/managers/server_manager.ts
383
- import { isEqual } from "lodash-es";
1073
+ function isEqual(a, b) {
1074
+ if (a === b) return true;
1075
+ if (a == null || b == null) return false;
1076
+ if (typeof a !== typeof b) return false;
1077
+ if (a instanceof Date && b instanceof Date) {
1078
+ return a.getTime() === b.getTime();
1079
+ }
1080
+ if (Array.isArray(a) && Array.isArray(b)) {
1081
+ if (a.length !== b.length) return false;
1082
+ return a.every((item, index) => isEqual(item, b[index]));
1083
+ }
1084
+ if (typeof a === "object" && typeof b === "object") {
1085
+ const keysA = Object.keys(a);
1086
+ const keysB = Object.keys(b);
1087
+ if (keysA.length !== keysB.length) return false;
1088
+ return keysA.every((key) => {
1089
+ return Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]);
1090
+ });
1091
+ }
1092
+ return false;
1093
+ }
1094
+ __name(isEqual, "isEqual");
384
1095
  var ServerManager = class {
385
1096
  static {
386
1097
  __name(this, "ServerManager");
@@ -531,9 +1242,9 @@ var ObservabilityManager = class {
531
1242
  return;
532
1243
  }
533
1244
  try {
534
- const { langfuseHandler: langfuseHandler2, langfuseInitPromise: langfuseInitPromise2 } = await import("./langfuse-C4HKZ3NL.js");
1245
+ const { langfuseHandler: langfuseHandler2, langfuseInitPromise: langfuseInitPromise2 } = await import("./langfuse-N5Y5BSXK.js");
535
1246
  if (this.agentId || this.metadata || this.metadataProvider || this.tagsProvider) {
536
- const { initializeLangfuse } = await import("./langfuse-C4HKZ3NL.js");
1247
+ const { initializeLangfuse } = await import("./langfuse-N5Y5BSXK.js");
537
1248
  await initializeLangfuse(
538
1249
  this.agentId,
539
1250
  this.metadata,
@@ -694,7 +1405,6 @@ import * as fs2 from "fs";
694
1405
  import * as os from "os";
695
1406
  import * as path2 from "path";
696
1407
  import { PostHog } from "posthog-node";
697
- import { v4 as uuidv4 } from "uuid";
698
1408
 
699
1409
  // src/telemetry/events.ts
700
1410
  var BaseTelemetryEvent = class {
@@ -957,7 +1667,7 @@ var Telemetry = class _Telemetry {
957
1667
  if (isFirstTime) {
958
1668
  logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
959
1669
  fs2.mkdirSync(path2.dirname(this.USER_ID_PATH), { recursive: true });
960
- const newUserId = uuidv4();
1670
+ const newUserId = generateUUID();
961
1671
  fs2.writeFileSync(this.USER_ID_PATH, newUserId);
962
1672
  this._currUserId = newUserId;
963
1673
  logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
@@ -1088,7 +1798,7 @@ function setTelemetrySource(source) {
1088
1798
  __name(setTelemetrySource, "setTelemetrySource");
1089
1799
 
1090
1800
  // src/agents/remote.ts
1091
- import { zodToJsonSchema } from "zod-to-json-schema";
1801
+ import { toJSONSchema } from "zod";
1092
1802
  var API_CHATS_ENDPOINT = "/api/v1/chats";
1093
1803
  var API_CHAT_EXECUTE_ENDPOINT = "/api/v1/chats/{chat_id}/execute";
1094
1804
  var RemoteAgent = class {
@@ -1111,7 +1821,7 @@ var RemoteAgent = class {
1111
1821
  this.apiKey = apiKey;
1112
1822
  }
1113
1823
  pydanticToJsonSchema(schema) {
1114
- return zodToJsonSchema(schema);
1824
+ return toJSONSchema(schema);
1115
1825
  }
1116
1826
  parseStructuredResponse(responseData, outputSchema) {
1117
1827
  let resultData;
@@ -1326,7 +2036,7 @@ import {
1326
2036
  SystemMessage as SystemMessage2,
1327
2037
  ToolMessage
1328
2038
  } from "langchain";
1329
- import { zodToJsonSchema as zodToJsonSchema2 } from "zod-to-json-schema";
2039
+ import { toJSONSchema as toJSONSchema2 } from "zod";
1330
2040
 
1331
2041
  // src/agents/prompts/system_prompt_builder.ts
1332
2042
  import { SystemMessage } from "langchain";
@@ -2408,7 +3118,7 @@ var MCPAgent = class {
2408
3118
  * This method formats and displays tool executions in a user-friendly way with syntax highlighting.
2409
3119
  */
2410
3120
  async *prettyStreamEvents(query, maxSteps, manageConnector = true, externalHistory, outputSchema) {
2411
- const { prettyStreamEvents: prettyStream } = await import("./display-YIYC6WJE.js");
3121
+ const { prettyStreamEvents: prettyStream } = await import("./display-A5IEINAP.js");
2412
3122
  const finalResponse = "";
2413
3123
  for await (const _ of prettyStream(
2414
3124
  this.streamEvents(
@@ -2648,7 +3358,7 @@ var MCPAgent = class {
2648
3358
  let structuredLlm = null;
2649
3359
  let schemaDescription = "";
2650
3360
  logger.debug(
2651
- `\u{1F504} Structured output requested, schema: ${JSON.stringify(zodToJsonSchema2(outputSchema), null, 2)}`
3361
+ `\u{1F504} Structured output requested, schema: ${JSON.stringify(toJSONSchema2(outputSchema), null, 2)}`
2652
3362
  );
2653
3363
  if (llm && "withStructuredOutput" in llm && typeof llm.withStructuredOutput === "function") {
2654
3364
  structuredLlm = llm.withStructuredOutput(outputSchema);
@@ -2657,7 +3367,7 @@ var MCPAgent = class {
2657
3367
  } else {
2658
3368
  throw new Error("LLM is required for structured output");
2659
3369
  }
2660
- const jsonSchema = zodToJsonSchema2(outputSchema);
3370
+ const jsonSchema = toJSONSchema2(outputSchema);
2661
3371
  const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2662
3372
  schemaDescription = JSON.stringify(cleanSchema, null, 2);
2663
3373
  logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
@@ -2802,7 +3512,7 @@ ${formatPrompt}`
2802
3512
  */
2803
3513
  _enhanceQueryWithSchema(query, outputSchema) {
2804
3514
  try {
2805
- const jsonSchema = zodToJsonSchema2(outputSchema);
3515
+ const jsonSchema = toJSONSchema2(outputSchema);
2806
3516
  const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
2807
3517
  const schemaDescription = JSON.stringify(cleanSchema, null, 2);
2808
3518
  const enhancedQuery = `