fixparser-plugin-mcp 9.1.7-3e178996 → 9.1.7-525accda
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/build/cjs/MCPLocal.js +499 -1568
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +511 -1577
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +4 -5
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +4 -5
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +5 -4
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -3,1267 +3,11 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import {
|
|
5
5
|
CallToolRequestSchema,
|
|
6
|
+
GetPromptRequestSchema,
|
|
7
|
+
ListPromptsRequestSchema,
|
|
8
|
+
ListResourcesRequestSchema,
|
|
6
9
|
ListToolsRequestSchema
|
|
7
10
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
|
|
10
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
11
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
12
|
-
var defaultOptions = {
|
|
13
|
-
name: void 0,
|
|
14
|
-
$refStrategy: "root",
|
|
15
|
-
basePath: ["#"],
|
|
16
|
-
effectStrategy: "input",
|
|
17
|
-
pipeStrategy: "all",
|
|
18
|
-
dateStrategy: "format:date-time",
|
|
19
|
-
mapStrategy: "entries",
|
|
20
|
-
removeAdditionalStrategy: "passthrough",
|
|
21
|
-
allowedAdditionalProperties: true,
|
|
22
|
-
rejectedAdditionalProperties: false,
|
|
23
|
-
definitionPath: "definitions",
|
|
24
|
-
target: "jsonSchema7",
|
|
25
|
-
strictUnions: false,
|
|
26
|
-
definitions: {},
|
|
27
|
-
errorMessages: false,
|
|
28
|
-
markdownDescription: false,
|
|
29
|
-
patternStrategy: "escape",
|
|
30
|
-
applyRegexFlags: false,
|
|
31
|
-
emailStrategy: "format:email",
|
|
32
|
-
base64Strategy: "contentEncoding:base64",
|
|
33
|
-
nameStrategy: "ref"
|
|
34
|
-
};
|
|
35
|
-
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
36
|
-
...defaultOptions,
|
|
37
|
-
name: options
|
|
38
|
-
} : {
|
|
39
|
-
...defaultOptions,
|
|
40
|
-
...options
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
44
|
-
var getRefs = (options) => {
|
|
45
|
-
const _options = getDefaultOptions(options);
|
|
46
|
-
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
47
|
-
return {
|
|
48
|
-
..._options,
|
|
49
|
-
currentPath,
|
|
50
|
-
propertyPath: void 0,
|
|
51
|
-
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
52
|
-
def._def,
|
|
53
|
-
{
|
|
54
|
-
def: def._def,
|
|
55
|
-
path: [..._options.basePath, _options.definitionPath, name],
|
|
56
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
57
|
-
jsonSchema: void 0
|
|
58
|
-
}
|
|
59
|
-
]))
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
64
|
-
function addErrorMessage(res, key, errorMessage, refs) {
|
|
65
|
-
if (!refs?.errorMessages)
|
|
66
|
-
return;
|
|
67
|
-
if (errorMessage) {
|
|
68
|
-
res.errorMessage = {
|
|
69
|
-
...res.errorMessage,
|
|
70
|
-
[key]: errorMessage
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
75
|
-
res[key] = value;
|
|
76
|
-
addErrorMessage(res, key, errorMessage, refs);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
80
|
-
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
81
|
-
|
|
82
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
83
|
-
function parseAnyDef() {
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
88
|
-
import { ZodFirstPartyTypeKind } from "zod";
|
|
89
|
-
function parseArrayDef(def, refs) {
|
|
90
|
-
const res = {
|
|
91
|
-
type: "array"
|
|
92
|
-
};
|
|
93
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
94
|
-
res.items = parseDef(def.type._def, {
|
|
95
|
-
...refs,
|
|
96
|
-
currentPath: [...refs.currentPath, "items"]
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (def.minLength) {
|
|
100
|
-
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
101
|
-
}
|
|
102
|
-
if (def.maxLength) {
|
|
103
|
-
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
104
|
-
}
|
|
105
|
-
if (def.exactLength) {
|
|
106
|
-
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
107
|
-
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
108
|
-
}
|
|
109
|
-
return res;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
113
|
-
function parseBigintDef(def, refs) {
|
|
114
|
-
const res = {
|
|
115
|
-
type: "integer",
|
|
116
|
-
format: "int64"
|
|
117
|
-
};
|
|
118
|
-
if (!def.checks)
|
|
119
|
-
return res;
|
|
120
|
-
for (const check of def.checks) {
|
|
121
|
-
switch (check.kind) {
|
|
122
|
-
case "min":
|
|
123
|
-
if (refs.target === "jsonSchema7") {
|
|
124
|
-
if (check.inclusive) {
|
|
125
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
126
|
-
} else {
|
|
127
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
if (!check.inclusive) {
|
|
131
|
-
res.exclusiveMinimum = true;
|
|
132
|
-
}
|
|
133
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
134
|
-
}
|
|
135
|
-
break;
|
|
136
|
-
case "max":
|
|
137
|
-
if (refs.target === "jsonSchema7") {
|
|
138
|
-
if (check.inclusive) {
|
|
139
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
140
|
-
} else {
|
|
141
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
if (!check.inclusive) {
|
|
145
|
-
res.exclusiveMaximum = true;
|
|
146
|
-
}
|
|
147
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
case "multipleOf":
|
|
151
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return res;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
159
|
-
function parseBooleanDef() {
|
|
160
|
-
return {
|
|
161
|
-
type: "boolean"
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
166
|
-
function parseBrandedDef(_def, refs) {
|
|
167
|
-
return parseDef(_def.type._def, refs);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
171
|
-
var parseCatchDef = (def, refs) => {
|
|
172
|
-
return parseDef(def.innerType._def, refs);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
176
|
-
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
177
|
-
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
178
|
-
if (Array.isArray(strategy)) {
|
|
179
|
-
return {
|
|
180
|
-
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
switch (strategy) {
|
|
184
|
-
case "string":
|
|
185
|
-
case "format:date-time":
|
|
186
|
-
return {
|
|
187
|
-
type: "string",
|
|
188
|
-
format: "date-time"
|
|
189
|
-
};
|
|
190
|
-
case "format:date":
|
|
191
|
-
return {
|
|
192
|
-
type: "string",
|
|
193
|
-
format: "date"
|
|
194
|
-
};
|
|
195
|
-
case "integer":
|
|
196
|
-
return integerDateParser(def, refs);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
var integerDateParser = (def, refs) => {
|
|
200
|
-
const res = {
|
|
201
|
-
type: "integer",
|
|
202
|
-
format: "unix-time"
|
|
203
|
-
};
|
|
204
|
-
if (refs.target === "openApi3") {
|
|
205
|
-
return res;
|
|
206
|
-
}
|
|
207
|
-
for (const check of def.checks) {
|
|
208
|
-
switch (check.kind) {
|
|
209
|
-
case "min":
|
|
210
|
-
setResponseValueAndErrors(
|
|
211
|
-
res,
|
|
212
|
-
"minimum",
|
|
213
|
-
check.value,
|
|
214
|
-
// This is in milliseconds
|
|
215
|
-
check.message,
|
|
216
|
-
refs
|
|
217
|
-
);
|
|
218
|
-
break;
|
|
219
|
-
case "max":
|
|
220
|
-
setResponseValueAndErrors(
|
|
221
|
-
res,
|
|
222
|
-
"maximum",
|
|
223
|
-
check.value,
|
|
224
|
-
// This is in milliseconds
|
|
225
|
-
check.message,
|
|
226
|
-
refs
|
|
227
|
-
);
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return res;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
235
|
-
function parseDefaultDef(_def, refs) {
|
|
236
|
-
return {
|
|
237
|
-
...parseDef(_def.innerType._def, refs),
|
|
238
|
-
default: _def.defaultValue()
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
243
|
-
function parseEffectsDef(_def, refs) {
|
|
244
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
248
|
-
function parseEnumDef(def) {
|
|
249
|
-
return {
|
|
250
|
-
type: "string",
|
|
251
|
-
enum: Array.from(def.values)
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
256
|
-
var isJsonSchema7AllOfType = (type) => {
|
|
257
|
-
if ("type" in type && type.type === "string")
|
|
258
|
-
return false;
|
|
259
|
-
return "allOf" in type;
|
|
260
|
-
};
|
|
261
|
-
function parseIntersectionDef(def, refs) {
|
|
262
|
-
const allOf = [
|
|
263
|
-
parseDef(def.left._def, {
|
|
264
|
-
...refs,
|
|
265
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
266
|
-
}),
|
|
267
|
-
parseDef(def.right._def, {
|
|
268
|
-
...refs,
|
|
269
|
-
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
270
|
-
})
|
|
271
|
-
].filter((x) => !!x);
|
|
272
|
-
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
273
|
-
const mergedAllOf = [];
|
|
274
|
-
allOf.forEach((schema) => {
|
|
275
|
-
if (isJsonSchema7AllOfType(schema)) {
|
|
276
|
-
mergedAllOf.push(...schema.allOf);
|
|
277
|
-
if (schema.unevaluatedProperties === void 0) {
|
|
278
|
-
unevaluatedProperties = void 0;
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
let nestedSchema = schema;
|
|
282
|
-
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
283
|
-
const { additionalProperties, ...rest } = schema;
|
|
284
|
-
nestedSchema = rest;
|
|
285
|
-
} else {
|
|
286
|
-
unevaluatedProperties = void 0;
|
|
287
|
-
}
|
|
288
|
-
mergedAllOf.push(nestedSchema);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return mergedAllOf.length ? {
|
|
292
|
-
allOf: mergedAllOf,
|
|
293
|
-
...unevaluatedProperties
|
|
294
|
-
} : void 0;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
298
|
-
function parseLiteralDef(def, refs) {
|
|
299
|
-
const parsedType = typeof def.value;
|
|
300
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
301
|
-
return {
|
|
302
|
-
type: Array.isArray(def.value) ? "array" : "object"
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
if (refs.target === "openApi3") {
|
|
306
|
-
return {
|
|
307
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
308
|
-
enum: [def.value]
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
313
|
-
const: def.value
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
318
|
-
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
319
|
-
|
|
320
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
321
|
-
var emojiRegex = void 0;
|
|
322
|
-
var zodPatterns = {
|
|
323
|
-
/**
|
|
324
|
-
* `c` was changed to `[cC]` to replicate /i flag
|
|
325
|
-
*/
|
|
326
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
327
|
-
cuid2: /^[0-9a-z]+$/,
|
|
328
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
329
|
-
/**
|
|
330
|
-
* `a-z` was added to replicate /i flag
|
|
331
|
-
*/
|
|
332
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
333
|
-
/**
|
|
334
|
-
* Constructed a valid Unicode RegExp
|
|
335
|
-
*
|
|
336
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
337
|
-
* in all envs (e.g. React Native).
|
|
338
|
-
*
|
|
339
|
-
* See:
|
|
340
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
341
|
-
* Fix in Zod:
|
|
342
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
343
|
-
*/
|
|
344
|
-
emoji: () => {
|
|
345
|
-
if (emojiRegex === void 0) {
|
|
346
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
347
|
-
}
|
|
348
|
-
return emojiRegex;
|
|
349
|
-
},
|
|
350
|
-
/**
|
|
351
|
-
* Unused
|
|
352
|
-
*/
|
|
353
|
-
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}$/,
|
|
354
|
-
/**
|
|
355
|
-
* Unused
|
|
356
|
-
*/
|
|
357
|
-
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])$/,
|
|
358
|
-
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])$/,
|
|
359
|
-
/**
|
|
360
|
-
* Unused
|
|
361
|
-
*/
|
|
362
|
-
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})))$/,
|
|
363
|
-
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])$/,
|
|
364
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
365
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
366
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
367
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
368
|
-
};
|
|
369
|
-
function parseStringDef(def, refs) {
|
|
370
|
-
const res = {
|
|
371
|
-
type: "string"
|
|
372
|
-
};
|
|
373
|
-
if (def.checks) {
|
|
374
|
-
for (const check of def.checks) {
|
|
375
|
-
switch (check.kind) {
|
|
376
|
-
case "min":
|
|
377
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
378
|
-
break;
|
|
379
|
-
case "max":
|
|
380
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
381
|
-
break;
|
|
382
|
-
case "email":
|
|
383
|
-
switch (refs.emailStrategy) {
|
|
384
|
-
case "format:email":
|
|
385
|
-
addFormat(res, "email", check.message, refs);
|
|
386
|
-
break;
|
|
387
|
-
case "format:idn-email":
|
|
388
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
389
|
-
break;
|
|
390
|
-
case "pattern:zod":
|
|
391
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
392
|
-
break;
|
|
393
|
-
}
|
|
394
|
-
break;
|
|
395
|
-
case "url":
|
|
396
|
-
addFormat(res, "uri", check.message, refs);
|
|
397
|
-
break;
|
|
398
|
-
case "uuid":
|
|
399
|
-
addFormat(res, "uuid", check.message, refs);
|
|
400
|
-
break;
|
|
401
|
-
case "regex":
|
|
402
|
-
addPattern(res, check.regex, check.message, refs);
|
|
403
|
-
break;
|
|
404
|
-
case "cuid":
|
|
405
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
406
|
-
break;
|
|
407
|
-
case "cuid2":
|
|
408
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
409
|
-
break;
|
|
410
|
-
case "startsWith":
|
|
411
|
-
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
412
|
-
break;
|
|
413
|
-
case "endsWith":
|
|
414
|
-
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
415
|
-
break;
|
|
416
|
-
case "datetime":
|
|
417
|
-
addFormat(res, "date-time", check.message, refs);
|
|
418
|
-
break;
|
|
419
|
-
case "date":
|
|
420
|
-
addFormat(res, "date", check.message, refs);
|
|
421
|
-
break;
|
|
422
|
-
case "time":
|
|
423
|
-
addFormat(res, "time", check.message, refs);
|
|
424
|
-
break;
|
|
425
|
-
case "duration":
|
|
426
|
-
addFormat(res, "duration", check.message, refs);
|
|
427
|
-
break;
|
|
428
|
-
case "length":
|
|
429
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
430
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
431
|
-
break;
|
|
432
|
-
case "includes": {
|
|
433
|
-
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
case "ip": {
|
|
437
|
-
if (check.version !== "v6") {
|
|
438
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
439
|
-
}
|
|
440
|
-
if (check.version !== "v4") {
|
|
441
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
442
|
-
}
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
case "base64url":
|
|
446
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
447
|
-
break;
|
|
448
|
-
case "jwt":
|
|
449
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
450
|
-
break;
|
|
451
|
-
case "cidr": {
|
|
452
|
-
if (check.version !== "v6") {
|
|
453
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
454
|
-
}
|
|
455
|
-
if (check.version !== "v4") {
|
|
456
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
457
|
-
}
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
case "emoji":
|
|
461
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
462
|
-
break;
|
|
463
|
-
case "ulid": {
|
|
464
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
case "base64": {
|
|
468
|
-
switch (refs.base64Strategy) {
|
|
469
|
-
case "format:binary": {
|
|
470
|
-
addFormat(res, "binary", check.message, refs);
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
case "contentEncoding:base64": {
|
|
474
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
475
|
-
break;
|
|
476
|
-
}
|
|
477
|
-
case "pattern:zod": {
|
|
478
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
case "nanoid": {
|
|
485
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
486
|
-
}
|
|
487
|
-
case "toLowerCase":
|
|
488
|
-
case "toUpperCase":
|
|
489
|
-
case "trim":
|
|
490
|
-
break;
|
|
491
|
-
default:
|
|
492
|
-
/* @__PURE__ */ ((_) => {
|
|
493
|
-
})(check);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return res;
|
|
498
|
-
}
|
|
499
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
500
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
501
|
-
}
|
|
502
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
503
|
-
function escapeNonAlphaNumeric(source) {
|
|
504
|
-
let result = "";
|
|
505
|
-
for (let i = 0; i < source.length; i++) {
|
|
506
|
-
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
507
|
-
result += "\\";
|
|
508
|
-
}
|
|
509
|
-
result += source[i];
|
|
510
|
-
}
|
|
511
|
-
return result;
|
|
512
|
-
}
|
|
513
|
-
function addFormat(schema, value, message, refs) {
|
|
514
|
-
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
515
|
-
if (!schema.anyOf) {
|
|
516
|
-
schema.anyOf = [];
|
|
517
|
-
}
|
|
518
|
-
if (schema.format) {
|
|
519
|
-
schema.anyOf.push({
|
|
520
|
-
format: schema.format,
|
|
521
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
522
|
-
errorMessage: { format: schema.errorMessage.format }
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
delete schema.format;
|
|
526
|
-
if (schema.errorMessage) {
|
|
527
|
-
delete schema.errorMessage.format;
|
|
528
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
529
|
-
delete schema.errorMessage;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
schema.anyOf.push({
|
|
534
|
-
format: value,
|
|
535
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
536
|
-
});
|
|
537
|
-
} else {
|
|
538
|
-
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
function addPattern(schema, regex, message, refs) {
|
|
542
|
-
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
543
|
-
if (!schema.allOf) {
|
|
544
|
-
schema.allOf = [];
|
|
545
|
-
}
|
|
546
|
-
if (schema.pattern) {
|
|
547
|
-
schema.allOf.push({
|
|
548
|
-
pattern: schema.pattern,
|
|
549
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
550
|
-
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
delete schema.pattern;
|
|
554
|
-
if (schema.errorMessage) {
|
|
555
|
-
delete schema.errorMessage.pattern;
|
|
556
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
557
|
-
delete schema.errorMessage;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
schema.allOf.push({
|
|
562
|
-
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
563
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
564
|
-
});
|
|
565
|
-
} else {
|
|
566
|
-
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
function stringifyRegExpWithFlags(regex, refs) {
|
|
570
|
-
if (!refs.applyRegexFlags || !regex.flags) {
|
|
571
|
-
return regex.source;
|
|
572
|
-
}
|
|
573
|
-
const flags = {
|
|
574
|
-
i: regex.flags.includes("i"),
|
|
575
|
-
m: regex.flags.includes("m"),
|
|
576
|
-
s: regex.flags.includes("s")
|
|
577
|
-
// `.` matches newlines
|
|
578
|
-
};
|
|
579
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
580
|
-
let pattern = "";
|
|
581
|
-
let isEscaped = false;
|
|
582
|
-
let inCharGroup = false;
|
|
583
|
-
let inCharRange = false;
|
|
584
|
-
for (let i = 0; i < source.length; i++) {
|
|
585
|
-
if (isEscaped) {
|
|
586
|
-
pattern += source[i];
|
|
587
|
-
isEscaped = false;
|
|
588
|
-
continue;
|
|
589
|
-
}
|
|
590
|
-
if (flags.i) {
|
|
591
|
-
if (inCharGroup) {
|
|
592
|
-
if (source[i].match(/[a-z]/)) {
|
|
593
|
-
if (inCharRange) {
|
|
594
|
-
pattern += source[i];
|
|
595
|
-
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
596
|
-
inCharRange = false;
|
|
597
|
-
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
598
|
-
pattern += source[i];
|
|
599
|
-
inCharRange = true;
|
|
600
|
-
} else {
|
|
601
|
-
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
602
|
-
}
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
} else if (source[i].match(/[a-z]/)) {
|
|
606
|
-
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
607
|
-
continue;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
if (flags.m) {
|
|
611
|
-
if (source[i] === "^") {
|
|
612
|
-
pattern += `(^|(?<=[\r
|
|
613
|
-
]))`;
|
|
614
|
-
continue;
|
|
615
|
-
} else if (source[i] === "$") {
|
|
616
|
-
pattern += `($|(?=[\r
|
|
617
|
-
]))`;
|
|
618
|
-
continue;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
if (flags.s && source[i] === ".") {
|
|
622
|
-
pattern += inCharGroup ? `${source[i]}\r
|
|
623
|
-
` : `[${source[i]}\r
|
|
624
|
-
]`;
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
pattern += source[i];
|
|
628
|
-
if (source[i] === "\\") {
|
|
629
|
-
isEscaped = true;
|
|
630
|
-
} else if (inCharGroup && source[i] === "]") {
|
|
631
|
-
inCharGroup = false;
|
|
632
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
633
|
-
inCharGroup = true;
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
try {
|
|
637
|
-
new RegExp(pattern);
|
|
638
|
-
} catch {
|
|
639
|
-
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
640
|
-
return regex.source;
|
|
641
|
-
}
|
|
642
|
-
return pattern;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
646
|
-
function parseRecordDef(def, refs) {
|
|
647
|
-
if (refs.target === "openAi") {
|
|
648
|
-
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
649
|
-
}
|
|
650
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
651
|
-
return {
|
|
652
|
-
type: "object",
|
|
653
|
-
required: def.keyType._def.values,
|
|
654
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
655
|
-
...acc,
|
|
656
|
-
[key]: parseDef(def.valueType._def, {
|
|
657
|
-
...refs,
|
|
658
|
-
currentPath: [...refs.currentPath, "properties", key]
|
|
659
|
-
}) ?? {}
|
|
660
|
-
}), {}),
|
|
661
|
-
additionalProperties: refs.rejectedAdditionalProperties
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
const schema = {
|
|
665
|
-
type: "object",
|
|
666
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
667
|
-
...refs,
|
|
668
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
669
|
-
}) ?? refs.allowedAdditionalProperties
|
|
670
|
-
};
|
|
671
|
-
if (refs.target === "openApi3") {
|
|
672
|
-
return schema;
|
|
673
|
-
}
|
|
674
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
675
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
676
|
-
return {
|
|
677
|
-
...schema,
|
|
678
|
-
propertyNames: keyType
|
|
679
|
-
};
|
|
680
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
681
|
-
return {
|
|
682
|
-
...schema,
|
|
683
|
-
propertyNames: {
|
|
684
|
-
enum: def.keyType._def.values
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
688
|
-
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
689
|
-
return {
|
|
690
|
-
...schema,
|
|
691
|
-
propertyNames: keyType
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
return schema;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
698
|
-
function parseMapDef(def, refs) {
|
|
699
|
-
if (refs.mapStrategy === "record") {
|
|
700
|
-
return parseRecordDef(def, refs);
|
|
701
|
-
}
|
|
702
|
-
const keys = parseDef(def.keyType._def, {
|
|
703
|
-
...refs,
|
|
704
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
705
|
-
}) || {};
|
|
706
|
-
const values = parseDef(def.valueType._def, {
|
|
707
|
-
...refs,
|
|
708
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
709
|
-
}) || {};
|
|
710
|
-
return {
|
|
711
|
-
type: "array",
|
|
712
|
-
maxItems: 125,
|
|
713
|
-
items: {
|
|
714
|
-
type: "array",
|
|
715
|
-
items: [keys, values],
|
|
716
|
-
minItems: 2,
|
|
717
|
-
maxItems: 2
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
723
|
-
function parseNativeEnumDef(def) {
|
|
724
|
-
const object = def.values;
|
|
725
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
726
|
-
return typeof object[object[key]] !== "number";
|
|
727
|
-
});
|
|
728
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
729
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
730
|
-
return {
|
|
731
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
732
|
-
enum: actualValues
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
737
|
-
function parseNeverDef() {
|
|
738
|
-
return {
|
|
739
|
-
not: {}
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
744
|
-
function parseNullDef(refs) {
|
|
745
|
-
return refs.target === "openApi3" ? {
|
|
746
|
-
enum: ["null"],
|
|
747
|
-
nullable: true
|
|
748
|
-
} : {
|
|
749
|
-
type: "null"
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
754
|
-
var primitiveMappings = {
|
|
755
|
-
ZodString: "string",
|
|
756
|
-
ZodNumber: "number",
|
|
757
|
-
ZodBigInt: "integer",
|
|
758
|
-
ZodBoolean: "boolean",
|
|
759
|
-
ZodNull: "null"
|
|
760
|
-
};
|
|
761
|
-
function parseUnionDef(def, refs) {
|
|
762
|
-
if (refs.target === "openApi3")
|
|
763
|
-
return asAnyOf(def, refs);
|
|
764
|
-
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
765
|
-
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
766
|
-
const types = options.reduce((types2, x) => {
|
|
767
|
-
const type = primitiveMappings[x._def.typeName];
|
|
768
|
-
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
769
|
-
}, []);
|
|
770
|
-
return {
|
|
771
|
-
type: types.length > 1 ? types : types[0]
|
|
772
|
-
};
|
|
773
|
-
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
774
|
-
const types = options.reduce((acc, x) => {
|
|
775
|
-
const type = typeof x._def.value;
|
|
776
|
-
switch (type) {
|
|
777
|
-
case "string":
|
|
778
|
-
case "number":
|
|
779
|
-
case "boolean":
|
|
780
|
-
return [...acc, type];
|
|
781
|
-
case "bigint":
|
|
782
|
-
return [...acc, "integer"];
|
|
783
|
-
case "object":
|
|
784
|
-
if (x._def.value === null)
|
|
785
|
-
return [...acc, "null"];
|
|
786
|
-
case "symbol":
|
|
787
|
-
case "undefined":
|
|
788
|
-
case "function":
|
|
789
|
-
default:
|
|
790
|
-
return acc;
|
|
791
|
-
}
|
|
792
|
-
}, []);
|
|
793
|
-
if (types.length === options.length) {
|
|
794
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
795
|
-
return {
|
|
796
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
797
|
-
enum: options.reduce((acc, x) => {
|
|
798
|
-
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
799
|
-
}, [])
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
803
|
-
return {
|
|
804
|
-
type: "string",
|
|
805
|
-
enum: options.reduce((acc, x) => [
|
|
806
|
-
...acc,
|
|
807
|
-
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
808
|
-
], [])
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
return asAnyOf(def, refs);
|
|
812
|
-
}
|
|
813
|
-
var asAnyOf = (def, refs) => {
|
|
814
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
815
|
-
...refs,
|
|
816
|
-
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
817
|
-
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
818
|
-
return anyOf.length ? { anyOf } : void 0;
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
822
|
-
function parseNullableDef(def, refs) {
|
|
823
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
824
|
-
if (refs.target === "openApi3") {
|
|
825
|
-
return {
|
|
826
|
-
type: primitiveMappings[def.innerType._def.typeName],
|
|
827
|
-
nullable: true
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
return {
|
|
831
|
-
type: [
|
|
832
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
833
|
-
"null"
|
|
834
|
-
]
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
if (refs.target === "openApi3") {
|
|
838
|
-
const base2 = parseDef(def.innerType._def, {
|
|
839
|
-
...refs,
|
|
840
|
-
currentPath: [...refs.currentPath]
|
|
841
|
-
});
|
|
842
|
-
if (base2 && "$ref" in base2)
|
|
843
|
-
return { allOf: [base2], nullable: true };
|
|
844
|
-
return base2 && { ...base2, nullable: true };
|
|
845
|
-
}
|
|
846
|
-
const base = parseDef(def.innerType._def, {
|
|
847
|
-
...refs,
|
|
848
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
849
|
-
});
|
|
850
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
854
|
-
function parseNumberDef(def, refs) {
|
|
855
|
-
const res = {
|
|
856
|
-
type: "number"
|
|
857
|
-
};
|
|
858
|
-
if (!def.checks)
|
|
859
|
-
return res;
|
|
860
|
-
for (const check of def.checks) {
|
|
861
|
-
switch (check.kind) {
|
|
862
|
-
case "int":
|
|
863
|
-
res.type = "integer";
|
|
864
|
-
addErrorMessage(res, "type", check.message, refs);
|
|
865
|
-
break;
|
|
866
|
-
case "min":
|
|
867
|
-
if (refs.target === "jsonSchema7") {
|
|
868
|
-
if (check.inclusive) {
|
|
869
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
870
|
-
} else {
|
|
871
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
872
|
-
}
|
|
873
|
-
} else {
|
|
874
|
-
if (!check.inclusive) {
|
|
875
|
-
res.exclusiveMinimum = true;
|
|
876
|
-
}
|
|
877
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
878
|
-
}
|
|
879
|
-
break;
|
|
880
|
-
case "max":
|
|
881
|
-
if (refs.target === "jsonSchema7") {
|
|
882
|
-
if (check.inclusive) {
|
|
883
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
884
|
-
} else {
|
|
885
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
886
|
-
}
|
|
887
|
-
} else {
|
|
888
|
-
if (!check.inclusive) {
|
|
889
|
-
res.exclusiveMaximum = true;
|
|
890
|
-
}
|
|
891
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
892
|
-
}
|
|
893
|
-
break;
|
|
894
|
-
case "multipleOf":
|
|
895
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
896
|
-
break;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
return res;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
903
|
-
import { ZodOptional } from "zod";
|
|
904
|
-
function parseObjectDef(def, refs) {
|
|
905
|
-
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
906
|
-
const result = {
|
|
907
|
-
type: "object",
|
|
908
|
-
properties: {}
|
|
909
|
-
};
|
|
910
|
-
const required = [];
|
|
911
|
-
const shape = def.shape();
|
|
912
|
-
for (const propName in shape) {
|
|
913
|
-
let propDef = shape[propName];
|
|
914
|
-
if (propDef === void 0 || propDef._def === void 0) {
|
|
915
|
-
continue;
|
|
916
|
-
}
|
|
917
|
-
let propOptional = safeIsOptional(propDef);
|
|
918
|
-
if (propOptional && forceOptionalIntoNullable) {
|
|
919
|
-
if (propDef instanceof ZodOptional) {
|
|
920
|
-
propDef = propDef._def.innerType;
|
|
921
|
-
}
|
|
922
|
-
if (!propDef.isNullable()) {
|
|
923
|
-
propDef = propDef.nullable();
|
|
924
|
-
}
|
|
925
|
-
propOptional = false;
|
|
926
|
-
}
|
|
927
|
-
const parsedDef = parseDef(propDef._def, {
|
|
928
|
-
...refs,
|
|
929
|
-
currentPath: [...refs.currentPath, "properties", propName],
|
|
930
|
-
propertyPath: [...refs.currentPath, "properties", propName]
|
|
931
|
-
});
|
|
932
|
-
if (parsedDef === void 0) {
|
|
933
|
-
continue;
|
|
934
|
-
}
|
|
935
|
-
result.properties[propName] = parsedDef;
|
|
936
|
-
if (!propOptional) {
|
|
937
|
-
required.push(propName);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (required.length) {
|
|
941
|
-
result.required = required;
|
|
942
|
-
}
|
|
943
|
-
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
944
|
-
if (additionalProperties !== void 0) {
|
|
945
|
-
result.additionalProperties = additionalProperties;
|
|
946
|
-
}
|
|
947
|
-
return result;
|
|
948
|
-
}
|
|
949
|
-
function decideAdditionalProperties(def, refs) {
|
|
950
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
951
|
-
return parseDef(def.catchall._def, {
|
|
952
|
-
...refs,
|
|
953
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
switch (def.unknownKeys) {
|
|
957
|
-
case "passthrough":
|
|
958
|
-
return refs.allowedAdditionalProperties;
|
|
959
|
-
case "strict":
|
|
960
|
-
return refs.rejectedAdditionalProperties;
|
|
961
|
-
case "strip":
|
|
962
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
function safeIsOptional(schema) {
|
|
966
|
-
try {
|
|
967
|
-
return schema.isOptional();
|
|
968
|
-
} catch {
|
|
969
|
-
return true;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
974
|
-
var parseOptionalDef = (def, refs) => {
|
|
975
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
976
|
-
return parseDef(def.innerType._def, refs);
|
|
977
|
-
}
|
|
978
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
979
|
-
...refs,
|
|
980
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
981
|
-
});
|
|
982
|
-
return innerSchema ? {
|
|
983
|
-
anyOf: [
|
|
984
|
-
{
|
|
985
|
-
not: {}
|
|
986
|
-
},
|
|
987
|
-
innerSchema
|
|
988
|
-
]
|
|
989
|
-
} : {};
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
993
|
-
var parsePipelineDef = (def, refs) => {
|
|
994
|
-
if (refs.pipeStrategy === "input") {
|
|
995
|
-
return parseDef(def.in._def, refs);
|
|
996
|
-
} else if (refs.pipeStrategy === "output") {
|
|
997
|
-
return parseDef(def.out._def, refs);
|
|
998
|
-
}
|
|
999
|
-
const a = parseDef(def.in._def, {
|
|
1000
|
-
...refs,
|
|
1001
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1002
|
-
});
|
|
1003
|
-
const b = parseDef(def.out._def, {
|
|
1004
|
-
...refs,
|
|
1005
|
-
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1006
|
-
});
|
|
1007
|
-
return {
|
|
1008
|
-
allOf: [a, b].filter((x) => x !== void 0)
|
|
1009
|
-
};
|
|
1010
|
-
};
|
|
1011
|
-
|
|
1012
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1013
|
-
function parsePromiseDef(def, refs) {
|
|
1014
|
-
return parseDef(def.type._def, refs);
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1018
|
-
function parseSetDef(def, refs) {
|
|
1019
|
-
const items = parseDef(def.valueType._def, {
|
|
1020
|
-
...refs,
|
|
1021
|
-
currentPath: [...refs.currentPath, "items"]
|
|
1022
|
-
});
|
|
1023
|
-
const schema = {
|
|
1024
|
-
type: "array",
|
|
1025
|
-
uniqueItems: true,
|
|
1026
|
-
items
|
|
1027
|
-
};
|
|
1028
|
-
if (def.minSize) {
|
|
1029
|
-
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1030
|
-
}
|
|
1031
|
-
if (def.maxSize) {
|
|
1032
|
-
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1033
|
-
}
|
|
1034
|
-
return schema;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1038
|
-
function parseTupleDef(def, refs) {
|
|
1039
|
-
if (def.rest) {
|
|
1040
|
-
return {
|
|
1041
|
-
type: "array",
|
|
1042
|
-
minItems: def.items.length,
|
|
1043
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1044
|
-
...refs,
|
|
1045
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1046
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1047
|
-
additionalItems: parseDef(def.rest._def, {
|
|
1048
|
-
...refs,
|
|
1049
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1050
|
-
})
|
|
1051
|
-
};
|
|
1052
|
-
} else {
|
|
1053
|
-
return {
|
|
1054
|
-
type: "array",
|
|
1055
|
-
minItems: def.items.length,
|
|
1056
|
-
maxItems: def.items.length,
|
|
1057
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1058
|
-
...refs,
|
|
1059
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1060
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1066
|
-
function parseUndefinedDef() {
|
|
1067
|
-
return {
|
|
1068
|
-
not: {}
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1073
|
-
function parseUnknownDef() {
|
|
1074
|
-
return {};
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1078
|
-
var parseReadonlyDef = (def, refs) => {
|
|
1079
|
-
return parseDef(def.innerType._def, refs);
|
|
1080
|
-
};
|
|
1081
|
-
|
|
1082
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
1083
|
-
var selectParser = (def, typeName, refs) => {
|
|
1084
|
-
switch (typeName) {
|
|
1085
|
-
case ZodFirstPartyTypeKind3.ZodString:
|
|
1086
|
-
return parseStringDef(def, refs);
|
|
1087
|
-
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1088
|
-
return parseNumberDef(def, refs);
|
|
1089
|
-
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1090
|
-
return parseObjectDef(def, refs);
|
|
1091
|
-
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1092
|
-
return parseBigintDef(def, refs);
|
|
1093
|
-
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1094
|
-
return parseBooleanDef();
|
|
1095
|
-
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1096
|
-
return parseDateDef(def, refs);
|
|
1097
|
-
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1098
|
-
return parseUndefinedDef();
|
|
1099
|
-
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1100
|
-
return parseNullDef(refs);
|
|
1101
|
-
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1102
|
-
return parseArrayDef(def, refs);
|
|
1103
|
-
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1104
|
-
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1105
|
-
return parseUnionDef(def, refs);
|
|
1106
|
-
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1107
|
-
return parseIntersectionDef(def, refs);
|
|
1108
|
-
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1109
|
-
return parseTupleDef(def, refs);
|
|
1110
|
-
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1111
|
-
return parseRecordDef(def, refs);
|
|
1112
|
-
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1113
|
-
return parseLiteralDef(def, refs);
|
|
1114
|
-
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1115
|
-
return parseEnumDef(def);
|
|
1116
|
-
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1117
|
-
return parseNativeEnumDef(def);
|
|
1118
|
-
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1119
|
-
return parseNullableDef(def, refs);
|
|
1120
|
-
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1121
|
-
return parseOptionalDef(def, refs);
|
|
1122
|
-
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1123
|
-
return parseMapDef(def, refs);
|
|
1124
|
-
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1125
|
-
return parseSetDef(def, refs);
|
|
1126
|
-
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1127
|
-
return () => def.getter()._def;
|
|
1128
|
-
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1129
|
-
return parsePromiseDef(def, refs);
|
|
1130
|
-
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1131
|
-
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1132
|
-
return parseNeverDef();
|
|
1133
|
-
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1134
|
-
return parseEffectsDef(def, refs);
|
|
1135
|
-
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1136
|
-
return parseAnyDef();
|
|
1137
|
-
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1138
|
-
return parseUnknownDef();
|
|
1139
|
-
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1140
|
-
return parseDefaultDef(def, refs);
|
|
1141
|
-
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1142
|
-
return parseBrandedDef(def, refs);
|
|
1143
|
-
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1144
|
-
return parseReadonlyDef(def, refs);
|
|
1145
|
-
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1146
|
-
return parseCatchDef(def, refs);
|
|
1147
|
-
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1148
|
-
return parsePipelineDef(def, refs);
|
|
1149
|
-
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1150
|
-
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1151
|
-
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1152
|
-
return void 0;
|
|
1153
|
-
default:
|
|
1154
|
-
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
|
|
1158
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1159
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
1160
|
-
const seenItem = refs.seen.get(def);
|
|
1161
|
-
if (refs.override) {
|
|
1162
|
-
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1163
|
-
if (overrideResult !== ignoreOverride) {
|
|
1164
|
-
return overrideResult;
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
if (seenItem && !forceResolution) {
|
|
1168
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
1169
|
-
if (seenSchema !== void 0) {
|
|
1170
|
-
return seenSchema;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1174
|
-
refs.seen.set(def, newItem);
|
|
1175
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1176
|
-
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1177
|
-
if (jsonSchema) {
|
|
1178
|
-
addMeta(def, refs, jsonSchema);
|
|
1179
|
-
}
|
|
1180
|
-
if (refs.postProcess) {
|
|
1181
|
-
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
1182
|
-
newItem.jsonSchema = jsonSchema;
|
|
1183
|
-
return postProcessResult;
|
|
1184
|
-
}
|
|
1185
|
-
newItem.jsonSchema = jsonSchema;
|
|
1186
|
-
return jsonSchema;
|
|
1187
|
-
}
|
|
1188
|
-
var get$ref = (item, refs) => {
|
|
1189
|
-
switch (refs.$refStrategy) {
|
|
1190
|
-
case "root":
|
|
1191
|
-
return { $ref: item.path.join("/") };
|
|
1192
|
-
case "relative":
|
|
1193
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1194
|
-
case "none":
|
|
1195
|
-
case "seen": {
|
|
1196
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1197
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1198
|
-
return {};
|
|
1199
|
-
}
|
|
1200
|
-
return refs.$refStrategy === "seen" ? {} : void 0;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
var getRelativePath = (pathA, pathB) => {
|
|
1205
|
-
let i = 0;
|
|
1206
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1207
|
-
if (pathA[i] !== pathB[i])
|
|
1208
|
-
break;
|
|
1209
|
-
}
|
|
1210
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1211
|
-
};
|
|
1212
|
-
var addMeta = (def, refs, jsonSchema) => {
|
|
1213
|
-
if (def.description) {
|
|
1214
|
-
jsonSchema.description = def.description;
|
|
1215
|
-
if (refs.markdownDescription) {
|
|
1216
|
-
jsonSchema.markdownDescription = def.description;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
return jsonSchema;
|
|
1220
|
-
};
|
|
1221
|
-
|
|
1222
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1223
|
-
var zodToJsonSchema = (schema, options) => {
|
|
1224
|
-
const refs = getRefs(options);
|
|
1225
|
-
const definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
1226
|
-
...acc,
|
|
1227
|
-
[name2]: parseDef(schema2._def, {
|
|
1228
|
-
...refs,
|
|
1229
|
-
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
1230
|
-
}, true) ?? {}
|
|
1231
|
-
}), {}) : void 0;
|
|
1232
|
-
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
1233
|
-
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
1234
|
-
...refs,
|
|
1235
|
-
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
1236
|
-
}, false) ?? {};
|
|
1237
|
-
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1238
|
-
if (title !== void 0) {
|
|
1239
|
-
main.title = title;
|
|
1240
|
-
}
|
|
1241
|
-
const combined = name === void 0 ? definitions ? {
|
|
1242
|
-
...main,
|
|
1243
|
-
[refs.definitionPath]: definitions
|
|
1244
|
-
} : main : {
|
|
1245
|
-
$ref: [
|
|
1246
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1247
|
-
refs.definitionPath,
|
|
1248
|
-
name
|
|
1249
|
-
].join("/"),
|
|
1250
|
-
[refs.definitionPath]: {
|
|
1251
|
-
...definitions,
|
|
1252
|
-
[name]: main
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
|
-
if (refs.target === "jsonSchema7") {
|
|
1256
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1257
|
-
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
1258
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1259
|
-
}
|
|
1260
|
-
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
1261
|
-
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
1262
|
-
}
|
|
1263
|
-
return combined;
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
// src/MCPLocal.ts
|
|
1267
11
|
import {
|
|
1268
12
|
Field,
|
|
1269
13
|
Fields,
|
|
@@ -1274,6 +18,175 @@ import {
|
|
|
1274
18
|
SubscriptionRequestType,
|
|
1275
19
|
TimeInForce
|
|
1276
20
|
} from "fixparser";
|
|
21
|
+
var parseInputSchema = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
fixString: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "FIX message string to parse"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
required: ["fixString"]
|
|
30
|
+
};
|
|
31
|
+
var parseToJSONInputSchema = {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
fixString: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "FIX message string to parse"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
required: ["fixString"]
|
|
40
|
+
};
|
|
41
|
+
var newOrderSingleInputSchema = {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
clOrdID: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "Client Order ID"
|
|
47
|
+
},
|
|
48
|
+
handlInst: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["1", "2", "3"],
|
|
51
|
+
default: HandlInst.AutomatedExecutionNoIntervention,
|
|
52
|
+
description: 'Handling instruction (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention)'
|
|
53
|
+
},
|
|
54
|
+
quantity: {
|
|
55
|
+
type: "number",
|
|
56
|
+
description: "Order quantity"
|
|
57
|
+
},
|
|
58
|
+
price: {
|
|
59
|
+
type: "number",
|
|
60
|
+
description: "Order price"
|
|
61
|
+
},
|
|
62
|
+
ordType: {
|
|
63
|
+
type: "string",
|
|
64
|
+
enum: [
|
|
65
|
+
"1",
|
|
66
|
+
"2",
|
|
67
|
+
"3",
|
|
68
|
+
"4",
|
|
69
|
+
"5",
|
|
70
|
+
"6",
|
|
71
|
+
"7",
|
|
72
|
+
"8",
|
|
73
|
+
"9",
|
|
74
|
+
"A",
|
|
75
|
+
"B",
|
|
76
|
+
"C",
|
|
77
|
+
"D",
|
|
78
|
+
"E",
|
|
79
|
+
"F",
|
|
80
|
+
"G",
|
|
81
|
+
"H",
|
|
82
|
+
"I",
|
|
83
|
+
"J",
|
|
84
|
+
"K",
|
|
85
|
+
"L",
|
|
86
|
+
"M",
|
|
87
|
+
"P",
|
|
88
|
+
"Q",
|
|
89
|
+
"R",
|
|
90
|
+
"S"
|
|
91
|
+
],
|
|
92
|
+
default: OrdType.Market,
|
|
93
|
+
description: 'Order type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Market, "2" for Limit, "3" for Stop)'
|
|
94
|
+
},
|
|
95
|
+
side: {
|
|
96
|
+
type: "string",
|
|
97
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
98
|
+
description: 'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'
|
|
99
|
+
},
|
|
100
|
+
symbol: {
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "Trading symbol"
|
|
103
|
+
},
|
|
104
|
+
timeInForce: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
107
|
+
default: TimeInForce.Day,
|
|
108
|
+
description: 'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
required: ["clOrdID", "quantity", "price", "side", "symbol"]
|
|
112
|
+
};
|
|
113
|
+
var marketDataRequestInputSchema = {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
mdUpdateType: {
|
|
117
|
+
type: "string",
|
|
118
|
+
enum: ["0", "1"],
|
|
119
|
+
default: "0",
|
|
120
|
+
description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
|
|
121
|
+
},
|
|
122
|
+
symbol: {
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "Trading symbol"
|
|
125
|
+
},
|
|
126
|
+
mdReqID: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Market data request ID"
|
|
129
|
+
},
|
|
130
|
+
subscriptionRequestType: {
|
|
131
|
+
type: "string",
|
|
132
|
+
enum: ["0", "1", "2"],
|
|
133
|
+
default: SubscriptionRequestType.SnapshotAndUpdates,
|
|
134
|
+
description: 'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'
|
|
135
|
+
},
|
|
136
|
+
mdEntryType: {
|
|
137
|
+
type: "string",
|
|
138
|
+
enum: [
|
|
139
|
+
"0",
|
|
140
|
+
"1",
|
|
141
|
+
"2",
|
|
142
|
+
"3",
|
|
143
|
+
"4",
|
|
144
|
+
"5",
|
|
145
|
+
"6",
|
|
146
|
+
"7",
|
|
147
|
+
"8",
|
|
148
|
+
"9",
|
|
149
|
+
"A",
|
|
150
|
+
"B",
|
|
151
|
+
"C",
|
|
152
|
+
"D",
|
|
153
|
+
"E",
|
|
154
|
+
"F",
|
|
155
|
+
"G",
|
|
156
|
+
"H",
|
|
157
|
+
"J",
|
|
158
|
+
"K",
|
|
159
|
+
"L",
|
|
160
|
+
"M",
|
|
161
|
+
"N",
|
|
162
|
+
"O",
|
|
163
|
+
"P",
|
|
164
|
+
"Q",
|
|
165
|
+
"S",
|
|
166
|
+
"R",
|
|
167
|
+
"T",
|
|
168
|
+
"U",
|
|
169
|
+
"V",
|
|
170
|
+
"W",
|
|
171
|
+
"X",
|
|
172
|
+
"Y",
|
|
173
|
+
"Z",
|
|
174
|
+
"a",
|
|
175
|
+
"b",
|
|
176
|
+
"c",
|
|
177
|
+
"d",
|
|
178
|
+
"e",
|
|
179
|
+
"g",
|
|
180
|
+
"h",
|
|
181
|
+
"i",
|
|
182
|
+
"t"
|
|
183
|
+
],
|
|
184
|
+
default: MDEntryType.Bid,
|
|
185
|
+
description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
required: ["symbol", "mdReqID"]
|
|
189
|
+
};
|
|
1277
190
|
var MCPLocal = class {
|
|
1278
191
|
logger;
|
|
1279
192
|
parser;
|
|
@@ -1283,23 +196,28 @@ var MCPLocal = class {
|
|
|
1283
196
|
version: "1.0.0"
|
|
1284
197
|
},
|
|
1285
198
|
{
|
|
1286
|
-
capabilities: {
|
|
199
|
+
capabilities: {
|
|
200
|
+
tools: {},
|
|
201
|
+
prompts: {},
|
|
202
|
+
resources: {}
|
|
203
|
+
}
|
|
1287
204
|
}
|
|
1288
205
|
);
|
|
1289
206
|
transport = new StdioServerTransport();
|
|
1290
207
|
onReady = void 0;
|
|
1291
208
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
1292
209
|
constructor({ logger, onReady }) {
|
|
1293
|
-
if (logger
|
|
210
|
+
if (logger && !logger.silent) {
|
|
211
|
+
this.logger = logger;
|
|
212
|
+
}
|
|
1294
213
|
if (onReady) this.onReady = onReady;
|
|
1295
214
|
}
|
|
1296
215
|
async register(parser) {
|
|
1297
216
|
this.parser = parser;
|
|
217
|
+
if (parser.logger && !parser.logger.silent) {
|
|
218
|
+
this.logger = parser.logger;
|
|
219
|
+
}
|
|
1298
220
|
this.parser.addOnMessageCallback((message) => {
|
|
1299
|
-
this.logger?.log({
|
|
1300
|
-
level: "info",
|
|
1301
|
-
message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
|
|
1302
|
-
});
|
|
1303
221
|
const msgType = message.messageType;
|
|
1304
222
|
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport) {
|
|
1305
223
|
const idField = msgType === Messages.MarketDataSnapshotFullRefresh ? message.getField(Fields.MDReqID) : message.getField(Fields.ClOrdID);
|
|
@@ -1315,7 +233,6 @@ var MCPLocal = class {
|
|
|
1315
233
|
}
|
|
1316
234
|
}
|
|
1317
235
|
});
|
|
1318
|
-
this.logger = parser.logger;
|
|
1319
236
|
this.addWorkflows();
|
|
1320
237
|
await this.server.connect(this.transport);
|
|
1321
238
|
if (this.onReady) {
|
|
@@ -1337,149 +254,49 @@ var MCPLocal = class {
|
|
|
1337
254
|
});
|
|
1338
255
|
return;
|
|
1339
256
|
}
|
|
257
|
+
const validateArgs = (args, schema) => {
|
|
258
|
+
const result = {};
|
|
259
|
+
for (const [key, propSchema] of Object.entries(schema.properties || {})) {
|
|
260
|
+
const prop = propSchema;
|
|
261
|
+
const value = args?.[key];
|
|
262
|
+
if (prop.required && (value === void 0 || value === null)) {
|
|
263
|
+
throw new Error(`Required property '${key}' is missing`);
|
|
264
|
+
}
|
|
265
|
+
if (value !== void 0) {
|
|
266
|
+
result[key] = value;
|
|
267
|
+
} else if (prop.default !== void 0) {
|
|
268
|
+
result[key] = prop.default;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
272
|
+
};
|
|
273
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
274
|
+
return {
|
|
275
|
+
resources: []
|
|
276
|
+
};
|
|
277
|
+
});
|
|
1340
278
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
1341
279
|
return {
|
|
1342
280
|
tools: [
|
|
1343
281
|
{
|
|
1344
282
|
name: "parse",
|
|
1345
283
|
description: "Parses a FIX message and describes it in plain language",
|
|
1346
|
-
inputSchema:
|
|
1347
|
-
z.object({
|
|
1348
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1349
|
-
}),
|
|
1350
|
-
{ name: "ParseInput" }
|
|
1351
|
-
)
|
|
284
|
+
inputSchema: parseInputSchema
|
|
1352
285
|
},
|
|
1353
286
|
{
|
|
1354
287
|
name: "parseToJSON",
|
|
1355
288
|
description: "Parses a FIX message into JSON",
|
|
1356
|
-
inputSchema:
|
|
1357
|
-
z.object({
|
|
1358
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1359
|
-
}),
|
|
1360
|
-
{ name: "ParseToJSONInput" }
|
|
1361
|
-
)
|
|
289
|
+
inputSchema: parseToJSONInputSchema
|
|
1362
290
|
},
|
|
1363
291
|
{
|
|
1364
292
|
name: "newOrderSingle",
|
|
1365
293
|
description: "Creates and sends a New Order Single",
|
|
1366
|
-
inputSchema:
|
|
1367
|
-
z.object({
|
|
1368
|
-
clOrdID: z.string().describe("Client Order ID"),
|
|
1369
|
-
handlInst: z.enum(["1", "2", "3"]).default(HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),
|
|
1370
|
-
quantity: z.number().describe("Order quantity"),
|
|
1371
|
-
price: z.number().describe("Order price"),
|
|
1372
|
-
ordType: z.enum([
|
|
1373
|
-
"1",
|
|
1374
|
-
"2",
|
|
1375
|
-
"3",
|
|
1376
|
-
"4",
|
|
1377
|
-
"5",
|
|
1378
|
-
"6",
|
|
1379
|
-
"7",
|
|
1380
|
-
"8",
|
|
1381
|
-
"9",
|
|
1382
|
-
"A",
|
|
1383
|
-
"B",
|
|
1384
|
-
"C",
|
|
1385
|
-
"D",
|
|
1386
|
-
"E",
|
|
1387
|
-
"F",
|
|
1388
|
-
"G",
|
|
1389
|
-
"H",
|
|
1390
|
-
"I",
|
|
1391
|
-
"J",
|
|
1392
|
-
"K",
|
|
1393
|
-
"L",
|
|
1394
|
-
"M",
|
|
1395
|
-
"P",
|
|
1396
|
-
"Q",
|
|
1397
|
-
"R",
|
|
1398
|
-
"S"
|
|
1399
|
-
]).default("1").optional().describe("Order type"),
|
|
1400
|
-
side: z.enum([
|
|
1401
|
-
"1",
|
|
1402
|
-
"2",
|
|
1403
|
-
"3",
|
|
1404
|
-
"4",
|
|
1405
|
-
"5",
|
|
1406
|
-
"6",
|
|
1407
|
-
"7",
|
|
1408
|
-
"8",
|
|
1409
|
-
"9",
|
|
1410
|
-
"A",
|
|
1411
|
-
"B",
|
|
1412
|
-
"C",
|
|
1413
|
-
"D",
|
|
1414
|
-
"E",
|
|
1415
|
-
"F",
|
|
1416
|
-
"G",
|
|
1417
|
-
"H"
|
|
1418
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1419
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1420
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1421
|
-
}),
|
|
1422
|
-
{ name: "NewOrderSingleInput" }
|
|
1423
|
-
)
|
|
294
|
+
inputSchema: newOrderSingleInputSchema
|
|
1424
295
|
},
|
|
1425
296
|
{
|
|
1426
297
|
name: "marketDataRequest",
|
|
1427
298
|
description: "Sends a request for Market Data with the given symbol",
|
|
1428
|
-
inputSchema:
|
|
1429
|
-
z.object({
|
|
1430
|
-
mdUpdateType: z.enum(["0", "1"]).default("0").optional().describe("Market data update type"),
|
|
1431
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1432
|
-
mdReqID: z.string().describe("Market data request ID"),
|
|
1433
|
-
subscriptionRequestType: z.enum(["0", "1", "2"]).default(SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),
|
|
1434
|
-
mdEntryType: z.enum([
|
|
1435
|
-
"0",
|
|
1436
|
-
"1",
|
|
1437
|
-
"2",
|
|
1438
|
-
"3",
|
|
1439
|
-
"4",
|
|
1440
|
-
"5",
|
|
1441
|
-
"6",
|
|
1442
|
-
"7",
|
|
1443
|
-
"8",
|
|
1444
|
-
"9",
|
|
1445
|
-
"A",
|
|
1446
|
-
"B",
|
|
1447
|
-
"C",
|
|
1448
|
-
"D",
|
|
1449
|
-
"E",
|
|
1450
|
-
"F",
|
|
1451
|
-
"G",
|
|
1452
|
-
"H",
|
|
1453
|
-
"J",
|
|
1454
|
-
"K",
|
|
1455
|
-
"L",
|
|
1456
|
-
"M",
|
|
1457
|
-
"N",
|
|
1458
|
-
"O",
|
|
1459
|
-
"P",
|
|
1460
|
-
"Q",
|
|
1461
|
-
"S",
|
|
1462
|
-
"R",
|
|
1463
|
-
"T",
|
|
1464
|
-
"U",
|
|
1465
|
-
"V",
|
|
1466
|
-
"W",
|
|
1467
|
-
"X",
|
|
1468
|
-
"Y",
|
|
1469
|
-
"Z",
|
|
1470
|
-
"a",
|
|
1471
|
-
"b",
|
|
1472
|
-
"c",
|
|
1473
|
-
"d",
|
|
1474
|
-
"e",
|
|
1475
|
-
"g",
|
|
1476
|
-
"h",
|
|
1477
|
-
"i",
|
|
1478
|
-
"t"
|
|
1479
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1480
|
-
}),
|
|
1481
|
-
{ name: "MarketDataRequestInput" }
|
|
1482
|
-
)
|
|
299
|
+
inputSchema: marketDataRequestInputSchema
|
|
1483
300
|
}
|
|
1484
301
|
]
|
|
1485
302
|
};
|
|
@@ -1488,10 +305,8 @@ var MCPLocal = class {
|
|
|
1488
305
|
const { name, arguments: args } = request.params;
|
|
1489
306
|
switch (name) {
|
|
1490
307
|
case "parse": {
|
|
1491
|
-
const { fixString } = z.object({
|
|
1492
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1493
|
-
}).parse(args || {});
|
|
1494
308
|
try {
|
|
309
|
+
const { fixString } = validateArgs(args, parseInputSchema);
|
|
1495
310
|
const parsedMessage = this.parser?.parse(fixString);
|
|
1496
311
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1497
312
|
return {
|
|
@@ -1503,7 +318,8 @@ var MCPLocal = class {
|
|
|
1503
318
|
content: [
|
|
1504
319
|
{
|
|
1505
320
|
type: "text",
|
|
1506
|
-
text:
|
|
321
|
+
text: `${parsedMessage[0].description}
|
|
322
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
1507
323
|
}
|
|
1508
324
|
]
|
|
1509
325
|
};
|
|
@@ -1513,17 +329,15 @@ var MCPLocal = class {
|
|
|
1513
329
|
content: [
|
|
1514
330
|
{
|
|
1515
331
|
type: "text",
|
|
1516
|
-
text:
|
|
332
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1517
333
|
}
|
|
1518
334
|
]
|
|
1519
335
|
};
|
|
1520
336
|
}
|
|
1521
337
|
}
|
|
1522
338
|
case "parseToJSON": {
|
|
1523
|
-
const { fixString } = z.object({
|
|
1524
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1525
|
-
}).parse(args || {});
|
|
1526
339
|
try {
|
|
340
|
+
const { fixString } = validateArgs(args, parseToJSONInputSchema);
|
|
1527
341
|
const parsedMessage = this.parser?.parse(fixString);
|
|
1528
342
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1529
343
|
return {
|
|
@@ -1535,7 +349,7 @@ var MCPLocal = class {
|
|
|
1535
349
|
content: [
|
|
1536
350
|
{
|
|
1537
351
|
type: "text",
|
|
1538
|
-
text:
|
|
352
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
1539
353
|
}
|
|
1540
354
|
]
|
|
1541
355
|
};
|
|
@@ -1545,220 +359,340 @@ var MCPLocal = class {
|
|
|
1545
359
|
content: [
|
|
1546
360
|
{
|
|
1547
361
|
type: "text",
|
|
1548
|
-
text:
|
|
362
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1549
363
|
}
|
|
1550
364
|
]
|
|
1551
365
|
};
|
|
1552
366
|
}
|
|
1553
367
|
}
|
|
1554
368
|
case "newOrderSingle": {
|
|
1555
|
-
|
|
1556
|
-
clOrdID
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
"4",
|
|
1593
|
-
"5",
|
|
1594
|
-
"6",
|
|
1595
|
-
"7",
|
|
1596
|
-
"8",
|
|
1597
|
-
"9",
|
|
1598
|
-
"A",
|
|
1599
|
-
"B",
|
|
1600
|
-
"C",
|
|
1601
|
-
"D",
|
|
1602
|
-
"E",
|
|
1603
|
-
"F",
|
|
1604
|
-
"G",
|
|
1605
|
-
"H"
|
|
1606
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1607
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1608
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1609
|
-
}).parse(args || {});
|
|
1610
|
-
const response = new Promise((resolve) => {
|
|
1611
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
1612
|
-
});
|
|
1613
|
-
const order = this.parser?.createMessage(
|
|
1614
|
-
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
1615
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1616
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1617
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1618
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1619
|
-
new Field(Fields.ClOrdID, clOrdID),
|
|
1620
|
-
new Field(Fields.Side, side),
|
|
1621
|
-
new Field(Fields.Symbol, symbol),
|
|
1622
|
-
new Field(Fields.OrderQty, quantity),
|
|
1623
|
-
new Field(Fields.Price, price),
|
|
1624
|
-
new Field(Fields.OrdType, ordType),
|
|
1625
|
-
new Field(Fields.HandlInst, handlInst),
|
|
1626
|
-
new Field(Fields.TimeInForce, timeInForce),
|
|
1627
|
-
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
1628
|
-
);
|
|
1629
|
-
if (!this.parser?.connected) {
|
|
369
|
+
try {
|
|
370
|
+
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
|
|
371
|
+
const response = new Promise((resolve) => {
|
|
372
|
+
this.pendingRequests.set(clOrdID, resolve);
|
|
373
|
+
});
|
|
374
|
+
const order = this.parser?.createMessage(
|
|
375
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
376
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
377
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
378
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
379
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
380
|
+
new Field(Fields.ClOrdID, clOrdID),
|
|
381
|
+
new Field(Fields.Side, side),
|
|
382
|
+
new Field(Fields.Symbol, symbol),
|
|
383
|
+
new Field(Fields.OrderQty, quantity),
|
|
384
|
+
new Field(Fields.Price, price),
|
|
385
|
+
new Field(Fields.OrdType, ordType),
|
|
386
|
+
new Field(Fields.HandlInst, handlInst),
|
|
387
|
+
new Field(Fields.TimeInForce, timeInForce),
|
|
388
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
389
|
+
);
|
|
390
|
+
if (!this.parser?.connected) {
|
|
391
|
+
this.logger?.log({
|
|
392
|
+
level: "error",
|
|
393
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
394
|
+
});
|
|
395
|
+
return {
|
|
396
|
+
isError: true,
|
|
397
|
+
content: [
|
|
398
|
+
{
|
|
399
|
+
type: "text",
|
|
400
|
+
text: "Error: Not connected. Ignoring message."
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
this.parser?.send(order);
|
|
1630
406
|
this.logger?.log({
|
|
1631
|
-
level: "
|
|
1632
|
-
message:
|
|
407
|
+
level: "info",
|
|
408
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
1633
409
|
});
|
|
410
|
+
const fixData = await response;
|
|
411
|
+
return {
|
|
412
|
+
content: [
|
|
413
|
+
{
|
|
414
|
+
type: "text",
|
|
415
|
+
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
};
|
|
419
|
+
} catch (error) {
|
|
1634
420
|
return {
|
|
1635
421
|
isError: true,
|
|
1636
422
|
content: [
|
|
1637
423
|
{
|
|
1638
424
|
type: "text",
|
|
1639
|
-
text:
|
|
425
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
|
|
1640
426
|
}
|
|
1641
427
|
]
|
|
1642
428
|
};
|
|
1643
429
|
}
|
|
1644
|
-
this.parser?.send(order);
|
|
1645
|
-
this.logger?.log({
|
|
1646
|
-
level: "info",
|
|
1647
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
1648
|
-
});
|
|
1649
|
-
const fixData = await response;
|
|
1650
|
-
return {
|
|
1651
|
-
content: [
|
|
1652
|
-
{
|
|
1653
|
-
type: "text",
|
|
1654
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1655
|
-
}
|
|
1656
|
-
]
|
|
1657
|
-
};
|
|
1658
430
|
}
|
|
1659
431
|
case "marketDataRequest": {
|
|
1660
|
-
|
|
1661
|
-
mdUpdateType
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
"Y",
|
|
1700
|
-
"Z",
|
|
1701
|
-
"a",
|
|
1702
|
-
"b",
|
|
1703
|
-
"c",
|
|
1704
|
-
"d",
|
|
1705
|
-
"e",
|
|
1706
|
-
"g",
|
|
1707
|
-
"h",
|
|
1708
|
-
"i",
|
|
1709
|
-
"t"
|
|
1710
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1711
|
-
}).parse(args || {});
|
|
1712
|
-
const response = new Promise((resolve) => {
|
|
1713
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
1714
|
-
});
|
|
1715
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
1716
|
-
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1717
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1718
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1719
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1720
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1721
|
-
new Field(Fields.MarketDepth, 0),
|
|
1722
|
-
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
1723
|
-
new Field(Fields.NoRelatedSym, 1),
|
|
1724
|
-
new Field(Fields.Symbol, symbol),
|
|
1725
|
-
new Field(Fields.MDReqID, mdReqID),
|
|
1726
|
-
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
1727
|
-
new Field(Fields.NoMDEntryTypes, 1),
|
|
1728
|
-
new Field(Fields.MDEntryType, mdEntryType)
|
|
1729
|
-
);
|
|
1730
|
-
if (!this.parser?.connected) {
|
|
432
|
+
try {
|
|
433
|
+
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
434
|
+
args,
|
|
435
|
+
marketDataRequestInputSchema
|
|
436
|
+
);
|
|
437
|
+
const response = new Promise((resolve) => {
|
|
438
|
+
this.pendingRequests.set(mdReqID, resolve);
|
|
439
|
+
});
|
|
440
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
441
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
442
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
443
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
444
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
445
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
446
|
+
new Field(Fields.MarketDepth, 0),
|
|
447
|
+
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
448
|
+
new Field(Fields.NoRelatedSym, 1),
|
|
449
|
+
new Field(Fields.Symbol, symbol),
|
|
450
|
+
new Field(Fields.MDReqID, mdReqID),
|
|
451
|
+
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
452
|
+
new Field(Fields.NoMDEntryTypes, 1),
|
|
453
|
+
new Field(Fields.MDEntryType, mdEntryType)
|
|
454
|
+
);
|
|
455
|
+
if (!this.parser?.connected) {
|
|
456
|
+
this.logger?.log({
|
|
457
|
+
level: "error",
|
|
458
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
459
|
+
});
|
|
460
|
+
return {
|
|
461
|
+
isError: true,
|
|
462
|
+
content: [
|
|
463
|
+
{
|
|
464
|
+
type: "text",
|
|
465
|
+
text: "Error: Not connected. Ignoring message."
|
|
466
|
+
}
|
|
467
|
+
]
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
this.parser?.send(marketDataRequest);
|
|
1731
471
|
this.logger?.log({
|
|
1732
|
-
level: "
|
|
1733
|
-
message:
|
|
472
|
+
level: "info",
|
|
473
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
1734
474
|
});
|
|
475
|
+
const fixData = await response;
|
|
476
|
+
return {
|
|
477
|
+
content: [
|
|
478
|
+
{
|
|
479
|
+
type: "text",
|
|
480
|
+
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
481
|
+
}
|
|
482
|
+
]
|
|
483
|
+
};
|
|
484
|
+
} catch (error) {
|
|
1735
485
|
return {
|
|
1736
486
|
isError: true,
|
|
1737
487
|
content: [
|
|
1738
488
|
{
|
|
1739
489
|
type: "text",
|
|
1740
|
-
text:
|
|
490
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
1741
491
|
}
|
|
1742
492
|
]
|
|
1743
493
|
};
|
|
1744
494
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
495
|
+
}
|
|
496
|
+
default:
|
|
497
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
501
|
+
return {
|
|
502
|
+
prompts: [
|
|
503
|
+
{
|
|
504
|
+
name: "parse",
|
|
505
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
506
|
+
arguments: [
|
|
507
|
+
{
|
|
508
|
+
name: "fixString",
|
|
509
|
+
description: "FIX message string to parse",
|
|
510
|
+
required: true
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
name: "parseToJSON",
|
|
516
|
+
description: "Parses a FIX message into JSON",
|
|
517
|
+
arguments: [
|
|
518
|
+
{
|
|
519
|
+
name: "fixString",
|
|
520
|
+
description: "FIX message string to parse",
|
|
521
|
+
required: true
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: "newOrderSingle",
|
|
527
|
+
description: "Creates and sends a New Order Single",
|
|
528
|
+
arguments: [
|
|
529
|
+
{
|
|
530
|
+
name: "clOrdID",
|
|
531
|
+
description: "Client Order ID",
|
|
532
|
+
required: true
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: "handlInst",
|
|
536
|
+
description: "Handling instruction",
|
|
537
|
+
required: false
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
name: "quantity",
|
|
541
|
+
description: "Order quantity",
|
|
542
|
+
required: true
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
name: "price",
|
|
546
|
+
description: "Order price",
|
|
547
|
+
required: true
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
name: "ordType",
|
|
551
|
+
description: "Order type",
|
|
552
|
+
required: false
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
name: "side",
|
|
556
|
+
description: "Order side (1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed)",
|
|
557
|
+
required: true
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
name: "symbol",
|
|
561
|
+
description: "Trading symbol",
|
|
562
|
+
required: true
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: "timeInForce",
|
|
566
|
+
description: "Time in force",
|
|
567
|
+
required: false
|
|
568
|
+
}
|
|
569
|
+
]
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
name: "marketDataRequest",
|
|
573
|
+
description: "Sends a request for Market Data with the given symbol",
|
|
574
|
+
arguments: [
|
|
575
|
+
{
|
|
576
|
+
name: "mdUpdateType",
|
|
577
|
+
description: "Market data update type",
|
|
578
|
+
required: false
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
name: "symbol",
|
|
582
|
+
description: "Trading symbol",
|
|
583
|
+
required: true
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
name: "mdReqID",
|
|
587
|
+
description: "Market data request ID",
|
|
588
|
+
required: true
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
name: "subscriptionRequestType",
|
|
592
|
+
description: "Subscription request type",
|
|
593
|
+
required: false
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
name: "mdEntryType",
|
|
597
|
+
description: "Market data entry type",
|
|
598
|
+
required: false
|
|
599
|
+
}
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
]
|
|
603
|
+
};
|
|
604
|
+
});
|
|
605
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
606
|
+
const { name, arguments: args } = request.params;
|
|
607
|
+
switch (name) {
|
|
608
|
+
case "parse": {
|
|
609
|
+
const fixString = args?.fixString || "";
|
|
610
|
+
return {
|
|
611
|
+
messages: [
|
|
612
|
+
{
|
|
613
|
+
role: "user",
|
|
614
|
+
content: {
|
|
615
|
+
type: "text",
|
|
616
|
+
text: `Please parse and explain this FIX message: ${fixString}`
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
case "parseToJSON": {
|
|
623
|
+
const fixString = args?.fixString || "";
|
|
1751
624
|
return {
|
|
1752
|
-
|
|
625
|
+
messages: [
|
|
1753
626
|
{
|
|
1754
|
-
|
|
1755
|
-
|
|
627
|
+
role: "user",
|
|
628
|
+
content: {
|
|
629
|
+
type: "text",
|
|
630
|
+
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
]
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
case "newOrderSingle": {
|
|
637
|
+
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
|
|
638
|
+
return {
|
|
639
|
+
messages: [
|
|
640
|
+
{
|
|
641
|
+
role: "user",
|
|
642
|
+
content: {
|
|
643
|
+
type: "text",
|
|
644
|
+
text: [
|
|
645
|
+
"Create a New Order Single FIX message with the following parameters:",
|
|
646
|
+
`- ClOrdID: ${clOrdID}`,
|
|
647
|
+
`- HandlInst: ${handlInst ?? "3"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Manual, '2' for Automated, '3' for AutomatedNoIntervention)`,
|
|
648
|
+
`- Quantity: ${quantity}`,
|
|
649
|
+
`- Price: ${price}`,
|
|
650
|
+
`- OrdType: ${ordType ?? "1"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Market, '2' for Limit, '3' for Stop)`,
|
|
651
|
+
`- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
|
|
652
|
+
`- Symbol: ${symbol}`,
|
|
653
|
+
`- TimeInForce: ${timeInForce ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Day, '1' for Good Till Cancel, '2' for At Opening, '3' for Immediate or Cancel, '4' for Fill or Kill, '5' for Good Till Crossing, '6' for Good Till Date)`,
|
|
654
|
+
"",
|
|
655
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
656
|
+
"",
|
|
657
|
+
'Note: For the Side parameter, always use the numeric/alphabetic value (e.g., "1" for Buy, "2" for Sell) as defined in the FIX protocol, not the descriptive name.',
|
|
658
|
+
'Note: For the HandlInst parameter, always use the numeric/alphabetic value (e.g., "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention) as defined in the FIX protocol, not the descriptive name.',
|
|
659
|
+
'Note: For the OrdType parameter, always use the numeric/alphabetic value (e.g., "1" for Market, "2" for Limit, "3" for Stop) as defined in the FIX protocol, not the descriptive name.',
|
|
660
|
+
'Note: For the TimeInForce parameter, always use the numeric/alphabetic value (e.g., "0" for Day, "1" for Good Till Cancel, "2" for At Opening) as defined in the FIX protocol, not the descriptive name.'
|
|
661
|
+
].join("\n")
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
]
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
case "marketDataRequest": {
|
|
668
|
+
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
669
|
+
return {
|
|
670
|
+
messages: [
|
|
671
|
+
{
|
|
672
|
+
role: "user",
|
|
673
|
+
content: {
|
|
674
|
+
type: "text",
|
|
675
|
+
text: [
|
|
676
|
+
"Create a Market Data Request FIX message with the following parameters:",
|
|
677
|
+
`- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
|
|
678
|
+
`- Symbol: ${symbol}`,
|
|
679
|
+
`- MDReqID: ${mdReqID}`,
|
|
680
|
+
`- SubscriptionRequestType: ${subscriptionRequestType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Snapshot + Updates, '1' for Snapshot, '2' for Unsubscribe)`,
|
|
681
|
+
`- MDEntryType: ${mdEntryType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Bid, '1' for Offer, '2' for Trade, '3' for Index Value, '4' for Opening Price)`,
|
|
682
|
+
"",
|
|
683
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
684
|
+
"",
|
|
685
|
+
'Note: For the MDUpdateType parameter, always use the numeric/alphabetic value (e.g., "0" for FullRefresh, "1" for IncrementalRefresh) as defined in the FIX protocol, not the descriptive name.',
|
|
686
|
+
'Note: For the SubscriptionRequestType parameter, always use the numeric/alphabetic value (e.g., "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe) as defined in the FIX protocol, not the descriptive name.',
|
|
687
|
+
'Note: For the MDEntryType parameter, always use the numeric/alphabetic value (e.g., "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price) as defined in the FIX protocol, not the descriptive name.'
|
|
688
|
+
].join("\n")
|
|
689
|
+
}
|
|
1756
690
|
}
|
|
1757
691
|
]
|
|
1758
692
|
};
|
|
1759
693
|
}
|
|
1760
694
|
default:
|
|
1761
|
-
throw new Error(`Unknown
|
|
695
|
+
throw new Error(`Unknown prompt: ${name}`);
|
|
1762
696
|
}
|
|
1763
697
|
});
|
|
1764
698
|
process.on("SIGINT", async () => {
|