@mastra/deployer 0.2.5 → 0.2.6-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.cts +61 -7
- package/dist/_tsup-dts-rollup.d.ts +61 -7
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +9 -9
- package/dist/build/index.js +2 -2
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-7GYBZLVN.cjs → chunk-2JXRI3DC.cjs} +3 -3
- package/dist/{chunk-OT6UKL2S.cjs → chunk-AE4CVAPK.cjs} +11 -0
- package/dist/{chunk-PUX2FDGX.js → chunk-C6LYG5EA.js} +1 -1
- package/dist/{chunk-KLVSED7T.js → chunk-DUK5PGPQ.js} +1 -1
- package/dist/{chunk-XEFBJH3T.js → chunk-IKPL4RGG.js} +11 -0
- package/dist/{chunk-NXBTVZHO.cjs → chunk-OE6LAGEI.cjs} +4 -4
- package/dist/index.cjs +5 -5
- package/dist/index.js +3 -3
- package/dist/server/index.cjs +390 -2583
- package/dist/server/index.js +379 -2572
- package/dist/templates/instrumentation-template.js +4 -19
- package/package.json +4 -3
package/dist/server/index.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
|
+
import crypto, { randomUUID } from 'crypto';
|
|
1
2
|
import { readFile } from 'fs/promises';
|
|
2
3
|
import { join } from 'path';
|
|
3
4
|
import { pathToFileURL } from 'url';
|
|
4
5
|
import { createServer } from 'http';
|
|
5
6
|
import { Http2ServerRequest } from 'http2';
|
|
6
7
|
import { Readable } from 'stream';
|
|
7
|
-
import crypto from 'crypto';
|
|
8
8
|
import { getFilePathWithoutDefaultDocument, getFilePath } from 'hono/utils/filepath';
|
|
9
9
|
import { getMimeType } from 'hono/utils/mime';
|
|
10
10
|
import { createReadStream, lstatSync } from 'fs';
|
|
11
11
|
import { html } from 'hono/html';
|
|
12
|
+
import { Telemetry } from '@mastra/core';
|
|
12
13
|
import { Hono } from 'hono';
|
|
13
14
|
import { bodyLimit } from 'hono/body-limit';
|
|
14
15
|
import { cors } from 'hono/cors';
|
|
15
16
|
import { logger } from 'hono/logger';
|
|
16
17
|
import { HTTPException } from 'hono/http-exception';
|
|
17
|
-
import {
|
|
18
|
+
import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$2, streamGenerateHandler as streamGenerateHandler$2 } from '@mastra/server/handlers/agents';
|
|
19
|
+
import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
|
|
20
|
+
import { getMemoryStatusHandler as getMemoryStatusHandler$1, getThreadsHandler as getThreadsHandler$1, getThreadByIdHandler as getThreadByIdHandler$1, getMessagesHandler as getMessagesHandler$1, createThreadHandler as createThreadHandler$1, updateThreadHandler as updateThreadHandler$1, deleteThreadHandler as deleteThreadHandler$1, saveMessagesHandler as saveMessagesHandler$1 } from '@mastra/server/handlers/memory';
|
|
21
|
+
import { getNetworksHandler as getNetworksHandler$1, getNetworkByIdHandler as getNetworkByIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1 } from '@mastra/server/handlers/network';
|
|
18
22
|
import { Agent } from '@mastra/core/agent';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
23
|
+
import { z } from 'zod';
|
|
24
|
+
import { getTelemetryHandler as getTelemetryHandler$1, storeTelemetryHandler as storeTelemetryHandler$1 } from '@mastra/server/handlers/telemetry';
|
|
25
|
+
import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
|
|
26
|
+
import { upsertVectors as upsertVectors$1, createIndex as createIndex$1, queryVectors as queryVectors$1, listIndexes as listIndexes$1, describeIndex as describeIndex$1, deleteIndex as deleteIndex$1 } from '@mastra/server/handlers/vector';
|
|
27
|
+
import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
|
|
28
|
+
import { getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, createRunHandler as createRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, watchWorkflowHandler as watchWorkflowHandler$1 } from '@mastra/server/handlers/workflows';
|
|
29
|
+
import { stream } from 'hono/streaming';
|
|
21
30
|
|
|
22
31
|
// src/server/index.ts
|
|
23
32
|
var RequestError = class extends Error {
|
|
@@ -155,14 +164,14 @@ var newRequest = (incoming, defaultHostname) => {
|
|
|
155
164
|
req[urlKey] = url.href;
|
|
156
165
|
return req;
|
|
157
166
|
};
|
|
158
|
-
function writeFromReadableStream(
|
|
159
|
-
if (
|
|
167
|
+
function writeFromReadableStream(stream2, writable) {
|
|
168
|
+
if (stream2.locked) {
|
|
160
169
|
throw new TypeError("ReadableStream is locked.");
|
|
161
170
|
} else if (writable.destroyed) {
|
|
162
|
-
|
|
171
|
+
stream2.cancel();
|
|
163
172
|
return;
|
|
164
173
|
}
|
|
165
|
-
const reader =
|
|
174
|
+
const reader = stream2.getReader();
|
|
166
175
|
writable.on("close", cancel);
|
|
167
176
|
writable.on("error", cancel);
|
|
168
177
|
reader.read().then(flow, cancel);
|
|
@@ -360,7 +369,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
360
369
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
361
370
|
const internalBody = getInternalBody(res);
|
|
362
371
|
if (internalBody) {
|
|
363
|
-
const { length, source, stream } = internalBody;
|
|
372
|
+
const { length, source, stream: stream2 } = internalBody;
|
|
364
373
|
if (source instanceof Uint8Array && source.byteLength !== length) ; else {
|
|
365
374
|
if (length) {
|
|
366
375
|
resHeaderRecord["content-length"] = length;
|
|
@@ -371,7 +380,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
371
380
|
} else if (source instanceof Blob) {
|
|
372
381
|
outgoing.end(new Uint8Array(await source.arrayBuffer()));
|
|
373
382
|
} else {
|
|
374
|
-
await writeFromReadableStream(
|
|
383
|
+
await writeFromReadableStream(stream2, outgoing);
|
|
375
384
|
}
|
|
376
385
|
return;
|
|
377
386
|
}
|
|
@@ -475,18 +484,18 @@ var ENCODINGS = {
|
|
|
475
484
|
gzip: ".gz"
|
|
476
485
|
};
|
|
477
486
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
478
|
-
var createStreamBody = (
|
|
487
|
+
var createStreamBody = (stream2) => {
|
|
479
488
|
const body = new ReadableStream({
|
|
480
489
|
start(controller) {
|
|
481
|
-
|
|
490
|
+
stream2.on("data", (chunk) => {
|
|
482
491
|
controller.enqueue(chunk);
|
|
483
492
|
});
|
|
484
|
-
|
|
493
|
+
stream2.on("end", () => {
|
|
485
494
|
controller.close();
|
|
486
495
|
});
|
|
487
496
|
},
|
|
488
497
|
cancel() {
|
|
489
|
-
|
|
498
|
+
stream2.destroy();
|
|
490
499
|
}
|
|
491
500
|
});
|
|
492
501
|
return body;
|
|
@@ -582,10 +591,10 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
582
591
|
end = size - 1;
|
|
583
592
|
}
|
|
584
593
|
const chunksize = end - start + 1;
|
|
585
|
-
const
|
|
594
|
+
const stream2 = createReadStream(path, { start, end });
|
|
586
595
|
c2.header("Content-Length", chunksize.toString());
|
|
587
596
|
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
588
|
-
return c2.body(createStreamBody(
|
|
597
|
+
return c2.body(createStreamBody(stream2), 206);
|
|
589
598
|
};
|
|
590
599
|
};
|
|
591
600
|
var RENDER_TYPE = {
|
|
@@ -832,2006 +841,7 @@ async function x(e2, t2, s3 = {}) {
|
|
|
832
841
|
}
|
|
833
842
|
return { docs: o2, components: n2 };
|
|
834
843
|
}
|
|
835
|
-
|
|
836
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/double-indexed-kv.js
|
|
837
|
-
var DoubleIndexedKV = class {
|
|
838
|
-
constructor() {
|
|
839
|
-
this.keyToValue = /* @__PURE__ */ new Map();
|
|
840
|
-
this.valueToKey = /* @__PURE__ */ new Map();
|
|
841
|
-
}
|
|
842
|
-
set(key, value) {
|
|
843
|
-
this.keyToValue.set(key, value);
|
|
844
|
-
this.valueToKey.set(value, key);
|
|
845
|
-
}
|
|
846
|
-
getByKey(key) {
|
|
847
|
-
return this.keyToValue.get(key);
|
|
848
|
-
}
|
|
849
|
-
getByValue(value) {
|
|
850
|
-
return this.valueToKey.get(value);
|
|
851
|
-
}
|
|
852
|
-
clear() {
|
|
853
|
-
this.keyToValue.clear();
|
|
854
|
-
this.valueToKey.clear();
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/registry.js
|
|
859
|
-
var Registry = class {
|
|
860
|
-
constructor(generateIdentifier) {
|
|
861
|
-
this.generateIdentifier = generateIdentifier;
|
|
862
|
-
this.kv = new DoubleIndexedKV();
|
|
863
|
-
}
|
|
864
|
-
register(value, identifier) {
|
|
865
|
-
if (this.kv.getByValue(value)) {
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
if (!identifier) {
|
|
869
|
-
identifier = this.generateIdentifier(value);
|
|
870
|
-
}
|
|
871
|
-
this.kv.set(identifier, value);
|
|
872
|
-
}
|
|
873
|
-
clear() {
|
|
874
|
-
this.kv.clear();
|
|
875
|
-
}
|
|
876
|
-
getIdentifier(value) {
|
|
877
|
-
return this.kv.getByValue(value);
|
|
878
|
-
}
|
|
879
|
-
getValue(identifier) {
|
|
880
|
-
return this.kv.getByKey(identifier);
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/class-registry.js
|
|
885
|
-
var ClassRegistry = class extends Registry {
|
|
886
|
-
constructor() {
|
|
887
|
-
super((c2) => c2.name);
|
|
888
|
-
this.classToAllowedProps = /* @__PURE__ */ new Map();
|
|
889
|
-
}
|
|
890
|
-
register(value, options) {
|
|
891
|
-
if (typeof options === "object") {
|
|
892
|
-
if (options.allowProps) {
|
|
893
|
-
this.classToAllowedProps.set(value, options.allowProps);
|
|
894
|
-
}
|
|
895
|
-
super.register(value, options.identifier);
|
|
896
|
-
} else {
|
|
897
|
-
super.register(value, options);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
getAllowedProps(value) {
|
|
901
|
-
return this.classToAllowedProps.get(value);
|
|
902
|
-
}
|
|
903
|
-
};
|
|
904
|
-
|
|
905
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/util.js
|
|
906
|
-
function valuesOfObj(record) {
|
|
907
|
-
if ("values" in Object) {
|
|
908
|
-
return Object.values(record);
|
|
909
|
-
}
|
|
910
|
-
const values = [];
|
|
911
|
-
for (const key in record) {
|
|
912
|
-
if (record.hasOwnProperty(key)) {
|
|
913
|
-
values.push(record[key]);
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
return values;
|
|
917
|
-
}
|
|
918
|
-
function find(record, predicate) {
|
|
919
|
-
const values = valuesOfObj(record);
|
|
920
|
-
if ("find" in values) {
|
|
921
|
-
return values.find(predicate);
|
|
922
|
-
}
|
|
923
|
-
const valuesNotNever = values;
|
|
924
|
-
for (let i2 = 0; i2 < valuesNotNever.length; i2++) {
|
|
925
|
-
const value = valuesNotNever[i2];
|
|
926
|
-
if (predicate(value)) {
|
|
927
|
-
return value;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
return void 0;
|
|
931
|
-
}
|
|
932
|
-
function forEach(record, run) {
|
|
933
|
-
Object.entries(record).forEach(([key, value]) => run(value, key));
|
|
934
|
-
}
|
|
935
|
-
function includes(arr, value) {
|
|
936
|
-
return arr.indexOf(value) !== -1;
|
|
937
|
-
}
|
|
938
|
-
function findArr(record, predicate) {
|
|
939
|
-
for (let i2 = 0; i2 < record.length; i2++) {
|
|
940
|
-
const value = record[i2];
|
|
941
|
-
if (predicate(value)) {
|
|
942
|
-
return value;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
return void 0;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/custom-transformer-registry.js
|
|
949
|
-
var CustomTransformerRegistry = class {
|
|
950
|
-
constructor() {
|
|
951
|
-
this.transfomers = {};
|
|
952
|
-
}
|
|
953
|
-
register(transformer) {
|
|
954
|
-
this.transfomers[transformer.name] = transformer;
|
|
955
|
-
}
|
|
956
|
-
findApplicable(v) {
|
|
957
|
-
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
|
958
|
-
}
|
|
959
|
-
findByName(name) {
|
|
960
|
-
return this.transfomers[name];
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/is.js
|
|
965
|
-
var getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
|
966
|
-
var isUndefined = (payload) => typeof payload === "undefined";
|
|
967
|
-
var isNull = (payload) => payload === null;
|
|
968
|
-
var isPlainObject = (payload) => {
|
|
969
|
-
if (typeof payload !== "object" || payload === null)
|
|
970
|
-
return false;
|
|
971
|
-
if (payload === Object.prototype)
|
|
972
|
-
return false;
|
|
973
|
-
if (Object.getPrototypeOf(payload) === null)
|
|
974
|
-
return true;
|
|
975
|
-
return Object.getPrototypeOf(payload) === Object.prototype;
|
|
976
|
-
};
|
|
977
|
-
var isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0;
|
|
978
|
-
var isArray = (payload) => Array.isArray(payload);
|
|
979
|
-
var isString = (payload) => typeof payload === "string";
|
|
980
|
-
var isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
|
981
|
-
var isBoolean = (payload) => typeof payload === "boolean";
|
|
982
|
-
var isRegExp = (payload) => payload instanceof RegExp;
|
|
983
|
-
var isMap = (payload) => payload instanceof Map;
|
|
984
|
-
var isSet = (payload) => payload instanceof Set;
|
|
985
|
-
var isSymbol = (payload) => getType(payload) === "Symbol";
|
|
986
|
-
var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
|
987
|
-
var isError = (payload) => payload instanceof Error;
|
|
988
|
-
var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
|
989
|
-
var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
|
990
|
-
var isBigint = (payload) => typeof payload === "bigint";
|
|
991
|
-
var isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
|
992
|
-
var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
|
993
|
-
var isURL = (payload) => payload instanceof URL;
|
|
994
|
-
|
|
995
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
|
996
|
-
var escapeKey = (key) => key.replace(/\./g, "\\.");
|
|
997
|
-
var stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
|
998
|
-
var parsePath = (string) => {
|
|
999
|
-
const result = [];
|
|
1000
|
-
let segment = "";
|
|
1001
|
-
for (let i2 = 0; i2 < string.length; i2++) {
|
|
1002
|
-
let char = string.charAt(i2);
|
|
1003
|
-
const isEscapedDot = char === "\\" && string.charAt(i2 + 1) === ".";
|
|
1004
|
-
if (isEscapedDot) {
|
|
1005
|
-
segment += ".";
|
|
1006
|
-
i2++;
|
|
1007
|
-
continue;
|
|
1008
|
-
}
|
|
1009
|
-
const isEndOfSegment = char === ".";
|
|
1010
|
-
if (isEndOfSegment) {
|
|
1011
|
-
result.push(segment);
|
|
1012
|
-
segment = "";
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
segment += char;
|
|
1016
|
-
}
|
|
1017
|
-
const lastSegment = segment;
|
|
1018
|
-
result.push(lastSegment);
|
|
1019
|
-
return result;
|
|
1020
|
-
};
|
|
1021
|
-
|
|
1022
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/transformer.js
|
|
1023
|
-
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
|
1024
|
-
return {
|
|
1025
|
-
isApplicable,
|
|
1026
|
-
annotation,
|
|
1027
|
-
transform,
|
|
1028
|
-
untransform
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
var simpleRules = [
|
|
1032
|
-
simpleTransformation(isUndefined, "undefined", () => null, () => void 0),
|
|
1033
|
-
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
|
1034
|
-
if (typeof BigInt !== "undefined") {
|
|
1035
|
-
return BigInt(v);
|
|
1036
|
-
}
|
|
1037
|
-
console.error("Please add a BigInt polyfill.");
|
|
1038
|
-
return v;
|
|
1039
|
-
}),
|
|
1040
|
-
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
|
1041
|
-
simpleTransformation(isError, "Error", (v, superJson) => {
|
|
1042
|
-
const baseError = {
|
|
1043
|
-
name: v.name,
|
|
1044
|
-
message: v.message
|
|
1045
|
-
};
|
|
1046
|
-
superJson.allowedErrorProps.forEach((prop) => {
|
|
1047
|
-
baseError[prop] = v[prop];
|
|
1048
|
-
});
|
|
1049
|
-
return baseError;
|
|
1050
|
-
}, (v, superJson) => {
|
|
1051
|
-
const e2 = new Error(v.message);
|
|
1052
|
-
e2.name = v.name;
|
|
1053
|
-
e2.stack = v.stack;
|
|
1054
|
-
superJson.allowedErrorProps.forEach((prop) => {
|
|
1055
|
-
e2[prop] = v[prop];
|
|
1056
|
-
});
|
|
1057
|
-
return e2;
|
|
1058
|
-
}),
|
|
1059
|
-
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
|
1060
|
-
const body = regex.slice(1, regex.lastIndexOf("/"));
|
|
1061
|
-
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
|
1062
|
-
return new RegExp(body, flags);
|
|
1063
|
-
}),
|
|
1064
|
-
simpleTransformation(
|
|
1065
|
-
isSet,
|
|
1066
|
-
"set",
|
|
1067
|
-
// (sets only exist in es6+)
|
|
1068
|
-
// eslint-disable-next-line es5/no-es6-methods
|
|
1069
|
-
(v) => [...v.values()],
|
|
1070
|
-
(v) => new Set(v)
|
|
1071
|
-
),
|
|
1072
|
-
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
|
1073
|
-
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
|
1074
|
-
if (isNaNValue(v)) {
|
|
1075
|
-
return "NaN";
|
|
1076
|
-
}
|
|
1077
|
-
if (v > 0) {
|
|
1078
|
-
return "Infinity";
|
|
1079
|
-
} else {
|
|
1080
|
-
return "-Infinity";
|
|
1081
|
-
}
|
|
1082
|
-
}, Number),
|
|
1083
|
-
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
|
1084
|
-
return "-0";
|
|
1085
|
-
}, Number),
|
|
1086
|
-
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
|
1087
|
-
];
|
|
1088
|
-
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
|
1089
|
-
return {
|
|
1090
|
-
isApplicable,
|
|
1091
|
-
annotation,
|
|
1092
|
-
transform,
|
|
1093
|
-
untransform
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
var symbolRule = compositeTransformation((s3, superJson) => {
|
|
1097
|
-
if (isSymbol(s3)) {
|
|
1098
|
-
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s3);
|
|
1099
|
-
return isRegistered;
|
|
1100
|
-
}
|
|
1101
|
-
return false;
|
|
1102
|
-
}, (s3, superJson) => {
|
|
1103
|
-
const identifier = superJson.symbolRegistry.getIdentifier(s3);
|
|
1104
|
-
return ["symbol", identifier];
|
|
1105
|
-
}, (v) => v.description, (_, a2, superJson) => {
|
|
1106
|
-
const value = superJson.symbolRegistry.getValue(a2[1]);
|
|
1107
|
-
if (!value) {
|
|
1108
|
-
throw new Error("Trying to deserialize unknown symbol");
|
|
1109
|
-
}
|
|
1110
|
-
return value;
|
|
1111
|
-
});
|
|
1112
|
-
var constructorToName = [
|
|
1113
|
-
Int8Array,
|
|
1114
|
-
Uint8Array,
|
|
1115
|
-
Int16Array,
|
|
1116
|
-
Uint16Array,
|
|
1117
|
-
Int32Array,
|
|
1118
|
-
Uint32Array,
|
|
1119
|
-
Float32Array,
|
|
1120
|
-
Float64Array,
|
|
1121
|
-
Uint8ClampedArray
|
|
1122
|
-
].reduce((obj, ctor) => {
|
|
1123
|
-
obj[ctor.name] = ctor;
|
|
1124
|
-
return obj;
|
|
1125
|
-
}, {});
|
|
1126
|
-
var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a2) => {
|
|
1127
|
-
const ctor = constructorToName[a2[1]];
|
|
1128
|
-
if (!ctor) {
|
|
1129
|
-
throw new Error("Trying to deserialize unknown typed array");
|
|
1130
|
-
}
|
|
1131
|
-
return new ctor(v);
|
|
1132
|
-
});
|
|
1133
|
-
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
|
1134
|
-
if (potentialClass?.constructor) {
|
|
1135
|
-
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
|
1136
|
-
return isRegistered;
|
|
1137
|
-
}
|
|
1138
|
-
return false;
|
|
1139
|
-
}
|
|
1140
|
-
var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
|
1141
|
-
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
|
1142
|
-
return ["class", identifier];
|
|
1143
|
-
}, (clazz, superJson) => {
|
|
1144
|
-
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
|
1145
|
-
if (!allowedProps) {
|
|
1146
|
-
return { ...clazz };
|
|
1147
|
-
}
|
|
1148
|
-
const result = {};
|
|
1149
|
-
allowedProps.forEach((prop) => {
|
|
1150
|
-
result[prop] = clazz[prop];
|
|
1151
|
-
});
|
|
1152
|
-
return result;
|
|
1153
|
-
}, (v, a2, superJson) => {
|
|
1154
|
-
const clazz = superJson.classRegistry.getValue(a2[1]);
|
|
1155
|
-
if (!clazz) {
|
|
1156
|
-
throw new Error(`Trying to deserialize unknown class '${a2[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
|
1157
|
-
}
|
|
1158
|
-
return Object.assign(Object.create(clazz.prototype), v);
|
|
1159
|
-
});
|
|
1160
|
-
var customRule = compositeTransformation((value, superJson) => {
|
|
1161
|
-
return !!superJson.customTransformerRegistry.findApplicable(value);
|
|
1162
|
-
}, (value, superJson) => {
|
|
1163
|
-
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
1164
|
-
return ["custom", transformer.name];
|
|
1165
|
-
}, (value, superJson) => {
|
|
1166
|
-
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
1167
|
-
return transformer.serialize(value);
|
|
1168
|
-
}, (v, a2, superJson) => {
|
|
1169
|
-
const transformer = superJson.customTransformerRegistry.findByName(a2[1]);
|
|
1170
|
-
if (!transformer) {
|
|
1171
|
-
throw new Error("Trying to deserialize unknown custom value");
|
|
1172
|
-
}
|
|
1173
|
-
return transformer.deserialize(v);
|
|
1174
|
-
});
|
|
1175
|
-
var compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
|
1176
|
-
var transformValue = (value, superJson) => {
|
|
1177
|
-
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
|
1178
|
-
if (applicableCompositeRule) {
|
|
1179
|
-
return {
|
|
1180
|
-
value: applicableCompositeRule.transform(value, superJson),
|
|
1181
|
-
type: applicableCompositeRule.annotation(value, superJson)
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
|
1185
|
-
if (applicableSimpleRule) {
|
|
1186
|
-
return {
|
|
1187
|
-
value: applicableSimpleRule.transform(value, superJson),
|
|
1188
|
-
type: applicableSimpleRule.annotation
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
return void 0;
|
|
1192
|
-
};
|
|
1193
|
-
var simpleRulesByAnnotation = {};
|
|
1194
|
-
simpleRules.forEach((rule) => {
|
|
1195
|
-
simpleRulesByAnnotation[rule.annotation] = rule;
|
|
1196
|
-
});
|
|
1197
|
-
var untransformValue = (json, type, superJson) => {
|
|
1198
|
-
if (isArray(type)) {
|
|
1199
|
-
switch (type[0]) {
|
|
1200
|
-
case "symbol":
|
|
1201
|
-
return symbolRule.untransform(json, type, superJson);
|
|
1202
|
-
case "class":
|
|
1203
|
-
return classRule.untransform(json, type, superJson);
|
|
1204
|
-
case "custom":
|
|
1205
|
-
return customRule.untransform(json, type, superJson);
|
|
1206
|
-
case "typed-array":
|
|
1207
|
-
return typedArrayRule.untransform(json, type, superJson);
|
|
1208
|
-
default:
|
|
1209
|
-
throw new Error("Unknown transformation: " + type);
|
|
1210
|
-
}
|
|
1211
|
-
} else {
|
|
1212
|
-
const transformation = simpleRulesByAnnotation[type];
|
|
1213
|
-
if (!transformation) {
|
|
1214
|
-
throw new Error("Unknown transformation: " + type);
|
|
1215
|
-
}
|
|
1216
|
-
return transformation.untransform(json, superJson);
|
|
1217
|
-
}
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/accessDeep.js
|
|
1221
|
-
var getNthKey = (value, n2) => {
|
|
1222
|
-
if (n2 > value.size)
|
|
1223
|
-
throw new Error("index out of bounds");
|
|
1224
|
-
const keys = value.keys();
|
|
1225
|
-
while (n2 > 0) {
|
|
1226
|
-
keys.next();
|
|
1227
|
-
n2--;
|
|
1228
|
-
}
|
|
1229
|
-
return keys.next().value;
|
|
1230
|
-
};
|
|
1231
|
-
function validatePath(path) {
|
|
1232
|
-
if (includes(path, "__proto__")) {
|
|
1233
|
-
throw new Error("__proto__ is not allowed as a property");
|
|
1234
|
-
}
|
|
1235
|
-
if (includes(path, "prototype")) {
|
|
1236
|
-
throw new Error("prototype is not allowed as a property");
|
|
1237
|
-
}
|
|
1238
|
-
if (includes(path, "constructor")) {
|
|
1239
|
-
throw new Error("constructor is not allowed as a property");
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
var getDeep = (object, path) => {
|
|
1243
|
-
validatePath(path);
|
|
1244
|
-
for (let i2 = 0; i2 < path.length; i2++) {
|
|
1245
|
-
const key = path[i2];
|
|
1246
|
-
if (isSet(object)) {
|
|
1247
|
-
object = getNthKey(object, +key);
|
|
1248
|
-
} else if (isMap(object)) {
|
|
1249
|
-
const row = +key;
|
|
1250
|
-
const type = +path[++i2] === 0 ? "key" : "value";
|
|
1251
|
-
const keyOfRow = getNthKey(object, row);
|
|
1252
|
-
switch (type) {
|
|
1253
|
-
case "key":
|
|
1254
|
-
object = keyOfRow;
|
|
1255
|
-
break;
|
|
1256
|
-
case "value":
|
|
1257
|
-
object = object.get(keyOfRow);
|
|
1258
|
-
break;
|
|
1259
|
-
}
|
|
1260
|
-
} else {
|
|
1261
|
-
object = object[key];
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
return object;
|
|
1265
|
-
};
|
|
1266
|
-
var setDeep = (object, path, mapper) => {
|
|
1267
|
-
validatePath(path);
|
|
1268
|
-
if (path.length === 0) {
|
|
1269
|
-
return mapper(object);
|
|
1270
|
-
}
|
|
1271
|
-
let parent = object;
|
|
1272
|
-
for (let i2 = 0; i2 < path.length - 1; i2++) {
|
|
1273
|
-
const key = path[i2];
|
|
1274
|
-
if (isArray(parent)) {
|
|
1275
|
-
const index = +key;
|
|
1276
|
-
parent = parent[index];
|
|
1277
|
-
} else if (isPlainObject(parent)) {
|
|
1278
|
-
parent = parent[key];
|
|
1279
|
-
} else if (isSet(parent)) {
|
|
1280
|
-
const row = +key;
|
|
1281
|
-
parent = getNthKey(parent, row);
|
|
1282
|
-
} else if (isMap(parent)) {
|
|
1283
|
-
const isEnd = i2 === path.length - 2;
|
|
1284
|
-
if (isEnd) {
|
|
1285
|
-
break;
|
|
1286
|
-
}
|
|
1287
|
-
const row = +key;
|
|
1288
|
-
const type = +path[++i2] === 0 ? "key" : "value";
|
|
1289
|
-
const keyOfRow = getNthKey(parent, row);
|
|
1290
|
-
switch (type) {
|
|
1291
|
-
case "key":
|
|
1292
|
-
parent = keyOfRow;
|
|
1293
|
-
break;
|
|
1294
|
-
case "value":
|
|
1295
|
-
parent = parent.get(keyOfRow);
|
|
1296
|
-
break;
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
const lastKey = path[path.length - 1];
|
|
1301
|
-
if (isArray(parent)) {
|
|
1302
|
-
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
1303
|
-
} else if (isPlainObject(parent)) {
|
|
1304
|
-
parent[lastKey] = mapper(parent[lastKey]);
|
|
1305
|
-
}
|
|
1306
|
-
if (isSet(parent)) {
|
|
1307
|
-
const oldValue = getNthKey(parent, +lastKey);
|
|
1308
|
-
const newValue = mapper(oldValue);
|
|
1309
|
-
if (oldValue !== newValue) {
|
|
1310
|
-
parent.delete(oldValue);
|
|
1311
|
-
parent.add(newValue);
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
if (isMap(parent)) {
|
|
1315
|
-
const row = +path[path.length - 2];
|
|
1316
|
-
const keyToRow = getNthKey(parent, row);
|
|
1317
|
-
const type = +lastKey === 0 ? "key" : "value";
|
|
1318
|
-
switch (type) {
|
|
1319
|
-
case "key": {
|
|
1320
|
-
const newKey = mapper(keyToRow);
|
|
1321
|
-
parent.set(newKey, parent.get(keyToRow));
|
|
1322
|
-
if (newKey !== keyToRow) {
|
|
1323
|
-
parent.delete(keyToRow);
|
|
1324
|
-
}
|
|
1325
|
-
break;
|
|
1326
|
-
}
|
|
1327
|
-
case "value": {
|
|
1328
|
-
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
|
1329
|
-
break;
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
return object;
|
|
1334
|
-
};
|
|
1335
|
-
|
|
1336
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/plainer.js
|
|
1337
|
-
function traverse(tree, walker2, origin = []) {
|
|
1338
|
-
if (!tree) {
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
if (!isArray(tree)) {
|
|
1342
|
-
forEach(tree, (subtree, key) => traverse(subtree, walker2, [...origin, ...parsePath(key)]));
|
|
1343
|
-
return;
|
|
1344
|
-
}
|
|
1345
|
-
const [nodeValue, children] = tree;
|
|
1346
|
-
if (children) {
|
|
1347
|
-
forEach(children, (child, key) => {
|
|
1348
|
-
traverse(child, walker2, [...origin, ...parsePath(key)]);
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
walker2(nodeValue, origin);
|
|
1352
|
-
}
|
|
1353
|
-
function applyValueAnnotations(plain, annotations, superJson) {
|
|
1354
|
-
traverse(annotations, (type, path) => {
|
|
1355
|
-
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
|
1356
|
-
});
|
|
1357
|
-
return plain;
|
|
1358
|
-
}
|
|
1359
|
-
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
1360
|
-
function apply(identicalPaths, path) {
|
|
1361
|
-
const object = getDeep(plain, parsePath(path));
|
|
1362
|
-
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
1363
|
-
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
if (isArray(annotations)) {
|
|
1367
|
-
const [root, other] = annotations;
|
|
1368
|
-
root.forEach((identicalPath) => {
|
|
1369
|
-
plain = setDeep(plain, parsePath(identicalPath), () => plain);
|
|
1370
|
-
});
|
|
1371
|
-
if (other) {
|
|
1372
|
-
forEach(other, apply);
|
|
1373
|
-
}
|
|
1374
|
-
} else {
|
|
1375
|
-
forEach(annotations, apply);
|
|
1376
|
-
}
|
|
1377
|
-
return plain;
|
|
1378
|
-
}
|
|
1379
|
-
var isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson);
|
|
1380
|
-
function addIdentity(object, path, identities) {
|
|
1381
|
-
const existingSet = identities.get(object);
|
|
1382
|
-
if (existingSet) {
|
|
1383
|
-
existingSet.push(path);
|
|
1384
|
-
} else {
|
|
1385
|
-
identities.set(object, [path]);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
1389
|
-
const result = {};
|
|
1390
|
-
let rootEqualityPaths = void 0;
|
|
1391
|
-
identitites.forEach((paths) => {
|
|
1392
|
-
if (paths.length <= 1) {
|
|
1393
|
-
return;
|
|
1394
|
-
}
|
|
1395
|
-
if (!dedupe) {
|
|
1396
|
-
paths = paths.map((path) => path.map(String)).sort((a2, b) => a2.length - b.length);
|
|
1397
|
-
}
|
|
1398
|
-
const [representativePath, ...identicalPaths] = paths;
|
|
1399
|
-
if (representativePath.length === 0) {
|
|
1400
|
-
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
|
1401
|
-
} else {
|
|
1402
|
-
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
if (rootEqualityPaths) {
|
|
1406
|
-
if (isEmptyObject(result)) {
|
|
1407
|
-
return [rootEqualityPaths];
|
|
1408
|
-
} else {
|
|
1409
|
-
return [rootEqualityPaths, result];
|
|
1410
|
-
}
|
|
1411
|
-
} else {
|
|
1412
|
-
return isEmptyObject(result) ? void 0 : result;
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
1416
|
-
const primitive = isPrimitive(object);
|
|
1417
|
-
if (!primitive) {
|
|
1418
|
-
addIdentity(object, path, identities);
|
|
1419
|
-
const seen = seenObjects.get(object);
|
|
1420
|
-
if (seen) {
|
|
1421
|
-
return dedupe ? {
|
|
1422
|
-
transformedValue: null
|
|
1423
|
-
} : seen;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (!isDeep(object, superJson)) {
|
|
1427
|
-
const transformed2 = transformValue(object, superJson);
|
|
1428
|
-
const result2 = transformed2 ? {
|
|
1429
|
-
transformedValue: transformed2.value,
|
|
1430
|
-
annotations: [transformed2.type]
|
|
1431
|
-
} : {
|
|
1432
|
-
transformedValue: object
|
|
1433
|
-
};
|
|
1434
|
-
if (!primitive) {
|
|
1435
|
-
seenObjects.set(object, result2);
|
|
1436
|
-
}
|
|
1437
|
-
return result2;
|
|
1438
|
-
}
|
|
1439
|
-
if (includes(objectsInThisPath, object)) {
|
|
1440
|
-
return {
|
|
1441
|
-
transformedValue: null
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
|
-
const transformationResult = transformValue(object, superJson);
|
|
1445
|
-
const transformed = transformationResult?.value ?? object;
|
|
1446
|
-
const transformedValue = isArray(transformed) ? [] : {};
|
|
1447
|
-
const innerAnnotations = {};
|
|
1448
|
-
forEach(transformed, (value, index) => {
|
|
1449
|
-
if (index === "__proto__" || index === "constructor" || index === "prototype") {
|
|
1450
|
-
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
1451
|
-
}
|
|
1452
|
-
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
|
1453
|
-
transformedValue[index] = recursiveResult.transformedValue;
|
|
1454
|
-
if (isArray(recursiveResult.annotations)) {
|
|
1455
|
-
innerAnnotations[index] = recursiveResult.annotations;
|
|
1456
|
-
} else if (isPlainObject(recursiveResult.annotations)) {
|
|
1457
|
-
forEach(recursiveResult.annotations, (tree, key) => {
|
|
1458
|
-
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
});
|
|
1462
|
-
const result = isEmptyObject(innerAnnotations) ? {
|
|
1463
|
-
transformedValue,
|
|
1464
|
-
annotations: !!transformationResult ? [transformationResult.type] : void 0
|
|
1465
|
-
} : {
|
|
1466
|
-
transformedValue,
|
|
1467
|
-
annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
|
1468
|
-
};
|
|
1469
|
-
if (!primitive) {
|
|
1470
|
-
seenObjects.set(object, result);
|
|
1471
|
-
}
|
|
1472
|
-
return result;
|
|
1473
|
-
};
|
|
1474
|
-
|
|
1475
|
-
// ../../node_modules/.pnpm/is-what@4.1.16/node_modules/is-what/dist/index.js
|
|
1476
|
-
function getType2(payload) {
|
|
1477
|
-
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
1478
|
-
}
|
|
1479
|
-
function isArray2(payload) {
|
|
1480
|
-
return getType2(payload) === "Array";
|
|
1481
|
-
}
|
|
1482
|
-
function isPlainObject2(payload) {
|
|
1483
|
-
if (getType2(payload) !== "Object")
|
|
1484
|
-
return false;
|
|
1485
|
-
const prototype = Object.getPrototypeOf(payload);
|
|
1486
|
-
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
// ../../node_modules/.pnpm/copy-anything@3.0.5/node_modules/copy-anything/dist/index.js
|
|
1490
|
-
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
1491
|
-
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
1492
|
-
if (propType === "enumerable")
|
|
1493
|
-
carry[key] = newVal;
|
|
1494
|
-
if (includeNonenumerable && propType === "nonenumerable") {
|
|
1495
|
-
Object.defineProperty(carry, key, {
|
|
1496
|
-
value: newVal,
|
|
1497
|
-
enumerable: false,
|
|
1498
|
-
writable: true,
|
|
1499
|
-
configurable: true
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
function copy(target, options = {}) {
|
|
1504
|
-
if (isArray2(target)) {
|
|
1505
|
-
return target.map((item) => copy(item, options));
|
|
1506
|
-
}
|
|
1507
|
-
if (!isPlainObject2(target)) {
|
|
1508
|
-
return target;
|
|
1509
|
-
}
|
|
1510
|
-
const props = Object.getOwnPropertyNames(target);
|
|
1511
|
-
const symbols = Object.getOwnPropertySymbols(target);
|
|
1512
|
-
return [...props, ...symbols].reduce((carry, key) => {
|
|
1513
|
-
if (isArray2(options.props) && !options.props.includes(key)) {
|
|
1514
|
-
return carry;
|
|
1515
|
-
}
|
|
1516
|
-
const val = target[key];
|
|
1517
|
-
const newVal = copy(val, options);
|
|
1518
|
-
assignProp(carry, key, newVal, target, options.nonenumerable);
|
|
1519
|
-
return carry;
|
|
1520
|
-
}, {});
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/index.js
|
|
1524
|
-
var SuperJSON = class {
|
|
1525
|
-
/**
|
|
1526
|
-
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
|
1527
|
-
*/
|
|
1528
|
-
constructor({ dedupe = false } = {}) {
|
|
1529
|
-
this.classRegistry = new ClassRegistry();
|
|
1530
|
-
this.symbolRegistry = new Registry((s3) => s3.description ?? "");
|
|
1531
|
-
this.customTransformerRegistry = new CustomTransformerRegistry();
|
|
1532
|
-
this.allowedErrorProps = [];
|
|
1533
|
-
this.dedupe = dedupe;
|
|
1534
|
-
}
|
|
1535
|
-
serialize(object) {
|
|
1536
|
-
const identities = /* @__PURE__ */ new Map();
|
|
1537
|
-
const output = walker(object, identities, this, this.dedupe);
|
|
1538
|
-
const res = {
|
|
1539
|
-
json: output.transformedValue
|
|
1540
|
-
};
|
|
1541
|
-
if (output.annotations) {
|
|
1542
|
-
res.meta = {
|
|
1543
|
-
...res.meta,
|
|
1544
|
-
values: output.annotations
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
|
1548
|
-
if (equalityAnnotations) {
|
|
1549
|
-
res.meta = {
|
|
1550
|
-
...res.meta,
|
|
1551
|
-
referentialEqualities: equalityAnnotations
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
return res;
|
|
1555
|
-
}
|
|
1556
|
-
deserialize(payload) {
|
|
1557
|
-
const { json, meta } = payload;
|
|
1558
|
-
let result = copy(json);
|
|
1559
|
-
if (meta?.values) {
|
|
1560
|
-
result = applyValueAnnotations(result, meta.values, this);
|
|
1561
|
-
}
|
|
1562
|
-
if (meta?.referentialEqualities) {
|
|
1563
|
-
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities);
|
|
1564
|
-
}
|
|
1565
|
-
return result;
|
|
1566
|
-
}
|
|
1567
|
-
stringify(object) {
|
|
1568
|
-
return JSON.stringify(this.serialize(object));
|
|
1569
|
-
}
|
|
1570
|
-
parse(string) {
|
|
1571
|
-
return this.deserialize(JSON.parse(string));
|
|
1572
|
-
}
|
|
1573
|
-
registerClass(v, options) {
|
|
1574
|
-
this.classRegistry.register(v, options);
|
|
1575
|
-
}
|
|
1576
|
-
registerSymbol(v, identifier) {
|
|
1577
|
-
this.symbolRegistry.register(v, identifier);
|
|
1578
|
-
}
|
|
1579
|
-
registerCustom(transformer, name) {
|
|
1580
|
-
this.customTransformerRegistry.register({
|
|
1581
|
-
name,
|
|
1582
|
-
...transformer
|
|
1583
|
-
});
|
|
1584
|
-
}
|
|
1585
|
-
allowErrorProps(...props) {
|
|
1586
|
-
this.allowedErrorProps.push(...props);
|
|
1587
|
-
}
|
|
1588
|
-
};
|
|
1589
|
-
SuperJSON.defaultInstance = new SuperJSON();
|
|
1590
|
-
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
|
1591
|
-
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
|
1592
|
-
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
|
1593
|
-
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
|
1594
|
-
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
|
1595
|
-
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
|
1596
|
-
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
|
1597
|
-
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
1598
|
-
var stringify = SuperJSON.stringify;
|
|
1599
|
-
|
|
1600
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
1601
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
1602
|
-
var defaultOptions = {
|
|
1603
|
-
name: void 0,
|
|
1604
|
-
$refStrategy: "root",
|
|
1605
|
-
basePath: ["#"],
|
|
1606
|
-
effectStrategy: "input",
|
|
1607
|
-
pipeStrategy: "all",
|
|
1608
|
-
dateStrategy: "format:date-time",
|
|
1609
|
-
mapStrategy: "entries",
|
|
1610
|
-
removeAdditionalStrategy: "passthrough",
|
|
1611
|
-
allowedAdditionalProperties: true,
|
|
1612
|
-
rejectedAdditionalProperties: false,
|
|
1613
|
-
definitionPath: "definitions",
|
|
1614
|
-
target: "jsonSchema7",
|
|
1615
|
-
strictUnions: false,
|
|
1616
|
-
definitions: {},
|
|
1617
|
-
errorMessages: false,
|
|
1618
|
-
markdownDescription: false,
|
|
1619
|
-
patternStrategy: "escape",
|
|
1620
|
-
applyRegexFlags: false,
|
|
1621
|
-
emailStrategy: "format:email",
|
|
1622
|
-
base64Strategy: "contentEncoding:base64",
|
|
1623
|
-
nameStrategy: "ref"
|
|
1624
|
-
};
|
|
1625
|
-
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
1626
|
-
...defaultOptions,
|
|
1627
|
-
name: options
|
|
1628
|
-
} : {
|
|
1629
|
-
...defaultOptions,
|
|
1630
|
-
...options
|
|
1631
|
-
};
|
|
1632
|
-
|
|
1633
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
1634
|
-
var getRefs = (options) => {
|
|
1635
|
-
const _options = getDefaultOptions(options);
|
|
1636
|
-
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
1637
|
-
return {
|
|
1638
|
-
..._options,
|
|
1639
|
-
currentPath,
|
|
1640
|
-
propertyPath: void 0,
|
|
1641
|
-
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
1642
|
-
def._def,
|
|
1643
|
-
{
|
|
1644
|
-
def: def._def,
|
|
1645
|
-
path: [..._options.basePath, _options.definitionPath, name],
|
|
1646
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1647
|
-
jsonSchema: void 0
|
|
1648
|
-
}
|
|
1649
|
-
]))
|
|
1650
|
-
};
|
|
1651
|
-
};
|
|
1652
|
-
|
|
1653
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
1654
|
-
function addErrorMessage(res, key, errorMessage, refs) {
|
|
1655
|
-
if (!refs?.errorMessages)
|
|
1656
|
-
return;
|
|
1657
|
-
if (errorMessage) {
|
|
1658
|
-
res.errorMessage = {
|
|
1659
|
-
...res.errorMessage,
|
|
1660
|
-
[key]: errorMessage
|
|
1661
|
-
};
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
1665
|
-
res[key] = value;
|
|
1666
|
-
addErrorMessage(res, key, errorMessage, refs);
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
1670
|
-
function parseAnyDef() {
|
|
1671
|
-
return {};
|
|
1672
|
-
}
|
|
1673
|
-
function parseArrayDef(def, refs) {
|
|
1674
|
-
const res = {
|
|
1675
|
-
type: "array"
|
|
1676
|
-
};
|
|
1677
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1678
|
-
res.items = parseDef(def.type._def, {
|
|
1679
|
-
...refs,
|
|
1680
|
-
currentPath: [...refs.currentPath, "items"]
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
if (def.minLength) {
|
|
1684
|
-
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
1685
|
-
}
|
|
1686
|
-
if (def.maxLength) {
|
|
1687
|
-
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
1688
|
-
}
|
|
1689
|
-
if (def.exactLength) {
|
|
1690
|
-
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
1691
|
-
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
1692
|
-
}
|
|
1693
|
-
return res;
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
1697
|
-
function parseBigintDef(def, refs) {
|
|
1698
|
-
const res = {
|
|
1699
|
-
type: "integer",
|
|
1700
|
-
format: "int64"
|
|
1701
|
-
};
|
|
1702
|
-
if (!def.checks)
|
|
1703
|
-
return res;
|
|
1704
|
-
for (const check of def.checks) {
|
|
1705
|
-
switch (check.kind) {
|
|
1706
|
-
case "min":
|
|
1707
|
-
if (refs.target === "jsonSchema7") {
|
|
1708
|
-
if (check.inclusive) {
|
|
1709
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1710
|
-
} else {
|
|
1711
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
1712
|
-
}
|
|
1713
|
-
} else {
|
|
1714
|
-
if (!check.inclusive) {
|
|
1715
|
-
res.exclusiveMinimum = true;
|
|
1716
|
-
}
|
|
1717
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1718
|
-
}
|
|
1719
|
-
break;
|
|
1720
|
-
case "max":
|
|
1721
|
-
if (refs.target === "jsonSchema7") {
|
|
1722
|
-
if (check.inclusive) {
|
|
1723
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1724
|
-
} else {
|
|
1725
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1726
|
-
}
|
|
1727
|
-
} else {
|
|
1728
|
-
if (!check.inclusive) {
|
|
1729
|
-
res.exclusiveMaximum = true;
|
|
1730
|
-
}
|
|
1731
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1732
|
-
}
|
|
1733
|
-
break;
|
|
1734
|
-
case "multipleOf":
|
|
1735
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1736
|
-
break;
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
return res;
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
1743
|
-
function parseBooleanDef() {
|
|
1744
|
-
return {
|
|
1745
|
-
type: "boolean"
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
1750
|
-
function parseBrandedDef(_def, refs) {
|
|
1751
|
-
return parseDef(_def.type._def, refs);
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
1755
|
-
var parseCatchDef = (def, refs) => {
|
|
1756
|
-
return parseDef(def.innerType._def, refs);
|
|
1757
|
-
};
|
|
1758
|
-
|
|
1759
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
1760
|
-
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
1761
|
-
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
1762
|
-
if (Array.isArray(strategy)) {
|
|
1763
|
-
return {
|
|
1764
|
-
anyOf: strategy.map((item, i2) => parseDateDef(def, refs, item))
|
|
1765
|
-
};
|
|
1766
|
-
}
|
|
1767
|
-
switch (strategy) {
|
|
1768
|
-
case "string":
|
|
1769
|
-
case "format:date-time":
|
|
1770
|
-
return {
|
|
1771
|
-
type: "string",
|
|
1772
|
-
format: "date-time"
|
|
1773
|
-
};
|
|
1774
|
-
case "format:date":
|
|
1775
|
-
return {
|
|
1776
|
-
type: "string",
|
|
1777
|
-
format: "date"
|
|
1778
|
-
};
|
|
1779
|
-
case "integer":
|
|
1780
|
-
return integerDateParser(def, refs);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
var integerDateParser = (def, refs) => {
|
|
1784
|
-
const res = {
|
|
1785
|
-
type: "integer",
|
|
1786
|
-
format: "unix-time"
|
|
1787
|
-
};
|
|
1788
|
-
if (refs.target === "openApi3") {
|
|
1789
|
-
return res;
|
|
1790
|
-
}
|
|
1791
|
-
for (const check of def.checks) {
|
|
1792
|
-
switch (check.kind) {
|
|
1793
|
-
case "min":
|
|
1794
|
-
setResponseValueAndErrors(
|
|
1795
|
-
res,
|
|
1796
|
-
"minimum",
|
|
1797
|
-
check.value,
|
|
1798
|
-
// This is in milliseconds
|
|
1799
|
-
check.message,
|
|
1800
|
-
refs
|
|
1801
|
-
);
|
|
1802
|
-
break;
|
|
1803
|
-
case "max":
|
|
1804
|
-
setResponseValueAndErrors(
|
|
1805
|
-
res,
|
|
1806
|
-
"maximum",
|
|
1807
|
-
check.value,
|
|
1808
|
-
// This is in milliseconds
|
|
1809
|
-
check.message,
|
|
1810
|
-
refs
|
|
1811
|
-
);
|
|
1812
|
-
break;
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
return res;
|
|
1816
|
-
};
|
|
1817
|
-
|
|
1818
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
1819
|
-
function parseDefaultDef(_def, refs) {
|
|
1820
|
-
return {
|
|
1821
|
-
...parseDef(_def.innerType._def, refs),
|
|
1822
|
-
default: _def.defaultValue()
|
|
1823
|
-
};
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
1827
|
-
function parseEffectsDef(_def, refs) {
|
|
1828
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
1832
|
-
function parseEnumDef(def) {
|
|
1833
|
-
return {
|
|
1834
|
-
type: "string",
|
|
1835
|
-
enum: Array.from(def.values)
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
1840
|
-
var isJsonSchema7AllOfType = (type) => {
|
|
1841
|
-
if ("type" in type && type.type === "string")
|
|
1842
|
-
return false;
|
|
1843
|
-
return "allOf" in type;
|
|
1844
|
-
};
|
|
1845
|
-
function parseIntersectionDef(def, refs) {
|
|
1846
|
-
const allOf = [
|
|
1847
|
-
parseDef(def.left._def, {
|
|
1848
|
-
...refs,
|
|
1849
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1850
|
-
}),
|
|
1851
|
-
parseDef(def.right._def, {
|
|
1852
|
-
...refs,
|
|
1853
|
-
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
1854
|
-
})
|
|
1855
|
-
].filter((x2) => !!x2);
|
|
1856
|
-
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
1857
|
-
const mergedAllOf = [];
|
|
1858
|
-
allOf.forEach((schema) => {
|
|
1859
|
-
if (isJsonSchema7AllOfType(schema)) {
|
|
1860
|
-
mergedAllOf.push(...schema.allOf);
|
|
1861
|
-
if (schema.unevaluatedProperties === void 0) {
|
|
1862
|
-
unevaluatedProperties = void 0;
|
|
1863
|
-
}
|
|
1864
|
-
} else {
|
|
1865
|
-
let nestedSchema = schema;
|
|
1866
|
-
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1867
|
-
const { additionalProperties, ...rest } = schema;
|
|
1868
|
-
nestedSchema = rest;
|
|
1869
|
-
} else {
|
|
1870
|
-
unevaluatedProperties = void 0;
|
|
1871
|
-
}
|
|
1872
|
-
mergedAllOf.push(nestedSchema);
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
return mergedAllOf.length ? {
|
|
1876
|
-
allOf: mergedAllOf,
|
|
1877
|
-
...unevaluatedProperties
|
|
1878
|
-
} : void 0;
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
1882
|
-
function parseLiteralDef(def, refs) {
|
|
1883
|
-
const parsedType = typeof def.value;
|
|
1884
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
1885
|
-
return {
|
|
1886
|
-
type: Array.isArray(def.value) ? "array" : "object"
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1889
|
-
if (refs.target === "openApi3") {
|
|
1890
|
-
return {
|
|
1891
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1892
|
-
enum: [def.value]
|
|
1893
|
-
};
|
|
1894
|
-
}
|
|
1895
|
-
return {
|
|
1896
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1897
|
-
const: def.value
|
|
1898
|
-
};
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
1902
|
-
var emojiRegex = void 0;
|
|
1903
|
-
var zodPatterns = {
|
|
1904
|
-
/**
|
|
1905
|
-
* `c` was changed to `[cC]` to replicate /i flag
|
|
1906
|
-
*/
|
|
1907
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
1908
|
-
cuid2: /^[0-9a-z]+$/,
|
|
1909
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1910
|
-
/**
|
|
1911
|
-
* `a-z` was added to replicate /i flag
|
|
1912
|
-
*/
|
|
1913
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1914
|
-
/**
|
|
1915
|
-
* Constructed a valid Unicode RegExp
|
|
1916
|
-
*
|
|
1917
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
1918
|
-
* in all envs (e.g. React Native).
|
|
1919
|
-
*
|
|
1920
|
-
* See:
|
|
1921
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
1922
|
-
* Fix in Zod:
|
|
1923
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
1924
|
-
*/
|
|
1925
|
-
emoji: () => {
|
|
1926
|
-
if (emojiRegex === void 0) {
|
|
1927
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
1928
|
-
}
|
|
1929
|
-
return emojiRegex;
|
|
1930
|
-
},
|
|
1931
|
-
/**
|
|
1932
|
-
* Unused
|
|
1933
|
-
*/
|
|
1934
|
-
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}$/,
|
|
1935
|
-
/**
|
|
1936
|
-
* Unused
|
|
1937
|
-
*/
|
|
1938
|
-
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])$/,
|
|
1939
|
-
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])$/,
|
|
1940
|
-
/**
|
|
1941
|
-
* Unused
|
|
1942
|
-
*/
|
|
1943
|
-
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})))$/,
|
|
1944
|
-
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])$/,
|
|
1945
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1946
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1947
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1948
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1949
|
-
};
|
|
1950
|
-
function parseStringDef(def, refs) {
|
|
1951
|
-
const res = {
|
|
1952
|
-
type: "string"
|
|
1953
|
-
};
|
|
1954
|
-
if (def.checks) {
|
|
1955
|
-
for (const check of def.checks) {
|
|
1956
|
-
switch (check.kind) {
|
|
1957
|
-
case "min":
|
|
1958
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
1959
|
-
break;
|
|
1960
|
-
case "max":
|
|
1961
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
1962
|
-
break;
|
|
1963
|
-
case "email":
|
|
1964
|
-
switch (refs.emailStrategy) {
|
|
1965
|
-
case "format:email":
|
|
1966
|
-
addFormat(res, "email", check.message, refs);
|
|
1967
|
-
break;
|
|
1968
|
-
case "format:idn-email":
|
|
1969
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
1970
|
-
break;
|
|
1971
|
-
case "pattern:zod":
|
|
1972
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1973
|
-
break;
|
|
1974
|
-
}
|
|
1975
|
-
break;
|
|
1976
|
-
case "url":
|
|
1977
|
-
addFormat(res, "uri", check.message, refs);
|
|
1978
|
-
break;
|
|
1979
|
-
case "uuid":
|
|
1980
|
-
addFormat(res, "uuid", check.message, refs);
|
|
1981
|
-
break;
|
|
1982
|
-
case "regex":
|
|
1983
|
-
addPattern(res, check.regex, check.message, refs);
|
|
1984
|
-
break;
|
|
1985
|
-
case "cuid":
|
|
1986
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1987
|
-
break;
|
|
1988
|
-
case "cuid2":
|
|
1989
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1990
|
-
break;
|
|
1991
|
-
case "startsWith":
|
|
1992
|
-
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
1993
|
-
break;
|
|
1994
|
-
case "endsWith":
|
|
1995
|
-
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
1996
|
-
break;
|
|
1997
|
-
case "datetime":
|
|
1998
|
-
addFormat(res, "date-time", check.message, refs);
|
|
1999
|
-
break;
|
|
2000
|
-
case "date":
|
|
2001
|
-
addFormat(res, "date", check.message, refs);
|
|
2002
|
-
break;
|
|
2003
|
-
case "time":
|
|
2004
|
-
addFormat(res, "time", check.message, refs);
|
|
2005
|
-
break;
|
|
2006
|
-
case "duration":
|
|
2007
|
-
addFormat(res, "duration", check.message, refs);
|
|
2008
|
-
break;
|
|
2009
|
-
case "length":
|
|
2010
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
2011
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
2012
|
-
break;
|
|
2013
|
-
case "includes": {
|
|
2014
|
-
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
case "ip": {
|
|
2018
|
-
if (check.version !== "v6") {
|
|
2019
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
2020
|
-
}
|
|
2021
|
-
if (check.version !== "v4") {
|
|
2022
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
2023
|
-
}
|
|
2024
|
-
break;
|
|
2025
|
-
}
|
|
2026
|
-
case "base64url":
|
|
2027
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
2028
|
-
break;
|
|
2029
|
-
case "jwt":
|
|
2030
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
2031
|
-
break;
|
|
2032
|
-
case "cidr": {
|
|
2033
|
-
if (check.version !== "v6") {
|
|
2034
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
2035
|
-
}
|
|
2036
|
-
if (check.version !== "v4") {
|
|
2037
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
2038
|
-
}
|
|
2039
|
-
break;
|
|
2040
|
-
}
|
|
2041
|
-
case "emoji":
|
|
2042
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
2043
|
-
break;
|
|
2044
|
-
case "ulid": {
|
|
2045
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
2046
|
-
break;
|
|
2047
|
-
}
|
|
2048
|
-
case "base64": {
|
|
2049
|
-
switch (refs.base64Strategy) {
|
|
2050
|
-
case "format:binary": {
|
|
2051
|
-
addFormat(res, "binary", check.message, refs);
|
|
2052
|
-
break;
|
|
2053
|
-
}
|
|
2054
|
-
case "contentEncoding:base64": {
|
|
2055
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
2056
|
-
break;
|
|
2057
|
-
}
|
|
2058
|
-
case "pattern:zod": {
|
|
2059
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
2060
|
-
break;
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
break;
|
|
2064
|
-
}
|
|
2065
|
-
case "nanoid": {
|
|
2066
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
return res;
|
|
2072
|
-
}
|
|
2073
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
2074
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
2075
|
-
}
|
|
2076
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
2077
|
-
function escapeNonAlphaNumeric(source) {
|
|
2078
|
-
let result = "";
|
|
2079
|
-
for (let i2 = 0; i2 < source.length; i2++) {
|
|
2080
|
-
if (!ALPHA_NUMERIC.has(source[i2])) {
|
|
2081
|
-
result += "\\";
|
|
2082
|
-
}
|
|
2083
|
-
result += source[i2];
|
|
2084
|
-
}
|
|
2085
|
-
return result;
|
|
2086
|
-
}
|
|
2087
|
-
function addFormat(schema, value, message, refs) {
|
|
2088
|
-
if (schema.format || schema.anyOf?.some((x2) => x2.format)) {
|
|
2089
|
-
if (!schema.anyOf) {
|
|
2090
|
-
schema.anyOf = [];
|
|
2091
|
-
}
|
|
2092
|
-
if (schema.format) {
|
|
2093
|
-
schema.anyOf.push({
|
|
2094
|
-
format: schema.format,
|
|
2095
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
2096
|
-
errorMessage: { format: schema.errorMessage.format }
|
|
2097
|
-
}
|
|
2098
|
-
});
|
|
2099
|
-
delete schema.format;
|
|
2100
|
-
if (schema.errorMessage) {
|
|
2101
|
-
delete schema.errorMessage.format;
|
|
2102
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
2103
|
-
delete schema.errorMessage;
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
schema.anyOf.push({
|
|
2108
|
-
format: value,
|
|
2109
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
2110
|
-
});
|
|
2111
|
-
} else {
|
|
2112
|
-
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
function addPattern(schema, regex, message, refs) {
|
|
2116
|
-
if (schema.pattern || schema.allOf?.some((x2) => x2.pattern)) {
|
|
2117
|
-
if (!schema.allOf) {
|
|
2118
|
-
schema.allOf = [];
|
|
2119
|
-
}
|
|
2120
|
-
if (schema.pattern) {
|
|
2121
|
-
schema.allOf.push({
|
|
2122
|
-
pattern: schema.pattern,
|
|
2123
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
2124
|
-
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
2125
|
-
}
|
|
2126
|
-
});
|
|
2127
|
-
delete schema.pattern;
|
|
2128
|
-
if (schema.errorMessage) {
|
|
2129
|
-
delete schema.errorMessage.pattern;
|
|
2130
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
2131
|
-
delete schema.errorMessage;
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
}
|
|
2135
|
-
schema.allOf.push({
|
|
2136
|
-
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
2137
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
2138
|
-
});
|
|
2139
|
-
} else {
|
|
2140
|
-
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
function stringifyRegExpWithFlags(regex, refs) {
|
|
2144
|
-
if (!refs.applyRegexFlags || !regex.flags) {
|
|
2145
|
-
return regex.source;
|
|
2146
|
-
}
|
|
2147
|
-
const flags = {
|
|
2148
|
-
i: regex.flags.includes("i"),
|
|
2149
|
-
m: regex.flags.includes("m"),
|
|
2150
|
-
s: regex.flags.includes("s")
|
|
2151
|
-
// `.` matches newlines
|
|
2152
|
-
};
|
|
2153
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
2154
|
-
let pattern = "";
|
|
2155
|
-
let isEscaped = false;
|
|
2156
|
-
let inCharGroup = false;
|
|
2157
|
-
let inCharRange = false;
|
|
2158
|
-
for (let i2 = 0; i2 < source.length; i2++) {
|
|
2159
|
-
if (isEscaped) {
|
|
2160
|
-
pattern += source[i2];
|
|
2161
|
-
isEscaped = false;
|
|
2162
|
-
continue;
|
|
2163
|
-
}
|
|
2164
|
-
if (flags.i) {
|
|
2165
|
-
if (inCharGroup) {
|
|
2166
|
-
if (source[i2].match(/[a-z]/)) {
|
|
2167
|
-
if (inCharRange) {
|
|
2168
|
-
pattern += source[i2];
|
|
2169
|
-
pattern += `${source[i2 - 2]}-${source[i2]}`.toUpperCase();
|
|
2170
|
-
inCharRange = false;
|
|
2171
|
-
} else if (source[i2 + 1] === "-" && source[i2 + 2]?.match(/[a-z]/)) {
|
|
2172
|
-
pattern += source[i2];
|
|
2173
|
-
inCharRange = true;
|
|
2174
|
-
} else {
|
|
2175
|
-
pattern += `${source[i2]}${source[i2].toUpperCase()}`;
|
|
2176
|
-
}
|
|
2177
|
-
continue;
|
|
2178
|
-
}
|
|
2179
|
-
} else if (source[i2].match(/[a-z]/)) {
|
|
2180
|
-
pattern += `[${source[i2]}${source[i2].toUpperCase()}]`;
|
|
2181
|
-
continue;
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
if (flags.m) {
|
|
2185
|
-
if (source[i2] === "^") {
|
|
2186
|
-
pattern += `(^|(?<=[\r
|
|
2187
|
-
]))`;
|
|
2188
|
-
continue;
|
|
2189
|
-
} else if (source[i2] === "$") {
|
|
2190
|
-
pattern += `($|(?=[\r
|
|
2191
|
-
]))`;
|
|
2192
|
-
continue;
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
if (flags.s && source[i2] === ".") {
|
|
2196
|
-
pattern += inCharGroup ? `${source[i2]}\r
|
|
2197
|
-
` : `[${source[i2]}\r
|
|
2198
|
-
]`;
|
|
2199
|
-
continue;
|
|
2200
|
-
}
|
|
2201
|
-
pattern += source[i2];
|
|
2202
|
-
if (source[i2] === "\\") {
|
|
2203
|
-
isEscaped = true;
|
|
2204
|
-
} else if (inCharGroup && source[i2] === "]") {
|
|
2205
|
-
inCharGroup = false;
|
|
2206
|
-
} else if (!inCharGroup && source[i2] === "[") {
|
|
2207
|
-
inCharGroup = true;
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
return pattern;
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
2214
|
-
function parseRecordDef(def, refs) {
|
|
2215
|
-
if (refs.target === "openAi") {
|
|
2216
|
-
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
2217
|
-
}
|
|
2218
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
2219
|
-
return {
|
|
2220
|
-
type: "object",
|
|
2221
|
-
required: def.keyType._def.values,
|
|
2222
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
2223
|
-
...acc,
|
|
2224
|
-
[key]: parseDef(def.valueType._def, {
|
|
2225
|
-
...refs,
|
|
2226
|
-
currentPath: [...refs.currentPath, "properties", key]
|
|
2227
|
-
}) ?? {}
|
|
2228
|
-
}), {}),
|
|
2229
|
-
additionalProperties: refs.rejectedAdditionalProperties
|
|
2230
|
-
};
|
|
2231
|
-
}
|
|
2232
|
-
const schema = {
|
|
2233
|
-
type: "object",
|
|
2234
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
2235
|
-
...refs,
|
|
2236
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2237
|
-
}) ?? refs.allowedAdditionalProperties
|
|
2238
|
-
};
|
|
2239
|
-
if (refs.target === "openApi3") {
|
|
2240
|
-
return schema;
|
|
2241
|
-
}
|
|
2242
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
|
|
2243
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
2244
|
-
return {
|
|
2245
|
-
...schema,
|
|
2246
|
-
propertyNames: keyType
|
|
2247
|
-
};
|
|
2248
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
2249
|
-
return {
|
|
2250
|
-
...schema,
|
|
2251
|
-
propertyNames: {
|
|
2252
|
-
enum: def.keyType._def.values
|
|
2253
|
-
}
|
|
2254
|
-
};
|
|
2255
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
2256
|
-
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
2257
|
-
return {
|
|
2258
|
-
...schema,
|
|
2259
|
-
propertyNames: keyType
|
|
2260
|
-
};
|
|
2261
|
-
}
|
|
2262
|
-
return schema;
|
|
2263
|
-
}
|
|
2264
|
-
|
|
2265
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
2266
|
-
function parseMapDef(def, refs) {
|
|
2267
|
-
if (refs.mapStrategy === "record") {
|
|
2268
|
-
return parseRecordDef(def, refs);
|
|
2269
|
-
}
|
|
2270
|
-
const keys = parseDef(def.keyType._def, {
|
|
2271
|
-
...refs,
|
|
2272
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
2273
|
-
}) || {};
|
|
2274
|
-
const values = parseDef(def.valueType._def, {
|
|
2275
|
-
...refs,
|
|
2276
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
2277
|
-
}) || {};
|
|
2278
|
-
return {
|
|
2279
|
-
type: "array",
|
|
2280
|
-
maxItems: 125,
|
|
2281
|
-
items: {
|
|
2282
|
-
type: "array",
|
|
2283
|
-
items: [keys, values],
|
|
2284
|
-
minItems: 2,
|
|
2285
|
-
maxItems: 2
|
|
2286
|
-
}
|
|
2287
|
-
};
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
2291
|
-
function parseNativeEnumDef(def) {
|
|
2292
|
-
const object = def.values;
|
|
2293
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
2294
|
-
return typeof object[object[key]] !== "number";
|
|
2295
|
-
});
|
|
2296
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
2297
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
2298
|
-
return {
|
|
2299
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
2300
|
-
enum: actualValues
|
|
2301
|
-
};
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
2305
|
-
function parseNeverDef() {
|
|
2306
|
-
return {
|
|
2307
|
-
not: {}
|
|
2308
|
-
};
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
2312
|
-
function parseNullDef(refs) {
|
|
2313
|
-
return refs.target === "openApi3" ? {
|
|
2314
|
-
enum: ["null"],
|
|
2315
|
-
nullable: true
|
|
2316
|
-
} : {
|
|
2317
|
-
type: "null"
|
|
2318
|
-
};
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
2322
|
-
var primitiveMappings = {
|
|
2323
|
-
ZodString: "string",
|
|
2324
|
-
ZodNumber: "number",
|
|
2325
|
-
ZodBigInt: "integer",
|
|
2326
|
-
ZodBoolean: "boolean",
|
|
2327
|
-
ZodNull: "null"
|
|
2328
|
-
};
|
|
2329
|
-
function parseUnionDef(def, refs) {
|
|
2330
|
-
if (refs.target === "openApi3")
|
|
2331
|
-
return asAnyOf(def, refs);
|
|
2332
|
-
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
2333
|
-
if (options.every((x2) => x2._def.typeName in primitiveMappings && (!x2._def.checks || !x2._def.checks.length))) {
|
|
2334
|
-
const types = options.reduce((types2, x2) => {
|
|
2335
|
-
const type = primitiveMappings[x2._def.typeName];
|
|
2336
|
-
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
2337
|
-
}, []);
|
|
2338
|
-
return {
|
|
2339
|
-
type: types.length > 1 ? types : types[0]
|
|
2340
|
-
};
|
|
2341
|
-
} else if (options.every((x2) => x2._def.typeName === "ZodLiteral" && !x2.description)) {
|
|
2342
|
-
const types = options.reduce((acc, x2) => {
|
|
2343
|
-
const type = typeof x2._def.value;
|
|
2344
|
-
switch (type) {
|
|
2345
|
-
case "string":
|
|
2346
|
-
case "number":
|
|
2347
|
-
case "boolean":
|
|
2348
|
-
return [...acc, type];
|
|
2349
|
-
case "bigint":
|
|
2350
|
-
return [...acc, "integer"];
|
|
2351
|
-
case "object":
|
|
2352
|
-
if (x2._def.value === null)
|
|
2353
|
-
return [...acc, "null"];
|
|
2354
|
-
case "symbol":
|
|
2355
|
-
case "undefined":
|
|
2356
|
-
case "function":
|
|
2357
|
-
default:
|
|
2358
|
-
return acc;
|
|
2359
|
-
}
|
|
2360
|
-
}, []);
|
|
2361
|
-
if (types.length === options.length) {
|
|
2362
|
-
const uniqueTypes = types.filter((x2, i2, a2) => a2.indexOf(x2) === i2);
|
|
2363
|
-
return {
|
|
2364
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
2365
|
-
enum: options.reduce((acc, x2) => {
|
|
2366
|
-
return acc.includes(x2._def.value) ? acc : [...acc, x2._def.value];
|
|
2367
|
-
}, [])
|
|
2368
|
-
};
|
|
2369
|
-
}
|
|
2370
|
-
} else if (options.every((x2) => x2._def.typeName === "ZodEnum")) {
|
|
2371
|
-
return {
|
|
2372
|
-
type: "string",
|
|
2373
|
-
enum: options.reduce((acc, x2) => [
|
|
2374
|
-
...acc,
|
|
2375
|
-
...x2._def.values.filter((x3) => !acc.includes(x3))
|
|
2376
|
-
], [])
|
|
2377
|
-
};
|
|
2378
|
-
}
|
|
2379
|
-
return asAnyOf(def, refs);
|
|
2380
|
-
}
|
|
2381
|
-
var asAnyOf = (def, refs) => {
|
|
2382
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x2, i2) => parseDef(x2._def, {
|
|
2383
|
-
...refs,
|
|
2384
|
-
currentPath: [...refs.currentPath, "anyOf", `${i2}`]
|
|
2385
|
-
})).filter((x2) => !!x2 && (!refs.strictUnions || typeof x2 === "object" && Object.keys(x2).length > 0));
|
|
2386
|
-
return anyOf.length ? { anyOf } : void 0;
|
|
2387
|
-
};
|
|
2388
|
-
|
|
2389
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
2390
|
-
function parseNullableDef(def, refs) {
|
|
2391
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
2392
|
-
if (refs.target === "openApi3") {
|
|
2393
|
-
return {
|
|
2394
|
-
type: primitiveMappings[def.innerType._def.typeName],
|
|
2395
|
-
nullable: true
|
|
2396
|
-
};
|
|
2397
|
-
}
|
|
2398
|
-
return {
|
|
2399
|
-
type: [
|
|
2400
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
2401
|
-
"null"
|
|
2402
|
-
]
|
|
2403
|
-
};
|
|
2404
|
-
}
|
|
2405
|
-
if (refs.target === "openApi3") {
|
|
2406
|
-
const base2 = parseDef(def.innerType._def, {
|
|
2407
|
-
...refs,
|
|
2408
|
-
currentPath: [...refs.currentPath]
|
|
2409
|
-
});
|
|
2410
|
-
if (base2 && "$ref" in base2)
|
|
2411
|
-
return { allOf: [base2], nullable: true };
|
|
2412
|
-
return base2 && { ...base2, nullable: true };
|
|
2413
|
-
}
|
|
2414
|
-
const base = parseDef(def.innerType._def, {
|
|
2415
|
-
...refs,
|
|
2416
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
2417
|
-
});
|
|
2418
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
2422
|
-
function parseNumberDef(def, refs) {
|
|
2423
|
-
const res = {
|
|
2424
|
-
type: "number"
|
|
2425
|
-
};
|
|
2426
|
-
if (!def.checks)
|
|
2427
|
-
return res;
|
|
2428
|
-
for (const check of def.checks) {
|
|
2429
|
-
switch (check.kind) {
|
|
2430
|
-
case "int":
|
|
2431
|
-
res.type = "integer";
|
|
2432
|
-
addErrorMessage(res, "type", check.message, refs);
|
|
2433
|
-
break;
|
|
2434
|
-
case "min":
|
|
2435
|
-
if (refs.target === "jsonSchema7") {
|
|
2436
|
-
if (check.inclusive) {
|
|
2437
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
2438
|
-
} else {
|
|
2439
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
2440
|
-
}
|
|
2441
|
-
} else {
|
|
2442
|
-
if (!check.inclusive) {
|
|
2443
|
-
res.exclusiveMinimum = true;
|
|
2444
|
-
}
|
|
2445
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
2446
|
-
}
|
|
2447
|
-
break;
|
|
2448
|
-
case "max":
|
|
2449
|
-
if (refs.target === "jsonSchema7") {
|
|
2450
|
-
if (check.inclusive) {
|
|
2451
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
2452
|
-
} else {
|
|
2453
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
2454
|
-
}
|
|
2455
|
-
} else {
|
|
2456
|
-
if (!check.inclusive) {
|
|
2457
|
-
res.exclusiveMaximum = true;
|
|
2458
|
-
}
|
|
2459
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
2460
|
-
}
|
|
2461
|
-
break;
|
|
2462
|
-
case "multipleOf":
|
|
2463
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
2464
|
-
break;
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
return res;
|
|
2468
|
-
}
|
|
2469
|
-
function parseObjectDef(def, refs) {
|
|
2470
|
-
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
2471
|
-
const result = {
|
|
2472
|
-
type: "object",
|
|
2473
|
-
properties: {}
|
|
2474
|
-
};
|
|
2475
|
-
const required = [];
|
|
2476
|
-
const shape = def.shape();
|
|
2477
|
-
for (const propName in shape) {
|
|
2478
|
-
let propDef = shape[propName];
|
|
2479
|
-
if (propDef === void 0 || propDef._def === void 0) {
|
|
2480
|
-
continue;
|
|
2481
|
-
}
|
|
2482
|
-
let propOptional = safeIsOptional(propDef);
|
|
2483
|
-
if (propOptional && forceOptionalIntoNullable) {
|
|
2484
|
-
if (propDef instanceof ZodOptional) {
|
|
2485
|
-
propDef = propDef._def.innerType;
|
|
2486
|
-
}
|
|
2487
|
-
if (!propDef.isNullable()) {
|
|
2488
|
-
propDef = propDef.nullable();
|
|
2489
|
-
}
|
|
2490
|
-
propOptional = false;
|
|
2491
|
-
}
|
|
2492
|
-
const parsedDef = parseDef(propDef._def, {
|
|
2493
|
-
...refs,
|
|
2494
|
-
currentPath: [...refs.currentPath, "properties", propName],
|
|
2495
|
-
propertyPath: [...refs.currentPath, "properties", propName]
|
|
2496
|
-
});
|
|
2497
|
-
if (parsedDef === void 0) {
|
|
2498
|
-
continue;
|
|
2499
|
-
}
|
|
2500
|
-
result.properties[propName] = parsedDef;
|
|
2501
|
-
if (!propOptional) {
|
|
2502
|
-
required.push(propName);
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
if (required.length) {
|
|
2506
|
-
result.required = required;
|
|
2507
|
-
}
|
|
2508
|
-
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
2509
|
-
if (additionalProperties !== void 0) {
|
|
2510
|
-
result.additionalProperties = additionalProperties;
|
|
2511
|
-
}
|
|
2512
|
-
return result;
|
|
2513
|
-
}
|
|
2514
|
-
function decideAdditionalProperties(def, refs) {
|
|
2515
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
2516
|
-
return parseDef(def.catchall._def, {
|
|
2517
|
-
...refs,
|
|
2518
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2519
|
-
});
|
|
2520
|
-
}
|
|
2521
|
-
switch (def.unknownKeys) {
|
|
2522
|
-
case "passthrough":
|
|
2523
|
-
return refs.allowedAdditionalProperties;
|
|
2524
|
-
case "strict":
|
|
2525
|
-
return refs.rejectedAdditionalProperties;
|
|
2526
|
-
case "strip":
|
|
2527
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
function safeIsOptional(schema) {
|
|
2531
|
-
try {
|
|
2532
|
-
return schema.isOptional();
|
|
2533
|
-
} catch {
|
|
2534
|
-
return true;
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
2539
|
-
var parseOptionalDef = (def, refs) => {
|
|
2540
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
2541
|
-
return parseDef(def.innerType._def, refs);
|
|
2542
|
-
}
|
|
2543
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
2544
|
-
...refs,
|
|
2545
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
2546
|
-
});
|
|
2547
|
-
return innerSchema ? {
|
|
2548
|
-
anyOf: [
|
|
2549
|
-
{
|
|
2550
|
-
not: {}
|
|
2551
|
-
},
|
|
2552
|
-
innerSchema
|
|
2553
|
-
]
|
|
2554
|
-
} : {};
|
|
2555
|
-
};
|
|
2556
|
-
|
|
2557
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
2558
|
-
var parsePipelineDef = (def, refs) => {
|
|
2559
|
-
if (refs.pipeStrategy === "input") {
|
|
2560
|
-
return parseDef(def.in._def, refs);
|
|
2561
|
-
} else if (refs.pipeStrategy === "output") {
|
|
2562
|
-
return parseDef(def.out._def, refs);
|
|
2563
|
-
}
|
|
2564
|
-
const a2 = parseDef(def.in._def, {
|
|
2565
|
-
...refs,
|
|
2566
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
2567
|
-
});
|
|
2568
|
-
const b = parseDef(def.out._def, {
|
|
2569
|
-
...refs,
|
|
2570
|
-
currentPath: [...refs.currentPath, "allOf", a2 ? "1" : "0"]
|
|
2571
|
-
});
|
|
2572
|
-
return {
|
|
2573
|
-
allOf: [a2, b].filter((x2) => x2 !== void 0)
|
|
2574
|
-
};
|
|
2575
|
-
};
|
|
2576
|
-
|
|
2577
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
2578
|
-
function parsePromiseDef(def, refs) {
|
|
2579
|
-
return parseDef(def.type._def, refs);
|
|
2580
|
-
}
|
|
2581
|
-
|
|
2582
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
2583
|
-
function parseSetDef(def, refs) {
|
|
2584
|
-
const items = parseDef(def.valueType._def, {
|
|
2585
|
-
...refs,
|
|
2586
|
-
currentPath: [...refs.currentPath, "items"]
|
|
2587
|
-
});
|
|
2588
|
-
const schema = {
|
|
2589
|
-
type: "array",
|
|
2590
|
-
uniqueItems: true,
|
|
2591
|
-
items
|
|
2592
|
-
};
|
|
2593
|
-
if (def.minSize) {
|
|
2594
|
-
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
2595
|
-
}
|
|
2596
|
-
if (def.maxSize) {
|
|
2597
|
-
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
2598
|
-
}
|
|
2599
|
-
return schema;
|
|
2600
|
-
}
|
|
2601
|
-
|
|
2602
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
2603
|
-
function parseTupleDef(def, refs) {
|
|
2604
|
-
if (def.rest) {
|
|
2605
|
-
return {
|
|
2606
|
-
type: "array",
|
|
2607
|
-
minItems: def.items.length,
|
|
2608
|
-
items: def.items.map((x2, i2) => parseDef(x2._def, {
|
|
2609
|
-
...refs,
|
|
2610
|
-
currentPath: [...refs.currentPath, "items", `${i2}`]
|
|
2611
|
-
})).reduce((acc, x2) => x2 === void 0 ? acc : [...acc, x2], []),
|
|
2612
|
-
additionalItems: parseDef(def.rest._def, {
|
|
2613
|
-
...refs,
|
|
2614
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
2615
|
-
})
|
|
2616
|
-
};
|
|
2617
|
-
} else {
|
|
2618
|
-
return {
|
|
2619
|
-
type: "array",
|
|
2620
|
-
minItems: def.items.length,
|
|
2621
|
-
maxItems: def.items.length,
|
|
2622
|
-
items: def.items.map((x2, i2) => parseDef(x2._def, {
|
|
2623
|
-
...refs,
|
|
2624
|
-
currentPath: [...refs.currentPath, "items", `${i2}`]
|
|
2625
|
-
})).reduce((acc, x2) => x2 === void 0 ? acc : [...acc, x2], [])
|
|
2626
|
-
};
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
|
|
2630
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
2631
|
-
function parseUndefinedDef() {
|
|
2632
|
-
return {
|
|
2633
|
-
not: {}
|
|
2634
|
-
};
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
2638
|
-
function parseUnknownDef() {
|
|
2639
|
-
return {};
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
2643
|
-
var parseReadonlyDef = (def, refs) => {
|
|
2644
|
-
return parseDef(def.innerType._def, refs);
|
|
2645
|
-
};
|
|
2646
|
-
|
|
2647
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
2648
|
-
var selectParser = (def, typeName, refs) => {
|
|
2649
|
-
switch (typeName) {
|
|
2650
|
-
case ZodFirstPartyTypeKind.ZodString:
|
|
2651
|
-
return parseStringDef(def, refs);
|
|
2652
|
-
case ZodFirstPartyTypeKind.ZodNumber:
|
|
2653
|
-
return parseNumberDef(def, refs);
|
|
2654
|
-
case ZodFirstPartyTypeKind.ZodObject:
|
|
2655
|
-
return parseObjectDef(def, refs);
|
|
2656
|
-
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
2657
|
-
return parseBigintDef(def, refs);
|
|
2658
|
-
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
2659
|
-
return parseBooleanDef();
|
|
2660
|
-
case ZodFirstPartyTypeKind.ZodDate:
|
|
2661
|
-
return parseDateDef(def, refs);
|
|
2662
|
-
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
2663
|
-
return parseUndefinedDef();
|
|
2664
|
-
case ZodFirstPartyTypeKind.ZodNull:
|
|
2665
|
-
return parseNullDef(refs);
|
|
2666
|
-
case ZodFirstPartyTypeKind.ZodArray:
|
|
2667
|
-
return parseArrayDef(def, refs);
|
|
2668
|
-
case ZodFirstPartyTypeKind.ZodUnion:
|
|
2669
|
-
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
2670
|
-
return parseUnionDef(def, refs);
|
|
2671
|
-
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
2672
|
-
return parseIntersectionDef(def, refs);
|
|
2673
|
-
case ZodFirstPartyTypeKind.ZodTuple:
|
|
2674
|
-
return parseTupleDef(def, refs);
|
|
2675
|
-
case ZodFirstPartyTypeKind.ZodRecord:
|
|
2676
|
-
return parseRecordDef(def, refs);
|
|
2677
|
-
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
2678
|
-
return parseLiteralDef(def, refs);
|
|
2679
|
-
case ZodFirstPartyTypeKind.ZodEnum:
|
|
2680
|
-
return parseEnumDef(def);
|
|
2681
|
-
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
2682
|
-
return parseNativeEnumDef(def);
|
|
2683
|
-
case ZodFirstPartyTypeKind.ZodNullable:
|
|
2684
|
-
return parseNullableDef(def, refs);
|
|
2685
|
-
case ZodFirstPartyTypeKind.ZodOptional:
|
|
2686
|
-
return parseOptionalDef(def, refs);
|
|
2687
|
-
case ZodFirstPartyTypeKind.ZodMap:
|
|
2688
|
-
return parseMapDef(def, refs);
|
|
2689
|
-
case ZodFirstPartyTypeKind.ZodSet:
|
|
2690
|
-
return parseSetDef(def, refs);
|
|
2691
|
-
case ZodFirstPartyTypeKind.ZodLazy:
|
|
2692
|
-
return () => def.getter()._def;
|
|
2693
|
-
case ZodFirstPartyTypeKind.ZodPromise:
|
|
2694
|
-
return parsePromiseDef(def, refs);
|
|
2695
|
-
case ZodFirstPartyTypeKind.ZodNaN:
|
|
2696
|
-
case ZodFirstPartyTypeKind.ZodNever:
|
|
2697
|
-
return parseNeverDef();
|
|
2698
|
-
case ZodFirstPartyTypeKind.ZodEffects:
|
|
2699
|
-
return parseEffectsDef(def, refs);
|
|
2700
|
-
case ZodFirstPartyTypeKind.ZodAny:
|
|
2701
|
-
return parseAnyDef();
|
|
2702
|
-
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
2703
|
-
return parseUnknownDef();
|
|
2704
|
-
case ZodFirstPartyTypeKind.ZodDefault:
|
|
2705
|
-
return parseDefaultDef(def, refs);
|
|
2706
|
-
case ZodFirstPartyTypeKind.ZodBranded:
|
|
2707
|
-
return parseBrandedDef(def, refs);
|
|
2708
|
-
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
2709
|
-
return parseReadonlyDef(def, refs);
|
|
2710
|
-
case ZodFirstPartyTypeKind.ZodCatch:
|
|
2711
|
-
return parseCatchDef(def, refs);
|
|
2712
|
-
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
2713
|
-
return parsePipelineDef(def, refs);
|
|
2714
|
-
case ZodFirstPartyTypeKind.ZodFunction:
|
|
2715
|
-
case ZodFirstPartyTypeKind.ZodVoid:
|
|
2716
|
-
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
2717
|
-
return void 0;
|
|
2718
|
-
default:
|
|
2719
|
-
return /* @__PURE__ */ ((_) => void 0)();
|
|
2720
|
-
}
|
|
2721
|
-
};
|
|
2722
|
-
|
|
2723
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
2724
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
2725
|
-
const seenItem = refs.seen.get(def);
|
|
2726
|
-
if (refs.override) {
|
|
2727
|
-
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
2728
|
-
if (overrideResult !== ignoreOverride) {
|
|
2729
|
-
return overrideResult;
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
if (seenItem && !forceResolution) {
|
|
2733
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
2734
|
-
if (seenSchema !== void 0) {
|
|
2735
|
-
return seenSchema;
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
2739
|
-
refs.seen.set(def, newItem);
|
|
2740
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
2741
|
-
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
2742
|
-
if (jsonSchema) {
|
|
2743
|
-
addMeta(def, refs, jsonSchema);
|
|
2744
|
-
}
|
|
2745
|
-
if (refs.postProcess) {
|
|
2746
|
-
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
2747
|
-
newItem.jsonSchema = jsonSchema;
|
|
2748
|
-
return postProcessResult;
|
|
2749
|
-
}
|
|
2750
|
-
newItem.jsonSchema = jsonSchema;
|
|
2751
|
-
return jsonSchema;
|
|
2752
|
-
}
|
|
2753
|
-
var get$ref = (item, refs) => {
|
|
2754
|
-
switch (refs.$refStrategy) {
|
|
2755
|
-
case "root":
|
|
2756
|
-
return { $ref: item.path.join("/") };
|
|
2757
|
-
case "relative":
|
|
2758
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
2759
|
-
case "none":
|
|
2760
|
-
case "seen": {
|
|
2761
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
2762
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
2763
|
-
return {};
|
|
2764
|
-
}
|
|
2765
|
-
return refs.$refStrategy === "seen" ? {} : void 0;
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
};
|
|
2769
|
-
var getRelativePath = (pathA, pathB) => {
|
|
2770
|
-
let i2 = 0;
|
|
2771
|
-
for (; i2 < pathA.length && i2 < pathB.length; i2++) {
|
|
2772
|
-
if (pathA[i2] !== pathB[i2])
|
|
2773
|
-
break;
|
|
2774
|
-
}
|
|
2775
|
-
return [(pathA.length - i2).toString(), ...pathB.slice(i2)].join("/");
|
|
2776
|
-
};
|
|
2777
|
-
var addMeta = (def, refs, jsonSchema) => {
|
|
2778
|
-
if (def.description) {
|
|
2779
|
-
jsonSchema.description = def.description;
|
|
2780
|
-
if (refs.markdownDescription) {
|
|
2781
|
-
jsonSchema.markdownDescription = def.description;
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
return jsonSchema;
|
|
2785
|
-
};
|
|
2786
|
-
|
|
2787
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
2788
|
-
var zodToJsonSchema = (schema, options) => {
|
|
2789
|
-
const refs = getRefs(options);
|
|
2790
|
-
const definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
2791
|
-
...acc,
|
|
2792
|
-
[name2]: parseDef(schema2._def, {
|
|
2793
|
-
...refs,
|
|
2794
|
-
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
2795
|
-
}, true) ?? {}
|
|
2796
|
-
}), {}) : void 0;
|
|
2797
|
-
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
2798
|
-
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
2799
|
-
...refs,
|
|
2800
|
-
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
2801
|
-
}, false) ?? {};
|
|
2802
|
-
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2803
|
-
if (title !== void 0) {
|
|
2804
|
-
main.title = title;
|
|
2805
|
-
}
|
|
2806
|
-
const combined = name === void 0 ? definitions ? {
|
|
2807
|
-
...main,
|
|
2808
|
-
[refs.definitionPath]: definitions
|
|
2809
|
-
} : main : {
|
|
2810
|
-
$ref: [
|
|
2811
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2812
|
-
refs.definitionPath,
|
|
2813
|
-
name
|
|
2814
|
-
].join("/"),
|
|
2815
|
-
[refs.definitionPath]: {
|
|
2816
|
-
...definitions,
|
|
2817
|
-
[name]: main
|
|
2818
|
-
}
|
|
2819
|
-
};
|
|
2820
|
-
if (refs.target === "jsonSchema7") {
|
|
2821
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
2822
|
-
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
2823
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
2824
|
-
}
|
|
2825
|
-
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
2826
|
-
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
2827
|
-
}
|
|
2828
|
-
return combined;
|
|
2829
|
-
};
|
|
2830
|
-
|
|
2831
|
-
// ../../node_modules/.pnpm/zod-to-json-schema@3.24.4_zod@3.24.2/node_modules/zod-to-json-schema/dist/esm/index.js
|
|
2832
|
-
var esm_default = zodToJsonSchema;
|
|
2833
844
|
function handleError(error, defaultMessage) {
|
|
2834
|
-
console.error(defaultMessage, error);
|
|
2835
845
|
const apiError = error;
|
|
2836
846
|
throw new HTTPException(apiError.status || 500, {
|
|
2837
847
|
message: apiError.message || defaultMessage
|
|
@@ -2844,120 +854,51 @@ function errorHandler(err, c2) {
|
|
|
2844
854
|
console.error(err);
|
|
2845
855
|
return c2.json({ error: "Internal Server Error" }, 500);
|
|
2846
856
|
}
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
const mastra = c2.get("mastra");
|
|
2863
|
-
const agents = mastra.getAgents();
|
|
2864
|
-
const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
|
|
2865
|
-
const agent = _agent;
|
|
2866
|
-
const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc2, [key, tool]) => {
|
|
2867
|
-
const _tool = tool;
|
|
2868
|
-
acc2[key] = {
|
|
2869
|
-
..._tool,
|
|
2870
|
-
inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
|
|
2871
|
-
outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
|
|
2872
|
-
};
|
|
2873
|
-
return acc2;
|
|
2874
|
-
}, {});
|
|
2875
|
-
acc[_id] = {
|
|
2876
|
-
name: agent.name,
|
|
2877
|
-
instructions: agent.instructions,
|
|
2878
|
-
tools: serializedAgentTools,
|
|
2879
|
-
provider: agent.llm?.getProvider(),
|
|
2880
|
-
modelId: agent.llm?.getModelId()
|
|
2881
|
-
};
|
|
2882
|
-
return acc;
|
|
2883
|
-
}, {});
|
|
2884
|
-
return c2.json(serializedAgents);
|
|
2885
|
-
} catch (error) {
|
|
2886
|
-
return handleError(error, "Error getting agents");
|
|
2887
|
-
}
|
|
2888
|
-
}
|
|
2889
|
-
async function getAgentByIdHandler(c2) {
|
|
2890
|
-
try {
|
|
2891
|
-
const mastra = c2.get("mastra");
|
|
2892
|
-
const agentId = c2.req.param("agentId");
|
|
2893
|
-
const agent = mastra.getAgent(agentId);
|
|
2894
|
-
if (!agent) {
|
|
2895
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
2896
|
-
}
|
|
2897
|
-
const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
|
|
2898
|
-
const _tool = tool;
|
|
2899
|
-
acc[key] = {
|
|
2900
|
-
..._tool,
|
|
2901
|
-
inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
|
|
2902
|
-
outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
|
|
2903
|
-
};
|
|
2904
|
-
return acc;
|
|
2905
|
-
}, {});
|
|
2906
|
-
return c2.json({
|
|
2907
|
-
name: agent.name,
|
|
2908
|
-
instructions: agent.instructions,
|
|
2909
|
-
tools: serializedAgentTools,
|
|
2910
|
-
provider: agent.llm?.getProvider(),
|
|
2911
|
-
modelId: agent.llm?.getModelId()
|
|
2912
|
-
});
|
|
2913
|
-
} catch (error) {
|
|
2914
|
-
return handleError(error, "Error getting agent");
|
|
2915
|
-
}
|
|
2916
|
-
}
|
|
857
|
+
|
|
858
|
+
// src/server/handlers/agents.ts
|
|
859
|
+
async function getAgentsHandler(c2) {
|
|
860
|
+
const serializedAgents = await getAgentsHandler$1({ mastra: c2.get("mastra") });
|
|
861
|
+
return c2.json(serializedAgents);
|
|
862
|
+
}
|
|
863
|
+
async function getAgentByIdHandler(c2) {
|
|
864
|
+
const mastra = c2.get("mastra");
|
|
865
|
+
const agentId = c2.req.param("agentId");
|
|
866
|
+
const result = await getAgentByIdHandler$1({
|
|
867
|
+
mastra,
|
|
868
|
+
agentId
|
|
869
|
+
});
|
|
870
|
+
return c2.json(result);
|
|
871
|
+
}
|
|
2917
872
|
async function getEvalsByAgentIdHandler(c2) {
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
name: agent.name,
|
|
2926
|
-
instructions: agent.instructions,
|
|
2927
|
-
evals
|
|
2928
|
-
});
|
|
2929
|
-
} catch (error) {
|
|
2930
|
-
return handleError(error, "Error getting test evals");
|
|
2931
|
-
}
|
|
873
|
+
const mastra = c2.get("mastra");
|
|
874
|
+
const agentId = c2.req.param("agentId");
|
|
875
|
+
const result = await getEvalsByAgentIdHandler$1({
|
|
876
|
+
mastra,
|
|
877
|
+
agentId
|
|
878
|
+
});
|
|
879
|
+
return c2.json(result);
|
|
2932
880
|
}
|
|
2933
881
|
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
name: agent.name,
|
|
2942
|
-
instructions: agent.instructions,
|
|
2943
|
-
evals
|
|
2944
|
-
});
|
|
2945
|
-
} catch (error) {
|
|
2946
|
-
return handleError(error, "Error getting live evals");
|
|
2947
|
-
}
|
|
882
|
+
const mastra = c2.get("mastra");
|
|
883
|
+
const agentId = c2.req.param("agentId");
|
|
884
|
+
const result = await getLiveEvalsByAgentIdHandler$1({
|
|
885
|
+
mastra,
|
|
886
|
+
agentId
|
|
887
|
+
});
|
|
888
|
+
return c2.json(result);
|
|
2948
889
|
}
|
|
2949
890
|
async function generateHandler(c2) {
|
|
2950
891
|
try {
|
|
2951
892
|
const mastra = c2.get("mastra");
|
|
2952
893
|
const agentId = c2.req.param("agentId");
|
|
2953
|
-
const
|
|
2954
|
-
if (!agent) {
|
|
2955
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
2956
|
-
}
|
|
2957
|
-
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
2958
|
-
validateBody({ messages });
|
|
894
|
+
const { resourceId, resourceid, ...body } = await c2.req.json();
|
|
2959
895
|
const finalResourceId = resourceId ?? resourceid;
|
|
2960
|
-
const result = await
|
|
896
|
+
const result = await generateHandler$2({
|
|
897
|
+
mastra,
|
|
898
|
+
agentId,
|
|
899
|
+
resourceId: finalResourceId,
|
|
900
|
+
...body
|
|
901
|
+
});
|
|
2961
902
|
return c2.json(result);
|
|
2962
903
|
} catch (error) {
|
|
2963
904
|
return handleError(error, "Error generating from agent");
|
|
@@ -2967,26 +908,13 @@ async function streamGenerateHandler(c2) {
|
|
|
2967
908
|
try {
|
|
2968
909
|
const mastra = c2.get("mastra");
|
|
2969
910
|
const agentId = c2.req.param("agentId");
|
|
2970
|
-
const
|
|
2971
|
-
if (!agent) {
|
|
2972
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
2973
|
-
}
|
|
2974
|
-
const { messages, threadId, resourceid, resourceId, output, runId, ...rest } = await c2.req.json();
|
|
2975
|
-
validateBody({ messages });
|
|
911
|
+
const { resourceId, resourceid, ...body } = await c2.req.json();
|
|
2976
912
|
const finalResourceId = resourceId ?? resourceid;
|
|
2977
|
-
const
|
|
2978
|
-
|
|
913
|
+
const streamResponse = await streamGenerateHandler$2({
|
|
914
|
+
mastra,
|
|
915
|
+
agentId,
|
|
2979
916
|
resourceId: finalResourceId,
|
|
2980
|
-
|
|
2981
|
-
runId,
|
|
2982
|
-
...rest
|
|
2983
|
-
});
|
|
2984
|
-
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
2985
|
-
sendUsage: true,
|
|
2986
|
-
sendReasoning: true,
|
|
2987
|
-
getErrorMessage: (error) => {
|
|
2988
|
-
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
2989
|
-
}
|
|
917
|
+
...body
|
|
2990
918
|
});
|
|
2991
919
|
return streamResponse;
|
|
2992
920
|
} catch (error) {
|
|
@@ -3024,7 +952,7 @@ async function setAgentInstructionsHandler(c2) {
|
|
|
3024
952
|
// src/server/handlers/client.ts
|
|
3025
953
|
var clients = /* @__PURE__ */ new Set();
|
|
3026
954
|
function handleClientsRefresh(c2) {
|
|
3027
|
-
const
|
|
955
|
+
const stream2 = new ReadableStream({
|
|
3028
956
|
start(controller) {
|
|
3029
957
|
clients.add(controller);
|
|
3030
958
|
controller.enqueue("data: connected\n\n");
|
|
@@ -3033,7 +961,7 @@ function handleClientsRefresh(c2) {
|
|
|
3033
961
|
});
|
|
3034
962
|
}
|
|
3035
963
|
});
|
|
3036
|
-
return new Response(
|
|
964
|
+
return new Response(stream2, {
|
|
3037
965
|
headers: {
|
|
3038
966
|
"Content-Type": "text/event-stream",
|
|
3039
967
|
"Cache-Control": "no-cache",
|
|
@@ -3056,10 +984,10 @@ async function getLogsHandler(c2) {
|
|
|
3056
984
|
try {
|
|
3057
985
|
const mastra = c2.get("mastra");
|
|
3058
986
|
const transportId = c2.req.query("transportId");
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
987
|
+
const logs = await getLogsHandler$1({
|
|
988
|
+
mastra,
|
|
989
|
+
transportId
|
|
990
|
+
});
|
|
3063
991
|
return c2.json(logs);
|
|
3064
992
|
} catch (error) {
|
|
3065
993
|
return handleError(error, "Error getting logs");
|
|
@@ -3070,10 +998,11 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
3070
998
|
const mastra = c2.get("mastra");
|
|
3071
999
|
const runId = c2.req.param("runId");
|
|
3072
1000
|
const transportId = c2.req.query("transportId");
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
1001
|
+
const logs = await getLogsByRunIdHandler$1({
|
|
1002
|
+
mastra,
|
|
1003
|
+
runId,
|
|
1004
|
+
transportId
|
|
1005
|
+
});
|
|
3077
1006
|
return c2.json(logs);
|
|
3078
1007
|
} catch (error) {
|
|
3079
1008
|
return handleError(error, "Error getting logs by run ID");
|
|
@@ -3082,85 +1011,67 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
3082
1011
|
async function getLogTransports(c2) {
|
|
3083
1012
|
try {
|
|
3084
1013
|
const mastra = c2.get("mastra");
|
|
3085
|
-
const
|
|
3086
|
-
|
|
3087
|
-
return c2.json({
|
|
3088
|
-
transports: Object.keys(transports)
|
|
1014
|
+
const result = await getLogTransports$1({
|
|
1015
|
+
mastra
|
|
3089
1016
|
});
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
}
|
|
3094
|
-
function getMemoryFromContext(c2) {
|
|
3095
|
-
const mastra = c2.get("mastra");
|
|
3096
|
-
const agentId = c2.req.query("agentId");
|
|
3097
|
-
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
3098
|
-
if (agentId && !agent) {
|
|
3099
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
1017
|
+
return c2.json(result);
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
return handleError(error, "Error getting log Transports");
|
|
3100
1020
|
}
|
|
3101
|
-
const memory = agent?.getMemory?.() || mastra.memory;
|
|
3102
|
-
return memory;
|
|
3103
1021
|
}
|
|
3104
1022
|
async function getMemoryStatusHandler(c2) {
|
|
3105
1023
|
try {
|
|
3106
|
-
const
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
1024
|
+
const mastra = c2.get("mastra");
|
|
1025
|
+
const agentId = c2.req.query("agentId");
|
|
1026
|
+
const result = await getMemoryStatusHandler$1({
|
|
1027
|
+
mastra,
|
|
1028
|
+
agentId
|
|
1029
|
+
});
|
|
1030
|
+
return c2.json(result);
|
|
3111
1031
|
} catch (error) {
|
|
3112
1032
|
return handleError(error, "Error getting memory status");
|
|
3113
1033
|
}
|
|
3114
1034
|
}
|
|
3115
1035
|
async function getThreadsHandler(c2) {
|
|
3116
1036
|
try {
|
|
3117
|
-
const
|
|
3118
|
-
const
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
}
|
|
3125
|
-
|
|
3126
|
-
return c2.json(threads);
|
|
1037
|
+
const mastra = c2.get("mastra");
|
|
1038
|
+
const agentId = c2.req.query("agentId");
|
|
1039
|
+
const resourceId = c2.req.query("resourceid");
|
|
1040
|
+
const result = await getThreadsHandler$1({
|
|
1041
|
+
mastra,
|
|
1042
|
+
agentId,
|
|
1043
|
+
resourceId
|
|
1044
|
+
});
|
|
1045
|
+
return c2.json(result);
|
|
3127
1046
|
} catch (error) {
|
|
3128
1047
|
return handleError(error, "Error getting threads");
|
|
3129
1048
|
}
|
|
3130
1049
|
}
|
|
3131
1050
|
async function getThreadByIdHandler(c2) {
|
|
3132
1051
|
try {
|
|
3133
|
-
const
|
|
1052
|
+
const mastra = c2.get("mastra");
|
|
1053
|
+
const agentId = c2.req.query("agentId");
|
|
3134
1054
|
const threadId = c2.req.param("threadId");
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
}
|
|
3142
|
-
return c2.json(thread);
|
|
1055
|
+
const result = await getThreadByIdHandler$1({
|
|
1056
|
+
mastra,
|
|
1057
|
+
agentId,
|
|
1058
|
+
threadId
|
|
1059
|
+
});
|
|
1060
|
+
return c2.json(result);
|
|
3143
1061
|
} catch (error) {
|
|
3144
1062
|
return handleError(error, "Error getting thread");
|
|
3145
1063
|
}
|
|
3146
1064
|
}
|
|
3147
1065
|
async function saveMessagesHandler(c2) {
|
|
3148
1066
|
try {
|
|
3149
|
-
const
|
|
3150
|
-
const
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
}
|
|
3158
|
-
const processedMessages = messages.map((message) => ({
|
|
3159
|
-
...message,
|
|
3160
|
-
id: memory.generateId(),
|
|
3161
|
-
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
3162
|
-
}));
|
|
3163
|
-
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
1067
|
+
const mastra = c2.get("mastra");
|
|
1068
|
+
const agentId = c2.req.query("agentId");
|
|
1069
|
+
const body = await c2.req.json();
|
|
1070
|
+
const result = await saveMessagesHandler$1({
|
|
1071
|
+
mastra,
|
|
1072
|
+
agentId,
|
|
1073
|
+
body
|
|
1074
|
+
});
|
|
3164
1075
|
return c2.json(result);
|
|
3165
1076
|
} catch (error) {
|
|
3166
1077
|
return handleError(error, "Error saving messages");
|
|
@@ -3168,13 +1079,14 @@ async function saveMessagesHandler(c2) {
|
|
|
3168
1079
|
}
|
|
3169
1080
|
async function createThreadHandler(c2) {
|
|
3170
1081
|
try {
|
|
3171
|
-
const
|
|
3172
|
-
const
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
1082
|
+
const mastra = c2.get("mastra");
|
|
1083
|
+
const agentId = c2.req.query("agentId");
|
|
1084
|
+
const body = await c2.req.json();
|
|
1085
|
+
const result = await createThreadHandler$1({
|
|
1086
|
+
mastra,
|
|
1087
|
+
agentId,
|
|
1088
|
+
body
|
|
1089
|
+
});
|
|
3178
1090
|
return c2.json(result);
|
|
3179
1091
|
} catch (error) {
|
|
3180
1092
|
return handleError(error, "Error saving thread to memory");
|
|
@@ -3182,26 +1094,16 @@ async function createThreadHandler(c2) {
|
|
|
3182
1094
|
}
|
|
3183
1095
|
async function updateThreadHandler(c2) {
|
|
3184
1096
|
try {
|
|
3185
|
-
const
|
|
1097
|
+
const mastra = c2.get("mastra");
|
|
1098
|
+
const agentId = c2.req.query("agentId");
|
|
3186
1099
|
const threadId = c2.req.param("threadId");
|
|
3187
|
-
const
|
|
3188
|
-
const
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
3195
|
-
}
|
|
3196
|
-
const updatedThread = {
|
|
3197
|
-
...thread,
|
|
3198
|
-
title: title || thread.title,
|
|
3199
|
-
metadata: metadata || thread.metadata,
|
|
3200
|
-
resourceId: resourceid || thread.resourceId,
|
|
3201
|
-
createdAt: thread.createdAt,
|
|
3202
|
-
updatedAt
|
|
3203
|
-
};
|
|
3204
|
-
const result = await memory.saveThread({ thread: updatedThread });
|
|
1100
|
+
const body = await c2.req.json();
|
|
1101
|
+
const result = await updateThreadHandler$1({
|
|
1102
|
+
mastra,
|
|
1103
|
+
agentId,
|
|
1104
|
+
threadId,
|
|
1105
|
+
body
|
|
1106
|
+
});
|
|
3205
1107
|
return c2.json(result);
|
|
3206
1108
|
} catch (error) {
|
|
3207
1109
|
return handleError(error, "Error updating thread");
|
|
@@ -3209,33 +1111,29 @@ async function updateThreadHandler(c2) {
|
|
|
3209
1111
|
}
|
|
3210
1112
|
async function deleteThreadHandler(c2) {
|
|
3211
1113
|
try {
|
|
3212
|
-
const
|
|
1114
|
+
const mastra = c2.get("mastra");
|
|
1115
|
+
const agentId = c2.req.query("agentId");
|
|
3213
1116
|
const threadId = c2.req.param("threadId");
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
}
|
|
3221
|
-
await memory.deleteThread(threadId);
|
|
3222
|
-
return c2.json({ result: "Thread deleted" });
|
|
1117
|
+
const result = await deleteThreadHandler$1({
|
|
1118
|
+
mastra,
|
|
1119
|
+
agentId,
|
|
1120
|
+
threadId
|
|
1121
|
+
});
|
|
1122
|
+
return c2.json(result);
|
|
3223
1123
|
} catch (error) {
|
|
3224
1124
|
return handleError(error, "Error deleting thread");
|
|
3225
1125
|
}
|
|
3226
1126
|
}
|
|
3227
1127
|
async function getMessagesHandler(c2) {
|
|
3228
1128
|
try {
|
|
3229
|
-
const
|
|
1129
|
+
const mastra = c2.get("mastra");
|
|
1130
|
+
const agentId = c2.req.query("agentId");
|
|
3230
1131
|
const threadId = c2.req.param("threadId");
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
return c2.json({ error: "Thread not found" }, 404);
|
|
3237
|
-
}
|
|
3238
|
-
const result = await memory.query({ threadId });
|
|
1132
|
+
const result = await getMessagesHandler$1({
|
|
1133
|
+
mastra,
|
|
1134
|
+
agentId,
|
|
1135
|
+
threadId
|
|
1136
|
+
});
|
|
3239
1137
|
return c2.json(result);
|
|
3240
1138
|
} catch (error) {
|
|
3241
1139
|
return handleError(error, "Error getting messages");
|
|
@@ -3244,26 +1142,10 @@ async function getMessagesHandler(c2) {
|
|
|
3244
1142
|
async function getNetworksHandler(c2) {
|
|
3245
1143
|
try {
|
|
3246
1144
|
const mastra = c2.get("mastra");
|
|
3247
|
-
const networks =
|
|
3248
|
-
|
|
3249
|
-
const routingAgent = network.getRoutingAgent();
|
|
3250
|
-
const agents = network.getAgents();
|
|
3251
|
-
return {
|
|
3252
|
-
id: network.formatAgentId(routingAgent.name),
|
|
3253
|
-
name: routingAgent.name,
|
|
3254
|
-
instructions: routingAgent.instructions,
|
|
3255
|
-
agents: agents.map((agent) => ({
|
|
3256
|
-
name: agent.name,
|
|
3257
|
-
provider: agent.llm?.getProvider(),
|
|
3258
|
-
modelId: agent.llm?.getModelId()
|
|
3259
|
-
})),
|
|
3260
|
-
routingModel: {
|
|
3261
|
-
provider: routingAgent.llm?.getProvider(),
|
|
3262
|
-
modelId: routingAgent.llm?.getModelId()
|
|
3263
|
-
}
|
|
3264
|
-
};
|
|
1145
|
+
const networks = await getNetworksHandler$1({
|
|
1146
|
+
mastra
|
|
3265
1147
|
});
|
|
3266
|
-
return c2.json(
|
|
1148
|
+
return c2.json(networks);
|
|
3267
1149
|
} catch (error) {
|
|
3268
1150
|
return handleError(error, "Error getting networks");
|
|
3269
1151
|
}
|
|
@@ -3272,31 +1154,11 @@ async function getNetworkByIdHandler(c2) {
|
|
|
3272
1154
|
try {
|
|
3273
1155
|
const mastra = c2.get("mastra");
|
|
3274
1156
|
const networkId = c2.req.param("networkId");
|
|
3275
|
-
const
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
1157
|
+
const network = await getNetworkByIdHandler$1({
|
|
1158
|
+
mastra,
|
|
1159
|
+
networkId
|
|
3279
1160
|
});
|
|
3280
|
-
|
|
3281
|
-
return c2.json({ error: "Network not found" }, 404);
|
|
3282
|
-
}
|
|
3283
|
-
const routingAgent = network.getRoutingAgent();
|
|
3284
|
-
const agents = network.getAgents();
|
|
3285
|
-
const serializedNetwork = {
|
|
3286
|
-
id: network.formatAgentId(routingAgent.name),
|
|
3287
|
-
name: routingAgent.name,
|
|
3288
|
-
instructions: routingAgent.instructions,
|
|
3289
|
-
agents: agents.map((agent) => ({
|
|
3290
|
-
name: agent.name,
|
|
3291
|
-
provider: agent.llm?.getProvider(),
|
|
3292
|
-
modelId: agent.llm?.getModelId()
|
|
3293
|
-
})),
|
|
3294
|
-
routingModel: {
|
|
3295
|
-
provider: routingAgent.llm?.getProvider(),
|
|
3296
|
-
modelId: routingAgent.llm?.getModelId()
|
|
3297
|
-
}
|
|
3298
|
-
};
|
|
3299
|
-
return c2.json(serializedNetwork);
|
|
1161
|
+
return c2.json(network);
|
|
3300
1162
|
} catch (error) {
|
|
3301
1163
|
return handleError(error, "Error getting network by ID");
|
|
3302
1164
|
}
|
|
@@ -3305,14 +1167,12 @@ async function generateHandler2(c2) {
|
|
|
3305
1167
|
try {
|
|
3306
1168
|
const mastra = c2.get("mastra");
|
|
3307
1169
|
const networkId = c2.req.param("networkId");
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
const finalResourceId = resourceId ?? resourceid;
|
|
3315
|
-
const result = await network.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
1170
|
+
const body = await c2.req.json();
|
|
1171
|
+
const result = await generateHandler$1({
|
|
1172
|
+
mastra,
|
|
1173
|
+
networkId,
|
|
1174
|
+
body
|
|
1175
|
+
});
|
|
3316
1176
|
return c2.json(result);
|
|
3317
1177
|
} catch (error) {
|
|
3318
1178
|
return handleError(error, "Error generating from network");
|
|
@@ -3322,26 +1182,11 @@ async function streamGenerateHandler2(c2) {
|
|
|
3322
1182
|
try {
|
|
3323
1183
|
const mastra = c2.get("mastra");
|
|
3324
1184
|
const networkId = c2.req.param("networkId");
|
|
3325
|
-
const
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
validateBody({ messages });
|
|
3331
|
-
const finalResourceId = resourceId ?? resourceid;
|
|
3332
|
-
const streamResult = await network.stream(messages, {
|
|
3333
|
-
threadId,
|
|
3334
|
-
resourceId: finalResourceId,
|
|
3335
|
-
output,
|
|
3336
|
-
runId,
|
|
3337
|
-
...rest
|
|
3338
|
-
});
|
|
3339
|
-
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
3340
|
-
sendUsage: true,
|
|
3341
|
-
sendReasoning: true,
|
|
3342
|
-
getErrorMessage: (error) => {
|
|
3343
|
-
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
3344
|
-
}
|
|
1185
|
+
const body = await c2.req.json();
|
|
1186
|
+
const streamResponse = await streamGenerateHandler$1({
|
|
1187
|
+
mastra,
|
|
1188
|
+
networkId,
|
|
1189
|
+
body
|
|
3345
1190
|
});
|
|
3346
1191
|
return streamResponse;
|
|
3347
1192
|
} catch (error) {
|
|
@@ -3465,53 +1310,37 @@ async function rootHandler(c2) {
|
|
|
3465
1310
|
async function getTelemetryHandler(c2) {
|
|
3466
1311
|
try {
|
|
3467
1312
|
const mastra = c2.get("mastra");
|
|
3468
|
-
const telemetry = mastra.getTelemetry();
|
|
3469
|
-
const storage = mastra.getStorage();
|
|
3470
1313
|
const { name, scope, page, perPage } = c2.req.query();
|
|
3471
1314
|
const attribute = c2.req.queries("attribute");
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
if (!storage) {
|
|
3476
|
-
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
3477
|
-
}
|
|
3478
|
-
const attributes = attribute ? Object.fromEntries(
|
|
3479
|
-
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
3480
|
-
const [key, value] = attr.split(":");
|
|
3481
|
-
return [key, value];
|
|
3482
|
-
})
|
|
3483
|
-
) : void 0;
|
|
3484
|
-
const traces = await storage.getTraces({
|
|
3485
|
-
name,
|
|
3486
|
-
scope,
|
|
3487
|
-
page: Number(page ?? 0),
|
|
3488
|
-
perPage: Number(perPage ?? 100),
|
|
3489
|
-
attributes
|
|
1315
|
+
const traces = await getTelemetryHandler$1({
|
|
1316
|
+
mastra,
|
|
1317
|
+
body: { name, scope, page: Number(page ?? 0), perPage: Number(perPage ?? 100), attribute }
|
|
3490
1318
|
});
|
|
3491
1319
|
return c2.json({ traces });
|
|
3492
1320
|
} catch (error) {
|
|
3493
|
-
return handleError(error, "Error
|
|
1321
|
+
return handleError(error, "Error getting telemetry traces");
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
async function storeTelemetryHandler(c2) {
|
|
1325
|
+
try {
|
|
1326
|
+
const body = await c2.req.json();
|
|
1327
|
+
const mastra = c2.get("mastra");
|
|
1328
|
+
const result = await storeTelemetryHandler$1({ mastra, body });
|
|
1329
|
+
if (result.status === "error") {
|
|
1330
|
+
return c2.json(result, 500);
|
|
1331
|
+
}
|
|
1332
|
+
return c2.json(result, 200);
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
return handleError(error, "Error storing telemetry traces");
|
|
3494
1335
|
}
|
|
3495
1336
|
}
|
|
3496
1337
|
async function getToolsHandler(c2) {
|
|
3497
1338
|
try {
|
|
3498
1339
|
const tools = c2.get("tools");
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
}
|
|
3502
|
-
|
|
3503
|
-
(acc, [id, _tool]) => {
|
|
3504
|
-
const tool = _tool;
|
|
3505
|
-
acc[id] = {
|
|
3506
|
-
...tool,
|
|
3507
|
-
inputSchema: tool.inputSchema ? stringify(esm_default(tool.inputSchema)) : void 0,
|
|
3508
|
-
outputSchema: tool.outputSchema ? stringify(esm_default(tool.outputSchema)) : void 0
|
|
3509
|
-
};
|
|
3510
|
-
return acc;
|
|
3511
|
-
},
|
|
3512
|
-
{}
|
|
3513
|
-
);
|
|
3514
|
-
return c2.json(serializedTools);
|
|
1340
|
+
const result = await getToolsHandler$1({
|
|
1341
|
+
tools
|
|
1342
|
+
});
|
|
1343
|
+
return c2.json(result);
|
|
3515
1344
|
} catch (error) {
|
|
3516
1345
|
return handleError(error, "Error getting tools");
|
|
3517
1346
|
}
|
|
@@ -3520,16 +1349,11 @@ async function getToolByIdHandler(c2) {
|
|
|
3520
1349
|
try {
|
|
3521
1350
|
const tools = c2.get("tools");
|
|
3522
1351
|
const toolId = c2.req.param("toolId");
|
|
3523
|
-
const
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
}
|
|
3527
|
-
|
|
3528
|
-
...tool,
|
|
3529
|
-
inputSchema: tool.inputSchema ? stringify(esm_default(tool.inputSchema)) : void 0,
|
|
3530
|
-
outputSchema: tool.outputSchema ? stringify(esm_default(tool.outputSchema)) : void 0
|
|
3531
|
-
};
|
|
3532
|
-
return c2.json(serializedTool);
|
|
1352
|
+
const result = await getToolByIdHandler$1({
|
|
1353
|
+
tools,
|
|
1354
|
+
toolId
|
|
1355
|
+
});
|
|
1356
|
+
return c2.json(result);
|
|
3533
1357
|
} catch (error) {
|
|
3534
1358
|
return handleError(error, "Error getting tool");
|
|
3535
1359
|
}
|
|
@@ -3537,24 +1361,13 @@ async function getToolByIdHandler(c2) {
|
|
|
3537
1361
|
function executeToolHandler(tools) {
|
|
3538
1362
|
return async (c2) => {
|
|
3539
1363
|
try {
|
|
1364
|
+
const mastra = c2.get("mastra");
|
|
3540
1365
|
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
3541
|
-
const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
|
|
3542
|
-
if (!tool) {
|
|
3543
|
-
return c2.json({ error: "Tool not found" }, 404);
|
|
3544
|
-
}
|
|
3545
|
-
if (!tool?.execute) {
|
|
3546
|
-
return c2.json({ error: "Tool is not executable" }, 400);
|
|
3547
|
-
}
|
|
3548
1366
|
const { data } = await c2.req.json();
|
|
3549
|
-
const
|
|
3550
|
-
if (isVercelTool(tool)) {
|
|
3551
|
-
const result2 = await tool.execute(data);
|
|
3552
|
-
return c2.json(result2);
|
|
3553
|
-
}
|
|
3554
|
-
const result = await tool.execute({
|
|
3555
|
-
context: data,
|
|
1367
|
+
const result = await executeToolHandler$1(tools)({
|
|
3556
1368
|
mastra,
|
|
3557
|
-
|
|
1369
|
+
toolId,
|
|
1370
|
+
data
|
|
3558
1371
|
});
|
|
3559
1372
|
return c2.json(result);
|
|
3560
1373
|
} catch (error) {
|
|
@@ -3567,45 +1380,28 @@ async function executeAgentToolHandler(c2) {
|
|
|
3567
1380
|
const mastra = c2.get("mastra");
|
|
3568
1381
|
const agentId = c2.req.param("agentId");
|
|
3569
1382
|
const toolId = c2.req.param("toolId");
|
|
3570
|
-
const agent = mastra.getAgent(agentId);
|
|
3571
|
-
const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
|
|
3572
|
-
if (!tool) {
|
|
3573
|
-
throw new HTTPException(404, { message: "Tool not found" });
|
|
3574
|
-
}
|
|
3575
|
-
if (!tool?.execute) {
|
|
3576
|
-
return c2.json({ error: "Tool is not executable" }, 400);
|
|
3577
|
-
}
|
|
3578
1383
|
const { data } = await c2.req.json();
|
|
3579
|
-
|
|
3580
|
-
const result2 = await tool.execute(data);
|
|
3581
|
-
return c2.json(result2);
|
|
3582
|
-
}
|
|
3583
|
-
const result = await tool.execute({
|
|
3584
|
-
context: data,
|
|
1384
|
+
const result = await executeAgentToolHandler$1({
|
|
3585
1385
|
mastra,
|
|
3586
|
-
|
|
1386
|
+
agentId,
|
|
1387
|
+
toolId,
|
|
1388
|
+
data
|
|
3587
1389
|
});
|
|
3588
1390
|
return c2.json(result);
|
|
3589
1391
|
} catch (error) {
|
|
3590
1392
|
return handleError(error, "Error executing tool");
|
|
3591
1393
|
}
|
|
3592
1394
|
}
|
|
3593
|
-
var getVector = (c2, vectorName) => {
|
|
3594
|
-
const vector = c2.get("mastra").getVector(vectorName);
|
|
3595
|
-
if (!vector) {
|
|
3596
|
-
throw new HTTPException(404, { message: `Vector store ${vectorName} not found` });
|
|
3597
|
-
}
|
|
3598
|
-
return vector;
|
|
3599
|
-
};
|
|
3600
1395
|
async function upsertVectors(c2) {
|
|
3601
1396
|
try {
|
|
1397
|
+
const mastra = c2.get("mastra");
|
|
3602
1398
|
const vectorName = c2.req.param("vectorName");
|
|
3603
|
-
const
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
1399
|
+
const body = await c2.req.json();
|
|
1400
|
+
const result = await upsertVectors$1({
|
|
1401
|
+
mastra,
|
|
1402
|
+
vectorName,
|
|
1403
|
+
index: body
|
|
1404
|
+
});
|
|
3609
1405
|
return c2.json({ ids: result });
|
|
3610
1406
|
} catch (error) {
|
|
3611
1407
|
return handleError(error, "Error upserting vectors");
|
|
@@ -3613,18 +1409,14 @@ async function upsertVectors(c2) {
|
|
|
3613
1409
|
}
|
|
3614
1410
|
async function createIndex(c2) {
|
|
3615
1411
|
try {
|
|
1412
|
+
const mastra = c2.get("mastra");
|
|
3616
1413
|
const vectorName = c2.req.param("vectorName");
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
}
|
|
3623
|
-
if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
|
|
3624
|
-
throw new HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
|
|
3625
|
-
}
|
|
3626
|
-
const vector = getVector(c2, vectorName);
|
|
3627
|
-
await vector.createIndex({ indexName, dimension, metric });
|
|
1414
|
+
const body = await c2.req.json();
|
|
1415
|
+
await createIndex$1({
|
|
1416
|
+
mastra,
|
|
1417
|
+
vectorName,
|
|
1418
|
+
index: body
|
|
1419
|
+
});
|
|
3628
1420
|
return c2.json({ success: true });
|
|
3629
1421
|
} catch (error) {
|
|
3630
1422
|
return handleError(error, "Error creating index");
|
|
@@ -3632,13 +1424,14 @@ async function createIndex(c2) {
|
|
|
3632
1424
|
}
|
|
3633
1425
|
async function queryVectors(c2) {
|
|
3634
1426
|
try {
|
|
1427
|
+
const mastra = c2.get("mastra");
|
|
3635
1428
|
const vectorName = c2.req.param("vectorName");
|
|
3636
1429
|
const { indexName, queryVector, topK = 10, filter, includeVector = false } = await c2.req.json();
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
1430
|
+
const results = await queryVectors$1({
|
|
1431
|
+
mastra,
|
|
1432
|
+
vectorName,
|
|
1433
|
+
query: { indexName, queryVector, topK, filter, includeVector }
|
|
1434
|
+
});
|
|
3642
1435
|
return c2.json({ results });
|
|
3643
1436
|
} catch (error) {
|
|
3644
1437
|
return handleError(error, "Error querying vectors");
|
|
@@ -3646,23 +1439,30 @@ async function queryVectors(c2) {
|
|
|
3646
1439
|
}
|
|
3647
1440
|
async function listIndexes(c2) {
|
|
3648
1441
|
try {
|
|
1442
|
+
const mastra = c2.get("mastra");
|
|
3649
1443
|
const vectorName = c2.req.param("vectorName");
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3652
|
-
|
|
1444
|
+
const indexes = await listIndexes$1({
|
|
1445
|
+
mastra,
|
|
1446
|
+
vectorName
|
|
1447
|
+
});
|
|
1448
|
+
return c2.json({ indexes });
|
|
3653
1449
|
} catch (error) {
|
|
3654
1450
|
return handleError(error, "Error listing indexes");
|
|
3655
1451
|
}
|
|
3656
1452
|
}
|
|
3657
1453
|
async function describeIndex(c2) {
|
|
3658
1454
|
try {
|
|
1455
|
+
const mastra = c2.get("mastra");
|
|
3659
1456
|
const vectorName = c2.req.param("vectorName");
|
|
3660
1457
|
const indexName = c2.req.param("indexName");
|
|
3661
1458
|
if (!indexName) {
|
|
3662
1459
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
3663
1460
|
}
|
|
3664
|
-
const
|
|
3665
|
-
|
|
1461
|
+
const stats = await describeIndex$1({
|
|
1462
|
+
mastra,
|
|
1463
|
+
vectorName,
|
|
1464
|
+
indexName
|
|
1465
|
+
});
|
|
3666
1466
|
return c2.json({
|
|
3667
1467
|
dimension: stats.dimension,
|
|
3668
1468
|
count: stats.count,
|
|
@@ -3674,13 +1474,17 @@ async function describeIndex(c2) {
|
|
|
3674
1474
|
}
|
|
3675
1475
|
async function deleteIndex(c2) {
|
|
3676
1476
|
try {
|
|
1477
|
+
const mastra = c2.get("mastra");
|
|
3677
1478
|
const vectorName = c2.req.param("vectorName");
|
|
3678
1479
|
const indexName = c2.req.param("indexName");
|
|
3679
1480
|
if (!indexName) {
|
|
3680
1481
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
3681
1482
|
}
|
|
3682
|
-
|
|
3683
|
-
|
|
1483
|
+
await deleteIndex$1({
|
|
1484
|
+
mastra,
|
|
1485
|
+
vectorName,
|
|
1486
|
+
indexName
|
|
1487
|
+
});
|
|
3684
1488
|
return c2.json({ success: true });
|
|
3685
1489
|
} catch (error) {
|
|
3686
1490
|
return handleError(error, "Error deleting index");
|
|
@@ -3690,14 +1494,10 @@ async function getSpeakersHandler(c2) {
|
|
|
3690
1494
|
try {
|
|
3691
1495
|
const mastra = c2.get("mastra");
|
|
3692
1496
|
const agentId = c2.req.param("agentId");
|
|
3693
|
-
const
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
}
|
|
3697
|
-
if (!agent.voice) {
|
|
3698
|
-
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
3699
|
-
}
|
|
3700
|
-
const speakers = await agent.getSpeakers();
|
|
1497
|
+
const speakers = await getSpeakersHandler$1({
|
|
1498
|
+
mastra,
|
|
1499
|
+
agentId
|
|
1500
|
+
});
|
|
3701
1501
|
return c2.json(speakers);
|
|
3702
1502
|
} catch (error) {
|
|
3703
1503
|
return handleError(error, "Error getting speakers");
|
|
@@ -3707,16 +1507,12 @@ async function speakHandler(c2) {
|
|
|
3707
1507
|
try {
|
|
3708
1508
|
const mastra = c2.get("mastra");
|
|
3709
1509
|
const agentId = c2.req.param("agentId");
|
|
3710
|
-
const agent = mastra.getAgent(agentId);
|
|
3711
|
-
if (!agent) {
|
|
3712
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
3713
|
-
}
|
|
3714
|
-
if (!agent.voice) {
|
|
3715
|
-
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
3716
|
-
}
|
|
3717
1510
|
const { input, options } = await c2.req.json();
|
|
3718
|
-
await
|
|
3719
|
-
|
|
1511
|
+
const audioStream = await generateSpeechHandler({
|
|
1512
|
+
mastra,
|
|
1513
|
+
agentId,
|
|
1514
|
+
body: { text: input, speakerId: options?.speakerId }
|
|
1515
|
+
});
|
|
3720
1516
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3721
1517
|
c2.header("Transfer-Encoding", "chunked");
|
|
3722
1518
|
return c2.body(audioStream);
|
|
@@ -3728,14 +1524,6 @@ async function listenHandler(c2) {
|
|
|
3728
1524
|
try {
|
|
3729
1525
|
const mastra = c2.get("mastra");
|
|
3730
1526
|
const agentId = c2.req.param("agentId");
|
|
3731
|
-
const agent = mastra.getAgent(agentId);
|
|
3732
|
-
const logger2 = mastra.getLogger();
|
|
3733
|
-
if (!agent) {
|
|
3734
|
-
throw new HTTPException(404, { message: "Agent not found" });
|
|
3735
|
-
}
|
|
3736
|
-
if (!agent.voice) {
|
|
3737
|
-
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
3738
|
-
}
|
|
3739
1527
|
const formData = await c2.req.formData();
|
|
3740
1528
|
const audioFile = formData.get("audio");
|
|
3741
1529
|
const options = formData.get("options");
|
|
@@ -3743,19 +1531,19 @@ async function listenHandler(c2) {
|
|
|
3743
1531
|
throw new HTTPException(400, { message: "Audio file is required" });
|
|
3744
1532
|
}
|
|
3745
1533
|
const audioData = await audioFile.arrayBuffer();
|
|
3746
|
-
|
|
3747
|
-
audioStream.push(Buffer.from(audioData));
|
|
3748
|
-
audioStream.push(null);
|
|
3749
|
-
let parsedOptions;
|
|
1534
|
+
let parsedOptions = {};
|
|
3750
1535
|
try {
|
|
3751
1536
|
parsedOptions = options ? JSON.parse(options) : {};
|
|
3752
|
-
} catch
|
|
3753
|
-
if (error instanceof SyntaxError) {
|
|
3754
|
-
logger2.error("Invalid JSON in options:", error);
|
|
3755
|
-
}
|
|
3756
|
-
parsedOptions = {};
|
|
1537
|
+
} catch {
|
|
3757
1538
|
}
|
|
3758
|
-
const transcription = await
|
|
1539
|
+
const transcription = await transcribeSpeechHandler({
|
|
1540
|
+
mastra,
|
|
1541
|
+
agentId,
|
|
1542
|
+
body: {
|
|
1543
|
+
audioData: Buffer.from(audioData),
|
|
1544
|
+
options: parsedOptions
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
3759
1547
|
return c2.json({ text: transcription });
|
|
3760
1548
|
} catch (error) {
|
|
3761
1549
|
return handleError(error, "Error transcribing speech");
|
|
@@ -3764,28 +1552,10 @@ async function listenHandler(c2) {
|
|
|
3764
1552
|
async function getWorkflowsHandler(c2) {
|
|
3765
1553
|
try {
|
|
3766
1554
|
const mastra = c2.get("mastra");
|
|
3767
|
-
const workflows =
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
3772
|
-
serializedStepGraph: workflow.serializedStepGraph,
|
|
3773
|
-
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
3774
|
-
name: workflow.name,
|
|
3775
|
-
triggerSchema: workflow.triggerSchema ? stringify(esm_default(workflow.triggerSchema)) : void 0,
|
|
3776
|
-
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
3777
|
-
const _step = step;
|
|
3778
|
-
acc2[key2] = {
|
|
3779
|
-
..._step,
|
|
3780
|
-
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
3781
|
-
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
3782
|
-
};
|
|
3783
|
-
return acc2;
|
|
3784
|
-
}, {})
|
|
3785
|
-
};
|
|
3786
|
-
return acc;
|
|
3787
|
-
}, {});
|
|
3788
|
-
return c2.json(_workflows);
|
|
1555
|
+
const workflows = await getWorkflowsHandler$1({
|
|
1556
|
+
mastra
|
|
1557
|
+
});
|
|
1558
|
+
return c2.json(workflows);
|
|
3789
1559
|
} catch (error) {
|
|
3790
1560
|
return handleError(error, "Error getting workflows");
|
|
3791
1561
|
}
|
|
@@ -3794,30 +1564,11 @@ async function getWorkflowByIdHandler(c2) {
|
|
|
3794
1564
|
try {
|
|
3795
1565
|
const mastra = c2.get("mastra");
|
|
3796
1566
|
const workflowId = c2.req.param("workflowId");
|
|
3797
|
-
const workflow =
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
const stepSubscriberGraph = workflow.stepSubscriberGraph;
|
|
3801
|
-
const serializedStepGraph = workflow.serializedStepGraph;
|
|
3802
|
-
const serializedStepSubscriberGraph = workflow.serializedStepSubscriberGraph;
|
|
3803
|
-
const serializedSteps = Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
3804
|
-
const _step = step;
|
|
3805
|
-
acc[key] = {
|
|
3806
|
-
..._step,
|
|
3807
|
-
inputSchema: _step.inputSchema ? stringify(esm_default(_step.inputSchema)) : void 0,
|
|
3808
|
-
outputSchema: _step.outputSchema ? stringify(esm_default(_step.outputSchema)) : void 0
|
|
3809
|
-
};
|
|
3810
|
-
return acc;
|
|
3811
|
-
}, {});
|
|
3812
|
-
return c2.json({
|
|
3813
|
-
name: workflow.name,
|
|
3814
|
-
triggerSchema: triggerSchema ? stringify(esm_default(triggerSchema)) : void 0,
|
|
3815
|
-
steps: serializedSteps,
|
|
3816
|
-
stepGraph,
|
|
3817
|
-
stepSubscriberGraph,
|
|
3818
|
-
serializedStepGraph,
|
|
3819
|
-
serializedStepSubscriberGraph
|
|
1567
|
+
const workflow = await getWorkflowByIdHandler$1({
|
|
1568
|
+
mastra,
|
|
1569
|
+
workflowId
|
|
3820
1570
|
});
|
|
1571
|
+
return c2.json(workflow);
|
|
3821
1572
|
} catch (error) {
|
|
3822
1573
|
return handleError(error, "Error getting workflow");
|
|
3823
1574
|
}
|
|
@@ -3826,18 +1577,13 @@ async function startAsyncWorkflowHandler(c2) {
|
|
|
3826
1577
|
try {
|
|
3827
1578
|
const mastra = c2.get("mastra");
|
|
3828
1579
|
const workflowId = c2.req.param("workflowId");
|
|
3829
|
-
const
|
|
3830
|
-
const body = await c2.req.json();
|
|
1580
|
+
const triggerData = await c2.req.json();
|
|
3831
1581
|
const runId = c2.req.query("runId");
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
3838
|
-
}
|
|
3839
|
-
const result = await run.start({
|
|
3840
|
-
triggerData: body
|
|
1582
|
+
const result = await startAsyncWorkflowHandler$1({
|
|
1583
|
+
mastra,
|
|
1584
|
+
workflowId,
|
|
1585
|
+
runId,
|
|
1586
|
+
triggerData
|
|
3841
1587
|
});
|
|
3842
1588
|
return c2.json(result);
|
|
3843
1589
|
} catch (error) {
|
|
@@ -3848,10 +1594,13 @@ async function createRunHandler(c2) {
|
|
|
3848
1594
|
try {
|
|
3849
1595
|
const mastra = c2.get("mastra");
|
|
3850
1596
|
const workflowId = c2.req.param("workflowId");
|
|
3851
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3852
1597
|
const prevRunId = c2.req.query("runId");
|
|
3853
|
-
const
|
|
3854
|
-
|
|
1598
|
+
const result = await createRunHandler$1({
|
|
1599
|
+
mastra,
|
|
1600
|
+
workflowId,
|
|
1601
|
+
runId: prevRunId
|
|
1602
|
+
});
|
|
1603
|
+
return c2.json(result);
|
|
3855
1604
|
} catch (e2) {
|
|
3856
1605
|
return handleError(e2, "Error creating run");
|
|
3857
1606
|
}
|
|
@@ -3860,54 +1609,51 @@ async function startWorkflowRunHandler(c2) {
|
|
|
3860
1609
|
try {
|
|
3861
1610
|
const mastra = c2.get("mastra");
|
|
3862
1611
|
const workflowId = c2.req.param("workflowId");
|
|
3863
|
-
const
|
|
3864
|
-
const body = await c2.req.json();
|
|
1612
|
+
const triggerData = await c2.req.json();
|
|
3865
1613
|
const runId = c2.req.query("runId");
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
3872
|
-
}
|
|
3873
|
-
run.start({
|
|
3874
|
-
triggerData: body
|
|
1614
|
+
await startWorkflowRunHandler$1({
|
|
1615
|
+
mastra,
|
|
1616
|
+
workflowId,
|
|
1617
|
+
runId,
|
|
1618
|
+
triggerData
|
|
3875
1619
|
});
|
|
3876
1620
|
return c2.json({ message: "Workflow run started" });
|
|
3877
1621
|
} catch (e2) {
|
|
3878
1622
|
return handleError(e2, "Error starting workflow run");
|
|
3879
1623
|
}
|
|
3880
1624
|
}
|
|
3881
|
-
|
|
1625
|
+
function watchWorkflowHandler(c2) {
|
|
3882
1626
|
try {
|
|
3883
1627
|
const mastra = c2.get("mastra");
|
|
3884
1628
|
const logger2 = mastra.getLogger();
|
|
3885
1629
|
const workflowId = c2.req.param("workflowId");
|
|
3886
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3887
1630
|
const runId = c2.req.query("runId");
|
|
3888
1631
|
if (!runId) {
|
|
3889
1632
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
3890
1633
|
}
|
|
3891
|
-
|
|
3892
|
-
if (!run) {
|
|
3893
|
-
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
3894
|
-
}
|
|
3895
|
-
return streamText(
|
|
1634
|
+
return stream(
|
|
3896
1635
|
c2,
|
|
3897
|
-
async (
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
1636
|
+
async (stream2) => {
|
|
1637
|
+
try {
|
|
1638
|
+
const result = await watchWorkflowHandler$1({
|
|
1639
|
+
mastra,
|
|
1640
|
+
workflowId,
|
|
1641
|
+
runId
|
|
3901
1642
|
});
|
|
3902
|
-
|
|
3903
|
-
|
|
1643
|
+
stream2.onAbort(() => {
|
|
1644
|
+
if (!result.locked) {
|
|
1645
|
+
return result.cancel();
|
|
1646
|
+
}
|
|
3904
1647
|
});
|
|
3905
|
-
|
|
1648
|
+
for await (const chunk of result) {
|
|
1649
|
+
await stream2.write(chunk.toString() + "");
|
|
1650
|
+
}
|
|
1651
|
+
} catch (err) {
|
|
1652
|
+
console.log(err);
|
|
1653
|
+
}
|
|
3906
1654
|
},
|
|
3907
|
-
async (err
|
|
1655
|
+
async (err) => {
|
|
3908
1656
|
logger2.error("Error in watch stream: " + err?.message);
|
|
3909
|
-
stream.abort();
|
|
3910
|
-
await stream.close();
|
|
3911
1657
|
}
|
|
3912
1658
|
);
|
|
3913
1659
|
} catch (error) {
|
|
@@ -3918,19 +1664,16 @@ async function resumeAsyncWorkflowHandler(c2) {
|
|
|
3918
1664
|
try {
|
|
3919
1665
|
const mastra = c2.get("mastra");
|
|
3920
1666
|
const workflowId = c2.req.param("workflowId");
|
|
3921
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3922
1667
|
const runId = c2.req.query("runId");
|
|
3923
1668
|
const { stepId, context } = await c2.req.json();
|
|
3924
1669
|
if (!runId) {
|
|
3925
1670
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
3926
1671
|
}
|
|
3927
|
-
const
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
stepId,
|
|
3933
|
-
context
|
|
1672
|
+
const result = await resumeAsyncWorkflowHandler$1({
|
|
1673
|
+
mastra,
|
|
1674
|
+
workflowId,
|
|
1675
|
+
runId,
|
|
1676
|
+
body: { stepId, context }
|
|
3934
1677
|
});
|
|
3935
1678
|
return c2.json(result);
|
|
3936
1679
|
} catch (error) {
|
|
@@ -3941,19 +1684,16 @@ async function resumeWorkflowHandler(c2) {
|
|
|
3941
1684
|
try {
|
|
3942
1685
|
const mastra = c2.get("mastra");
|
|
3943
1686
|
const workflowId = c2.req.param("workflowId");
|
|
3944
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3945
1687
|
const runId = c2.req.query("runId");
|
|
3946
1688
|
const { stepId, context } = await c2.req.json();
|
|
3947
1689
|
if (!runId) {
|
|
3948
1690
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
3949
1691
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
stepId,
|
|
3956
|
-
context
|
|
1692
|
+
await resumeWorkflowHandler$1({
|
|
1693
|
+
mastra,
|
|
1694
|
+
workflowId,
|
|
1695
|
+
runId,
|
|
1696
|
+
body: { stepId, context }
|
|
3957
1697
|
});
|
|
3958
1698
|
return c2.json({ message: "Workflow run resumed" });
|
|
3959
1699
|
} catch (error) {
|
|
@@ -4088,7 +1828,7 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4088
1828
|
cors({
|
|
4089
1829
|
origin: "*",
|
|
4090
1830
|
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
4091
|
-
allowHeaders: ["Content-Type", "Authorization"],
|
|
1831
|
+
allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type"],
|
|
4092
1832
|
exposeHeaders: ["Content-Length", "X-Requested-With"],
|
|
4093
1833
|
credentials: false,
|
|
4094
1834
|
maxAge: 3600
|
|
@@ -4108,13 +1848,67 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4108
1848
|
c2.set("mastra", mastra);
|
|
4109
1849
|
c2.set("tools", tools);
|
|
4110
1850
|
c2.set("playground", options.playground === true);
|
|
4111
|
-
|
|
1851
|
+
const requestId = c2.req.header("x-request-id") ?? randomUUID();
|
|
1852
|
+
const span = Telemetry.getActiveSpan();
|
|
1853
|
+
if (span) {
|
|
1854
|
+
span.setAttribute("http.request_id", requestId);
|
|
1855
|
+
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
1856
|
+
const newCtx = Telemetry.setBaggage({
|
|
1857
|
+
"http.request_id": requestId
|
|
1858
|
+
});
|
|
1859
|
+
await new Promise((resolve) => {
|
|
1860
|
+
Telemetry.withContext(newCtx, async () => {
|
|
1861
|
+
await next();
|
|
1862
|
+
resolve(true);
|
|
1863
|
+
});
|
|
1864
|
+
});
|
|
1865
|
+
} else {
|
|
1866
|
+
await next();
|
|
1867
|
+
}
|
|
4112
1868
|
});
|
|
4113
1869
|
const bodyLimitOptions = {
|
|
4114
1870
|
maxSize: 4.5 * 1024 * 1024,
|
|
4115
1871
|
// 4.5 MB,
|
|
4116
1872
|
onError: (c2) => c2.json({ error: "Request body too large" }, 413)
|
|
4117
1873
|
};
|
|
1874
|
+
const server = mastra.getServer();
|
|
1875
|
+
const routes = server?.apiRoutes;
|
|
1876
|
+
if (server?.middleware) {
|
|
1877
|
+
const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
|
|
1878
|
+
const middlewares = normalizedMiddlewares.map((middleware2) => {
|
|
1879
|
+
if (typeof middleware2 === "function") {
|
|
1880
|
+
return {
|
|
1881
|
+
path: "*",
|
|
1882
|
+
handler: middleware2
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
return middleware2;
|
|
1886
|
+
});
|
|
1887
|
+
for (const middleware2 of middlewares) {
|
|
1888
|
+
app.use(middleware2.path, middleware2.handler);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
if (routes) {
|
|
1892
|
+
for (const route of routes) {
|
|
1893
|
+
const middlewares = [];
|
|
1894
|
+
if (route.middleware) {
|
|
1895
|
+
middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
|
|
1896
|
+
}
|
|
1897
|
+
if (route.openapi) {
|
|
1898
|
+
middlewares.push(h(route.openapi));
|
|
1899
|
+
}
|
|
1900
|
+
console.log({ path: route.path, middlewares });
|
|
1901
|
+
if (route.method === "GET") {
|
|
1902
|
+
app.get(route.path, ...middlewares, route.handler);
|
|
1903
|
+
} else if (route.method === "POST") {
|
|
1904
|
+
app.post(route.path, ...middlewares, route.handler);
|
|
1905
|
+
} else if (route.method === "PUT") {
|
|
1906
|
+
app.put(route.path, ...middlewares, route.handler);
|
|
1907
|
+
} else if (route.method === "DELETE") {
|
|
1908
|
+
app.delete(route.path, ...middlewares, route.handler);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
4118
1912
|
app.get(
|
|
4119
1913
|
"/api",
|
|
4120
1914
|
h({
|
|
@@ -5236,6 +3030,19 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5236
3030
|
}),
|
|
5237
3031
|
getTelemetryHandler
|
|
5238
3032
|
);
|
|
3033
|
+
app.post(
|
|
3034
|
+
"/api/telemetry",
|
|
3035
|
+
h({
|
|
3036
|
+
description: "Store telemetry",
|
|
3037
|
+
tags: ["telemetry"],
|
|
3038
|
+
responses: {
|
|
3039
|
+
200: {
|
|
3040
|
+
description: "Traces stored"
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
}),
|
|
3044
|
+
storeTelemetryHandler
|
|
3045
|
+
);
|
|
5239
3046
|
app.get(
|
|
5240
3047
|
"/api/workflows",
|
|
5241
3048
|
h({
|