@mastra/mcp 0.4.0-alpha.8 → 0.4.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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +41 -0
- package/dist/_tsup-dts-rollup.d.cts +132 -0
- package/dist/_tsup-dts-rollup.d.ts +132 -0
- package/dist/index.cjs +2154 -5
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2133 -7
- package/package.json +3 -2
- package/src/__fixtures__/server-weather.ts +16 -0
- package/src/__fixtures__/tools.ts +103 -0
- package/src/index.ts +1 -0
- package/src/logger.ts +104 -0
- package/src/server.test.ts +115 -0
- package/src/server.ts +253 -0
package/dist/index.js
CHANGED
|
@@ -5,9 +5,16 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
|
5
5
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
6
6
|
import { StdioClientTransport, getDefaultEnvironment } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
7
|
import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
8
|
-
import { ListResourcesResultSchema, CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
import { ListResourcesResultSchema, CallToolResultSchema, ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
9
|
import { asyncExitHook, gracefulExit } from 'exit-hook';
|
|
10
10
|
import { v5 } from 'uuid';
|
|
11
|
+
import { isVercelTool, isZodType, resolveSerializedZodOutput } from '@mastra/core';
|
|
12
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
13
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
14
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
15
|
+
import * as fs from 'fs';
|
|
16
|
+
import * as os from 'os';
|
|
17
|
+
import * as path from 'path';
|
|
11
18
|
|
|
12
19
|
// src/client.ts
|
|
13
20
|
|
|
@@ -364,8 +371,8 @@ function getErrorMap() {
|
|
|
364
371
|
return overrideErrorMap;
|
|
365
372
|
}
|
|
366
373
|
var makeIssue = (params) => {
|
|
367
|
-
const { data, path, errorMaps, issueData } = params;
|
|
368
|
-
const fullPath = [...
|
|
374
|
+
const { data, path: path2, errorMaps, issueData } = params;
|
|
375
|
+
const fullPath = [...path2, ...issueData.path || []];
|
|
369
376
|
const fullIssue = {
|
|
370
377
|
...issueData,
|
|
371
378
|
path: fullPath
|
|
@@ -487,11 +494,11 @@ var errorUtil;
|
|
|
487
494
|
var _ZodEnum_cache;
|
|
488
495
|
var _ZodNativeEnum_cache;
|
|
489
496
|
var ParseInputLazyPath = class {
|
|
490
|
-
constructor(parent, value,
|
|
497
|
+
constructor(parent, value, path2, key) {
|
|
491
498
|
this._cachedPath = [];
|
|
492
499
|
this.parent = parent;
|
|
493
500
|
this.data = value;
|
|
494
|
-
this._path =
|
|
501
|
+
this._path = path2;
|
|
495
502
|
this._key = key;
|
|
496
503
|
}
|
|
497
504
|
get path() {
|
|
@@ -4105,7 +4112,7 @@ var MastraMCPClient = class extends MastraBase {
|
|
|
4105
4112
|
this.timeout = timeout;
|
|
4106
4113
|
this.logHandler = server.logger;
|
|
4107
4114
|
this.enableServerLogs = server.enableServerLogs ?? true;
|
|
4108
|
-
const { logger, enableServerLogs, ...serverConfig } = server;
|
|
4115
|
+
const { logger: logger3, enableServerLogs, ...serverConfig } = server;
|
|
4109
4116
|
if (`url` in serverConfig) {
|
|
4110
4117
|
this.transport = new SSEClientTransport(serverConfig.url, {
|
|
4111
4118
|
requestInit: serverConfig.requestInit,
|
|
@@ -4352,4 +4359,2123 @@ To fix this you have three different options:
|
|
|
4352
4359
|
}
|
|
4353
4360
|
};
|
|
4354
4361
|
|
|
4355
|
-
|
|
4362
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
|
|
4363
|
+
var parseAnyOf = (schema, refs) => {
|
|
4364
|
+
return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], {
|
|
4365
|
+
...refs,
|
|
4366
|
+
path: [...refs.path, "anyOf", 0]
|
|
4367
|
+
}) : `z.union([${schema.anyOf.map((schema2, i) => parseSchema(schema2, { ...refs, path: [...refs.path, "anyOf", i] })).join(", ")}])` : `z.any()`;
|
|
4368
|
+
};
|
|
4369
|
+
|
|
4370
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseBoolean.js
|
|
4371
|
+
var parseBoolean = (_schema) => {
|
|
4372
|
+
return "z.boolean()";
|
|
4373
|
+
};
|
|
4374
|
+
|
|
4375
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseDefault.js
|
|
4376
|
+
var parseDefault = (_schema) => {
|
|
4377
|
+
return "z.any()";
|
|
4378
|
+
};
|
|
4379
|
+
|
|
4380
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseMultipleType.js
|
|
4381
|
+
var parseMultipleType = (schema, refs) => {
|
|
4382
|
+
return `z.union([${schema.type.map((type) => parseSchema({ ...schema, type }, refs)).join(", ")}])`;
|
|
4383
|
+
};
|
|
4384
|
+
|
|
4385
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNot.js
|
|
4386
|
+
var parseNot = (schema, refs) => {
|
|
4387
|
+
return `z.any().refine((value) => !${parseSchema(schema.not, {
|
|
4388
|
+
...refs,
|
|
4389
|
+
path: [...refs.path, "not"]
|
|
4390
|
+
})}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
|
|
4391
|
+
};
|
|
4392
|
+
|
|
4393
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNull.js
|
|
4394
|
+
var parseNull = (_schema) => {
|
|
4395
|
+
return "z.null()";
|
|
4396
|
+
};
|
|
4397
|
+
|
|
4398
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/half.js
|
|
4399
|
+
var half = (arr) => {
|
|
4400
|
+
return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
|
|
4401
|
+
};
|
|
4402
|
+
|
|
4403
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAllOf.js
|
|
4404
|
+
var originalIndex = Symbol("Original index");
|
|
4405
|
+
var ensureOriginalIndex = (arr) => {
|
|
4406
|
+
let newArr = [];
|
|
4407
|
+
for (let i = 0; i < arr.length; i++) {
|
|
4408
|
+
const item = arr[i];
|
|
4409
|
+
if (typeof item === "boolean") {
|
|
4410
|
+
newArr.push(item ? { [originalIndex]: i } : { [originalIndex]: i, not: {} });
|
|
4411
|
+
} else if (originalIndex in item) {
|
|
4412
|
+
return arr;
|
|
4413
|
+
} else {
|
|
4414
|
+
newArr.push({ ...item, [originalIndex]: i });
|
|
4415
|
+
}
|
|
4416
|
+
}
|
|
4417
|
+
return newArr;
|
|
4418
|
+
};
|
|
4419
|
+
function parseAllOf(schema, refs) {
|
|
4420
|
+
if (schema.allOf.length === 0) {
|
|
4421
|
+
return "z.never()";
|
|
4422
|
+
} else if (schema.allOf.length === 1) {
|
|
4423
|
+
const item = schema.allOf[0];
|
|
4424
|
+
return parseSchema(item, {
|
|
4425
|
+
...refs,
|
|
4426
|
+
path: [...refs.path, "allOf", item[originalIndex]]
|
|
4427
|
+
});
|
|
4428
|
+
} else {
|
|
4429
|
+
const [left, right] = half(ensureOriginalIndex(schema.allOf));
|
|
4430
|
+
return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({
|
|
4431
|
+
allOf: right
|
|
4432
|
+
}, refs)})`;
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/withMessage.js
|
|
4437
|
+
function withMessage(schema, key, get) {
|
|
4438
|
+
const value = schema[key];
|
|
4439
|
+
let r = "";
|
|
4440
|
+
if (value !== void 0) {
|
|
4441
|
+
const got = get({ value, json: JSON.stringify(value) });
|
|
4442
|
+
if (got) {
|
|
4443
|
+
const opener = got[0];
|
|
4444
|
+
const prefix = got.length === 3 ? got[1] : "";
|
|
4445
|
+
const closer = got.length === 3 ? got[2] : got[1];
|
|
4446
|
+
r += opener;
|
|
4447
|
+
if (schema.errorMessage?.[key] !== void 0) {
|
|
4448
|
+
r += prefix + JSON.stringify(schema.errorMessage[key]);
|
|
4449
|
+
}
|
|
4450
|
+
r += closer;
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
return r;
|
|
4454
|
+
}
|
|
4455
|
+
|
|
4456
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseArray.js
|
|
4457
|
+
var parseArray = (schema, refs) => {
|
|
4458
|
+
if (Array.isArray(schema.items)) {
|
|
4459
|
+
return `z.tuple([${schema.items.map((v, i) => parseSchema(v, { ...refs, path: [...refs.path, "items", i] }))}])`;
|
|
4460
|
+
}
|
|
4461
|
+
let r = !schema.items ? "z.array(z.any())" : `z.array(${parseSchema(schema.items, {
|
|
4462
|
+
...refs,
|
|
4463
|
+
path: [...refs.path, "items"]
|
|
4464
|
+
})})`;
|
|
4465
|
+
r += withMessage(schema, "minItems", ({ json }) => [
|
|
4466
|
+
`.min(${json}`,
|
|
4467
|
+
", ",
|
|
4468
|
+
")"
|
|
4469
|
+
]);
|
|
4470
|
+
r += withMessage(schema, "maxItems", ({ json }) => [
|
|
4471
|
+
`.max(${json}`,
|
|
4472
|
+
", ",
|
|
4473
|
+
")"
|
|
4474
|
+
]);
|
|
4475
|
+
return r;
|
|
4476
|
+
};
|
|
4477
|
+
|
|
4478
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseConst.js
|
|
4479
|
+
var parseConst = (schema) => {
|
|
4480
|
+
return `z.literal(${JSON.stringify(schema.const)})`;
|
|
4481
|
+
};
|
|
4482
|
+
|
|
4483
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseEnum.js
|
|
4484
|
+
var parseEnum = (schema) => {
|
|
4485
|
+
if (schema.enum.length === 0) {
|
|
4486
|
+
return "z.never()";
|
|
4487
|
+
} else if (schema.enum.length === 1) {
|
|
4488
|
+
return `z.literal(${JSON.stringify(schema.enum[0])})`;
|
|
4489
|
+
} else if (schema.enum.every((x) => typeof x === "string")) {
|
|
4490
|
+
return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
|
|
4491
|
+
} else {
|
|
4492
|
+
return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
|
|
4493
|
+
}
|
|
4494
|
+
};
|
|
4495
|
+
|
|
4496
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseIfThenElse.js
|
|
4497
|
+
var parseIfThenElse = (schema, refs) => {
|
|
4498
|
+
const $if = parseSchema(schema.if, { ...refs, path: [...refs.path, "if"] });
|
|
4499
|
+
const $then = parseSchema(schema.then, {
|
|
4500
|
+
...refs,
|
|
4501
|
+
path: [...refs.path, "then"]
|
|
4502
|
+
});
|
|
4503
|
+
const $else = parseSchema(schema.else, {
|
|
4504
|
+
...refs,
|
|
4505
|
+
path: [...refs.path, "else"]
|
|
4506
|
+
});
|
|
4507
|
+
return `z.union([${$then}, ${$else}]).superRefine((value,ctx) => {
|
|
4508
|
+
const result = ${$if}.safeParse(value).success
|
|
4509
|
+
? ${$then}.safeParse(value)
|
|
4510
|
+
: ${$else}.safeParse(value);
|
|
4511
|
+
if (!result.success) {
|
|
4512
|
+
result.error.errors.forEach((error) => ctx.addIssue(error))
|
|
4513
|
+
}
|
|
4514
|
+
})`;
|
|
4515
|
+
};
|
|
4516
|
+
|
|
4517
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNumber.js
|
|
4518
|
+
var parseNumber = (schema) => {
|
|
4519
|
+
let r = "z.number()";
|
|
4520
|
+
if (schema.type === "integer") {
|
|
4521
|
+
r += withMessage(schema, "type", () => [".int(", ")"]);
|
|
4522
|
+
} else {
|
|
4523
|
+
r += withMessage(schema, "format", ({ value }) => {
|
|
4524
|
+
if (value === "int64") {
|
|
4525
|
+
return [".int(", ")"];
|
|
4526
|
+
}
|
|
4527
|
+
});
|
|
4528
|
+
}
|
|
4529
|
+
r += withMessage(schema, "multipleOf", ({ value, json }) => {
|
|
4530
|
+
if (value === 1) {
|
|
4531
|
+
if (r.startsWith("z.number().int(")) {
|
|
4532
|
+
return;
|
|
4533
|
+
}
|
|
4534
|
+
return [".int(", ")"];
|
|
4535
|
+
}
|
|
4536
|
+
return [`.multipleOf(${json}`, ", ", ")"];
|
|
4537
|
+
});
|
|
4538
|
+
if (typeof schema.minimum === "number") {
|
|
4539
|
+
if (schema.exclusiveMinimum === true) {
|
|
4540
|
+
r += withMessage(schema, "minimum", ({ json }) => [
|
|
4541
|
+
`.gt(${json}`,
|
|
4542
|
+
", ",
|
|
4543
|
+
")"
|
|
4544
|
+
]);
|
|
4545
|
+
} else {
|
|
4546
|
+
r += withMessage(schema, "minimum", ({ json }) => [
|
|
4547
|
+
`.gte(${json}`,
|
|
4548
|
+
", ",
|
|
4549
|
+
")"
|
|
4550
|
+
]);
|
|
4551
|
+
}
|
|
4552
|
+
} else if (typeof schema.exclusiveMinimum === "number") {
|
|
4553
|
+
r += withMessage(schema, "exclusiveMinimum", ({ json }) => [
|
|
4554
|
+
`.gt(${json}`,
|
|
4555
|
+
", ",
|
|
4556
|
+
")"
|
|
4557
|
+
]);
|
|
4558
|
+
}
|
|
4559
|
+
if (typeof schema.maximum === "number") {
|
|
4560
|
+
if (schema.exclusiveMaximum === true) {
|
|
4561
|
+
r += withMessage(schema, "maximum", ({ json }) => [
|
|
4562
|
+
`.lt(${json}`,
|
|
4563
|
+
", ",
|
|
4564
|
+
")"
|
|
4565
|
+
]);
|
|
4566
|
+
} else {
|
|
4567
|
+
r += withMessage(schema, "maximum", ({ json }) => [
|
|
4568
|
+
`.lte(${json}`,
|
|
4569
|
+
", ",
|
|
4570
|
+
")"
|
|
4571
|
+
]);
|
|
4572
|
+
}
|
|
4573
|
+
} else if (typeof schema.exclusiveMaximum === "number") {
|
|
4574
|
+
r += withMessage(schema, "exclusiveMaximum", ({ json }) => [
|
|
4575
|
+
`.lt(${json}`,
|
|
4576
|
+
", ",
|
|
4577
|
+
")"
|
|
4578
|
+
]);
|
|
4579
|
+
}
|
|
4580
|
+
return r;
|
|
4581
|
+
};
|
|
4582
|
+
|
|
4583
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseOneOf.js
|
|
4584
|
+
var parseOneOf = (schema, refs) => {
|
|
4585
|
+
return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
|
|
4586
|
+
...refs,
|
|
4587
|
+
path: [...refs.path, "oneOf", 0]
|
|
4588
|
+
}) : `z.any().superRefine((x, ctx) => {
|
|
4589
|
+
const schemas = [${schema.oneOf.map((schema2, i) => parseSchema(schema2, {
|
|
4590
|
+
...refs,
|
|
4591
|
+
path: [...refs.path, "oneOf", i]
|
|
4592
|
+
})).join(", ")}];
|
|
4593
|
+
const errors = schemas.reduce<z.ZodError[]>(
|
|
4594
|
+
(errors, schema) =>
|
|
4595
|
+
((result) =>
|
|
4596
|
+
result.error ? [...errors, result.error] : errors)(
|
|
4597
|
+
schema.safeParse(x),
|
|
4598
|
+
),
|
|
4599
|
+
[],
|
|
4600
|
+
);
|
|
4601
|
+
if (schemas.length - errors.length !== 1) {
|
|
4602
|
+
ctx.addIssue({
|
|
4603
|
+
path: ctx.path,
|
|
4604
|
+
code: "invalid_union",
|
|
4605
|
+
unionErrors: errors,
|
|
4606
|
+
message: "Invalid input: Should pass single schema",
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
})` : "z.any()";
|
|
4610
|
+
};
|
|
4611
|
+
|
|
4612
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/jsdocs.js
|
|
4613
|
+
var expandJsdocs = (jsdocs) => {
|
|
4614
|
+
const lines = jsdocs.split("\n");
|
|
4615
|
+
const result = lines.length === 1 ? lines[0] : `
|
|
4616
|
+
${lines.map((x) => `* ${x}`).join("\n")}
|
|
4617
|
+
`;
|
|
4618
|
+
return `/**${result}*/
|
|
4619
|
+
`;
|
|
4620
|
+
};
|
|
4621
|
+
var addJsdocs = (schema, parsed) => {
|
|
4622
|
+
const description = schema.description;
|
|
4623
|
+
if (!description) {
|
|
4624
|
+
return parsed;
|
|
4625
|
+
}
|
|
4626
|
+
return `
|
|
4627
|
+
${expandJsdocs(description)}${parsed}`;
|
|
4628
|
+
};
|
|
4629
|
+
|
|
4630
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseObject.js
|
|
4631
|
+
function parseObject(objectSchema, refs) {
|
|
4632
|
+
let properties = void 0;
|
|
4633
|
+
if (objectSchema.properties) {
|
|
4634
|
+
if (!Object.keys(objectSchema.properties).length) {
|
|
4635
|
+
properties = "z.object({})";
|
|
4636
|
+
} else {
|
|
4637
|
+
properties = "z.object({ ";
|
|
4638
|
+
properties += Object.keys(objectSchema.properties).map((key) => {
|
|
4639
|
+
const propSchema = objectSchema.properties[key];
|
|
4640
|
+
let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
|
|
4641
|
+
...refs,
|
|
4642
|
+
path: [...refs.path, "properties", key]
|
|
4643
|
+
})}`;
|
|
4644
|
+
if (refs.withJsdocs && typeof propSchema === "object") {
|
|
4645
|
+
result = addJsdocs(propSchema, result);
|
|
4646
|
+
}
|
|
4647
|
+
const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
|
|
4648
|
+
const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
|
|
4649
|
+
const optional = !hasDefault && !required;
|
|
4650
|
+
return optional ? `${result}.optional()` : result;
|
|
4651
|
+
}).join(", ");
|
|
4652
|
+
properties += " })";
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
|
|
4656
|
+
...refs,
|
|
4657
|
+
path: [...refs.path, "additionalProperties"]
|
|
4658
|
+
}) : void 0;
|
|
4659
|
+
let patternProperties = void 0;
|
|
4660
|
+
if (objectSchema.patternProperties) {
|
|
4661
|
+
const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
|
|
4662
|
+
return [
|
|
4663
|
+
key,
|
|
4664
|
+
parseSchema(value, {
|
|
4665
|
+
...refs,
|
|
4666
|
+
path: [...refs.path, "patternProperties", key]
|
|
4667
|
+
})
|
|
4668
|
+
];
|
|
4669
|
+
}, {}));
|
|
4670
|
+
patternProperties = "";
|
|
4671
|
+
if (properties) {
|
|
4672
|
+
if (additionalProperties) {
|
|
4673
|
+
patternProperties += `.catchall(z.union([${[
|
|
4674
|
+
...Object.values(parsedPatternProperties),
|
|
4675
|
+
additionalProperties
|
|
4676
|
+
].join(", ")}]))`;
|
|
4677
|
+
} else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
4678
|
+
patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
4679
|
+
} else {
|
|
4680
|
+
patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
|
|
4681
|
+
}
|
|
4682
|
+
} else {
|
|
4683
|
+
if (additionalProperties) {
|
|
4684
|
+
patternProperties += `z.record(z.union([${[
|
|
4685
|
+
...Object.values(parsedPatternProperties),
|
|
4686
|
+
additionalProperties
|
|
4687
|
+
].join(", ")}]))`;
|
|
4688
|
+
} else if (Object.keys(parsedPatternProperties).length > 1) {
|
|
4689
|
+
patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
|
|
4690
|
+
} else {
|
|
4691
|
+
patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
patternProperties += ".superRefine((value, ctx) => {\n";
|
|
4695
|
+
patternProperties += "for (const key in value) {\n";
|
|
4696
|
+
if (additionalProperties) {
|
|
4697
|
+
if (objectSchema.properties) {
|
|
4698
|
+
patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)
|
|
4699
|
+
`;
|
|
4700
|
+
} else {
|
|
4701
|
+
patternProperties += `let evaluated = false
|
|
4702
|
+
`;
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
for (const key in objectSchema.patternProperties) {
|
|
4706
|
+
patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
|
|
4707
|
+
if (additionalProperties) {
|
|
4708
|
+
patternProperties += "evaluated = true\n";
|
|
4709
|
+
}
|
|
4710
|
+
patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
|
|
4711
|
+
patternProperties += "if (!result.success) {\n";
|
|
4712
|
+
patternProperties += `ctx.addIssue({
|
|
4713
|
+
path: [...ctx.path, key],
|
|
4714
|
+
code: 'custom',
|
|
4715
|
+
message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
|
|
4716
|
+
params: {
|
|
4717
|
+
issues: result.error.issues
|
|
4718
|
+
}
|
|
4719
|
+
})
|
|
4720
|
+
`;
|
|
4721
|
+
patternProperties += "}\n";
|
|
4722
|
+
patternProperties += "}\n";
|
|
4723
|
+
}
|
|
4724
|
+
if (additionalProperties) {
|
|
4725
|
+
patternProperties += "if (!evaluated) {\n";
|
|
4726
|
+
patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
|
|
4727
|
+
patternProperties += "if (!result.success) {\n";
|
|
4728
|
+
patternProperties += `ctx.addIssue({
|
|
4729
|
+
path: [...ctx.path, key],
|
|
4730
|
+
code: 'custom',
|
|
4731
|
+
message: \`Invalid input: must match catchall schema\`,
|
|
4732
|
+
params: {
|
|
4733
|
+
issues: result.error.issues
|
|
4734
|
+
}
|
|
4735
|
+
})
|
|
4736
|
+
`;
|
|
4737
|
+
patternProperties += "}\n";
|
|
4738
|
+
patternProperties += "}\n";
|
|
4739
|
+
}
|
|
4740
|
+
patternProperties += "}\n";
|
|
4741
|
+
patternProperties += "})";
|
|
4742
|
+
}
|
|
4743
|
+
let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? `z.record(${additionalProperties})` : "z.record(z.any())";
|
|
4744
|
+
if (its.an.anyOf(objectSchema)) {
|
|
4745
|
+
output += `.and(${parseAnyOf({
|
|
4746
|
+
anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
4747
|
+
}, refs)})`;
|
|
4748
|
+
}
|
|
4749
|
+
if (its.a.oneOf(objectSchema)) {
|
|
4750
|
+
output += `.and(${parseOneOf({
|
|
4751
|
+
oneOf: objectSchema.oneOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
4752
|
+
}, refs)})`;
|
|
4753
|
+
}
|
|
4754
|
+
if (its.an.allOf(objectSchema)) {
|
|
4755
|
+
output += `.and(${parseAllOf({
|
|
4756
|
+
allOf: objectSchema.allOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
|
|
4757
|
+
}, refs)})`;
|
|
4758
|
+
}
|
|
4759
|
+
return output;
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4762
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseString.js
|
|
4763
|
+
var parseString = (schema) => {
|
|
4764
|
+
let r = "z.string()";
|
|
4765
|
+
r += withMessage(schema, "format", ({ value }) => {
|
|
4766
|
+
switch (value) {
|
|
4767
|
+
case "email":
|
|
4768
|
+
return [".email(", ")"];
|
|
4769
|
+
case "ip":
|
|
4770
|
+
return [".ip(", ")"];
|
|
4771
|
+
case "ipv4":
|
|
4772
|
+
return ['.ip({ version: "v4"', ", message: ", " })"];
|
|
4773
|
+
case "ipv6":
|
|
4774
|
+
return ['.ip({ version: "v6"', ", message: ", " })"];
|
|
4775
|
+
case "uri":
|
|
4776
|
+
return [".url(", ")"];
|
|
4777
|
+
case "uuid":
|
|
4778
|
+
return [".uuid(", ")"];
|
|
4779
|
+
case "date-time":
|
|
4780
|
+
return [".datetime({ offset: true", ", message: ", " })"];
|
|
4781
|
+
case "time":
|
|
4782
|
+
return [".time(", ")"];
|
|
4783
|
+
case "date":
|
|
4784
|
+
return [".date(", ")"];
|
|
4785
|
+
case "binary":
|
|
4786
|
+
return [".base64(", ")"];
|
|
4787
|
+
case "duration":
|
|
4788
|
+
return [".duration(", ")"];
|
|
4789
|
+
}
|
|
4790
|
+
});
|
|
4791
|
+
r += withMessage(schema, "pattern", ({ json }) => [
|
|
4792
|
+
`.regex(new RegExp(${json})`,
|
|
4793
|
+
", ",
|
|
4794
|
+
")"
|
|
4795
|
+
]);
|
|
4796
|
+
r += withMessage(schema, "minLength", ({ json }) => [
|
|
4797
|
+
`.min(${json}`,
|
|
4798
|
+
", ",
|
|
4799
|
+
")"
|
|
4800
|
+
]);
|
|
4801
|
+
r += withMessage(schema, "maxLength", ({ json }) => [
|
|
4802
|
+
`.max(${json}`,
|
|
4803
|
+
", ",
|
|
4804
|
+
")"
|
|
4805
|
+
]);
|
|
4806
|
+
r += withMessage(schema, "contentEncoding", ({ value }) => {
|
|
4807
|
+
if (value === "base64") {
|
|
4808
|
+
return [".base64(", ")"];
|
|
4809
|
+
}
|
|
4810
|
+
});
|
|
4811
|
+
const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
|
|
4812
|
+
if (value === "application/json") {
|
|
4813
|
+
return [
|
|
4814
|
+
'.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',
|
|
4815
|
+
", ",
|
|
4816
|
+
")"
|
|
4817
|
+
];
|
|
4818
|
+
}
|
|
4819
|
+
});
|
|
4820
|
+
if (contentMediaType != "") {
|
|
4821
|
+
r += contentMediaType;
|
|
4822
|
+
r += withMessage(schema, "contentSchema", ({ value }) => {
|
|
4823
|
+
if (value && value instanceof Object) {
|
|
4824
|
+
return [
|
|
4825
|
+
`.pipe(${parseSchema(value)}`,
|
|
4826
|
+
", ",
|
|
4827
|
+
")"
|
|
4828
|
+
];
|
|
4829
|
+
}
|
|
4830
|
+
});
|
|
4831
|
+
}
|
|
4832
|
+
return r;
|
|
4833
|
+
};
|
|
4834
|
+
|
|
4835
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/omit.js
|
|
4836
|
+
var omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
|
|
4837
|
+
if (!keys.includes(key)) {
|
|
4838
|
+
acc[key] = obj[key];
|
|
4839
|
+
}
|
|
4840
|
+
return acc;
|
|
4841
|
+
}, {});
|
|
4842
|
+
|
|
4843
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNullable.js
|
|
4844
|
+
var parseNullable = (schema, refs) => {
|
|
4845
|
+
return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
|
|
4846
|
+
};
|
|
4847
|
+
|
|
4848
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseSchema.js
|
|
4849
|
+
var parseSchema = (schema, refs = { seen: /* @__PURE__ */ new Map(), path: [] }, blockMeta) => {
|
|
4850
|
+
if (typeof schema !== "object")
|
|
4851
|
+
return schema ? "z.any()" : "z.never()";
|
|
4852
|
+
if (refs.parserOverride) {
|
|
4853
|
+
const custom2 = refs.parserOverride(schema, refs);
|
|
4854
|
+
if (typeof custom2 === "string") {
|
|
4855
|
+
return custom2;
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
let seen = refs.seen.get(schema);
|
|
4859
|
+
if (seen) {
|
|
4860
|
+
if (seen.r !== void 0) {
|
|
4861
|
+
return seen.r;
|
|
4862
|
+
}
|
|
4863
|
+
if (refs.depth === void 0 || seen.n >= refs.depth) {
|
|
4864
|
+
return "z.any()";
|
|
4865
|
+
}
|
|
4866
|
+
seen.n += 1;
|
|
4867
|
+
} else {
|
|
4868
|
+
seen = { r: void 0, n: 0 };
|
|
4869
|
+
refs.seen.set(schema, seen);
|
|
4870
|
+
}
|
|
4871
|
+
let parsed = selectParser(schema, refs);
|
|
4872
|
+
if (!blockMeta) {
|
|
4873
|
+
if (!refs.withoutDescribes) {
|
|
4874
|
+
parsed = addDescribes(schema, parsed);
|
|
4875
|
+
}
|
|
4876
|
+
if (!refs.withoutDefaults) {
|
|
4877
|
+
parsed = addDefaults(schema, parsed);
|
|
4878
|
+
}
|
|
4879
|
+
parsed = addAnnotations(schema, parsed);
|
|
4880
|
+
}
|
|
4881
|
+
seen.r = parsed;
|
|
4882
|
+
return parsed;
|
|
4883
|
+
};
|
|
4884
|
+
var addDescribes = (schema, parsed) => {
|
|
4885
|
+
if (schema.description) {
|
|
4886
|
+
parsed += `.describe(${JSON.stringify(schema.description)})`;
|
|
4887
|
+
}
|
|
4888
|
+
return parsed;
|
|
4889
|
+
};
|
|
4890
|
+
var addDefaults = (schema, parsed) => {
|
|
4891
|
+
if (schema.default !== void 0) {
|
|
4892
|
+
parsed += `.default(${JSON.stringify(schema.default)})`;
|
|
4893
|
+
}
|
|
4894
|
+
return parsed;
|
|
4895
|
+
};
|
|
4896
|
+
var addAnnotations = (schema, parsed) => {
|
|
4897
|
+
if (schema.readOnly) {
|
|
4898
|
+
parsed += ".readonly()";
|
|
4899
|
+
}
|
|
4900
|
+
return parsed;
|
|
4901
|
+
};
|
|
4902
|
+
var selectParser = (schema, refs) => {
|
|
4903
|
+
if (its.a.nullable(schema)) {
|
|
4904
|
+
return parseNullable(schema, refs);
|
|
4905
|
+
} else if (its.an.object(schema)) {
|
|
4906
|
+
return parseObject(schema, refs);
|
|
4907
|
+
} else if (its.an.array(schema)) {
|
|
4908
|
+
return parseArray(schema, refs);
|
|
4909
|
+
} else if (its.an.anyOf(schema)) {
|
|
4910
|
+
return parseAnyOf(schema, refs);
|
|
4911
|
+
} else if (its.an.allOf(schema)) {
|
|
4912
|
+
return parseAllOf(schema, refs);
|
|
4913
|
+
} else if (its.a.oneOf(schema)) {
|
|
4914
|
+
return parseOneOf(schema, refs);
|
|
4915
|
+
} else if (its.a.not(schema)) {
|
|
4916
|
+
return parseNot(schema, refs);
|
|
4917
|
+
} else if (its.an.enum(schema)) {
|
|
4918
|
+
return parseEnum(schema);
|
|
4919
|
+
} else if (its.a.const(schema)) {
|
|
4920
|
+
return parseConst(schema);
|
|
4921
|
+
} else if (its.a.multipleType(schema)) {
|
|
4922
|
+
return parseMultipleType(schema, refs);
|
|
4923
|
+
} else if (its.a.primitive(schema, "string")) {
|
|
4924
|
+
return parseString(schema);
|
|
4925
|
+
} else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) {
|
|
4926
|
+
return parseNumber(schema);
|
|
4927
|
+
} else if (its.a.primitive(schema, "boolean")) {
|
|
4928
|
+
return parseBoolean();
|
|
4929
|
+
} else if (its.a.primitive(schema, "null")) {
|
|
4930
|
+
return parseNull();
|
|
4931
|
+
} else if (its.a.conditional(schema)) {
|
|
4932
|
+
return parseIfThenElse(schema, refs);
|
|
4933
|
+
} else {
|
|
4934
|
+
return parseDefault();
|
|
4935
|
+
}
|
|
4936
|
+
};
|
|
4937
|
+
var its = {
|
|
4938
|
+
an: {
|
|
4939
|
+
object: (x) => x.type === "object",
|
|
4940
|
+
array: (x) => x.type === "array",
|
|
4941
|
+
anyOf: (x) => x.anyOf !== void 0,
|
|
4942
|
+
allOf: (x) => x.allOf !== void 0,
|
|
4943
|
+
enum: (x) => x.enum !== void 0
|
|
4944
|
+
},
|
|
4945
|
+
a: {
|
|
4946
|
+
nullable: (x) => x.nullable === true,
|
|
4947
|
+
multipleType: (x) => Array.isArray(x.type),
|
|
4948
|
+
not: (x) => x.not !== void 0,
|
|
4949
|
+
const: (x) => x.const !== void 0,
|
|
4950
|
+
primitive: (x, p) => x.type === p,
|
|
4951
|
+
conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
|
|
4952
|
+
oneOf: (x) => x.oneOf !== void 0
|
|
4953
|
+
}
|
|
4954
|
+
};
|
|
4955
|
+
|
|
4956
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/jsonSchemaToZod.js
|
|
4957
|
+
var jsonSchemaToZod = (schema, { module, name, type, noImport, ...rest } = {}) => {
|
|
4958
|
+
if (type && (!name || module !== "esm")) {
|
|
4959
|
+
throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
|
|
4960
|
+
}
|
|
4961
|
+
let result = parseSchema(schema, {
|
|
4962
|
+
module,
|
|
4963
|
+
name,
|
|
4964
|
+
path: [],
|
|
4965
|
+
seen: /* @__PURE__ */ new Map(),
|
|
4966
|
+
...rest
|
|
4967
|
+
});
|
|
4968
|
+
const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
|
|
4969
|
+
if (module === "cjs") {
|
|
4970
|
+
result = `${jsdocs}module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
|
|
4971
|
+
`;
|
|
4972
|
+
if (!noImport) {
|
|
4973
|
+
result = `${jsdocs}const { z } = require("zod")
|
|
4974
|
+
|
|
4975
|
+
${result}`;
|
|
4976
|
+
}
|
|
4977
|
+
} else if (module === "esm") {
|
|
4978
|
+
result = `${jsdocs}export ${name ? `const ${name} =` : `default`} ${result}
|
|
4979
|
+
`;
|
|
4980
|
+
if (!noImport) {
|
|
4981
|
+
result = `import { z } from "zod"
|
|
4982
|
+
|
|
4983
|
+
${result}`;
|
|
4984
|
+
}
|
|
4985
|
+
} else if (name) {
|
|
4986
|
+
result = `${jsdocs}const ${name} = ${result}`;
|
|
4987
|
+
}
|
|
4988
|
+
if (type && name) {
|
|
4989
|
+
let typeName = typeof type === "string" ? type : `${name[0].toUpperCase()}${name.substring(1)}`;
|
|
4990
|
+
result += `export type ${typeName} = z.infer<typeof ${name}>
|
|
4991
|
+
`;
|
|
4992
|
+
}
|
|
4993
|
+
return result;
|
|
4994
|
+
};
|
|
4995
|
+
|
|
4996
|
+
// ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/index.js
|
|
4997
|
+
var esm_default = jsonSchemaToZod;
|
|
4998
|
+
|
|
4999
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
5000
|
+
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
5001
|
+
var defaultOptions = {
|
|
5002
|
+
name: void 0,
|
|
5003
|
+
$refStrategy: "root",
|
|
5004
|
+
basePath: ["#"],
|
|
5005
|
+
effectStrategy: "input",
|
|
5006
|
+
pipeStrategy: "all",
|
|
5007
|
+
dateStrategy: "format:date-time",
|
|
5008
|
+
mapStrategy: "entries",
|
|
5009
|
+
removeAdditionalStrategy: "passthrough",
|
|
5010
|
+
allowedAdditionalProperties: true,
|
|
5011
|
+
rejectedAdditionalProperties: false,
|
|
5012
|
+
definitionPath: "definitions",
|
|
5013
|
+
target: "jsonSchema7",
|
|
5014
|
+
strictUnions: false,
|
|
5015
|
+
definitions: {},
|
|
5016
|
+
errorMessages: false,
|
|
5017
|
+
markdownDescription: false,
|
|
5018
|
+
patternStrategy: "escape",
|
|
5019
|
+
applyRegexFlags: false,
|
|
5020
|
+
emailStrategy: "format:email",
|
|
5021
|
+
base64Strategy: "contentEncoding:base64",
|
|
5022
|
+
nameStrategy: "ref"
|
|
5023
|
+
};
|
|
5024
|
+
var getDefaultOptions = (options) => ({
|
|
5025
|
+
...defaultOptions,
|
|
5026
|
+
...options
|
|
5027
|
+
});
|
|
5028
|
+
|
|
5029
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
5030
|
+
var getRefs = (options) => {
|
|
5031
|
+
const _options = getDefaultOptions(options);
|
|
5032
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
5033
|
+
return {
|
|
5034
|
+
..._options,
|
|
5035
|
+
currentPath,
|
|
5036
|
+
propertyPath: void 0,
|
|
5037
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
5038
|
+
def._def,
|
|
5039
|
+
{
|
|
5040
|
+
def: def._def,
|
|
5041
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
5042
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
5043
|
+
jsonSchema: void 0
|
|
5044
|
+
}
|
|
5045
|
+
]))
|
|
5046
|
+
};
|
|
5047
|
+
};
|
|
5048
|
+
|
|
5049
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
5050
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
5051
|
+
if (!refs?.errorMessages)
|
|
5052
|
+
return;
|
|
5053
|
+
if (errorMessage) {
|
|
5054
|
+
res.errorMessage = {
|
|
5055
|
+
...res.errorMessage,
|
|
5056
|
+
[key]: errorMessage
|
|
5057
|
+
};
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
5061
|
+
res[key] = value;
|
|
5062
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
5063
|
+
}
|
|
5064
|
+
|
|
5065
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
5066
|
+
function parseAnyDef() {
|
|
5067
|
+
return {};
|
|
5068
|
+
}
|
|
5069
|
+
|
|
5070
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
5071
|
+
function parseArrayDef(def, refs) {
|
|
5072
|
+
const res = {
|
|
5073
|
+
type: "array"
|
|
5074
|
+
};
|
|
5075
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
5076
|
+
res.items = parseDef(def.type._def, {
|
|
5077
|
+
...refs,
|
|
5078
|
+
currentPath: [...refs.currentPath, "items"]
|
|
5079
|
+
});
|
|
5080
|
+
}
|
|
5081
|
+
if (def.minLength) {
|
|
5082
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
5083
|
+
}
|
|
5084
|
+
if (def.maxLength) {
|
|
5085
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
5086
|
+
}
|
|
5087
|
+
if (def.exactLength) {
|
|
5088
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
5089
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
5090
|
+
}
|
|
5091
|
+
return res;
|
|
5092
|
+
}
|
|
5093
|
+
|
|
5094
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
5095
|
+
function parseBigintDef(def, refs) {
|
|
5096
|
+
const res = {
|
|
5097
|
+
type: "integer",
|
|
5098
|
+
format: "int64"
|
|
5099
|
+
};
|
|
5100
|
+
if (!def.checks)
|
|
5101
|
+
return res;
|
|
5102
|
+
for (const check of def.checks) {
|
|
5103
|
+
switch (check.kind) {
|
|
5104
|
+
case "min":
|
|
5105
|
+
if (refs.target === "jsonSchema7") {
|
|
5106
|
+
if (check.inclusive) {
|
|
5107
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
5108
|
+
} else {
|
|
5109
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
5110
|
+
}
|
|
5111
|
+
} else {
|
|
5112
|
+
if (!check.inclusive) {
|
|
5113
|
+
res.exclusiveMinimum = true;
|
|
5114
|
+
}
|
|
5115
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
5116
|
+
}
|
|
5117
|
+
break;
|
|
5118
|
+
case "max":
|
|
5119
|
+
if (refs.target === "jsonSchema7") {
|
|
5120
|
+
if (check.inclusive) {
|
|
5121
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
5122
|
+
} else {
|
|
5123
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
5124
|
+
}
|
|
5125
|
+
} else {
|
|
5126
|
+
if (!check.inclusive) {
|
|
5127
|
+
res.exclusiveMaximum = true;
|
|
5128
|
+
}
|
|
5129
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
5130
|
+
}
|
|
5131
|
+
break;
|
|
5132
|
+
case "multipleOf":
|
|
5133
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
5134
|
+
break;
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
return res;
|
|
5138
|
+
}
|
|
5139
|
+
|
|
5140
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
5141
|
+
function parseBooleanDef() {
|
|
5142
|
+
return {
|
|
5143
|
+
type: "boolean"
|
|
5144
|
+
};
|
|
5145
|
+
}
|
|
5146
|
+
|
|
5147
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
5148
|
+
function parseBrandedDef(_def, refs) {
|
|
5149
|
+
return parseDef(_def.type._def, refs);
|
|
5150
|
+
}
|
|
5151
|
+
|
|
5152
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
5153
|
+
var parseCatchDef = (def, refs) => {
|
|
5154
|
+
return parseDef(def.innerType._def, refs);
|
|
5155
|
+
};
|
|
5156
|
+
|
|
5157
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
5158
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
5159
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
5160
|
+
if (Array.isArray(strategy)) {
|
|
5161
|
+
return {
|
|
5162
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
5163
|
+
};
|
|
5164
|
+
}
|
|
5165
|
+
switch (strategy) {
|
|
5166
|
+
case "string":
|
|
5167
|
+
case "format:date-time":
|
|
5168
|
+
return {
|
|
5169
|
+
type: "string",
|
|
5170
|
+
format: "date-time"
|
|
5171
|
+
};
|
|
5172
|
+
case "format:date":
|
|
5173
|
+
return {
|
|
5174
|
+
type: "string",
|
|
5175
|
+
format: "date"
|
|
5176
|
+
};
|
|
5177
|
+
case "integer":
|
|
5178
|
+
return integerDateParser(def, refs);
|
|
5179
|
+
}
|
|
5180
|
+
}
|
|
5181
|
+
var integerDateParser = (def, refs) => {
|
|
5182
|
+
const res = {
|
|
5183
|
+
type: "integer",
|
|
5184
|
+
format: "unix-time"
|
|
5185
|
+
};
|
|
5186
|
+
if (refs.target === "openApi3") {
|
|
5187
|
+
return res;
|
|
5188
|
+
}
|
|
5189
|
+
for (const check of def.checks) {
|
|
5190
|
+
switch (check.kind) {
|
|
5191
|
+
case "min":
|
|
5192
|
+
setResponseValueAndErrors(
|
|
5193
|
+
res,
|
|
5194
|
+
"minimum",
|
|
5195
|
+
check.value,
|
|
5196
|
+
// This is in milliseconds
|
|
5197
|
+
check.message,
|
|
5198
|
+
refs
|
|
5199
|
+
);
|
|
5200
|
+
break;
|
|
5201
|
+
case "max":
|
|
5202
|
+
setResponseValueAndErrors(
|
|
5203
|
+
res,
|
|
5204
|
+
"maximum",
|
|
5205
|
+
check.value,
|
|
5206
|
+
// This is in milliseconds
|
|
5207
|
+
check.message,
|
|
5208
|
+
refs
|
|
5209
|
+
);
|
|
5210
|
+
break;
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
return res;
|
|
5214
|
+
};
|
|
5215
|
+
|
|
5216
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
5217
|
+
function parseDefaultDef(_def, refs) {
|
|
5218
|
+
return {
|
|
5219
|
+
...parseDef(_def.innerType._def, refs),
|
|
5220
|
+
default: _def.defaultValue()
|
|
5221
|
+
};
|
|
5222
|
+
}
|
|
5223
|
+
|
|
5224
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
5225
|
+
function parseEffectsDef(_def, refs) {
|
|
5226
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
5227
|
+
}
|
|
5228
|
+
|
|
5229
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
5230
|
+
function parseEnumDef(def) {
|
|
5231
|
+
return {
|
|
5232
|
+
type: "string",
|
|
5233
|
+
enum: Array.from(def.values)
|
|
5234
|
+
};
|
|
5235
|
+
}
|
|
5236
|
+
|
|
5237
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
5238
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
5239
|
+
if ("type" in type && type.type === "string")
|
|
5240
|
+
return false;
|
|
5241
|
+
return "allOf" in type;
|
|
5242
|
+
};
|
|
5243
|
+
function parseIntersectionDef(def, refs) {
|
|
5244
|
+
const allOf = [
|
|
5245
|
+
parseDef(def.left._def, {
|
|
5246
|
+
...refs,
|
|
5247
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
5248
|
+
}),
|
|
5249
|
+
parseDef(def.right._def, {
|
|
5250
|
+
...refs,
|
|
5251
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
5252
|
+
})
|
|
5253
|
+
].filter((x) => !!x);
|
|
5254
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
5255
|
+
const mergedAllOf = [];
|
|
5256
|
+
allOf.forEach((schema) => {
|
|
5257
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
5258
|
+
mergedAllOf.push(...schema.allOf);
|
|
5259
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
5260
|
+
unevaluatedProperties = void 0;
|
|
5261
|
+
}
|
|
5262
|
+
} else {
|
|
5263
|
+
let nestedSchema = schema;
|
|
5264
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
5265
|
+
const { additionalProperties, ...rest } = schema;
|
|
5266
|
+
nestedSchema = rest;
|
|
5267
|
+
} else {
|
|
5268
|
+
unevaluatedProperties = void 0;
|
|
5269
|
+
}
|
|
5270
|
+
mergedAllOf.push(nestedSchema);
|
|
5271
|
+
}
|
|
5272
|
+
});
|
|
5273
|
+
return mergedAllOf.length ? {
|
|
5274
|
+
allOf: mergedAllOf,
|
|
5275
|
+
...unevaluatedProperties
|
|
5276
|
+
} : void 0;
|
|
5277
|
+
}
|
|
5278
|
+
|
|
5279
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
5280
|
+
function parseLiteralDef(def, refs) {
|
|
5281
|
+
const parsedType = typeof def.value;
|
|
5282
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
5283
|
+
return {
|
|
5284
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
5285
|
+
};
|
|
5286
|
+
}
|
|
5287
|
+
if (refs.target === "openApi3") {
|
|
5288
|
+
return {
|
|
5289
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
5290
|
+
enum: [def.value]
|
|
5291
|
+
};
|
|
5292
|
+
}
|
|
5293
|
+
return {
|
|
5294
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
5295
|
+
const: def.value
|
|
5296
|
+
};
|
|
5297
|
+
}
|
|
5298
|
+
|
|
5299
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
5300
|
+
var emojiRegex2 = void 0;
|
|
5301
|
+
var zodPatterns = {
|
|
5302
|
+
/**
|
|
5303
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
5304
|
+
*/
|
|
5305
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
5306
|
+
cuid2: /^[0-9a-z]+$/,
|
|
5307
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
5308
|
+
/**
|
|
5309
|
+
* `a-z` was added to replicate /i flag
|
|
5310
|
+
*/
|
|
5311
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
5312
|
+
/**
|
|
5313
|
+
* Constructed a valid Unicode RegExp
|
|
5314
|
+
*
|
|
5315
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
5316
|
+
* in all envs (e.g. React Native).
|
|
5317
|
+
*
|
|
5318
|
+
* See:
|
|
5319
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
5320
|
+
* Fix in Zod:
|
|
5321
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
5322
|
+
*/
|
|
5323
|
+
emoji: () => {
|
|
5324
|
+
if (emojiRegex2 === void 0) {
|
|
5325
|
+
emojiRegex2 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
5326
|
+
}
|
|
5327
|
+
return emojiRegex2;
|
|
5328
|
+
},
|
|
5329
|
+
/**
|
|
5330
|
+
* Unused
|
|
5331
|
+
*/
|
|
5332
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
5333
|
+
/**
|
|
5334
|
+
* Unused
|
|
5335
|
+
*/
|
|
5336
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
5337
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
5338
|
+
/**
|
|
5339
|
+
* Unused
|
|
5340
|
+
*/
|
|
5341
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
5342
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
5343
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
5344
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
5345
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
5346
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
5347
|
+
};
|
|
5348
|
+
function parseStringDef(def, refs) {
|
|
5349
|
+
const res = {
|
|
5350
|
+
type: "string"
|
|
5351
|
+
};
|
|
5352
|
+
if (def.checks) {
|
|
5353
|
+
for (const check of def.checks) {
|
|
5354
|
+
switch (check.kind) {
|
|
5355
|
+
case "min":
|
|
5356
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
5357
|
+
break;
|
|
5358
|
+
case "max":
|
|
5359
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
5360
|
+
break;
|
|
5361
|
+
case "email":
|
|
5362
|
+
switch (refs.emailStrategy) {
|
|
5363
|
+
case "format:email":
|
|
5364
|
+
addFormat(res, "email", check.message, refs);
|
|
5365
|
+
break;
|
|
5366
|
+
case "format:idn-email":
|
|
5367
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
5368
|
+
break;
|
|
5369
|
+
case "pattern:zod":
|
|
5370
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
5371
|
+
break;
|
|
5372
|
+
}
|
|
5373
|
+
break;
|
|
5374
|
+
case "url":
|
|
5375
|
+
addFormat(res, "uri", check.message, refs);
|
|
5376
|
+
break;
|
|
5377
|
+
case "uuid":
|
|
5378
|
+
addFormat(res, "uuid", check.message, refs);
|
|
5379
|
+
break;
|
|
5380
|
+
case "regex":
|
|
5381
|
+
addPattern(res, check.regex, check.message, refs);
|
|
5382
|
+
break;
|
|
5383
|
+
case "cuid":
|
|
5384
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
5385
|
+
break;
|
|
5386
|
+
case "cuid2":
|
|
5387
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
5388
|
+
break;
|
|
5389
|
+
case "startsWith":
|
|
5390
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
5391
|
+
break;
|
|
5392
|
+
case "endsWith":
|
|
5393
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
5394
|
+
break;
|
|
5395
|
+
case "datetime":
|
|
5396
|
+
addFormat(res, "date-time", check.message, refs);
|
|
5397
|
+
break;
|
|
5398
|
+
case "date":
|
|
5399
|
+
addFormat(res, "date", check.message, refs);
|
|
5400
|
+
break;
|
|
5401
|
+
case "time":
|
|
5402
|
+
addFormat(res, "time", check.message, refs);
|
|
5403
|
+
break;
|
|
5404
|
+
case "duration":
|
|
5405
|
+
addFormat(res, "duration", check.message, refs);
|
|
5406
|
+
break;
|
|
5407
|
+
case "length":
|
|
5408
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
5409
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
5410
|
+
break;
|
|
5411
|
+
case "includes": {
|
|
5412
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
5413
|
+
break;
|
|
5414
|
+
}
|
|
5415
|
+
case "ip": {
|
|
5416
|
+
if (check.version !== "v6") {
|
|
5417
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
5418
|
+
}
|
|
5419
|
+
if (check.version !== "v4") {
|
|
5420
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
5421
|
+
}
|
|
5422
|
+
break;
|
|
5423
|
+
}
|
|
5424
|
+
case "base64url":
|
|
5425
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
5426
|
+
break;
|
|
5427
|
+
case "jwt":
|
|
5428
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
5429
|
+
break;
|
|
5430
|
+
case "cidr": {
|
|
5431
|
+
if (check.version !== "v6") {
|
|
5432
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
5433
|
+
}
|
|
5434
|
+
if (check.version !== "v4") {
|
|
5435
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
5436
|
+
}
|
|
5437
|
+
break;
|
|
5438
|
+
}
|
|
5439
|
+
case "emoji":
|
|
5440
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
5441
|
+
break;
|
|
5442
|
+
case "ulid": {
|
|
5443
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
5444
|
+
break;
|
|
5445
|
+
}
|
|
5446
|
+
case "base64": {
|
|
5447
|
+
switch (refs.base64Strategy) {
|
|
5448
|
+
case "format:binary": {
|
|
5449
|
+
addFormat(res, "binary", check.message, refs);
|
|
5450
|
+
break;
|
|
5451
|
+
}
|
|
5452
|
+
case "contentEncoding:base64": {
|
|
5453
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
5454
|
+
break;
|
|
5455
|
+
}
|
|
5456
|
+
case "pattern:zod": {
|
|
5457
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
5458
|
+
break;
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
break;
|
|
5462
|
+
}
|
|
5463
|
+
case "nanoid": {
|
|
5464
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5467
|
+
}
|
|
5468
|
+
}
|
|
5469
|
+
return res;
|
|
5470
|
+
}
|
|
5471
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
5472
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
5473
|
+
}
|
|
5474
|
+
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
5475
|
+
function escapeNonAlphaNumeric(source) {
|
|
5476
|
+
let result = "";
|
|
5477
|
+
for (let i = 0; i < source.length; i++) {
|
|
5478
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
5479
|
+
result += "\\";
|
|
5480
|
+
}
|
|
5481
|
+
result += source[i];
|
|
5482
|
+
}
|
|
5483
|
+
return result;
|
|
5484
|
+
}
|
|
5485
|
+
function addFormat(schema, value, message, refs) {
|
|
5486
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
5487
|
+
if (!schema.anyOf) {
|
|
5488
|
+
schema.anyOf = [];
|
|
5489
|
+
}
|
|
5490
|
+
if (schema.format) {
|
|
5491
|
+
schema.anyOf.push({
|
|
5492
|
+
format: schema.format,
|
|
5493
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
5494
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
5495
|
+
}
|
|
5496
|
+
});
|
|
5497
|
+
delete schema.format;
|
|
5498
|
+
if (schema.errorMessage) {
|
|
5499
|
+
delete schema.errorMessage.format;
|
|
5500
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
5501
|
+
delete schema.errorMessage;
|
|
5502
|
+
}
|
|
5503
|
+
}
|
|
5504
|
+
}
|
|
5505
|
+
schema.anyOf.push({
|
|
5506
|
+
format: value,
|
|
5507
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
5508
|
+
});
|
|
5509
|
+
} else {
|
|
5510
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
5511
|
+
}
|
|
5512
|
+
}
|
|
5513
|
+
function addPattern(schema, regex, message, refs) {
|
|
5514
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
5515
|
+
if (!schema.allOf) {
|
|
5516
|
+
schema.allOf = [];
|
|
5517
|
+
}
|
|
5518
|
+
if (schema.pattern) {
|
|
5519
|
+
schema.allOf.push({
|
|
5520
|
+
pattern: schema.pattern,
|
|
5521
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
5522
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
5523
|
+
}
|
|
5524
|
+
});
|
|
5525
|
+
delete schema.pattern;
|
|
5526
|
+
if (schema.errorMessage) {
|
|
5527
|
+
delete schema.errorMessage.pattern;
|
|
5528
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
5529
|
+
delete schema.errorMessage;
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5533
|
+
schema.allOf.push({
|
|
5534
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
5535
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
5536
|
+
});
|
|
5537
|
+
} else {
|
|
5538
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
5539
|
+
}
|
|
5540
|
+
}
|
|
5541
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
5542
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
5543
|
+
return regex.source;
|
|
5544
|
+
}
|
|
5545
|
+
const flags = {
|
|
5546
|
+
i: regex.flags.includes("i"),
|
|
5547
|
+
m: regex.flags.includes("m"),
|
|
5548
|
+
s: regex.flags.includes("s")
|
|
5549
|
+
// `.` matches newlines
|
|
5550
|
+
};
|
|
5551
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
5552
|
+
let pattern = "";
|
|
5553
|
+
let isEscaped = false;
|
|
5554
|
+
let inCharGroup = false;
|
|
5555
|
+
let inCharRange = false;
|
|
5556
|
+
for (let i = 0; i < source.length; i++) {
|
|
5557
|
+
if (isEscaped) {
|
|
5558
|
+
pattern += source[i];
|
|
5559
|
+
isEscaped = false;
|
|
5560
|
+
continue;
|
|
5561
|
+
}
|
|
5562
|
+
if (flags.i) {
|
|
5563
|
+
if (inCharGroup) {
|
|
5564
|
+
if (source[i].match(/[a-z]/)) {
|
|
5565
|
+
if (inCharRange) {
|
|
5566
|
+
pattern += source[i];
|
|
5567
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
5568
|
+
inCharRange = false;
|
|
5569
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
5570
|
+
pattern += source[i];
|
|
5571
|
+
inCharRange = true;
|
|
5572
|
+
} else {
|
|
5573
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
5574
|
+
}
|
|
5575
|
+
continue;
|
|
5576
|
+
}
|
|
5577
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
5578
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
5579
|
+
continue;
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
if (flags.m) {
|
|
5583
|
+
if (source[i] === "^") {
|
|
5584
|
+
pattern += `(^|(?<=[\r
|
|
5585
|
+
]))`;
|
|
5586
|
+
continue;
|
|
5587
|
+
} else if (source[i] === "$") {
|
|
5588
|
+
pattern += `($|(?=[\r
|
|
5589
|
+
]))`;
|
|
5590
|
+
continue;
|
|
5591
|
+
}
|
|
5592
|
+
}
|
|
5593
|
+
if (flags.s && source[i] === ".") {
|
|
5594
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
5595
|
+
` : `[${source[i]}\r
|
|
5596
|
+
]`;
|
|
5597
|
+
continue;
|
|
5598
|
+
}
|
|
5599
|
+
pattern += source[i];
|
|
5600
|
+
if (source[i] === "\\") {
|
|
5601
|
+
isEscaped = true;
|
|
5602
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
5603
|
+
inCharGroup = false;
|
|
5604
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
5605
|
+
inCharGroup = true;
|
|
5606
|
+
}
|
|
5607
|
+
}
|
|
5608
|
+
return pattern;
|
|
5609
|
+
}
|
|
5610
|
+
|
|
5611
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
5612
|
+
function parseRecordDef(def, refs) {
|
|
5613
|
+
if (refs.target === "openAi") {
|
|
5614
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
5615
|
+
}
|
|
5616
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
5617
|
+
return {
|
|
5618
|
+
type: "object",
|
|
5619
|
+
required: def.keyType._def.values,
|
|
5620
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
5621
|
+
...acc,
|
|
5622
|
+
[key]: parseDef(def.valueType._def, {
|
|
5623
|
+
...refs,
|
|
5624
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
5625
|
+
}) ?? {}
|
|
5626
|
+
}), {}),
|
|
5627
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
5628
|
+
};
|
|
5629
|
+
}
|
|
5630
|
+
const schema = {
|
|
5631
|
+
type: "object",
|
|
5632
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
5633
|
+
...refs,
|
|
5634
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
5635
|
+
}) ?? refs.allowedAdditionalProperties
|
|
5636
|
+
};
|
|
5637
|
+
if (refs.target === "openApi3") {
|
|
5638
|
+
return schema;
|
|
5639
|
+
}
|
|
5640
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
|
|
5641
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
5642
|
+
return {
|
|
5643
|
+
...schema,
|
|
5644
|
+
propertyNames: keyType
|
|
5645
|
+
};
|
|
5646
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
5647
|
+
return {
|
|
5648
|
+
...schema,
|
|
5649
|
+
propertyNames: {
|
|
5650
|
+
enum: def.keyType._def.values
|
|
5651
|
+
}
|
|
5652
|
+
};
|
|
5653
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
5654
|
+
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
5655
|
+
return {
|
|
5656
|
+
...schema,
|
|
5657
|
+
propertyNames: keyType
|
|
5658
|
+
};
|
|
5659
|
+
}
|
|
5660
|
+
return schema;
|
|
5661
|
+
}
|
|
5662
|
+
|
|
5663
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
5664
|
+
function parseMapDef(def, refs) {
|
|
5665
|
+
if (refs.mapStrategy === "record") {
|
|
5666
|
+
return parseRecordDef(def, refs);
|
|
5667
|
+
}
|
|
5668
|
+
const keys = parseDef(def.keyType._def, {
|
|
5669
|
+
...refs,
|
|
5670
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
5671
|
+
}) || {};
|
|
5672
|
+
const values = parseDef(def.valueType._def, {
|
|
5673
|
+
...refs,
|
|
5674
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
5675
|
+
}) || {};
|
|
5676
|
+
return {
|
|
5677
|
+
type: "array",
|
|
5678
|
+
maxItems: 125,
|
|
5679
|
+
items: {
|
|
5680
|
+
type: "array",
|
|
5681
|
+
items: [keys, values],
|
|
5682
|
+
minItems: 2,
|
|
5683
|
+
maxItems: 2
|
|
5684
|
+
}
|
|
5685
|
+
};
|
|
5686
|
+
}
|
|
5687
|
+
|
|
5688
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
5689
|
+
function parseNativeEnumDef(def) {
|
|
5690
|
+
const object = def.values;
|
|
5691
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
5692
|
+
return typeof object[object[key]] !== "number";
|
|
5693
|
+
});
|
|
5694
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
5695
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
5696
|
+
return {
|
|
5697
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
5698
|
+
enum: actualValues
|
|
5699
|
+
};
|
|
5700
|
+
}
|
|
5701
|
+
|
|
5702
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
5703
|
+
function parseNeverDef() {
|
|
5704
|
+
return {
|
|
5705
|
+
not: {}
|
|
5706
|
+
};
|
|
5707
|
+
}
|
|
5708
|
+
|
|
5709
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
5710
|
+
function parseNullDef(refs) {
|
|
5711
|
+
return refs.target === "openApi3" ? {
|
|
5712
|
+
enum: ["null"],
|
|
5713
|
+
nullable: true
|
|
5714
|
+
} : {
|
|
5715
|
+
type: "null"
|
|
5716
|
+
};
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5719
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
5720
|
+
var primitiveMappings = {
|
|
5721
|
+
ZodString: "string",
|
|
5722
|
+
ZodNumber: "number",
|
|
5723
|
+
ZodBigInt: "integer",
|
|
5724
|
+
ZodBoolean: "boolean",
|
|
5725
|
+
ZodNull: "null"
|
|
5726
|
+
};
|
|
5727
|
+
function parseUnionDef(def, refs) {
|
|
5728
|
+
if (refs.target === "openApi3")
|
|
5729
|
+
return asAnyOf(def, refs);
|
|
5730
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
5731
|
+
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
5732
|
+
const types = options.reduce((types2, x) => {
|
|
5733
|
+
const type = primitiveMappings[x._def.typeName];
|
|
5734
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
5735
|
+
}, []);
|
|
5736
|
+
return {
|
|
5737
|
+
type: types.length > 1 ? types : types[0]
|
|
5738
|
+
};
|
|
5739
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
5740
|
+
const types = options.reduce((acc, x) => {
|
|
5741
|
+
const type = typeof x._def.value;
|
|
5742
|
+
switch (type) {
|
|
5743
|
+
case "string":
|
|
5744
|
+
case "number":
|
|
5745
|
+
case "boolean":
|
|
5746
|
+
return [...acc, type];
|
|
5747
|
+
case "bigint":
|
|
5748
|
+
return [...acc, "integer"];
|
|
5749
|
+
case "object":
|
|
5750
|
+
if (x._def.value === null)
|
|
5751
|
+
return [...acc, "null"];
|
|
5752
|
+
case "symbol":
|
|
5753
|
+
case "undefined":
|
|
5754
|
+
case "function":
|
|
5755
|
+
default:
|
|
5756
|
+
return acc;
|
|
5757
|
+
}
|
|
5758
|
+
}, []);
|
|
5759
|
+
if (types.length === options.length) {
|
|
5760
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
5761
|
+
return {
|
|
5762
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
5763
|
+
enum: options.reduce((acc, x) => {
|
|
5764
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
5765
|
+
}, [])
|
|
5766
|
+
};
|
|
5767
|
+
}
|
|
5768
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
5769
|
+
return {
|
|
5770
|
+
type: "string",
|
|
5771
|
+
enum: options.reduce((acc, x) => [
|
|
5772
|
+
...acc,
|
|
5773
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
5774
|
+
], [])
|
|
5775
|
+
};
|
|
5776
|
+
}
|
|
5777
|
+
return asAnyOf(def, refs);
|
|
5778
|
+
}
|
|
5779
|
+
var asAnyOf = (def, refs) => {
|
|
5780
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
5781
|
+
...refs,
|
|
5782
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
5783
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
5784
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
5785
|
+
};
|
|
5786
|
+
|
|
5787
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
5788
|
+
function parseNullableDef(def, refs) {
|
|
5789
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
5790
|
+
if (refs.target === "openApi3") {
|
|
5791
|
+
return {
|
|
5792
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
5793
|
+
nullable: true
|
|
5794
|
+
};
|
|
5795
|
+
}
|
|
5796
|
+
return {
|
|
5797
|
+
type: [
|
|
5798
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
5799
|
+
"null"
|
|
5800
|
+
]
|
|
5801
|
+
};
|
|
5802
|
+
}
|
|
5803
|
+
if (refs.target === "openApi3") {
|
|
5804
|
+
const base2 = parseDef(def.innerType._def, {
|
|
5805
|
+
...refs,
|
|
5806
|
+
currentPath: [...refs.currentPath]
|
|
5807
|
+
});
|
|
5808
|
+
if (base2 && "$ref" in base2)
|
|
5809
|
+
return { allOf: [base2], nullable: true };
|
|
5810
|
+
return base2 && { ...base2, nullable: true };
|
|
5811
|
+
}
|
|
5812
|
+
const base = parseDef(def.innerType._def, {
|
|
5813
|
+
...refs,
|
|
5814
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
5815
|
+
});
|
|
5816
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
5817
|
+
}
|
|
5818
|
+
|
|
5819
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
5820
|
+
function parseNumberDef(def, refs) {
|
|
5821
|
+
const res = {
|
|
5822
|
+
type: "number"
|
|
5823
|
+
};
|
|
5824
|
+
if (!def.checks)
|
|
5825
|
+
return res;
|
|
5826
|
+
for (const check of def.checks) {
|
|
5827
|
+
switch (check.kind) {
|
|
5828
|
+
case "int":
|
|
5829
|
+
res.type = "integer";
|
|
5830
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
5831
|
+
break;
|
|
5832
|
+
case "min":
|
|
5833
|
+
if (refs.target === "jsonSchema7") {
|
|
5834
|
+
if (check.inclusive) {
|
|
5835
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
5836
|
+
} else {
|
|
5837
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
5838
|
+
}
|
|
5839
|
+
} else {
|
|
5840
|
+
if (!check.inclusive) {
|
|
5841
|
+
res.exclusiveMinimum = true;
|
|
5842
|
+
}
|
|
5843
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
5844
|
+
}
|
|
5845
|
+
break;
|
|
5846
|
+
case "max":
|
|
5847
|
+
if (refs.target === "jsonSchema7") {
|
|
5848
|
+
if (check.inclusive) {
|
|
5849
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
5850
|
+
} else {
|
|
5851
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
5852
|
+
}
|
|
5853
|
+
} else {
|
|
5854
|
+
if (!check.inclusive) {
|
|
5855
|
+
res.exclusiveMaximum = true;
|
|
5856
|
+
}
|
|
5857
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
5858
|
+
}
|
|
5859
|
+
break;
|
|
5860
|
+
case "multipleOf":
|
|
5861
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
5862
|
+
break;
|
|
5863
|
+
}
|
|
5864
|
+
}
|
|
5865
|
+
return res;
|
|
5866
|
+
}
|
|
5867
|
+
|
|
5868
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
5869
|
+
function parseObjectDef(def, refs) {
|
|
5870
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
5871
|
+
const result = {
|
|
5872
|
+
type: "object",
|
|
5873
|
+
properties: {}
|
|
5874
|
+
};
|
|
5875
|
+
const required = [];
|
|
5876
|
+
const shape = def.shape();
|
|
5877
|
+
for (const propName in shape) {
|
|
5878
|
+
let propDef = shape[propName];
|
|
5879
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
5880
|
+
continue;
|
|
5881
|
+
}
|
|
5882
|
+
let propOptional = safeIsOptional(propDef);
|
|
5883
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
5884
|
+
if (propDef instanceof ZodOptional) {
|
|
5885
|
+
propDef = propDef._def.innerType;
|
|
5886
|
+
}
|
|
5887
|
+
if (!propDef.isNullable()) {
|
|
5888
|
+
propDef = propDef.nullable();
|
|
5889
|
+
}
|
|
5890
|
+
propOptional = false;
|
|
5891
|
+
}
|
|
5892
|
+
const parsedDef = parseDef(propDef._def, {
|
|
5893
|
+
...refs,
|
|
5894
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
5895
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
5896
|
+
});
|
|
5897
|
+
if (parsedDef === void 0) {
|
|
5898
|
+
continue;
|
|
5899
|
+
}
|
|
5900
|
+
result.properties[propName] = parsedDef;
|
|
5901
|
+
if (!propOptional) {
|
|
5902
|
+
required.push(propName);
|
|
5903
|
+
}
|
|
5904
|
+
}
|
|
5905
|
+
if (required.length) {
|
|
5906
|
+
result.required = required;
|
|
5907
|
+
}
|
|
5908
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
5909
|
+
if (additionalProperties !== void 0) {
|
|
5910
|
+
result.additionalProperties = additionalProperties;
|
|
5911
|
+
}
|
|
5912
|
+
return result;
|
|
5913
|
+
}
|
|
5914
|
+
function decideAdditionalProperties(def, refs) {
|
|
5915
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
5916
|
+
return parseDef(def.catchall._def, {
|
|
5917
|
+
...refs,
|
|
5918
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
switch (def.unknownKeys) {
|
|
5922
|
+
case "passthrough":
|
|
5923
|
+
return refs.allowedAdditionalProperties;
|
|
5924
|
+
case "strict":
|
|
5925
|
+
return refs.rejectedAdditionalProperties;
|
|
5926
|
+
case "strip":
|
|
5927
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5930
|
+
function safeIsOptional(schema) {
|
|
5931
|
+
try {
|
|
5932
|
+
return schema.isOptional();
|
|
5933
|
+
} catch {
|
|
5934
|
+
return true;
|
|
5935
|
+
}
|
|
5936
|
+
}
|
|
5937
|
+
|
|
5938
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
5939
|
+
var parseOptionalDef = (def, refs) => {
|
|
5940
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
5941
|
+
return parseDef(def.innerType._def, refs);
|
|
5942
|
+
}
|
|
5943
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
5944
|
+
...refs,
|
|
5945
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
5946
|
+
});
|
|
5947
|
+
return innerSchema ? {
|
|
5948
|
+
anyOf: [
|
|
5949
|
+
{
|
|
5950
|
+
not: {}
|
|
5951
|
+
},
|
|
5952
|
+
innerSchema
|
|
5953
|
+
]
|
|
5954
|
+
} : {};
|
|
5955
|
+
};
|
|
5956
|
+
|
|
5957
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
5958
|
+
var parsePipelineDef = (def, refs) => {
|
|
5959
|
+
if (refs.pipeStrategy === "input") {
|
|
5960
|
+
return parseDef(def.in._def, refs);
|
|
5961
|
+
} else if (refs.pipeStrategy === "output") {
|
|
5962
|
+
return parseDef(def.out._def, refs);
|
|
5963
|
+
}
|
|
5964
|
+
const a = parseDef(def.in._def, {
|
|
5965
|
+
...refs,
|
|
5966
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
5967
|
+
});
|
|
5968
|
+
const b = parseDef(def.out._def, {
|
|
5969
|
+
...refs,
|
|
5970
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
5971
|
+
});
|
|
5972
|
+
return {
|
|
5973
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
5974
|
+
};
|
|
5975
|
+
};
|
|
5976
|
+
|
|
5977
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
5978
|
+
function parsePromiseDef(def, refs) {
|
|
5979
|
+
return parseDef(def.type._def, refs);
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
5983
|
+
function parseSetDef(def, refs) {
|
|
5984
|
+
const items = parseDef(def.valueType._def, {
|
|
5985
|
+
...refs,
|
|
5986
|
+
currentPath: [...refs.currentPath, "items"]
|
|
5987
|
+
});
|
|
5988
|
+
const schema = {
|
|
5989
|
+
type: "array",
|
|
5990
|
+
uniqueItems: true,
|
|
5991
|
+
items
|
|
5992
|
+
};
|
|
5993
|
+
if (def.minSize) {
|
|
5994
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
5995
|
+
}
|
|
5996
|
+
if (def.maxSize) {
|
|
5997
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
5998
|
+
}
|
|
5999
|
+
return schema;
|
|
6000
|
+
}
|
|
6001
|
+
|
|
6002
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
6003
|
+
function parseTupleDef(def, refs) {
|
|
6004
|
+
if (def.rest) {
|
|
6005
|
+
return {
|
|
6006
|
+
type: "array",
|
|
6007
|
+
minItems: def.items.length,
|
|
6008
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
6009
|
+
...refs,
|
|
6010
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
6011
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
6012
|
+
additionalItems: parseDef(def.rest._def, {
|
|
6013
|
+
...refs,
|
|
6014
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
6015
|
+
})
|
|
6016
|
+
};
|
|
6017
|
+
} else {
|
|
6018
|
+
return {
|
|
6019
|
+
type: "array",
|
|
6020
|
+
minItems: def.items.length,
|
|
6021
|
+
maxItems: def.items.length,
|
|
6022
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
6023
|
+
...refs,
|
|
6024
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
6025
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
6026
|
+
};
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
|
|
6030
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
6031
|
+
function parseUndefinedDef() {
|
|
6032
|
+
return {
|
|
6033
|
+
not: {}
|
|
6034
|
+
};
|
|
6035
|
+
}
|
|
6036
|
+
|
|
6037
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
6038
|
+
function parseUnknownDef() {
|
|
6039
|
+
return {};
|
|
6040
|
+
}
|
|
6041
|
+
|
|
6042
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
6043
|
+
var parseReadonlyDef = (def, refs) => {
|
|
6044
|
+
return parseDef(def.innerType._def, refs);
|
|
6045
|
+
};
|
|
6046
|
+
|
|
6047
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
6048
|
+
var selectParser2 = (def, typeName, refs) => {
|
|
6049
|
+
switch (typeName) {
|
|
6050
|
+
case ZodFirstPartyTypeKind.ZodString:
|
|
6051
|
+
return parseStringDef(def, refs);
|
|
6052
|
+
case ZodFirstPartyTypeKind.ZodNumber:
|
|
6053
|
+
return parseNumberDef(def, refs);
|
|
6054
|
+
case ZodFirstPartyTypeKind.ZodObject:
|
|
6055
|
+
return parseObjectDef(def, refs);
|
|
6056
|
+
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
6057
|
+
return parseBigintDef(def, refs);
|
|
6058
|
+
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
6059
|
+
return parseBooleanDef();
|
|
6060
|
+
case ZodFirstPartyTypeKind.ZodDate:
|
|
6061
|
+
return parseDateDef(def, refs);
|
|
6062
|
+
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
6063
|
+
return parseUndefinedDef();
|
|
6064
|
+
case ZodFirstPartyTypeKind.ZodNull:
|
|
6065
|
+
return parseNullDef(refs);
|
|
6066
|
+
case ZodFirstPartyTypeKind.ZodArray:
|
|
6067
|
+
return parseArrayDef(def, refs);
|
|
6068
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
6069
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
6070
|
+
return parseUnionDef(def, refs);
|
|
6071
|
+
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
6072
|
+
return parseIntersectionDef(def, refs);
|
|
6073
|
+
case ZodFirstPartyTypeKind.ZodTuple:
|
|
6074
|
+
return parseTupleDef(def, refs);
|
|
6075
|
+
case ZodFirstPartyTypeKind.ZodRecord:
|
|
6076
|
+
return parseRecordDef(def, refs);
|
|
6077
|
+
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
6078
|
+
return parseLiteralDef(def, refs);
|
|
6079
|
+
case ZodFirstPartyTypeKind.ZodEnum:
|
|
6080
|
+
return parseEnumDef(def);
|
|
6081
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
6082
|
+
return parseNativeEnumDef(def);
|
|
6083
|
+
case ZodFirstPartyTypeKind.ZodNullable:
|
|
6084
|
+
return parseNullableDef(def, refs);
|
|
6085
|
+
case ZodFirstPartyTypeKind.ZodOptional:
|
|
6086
|
+
return parseOptionalDef(def, refs);
|
|
6087
|
+
case ZodFirstPartyTypeKind.ZodMap:
|
|
6088
|
+
return parseMapDef(def, refs);
|
|
6089
|
+
case ZodFirstPartyTypeKind.ZodSet:
|
|
6090
|
+
return parseSetDef(def, refs);
|
|
6091
|
+
case ZodFirstPartyTypeKind.ZodLazy:
|
|
6092
|
+
return () => def.getter()._def;
|
|
6093
|
+
case ZodFirstPartyTypeKind.ZodPromise:
|
|
6094
|
+
return parsePromiseDef(def, refs);
|
|
6095
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
6096
|
+
case ZodFirstPartyTypeKind.ZodNever:
|
|
6097
|
+
return parseNeverDef();
|
|
6098
|
+
case ZodFirstPartyTypeKind.ZodEffects:
|
|
6099
|
+
return parseEffectsDef(def, refs);
|
|
6100
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
|
6101
|
+
return parseAnyDef();
|
|
6102
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
6103
|
+
return parseUnknownDef();
|
|
6104
|
+
case ZodFirstPartyTypeKind.ZodDefault:
|
|
6105
|
+
return parseDefaultDef(def, refs);
|
|
6106
|
+
case ZodFirstPartyTypeKind.ZodBranded:
|
|
6107
|
+
return parseBrandedDef(def, refs);
|
|
6108
|
+
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
6109
|
+
return parseReadonlyDef(def, refs);
|
|
6110
|
+
case ZodFirstPartyTypeKind.ZodCatch:
|
|
6111
|
+
return parseCatchDef(def, refs);
|
|
6112
|
+
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
6113
|
+
return parsePipelineDef(def, refs);
|
|
6114
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
6115
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
6116
|
+
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
6117
|
+
return void 0;
|
|
6118
|
+
default:
|
|
6119
|
+
return /* @__PURE__ */ ((_) => void 0)();
|
|
6120
|
+
}
|
|
6121
|
+
};
|
|
6122
|
+
|
|
6123
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
6124
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
6125
|
+
const seenItem = refs.seen.get(def);
|
|
6126
|
+
if (refs.override) {
|
|
6127
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
6128
|
+
if (overrideResult !== ignoreOverride) {
|
|
6129
|
+
return overrideResult;
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
if (seenItem && !forceResolution) {
|
|
6133
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
6134
|
+
if (seenSchema !== void 0) {
|
|
6135
|
+
return seenSchema;
|
|
6136
|
+
}
|
|
6137
|
+
}
|
|
6138
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
6139
|
+
refs.seen.set(def, newItem);
|
|
6140
|
+
const jsonSchemaOrGetter = selectParser2(def, def.typeName, refs);
|
|
6141
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
6142
|
+
if (jsonSchema) {
|
|
6143
|
+
addMeta(def, refs, jsonSchema);
|
|
6144
|
+
}
|
|
6145
|
+
if (refs.postProcess) {
|
|
6146
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
6147
|
+
newItem.jsonSchema = jsonSchema;
|
|
6148
|
+
return postProcessResult;
|
|
6149
|
+
}
|
|
6150
|
+
newItem.jsonSchema = jsonSchema;
|
|
6151
|
+
return jsonSchema;
|
|
6152
|
+
}
|
|
6153
|
+
var get$ref = (item, refs) => {
|
|
6154
|
+
switch (refs.$refStrategy) {
|
|
6155
|
+
case "root":
|
|
6156
|
+
return { $ref: item.path.join("/") };
|
|
6157
|
+
case "relative":
|
|
6158
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
6159
|
+
case "none":
|
|
6160
|
+
case "seen": {
|
|
6161
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
6162
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
6163
|
+
return {};
|
|
6164
|
+
}
|
|
6165
|
+
return refs.$refStrategy === "seen" ? {} : void 0;
|
|
6166
|
+
}
|
|
6167
|
+
}
|
|
6168
|
+
};
|
|
6169
|
+
var getRelativePath = (pathA, pathB) => {
|
|
6170
|
+
let i = 0;
|
|
6171
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
6172
|
+
if (pathA[i] !== pathB[i])
|
|
6173
|
+
break;
|
|
6174
|
+
}
|
|
6175
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
6176
|
+
};
|
|
6177
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
6178
|
+
if (def.description) {
|
|
6179
|
+
jsonSchema.description = def.description;
|
|
6180
|
+
if (refs.markdownDescription) {
|
|
6181
|
+
jsonSchema.markdownDescription = def.description;
|
|
6182
|
+
}
|
|
6183
|
+
}
|
|
6184
|
+
return jsonSchema;
|
|
6185
|
+
};
|
|
6186
|
+
|
|
6187
|
+
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
6188
|
+
var zodToJsonSchema = (schema, options) => {
|
|
6189
|
+
const refs = getRefs(options);
|
|
6190
|
+
const definitions = void 0;
|
|
6191
|
+
const name = options?.name;
|
|
6192
|
+
const main = parseDef(schema._def, refs , false) ?? {};
|
|
6193
|
+
const combined = name === void 0 ? definitions ? {
|
|
6194
|
+
...main,
|
|
6195
|
+
[refs.definitionPath]: definitions
|
|
6196
|
+
} : main : {
|
|
6197
|
+
$ref: [
|
|
6198
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
6199
|
+
refs.definitionPath,
|
|
6200
|
+
name
|
|
6201
|
+
].join("/"),
|
|
6202
|
+
[refs.definitionPath]: {
|
|
6203
|
+
...definitions,
|
|
6204
|
+
[name]: main
|
|
6205
|
+
}
|
|
6206
|
+
};
|
|
6207
|
+
if (refs.target === "jsonSchema7") {
|
|
6208
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
6209
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
6210
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
6211
|
+
}
|
|
6212
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
6213
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
6214
|
+
}
|
|
6215
|
+
return combined;
|
|
6216
|
+
};
|
|
6217
|
+
var writeErrorLog = (message, data) => {
|
|
6218
|
+
const now = /* @__PURE__ */ new Date();
|
|
6219
|
+
const timestamp = now.toISOString();
|
|
6220
|
+
const hourTimestamp = timestamp.slice(0, 13);
|
|
6221
|
+
const logMessage = {
|
|
6222
|
+
timestamp,
|
|
6223
|
+
message,
|
|
6224
|
+
...data ? typeof data === "object" ? data : { data } : {}
|
|
6225
|
+
};
|
|
6226
|
+
try {
|
|
6227
|
+
const cacheDir = path.join(os.homedir(), ".cache", "mastra", "mcp-docs-server-logs");
|
|
6228
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
6229
|
+
const logFile = path.join(cacheDir, `${hourTimestamp}.log`);
|
|
6230
|
+
fs.appendFileSync(logFile, JSON.stringify(logMessage) + "\n", "utf8");
|
|
6231
|
+
} catch (err) {
|
|
6232
|
+
console.error("Failed to write to log file:", err);
|
|
6233
|
+
}
|
|
6234
|
+
};
|
|
6235
|
+
function createLogger(server) {
|
|
6236
|
+
const sendLog = async (level, message, data) => {
|
|
6237
|
+
return;
|
|
6238
|
+
};
|
|
6239
|
+
return {
|
|
6240
|
+
info: async (message, data) => {
|
|
6241
|
+
console.error(message, data ? data : "");
|
|
6242
|
+
await sendLog();
|
|
6243
|
+
},
|
|
6244
|
+
warning: async (message, data) => {
|
|
6245
|
+
console.error(message, data ? data : "");
|
|
6246
|
+
await sendLog();
|
|
6247
|
+
},
|
|
6248
|
+
error: async (message, error) => {
|
|
6249
|
+
const errorData = error instanceof Error ? {
|
|
6250
|
+
message: error.message,
|
|
6251
|
+
stack: error.stack,
|
|
6252
|
+
name: error.name
|
|
6253
|
+
} : error;
|
|
6254
|
+
writeErrorLog(message, errorData);
|
|
6255
|
+
console.error(message, errorData ? errorData : "");
|
|
6256
|
+
await sendLog();
|
|
6257
|
+
},
|
|
6258
|
+
debug: async (message, data) => {
|
|
6259
|
+
if (process.env.DEBUG || process.env.NODE_ENV === "development") {
|
|
6260
|
+
console.error(message, data ? data : "");
|
|
6261
|
+
await sendLog();
|
|
6262
|
+
}
|
|
6263
|
+
}
|
|
6264
|
+
};
|
|
6265
|
+
}
|
|
6266
|
+
|
|
6267
|
+
// src/server.ts
|
|
6268
|
+
var logger2 = createLogger();
|
|
6269
|
+
var MCPServer = class {
|
|
6270
|
+
server;
|
|
6271
|
+
convertedTools;
|
|
6272
|
+
stdioTransport;
|
|
6273
|
+
sseTransport;
|
|
6274
|
+
/**
|
|
6275
|
+
* Get the current stdio transport.
|
|
6276
|
+
*/
|
|
6277
|
+
getStdioTransport() {
|
|
6278
|
+
return this.stdioTransport;
|
|
6279
|
+
}
|
|
6280
|
+
/**
|
|
6281
|
+
* Get the current SSE transport.
|
|
6282
|
+
*/
|
|
6283
|
+
getSseTransport() {
|
|
6284
|
+
return this.sseTransport;
|
|
6285
|
+
}
|
|
6286
|
+
/**
|
|
6287
|
+
* Get a read-only view of the registered tools (for testing/introspection).
|
|
6288
|
+
*/
|
|
6289
|
+
tools() {
|
|
6290
|
+
return this.convertedTools;
|
|
6291
|
+
}
|
|
6292
|
+
/**
|
|
6293
|
+
* Construct a new MCPServer instance.
|
|
6294
|
+
* @param opts.name - Server name
|
|
6295
|
+
* @param opts.version - Server version
|
|
6296
|
+
* @param opts.tools - Tool definitions to register
|
|
6297
|
+
*/
|
|
6298
|
+
constructor({ name, version, tools }) {
|
|
6299
|
+
this.server = new Server({ name, version }, { capabilities: { tools: {}, logging: { enabled: true } } });
|
|
6300
|
+
this.convertedTools = this.convertTools(tools);
|
|
6301
|
+
void logger2.info(
|
|
6302
|
+
`Initialized MCPServer '${name}' v${version} with tools: ${Object.keys(this.convertedTools).join(", ")}`
|
|
6303
|
+
);
|
|
6304
|
+
this.registerListToolsHandler();
|
|
6305
|
+
this.registerCallToolHandler();
|
|
6306
|
+
}
|
|
6307
|
+
/**
|
|
6308
|
+
* Convert and validate all provided tools, logging registration status.
|
|
6309
|
+
* @param tools Tool definitions
|
|
6310
|
+
* @returns Converted tools registry
|
|
6311
|
+
*/
|
|
6312
|
+
convertTools(tools) {
|
|
6313
|
+
const convertedTools = {};
|
|
6314
|
+
for (const toolName of Object.keys(tools)) {
|
|
6315
|
+
let inputSchema;
|
|
6316
|
+
let zodSchema;
|
|
6317
|
+
const toolInstance = tools[toolName];
|
|
6318
|
+
if (!toolInstance) {
|
|
6319
|
+
void logger2.warning(`Tool instance for '${toolName}' is undefined. Skipping.`);
|
|
6320
|
+
continue;
|
|
6321
|
+
}
|
|
6322
|
+
if (typeof toolInstance.execute !== "function") {
|
|
6323
|
+
void logger2.warning(`Tool '${toolName}' does not have a valid execute function. Skipping.`);
|
|
6324
|
+
continue;
|
|
6325
|
+
}
|
|
6326
|
+
if (isVercelTool(toolInstance)) {
|
|
6327
|
+
if (isZodType(toolInstance.parameters)) {
|
|
6328
|
+
zodSchema = toolInstance.parameters;
|
|
6329
|
+
inputSchema = zodToJsonSchema(zodSchema);
|
|
6330
|
+
} else if (typeof toolInstance.parameters === "object") {
|
|
6331
|
+
zodSchema = resolveSerializedZodOutput(esm_default(toolInstance.parameters));
|
|
6332
|
+
inputSchema = toolInstance.parameters;
|
|
6333
|
+
} else {
|
|
6334
|
+
zodSchema = z.object({});
|
|
6335
|
+
inputSchema = zodToJsonSchema(zodSchema);
|
|
6336
|
+
}
|
|
6337
|
+
} else {
|
|
6338
|
+
zodSchema = toolInstance?.inputSchema ?? z.object({});
|
|
6339
|
+
inputSchema = zodToJsonSchema(zodSchema);
|
|
6340
|
+
}
|
|
6341
|
+
const execute = async (args, execOptions) => {
|
|
6342
|
+
if (isVercelTool(toolInstance)) {
|
|
6343
|
+
return await toolInstance.execute?.(args, execOptions) ?? void 0;
|
|
6344
|
+
}
|
|
6345
|
+
return await toolInstance.execute?.({ context: args }, execOptions) ?? void 0;
|
|
6346
|
+
};
|
|
6347
|
+
convertedTools[toolName] = {
|
|
6348
|
+
name: toolName,
|
|
6349
|
+
description: toolInstance?.description,
|
|
6350
|
+
inputSchema,
|
|
6351
|
+
zodSchema,
|
|
6352
|
+
execute
|
|
6353
|
+
};
|
|
6354
|
+
void logger2.info(`Registered tool: '${toolName}' [${toolInstance?.description || "No description"}]`);
|
|
6355
|
+
}
|
|
6356
|
+
void logger2.info(`Total tools registered: ${Object.keys(convertedTools).length}`);
|
|
6357
|
+
return convertedTools;
|
|
6358
|
+
}
|
|
6359
|
+
/**
|
|
6360
|
+
* Register the ListTools handler for listing all available tools.
|
|
6361
|
+
*/
|
|
6362
|
+
registerListToolsHandler() {
|
|
6363
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
6364
|
+
await logger2.debug("Handling ListTools request");
|
|
6365
|
+
return {
|
|
6366
|
+
tools: Object.values(this.convertedTools).map((tool) => ({
|
|
6367
|
+
name: tool.name,
|
|
6368
|
+
description: tool.description,
|
|
6369
|
+
inputSchema: tool.inputSchema
|
|
6370
|
+
}))
|
|
6371
|
+
};
|
|
6372
|
+
});
|
|
6373
|
+
}
|
|
6374
|
+
/**
|
|
6375
|
+
* Register the CallTool handler for executing a tool by name.
|
|
6376
|
+
*/
|
|
6377
|
+
registerCallToolHandler() {
|
|
6378
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
6379
|
+
const startTime = Date.now();
|
|
6380
|
+
try {
|
|
6381
|
+
const tool = this.convertedTools[request.params.name];
|
|
6382
|
+
if (!tool) {
|
|
6383
|
+
await logger2.warning(`CallTool: Unknown tool '${request.params.name}' requested.`);
|
|
6384
|
+
return {
|
|
6385
|
+
content: [{ type: "text", text: `Unknown tool: ${request.params.name}` }],
|
|
6386
|
+
isError: true
|
|
6387
|
+
};
|
|
6388
|
+
}
|
|
6389
|
+
await logger2.debug(`CallTool: Invoking '${request.params.name}' with arguments:`, request.params.arguments);
|
|
6390
|
+
const args = tool.zodSchema.parse(request.params.arguments ?? {});
|
|
6391
|
+
const result = await tool.execute(args, request.params);
|
|
6392
|
+
const duration = Date.now() - startTime;
|
|
6393
|
+
await logger2.info(`Tool '${request.params.name}' executed successfully in ${duration}ms.`);
|
|
6394
|
+
return {
|
|
6395
|
+
content: [
|
|
6396
|
+
{
|
|
6397
|
+
type: "text",
|
|
6398
|
+
text: JSON.stringify(result)
|
|
6399
|
+
}
|
|
6400
|
+
],
|
|
6401
|
+
isError: false
|
|
6402
|
+
};
|
|
6403
|
+
} catch (error) {
|
|
6404
|
+
const duration = Date.now() - startTime;
|
|
6405
|
+
if (error instanceof z.ZodError) {
|
|
6406
|
+
await logger2.warning("Invalid tool arguments", {
|
|
6407
|
+
tool: request.params.name,
|
|
6408
|
+
errors: error.errors,
|
|
6409
|
+
duration: `${duration}ms`
|
|
6410
|
+
});
|
|
6411
|
+
return {
|
|
6412
|
+
content: [
|
|
6413
|
+
{
|
|
6414
|
+
type: "text",
|
|
6415
|
+
text: `Invalid arguments: ${error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ")}`
|
|
6416
|
+
}
|
|
6417
|
+
],
|
|
6418
|
+
isError: true
|
|
6419
|
+
};
|
|
6420
|
+
}
|
|
6421
|
+
await logger2.error(`Tool execution failed: ${request.params.name}`, error);
|
|
6422
|
+
return {
|
|
6423
|
+
content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
6424
|
+
isError: true
|
|
6425
|
+
};
|
|
6426
|
+
}
|
|
6427
|
+
});
|
|
6428
|
+
}
|
|
6429
|
+
/**
|
|
6430
|
+
* Start the MCP server using stdio transport (for Windsurf integration).
|
|
6431
|
+
*/
|
|
6432
|
+
async startStdio() {
|
|
6433
|
+
this.stdioTransport = new StdioServerTransport();
|
|
6434
|
+
await this.server.connect(this.stdioTransport);
|
|
6435
|
+
await logger2.info("Started MCP Server (stdio)");
|
|
6436
|
+
}
|
|
6437
|
+
/**
|
|
6438
|
+
* Handles MCP-over-SSE protocol for user-provided HTTP servers.
|
|
6439
|
+
* Call this from your HTTP server for both the SSE and message endpoints.
|
|
6440
|
+
*
|
|
6441
|
+
* @param url Parsed URL of the incoming request
|
|
6442
|
+
* @param ssePath Path for establishing the SSE connection (e.g. '/sse')
|
|
6443
|
+
* @param messagePath Path for POSTing client messages (e.g. '/message')
|
|
6444
|
+
* @param req Incoming HTTP request
|
|
6445
|
+
* @param res HTTP response (must support .write/.end)
|
|
6446
|
+
*/
|
|
6447
|
+
async startSSE({
|
|
6448
|
+
url,
|
|
6449
|
+
ssePath,
|
|
6450
|
+
messagePath,
|
|
6451
|
+
req,
|
|
6452
|
+
res
|
|
6453
|
+
}) {
|
|
6454
|
+
if (url.pathname === ssePath) {
|
|
6455
|
+
await logger2.debug("Received SSE connection");
|
|
6456
|
+
this.sseTransport = new SSEServerTransport(messagePath, res);
|
|
6457
|
+
await this.server.connect(this.sseTransport);
|
|
6458
|
+
this.server.onclose = async () => {
|
|
6459
|
+
await this.server.close();
|
|
6460
|
+
this.sseTransport = void 0;
|
|
6461
|
+
};
|
|
6462
|
+
res.on("close", () => {
|
|
6463
|
+
this.sseTransport = void 0;
|
|
6464
|
+
});
|
|
6465
|
+
} else if (url.pathname === messagePath) {
|
|
6466
|
+
await logger2.debug("Received message");
|
|
6467
|
+
if (!this.sseTransport) {
|
|
6468
|
+
res.writeHead(503);
|
|
6469
|
+
res.end("SSE connection not established");
|
|
6470
|
+
return;
|
|
6471
|
+
}
|
|
6472
|
+
await this.sseTransport.handlePostMessage(req, res);
|
|
6473
|
+
} else {
|
|
6474
|
+
await logger2.debug("Unknown path:", url.pathname);
|
|
6475
|
+
res.writeHead(404);
|
|
6476
|
+
res.end();
|
|
6477
|
+
}
|
|
6478
|
+
}
|
|
6479
|
+
};
|
|
6480
|
+
|
|
6481
|
+
export { MCPConfiguration, MCPServer, MastraMCPClient };
|